SHOW:
|
|
- or go back to the newest paste.
| 1 | -- This program was written by MorgosMaci for the CraftersLand | |
| 2 | -- Tekkit server. | |
| 3 | ||
| 4 | ct = colors.black | |
| 5 | cb = colors.white | |
| 6 | cv = colors.red | |
| 7 | cn = colors.red | |
| 8 | function writeColor(mon, text, fgColor, bgColor) | |
| 9 | if (mon.isColor()) then | |
| 10 | if fgColor then | |
| 11 | mon.setTextColor(fgColor) | |
| 12 | end | |
| 13 | if bgColor then | |
| 14 | mon.setBackgroundColor(bgColor) | |
| 15 | - | mon.setTextColor(colors.white) |
| 15 | + | |
| 16 | - | mon.setBackgroundColor(colors.black) |
| 16 | + | |
| 17 | mon.write(text) | |
| 18 | if (mon.isColor()) then | |
| 19 | mon.setTextColor(ct) | |
| 20 | mon.setBackgroundColor(cb) | |
| 21 | end | |
| 22 | end | |
| 23 | ||
| 24 | -- Return a wrapped device given a search term. | |
| 25 | function getDevice(search) | |
| 26 | local plist = peripheral.getNames() | |
| 27 | local i, name | |
| 28 | for i, name in pairs(plist) do | |
| 29 | if string.find(peripheral.getType(name), search) then | |
| 30 | return peripheral.wrap(name) | |
| 31 | end | |
| 32 | end | |
| 33 | if search == monitor then | |
| 34 | return term | |
| 35 | else | |
| 36 | return nil | |
| 37 | end | |
| 38 | end | |
| 39 | ||
| 40 | function readSettings(user) | |
| 41 | local filename, _ = user:gsub(" ", "_")
| |
| 42 | filename = filename..".settings" | |
| 43 | local settingsFile = fs.combine(settingsDirectory, filename) | |
| 44 | local fh = fs.open(settingsFile, "r") | |
| 45 | if fh then | |
| 46 | return textutils.unserialize(fh.readAll()) | |
| 47 | end | |
| 48 | return nil | |
| 49 | end | |
| 50 | ||
| 51 | function writeSettings(user, settings) | |
| 52 | local filename, _ = user:gsub(" ", "_")
| |
| 53 | filename = filename..".settings" | |
| 54 | local settingsFile = fs.combine(settingsDirectory, filename) | |
| 55 | local fh = fs.open(settingsFile, "w") | |
| 56 | if fh then | |
| 57 | fh.write(textutils.serialize(settings)) | |
| 58 | fh.close() | |
| 59 | end | |
| 60 | end | |
| 61 | ||
| 62 | -- This function extracts information from the livemap | |
| 63 | -- at the current timestamp and stores it in global | |
| 64 | -- tables. | |
| 65 | function extractLiveMap() | |
| 66 | local t = {}
| |
| 67 | local name, armor, account, health, world, x, y, z | |
| 68 | local a = 0 | |
| 69 | local b = 0 | |
| 70 | ||
| 71 | fh = http.get("http://tekkit.craftersland.net:25800/up/world/world/" .. ts)
| |
| 72 | if not fh then | |
| 73 | return | |
| 74 | end | |
| 75 | ||
| 76 | s = fh.readAll() | |
| 77 | fh.close() | |
| 78 | _,_,ts = string.find(s, "{\"timestamp\":(%d+),")
| |
| 79 | ||
| 80 | -- Could not find the timestamp so the page must have not returned completely. | |
| 81 | if not ts then | |
| 82 | return | |
| 83 | end | |
| 84 | ||
| 85 | -- Extract out the player information | |
| 86 | players = {}
| |
| 87 | playerCount = 0 | |
| 88 | local a = 0 | |
| 89 | local b = 0 | |
| 90 | local name, armor, account, health, z, y, world, x | |
| 91 | while (true) do | |
| 92 | a, b, name, armor, account, health, z, y, world, x = string.find(s, "\"sort\":0,\"name\":\"([^\"]+)\",\"armor\":(%d+),\"account\":\"([^\"]+)\",\"health\":(%d+),\"type\":\"player\",\"z\":([-0-9.]+),\"y\":([-0-9.]+),\"world\":\"([^\"]+)\",\"x\":([-0-9.]+)", b + 1) | |
| 93 | if (a == nil) then | |
| 94 | break | |
| 95 | end | |
| 96 | if world == "DIM-1" then | |
| 97 | world = "nether" | |
| 98 | elseif world == "DIM-28" then | |
| 99 | world = "moon" | |
| 100 | elseif world == "DIM-29" then | |
| 101 | world = "mars" | |
| 102 | elseif world == "-some-other-bogus-world-" then | |
| 103 | world = "camouflage" | |
| 104 | elseif world:sub(1, 8) == "DIM_MYST" then | |
| 105 | world = "myst_"..world:sub(9) | |
| 106 | elseif world:sub(1, 16) == "DIM_SPACESTATION" then | |
| 107 | world = "spacestation_"..world:sub(17) | |
| 108 | end | |
| 109 | worlds[world] = 1 | |
| 110 | players[account] = {}
| |
| 111 | players[account].armor = tonumber(armor) | |
| 112 | players[account].name = name | |
| 113 | players[account].health = tonumber(health) | |
| 114 | players[account].world = world | |
| 115 | local yn = tonumber(y) | |
| 116 | if yn > 999 then | |
| 117 | yn = 999 | |
| 118 | end | |
| 119 | players[account].loc = vector.new(tonumber(x), yn, tonumber(z)) | |
| 120 | playerCount = playerCount + 1 | |
| 121 | end | |
| 122 | end | |
| 123 | ||
| 124 | function getDir(s, t) | |
| 125 | local dir = math.atan2(s.z - t.z, s.x - t.x) | |
| 126 | if dir > 2.75 or dir < -2.74 then | |
| 127 | return "W" | |
| 128 | elseif dir > -2.75 and dir < -1.95 then | |
| 129 | return "NW" | |
| 130 | elseif dir > -1.96 and dir < -1.17 then | |
| 131 | return "N" | |
| 132 | elseif dir > -1.18 and dir < -0.38 then | |
| 133 | return "NE" | |
| 134 | elseif dir > -0.39 and dir < 0.40 then | |
| 135 | return "E" | |
| 136 | elseif dir > 0.39 and dir < 1.19 then | |
| 137 | return "SE" | |
| 138 | elseif dir > 1.18 and dir < 1.96 then | |
| 139 | return "S" | |
| 140 | elseif dir > 1.96 and dir < 2.76 then | |
| 141 | return "SW" | |
| 142 | end | |
| 143 | end | |
| 144 | ||
| 145 | function displayPlayersOnMon() | |
| 146 | local p = {}
| |
| 147 | local i = 1 | |
| 148 | local st = {}
| |
| 149 | local x = 1 | |
| 150 | local y = 3 | |
| 151 | for key in pairs(players) do | |
| 152 | if players[key].world == "world" or players[key].world == "camouflage" then | |
| 153 | p[key] = players[key] | |
| 154 | local offset = defaultSettings.hereDefault - p[key].loc | |
| 155 | if p[key].world == "camouflage" then | |
| 156 | p[key].dist = 999999 | |
| 157 | else | |
| 158 | p[key].dist = math.floor(math.sqrt(offset.x * offset.x + offset.z * offset.z)) | |
| 159 | p[key].dir = getDir(p[key].loc, defaultSettings.hereDefault) | |
| 160 | end | |
| 161 | st[#st+1] = key | |
| 162 | - | writeColor(mon, string.rep(" ", monW), colors.white, colors.blue)
|
| 162 | + | |
| 163 | end | |
| 164 | - | writeColor(mon, "--== Overworld ==--", colors.white, colors.blue) |
| 164 | + | |
| 165 | mon.setCursorPos(x, y) | |
| 166 | writeColor(mon, string.rep(" ", monW), ct, cv)
| |
| 167 | mon.setCursorPos(x, y) | |
| 168 | - | local pc = colors.cyan |
| 168 | + | writeColor(mon, "--== Overworld ==--", ct, cv) |
| 169 | for k = 1, #st do | |
| 170 | account = st[k] | |
| 171 | mon.setCursorPos(x, y + k) | |
| 172 | local pc = cn | |
| 173 | if account == highlight then | |
| 174 | pc = colors.yellow | |
| 175 | end | |
| 176 | writeColor(mon, rightPad(account, 12), pc) | |
| 177 | mon.setCursorPos(x + 13, y + k) | |
| 178 | if p[account].world == "camouflage" then | |
| 179 | writeColor(mon, "Camouflage", colors.red) | |
| 180 | else | |
| 181 | text = string.format("%s %s %s %s (%s)",
| |
| 182 | leftPad(math.floor(p[account].loc.x), 5), | |
| 183 | leftPad(math.floor(p[account].loc.z), 5), | |
| 184 | leftPad(math.floor(p[account].loc.y), 3), | |
| 185 | leftPad(p[account].dist, 5), | |
| 186 | p[account].dir) | |
| 187 | mon.write(text) | |
| 188 | end | |
| 189 | end | |
| 190 | if monW < 65 then | |
| 191 | return | |
| 192 | end | |
| 193 | x = 45 | |
| 194 | local mapY = monH - 3 - y | |
| 195 | local mapX = monW - x | |
| 196 | local map = {}
| |
| 197 | map[1] = "+"..string.rep("-", mapX - 2).."+"
| |
| 198 | for ty = 2, mapY - 1 do | |
| 199 | map[ty] = "|"..string.rep(" ", mapX - 2).."|"
| |
| 200 | end | |
| 201 | map[mapY] = "+"..string.rep("-", mapX - 2).."+"
| |
| 202 | local px = math.floor((defaultSettings.hereSpawn.x - xLim[1]) / xLim[2] * mapX) | |
| 203 | local py = math.floor((defaultSettings.hereSpawn.z - yLim[1]) / yLim[2] * mapY) | |
| 204 | map[py] = string.sub(map[py], 1, px - 1).."@"..string.sub(map[py], px + 1) | |
| 205 | local px = math.floor((defaultSettings.hereDefault.x - xLim[1]) / xLim[2] * mapX) | |
| 206 | - | writeColor(mon, "--== World Map ==--", colors.white, colors.blue) |
| 206 | + | |
| 207 | map[py] = string.sub(map[py], 1, px - 1).."#"..string.sub(map[py], px + 1) | |
| 208 | mon.setCursorPos(x, y) | |
| 209 | if mapMode then | |
| 210 | writeColor(mon, "--== World Map ==--", ct, cv) | |
| 211 | y = y + 1 | |
| 212 | local a = 65 | |
| 213 | for k = 1, #st do | |
| 214 | account = st[k] | |
| 215 | if p[account].world ~= "camouflage" then | |
| 216 | local px = math.floor((p[account].loc.x - xLim[1]) / xLim[2] * mapX) | |
| 217 | local py = math.floor((p[account].loc.z - yLim[1]) / yLim[2] * mapY) | |
| 218 | local c = string.sub(map[py], px, px) | |
| 219 | if c == " " or c == "|" or c == "+" or c == "-" then | |
| 220 | c = string.char(a) | |
| 221 | map[py] = string.sub(map[py], 1, px - 1)..c..string.sub(map[py], px + 1) | |
| 222 | a = a + 1 | |
| 223 | end | |
| 224 | mon.setCursorPos(x - 3, y) | |
| 225 | mon.write(c) | |
| 226 | y = y + 1 | |
| 227 | end | |
| 228 | end | |
| 229 | for ty = 1, mapY do | |
| 230 | - | writeColor(mon, "--== Other Dimensions ==--", colors.white, colors.blue) |
| 230 | + | |
| 231 | mon.write(map[ty]) | |
| 232 | end | |
| 233 | else | |
| 234 | writeColor(mon, "--== Other Dimensions ==--", ct, cv) | |
| 235 | - | local pc = colors.cyan |
| 235 | + | |
| 236 | for key in pairs(players) do | |
| 237 | if players[key].world ~= "world" and players[key].world ~= "camouflage" then | |
| 238 | mon.setCursorPos(x, y) | |
| 239 | local pc = cn | |
| 240 | if key == highlight then | |
| 241 | pc = colors.yellow | |
| 242 | end | |
| 243 | writeColor(mon, rightPad(key, 12), pc) | |
| 244 | mon.setCursorPos(x + 13, y) | |
| 245 | text = string.format("%s %s %s %s",
| |
| 246 | leftPad(math.floor(players[key].loc.x), 5), | |
| 247 | leftPad(math.floor(players[key].loc.z), 5), | |
| 248 | leftPad(math.floor(players[key].loc.y), 3), | |
| 249 | players[key].world) | |
| 250 | mon.write(text) | |
| 251 | y = y + 1 | |
| 252 | end | |
| 253 | end | |
| 254 | end | |
| 255 | end | |
| 256 | ||
| 257 | function displayPlayersOnUsersGlass(user) | |
| 258 | local settings = users[user].settings | |
| 259 | local surface = glass.getUserSurface(user) | |
| 260 | if not surface then | |
| 261 | return | |
| 262 | end | |
| 263 | local x = settings.trackLoc.x | |
| 264 | local y = settings.trackLoc.y | |
| 265 | local p = {}
| |
| 266 | local st = {}
| |
| 267 | for key in pairs(players) do | |
| 268 | if players[key].world == settings.worldFilter or players[key].world == "camouflage" then | |
| 269 | p[key] = players[key] | |
| 270 | local offset = users[user].here - p[key].loc | |
| 271 | if p[key].world == "camouflage" then | |
| 272 | p[key].dist = 999999 | |
| 273 | else | |
| 274 | p[key].dist = math.floor(math.sqrt(offset.x * offset.x + offset.z * offset.z)) | |
| 275 | end | |
| 276 | p[key].dir = getDir(p[key].loc, users[user].here) | |
| 277 | st[#st+1] = key | |
| 278 | end | |
| 279 | end | |
| 280 | surface.addBox(x, y, 226, #st * 10 + 4, 0x0000FF, 0.3) | |
| 281 | table.sort(st, function(a, b) return p[a].dist < p[b].dist end) | |
| 282 | x = x + 2 | |
| 283 | y = y + 2 | |
| 284 | for k = 1, #st do | |
| 285 | account = st[k] | |
| 286 | local pc = 0x80FFFF | |
| 287 | if account == highlight then | |
| 288 | pc = 0xFFFF00 | |
| 289 | end | |
| 290 | surface.addText(x, y + (10 * (k-1)), account:sub(1, 12), pc) | |
| 291 | if p[account].world == "camouflage" then | |
| 292 | surface.addText(x + 75, y + (10 * (k-1)), "Camouflage", 0xFF0000) | |
| 293 | else | |
| 294 | surface.addText(x + 75, y + (10 * (k-1)), string.format("%d", players[account].loc.x), 0xFFFFFF)
| |
| 295 | surface.addText(x + 110, y + (10 * (k-1)), string.format("%d", players[account].loc.z), 0xFFFFFF)
| |
| 296 | surface.addText(x + 145, y + (10 * (k-1)), string.format("%d", players[account].loc.y), 0xFFFFFF)
| |
| 297 | surface.addText(x + 165, y + (10 * (k-1)), string.format("%d", players[account].dist), 0xFFFFFF)
| |
| 298 | surface.addText(x + 200, y + (10 * (k-1)), string.format("(%s)", players[account].dir), 0xFFFFFF)
| |
| 299 | end | |
| 300 | end | |
| 301 | end | |
| 302 | ||
| 303 | function rightPad(v, n) | |
| 304 | return string.sub(""..v..string.rep(" ", n), 1, n)
| |
| 305 | end | |
| 306 | ||
| 307 | function leftPad(v, n) | |
| 308 | nv = ""..v | |
| 309 | lv = string.len(nv) | |
| 310 | if (lv > n) then | |
| 311 | return string.sub(nv, n - lv + 1, lv) | |
| 312 | else | |
| 313 | return string.rep(" ", n - lv )..nv
| |
| 314 | end | |
| 315 | end | |
| 316 | ||
| 317 | function refresh() | |
| 318 | extractLiveMap() | |
| 319 | updateMonitor() | |
| 320 | if glass then | |
| 321 | updateGlass() | |
| 322 | end | |
| 323 | end | |
| 324 | ||
| 325 | function updateMonitor() | |
| 326 | mon.clear() | |
| 327 | mon.setCursorPos(1, 1) | |
| 328 | mon.write(string.format("Visible Players: %d", playerCount))
| |
| 329 | s = textutils.formatTime(os.time(), false) | |
| 330 | mon.setCursorPos(monW - string.len(s), 1) | |
| 331 | mon.write(s) | |
| 332 | - | writeColor(mon, string.rep(" ", monW), colors.white, colors.blue)
|
| 332 | + | |
| 333 | local x = 1 | |
| 334 | - | writeColor(mon, string.rep(" ", monW), colors.white, colors.black)
|
| 334 | + | |
| 335 | mon.setCursorPos(x, y) | |
| 336 | - | writeColor(mon, string.rep(" ", monW), colors.white, colors.black)
|
| 336 | + | writeColor(mon, string.rep(" ", monW), ct, cv)
|
| 337 | mon.setCursorPos(x, y + 1) | |
| 338 | - | writeColor(mon, "--== Current Glass Users ==--", colors.white, colors.blue) |
| 338 | + | writeColor(mon, string.rep(" ", monW), ct, cb)
|
| 339 | mon.setCursorPos(x, y + 2) | |
| 340 | writeColor(mon, string.rep(" ", monW), ct, cb)
| |
| 341 | mon.setCursorPos(x, y) | |
| 342 | writeColor(mon, "--== Current Glass Users ==--", ct, cv) | |
| 343 | - | writeColor(mon, user, colors.lime, colors.black) |
| 343 | + | |
| 344 | for _, user in pairs(glass.getUsers()) do | |
| 345 | - | writeColor(mon, user, colors.cyan, colors.black) |
| 345 | + | |
| 346 | if defaultSettings.privUsers[user] then | |
| 347 | - | writeColor(mon, user, colors.red, colors.black) |
| 347 | + | writeColor(mon, user, colors.lime, cb) |
| 348 | elseif users[user] then | |
| 349 | writeColor(mon, user, cn, cb) | |
| 350 | else | |
| 351 | writeColor(mon, user, colors.red, cb) | |
| 352 | end | |
| 353 | x = x + 1 + string.len(user) | |
| 354 | end | |
| 355 | end | |
| 356 | ||
| 357 | function updateGlass() | |
| 358 | for _, user in pairs(glass.getUsers()) do | |
| 359 | local surface = glass.getUserSurface(user) | |
| 360 | if surface then | |
| 361 | surface.clear() | |
| 362 | if users[user] then | |
| 363 | if users[user].track then | |
| 364 | displayPlayersOnUsersGlass(user) | |
| 365 | end | |
| 366 | if users[user].glassOutput then | |
| 367 | local x = users[user].settings.outputLoc.x | |
| 368 | local y = users[user].settings.outputLoc.y | |
| 369 | local l = users[user].settings.outputLoc.l | |
| 370 | surface.addBox(x, y, l * 5, 40, 0x000000, 0.3) | |
| 371 | surface.addText(x + 5, y + 5, users[user].glassOutput:sub(1, l - 1), 0xFFFFFF) | |
| 372 | surface.addText(x + 5, y + 15, users[user].glassOutput:sub(l, l * 2 - 1), 0xFFFFFF) | |
| 373 | surface.addText(x + 5, y + 25, users[user].glassOutput:sub(l * 2, l * 3 - 1), 0xFFFFFF) | |
| 374 | end | |
| 375 | else | |
| 376 | local settings = readSettings(user) | |
| 377 | if settings then | |
| 378 | users[user] = {}
| |
| 379 | users[user].settings = settings | |
| 380 | users[user].glassOutput = "Welcome "..user | |
| 381 | users[user].here = defaultSettings.hereDefault | |
| 382 | users[user].track = true | |
| 383 | elseif defaultSettings.privUsers[user] then | |
| 384 | -- Allow priviledged users even if they don't have settings | |
| 385 | -- just give them the default. | |
| 386 | users[user] = {}
| |
| 387 | users[user].settings = defaultSettings | |
| 388 | users[user].glassOutput = "Welcome "..user.." (priv)" | |
| 389 | users[user].here = defaultSettings.hereDefault | |
| 390 | users[user].track = true | |
| 391 | else | |
| 392 | surface.addBox(40, 40, 159, 20, 0x000000, 0.5) | |
| 393 | surface.addText(45, 45, "Not a valid user.", 0xFF0000) | |
| 394 | end | |
| 395 | end | |
| 396 | end | |
| 397 | end | |
| 398 | end | |
| 399 | ||
| 400 | function parseCommand(command, user) | |
| 401 | if not command or not user or not users[user] then | |
| 402 | return | |
| 403 | end | |
| 404 | if command:lower() == "clear" then | |
| 405 | users[user].glassOutput = nil | |
| 406 | return | |
| 407 | elseif command:lower() == "loc default" then | |
| 408 | users[user].here = users[user].settings.hereDefault | |
| 409 | users[user].glassOutput = "Location set to default." | |
| 410 | return | |
| 411 | elseif command:lower() == "loc spawn" then | |
| 412 | users[user].here = users[user].settings.hereSpawn | |
| 413 | users[user].glassOutput = "Location set to spawn." | |
| 414 | return | |
| 415 | elseif command:lower():sub(1, 4) == "loc " then | |
| 416 | local a, b, x, z, y = string.find(command:lower(), "loc[ ]+([-0-9.]+)[ ]+([-0-9.]+)[ ]+([-0-9.]+)") | |
| 417 | if a then | |
| 418 | users[user].here = vector.new(x, y, z) | |
| 419 | users[user].glassOutput = "Location set to x:"..x.." z:"..z.." y:"..y | |
| 420 | return | |
| 421 | end | |
| 422 | local a, b, x, z = string.find(command:lower(), "loc[ ]+([-0-9.]+)[ ]+([-0-9.]+)") | |
| 423 | if a then | |
| 424 | users[user].here = vector.new(x, 65, z) | |
| 425 | users[user].glassOutput = "Location set to x:"..x.." z:"..z | |
| 426 | return | |
| 427 | end | |
| 428 | users[user].glassOutput = "Usage: loc {default|spawn|x z y} to set tracking location."
| |
| 429 | return | |
| 430 | elseif command:lower() == "track" then | |
| 431 | users[user].track = not users[user].track | |
| 432 | if users[user].track then | |
| 433 | users[user].glassOutput = "Tracking turned on." | |
| 434 | else | |
| 435 | users[user].glassOutput = "Tracking turned off." | |
| 436 | end | |
| 437 | return | |
| 438 | elseif command:lower():sub(1, 6) == "track " then | |
| 439 | local a, b, x, y = string.find(command:lower(), "track[ ]+(%d+)[ ]+(%d+)") | |
| 440 | if a then | |
| 441 | users[user].settings.trackLoc.x = x | |
| 442 | users[user].settings.trackLoc.y = y | |
| 443 | users[user].glassOutput = "Track window location set to x:"..x.." y:"..y | |
| 444 | track = true | |
| 445 | writeSettings(user, users[user].settings) | |
| 446 | return | |
| 447 | end | |
| 448 | users[user].glassOutput = "Usage: track <x y> Toggle track and set window location." | |
| 449 | return | |
| 450 | elseif command:lower():sub(1, 7) == "output " then | |
| 451 | local a, b, x, y, l = string.find(command:lower(), "output[ ]+(%d+)[ ]+(%d+)[ ]+(%d+)") | |
| 452 | if a then | |
| 453 | users[user].settings.outputLoc.x = x | |
| 454 | users[user].settings.outputLoc.y = y | |
| 455 | users[user].settings.outputLoc.l = l | |
| 456 | users[user].glassOutput = "Track window location set to x:"..x.." y:"..y | |
| 457 | writeSettings(user, users[user].settings) | |
| 458 | return | |
| 459 | end | |
| 460 | users[user].glassOutput = "Usage: output <x y length> Set output window location and length." | |
| 461 | return | |
| 462 | elseif command:lower():sub(1, 5) == "count" then | |
| 463 | if not me then | |
| 464 | users[user].glassOutput = "No ME interface found." | |
| 465 | return | |
| 466 | end | |
| 467 | local a, b, id, dmg = string.find(command:lower(), "count[ ]+(%d+):(%d+)") | |
| 468 | if a then | |
| 469 | local n = me.countOfItemType(id, dmg) | |
| 470 | users[user].glassOutput = "Count: "..n | |
| 471 | return | |
| 472 | end | |
| 473 | users[user].glassOutput = "Usage: count id:dmg" | |
| 474 | return | |
| 475 | elseif command:lower():sub(1, 5) == "craft" then | |
| 476 | if not me then | |
| 477 | users[user].glassOutput = "No ME interface found." | |
| 478 | return | |
| 479 | end | |
| 480 | local a, b, id, dmg, qty = string.find(command:lower(), "craft[ ]+(%d+):(%d+)[ ]+(%d+)") | |
| 481 | if a then | |
| 482 | local n = me.requestCrafting({id=tonumber(id), dmg=tonumber(dmg), qty=tonumber(qty)})
| |
| 483 | users[user].glassOutput = "Crafting requested." | |
| 484 | return | |
| 485 | end | |
| 486 | users[user].glassOutput = "Usage: craft id:dmg quantity" | |
| 487 | return | |
| 488 | elseif command:lower():sub(1, 7) == "deliver" then | |
| 489 | if not me then | |
| 490 | users[user].glassOutput = "No ME interface found." | |
| 491 | return | |
| 492 | end | |
| 493 | local a, b, id, dmg, qty = string.find(command:lower(), "deliver[ ]+(%d+):(%d+)[ ]+(%d+)") | |
| 494 | if a then | |
| 495 | local n = me.extractItem({id=tonumber(id), dmg=tonumber(dmg), qty=tonumber(qty)}, "up")
| |
| 496 | users[user].glassOutput = "Delivered "..n.." items." | |
| 497 | return | |
| 498 | end | |
| 499 | users[user].glassOutput = "Usage: deliver id:dmg quantity" | |
| 500 | return | |
| 501 | elseif command:lower() == "worlds" then | |
| 502 | users[user].glassOutput = "Available worlds:" | |
| 503 | for k, v in pairs(worlds) do | |
| 504 | if k ~= "camouflage" then | |
| 505 | users[user].glassOutput = users[user].glassOutput.." "..k | |
| 506 | end | |
| 507 | end | |
| 508 | elseif command:lower():sub(1, 9) == "highlight" then | |
| 509 | local a, b, u = string.find(command, "highlight[ ]+([^ ]+)") | |
| 510 | if a then | |
| 511 | if u == "clear" then | |
| 512 | highlight = "" | |
| 513 | else | |
| 514 | highlight = u | |
| 515 | users[user].glassOutput = "Now highlighting "..highlight | |
| 516 | end | |
| 517 | end | |
| 518 | return | |
| 519 | elseif command:lower():sub(1, 5) == "world" then | |
| 520 | users[user].settings.worldFilter = "world" | |
| 521 | local a, b, w = string.find(command:lower(), "world[ ]+([^ ]+)") | |
| 522 | if a then | |
| 523 | users[user].settings.worldFilter = w | |
| 524 | end | |
| 525 | users[user].glassOutput = "World filter set to: "..users[user].settings.worldFilter | |
| 526 | writeSettings(user, users[user].settings) | |
| 527 | return | |
| 528 | elseif command:lower() == "help" then | |
| 529 | users[user].glassOutput = "Commands available: track, loc, output, clear, count, craft, deliver, world, worlds" | |
| 530 | if defaultSettings.privUsers[user] then | |
| 531 | users[user].glassOutput = users[user].glassOutput..", register, unregister" | |
| 532 | end | |
| 533 | return | |
| 534 | end | |
| 535 | if defaultSettings.privUsers[user] then | |
| 536 | if command:sub(1, 8) == "register" then | |
| 537 | local a, b, u = string.find(command, "register[ ]+([^ ]+)") | |
| 538 | if a then | |
| 539 | local filename, _ = u:gsub(" ", "_")
| |
| 540 | filename = filename..".settings" | |
| 541 | local settingsFile = fs.combine(settingsDirectory, filename) | |
| 542 | local defaultFile = fs.combine(settingsDirectory, "default.settings") | |
| 543 | fs.copy(defaultFile, settingsFile) | |
| 544 | users[user].glassOutput = "Registered glass user "..u | |
| 545 | else | |
| 546 | users[user].glassOutput = "Usage: register <username>" | |
| 547 | end | |
| 548 | return | |
| 549 | elseif command:sub(1, 10) == "unregister" then | |
| 550 | local a, b, u = string.find(command, "unregister[ ]+([^ ]+)") | |
| 551 | if a then | |
| 552 | local filename, _ = u:gsub(" ", "_")
| |
| 553 | filename = filename..".settings" | |
| 554 | local settingsFile = fs.combine(settingsDirectory, filename) | |
| 555 | if fs.exists(settingsFile) then | |
| 556 | fs.delete(settingsFile) | |
| 557 | users[u] = nil | |
| 558 | users[user].glassOutput = "Unregistered glass user "..u | |
| 559 | else | |
| 560 | users[user].glassOutput = "User "..u.." was not registered." | |
| 561 | end | |
| 562 | else | |
| 563 | users[user].glassOutput = "Usage: register <username>" | |
| 564 | end | |
| 565 | return | |
| 566 | end | |
| 567 | end | |
| 568 | end | |
| 569 | ||
| 570 | function main() | |
| 571 | refreshTimer = os.startTimer(2.0) | |
| 572 | refresh() | |
| 573 | while not endProgram do | |
| 574 | event, p1, p2, p3, p4 = os.pullEvent() | |
| 575 | if event == "timer" then | |
| 576 | refreshTimer = os.startTimer(2.0) | |
| 577 | refresh() | |
| 578 | elseif event == "monitor_touch" then | |
| 579 | mapMode = not mapMode | |
| 580 | refreshTimer = os.startTimer(2.0) | |
| 581 | refresh() | |
| 582 | elseif event == "chat_command" then | |
| 583 | parseCommand(p1, p2) | |
| 584 | -- The command may have taken more than a refresh tick so make sure | |
| 585 | -- the timer is restarted. | |
| 586 | refreshTimer = os.startTimer(2.0) | |
| 587 | refresh() | |
| 588 | elseif event == "key" then | |
| 589 | if p1 == keys.q then | |
| 590 | endProgram = true | |
| 591 | sleep(0) | |
| 592 | end | |
| 593 | end | |
| 594 | end | |
| 595 | end | |
| 596 | ||
| 597 | -- Initialization of global variables | |
| 598 | mon = getDevice("monitor")
| |
| 599 | glass = getDevice("glassesbridge")
| |
| 600 | me = getDevice("me_interface")
| |
| 601 | ||
| 602 | endProgram = false | |
| 603 | mapMode = true | |
| 604 | ||
| 605 | xLim = {-4530, 10765}
| |
| 606 | - | mon.setBackgroundColor(colors.black) |
| 606 | + | |
| 607 | ||
| 608 | -- Initialize the monitors | |
| 609 | mon.setTextScale(0.5) | |
| 610 | mon.setBackgroundColor(cb) | |
| 611 | mon.clear() | |
| 612 | monW, monH = mon.getSize() | |
| 613 | ||
| 614 | if glass then | |
| 615 | glass.clear() | |
| 616 | end | |
| 617 | ||
| 618 | -- Get the current timestamp from the livemap server | |
| 619 | -- because computercraft doesn't have access to the | |
| 620 | -- real time. | |
| 621 | fh = http.get("http://tekkit.craftersland.net:25800/up/world/world/111")
| |
| 622 | s = fh.readAll() | |
| 623 | fh.close() | |
| 624 | _,_,ts = string.find(s, "{\"timestamp\":(%d+).")
| |
| 625 | ||
| 626 | -- Players and player sort table. | |
| 627 | playerCount = 0 | |
| 628 | players = {}
| |
| 629 | st = {}
| |
| 630 | worlds = {}
| |
| 631 | users = {}
| |
| 632 | highlight = "" | |
| 633 | ||
| 634 | -- Default settings. | |
| 635 | if fs.isDir("/disk/settings") then
| |
| 636 | settingsDirectory = "/disk/settings" | |
| 637 | elseif fs.isDir("/settings") then
| |
| 638 | settingsDirectory = "/settings" | |
| 639 | else | |
| 640 | print("Could not locate settings directory!")
| |
| 641 | exit() | |
| 642 | end | |
| 643 | print("TrackerGlass by MorgosMaci initialized.")
| |
| 644 | print("Using settings directory "..settingsDirectory)
| |
| 645 | defaultSettings = readSettings("default")
| |
| 646 | if not defaultSettings then | |
| 647 | defaultSettings = {}
| |
| 648 | defaultSettings.worldFilter = "world" | |
| 649 | defaultSettings.hereDefault = vector.new(-314, 100, -2538) | |
| 650 | defaultSettings.hereSpawn = vector.new(910, 65, 1035) | |
| 651 | defaultSettings.trackLoc = {x=1, y=1}
| |
| 652 | defaultSettings.outputLoc = {x=400, y=40, l=40}
| |
| 653 | defaultSettings.privUsers = { ["MorgosMaci"]=true }
| |
| 654 | writeSettings("default", defaultSettings)
| |
| 655 | end | |
| 656 | ||
| 657 | -- Main program. This calls the main function and traps all errors. | |
| 658 | -- Additionally it clears all of the displays so that it is obvious | |
| 659 | -- when the program exits. | |
| 660 | ||
| 661 | arg = { ... }
| |
| 662 | local ok, err = pcall(main) | |
| 663 | - | mon.setBackgroundColor(colors.black) |
| 663 | + | |
| 664 | print(err) | |
| 665 | end | |
| 666 | -- Clear all the existing displays. | |
| 667 | mon.setBackgroundColor(cb) | |
| 668 | mon.clear() | |
| 669 | if glass then | |
| 670 | glass.clear() | |
| 671 | for _, user in pairs(glass.getUsers()) do | |
| 672 | local surface = glass.getUserSurface(user) | |
| 673 | if surface then | |
| 674 | surface.clear() | |
| 675 | end | |
| 676 | end | |
| 677 | end |