Advertisement
harris4681

KrazDGServer

Oct 4th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.30 KB | None | 0 0
  1. -- DeadGlass Server, by Deadlock989
  2. -- August 2015
  3. -- Made for the Industrial Rage server, http://www.kbgmc.com/index.php?forums/
  4.  
  5. version = "1.01"
  6. debug = true
  7. knownprotocols = {"handshake","eout","estor","eoutspeed","aecells","eheat","tank","istor","sensor","fout","rcboiler"}
  8. groups = {
  9. ["batteries"]={"estor"},
  10. ["generators"]={"eout","eheat","fout","eoutspeed","rcboiler"},
  11. ["items"]={"aecells","istor"},
  12. ["liquids"]={"tank"},
  13. }
  14. colourlist = {"white", "lightgrey", "lightgray", "grey", "gray", "black", "red", "orange", "yellow", "green", "lime", "lightblue", "cyan", "blue", "purple", "magenta", "pink", "brown"}
  15. toggles = {}
  16. hbtime = 1
  17. hbcount = 0
  18. displaycheckcount = 30
  19. tickerttl = 30
  20. decaytime = 60
  21. playerlist = {}
  22. ticker = {}
  23. refreshticker = true
  24.  
  25. pcols = {
  26. ["eout"]={0xFFFF00,0xAA9900},
  27. ["eoutspeed"]={0x6666FF,0x0000AA},
  28. ["estor"]={0x33FF33,0x00AA00},
  29. ["eheat"]={0xFFAA33,0xAA6600},
  30. ["istor"]={0x990099,0x330033},
  31. }
  32. gap = 3
  33. x = gap
  34. firstgaugey = 16+gap*2
  35. y = firstgaugey
  36. mx = 100
  37. my = 16
  38. boxes = {}
  39. outlines = {}
  40. texts = {}
  41. gauges = {}
  42. icons = {}
  43. lastmessage = {}
  44. timestamp = {}
  45.  
  46. blockidms = {
  47. ["BigReactors-Reactor"]={"BigReactors:BRReactorPart",1},
  48. ["BigReactors-Turbine"]={"BigReactors:BRTurbinePart",1},
  49. ["batbox"]={"IC2:blockElectric",0},
  50. ["cesu"]={"IC2:blockElectric",7},
  51. ["mfe"]={"IC2:blockElectric",1},
  52. ["mfsu"]={"IC2:blockElectric",2},
  53. ["nuclear_reactor"]={"IC2:blockGenerator",5},
  54. ["reactor_fluid_port"]={"IC2:blockReactorFluidPort",0},
  55. ["tilechest"]={"appliedenergistics2:tile.BlockChest",0},
  56. ["tiledrive"]={"appliedenergistics2:tile.BlockDrive",0},
  57. ["blockenergycell"]={"appliedenergistics2:tile.BlockEnergyCell",0},
  58. ["blockdenseenergycell"]={"appliedenergistics2:tile.BlockDenseEnergyCell",0},
  59. ["tilecontroller"]={"appliedenergistics2:tile.BlockController",0},
  60. ["tile_thermalexpansion_cell_basic_name"]={"ThermalExpansion:Cell",1},
  61. ["tile_thermalexpansion_cell_hardened_name"]={"ThermalExpansion:Cell",2},
  62. ["tile_thermalexpansion_cell_redstone_name"]={"ThermalExpansion:Cell",3},
  63. ["tile_thermalexpansion_cell_resonant_name"]={"ThermalExpansion:Cell",4},
  64. ["tile_thermalexpansion_dynamo_steam_name"]={"ThermalExpansion:Dynamo",0},
  65. ["tile_thermalexpansion_dynamo_magmatic_name"]={"ThermalExpansion:Dynamo",1},
  66. ["tile_thermalexpansion_dynamo_compression_name"]={"ThermalExpansion:Dynamo",2},
  67. ["tile_thermalexpansion_dynamo_reactant_name"]={"ThermalExpansion:Dynamo",3},
  68. ["tile_thermalexpansion_dynamo_enervation_name"]={"ThermalExpansion:Dynamo",4},
  69. ["net_minecraft_src_buildcraft_factory_tiletank"]={"BuildCraft|Factory:tankBlock",0},
  70. ["tileentitycertustank"]={"extracells:certustank",0},
  71. ["openblocks_tank"]={"OpenBlocks:tank",0},
  72. ["rcirontankvalvetile"]={"Railcraft:machine.beta",1},
  73. ["rcsteeltankvalvetile"]={"Railcraft:machine.beta",14},
  74. ["chest"]={"minecraft:chest",0},
  75. ["tileskychest"]={"appliedenergistics2:tile.BlockSkyChest",1},
  76. ["iron"]={"IronChest:BlockIronChest",0},
  77. ["gold"]={"IronChest:BlockIronChest",1},
  78. ["diamond"]={"IronChest:BlockIronChest",2},
  79. ["copper"]={"IronChest:BlockIronChest",3},
  80. ["silver"]={"IronChest:BlockIronChest",4},
  81. ["crystal"]={"IronChest:BlockIronChest",5},
  82. ["obsidian"]={"IronChest:BlockIronChest",6},
  83. ["drum"]={"ExtraUtilities:drum",0},
  84. ["openperipheral_sensor"]={"OpenPeripheral:sensor",0},
  85. ["solid_fueled_boiler_firebox"]={"Railcraft:machine.beta",5},
  86. ["liquid_fueled_boiler_firebox"]={"Railcraft:machine.beta",6},
  87. ["rcsteamturbinetile"]={"Railcraft:machine.alpha",1},
  88. }
  89.  
  90. -- routines
  91. function printdebug(text)
  92. if not debug then return end
  93. if monitorfound then
  94. term.redirect(mymonitor)
  95. print(text)
  96. term.redirect(term.native())
  97. else print(text) end
  98. end
  99.  
  100. function fancytext(xx,yy,text,colour,alpha)
  101. if colour==nil then colour=0xFFFFFF end
  102. if alpha==nil then alpha=1 end
  103. local t1 = glass.addText(xx,yy,text,colour)
  104. t1.setAlpha(alpha)
  105. t1.setZ(10)
  106. local t2 = glass.addText(xx+1,yy+1,text,0x000000)
  107. t2.setAlpha(alpha/3)
  108. t2.setZ(5)
  109. return {t1,t2}
  110. end
  111.  
  112. function searchlist(searchfor,list)
  113. for i=1,#list do
  114. if list[i]==searchfor then return true end
  115. end
  116. return false
  117. end
  118.  
  119. function mysplit(str, pat)
  120. local t = {} -- NOTE: use {n = 0} in Lua-5.0
  121. local fpat = "(.-)" .. pat
  122. local last_end = 1
  123. local s, e, cap = str:find(fpat, 1)
  124. while s do
  125. if s ~= 1 or cap ~= "" then
  126. table.insert(t,cap)
  127. end
  128. last_end = e+1
  129. s, e, cap = str:find(fpat, last_end)
  130. end
  131. if last_end <= #str then
  132. cap = str:sub(last_end)
  133. table.insert(t, cap)
  134. end
  135. return t
  136. end
  137.  
  138. function pairsByKeys (t, f)
  139. local a = {}
  140. for n in pairs(t) do table.insert(a, n) end
  141. table.sort(a, f)
  142. local i = 0 -- iterator variable
  143. local iter = function () -- iterator function
  144. i = i + 1
  145. if a[i] == nil then return nil
  146. else return a[i], t[a[i]]
  147. end
  148. end
  149. return iter
  150. end
  151.  
  152. function outlinebox(xx,yy,ww,hh,colour)
  153. if colour==nil then colour=0x000000 end
  154. local outlinetable = {}
  155. table.insert(outlinetable,glass.addBox(xx-1,yy-1,ww+2,1,colour,0.5))
  156. table.insert(outlinetable,glass.addBox(xx-1,yy+hh,ww+2,1,colour,0.5))
  157. table.insert(outlinetable,glass.addBox(xx-1,yy,1,my,colour,0.5))
  158. table.insert(outlinetable,glass.addBox(xx+ww,yy,1,my,colour,0.5))
  159. return outlinetable
  160. end
  161.  
  162. function haligntext(halign,t)
  163. t.setObjectAnchor(halign,"top")
  164. end
  165.  
  166. function haligntexts(halign,texttable)
  167. for i,v in pairs(texttable) do
  168. v.setObjectAnchor(halign,"top")
  169. end
  170. end
  171.  
  172. function saligntext(halign,valign,t)
  173. t.setScreenAnchor(halign,valign)
  174. end
  175.  
  176. function saligntexts(halign,valign,texttable)
  177. for i,v in pairs(texttable) do
  178. v.setScreenAnchor(halign,valign)
  179. end
  180. end
  181.  
  182. function redraw()
  183. glass.clear()
  184. drawtitle()
  185. boxes = {}
  186. outlines = {}
  187. texts = {}
  188. gauges = {}
  189. icons = {}
  190. lastmessage = {}
  191. ticker = {}
  192. end
  193.  
  194. function drawtitle()
  195. local bannertext = "DeadGlass "..version
  196. if mx < 100 then bannertext = "DG "..version end
  197. haligntexts("middle",fancytext((16+mx+gap*2)/2,gap+4,bannertext,0xFFFFFF))
  198. outlinebox(gap,gap,16+mx+gap,my)
  199. glass.addGradientBox(gap,gap,16+mx+gap,my,0x000000,0.25,0x000000,0.5,1)
  200. end
  201.  
  202. function reorder()
  203. newy = firstgaugey
  204. index = 1
  205. for i,v in pairsByKeys(boxes) do
  206. index = index + 1
  207. for ii,vv in ipairs(gauges[i]) do
  208. diff = newy - boxes[i].getY()
  209. vv.setY(vv.getY() + diff)
  210. end
  211. for ii,vv in ipairs(outlines[i]) do
  212. diff = newy - boxes[i].getY()
  213. vv.setY(vv.getY() + diff)
  214. end
  215. for ii,vv in ipairs(texts[i]) do
  216. diff = newy - boxes[i].getY()
  217. vv.setY(vv.getY() + diff)
  218. end
  219. boxes[i].setY(newy)
  220. icons[i].setY(newy)
  221. newy = newy + gap + my
  222. end
  223. end
  224.  
  225. function timenow()
  226. return os.day()+(os.time()/24)
  227. end
  228.  
  229. function estimatetimediff(day,time)
  230. local daynow = timenow()
  231. local daythen = day+(time/24)
  232. return (daynow-daythen)*20
  233. end
  234.  
  235. function timedifftoenglish(diff)
  236. if diff < 0.1 then return "Now"
  237. elseif diff < 1 then return "<1 min"
  238. elseif diff >= 1 and diff < 60 then return math.floor(diff).." min"..(diff>=2 and "s" or "")
  239. elseif diff >= 60 and diff < 1440 then return math.floor(diff/60).." hour"..(diff/60>=2 and "s" or "")
  240. elseif diff >= 1440 and diff < 40320 then return math.floor(diff/1440).." day"..(diff/1440>=2 and "s" or "")
  241. else return "Long ago" end
  242. end
  243.  
  244. function filetoarray(file,array)
  245. local array = {}
  246. if fs.exists(file) then
  247. local f = fs.open(file,"r")
  248. repeat
  249. local l = f.readLine()
  250. if (l~=nil) then table.insert(array,l) end
  251. until l==nil
  252. end
  253. return array
  254. end
  255.  
  256. function arraytofile(array,file)
  257. local f = fs.open(file,"w")
  258. for k,v in ipairs(array) do
  259. f.writeLine(v)
  260. end
  261. f.close()
  262. end
  263.  
  264. function writeplayerlist()
  265. local f = fs.open("playerlist.txt","w")
  266. for k,v in pairs(playerlist) do
  267. f.writeLine(k..","..v.day..","..v.time)
  268. end
  269. f.close()
  270. end
  271.  
  272. function readplayerlist()
  273. local pt = filetoarray("playerlist.txt")
  274. for i,v in pairs(pt) do
  275. local split = mysplit(v,",")
  276. playerlist[split[1]] = {["day"]=split[2],["time"]=split[3]}
  277. --printdebug("Read player "..split[1]..", "..split[2]..", "..split[3])
  278. end
  279. end
  280.  
  281. function sense()
  282. printdebug(key.." "..message.." "..value)
  283. local players = mysplit(message,"!")
  284. if players[1]=="No-one" then return end
  285. for k,v in pairs(players) do
  286. playerlist[v] = {["day"]=os.day(),["time"]=os.time()}
  287. local colour = 0xFFFF00
  288. local notecommand = "random.orb#0.5"
  289. if searchlist(v,blacklist) then
  290. notecommand = "nuclearcontrol:alarm-default#1"
  291. colour = 0xFF0000
  292. end
  293. if not searchlist(v,whitelist) then
  294. rednet.broadcast("note "..notecommand,"krazserver")
  295. addtoticker("Sensor "..sender.."/"..pid..": "..v, colour)
  296. end
  297. end
  298. --updateticker()
  299. writeplayerlist()
  300. end
  301.  
  302. function daystominutes(days)
  303. return days*20
  304. end
  305.  
  306. function textsetalpha(t,a)
  307. --printdebug("Alpha "..a)
  308. t.setAlpha(a)
  309. end
  310.  
  311. function updateticker()
  312. local s = false
  313. if refreshticker then
  314. local yy = -20
  315. for i,t in ipairs(ticker) do
  316. t["text"].setY(yy)
  317. yy = yy - 10
  318. end
  319. refreshticker = false
  320. s = true
  321. end
  322. local i = 1
  323. if #ticker > 0 then s = true end
  324. while i <= #ticker do
  325. -- too old? Eastbourne
  326. if ticker[i]["timestamp"] >= tickerttl then
  327. ticker[i]["text"].delete()
  328. table.remove(ticker,i)
  329. else
  330. local a = 0.11+((tickerttl-ticker[i]["timestamp"])*0.89/tickerttl)
  331. textsetalpha(ticker[i]["text"], a)
  332. ticker[i]["timestamp"] = ticker[i]["timestamp"] + 1
  333. i = i + 1
  334. end
  335. end
  336. if s then glass.sync() end
  337. end
  338.  
  339. function addtoticker(text,colour)
  340. if colour==nil then colour=0xFFFFFF end
  341. table.insert(ticker, 1, {["timestamp"]=0, ["text"]=glass.addText(-10,-20,text,colour)})
  342. haligntext("right", ticker[1]["text"])
  343. saligntext("right", "bottom", ticker[1]["text"])
  344. refreshticker = true
  345. end
  346.  
  347. function draw()
  348. if texts[key] == nil then
  349. -- add to the bottom
  350. boxes[key] = glass.addBox(x+16+gap,y,mx,my,0xFFFFFF,0.0)
  351. texts[key] = fancytext(x+20+gap,y+4,message)
  352. icons[key] = glass.addIcon(x,y,blockidms[id][1],blockidms[id][2])
  353. icons[key].setZ(10)
  354. gauges[key] = {}
  355. outlines[key] = outlinebox(x+16+gap,y,mx,my)
  356. for i,v in pairs(outlinebox(gap,y,16,16)) do table.insert(outlines[key],v) end
  357. table.insert(outlines[key],glass.addGradientBox(gap,y,16,16,0x000000,0.25,0x000000,0.5,1))
  358. if protocol=="estor" or protocol=="eout" or protocol=="eheat" or protocol=="eoutspeed" or protocol=="istor" or protocol == "fout" then
  359. for i=1,mx,2 do
  360. local line = glass.addBox(x+20+i,y,1,my,0x000000,0.2)
  361. line.setZ(2)
  362. table.insert(outlines[key],line)
  363. end
  364. end
  365. y = y + my + gap
  366. -- sort them into key order
  367. reorder()
  368. else
  369. for ii,vv in ipairs(texts[key]) do
  370. vv.setText(message)
  371. end
  372. end
  373.  
  374. printdebug(key.." "..message.." "..value)
  375. --printdebug("Key: "..key)
  376. --printdebug("Message: "..message)
  377. --printdebug("Svalue: "..svalue)
  378. --printdebug("Value: "..value)
  379.  
  380. bx = boxes[key].getX()
  381. bw = boxes[key].getWidth()
  382. bpw = bw*(value/100)
  383. bxp = bx + bpw
  384. by = boxes[key].getY()
  385. bh = boxes[key].getHeight()
  386. for i,v in pairs(gauges[key]) do
  387. v.delete()
  388. end
  389. gauges[key] = {}
  390.  
  391. if protocol=="estor" or protocol=="eout" or protocol=="eoutspeed" or protocol=="eheat" or protocol=="istor" then
  392. if (value>0) then
  393. table.insert(gauges[key],glass.addGradientBox(bx,by,bpw,bh,pcols[protocol][2],0.7,pcols[protocol][1],0.7,1))
  394. end
  395. if (value<100) then
  396. table.insert(gauges[key],glass.addGradientBox(bxp,by,bw-bpw,bh,0x111111,0.7,0x333333,0.7,1))
  397. end
  398. elseif protocol=="aecells" then
  399. for ii,vv in ipairs(texts[key]) do
  400. vv.setText("")
  401. end
  402. for i=1,value do
  403. cw = (bw/value)
  404. cellcol = 0x333333
  405. if string.sub(message,i,i)=="g" then cellcol = 0x66FF66
  406. elseif string.sub(message,i,i)=="o" then cellcol = 0xFF9933
  407. elseif string.sub(message,i,i)=="r" then cellcol = 0xFF0000 end
  408. table.insert(gauges[key],glass.addGradientBox(bx+((i-1)*cw),by,cw,bh,cellcol,0.5,cellcol,0.7,2))
  409. end
  410. elseif protocol=="tank" or protocol=="fout" then
  411. if (value>0) then
  412. table.insert(gauges[key],glass.addLiquid(bx,by,bpw,bh,liquidname))
  413. gauges[key][1].setAlpha(0.7)
  414. end
  415. if (value<100) then table.insert(gauges[key],glass.addGradientBox(bxp,by,bw-bpw,bh,0x000000,0.25,0x000000,0.5,1)) end
  416. end
  417.  
  418. glass.sync()
  419.  
  420. end
  421.  
  422. function serialised(array)
  423. local s = ""
  424. for _,v in pairs(array) do
  425. s = s .. "," .. v
  426. end
  427. return string.sub(s, 2)
  428. end
  429.  
  430. function sendlist(sender,listname,list)
  431. rednet.send(sender,listname.." "..serialised(list),"krazserver")
  432. end
  433.  
  434. function broadcastlist(listname,list)
  435. rednet.broadcast(listname.." "..serialised(list),"krazserver")
  436. end
  437.  
  438.  
  439. -- initialise
  440.  
  441. term.clear()
  442. term.setCursorPos(1,1)
  443. print("Deadlock989's DeadGlass server "..version.." running!")
  444. if (os.getComputerLabel()==nil) then
  445. print("Setting computer label to 'krazserver'.")
  446. os.setComputerLabel("krazserver")
  447. end
  448. print("Loading whitelist ...")
  449. whitelist = filetoarray("whitelist.txt")
  450. print("Loading blacklist ...")
  451. blacklist = filetoarray("blacklist.txt")
  452. print("Loading detected players list ...")
  453. readplayerlist()
  454.  
  455. modemfound = false
  456. tgbfound = false
  457. monitorfound = false
  458. sides = peripheral.getNames()
  459. for i=1, #sides do
  460. thistype = peripheral.getType(sides[i])
  461. if thistype=="modem" then
  462. print("Attaching to modem on the "..sides[i].." ...")
  463. rednet.open(sides[i])
  464. modemfound = true
  465. end
  466. if thistype=="monitor" then
  467. print("Attaching to monitor on the "..sides[i].." ...")
  468. mymonitor = peripheral.wrap(sides[i])
  469. monitorfound = true
  470. mymonitor.clear()
  471. mymonitor.setCursorPos(1,1)
  472. end
  473. if not tgbfound and thistype=="openperipheral_bridge" then
  474. print("Attaching to TGB on the "..sides[i].." ...")
  475. glass = peripheral.wrap(sides[i])
  476. tgbfound = true
  477. -- workaround text bug?
  478. end
  479. end
  480.  
  481. if not modemfound then error("No modem attached. Aborting.") end
  482. if not tgbfound then error("No Terminal Glasses Bridge attached. Aborting.") end
  483.  
  484. rednet.host("krazserver","krazserver")
  485. glass.clear()
  486. drawtitle()
  487. print("Running ...")
  488.  
  489. -- network events
  490. function netevent(p1,p2,p3)
  491. sender = p1
  492. message = p2
  493. protocol = p3
  494. psplit = mysplit(protocol,"/")
  495. protocol = psplit[1]
  496. if not searchlist(protocol,knownprotocols) then return end
  497. pid = psplit[2]
  498.  
  499. if protocol=="handshake" then
  500. printdebug("Received handshake request from client "..sender)
  501. sendlist(sender,"whitelist",whitelist)
  502. sendlist(sender,"blacklist",blacklist)
  503. return
  504. end
  505.  
  506. id = ""
  507. value = 0
  508. split = mysplit(message,"|")
  509. message = split[1]
  510. id = split[2]
  511. value = tonumber(split[3])
  512. svalue = split[3]
  513. liquidname = split[4]
  514.  
  515. key = protocol.."/"..blockidms[id][1].."/"..sender.."/"..pid
  516. timestamp[key] = os.clock()
  517.  
  518. -- new info?
  519. if lastmessage[key]==nil or lastmessage[key]~=message then
  520. lastmessage[key] = message
  521. if protocol == "sensor" then sense()
  522. else draw() end
  523. end
  524. end
  525.  
  526. function listcommand(array,file,commands)
  527. local colour = 0x00FF00
  528. if commands[1]=="blacklist" then
  529. colour = 0xFF0000
  530. end
  531. if commands[2]==nil and commands[3]==nil then
  532. if #array==0 then addtoticker("List is empty")
  533. else
  534. addtoticker(commands[1]:gsub("^%l", string.upper)..":")
  535. for i,v in ipairs(array) do addtoticker(v, colour) end
  536. end
  537. --updateticker()
  538. elseif commands[3]==nil or (commands[2]~="add" and commands[2]~="remove") then
  539. addtoticker("Syntax: $$"..commands[1].." [add/remove playername]")
  540. --updateticker()
  541. elseif commands[2]=="add" then
  542. local found = false
  543. if commands[1]=="whitelist" and searchlist(commands[3],blacklist) then
  544. addtoticker("Player is in blacklist")
  545. return array
  546. elseif commands[1]=="blacklist" and searchlist(commands[3],whitelist) then
  547. addtoticker("Player is in whitelist")
  548. return array
  549. end
  550. for i,v in ipairs(array) do
  551. if v==commands[3] then
  552. found = true
  553. break
  554. end
  555. end
  556. if found then
  557. addtoticker("Player "..commands[3].." is already in list")
  558. --updateticker()
  559. else
  560. table.insert(array,commands[3])
  561. arraytofile(array,file)
  562. addtoticker("Player "..commands[3].." added")
  563. --updateticker()
  564. broadcastlist(commands[1],array)
  565. end
  566. elseif commands[2]=="remove" then
  567. local i = 1
  568. local found = false
  569. while i <= #array do
  570. if array[i]==commands[3] then
  571. table.remove(array,i)
  572. found = true
  573. break
  574. end
  575. i = i + 1
  576. end
  577. if found then
  578. arraytofile(array,file)
  579. addtoticker("Player "..commands[3].." removed")
  580. --updateticker()
  581. broadcastlist(commands[1],array)
  582. else
  583. addtoticker("Player "..commands[3].." not found in list")
  584. --updateticker()
  585. end
  586. end
  587. return array
  588. end
  589.  
  590. -- chat commands
  591. function chatcommand(side,player,key,command)
  592. printdebug("Command received: "..command)
  593. commands = mysplit(command," ")
  594. if command=="reset" then
  595. redraw()
  596. elseif command=="small" then
  597. mx=50
  598. redraw()
  599. elseif command=="medium" then
  600. mx=100
  601. redraw()
  602. elseif command=="large" then
  603. mx=200
  604. redraw()
  605. elseif command=="reboot" then
  606. os.reboot()
  607. elseif command=="players" then
  608. for k,v in pairs(playerlist) do
  609. local colour = 0xFFFF00
  610. if searchlist(v, whitelist) then colour = 0x00FF00
  611. elseif searchlist(v, blacklist) then colour = 0xFF0000
  612. end
  613. addtoticker(k..": "..timedifftoenglish(estimatetimediff(v["day"],v["time"])))
  614. end
  615. elseif commands[1]=="redstone" then
  616. if commands[2]==nil or (commands[2]~="on" and commands[2]~="off") then
  617. addtoticker("Syntax: $$redstone on/off [clientname]")
  618. return
  619. end
  620. printdebug("Broadcasting ...")
  621. rednet.broadcast(command,"krazserver")
  622. elseif commands[1]=="credstone" then
  623. if commands[2]==nil or not searchlist(commands[2],colourlist) or commands[3]==nil or (commands[3]~="on" and commands[3]~="off") then
  624. addtoticker("Syntax: $$credstone colour on/off [clientname]")
  625. return
  626. end
  627. printdebug("Broadcasting ...")
  628. rednet.broadcast(command,"krazserver")
  629. elseif commands[1]=="lamps" then
  630. if commands[2]==nil or string.find(commands[2],"^%x%x%x%x%x%x$")==nil then
  631. addtoticker("Syntax: $$lamps FFFFFF [clientname]")
  632. return
  633. end
  634. printdebug("Broadcasting ...")
  635. rednet.broadcast(command,"krazserver")
  636. elseif commands[1]=="note" then
  637. if commands[2]==nil or string.find(commands[2],"#")==nil then
  638. addtoticker("Syntax: $$note notename#pitch [clientname]")
  639. return
  640. end
  641. printdebug("Broadcasting ...")
  642. rednet.broadcast(command,"krazserver")
  643. elseif commands[1]=="whitelist" then
  644. whitelist = listcommand(whitelist,"whitelist.txt",commands)
  645. elseif commands[1]=="blacklist" then
  646. blacklist = listcommand(blacklist,"blacklist.txt",commands)
  647. elseif commands[1]=="brrods" then
  648. if commands[2]==nil or string.find(commands[2],"^%d%d?%d?$")==nil or tonumber(commands[2])<0 or tonumber(commands[2])>100 then
  649. addtoticker("Syntax: $$brrods 0-100 [clientname]")
  650. return
  651. end
  652. rednet.broadcast(command,"krazserver")
  653. elseif commands[1]=="brflow" then
  654. if commands[2]==nil or string.find(commands[2],"^%d%d?%d?%d?$")==nil or tonumber(commands[2])<0 or tonumber(commands[2])>2000 then
  655. addtoticker("Syntax: $$brrods 0-2000 [clientname]")
  656. return
  657. end
  658. rednet.broadcast(command,"krazserver")
  659. end
  660. end
  661.  
  662. function getkeyset(t)
  663. ks = {}
  664. for k,v in pairs(t) do
  665. table.insert(ks,k)
  666. end
  667. return ks
  668. end
  669.  
  670. function timerlistener(p1)
  671. if p1==heartbeat then
  672. heartbeat = os.startTimer(hbtime)
  673. printdebug("*Heartbeat*")
  674. updateticker()
  675. hbcount = hbcount + 1
  676. if (hbcount%displaycheckcount==0) then
  677. -- kill dead client displays
  678. local k = 1
  679. for i,k in ipairs(getkeyset(timestamp)) do
  680. if (os.clock()-timestamp[k])>=decaytime then
  681. printdebug("Removing "..k)
  682. if boxes[k] ~= nil then
  683. for ii,vv in ipairs(gauges[k]) do
  684. vv.delete()
  685. end
  686. for ii,vv in ipairs(outlines[k]) do
  687. vv.delete()
  688. end
  689. for ii,vv in ipairs(texts[k]) do
  690. vv.delete()
  691. end
  692. boxes[k].delete()
  693. icons[k].delete()
  694. end
  695. gauges[k] = nil
  696. outlines[k] = nil
  697. texts[k] = nil
  698. boxes[k] = nil
  699. icons[k] = nil
  700. timestamp[k] = nil
  701. lastmessage[k] = nil
  702. end
  703. end
  704. reorder()
  705. glass.sync()
  706. end
  707. end
  708. end
  709.  
  710. function eventlistener()
  711. local event, p1, p2, p3, p4, p5 = os.pullEvent()
  712. if event=="rednet_message" then netevent(p1,p2,p3)
  713. elseif event=="timer" then timerlistener(p1)
  714. elseif event=="glasses_chat_command" then chatcommand(p1,p2,p3,p4) end
  715. end
  716.  
  717. -- main loop
  718. heartbeat = os.startTimer(hbtime)
  719. while true do
  720. eventlistener()
  721. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement