Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setHost()
- modemState = rednet.isOpen(checkForModem_modem)
- if modemState == false or nil then
- setHost_fail = true
- else
- rednet.host(server1_protocol, server1_host)
- setHost_fail = false
- end
- end
- function peerCheck(peerCheck_protocol, peerCheck_host, peerCheck_var)
- local id = rednet.lookup(peerCheck_protocol, peerCheck_host)
- return id
- end
- function checkForModem()
- checkForModem_fail = false
- checkForModem_modem = "top"
- end
- function checkForCommand()
- local id, message, protocol = rednet.receive(protocolLv2, 10)
- if message == '' then return message, id
- else
- checkForCommand_attempts = checkForCommand_attempts + 1 --Waits a bit to check for a command again, prints number of attempts and the clock
- runningtime = os.clock()
- os.sleep(10)
- customMessage(nil, "Current computer runtime: "..runningtime)
- customMessage(nil, "Command check Attempts: "..checkForCommand_attempts)
- end
- end
- function customMessage(mode, message) --For fancy messages
- if aY == 19 then
- term.clear()
- term.setCursorPos(1, 1)
- end
- if mode == nil then mode = "Server" end
- aX, aY = term.getCursorPos()
- term.write("["..tostring(mode).."]: "..tostring(message))
- term.setCursorPos(1, aY+1)
- end
- function errorHandle() --Just to ennumarate the errors
- if setHost_fail == true then
- customMessage("Error", "The function setHost() failed.")
- errorCount = errorCount + 1
- end
- if checkForModem_fail == true then
- customMessage("Error", "The function checkForModem() failed.")
- errorCount = errorCount + 1
- end
- if furnaceChecker_fail == true then
- customMessage("Error", "Unable to find the computer furnaceChecker")
- errorCount = errorCount + 1
- end
- end
- --[[Action Functions]]--
- function action_ping()
- rednet.send(senderID, "pong!")
- end
- --[[Action Functions end]]--
- if setHost_fail or checkForModem_fail == true then
- startup_fail = true
- end
- function startup()
- -- protocol hierarchy list MUST BE TOP ROW IN EVERY startup() FUNCTION
- protocolLv1 = "alpha"
- protocolLv2 = "beta"
- protocolLv3 = "gamma"
- protocolLv4 = "delta"
- -- end
- -- local host settings
- server1_protocol = protocolLv1
- server1_host = "houseServer"
- -- end
- -- static hosts settings
- furnaceChecker = rednet.lookup(protocolLv3,"furnaceCheck")
- if furnaceChecker == nil then
- furnaceChecker_fail = true
- end
- -- end
- -- global variables
- errorCount = 0
- checkForCommand_attempts = 0
- -- end
- --peripherals
- monitor = peripheral.wrap("front")
- term.redirect(monitor)
- term.clear()
- term.setCursorPos(1,1)
- checkForModem()
- rednet.open(checkForModem_modem)
- -- end
- errorHandle()
- if errorCount == 1 then
- customMessage(nil, "Succesfully started with "..errorCount.." error.")
- elseif errorCount == 0 then
- customMessage(nil, "Succesfully started with no errors")
- elseif errorCount >= 2 then
- customMessage(nil, "Succesfully started with "..errorCount.." errors.")
- end
- end
- if startup_fail == true then errorCount = errorCount + 1
- else startup()
- end
- while true do --Main loop
- received_command, senderID = checkForCommand()
- if received_command == "ping" or "Ping" then
- action_ping()
- received_command = nil
- senderID = nil
- end
- end
- --DiegoG
- --Base server OS A.1.2.0
- --11/10/2016
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement