diff --git a/storage-net/.gitignore b/storage-net/.gitignore new file mode 100644 index 0000000..722d5e7 --- /dev/null +++ b/storage-net/.gitignore @@ -0,0 +1 @@ +.vscode diff --git a/storage-net/README.md b/storage-net/README.md index d5e05f2..fcfb073 100644 --- a/storage-net/README.md +++ b/storage-net/README.md @@ -57,15 +57,11 @@ Packet format is uniform between master <-> slaves and is structured like so: ### Slave Node Initialization * The slave starts up -* The slave receives a `ping` packet from a master server. The slave compares it to any stored `/pairednetwork` file in the root of the filesystem: - * If the file exists and the ID does not match, processing is halted - * The `networkid` of the packet is stored as `/pairednetwork` -* The slave responds with a `pong` packet. ### Master Node Initialization * The master node starts up -* The master node sends a packet with type `ping` and `networkid` initialized to its CC ID. +* The master node sends a packet with type `ping`. * The master node listens for `pong` packets for a configurable timeout. * The `sourceid` of all `pong` packets is recorded for statistics displays. This cached data is only used for user display. Node availability is evaluated at request time. diff --git a/storage-net/common.lua b/storage-net/common.lua index 8bc6ebf..4bdf7fa 100644 --- a/storage-net/common.lua +++ b/storage-net/common.lua @@ -1,2 +1,49 @@ --- MASTER SCRIPT +-- Salt's ComputerCraft Storage Network Script +-- +-- For information on this script, physical in-world setup, and configuration, +-- see: https://git.desu.ltd/salt/mc-scripts/src/branch/master/storage-net + +-- Default configuration values. Override in config.lua. DO NOT CHANGE HERE +mode = "undefined" -- The mode of function for this node +networkid = 0 -- Unique ID for this network +port_broadcast = 42914 -- Port for M->S traffic +port_return = 42915 -- Port for S->M traffic + +-- This loads config.lua. See masterconfig.lua and slaveconfig.lua for example +-- configurations. require "config" + +-- Startup diagnostics +print("Salt's CC Storage Net") +print("Computer ID: " .. os.getComputerID()) +print("Computer " .. os.getComputerID() .. " running as " .. mode) + +-- Common functions +function c_mainLoop(loopfunc) + -- Loops a thing forever + while true do + loopfunc() + sleep(1) + end +end +-- Master functions +function m_loop() + -- The main loop of the master server +end +-- Slave functions +function s_loop() + -- The main loop of any slave nodes +end + +-- Application entrypoint +function main () + if (mode == "master") then + c_mainLoop(m_loop) + elseif (mode == "slave") then + c_mainLoop(s_loop) + else + error("Invalid mode: " .. mode .. ", please configure this node appropriately") + end +end + +main() \ No newline at end of file diff --git a/storage-net/deploy.sh b/storage-net/deploy.sh index 715a021..bb9c54e 100755 --- a/storage-net/deploy.sh +++ b/storage-net/deploy.sh @@ -10,12 +10,17 @@ mcroot="$HOME/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/instan world="New World" masterid="0" -slaveid="1" +slaves=("1" "8" "9") _ccroot="$mcroot/.minecraft/saves/$world/computercraft/computer" echo "Root: $_ccroot" -for computer in $masterid $slaveid; do - cp common.lua "$_ccroot/$masterid/autostart.lua" +for computer in "$masterid" ${slaves[*]}; do + echo "Deploying to: $computer" + mkdir -p "$_ccroot/$computer" + cp common.lua "$_ccroot/$computer/autostart.lua" done cp masterconfig.lua "$_ccroot/$masterid/config.lua" -cp slaveconfig.lua "$_ccroot/$slaveid/config.lua" +for slave in ${slaves[*]}; do + echo "Deploying slave config: $slave" + cp slaveconfig.lua "$_ccroot/$slave/config.lua" +done