Advertisement
tupperkion

WirelessOS Client

Apr 7th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.  
  3. This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
  4.  
  5. ]]--
  6. sessionId = tostring(math.random(10000, 99999))
  7. rednet.broadcast(sessionId, "WirelessOS")
  8. cd = ""
  9. function string:split(query)
  10.     local result = {}
  11.     local sections = {1}
  12.     for i = 1, (#self - (#query - 1)) do
  13.         if self:sub(i, i + #query - 1) == query then
  14.             if (self:sub(sections[#sections], i - 1)) ~= query then
  15.                 result[#result + 1] = self:sub(sections[#sections], i - 1)
  16.             end
  17.             sections[#sections + 1] = sections[#sections] + #(self:sub(sections[#sections], i))
  18.         end
  19.     end
  20.     if sections[#sections] > #self then else
  21.         result[#result + 1] = self:sub(sections[#sections], #self)
  22.     end
  23.     if result == {} then
  24.         result[1] = self
  25.     end
  26.     return result
  27. end
  28. function run(program)
  29.     tArgs = program:split(" ")
  30.     if tArgs[1] == "cd" then
  31.         shell.setDir(tArgs[2])
  32.         cd = tArgs[2]
  33.     else
  34.         shell.run(unpack(tArgs))
  35.     end
  36. end
  37.  
  38. term.clear()
  39. term.setCursorPos(1, 1)
  40. print("ArtificialOS 1.0")
  41. while true do
  42.     write(cd.."> ")
  43.     prog = read()
  44.     rednet.broadcast(prog, sessionId)
  45.     if prog ~= "" then
  46.         if prog:split(" ")[1] == "exit" then
  47.             break
  48.         else
  49.             run(prog)
  50.         end
  51.     end
  52. end
  53. term.clear()
  54. term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement