Advertisement
Kodos

Server Rack Stuff

Oct 19th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local event = require("event")
  3. local os = require("os")
  4.  
  5. local ol = component.openlight
  6. local cb = component.chat_box
  7. local door = component.os_door
  8. local char_space = string.byte(" ")
  9. local running = true
  10. local char_pause = string.byte("p")
  11.  
  12. cb.setName("Dave")
  13.  
  14. function unknownEvent()
  15. end
  16.  
  17. local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end })
  18.  
  19. function myEventHandlers.key_up(adress, char, code, playerName)
  20.   if (char == char_space) then
  21.   running = false
  22.   --[[elseif (char == char_pause) then
  23.   cardMenu()
  24.   doChoice()  ]]--
  25.   end
  26.   end
  27.  
  28. local function openDoor()
  29.   door.toggle()
  30.   os.sleep(5)
  31.   door.toggle()
  32.   return
  33. end
  34.  
  35. local function cardMenu()
  36. term.clear()
  37. term.setCursor(1,1)
  38. print("Do you wish to add or remove a UUID? (A/r)")
  39. choice = io.read()
  40. if choice and (choice == "" or choice:sub(1,1):lower() == "a") then
  41. choice = "a" -- I have no idea where I was going with this
  42. else choice = "r"
  43. end
  44. return choice
  45. end
  46.  
  47. local messages = {
  48.  
  49.   ["lights"] = {
  50.     --Syntax: ["keyword"] = {function, all, other, arguments}
  51.     ["on"] = {},
  52.     ["off"] = {}
  53.   },
  54.  
  55.  ["door"] = {
  56.     ["open"] = {openDoor}
  57.   },
  58.  
  59.  ["lamp"] = {
  60.     ["on"] = {ol.setColor, 0x00FF00},
  61.     ["off"] = {ol.setColor, 0xFF0000}
  62.   },
  63.  
  64.   ["core"] = {
  65.     ["current"] = {cb.say, "Herpderp"},
  66.     ["max"] = {cb.say, "Herpderp"}
  67.   },
  68.  
  69.   ["reactor"] = {
  70.   ["fuel"] = {}
  71.   },
  72.  
  73.   ["awesome"] = {
  74.     ["you're"] = {cb.say, "No, you're awesome."}
  75.   }
  76.  
  77. }
  78.  
  79. local function getFunction(tbl, msg)
  80.   if tbl[1] then
  81.     return tbl
  82.   end
  83.   for i,j in pairs(tbl) do
  84.     if type(i) == "string" then
  85.       -- print(i)
  86.       if msg:find(i) and type(j) == "table" then
  87.         return getFunction(j, msg)
  88.       end
  89.     end
  90.   end
  91. end
  92.  
  93. local function parseMessage(msg)
  94.   local fnc = getFunction(messages, msg)
  95.   if not fnc then return false, "no command found" end
  96.   return pcall(table.unpack(fnc))
  97. end
  98.  
  99. function myEventHandlers.chat_message(adr,playerName,message)
  100. if message:find("^%Dave, .+") then
  101. local result, response = parseMessage(message:lower())
  102. end
  103. end
  104.  
  105.  
  106. local function doChoice()
  107. end
  108.  
  109. local function authorized()
  110.   local env = {}
  111.   local config = loadfile("/etc/auth.dat", nil, env)
  112.   if config then
  113.     pcall(config)
  114.   end
  115.   return env.authorized
  116. end
  117.  
  118. local authorized = authorized() -- This one?
  119.  
  120. function myEventHandlers.magData(addr, playerName, data, UUID, locked)
  121. for i = 1,#authorized do
  122. print("Checking index #" .. i .. " for a match against: " .. UUID)
  123. if UUID == authorized[i] then
  124. print("Door opening for " .. playerName .. ".")
  125. openDoor()
  126. break
  127. elseif UUID ~= authorized[i] then
  128. print("Unauthorized Access attempt from " .. playerName .. "!")
  129. end
  130. end
  131. end
  132.  
  133. function handleEvent(eventID, ...)
  134.   if (eventID) then -- can be nil if no event was pulled for some time
  135.     myEventHandlers[eventID](...) -- call the appropriate event handler with all remaining arguments
  136.   end
  137. end
  138.  
  139. --[[function myEventHandlers.chat_message(addr,playerName,msg)
  140. if playerName == "Kodos" and msg == "Open sesame" then
  141. openDoor()
  142. end
  143. end ]]--
  144.  
  145. while running do
  146. handleEvent(event.pull())
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement