Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("left")
- function EditDestinations()
- while true do
- local lsDestinations
- if fs.exists("destinations.ls") then
- --Load the existing destinations
- local file = fs.open("destinations.ls","r")
- local data = file.readAll()
- file.close()
- lsDestinations = textutils.unserialize(data)
- else
- lsDestinations = {}
- end
- --Display existing destinations
- print("\n")
- if #lsDestinations == 0 then
- print("No destinations exist\n")
- else
- for i=1,#lsDestinations do
- print(tostring(i)..". "..lsDestinations[i]["Display"])
- end
- end
- --Display option
- print("(a. Add)")
- --Receive input
- write("Your selection: ")
- local selection = read()
- --Decode selection
- if selection == "a" then
- write("\n\nEnter display name: ")
- local sName = read()
- write("Enter ticket: ")
- local sTicket = read()
- --Box this up
- local destination = {}
- destination["Display"] = sName
- destination["Ticket"] = sTicket
- --Add to the list
- table.insert(lsDestinations, destination)
- else
- local iSelection = tonumber(selection)
- if iSelection ~= null then
- if (iSelection <= #lsDestinations) then
- print("\n\nDisplay: " .. lsDestinations[iSelection]["Display"])
- print("Ticket: " .. lsDestinations[iSelection]["Ticket"])
- --Give options
- print("(d. Delete)")
- print("(e. Edit Display Name)")
- print("(t. Edit Ticket)")
- write("Your selection: ")
- selection = read()
- --Decode selection
- if selection == "d" then
- table.remove(lsDestinations,iSelection)
- elseif selection == "e" then
- write("New Display: ")
- local newName = read()
- lsDestinations[iSelection]["Display"] = newName
- elseif selection == "t" then
- write("New Ticket: ")
- local newTicket = read()
- lsDestinations[iSelection]["Ticket"] = newTicket
- else
- print("\nInvalid selection")
- end
- end
- else
- print("\nInvalid selection")
- end
- end
- --Save any edits to the list
- file = fs.open("destinations.ls","w")
- file.write(textutils.serialize(lsDestinations))
- file.close()
- end
- end
- function ServeTickets()
- while true do
- local event,side,freq,refreq,message = os.pullEvent("modem_message")
- if (message == "List") then
- --Load the list
- local data
- if fs.exists("destinations.ls") then
- local file = fs.open("destinations.ls","r")
- data = file.readAll()
- file.close()
- else
- local lsEmpty = {}
- data = textutils.serialize(lsEmpty)
- end
- --Send the list back on refreq
- modem.transmit(refreq,refreq,data)
- end
- end
- end
- --Start the server
- print("Starting server...")
- modem.open(10)
- print("Server listening on frequency 10.\n\n")
- --Run EditDestinations and ServeTickets in parallel
- parallel.waitForAll(EditDestinations,ServeTickets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement