dummyyyybOI

eee

Feb 20th, 2023
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. print(fs.exists("/cc-websocket-config.txt"))
  2. local uri = "ws://localhost:3000"
  3. print(uri)
  4. ws = http.websocket(uri)
  5. if(type(ws) == "boolean") then
  6. error("Failed to connect to websocket")
  7. end
  8. print(type(ws))
  9. while true do
  10. local event = os.pullEventRaw("terminate")
  11. if event == "terminate" and type(ws) == "table" then
  12. ws.close()
  13. error("Terminated...")
  14. end
  15. print(os.pullEventRaw())
  16. if(type(ws) == "table") then
  17. local msg = ws.receive()
  18. print(msg)
  19. local msgObj = {}
  20. local urlstartIndex, urlendIndex = string.find(msg, '"url":"')
  21. local url = string.sub(msg, urlendIndex + 1, string.find(msg, '"', urlendIndex + 1) - 1)
  22. local datastartIndex, dataendIndex = string.find(msg, '"data":"')
  23. local data = string.sub(msg, dataendIndex + 1, string.find(msg, '"', dataendIndex + 1) - 1)
  24. local typestartIndex, typeendIndex = string.find(msg, '"type":"')
  25. local type = string.sub(msg, typeendIndex + 1, string.find(msg, '"', typeendIndex + 1) - 1)
  26. print(url.." "..data.." "..type)
  27.  
  28. if type == "delete" then
  29. shell.run("delete " .. tostring(url))
  30. print("Deleted "..url)
  31. end
  32.  
  33. if type == "create" then
  34. shell.run("create " .. tostring(url))
  35. fs.open( url, "w"):write( data)
  36. print("Created "..url)
  37. end
  38.  
  39. if type == "change" then
  40. fs.open( url, "w").write( data)
  41. print("Updated "..url)
  42. end
  43. else
  44. print("Websocket is not started.")
  45. end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment