Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- globsl vars
- local info = {}
- local pcinfo = "serverinfo"
- local commands="commands"
- local defstate="states"
- local msgs = {}
- local mside=nil
- local id=nil
- local channel = nil
- local channelcheck=nil
- local pastebin = nil
- local modem = nil
- local color_green=0x66FF00
- local color_red=0xFF0800
- local bridge=peripheral.wrap("left")
- local hud=bridge.addText(1,80,"off",color_red)
- local function setstr(file,input) --writes to file from a var
- local f=fs.open(file,"a")
- f.writeLine(input)
- f.close()
- end
- local function mkfile(file) --creates a new file, deletes original first
- shell.run("delete "..file)
- local f=fs.open(file,"w")
- f.close()
- end
- function linecount(filename) --counts number of lines in a file and returns length
- f = fs.open(filename, "r")
- local length = 0
- while true do
- local line = f.readLine()
- if not line then break end
- end
- f.close()
- return length
- end
- local function getvars(file) --// Localize the function too, define it before we use it in 'startup' function
- local f = fs.open(file,"r")
- for i = 1,linecount(commands) do
- info[i] = f.readLine()
- end
- f.close()
- end
- local function conf()
- mkfile(pcinfo)
- print("insert name for this server pc")
- id = read()
- setstr(pcinfo,id)
- shell.run("label set "..id)
- print("input modem side, must be valid")
- mside = read()
- setstr(pcinfo,mside)
- print("What channel no. will this server be using?")
- channel = read()
- setstr(pcinfo,channel)
- print("please input pastebin command that will be sent to new client pcs")
- pastebin=read()
- setstr(pcinfo,pastebin)
- mkfile("config")
- print("config complete, rebooting in...")
- for i = 3,0,-1 do
- if i == 0 then
- shell.run("reboot")
- end
- print(tostring(i).."...")
- sleep(1)
- end
- end
- local function startup ()-- catches info from output
- getvars(pcinfo) -- sets all the variables needed from config
- id=info[1]
- mside=info[2]
- channel=tonumber(info[3])
- channelcheck= info[3]
- pastebin=info[4]
- getvars(commands) --gets all the commands for the server to display on Terminal Glasses
- for i = 1,linecount(commands) do
- msgs[i] = info[i]
- end
- end
- if not fs.exists("config") then
- conf()
- else
- startup()
- end
- function new_command(cmd)
- if not fs.exists(commands) then
- mkfile(commands)
- else
- setstr(commands,cmd)
- end
- end
- modem=peripheral.wrap(mside)
- modem.open(channel)--opens a channel on the predefined channel
- print("server:"..id..":ACTIVE")
- print("channel assigned:"..channelcheck)
- while true do
- local event= {os.pullEvent()}
- if event[5] == channelcheck then
- modem.transmit(channel,channel,channelcheck)
- print(chsnnelcheck)
- end
- if event[5] ~= "" then
- modem.transmit(channel,channel,message)
- end
- if event[5] == "New Command" then
- os.startTimer(1)
- local msgr = {os.pullEvent()}
- if msgr[5]~="" then
- setstr(commands,msgr[5])
- modem.transmit(channel,channel,"done")
- elseif msgr[1]=="timer" then
- error("Oops, Command failed to register")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment