Advertisement
theoriginalbit

CCPresenter (Client)

Mar 23rd, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. --[[
  2. CCPresenter by TheOriginalBIT
  3. Version 1.0
  4. First Created: 22 March 2013
  5. Last Updated: 22 March 2013
  6.  
  7. Inspired by, and continuation of: http://www.computercraft.info/forums2/index.php?/topic/11003-remote-presentation/
  8. ]]--
  9.  
  10. local version = '1.0'
  11. local h = fs.open('ccpresenter_log', 'a')
  12.  
  13. if #{...} > 0 then
  14.   printError('this program does not support runtime arguments')
  15.   return
  16. end
  17.  
  18. local nonVerboseError = function(msg) printError(msg) error() end -- error without line numbers and stuff
  19. local findPeripheral = function( t ) for _,s in pairs(rs.getSides()) do if peripheral.getType(s) == t then return s end end nonVerboseError('No '..t..' attached to the computer') end
  20. local split = function(str, pat) local t = {} for s in str:gmatch('[^:]+') do table.insert(t, s) end return t end
  21. local log = function(msg) if h then h.write(msg..'\n') h.flush() end end
  22.  
  23. local modemSide = findPeripheral( 'modem' )
  24. rednet.open(modemSide)
  25.  
  26. local function readPacket(method)
  27.   method = textutils.unserialize(method)
  28.  
  29.   if term[ method._m ]  then
  30.     -- protect the call, since changing colours will error on a non-advanced or pre-CC1.4 computer
  31.     pcall( term[ method._m ], unpack( method._a ) )
  32.   else
  33.     log('received invalid command | $_day '..os.day()..' | $_time '..os.time()..' | $_clock '..os.clock()..' | $_cmd '..tostring(method))
  34.   end
  35. end
  36.  
  37. term.clear()
  38. term.setCursorPos(1,1)
  39. log('========================================================= Day: '..os.day()..' Time: '..textutils.formatTime(os.time(), true)..' =========================================================')
  40.  
  41. while true do
  42.   local e = { os.pullEventRaw() }
  43.   if e[1] == 'rednet_message' then
  44.     if e[3] == 'service_closed' then
  45.       print('Service disconnected...')
  46.       sleep(1)
  47.       term.clear()
  48.       term.setCursorPos(1,1)
  49.       break
  50.     else
  51.       readPacket( e[3] )
  52.     end
  53.   elseif e[1] == 'terminate' then
  54.     log('===== END SESSION LOG =====')
  55.     break
  56.   end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement