streqicity

Untitled

Jan 26th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. local modem = peripheral.wrap("right")
  2. modem.open(999)
  3. modem.open(997)
  4. modem.open(995)
  5. while true do
  6. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  7. print("I just received a message on channel: "..senderChannel.."Respond on:"..replyChannel)
  8. print(message)
  9. if(senderChannel==999) then
  10. local file = fs.open("Locked.lua","r")
  11. local check = file.readLine()
  12. local isLocked =false;
  13. for line in file.readLine do
  14.  
  15. if(line==message.."") then
  16. isLocked=true;
  17. end
  18.  
  19. end
  20.  
  21. if(isLocked) then
  22. modem.transmit(998,997,"Locked")
  23. else
  24. modem.transmit(998,997,"Go")
  25. end
  26. file.close()
  27. elseif (senderChannel==997) then
  28. file = fs.open(message..".lua","r")
  29. modem.transmit(996,995,file.readAll())
  30. local lFile = fs.open("Locked.lua","a")
  31. lFile.write(message.."\n")
  32. lFile.close()
  33. elseif(senderChannel==995) then
  34. local fname = string.sub(message,1,1)
  35. local fcontents= string.sub(message,2,-1)
  36. file = fs.open(fname..".lua","w")
  37. file.write(fcontents)
  38. file.close()
  39.  
  40. local lFile = fs.open("Locked.lua","r")
  41. local temp = ""
  42. for line in lFile.readLine do
  43.  
  44. if(line==fname.."") then
  45. print("removed file lock:"..line)
  46. else
  47. temp=temp.."\n"+line
  48. end
  49.  
  50. end
  51.  
  52. lFile.close()
  53. lFile = fs.open("Locked.lua","w")
  54. lFile.write(temp)
  55. lFile.close()
  56.  
  57. modem.transmit(994,995,"Success")
  58. end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment