Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Turbine Client System
- --Version 0.1
- local component = require("component");
- local sides = require("sides");
- local thread = require("thread");
- local filesystem = require("filesystem");
- local gpu = component.gpu;
- local serialization = require("serialization");
- local event = require("event");
- local modem = component.modem;
- --variables
- local systemName;
- local redstone = {};
- local inventory = {};
- local serverAddress;
- local port = 60;
- modem.open(port);
- --Start Setup
- if not filesystem.exists("/home/systemName.dat") then
- print("No Current Name Found for System...")
- while true do
- print("Please Enter the System Name");
- io.write("> ");
- local tempName = io.read();
- io.write("\n");
- print("Are you sure you want System Name to be " .. tempName .. "? [y/n]");
- io.write("> ");
- local ans = io.read();
- io.write("\n");
- if ans == "y" then
- systemName = tempName;
- modem.setWakeMessage("Wake Up " .. systemName);
- local nameFile = io.open("systemName.dat", "w");
- nameFile:write(systemName);
- nameFile:close();
- break;
- end
- end
- else
- local nameFile = io.open("systemName.dat", "r");
- systemName = nameFile:read();
- nameFile:close();
- end
- local turbineStatus = "Offline";
- local fuelCreation1Status = "Offline";
- local fuelCreation2Status = "Offline";
- local mainPowerStatus = "Disconnected";
- local powerOutput = 232313123;
- local energyStored = 312312321;
- local fuelLoaded = 32312312321312;
- local connectionStatus = "Disconnected";
- local breakerStatus = "Disconnected";
- local checkCloche = true;
- function toggleTurbine(status)
- if status == true then
- turbineStatus = "Online"
- else
- turbineStatus = "Offline"
- end
- end
- function togglePotatoCloche1(status)
- if status == true then
- potatoChloche1Status = "Online"
- else
- potatoCloche1Address.setOutput(sides.left, 15)
- togglePotatoCloche1 = "Offline"
- end
- end
- function togglePotatoCloche2(status)
- if status == true then
- potatoChloche1Status = "Online"
- else
- togglePotatoCloche2 = "Offline"
- end
- end
- function togglehempCloche1(status)
- if status == true then
- hempChloche1Status = "Online"
- else
- togglehempCloche1 = "Offline"
- end
- end
- function togglehempCloche2(status)
- if status == true then
- hempChloche1Status = "Online"
- else
- togglehempCloche2 = "Offline"
- end
- end
- function toggleFuelCreation1(status)
- if status == true then
- toggleFuelCreation1 = "Online"
- else
- toggleFuelCreation1 = "Offline"
- end
- end
- function toggleFuelCreation2(status)
- if status == true then
- toggleFuelCreation2 = "Online"
- else
- toggleFuelCreation2 = "Offline"
- end
- end
- function toggleBreaker(status)
- if status == true then
- breakerStatus = "Connected"
- else
- toggleBreaker = "Disonnected"
- end
- end
- function toggleMainPower(status)
- if status == true then
- mainPowerStatus = "Connected"
- else
- toggleMainPower = "Disonnected"
- end
- end
- function checkFuel(inv, side)
- return false;
- end
- function serverUpdater()
- local timeout = 6;
- run = true;
- while true do
- local _, _, serverAddress, _, _, input = event.pull(10, "modem_message", nil, nil, nil, nil, "getInfo");
- if input == nil then
- if timeout == 0 then
- connectionStatus = "Disconnected";
- timeout = 6;
- else
- timeout = timeout - 1;
- end
- else
- modem.send(serverAddress, port, "info", turbineStatus, powerOutput, energyStored, mainPowerStatus, fuelLoaded, breakerStatus, checkCloche);
- connectionStatus = "Connected";
- end
- end
- end
- function serverHandler()
- while true do
- local _, _, serverAddress, _, _, msg1, msg2, msg3 = event.pull(10, "modem_message", nil);
- if msg1 == "cmd" then
- modem.send(serverAddress, port, "recieved");
- local cmdOut = executeCmd(msg2);
- os.sleep(1);
- modem.send(serverAddress, port, "report", cmdOut);
- elseif msg1 == "whois " .. systemName then
- modem.send(serverAddress, port, "I AM!!!", systemName);
- elseif msg1 == "getData" then
- modem.send(serverAddress, port, "heres data", getData(msg2));
- end
- end
- end
- function updateScreen()
- gpu.set(1, 1, "==================================");
- gpu.set(1, 2, "Turbine Control System [Ver 0.1]");
- gpu.set(1, 3, "By Yogi And Shaggy");
- gpu.set(1, 4, "==================================");
- gpu.set(1, 6, "System Name: ");
- gpu.set(1, 7, "Server Connection: ");
- gpu.set(1, 8, "Turbine Status: ");
- gpu.set(1, 9, "Fuel Creation 1: ");
- gpu.set(1, 10, "Fuel Creation 2: ");
- gpu.set(1, 11, "Breaker Status: ")
- gpu.set(1, 12, "Main Power: ");
- gpu.set(1, 13, "Power Output: ");
- gpu.set(1, 14, "Energy Stored: ");
- gpu.set(1, 15, "Biodiesel Stored: ");
- gpu.set(1, 17, "==================================");
- while true do
- os.sleep(1)
- gpu.set(14, 6, systemName .. " ");
- gpu.set(20, 7, connectionStatus .. " " );
- gpu.set(17, 8, turbineStatus .. " ");
- gpu.set(19, 9, fuelCreation1Status .. " ");
- gpu.set(19, 10, fuelCreation2Status .. " ");
- gpu.set(17, 11, breakerStatus .. " ");
- gpu.set(12, 12, mainPowerStatus .. " ");
- gpu.set(15, 13, tostring(math.floor(powerOutput)) .. " ");
- gpu.set(16, 14, tostring(math.floor(energyStored)) .. " ");
- gpu.set(19, 15, tostring(math.floor(fuelLoaded)) .. " ");
- end
- end
- function executeCmd(cmd)
- if cmd == "turnOnPotatoCloche1" then
- togglePotatoCloche1(true);
- return true
- elseif cmd == "turnOffPotatoCloche1" then
- togglePotatoCloche1(false);
- return true
- elseif cmd == "turnOnPotatoCloche2" then
- togglePotatoCloche2(true);
- return true
- elseif cnd == "turnOffPotatoCloche2" then
- togglePotatoCloche2(false);
- return true
- elseif cmd == "turnOnHempCloche1" then
- toggleHempCloche1(true);
- return true
- elseif cmd == "turnOffHempCloche1" then
- toggleHempCloche1(false);
- return true
- elseif cmd == "turnOnHempCloche2" then
- toggleHempCloche2(true);
- return true
- elseif cmd == "turnOffHempCloche2" then
- toggleHempCloche2(false);
- return true
- elseif cmd == "connectMainPower" then
- toggleMainPower(true);
- return true
- elseif cmd == "disconnectMainPower" then
- toggleMainPower(false);
- return true
- elseif cmd == "disableTurbine" then
- toggleTurbine(false);
- return true
- elseif cmd == "enableTurbine" then
- toggleTurbine(true)
- return true
- elseif cmd == "startSystems" then
- startSystems()
- return true
- elseif cmd == "stopSystems" then
- stopSystems()
- return true
- elseif cmd == "stopClocheCheck" then
- checkCloche = false;
- return true
- elseif cmd == "startClocheCheck" then
- checkCloche = true;
- return true
- else
- return false
- end
- end
- function startSystems()
- end
- function stopSystems()
- end
- function getData(data)
- if data == "potatoCloche1Status" then
- return potatoCloche1Status;
- elseif data == "potatoCloche2Status" then
- return potatoCloche2Status;
- elseif data == "hempCloche1Status" then
- return hempCloche1Status;
- elseif data == "hempCloche2Status" then
- return hempCloche2Status;
- elseif data == "mainPowerStatus" then
- return mainPowerStatus;
- elseif data == "turbineStatus" then
- return turbineStatus;
- elseif data == "breakerStatus" then
- return breakerStatus;
- elseif data == "fuelLoaded" then
- return fuelLoaded;
- elseif data == "powerOutput" then
- return powerOutput;
- elseif data == "energyStored" then
- return energyStored;
- elseif data == "checkCloche" then
- return checkCloches;
- else
- return "Variable Not Found";
- end
- end
- os.execute("clear");
- local handler = thread.create(serverHandler);
- local serverUpdateHandler = thread.create(serverUpdater);
- updateScreen();
- while true do
- os.sleep(1);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement