-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlog.lua
600 lines (500 loc) · 18.6 KB
/
log.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
-- Carl Frank Otto III
-- GitHub: https://github.com/M45-Science/SoftMod
-- License: MPL 2.0
local function protectPin(event)
local player = game.players[event.player_index]
if storage.SM_Store.mapPin.tag_number == event.tag.tag_number then
UTIL_MapPin()
UTIL_SmartPrint(player, "*** You can not edit or delete the discord invite pin.")
return true
end
return false
end
local function rejectPin(event)
local player = game.players[event.player_index]
local ltext = string.lower(event.tag.text)
if string.find(ltext, "http") or
string.find(ltext, "discord.gg") then
UTIL_SmartPrint(player, "URLs are not allowed in map pins.")
event.tag.destroy()
return true
end
return false
end
-- Create map tag -- log
function LOG_TagAdded(event)
if not event or not event.player_index or not event.tag then
return
end
local player = game.players[event.player_index]
if rejectPin(event) then
return
end
if event.tag.icon and event.tag.icon.name then
UTIL_MsgAll(player.name .. " add-tag "
.. UTIL_GPSObj(event.tag) .. " : " .. event.tag.icon.name .. " " .. event.tag.text)
else
UTIL_MsgAll(player.name .. " add-tag "
.. UTIL_GPSObj(event.tag) .. " : " .. event.tag.text)
end
end
-- Edit map tag -- log
function LOG_TagMod(event)
if not event or not event.player_index or not event.tag then
return
end
local player = game.players[event.player_index]
if protectPin(event) then
return
end
if rejectPin(event) then
return
end
if event.tag.icon and event.tag.icon.name then
UTIL_MsgAll(player.name .. " edit-tag "
.. UTIL_GPSObj(event.tag) .. " : " .. event.tag.icon.name .. " " .. event.tag.text)
else
UTIL_MsgAll(player.name .. " edit-tag "
.. UTIL_GPSObj(event.tag) .. " : " .. event.tag.text)
end
end
-- Delete map tag -- log
function LOG_TagDel(event)
if not event or not event.player_index or not event.tag then
return
end
local player = game.players[event.player_index]
if protectPin(event) then
return
end
if event.tag.icon and event.tag.icon.name then
UTIL_MsgAll(player.name .. " delete-tag "
.. UTIL_GPSObj(event.tag) .. " : " .. event.tag.icon.name .. " " .. event.tag.text)
else
UTIL_MsgAll(player.name .. " delete-tag "
.. UTIL_GPSObj(event.tag) .. " : " .. event.tag.text)
end
end
-- Player disconnect messages, with reason (Fact >= v1.1)
function LOG_PlayerLeft(event)
if not event or not event.player_index or not storage.PData or not storage.PData[event.player_index] then
return
end
if storage.PData[event.player_index].lastOnline then
storage.PData[event.player_index].lastOnline = game.tick
end
local player = game.players[event.player_index]
if event.reason then
local reason = { "(quit)", "(dropped)", "(reconnecting)", "(wrong input)", "(too many desync)",
"(cannot keep up)", "(afk)", "(kicked)", "(kicked and deleted)", "(banned)",
"(switching servers)", "(unknown reason)" }
UTIL_MsgDiscord(player.name .. " disconnected. " .. reason[event.reason + 1])
else
UTIL_MsgDiscord(player.name .. " disconnected!")
end
ONLINE_UpdatePlayerList()
end
function LOG_Redo(event)
if not event or not event.player_index or not event.actions then
return
end
local player = game.players[event.player_index]
if not player or not player.character then
return
end
if not UTIL_Is_New(player) and not UTIL_Is_Member(player) then
return
end
local buf = ""
for _, act in pairs(event.actions) do
if buf ~= "" then
buf = buf .. ", "
end
buf = buf .. act.type
end
UTIL_ConsolePrint("[ACT] " .. player.name .. " redo " .. buf .. player.character.gps_tag)
end
function LOG_Undo(event)
if not event or not event.player_index or not event.actions then
return
end
local player = game.players[event.player_index]
if not player or not player.character then
return
end
if not UTIL_Is_New(player) and not UTIL_Is_Member(player) then
return
end
local buf = ""
for _, act in pairs(event.actions) do
if buf ~= "" then
buf = buf .. ", "
end
buf = buf .. act.type
end
UTIL_ConsolePrint("[ACT] " .. player.name .. " undo " .. buf .. player.character.gps_tag)
end
function LOG_TrainSchedule(event)
if not event or not event.player_index or not event.train then
return
end
local player = game.players[event.player_index]
local tObj = event.train.front_stock
if tObj then
local msg = player.name ..
" changed schedule on train ID " .. event.train.id .. " at " .. UTIL_GPSObj(tObj)
if UTIL_Is_Regular(player) or UTIL_Is_Veteran(player) or player.admin then
UTIL_ConsolePrint("[ACT] " .. msg)
else
UTIL_MsgAll(msg)
end
end
end
function LOG_EntDied(event)
if event and event.entity then
if event.entity.name == "character" then
return
end
UTIL_ConsolePrint(event.entity.name .. " died at " .. event.entity.gps_tag)
end
end
function LOG_PickedItem(event)
if event and event.player_index and event.item_stack then
local player = game.players[event.player_index]
if not player or not player.character then
return
end
if not UTIL_Is_New(player) and not UTIL_Is_Member(player) then
return
end
local buf = ""
for _, item in pairs(event.item_stack) do
if buf ~= "" then
buf = buf .. " "
end
if item then
buf = buf .. item
end
end
if buf ~= "" then
UTIL_ConsolePrint("[ACT] " .. player.name .. " picked up " .. buf .. " at " .. player.character.gps_tag)
end
end
end
function LOG_DroppedItem(event)
if event and event.player_index and event.entity then
local player = game.players[event.player_index]
if not player or not player.character then
return
end
UTIL_ConsolePrint("[ACT] " ..
player.name .. " dropped " .. event.entity.name .. " at " .. player.character.gps_tag)
end
end
-- Deconstruction planner warning
function LOG_Decon(event)
if event and event.player_index and event.area then
local player = game.players[event.player_index]
local area = event.area
if not player or not player.character then
return
end
if player and area and area.left_top then
local decon_size = UTIL_Distance(area.left_top, area.right_bottom)
-- Don't bother if selection is zero.
if decon_size >= 1 then
local msg = ""
if event.alt then
msg = "[ACT] " ..
player.name ..
" at " ..
player.character.gps_tag ..
" is unmarking for deconstruction " .. UTIL_Area(decon_size, event.area)
else
msg = "[ACT] " ..
player.name ..
" at " .. player.character.gps_tag .. " is deconstructing " .. UTIL_Area(decon_size, event.area)
if UTIL_Is_New(player) or UTIL_Is_Member(player) then -- Dont bother with regulars/moderators
if not UTIL_Is_Banished(player) then -- Don't let bansihed players use this to spam
UTIL_MsgAll(msg)
end
end
end
UTIL_ConsolePrint(msg)
end
end
end
end
function LOG_MarkedUpgrade(event)
if event and event.player_index and event.entity then
local player = game.players[event.player_index]
local obj = event.entity
if player then
local msg = "[ACT] " .. player.name .. " marked for upgrade " .. obj.name .. " at " .. UTIL_GPSObj(obj)
if player.surface and player.surface.index ~= 1 then
msg = msg .. " (" .. player.surface.name .. ")"
end
if UTIL_Is_New(player) or UTIL_Is_Member(player) then -- Dont bother with regulars/moderators
if not UTIL_Is_Banished(player) then -- Don't let bansihed players use this to spam
if UTIL_WarnOkay(event.player_index) then
UTIL_MsgAll(msg)
end
end
end
UTIL_ConsolePrint(msg)
end
end
end
function LOG_CancelUpgrade(event)
if event and event.player_index and event.entity then
local player = game.players[event.player_index]
local obj = event.entity
if player then
local msg = "[ACT] " .. player.name .. " cancelled upgrade " .. obj.name .. " at " .. UTIL_GPSObj(obj)
if player.surface and player.surface.index ~= 1 then
msg = msg .. " (" .. player.surface.name .. ")"
end
if UTIL_Is_New(player) or UTIL_Is_Member(player) then -- Dont bother with regulars/moderators
if not UTIL_Is_Banished(player) then -- Don't let bansihed players use this to spam
if UTIL_WarnOkay(event.player_index) then
UTIL_MsgAll(msg)
end
end
end
UTIL_ConsolePrint(msg)
end
end
end
function LOG_MarkDecon(event)
if event and event.player_index and event.entity then
local player = game.players[event.player_index]
local obj = event.entity
if player then
local msg = "[ACT] " .. player.name .. " marked for deconstruction " .. obj.name .. " at " .. UTIL_GPSObj(obj)
if player.surface and player.surface.index ~= 1 then
msg = msg .. " (" .. player.surface.name .. ")"
end
if UTIL_Is_New(player) or UTIL_Is_Member(player) then -- Dont bother with regulars/moderators
if not UTIL_Is_Banished(player) then -- Don't let bansihed players use this to spam
if UTIL_WarnOkay(event.player_index) then
UTIL_MsgAll(msg)
end
end
end
UTIL_ConsolePrint(msg)
end
end
end
function LOG_CancelDecon(event)
if event and event.player_index and event.entity then
local player = game.players[event.player_index]
local obj = event.entity
if not UTIL_Is_New(player) and not UTIL_Is_Member(player) then
return
end
if player then
local msg = "[ACT] " .. player.name .. " cancelled deconstruction " .. obj.name .. " at " .. UTIL_GPSObj(obj)
if player.surface and player.surface.index ~= 1 then
msg = msg .. " (" .. player.surface.name .. ")"
end
if UTIL_Is_New(player) or UTIL_Is_Member(player) then -- Dont bother with regulars/moderators
if not UTIL_Is_Banished(player) then -- Don't let bansihed players use this to spam
if UTIL_WarnOkay(event.player_index) then
UTIL_MsgAll(msg)
end
end
end
UTIL_ConsolePrint(msg)
end
end
end
function LOG_Flushed(event)
if event and event.player_index then
local player = game.players[event.player_index]
local obj = event.entity
if player and event.amount and event.fluid and event.amount >= 1 then
local msg = "[ACT] " ..
player.name ..
" flushed " ..
obj.name ..
" of " .. math.floor(event.amount) .. " " .. event.fluid .. " at " .. obj.gps_tag
if player.surface and player.surface.index ~= 1 then
msg = msg .. " (" .. player.surface.name .. ")"
end
if UTIL_Is_New(player) or UTIL_Is_Member(player) then -- Dont bother with regulars/moderators
UTIL_MsgAll(msg)
end
UTIL_ConsolePrint(msg)
end
end
end
function LOG_PlayerDrive(event)
if event.player_index and event.entity then
local player = game.players[event.player_index]
if player then
local msg = ""
if player.vehicle then
msg = "[ACT] " ..
player.name ..
" got in of a " ..
event.entity.name .. " at " .. event.entity.gps_tag
else
msg = "[ACT] " ..
player.name ..
" got out of a " ..
event.entity.name .. " at " .. event.entity.gps_tag
end
if player.surface and player.surface.index ~= 1 then
msg = msg .. " (" .. player.surface.name .. ")"
end
if UTIL_Is_New(player) or UTIL_Is_Member(player) then -- Dont bother with regulars/moderators
UTIL_MsgAll(msg)
end
UTIL_ConsolePrint(msg)
end
end
end
function LOG_OrderLaunch(event)
if event.player_index and event.rocket_silo then
local player = game.players[event.player_index]
local msg = "[ACT] " ..
player.name .. " ordered a rocket launch at " .. event.rocket_silo.gps_tag
UTIL_ConsolePrint(msg)
UTIL_MsgAll(msg)
end
end
function LOG_FastTransferred (event)
if event and event.player_index and event.entity then
local player = game.players[event.player_index]
local obj = event.entity
if not UTIL_Is_New(player) and not UTIL_Is_Member(player) then
return
end
if player and obj then
if event.from_player then
UTIL_ConsolePrint("[ACT] " ..
player.name .. " fast-transferred items to " .. obj.name .. " at " .. obj.gps_tag)
else
UTIL_ConsolePrint("[ACT] " ..
player.name .. " fast-transferred items from " .. obj.name .. " at " .. obj.gps_tag)
end
end
end
end
function LOG_InvChanged(event)
if event and event.player_index then
local player = game.players[event.player_index]
if not player or not player.character then
return
end
if not UTIL_Is_New(player) and not UTIL_Is_Member(player) then
return
end
if player then
UTIL_ConsolePrint("[ACT] " .. player.name .. " transferred some items at " .. player.character.gps_tag)
end
end
end
-- EVENTS--
-- Command logging
function LOG_ConsoleCmd(event)
if event and event.command and event.parameters then
local command = ""
local args = ""
if event.command then
command = event.command
end
if event.parameters then
args = event.parameters
end
if event.player_index then
local player = game.players[event.player_index]
print(string.format("[CMD] NAME: %s, COMMAND: %s, ARGS: %s", player.name, command, args))
end
end
end
-- Research Finished -- discord
function LOG_ResearchFinished(event)
if event and event.research and not event.by_script then
if event.research.level and event.research.level > 1 then
UTIL_MsgDiscord("Research " ..
event.research.name .. " (level " .. event.research.level - 1 .. ") completed.")
else
UTIL_MsgDiscord("Research " .. event.research.name .. " completed.")
end
end
end
function LOG_BuiltEnt(event)
if not event or not event.player_index or not event.entity then
return
end
local player = game.players[event.player_index]
local obj = event.entity
if obj.name == "programmable-speaker" or
(obj.name == "entity-ghost" and obj.ghost_name == "programmable-speaker") then
UTIL_MsgAll(player.name .. " placed a speaker at " .. obj.gps_tag)
return
end
if obj.name ~= "tile-ghost" and obj.name ~= "tile" then
if obj.name ~= "entity-ghost" then
UTIL_ConsolePrint("[ACT] " .. player.name .. " placed " .. obj.name .. " " .. obj.gps_tag)
else
if UTIL_WarnOkay(event.player_index) then
UTIL_ConsolePrint("[ACT] " ..
player.name .. " placed-ghost " .. obj.name .. " " .. obj.gps_tag ..
obj.ghost_name)
end
end
end
end
function LOG_PreMined(event)
if not event or not event.player_index or not event.entity then
return
end
local player = game.players[event.player_index]
local obj = event.entity
if obj.force.name ~= "enemy" and obj.force.name ~= "neutral" then
if obj.name ~= "tile-ghost" and obj.name ~= "tile" then
if obj.name ~= "entity-ghost" then
-- log
UTIL_ConsolePrint("[ACT] " .. player.name .. " mined " .. obj.name .. " " .. obj.gps_tag)
-- Mark player as having picked up an item, and needing to be cleaned.
if storage.PData[event.player_index].cleaned then
storage.PData[event.player_index].cleaned = false
end
else
UTIL_ConsolePrint("[ACT] " ..
player.name .. " mined-ghost " .. obj.name .. " " .. obj.gps_tag ..
obj.ghost_name)
end
end
else
EVENT_Loot(event)
end
end
function LOG_Rotated(event)
if not event or not event.player_index or not event.previous_direction then
return
end
local player = game.players[event.player_index]
local obj = event.entity
-- If player and object are valid
if obj.name ~= "tile-ghost" and obj.name ~= "tile" then
if obj.name ~= "entity-ghost" then
UTIL_ConsolePrint("[ACT] " .. player.name .. " rotated " .. obj.name .. " " .. obj.gps_tag)
else
UTIL_ConsolePrint("[ACT] " ..
player.name .. " rotated ghost " .. obj.name .. obj.gps_tag ..
" " .. obj.ghost_name)
end
end
end
function LOG_Banned(event)
if not event or not event.player_index then
return
end
local player = game.players[event.player_index]
UTIL_DumpInv(player, true)
UTIL_MsgAllSys(player.name .. "'s items have been left at spawn, so they can be recovered.")
end