Advertisement
ecco7777

CC plethora functions

Jan 30th, 2022 (edited)
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. os.loadAPI("json")
  2. function wrapPs(peripheralName)
  3.     periTab = {}
  4.     sideTab = {}
  5.     if peripheralName == nil then
  6.         print("Fehler")
  7.     end
  8.     local peripherals = peripheral.getNames()
  9.     local i2 = 1
  10.     for i = 1, #peripherals do
  11.         if peripheral.getType(peripherals[i]) == peripheralName then
  12.             periTab[i2] = peripheral.wrap(peripherals[i])
  13.             sideTab[i2] = peripherals[i]
  14.             i2 = i2 + 1
  15.         end
  16.     end
  17.     if periTab ~= {} then
  18.         return periTab, sideTab
  19.     else
  20.         return nil
  21.     end
  22.  
  23.     function getPSide(peripheralName)
  24.         if peripheralName == nil then
  25.             print("Fehler")
  26.         end
  27.         local peripherals = peripheral.getNames()
  28.         local i = 1
  29.         while i < #peripherals and peripheral.getType(peripherals[i]) ~= peripheralName do
  30.             i = i + 1
  31.         end
  32.         if peripheral.getType(peripherals[i]) == peripheralName then
  33.             return peripherals[i]
  34.         else
  35.             return nil
  36.         end
  37.     end
  38. end
  39.  
  40. --define webserver
  41. os.loadAPI("connect")
  42.  
  43. --local ws,err = http.websocket("ws://"..connect.code..".ngrok.io")
  44. local ws,err = http.websocket("ws://"..connect.code)
  45.  
  46.  
  47. --wrap neural interface
  48. local ni=wrapPs("manipulator")
  49. if ni==nil then
  50. ni=wrapPs("neuralInterface")
  51. end
  52.  
  53. --functions
  54. function eval(command)
  55.     fp = fs.open("eval", "w")
  56.     fp.write(command)
  57.     fp.close()
  58.     shell.run("eval")
  59.     shell.run("rm eval")
  60. end
  61.  
  62. function sendStringToWS(txt)
  63.     ws.send(txt)
  64. end
  65.  
  66. function sendArrayToWS(txt)
  67.     ws.send(txt)
  68. end
  69.  
  70. function getID()
  71.     local cplabel=os.getComputerLabel()
  72.     if cplabel==nil then
  73.         cplabel=""
  74.     end
  75.     return cplabel..os.getComputerID()
  76. end
  77.  
  78. function sendIDToWS()
  79.     sendArraytoWS(json.encode({id=getID()}))
  80. end
  81.  
  82. function sendStringInPackets(txt)
  83.     maxPacket=100000
  84.     for i=1, math.floor(#txt/maxPacket)+1 do
  85.         sendStringToWS(string.sub((i-1)*maxPacket,i*maxPacket))
  86.     end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement