Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by holco.
- --- DateTime: 2/19/2022 11:28 PM
- ---
- --Turbine Server
- --Version 0.1
- os.execute("clear");
- local component = require("component");
- local thread = require("thread");
- local serialization = require("serialization")
- local consoleGpu;
- local consoleScreen;
- local modem = component.modem;
- local event = require("event");
- local filesystem = require("filesystem");
- local term = require("term");
- local computer = require("computer");
- local serverDataPattern = {};
- local serverData = {};
- local stayConnected = {};
- local servers = {};
- local serversPattern = {};
- local handlerThreads = {};
- local displayThreads = {};
- local gpus = {};
- local run = true;
- serversPattern["address"] = 0;
- serversPattern["screenAddress"] = 0;
- serversPattern["gpuAddress"] = "";
- serverDataPattern["connectionStatus"] = "Disconnected";
- serverDataPattern["turbineStatus"] = "Offline";
- serverDataPattern["energyOutput"] = 0;
- serverDataPattern["energyBuffer"] = 0;
- serverDataPattern["mainPowerConnection"] = "Disconnected";
- serverDataPattern["fuelLoaded"] = 0;
- serverDataPattern["breakerStatus"] = "Disconnected";
- serverDataPattern["checkCloche"] = true;
- local gpuLoopThread;
- local port = 60;
- modem.open(port)
- --Startup Server
- function log(inputType, log)
- end
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- local function shallowCopy(original)
- local copy = {}
- for key, value in pairs(original) do
- copy[key] = value
- end
- return copy
- end
- function connectionHandler(address, client)
- local timeout = 5;
- --displayStats(client, tempServerData["connectionStatus"], tempServerData["turbineStatus"], tempServerData["energyOutput"], tempServerData["energyBuffer"], tempServerData["mainPowerConnection"], tempServerData["fuelLoaded"], tempServerData["breakerStatus"], tempServerData["checkCloche"])
- --tempServerData = serverData[address];
- print("Started Connection Handler.")
- while stayConnected[address] do
- if serverData[address]["connectionStatus"] == "Starting" then
- local _, _, _, _, _, _ = event.pull("modem_message", nil, address, nil, nil, "started");
- serverData[address]["connectionStatus"] = "Connected";
- --print("Started");
- elseif serverData[address]["connectionStatus"] == "Stopping" then
- local _, _, _, _, _, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8 = event.pull("modem_message", nil, address, nil, nil, "stopped");
- serverData[address]["connectionStatus"] = "Connected";
- else
- modem.send(address, port, "getInfo");
- local _, _, _, _, _, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8 = event.pull(2, "modem_message", nil, address, nil, nil, "info");
- --print(msg1);
- if msg1 == nil and serverData[address]["connectionStatus"] ~= "Starting" and serverData[address]["connectionStatus"] ~= "Stopping" and timeout == 0 then
- serverData[address] = shallowCopy(serverDataPattern);
- elseif msg1 == nil and serverData[address]["connectionStatus"] ~= "Starting" and serverData[address]["connectionStatus"] ~= "Stopping" and timeout > 0 then
- timeout = timeout - 1;
- elseif serverData[address]["connectionStatus"] ~= "Starting" and serverData[address]["connectionStatus"] ~= "Stopping" then
- log("Recieved Data...Updating Current Data");
- serverData[address]["connectionStatus"] = "Connected";
- serverData[address]["turbineStatus"] = msg2;
- serverData[address]["energyOutput"] = msg3;
- serverData[address]["energyBuffer"] = msg4;
- serverData[address]["mainPowerConnection"] = msg5;
- serverData[address]["fuelLoaded"] = msg6;
- serverData[address]["breakerStatus"] = msg7;
- serverData[address]["checkCloche"] = msg8;
- tempServerData = serverData[address];
- displayStats(client, tempServerData["connectionStatus"], tempServerData["turbineStatus"], tempServerData["energyOutput"], tempServerData["energyBuffer"], tempServerData["mainPowerConnection"], tempServerData["fuelLoaded"], tempServerData["breakerStatus"], tempServerData["checkCloche"])
- timeout = 5;
- end
- end
- end
- serverData[address] = shallowCopy(serverDataPattern);
- modem.send(address, port, "disconnecting")
- log("Disconnecting From Server [Reason: Force Disconnected]");
- end
- function addNewClient(serverName)
- print("Rebinding All External Card Docks...");
- for address, componentType in component.list("carddock") do
- component.proxy(address).bindComponent();
- end
- log("Server", "Attempting connection with new client \"" .. serverName .. "\"");
- print("Attempting connection with new client \"" .. serverName .. "\"");
- local _, _, from, _, _, message, name;
- modem.broadcast(port, "whois " .. serverName);
- _, _, from, _, _, message, name = event.pull(5, "modem_message", nil, nil, nil, nil, "I AM!!!", serverName);
- if name == nil then
- log("Server", "Attempted Connection Failed...Unable to find ")
- print("Unable to find " .. serverName)
- elseif name == serverName then
- log("Server", "Found Server " .. serverName);
- print("Found Server " .. serverName .. " Attempting Connection...");
- print("Please Enter Screen Address For Displaying Data")
- local tempScreenAddress;
- local run = true;
- while run do
- tempScreenAddress = io.read();
- if component.get(tempScreenAddress, "screen") == nil then
- print("Error...Screen Does Not Exist");
- else
- tempScreenAddress = component.get(tempScreenAddress, "screen");
- run = false;
- end
- end
- print("Please Enter the Graphics card that will be controlling the Screen");
- local tempGpuAddress;
- run = true;
- while run do
- tempGpuAddress = io.read();
- if component.get(tempGpuAddress, "gpu") == nil then
- print("Error...Gpu Does Not Exist");
- else
- tempGpuAddress = component.get(tempGpuAddress, "gpu");
- run = false;
- end
- end
- print("Running");
- servers[serverName] = shallowCopy(serversPattern);
- servers[serverName]["address"] = from;
- servers[serverName]["screenAddress"] = tempScreenAddress;
- servers[serverName]["gpuAddress"] = tempGpuAddress;
- local serversFile = io.open("servers.dat", "w");
- serversFile:write(serialization.serialize(servers));
- serversFile:close();
- createHandler(serverName);
- end
- end
- function API()
- while true do
- local _, _, from, _, _, msg1, msg2, msg3, msg4 = event.pull("modem_message", nil, nil, nil, nil, "API");
- local out;
- print("working")
- if msg2 == "cmd" then
- executeCmd(msg3)
- modem.send(from, port, true);
- elseif msg2 == "getdata" then
- modem.send(from, port, getData(msg3, msg4));
- elseif msg2 == "whois PowerServer" then
- modem.send(from, port, "I AM POWERSERVER!")
- else
- modem.send(from, port, "command not found");
- end
- end
- end
- function createHandler(serverName)
- local clientAddress = servers[serverName]["address"];
- if servers[serverName] == nil then
- print("Server Does Not Exist, or has not been added to the server yet");
- elseif handlerThreads[clientAddress] ~= nil then
- print("Client Handler already exists for this client");
- else
- print("Attempting To Create Handler For " .. serverName);
- serverData[servers[serverName]["address"]] = shallowCopy(serverDataPattern);
- --local test = serverData[servers[serverName]["address"]];
- --print(test["connectionStatus"])
- stayConnected[servers[serverName]["address"]] = true;
- handlerThreads[serverName] = thread.create(connectionHandler, servers[serverName]["address"], serverName);
- print("Attempting to start display for client");
- displayThreads[serverName] = thread.create(printClientData, serverName);
- end
- end
- function removeClient(client)
- local tempServerAddress = servers[client]["address"];
- print("Removing " .. client .. " from System...");
- if servers[client] ~= nil then
- killHandler(client);
- servers[client] = nil;
- local serversFile = io.open("servers.dat", "w");
- serversFile:write(serialization.serialize(servers));
- serversFile:close();
- print(client .. " successfully removed!")
- else
- print("Client Not Found On System.")
- end
- end
- function getData(server, data)
- local serAddress = servers[server]["address"];
- if servers[server] == nil then
- return("Server Does Not Exist.");
- elseif serverData[serAddress][data] == nil then
- return("Data does not exist");
- else
- return(data .. ": " .. serverData[serAddress][data])
- end
- end
- function sendRequest(target, request)
- if servers[target] == nil then
- print("Client Not Found...");
- else
- local serAddress = servers[target]["address"]
- modem.send(serAddress, port, "cmd", request);
- _, _, _, _, _, response = event.pull(10, "modem_message", nil, serAddress, nil, nil, "recieved");
- if response ~= nil then
- print("Message Recieved!...Waiting for server to finish...");
- _, _, _, _, _, _, report = event.pull(10, "modem_message", nil, serAddress, nil, nil, "report");
- print(report);
- else
- print("No Response Recieved...");
- end
- end
- end
- function executeCmd(input)
- local cmds = split(input, " ");
- local tempServerData;
- if servers[cmds[2]] ~= nil then tempServerData = serverData[servers[cmds[2]]["address"]]; end
- if cmds[1] == "addclient" then --Add New Client [Usage: addclient [client]]
- if cmds[2] == nil then print("Please Insert client name."); else addNewClient(cmds[2]) end
- elseif cmds[1] == "removeclient" then --Remove New Client [Usage: removeclient [client]]
- if cmds[2] == nil then print("Please Insert Existing Client Name...") else removeClient(cmds[2]); end
- elseif cmds[1] == "shutdown" then --Shutdown System
- if cmds[2] == nil then print("Error: No Client Name Inputed.")
- elseif servers[cmds[2]] == nil then
- print("Server Does not Exist");
- elseif tempServerData["connectionStatus"] == "Starting" or tempServerData["connectionStatus"] == "Stopping" then
- print("Please wait for " .. cmds[2] .. " to finish " .. tempServerData["connectionStatus"]);
- else
- shutdown(cmds[2], true);
- end
- elseif cmds[1] == "exit" then --Exits The Terminal
- run = false;
- elseif cmds[1] == "getinfo" then --Get info from server
- if cmds[2] == nil then print("Please Insert Existing Client Name...") else print(getData(cmds[2], cmds[3])); end
- elseif cmds[1] == "clear" then --clears screen
- os.execute("clear");
- elseif cmds[1] == "sendrequest" then --Send RAW request to client
- if cmds[2] == nil then print("Error: No Client Name Inputed.")
- elseif servers[cmds[2]] == nil then
- print("Server Does not Exist");
- elseif tempServerData["connectionStatus"] == "Starting" or tempServerData["connectionStatus"] == "Stopping" then
- print("Please wait for " .. cmds[2] .. " to finish " .. tempServerData["connectionStatus"]);
- else
- if cmds[2] == nil then print("Please Insert Existing Client Name...") else sendRequest(cmds[2], cmds[3]); end
- end
- elseif cmds[1] == "getdata" then --Gets data from client
- if cmds[2] == nil then print("Error: No Client Name Inputed.")
- elseif servers[cmds[2]] == nil then
- print("Server Does not Exist");
- elseif tempServerData["connectionStatus"] == "Starting" or tempServerData["connectionStatus"] == "Stopping" then
- print("Please wait for " .. cmds[2] .. " to finish " .. tempServerData["connectionStatus"]);
- else
- if servers[cmds[2]] == nil then
- print("Server does not exist")
- else
- print("Requesting Data...")
- modem.send(servers[cmds[2]]["address"], port, "getData", cmds[3]);
- print("Waiting for response...")
- local _, _, _, _, _, _, response = event.pull(2, "modem_message", nil, servers[cmds[2]]["address"], nil, nil, "heres data");
- print(response);
- end
- end
- elseif cmds[1] == "start" then
- if cmds[2] == nil then print("Error: No Client Name Inputed.")
- elseif servers[cmds[2]] == nil then
- print("Server Does not Exist");
- elseif tempServerData["connectionStatus"] == "Starting" then
- print(cmds[2] .. " is already starting.");
- elseif tempServerData["connectionStatus"] == "Stopping" then
- print("Please wait for " .. cmds[2] .. " to finish stopping.");
- else
- startSystem(cmds[2]);
- end
- elseif cmds[1] == "stop" then
- if cmds[2] == nil then print("Error: No Client Name Inputed.")
- elseif servers[cmds[2]] == nil then
- print("Server Does not Exist");
- elseif tempServerData["connectionStatus"] == "Stopping" then
- print(cmds[2] .. " is already stopping.");
- elseif tempServerData["connectionStatus"] == "Starting" then
- print("Please wait for " .. cmds[2] .. " to finish starting.");
- else
- stopSystem(cmds[2]);
- end
- elseif cmds[1] == "wakeup" then
- if cmds[2] == nil then print("Error: No Client Name Inputed.")
- elseif servers[cmds[2]] == nil then
- print("Server Does not Exist");
- elseif tempServerData["connectionStatus"] == "Starting" or tempServerData["connectionStatus"] == "Stopping" then
- print("Please wait for " .. cmds[2] .. " to finish " .. tempServerData["connectionStatus"]);
- else
- wakeUpClient(cmds[2]);
- end
- elseif cmds[1] == "disconnect" then
- if cmds[2] == nil then print("Error: No Client Name Inputed.")
- elseif servers[cmds[2]] == nil then
- print("Server Does not Exist");
- elseif tempServerData["connectionStatus"] == "Starting" or tempServerData["connectionStatus"] == "Stopping" then
- print("Please wait for " .. cmds[2] .. " to finish " .. tempServerData["connectionStatus"]);
- else
- killHandler(cmds[2]);
- print(cmds[2] .. "Disconnected");
- end
- elseif cmds[1] == "connect" then
- if cmds[2] == nil then print("Error: No Client Name Inputed.")
- elseif servers[cmds[2]] == nil then
- print("Server Does not Exist");
- elseif tempServerData["connectionStatus"] == "Starting" or tempServerData["connectionStatus"] == "Stopping" then
- print("Please wait for " .. cmds[2] .. " to finish " .. tempServerData["connectionStatus"]);
- else
- createHandler(cmds[2]);
- end
- else
- print("Command Not Found!")
- end
- end
- function startSystem(client)
- if servers[client] ~= nil then
- print("Are you sure you want to start " .. client .. " [y/n]");
- local ans = io.read();
- if ans == "y" then
- for t=0, 3, 1 do
- modem.send(servers[client]["address"], port, "cmd", "startSystems");
- local _, _, _, _, _, msg = event.pull(5, "modem_message", nil, servers[client]["address"], nil, nil, "recieved");
- print("Client Recieved Command");
- local _, _, _, _, _, input = event.pull(5, "modem_message", nil, servers[client]["address"], nil, nil, "starting");
- if input == nil then
- print("Error Communicating With " .. client);
- else
- print("System starting...Please wait a few minutes for system to start up.");
- serverData[servers[client]["address"]]["connectionStatus"] = "Starting";
- break;
- end
- end
- end
- end
- end
- function stopSystem(client, ans);
- if ans == nil then ans = false; end
- if servers[client] ~= nil then
- if ans == false then
- print("Are you sure you want to stop " .. client .. " [y/n]");
- ans = io.read();
- if ans == "y" then ans = true; else ans = false; end
- end
- if ans == true then
- modem.send(servers[client]["address"], port, "cmd", "stopSystems");
- local _, _, _, _, _, msg = event.pull(5, "modem_message", nil, servers[client]["address"], nil, nil, "stopping")
- if msg == nil then
- print("Error Communicating With " .. client);
- else
- print("System beginning to stop...Please wait a few minutes for system to finish.");
- serverData[servers[client]["address"]]["connectionStatus"] = "Stopping";
- end
- else
- print("Aborting Stop...")
- end
- end
- end
- function wakeUpClient(client)
- local from, message, name
- local clientAddress = servers[client]["address"];
- if serverData[clientAddress] ~= nil then
- print("Server is already connected");
- else
- print("Checking to see if client is already awake");
- for i=1, 2, 1 do
- modem.send(clientAddress, port, "whois " .. client);
- _, _, from, _, _, message, name = event.pull(2, "modem_message", nil, clientAddress, nil, nil, "I AM!!!");
- if message == "I AM!!!" then break; end
- end
- if message == "I AM!!!" then print("Client appears to already be awake...creating handler.");
- else
- print("Client appears to be asleep...waking up.");
- modem.send(clientAddress, port, "Wake Up " .. client);
- os.sleep(1);
- for i=1, 3, 1 do
- modem.send(clientAddress, port, "whois " .. client);
- _, _, from, _, _, message, name = event.pull(2, "modem_message", nil, clientAddress, nil, nil, "I AM!!!");
- if message == "I AM!!!" then break; end
- end
- if message == "I AM!!!" then
- print("Client has started up...creating handler.");
- else print("Failed to start up " .. client);
- end
- end
- if message == "I AM!!!" then
- createHandler(client);
- end
- end
- end
- function colorText(gpuName, x, y, text, color)
- gpus[gpuName].setForeground(color)
- gpus[gpuName].set(x, y, text)
- gpus[gpuName].setForeground(0xFFFFFF)
- end
- function displayStats(serverName, connectionStatus, turbineStatus, energyOutput, energyBuffer, mainPowerConnection, fuelLoaded, breakerStatus, checkCloche);
- gpus[serverName].set(2, 1, "----------------------------");
- gpus[serverName].set(2, 2, serverName .. ":");
- gpus[serverName].set(2, 3, "----------------------------");
- gpus[serverName].set(2, 5, "Connection Status: ");
- gpus[serverName].set(2, 6, "Turbine Status: ");
- gpus[serverName].set(2, 7, "Main Power Status: ");
- gpus[serverName].set(2, 8, "Energy Output: ");
- gpus[serverName].set(2, 9, "Energy Buffer: ");
- gpus[serverName].set(2, 10, "Fuel Loaded: ");
- gpus[serverName].set(2, 11, "Breaker Status: ");
- gpus[serverName].set(2, 12, "Cloche Checking: ");
- if turbineStatus == "Online" then
- colorText(serverName, string.len(serverName) + 4, 2, "Running" .. " ", 0x00FF00);
- else
- colorText(serverName, string.len(serverName) + 4, 2, "Stopped" .. " ", 0xFF0000);
- end
- if connectionStatus == "Disconnected" then
- colorText(serverName, 21, 5, connectionStatus .. " ", 0xFF0000);
- elseif connectionStatus == "Starting" or connectionStatus == "Stopping" then
- colorText(serverName, 21, 5, connectionStatus .. " ", 0xFFFF00);
- else
- colorText(serverName, 21, 5, connectionStatus .. " ", 0x00FF00);
- end
- if turbineStatus == "Offline" then
- colorText(serverName, 18, 6, turbineStatus .. " ", 0xFF0000);
- else
- colorText(serverName, 18, 6, turbineStatus .. " ", 0x00FF00);
- end
- if mainPowerConnection == "Disconnected" then
- colorText(serverName, 21, 7, mainPowerConnection .. " ", 0xFF0000);
- else
- colorText(serverName, 21, 7, mainPowerConnection .. " ", 0x00FF00);
- end
- if energyOutput == 0 then
- colorText(serverName, 17, 8, tostring(math.floor(energyOutput)) .. " ", 0xFF0000);
- else
- colorText(serverName, 17, 8, tostring(math.floor(energyOutput)) .. " ", 0x00FF00);
- end
- if energyBuffer > 4000000 then
- colorText(serverName, 17, 9, tostring(math.floor(energyBuffer)) .. " ", 0x00FF00);
- else
- colorText(serverName, 17, 9, tostring(math.floor(energyBuffer)) .. " ", 0xFF0000);
- end
- if fuelLoaded < 400000 then
- colorText(serverName, 15, 10, tostring(math.floor(fuelLoaded)) .. " ", 0xFF0000);
- else
- colorText(serverName, 15, 10, tostring(math.floor(fuelLoaded)) .. " ", 0x00FF00);
- end
- if breakerStatus == "Connected" then
- colorText(serverName, 18, 11, breakerStatus .. " ", 0xFF0000);
- else
- colorText(serverName, 18, 11, breakerStatus .. " ", 0x00FF00);
- end
- if checkCloche == false then
- colorText(serverName, 19, 12, tostring(checkCloche) .. " ", 0xFFFF00);
- else
- colorText(serverName, 19, 12, tostring(checkCloche) .. " ", 0x00FF00);
- end
- end
- --displayStats(client, tempServerData["connectionStatus"], tempServerData["turbineStatus"], tempServerData["energyOutput"], tempServerData["energyBuffer"], tempServerData["mainPowerConnection"], tempServerData["fuelLoaded"], tempServerData["breakerStatus"], tempServerData["checkCloche"])
- function printClientData(client)
- gpus[client] = component.proxy(servers[client]["gpuAddress"]);
- gpus[client].bind(servers[client]["screenAddress"])
- gpus[client].setResolution(34, 17);
- gpus[client].fill(0, 0, 34, 17, " ");
- while stayConnected[servers[client]["address"]] do
- os.sleep(1);
- tempServerData = serverData[servers[client]["address"]];
- displayStats(client, tempServerData["connectionStatus"], tempServerData["turbineStatus"], tempServerData["energyOutput"], tempServerData["energyBuffer"], tempServerData["mainPowerConnection"], tempServerData["fuelLoaded"], tempServerData["breakerStatus"], tempServerData["checkCloche"])
- end
- end
- function killHandler(handler);
- local handlerServer = servers[handler]["address"]
- local handlerThread = handlerThreads[handler];
- if handlerThread == nil then
- print("Error: Handler Address Not Found for " .. handler);
- else
- stayConnected[handlerServer] = false;
- while handlerThreads[handler]:status() ~= "dead" do
- os.sleep(1);
- end
- gpus[handler].fill(0, 0, 34, 17, " ");
- handlerThreads[handler] = nil;
- serverData[handlerServer] = nil;
- return true;
- end
- end
- function shutdown(target, verify)
- if verify == nil then verify = true; end
- local targetAddress = servers[target]["address"];
- local tempServerData = serverData[targetAddress];
- local verifyOutput = true;
- if verify then
- print("Are you sure you would like to fully shut down " .. target .. "? [y/n]");
- local verifyOutput = io.read();
- if verifyOutput == "y" then verifyOutput = true;
- else verifyOutput = false;
- end
- end
- if verifyOutput then
- print("Beginning Shutdown on " .. target);
- if tempServerData["turbineStatus"] == "Online" then
- print("Power Status of this Section Appears to be online...attempting to stop operations.");
- stopSystem(target);
- os.sleep(1);
- while tempServerData["connectionStatus"] == "Stopping" do
- os.sleep(1);
- end
- print("System Successfully Stopped!")
- end
- print("Disconnecting from Client");
- killHandler(target);
- print("Successfully Disconnected");
- print("Attempting To Shutdown Client");
- modem.send(targetAddress, port, "shutdown");
- local _, _, _, _, _, msg = event.pull(10, "modem_message", nil, targetAddress, nil, nil, "shutting down");
- if msg == nil then print("Shutdown Attempt Failed...");
- else print("Successfully Shutdown System!");
- end
- else
- print("Aborting Shutdown...")
- end
- end
- print("Server Starting Up...Loading Files");
- if not filesystem.exists("screen.dat") then
- print("No Primary Graphics card found on file.");
- print("Please print the GPU you want your console to write on.");
- local gpuTEMP, screenTEMP;
- while true do
- gpuTEMP = io.read();
- if component.get(gpuTEMP, "gpu") == nil then
- print("GPU Not Found");
- else
- break;
- end
- end
- print("Please Set the Screen you would like your console to be on");
- while true do
- screenTEMP = io.read();
- if component.get(screenTEMP, "screen") == nil then
- print("Screen Not Found");
- else
- break;
- end
- end
- local screenFile = io.open("screen.dat", "w");
- screenFile:write(component.get(screenTEMP, "screen"));
- screenFile:close();
- local gpuFile = io.open("gpu.dat", "w");
- gpuFile:write(component.get(gpuTEMP, "gpu"));
- gpuFile:close();
- consoleGpu = component.proxy(component.get(gpuTEMP, "gpu"));
- consoleScreen = component.proxy(component.get(screenTEMP, "screen"));
- else
- local screenFile = io.open("screen.dat", "r");
- consoleScreen = component.proxy(screenFile:read());
- screenFile:close();
- local gpuFile = io.open("gpu.dat", "r");
- consoleGpu = component.proxy(gpuFile:read());
- gpuFile:close();
- end
- term.bind(consoleGpu);
- consoleGpu.bind(consoleScreen.address);
- if filesystem.exists("servers.dat") then
- local serversFile = io.open("servers.dat", "r");
- local serversSer = serversFile:read();
- servers = serialization.unserialize(serversSer);
- for i in pairs(servers) do
- wakeUpClient(i);
- end
- print("================================");
- end
- print("Server Started Up");
- local apiThread = thread.create(API);
- while run do
- io.write("> ");
- local input = io.read();
- executeCmd(input);
- end
- apiThread:kill();
- print("Shutting Down Client");
- for i in pairs(servers) do
- if serverData[servers[i]["address"]] ~= nil then
- print("Killing Connection to " .. i);
- killHandler(i);
- print("Telling " .. i .. " to handle itself in my absense");
- modem.send(servers[i]["address"], port, "startClocheCheck");
- end
- end
- print("Goodbye :(");
- os.sleep(5);
- computer.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement