Advertisement
Tapeline

server

Oct 8th, 2021
137
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local m = component.modem
  3. local fs = require("filesystem")
  4. local event = require("event")
  5.  
  6.  
  7. conf = {}
  8.  
  9.  
  10. function loadcfg()
  11.   local f = fs.open("/home/qclient.conf", "r")
  12.   local fc = f:read(fs.size("/home/qclient.conf"))
  13.   conf = split(fc, ";")
  14. end
  15.  
  16.  
  17. function split(s, sep)
  18.   if sep == nil then
  19.     sep = "%s"
  20.   end
  21.   local t = {}
  22.   for str in string.gmatch(s, "([^".. sep .."]+)") do
  23.     table.insert(t, str)
  24.   end
  25.   return t
  26. end
  27.  
  28.  
  29. function getpage(p)
  30.   local f = fs.open("/home/QServer/mctpdocs/".. p, "r")
  31.   local fc = f:read(fs.size("/home/QServer/mctpdocs/".. p))
  32.   print(p)
  33.   return fc
  34. end
  35.  
  36.  
  37. function handlerequest(r)
  38.   mctp = split(r[4], "/")
  39.   print("(:)             " .. mctp[1] .. " " .. mctp[2])
  40.   if mctp[1] == "mctp" then
  41.     page = getpage(mctp[2])
  42.     m.send(conf[1], 1110, conf[2] ..";".. r[1] ..";DATA;".. page)
  43.   end
  44. end
  45.  
  46.  
  47. function listen(_, _, from, _, _, msg)
  48.   handlerequest(split(msg, ";"))
  49. end
  50.  
  51.  
  52. function stop()
  53.   event.ignore("modem_message", listen)
  54.   print("(:) Stopping...")
  55. end
  56.  
  57.  
  58. function start()
  59.   m.open(1110)
  60.   print("(:) Start...")
  61.   print("(:) Booted up!")
  62.   event.listen("modem_message", listen)
  63. end
  64.  
  65. loadcfg()
  66. start()
  67. event.pull("touch")
  68. stop()
Advertisement
RAW Paste Data Copied
Advertisement