Advertisement
FoxWorn3365

Gaugle - Chat

Nov 7th, 2021 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function giremu(inputstr, sep)
  2. if sep == nil then
  3. sep = "%s"
  4. end
  5. local t={}
  6. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  7. table.insert(t, str)
  8. end
  9. return t
  10. end
  11.  
  12. local modem = peripheral.wrap("top")
  13. -- Aspetto la richiesta
  14. while true do
  15. modem.setListening(70, true)
  16. local event, lato, sender, canale, msg = os.pullEvent("lan_message")
  17.  
  18. print("Richiesta da: 144.91.97."..sender.."\nContenuto: "..msg)
  19. if msg == "server.chat.gaugle.com" then
  20. modem.sendChannel(80, "Pong!")
  21. elseif string.find(msg, "server.chat.gaugle.com/register") ~= nil then
  22. sus = giremu(msg, "$")
  23. if fs.exists("u/"..sus[2]) == true then
  24. modem.sendChannel(70, "NO")
  25. else
  26. local h = fs.open("u/"..sus[2], "w")
  27. h.write(sus[3])
  28. h.flush()
  29. h.close()
  30. modem.sendChannel(70, "SI")
  31. end
  32. elseif string.find(msg, "server.chat.gaugle.com/checkUsername") ~= nil then
  33. sua = giremu(msg, "$")
  34. if fs.exists("u/"..sua[2]) == true then
  35. modem.sendChannel(70, "SI")
  36. else
  37. modem.sendChannel(70, "NO")
  38. end
  39. elseif string.find(msg, "server.chat.gaugle.com/login") ~= nil then
  40. sao = giremu(msg, "$")
  41. local h = fs.open("u/"..sao[2], "r")
  42. pass = h.readAll()
  43. if sao[3] ~= pass then
  44. modem.sendChannel(70, "NO")
  45. else
  46. modem.sendChannel(70, "SI")
  47. end
  48. elseif string.find(msg, "server.chat.gaugle.com/get") ~= nil then
  49. sen = giremu(msg, "$")
  50. if fs.exists("c/"..sen[2]) == false then
  51. local h = fs.open("c/"..sen[2], "w")
  52. h.write("Chat iniziata!")
  53. h.flush()
  54. h.close()
  55. modem.sendChannel(70, "Ho appena creato la chat!")
  56. else
  57. local h = fs.open("c/"..sen[2], "r")
  58. chat = h.readAll()
  59. h.close()
  60. modem.sendChannel(70, chat)
  61. end
  62. elseif string.find(msg, "server.chat.gaugle.com/sendMessage") ~= nil then
  63. sar = giremu(msg, "$")
  64. local h = fs.open("c/"..sar[2], "w")
  65. h.writeLine(sar[3])
  66. h.flush()
  67. h.close()
  68. modem.sendChannel(70, "OK")
  69. end
  70. sleep(0.1)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement