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