function hasValue(tab,val,keySearch) for k,v in pairs(tab) do if keySearch then if k == val then return true end else if v == val then return true end end end end function split(s, delimiter) result = {} for match in (s..delimiter):gmatch("(.-)"..delimiter) do table.insert(result, match) end return result end function showValidCommands() s = "" for _,_command in pairs(validCommands) do s = s .. _command .. "," end return s end function config(action) if action == "load" then if fs.exists("chatConfig.json") then file = fs.open("chatConfig.json","r") _data = textutils.unserialize(file.readAll()) print(_data) owners = _data.owners or {"YourNameHere"} file.close() else owners = {"YourNameHere"} config("save") end elseif action == "save" then _data = {} _data.owners = owners file = fs.open("chatConfig.json","w") file.write(textutils.serialize(_data)) file.close() end end owners = {} config("load") requesterListFull = {"Alchemist", "Archer in Training", "Baker", "Beekeeper", "Blacksmith", "Builder", "Carpenter", "Chicken Farmer", "Composter", "Concrete Mixer", "Cook", "Assistant Cook", "Courier", "Cowhand", "Crusher", "Dyer", "Enchanter", "Farmer", "Fisher", "Fletcher", "Flourist", "Forester", "Glassblower", "Doctor", "Knight", "Archer", "Druid", "Knight in Training", "Library Student", "Mechanic", "Miner", "Planter", "Pupil", "Rabbit Herder", "Carpenter", "Student", "Shepherd", "Sifter", "Smelter", "Stonemason", "Stone Smelter", "Swineherd", "Teacher", "Undertaker", "Researcher", "Quarrier", "Request System"} validCommands = { "add", "rm", "list", "jobs", "output", --"view", "restart", "arShowAll", "doRequests", "update", "help"} validMainCommand = {"$rq", "rq", "requestmanager", "$requestmanager"} chat = peripheral.find("chatBox") while true do event, player, msg = os.pullEvent("chat") print(player) --Check owners list if hasValue(owners,player) then passes = true inputs = split(msg, " ") --check if its a command for this program if hasValue(validMainCommand,inputs[1]) then print("found command") command = inputs[2] --check if it has a proper sub command if command == "whoisoutthere" then chat.sendMessage("Colony Owner - " .. owners[1], "Request Manager") passes = false end if command == nil or hasValue(validCommands,command) ~= true or command == "help" then chat.sendMessageToPlayer(tostring(command) .. " is not a valid command. Valid Commands are: " .. showValidCommands(),player) passes = false end if command == "restart" then chat.sendMessageToPlayer("Restarting the Computer",player) os.reboot() end if command == "update" then chat.sendMessageToPlayer("Updating, then Restarting the Computer",player) os.run({},"update.lua") --os.reboot() -- if fs.exists("chatListener.lua") then fs.delete("chatListener.lua") end -- if fs.exists("colonyInfo.lua") then fs.delete("colonyInfo.lua") end -- if fs.exists("requestManager.lua") then fs.delete("requestManager.lua") end -- if fs.exists("monitorManager.lua") then fs.delete("monitorManager.lua") end -- shell.run("pastebin get Taa1i9Tn chatListener.lua") -- shell.run("pastebin get wVz0Kg0N colonyInfo.lua") -- shell.run("pastebin get rSDtwYBe requestManager.lua") -- shell.run("pastebin get bVQbY1qL monitorManager.lua") -- if not fs.exists("startup.lua") then -- file = fs.open("startup.lua", "w"); -- file.write("shell.execute('requestManager.lua')") -- file.close() -- end -- os.reboot() end -- extract job from the arguments arg = inputs[3] or "" job = "" if command == "add" or command == "rm" then for i=3, #inputs, 1 do job = job .. inputs[i] if i ~= #inputs then job = job .. " " end end -- check if job name if valid if hasValue(requesterListFull,job) ~= true then -- check if its already on the list. jobList = "" for i=1,#requesterListFull do jobList = jobList .. requesterListFull[i] .. ", " end chat.sendMessageToPlayer(job .. " is not a valid job. Valid Jobs are: " .. jobList,player) passes = false else arg = job end elseif command == "output" then if #inputs < 6 then chat.sendMessageToPlayer("Command Usage: rq output inventory x y z Example: rq output minecraft:chest_1 20 65 -10",player) passes = false else arg = textutils.serialize({{x=inputs[4],y=inputs[5],z=inputs[6]},inputs[3]}) end else arg = inputs[3] end -- pass on command to requestManager to handle. if passes then print("Sending request " .. command .. " " .. tostring(arg) .. " for " .. player) os.queueEvent("request",command, arg, player, subArg) -- start a timer and wait for a responce back myTimer = os.startTimer(0.5) while true do event,k1 = os.pullEvent() --resend event/timer if timed out if event == "timer" and k1 == myTimer then os.queueEvent("request",command, arg, player, subArg) myTimer = os.startTimer(0.5) --print("sending re-request") end --break out of confirm loop on proper confirmation if event == "confirm" then print("Transaction Complete") break end end end end end end