-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerReportUI.cs
More file actions
1264 lines (1099 loc) · 52.8 KB
/
PlayerReportUI.cs
File metadata and controls
1264 lines (1099 loc) · 52.8 KB
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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Facepunch;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Player Report UI", "gamezoneone", "1.4.0")]
[Description("In-game player reports with CUI form, environment snapshot, Discord webhook and optional collector.")]
public class PlayerReportUI : RustPlugin
{
private const string UiRoot = "PlayerRptUI.Root";
private const string UiDropdown = "PlayerRptUI.Dropdown";
private const string UiShotUrlsBorder = "PlayerRptUI.ShotUrlsBorder";
private const string UiShotUrlsFill = "PlayerRptUI.ShotUrlsFill";
private const string UiDetailsBorder = "PlayerRptUI.DetailsBorder";
private const string UiDetailsFill = "PlayerRptUI.DetailsFill";
private const string PermUse = "playerreportui.use";
private const string PermAdmin = "playerreportui.admin";
private const string InputBorderColor = "0.32 0.55 0.82 0.92";
private const string InputFillColor = "0.07 0.08 0.11 1";
private const string InputTextColor = "0.93 0.94 0.97 1";
private PluginConfig _config;
private readonly Dictionary<ulong, ReportDraft> _drafts = new Dictionary<ulong, ReportDraft>();
private readonly Dictionary<ulong, double> _cooldownUntil = new Dictionary<ulong, double>();
private ReportHistoryFile _reportHistory;
private const string HistoryDataPath = "PlayerReportUI/report_history";
private sealed class ReportDraft
{
public string Category = string.Empty;
public ulong? TargetSteamId;
public string TargetName = string.Empty;
public string Details = string.Empty;
public string ScreenshotUrls = string.Empty;
public int PlayerPage;
public bool ReasonDropdownOpen;
}
private sealed class ReportHistoryFile
{
public List<ReportHistoryEntry> Entries = new List<ReportHistoryEntry>();
}
private sealed class ReportHistoryEntry
{
public string TraceId;
public string UtcIso;
public string ReporterName;
public string ReporterId;
public string Category;
public string TargetShort;
public string DetailsPreview;
}
private sealed class PluginConfig
{
[JsonProperty("Open Command")]
public string OpenCommand = "report";
[JsonProperty("Discord Webhook URL (empty = disabled)")]
public string DiscordWebhookUrl = string.Empty;
[JsonProperty("Optional: Collector URL (e.g. MongoBridge)")]
public string CollectorUrl = string.Empty;
[JsonProperty("Optional: Collector API Key")]
public string CollectorApiKey = string.Empty;
[JsonProperty("Optional: Server ID (Collector)")]
public string ServerId = string.Empty;
[JsonProperty("Optional: Instance Name (Collector)")]
public string InstanceName = string.Empty;
[JsonProperty("Send Collector Event")]
public bool SendCollectorEvent = true;
[JsonProperty("Report Categories (Dropdown)")]
public List<string> Categories = new List<string>
{
"Cheating / Hacking",
"Griefing / RDM",
"Insults / Toxic",
"Bug / Technical",
"Other"
};
[JsonProperty("Players Per Page (Online Selection)")]
public int PlayersPerPage = 6;
[JsonProperty("Minimum Description Length")]
public int MinDetailsLength = 15;
[JsonProperty("Cooldown Seconds")]
public float CooldownSeconds = 120f;
[JsonProperty("Max Description Characters")]
public int MaxDetailsChars = 500;
[JsonProperty("Max Evidence URL Characters")]
public int MaxScreenshotUrlChars = 600;
[JsonProperty("Enable Surrounding Snapshot on Submit")]
public bool EnableSurroundSnapshot = true;
[JsonProperty("Snapshot Radius (meters)")]
public float SnapshotRadius = 50f;
[JsonProperty("Snapshot: Max Items Per Inventory Container")]
public int SnapshotMaxItemsPerContainer = 48;
[JsonProperty("Snapshot: Max Vehicle / Mount Entries")]
public int SnapshotMaxVehicles = 40;
[JsonProperty("Save Snapshot as JSON File (oxide/data)")]
public bool SaveSnapshotDataFile = true;
[JsonProperty("Require Target Player")]
public bool RequireTargetPlayer = false;
[JsonProperty("Auto-Grant Use Permission to Oxide Default Group")]
public bool AutoGrantUseToDefaultGroup = true;
[JsonProperty("Admin: Disable Report List and /reportadmin")]
public bool DisableAdminReportFeatures = false;
[JsonProperty("Admin: Max History Entries")]
public int MaxReportHistoryEntries = 40;
[JsonProperty("History In-Memory Only (no oxide/data)")]
public bool ReportHistoryMemoryOnly = false;
}
private sealed class EventActorDto
{
[JsonProperty("id")] public string Id;
[JsonProperty("name")] public string Name;
[JsonProperty("steamId")] public string SteamId;
[JsonProperty("authLevel")] public int? AuthLevel;
}
private sealed class RustEventDto
{
[JsonProperty("eventType")] public string EventType;
[JsonProperty("eventCategory")] public string EventCategory;
[JsonProperty("serverId")] public string ServerId;
[JsonProperty("instanceName")] public string InstanceName;
[JsonProperty("timestamp")] public string Timestamp;
[JsonProperty("source")] public string Source;
[JsonProperty("traceId")] public string TraceId;
[JsonProperty("actor")] public EventActorDto Actor;
[JsonProperty("target")] public EventActorDto Target;
[JsonProperty("payload")] public Dictionary<string, object> Payload;
[JsonProperty("raw")] public object Raw;
}
private sealed class DiscordEmbedImage
{
[JsonProperty("url")] public string Url;
}
private sealed class DiscordEmbedFooter
{
[JsonProperty("text")] public string Text;
}
private sealed class DiscordEmbed
{
[JsonProperty("title")] public string Title;
[JsonProperty("color")] public int Color;
[JsonProperty("fields")] public List<DiscordField> Fields;
[JsonProperty("timestamp")] public string Timestamp;
[JsonProperty("image", NullValueHandling = NullValueHandling.Ignore)]
public DiscordEmbedImage Image;
[JsonProperty("footer", NullValueHandling = NullValueHandling.Ignore)]
public DiscordEmbedFooter Footer;
}
private sealed class DiscordField
{
[JsonProperty("name")] public string Name;
[JsonProperty("value")] public string Value;
[JsonProperty("inline")] public bool Inline;
}
private sealed class DiscordWebhookBody
{
[JsonProperty("embeds")] public List<DiscordEmbed> Embeds;
}
#region Lang
private string T(string key, string userId = null, params object[] args)
{
var msg = lang.GetMessage(key, this, userId);
return args.Length > 0 ? string.Format(msg, args) : msg;
}
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
// UI
["UI.Title"] = "Report Player",
["UI.CategoryLabel"] = "Report Reason",
["UI.CategoryPlaceholder"] = "— select —",
["UI.TargetRequired"] = "Reported Player (required)",
["UI.TargetOptional"] = "Reported Player (optional)",
["UI.ClearSelection"] = "Clear Selection",
["UI.Page"] = "Page {0}/{1}",
["UI.EvidenceLabel"] = "Evidence: Image/Video Links (optional)",
["UI.EvidenceHint"] = "Note: The server cannot take screenshots. Upload them to Discord and paste the links here.",
["UI.DescriptionLabel"] = "Description (min. {0} chars)",
["UI.SnapshotHint"] = "On submit, a surrounding snapshot (~{0} m) with players, inventory and vehicles will be captured.",
["UI.Submit"] = "Submit",
["UI.DropdownTitle"] = "Select Reason",
// Chat
["Chat.NoPermission"] = "<color=#ff6b6b>No permission for /{0}.</color>",
["Chat.UseWithoutArgs"] = "<color=#aaaaaa>Use /{0} without text — the form opens in the UI.</color>",
["Chat.NoDestination"] = "<color=#ff6b6b>Report system: Neither webhook nor collector configured (see PlayerReportUI.json).</color>",
["Chat.Cooldown"] = "<color=#ff6b6b>Cooldown: ~{0} seconds remaining.</color>",
["Chat.SelectCategory"] = "<color=#ff6b6b>Please select a report reason.</color>",
["Chat.SelectTarget"] = "<color=#ff6b6b>Please select a reported player.</color>",
["Chat.DescriptionTooShort"] = "<color=#ff6b6b>Description too short (minimum {0} characters).</color>",
["Chat.Submitted"] = "<color=#7bed9f>Report submitted. Thank you!</color>",
["Chat.AdminNoReports"] = "<color=#aaaaaa>No reports stored yet.</color>",
["Chat.AdminHeader"] = "<color=#7bed9f>Latest reports (max. {0}):</color>",
["Chat.AdminEntry"] = "<color=#aaaaaa> Affected:</color> {0} — {1}",
["Chat.AdminDisabled"] = "<color=#ff6b6b>Report admin list is disabled (config).</color>",
["Chat.AdminNoPermission"] = "<color=#ff6b6b>No permission (playerreportui.admin or admin).</color>",
// Discord embed
["Discord.EmbedTitle"] = "New In-Game Report",
["Discord.TraceField"] = "Trace / File",
["Discord.ServerField"] = "Server",
["Discord.ReporterField"] = "Reporter",
["Discord.ReasonField"] = "Reason",
["Discord.AffectedField"] = "Affected",
["Discord.SnapshotField"] = "Surrounding Snapshot",
["Discord.EvidenceField"] = "Evidence Links",
["Discord.DescriptionField"] = "Description",
// Snapshot
["Snapshot.Summary"] = "Players in radius: {0}, vehicles/mounts: {1}",
["Snapshot.Error"] = "Error: {0}",
}, this);
}
#endregion
protected override void LoadDefaultConfig()
{
_config = new PluginConfig();
SaveConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
_config = Config.ReadObject<PluginConfig>() ?? new PluginConfig();
}
catch
{
PrintWarning("Config could not be read, loading defaults.");
_config = new PluginConfig();
}
if (_config.Categories == null || _config.Categories.Count == 0)
_config.Categories = new PluginConfig().Categories;
if (_config.PlayersPerPage < 3) _config.PlayersPerPage = 3;
if (_config.PlayersPerPage > 20) _config.PlayersPerPage = 20;
if (_config.SnapshotRadius < 5f) _config.SnapshotRadius = 5f;
if (_config.SnapshotRadius > 300f) _config.SnapshotRadius = 300f;
if (_config.SnapshotMaxItemsPerContainer < 8) _config.SnapshotMaxItemsPerContainer = 8;
if (_config.SnapshotMaxVehicles < 5) _config.SnapshotMaxVehicles = 5;
if (_config.MaxReportHistoryEntries < 5) _config.MaxReportHistoryEntries = 5;
if (_config.MaxReportHistoryEntries > 500) _config.MaxReportHistoryEntries = 500;
}
protected override void SaveConfig() => Config.WriteObject(_config, true);
private void Init()
{
permission.RegisterPermission(PermUse, this);
permission.RegisterPermission(PermAdmin, this);
var cmd = string.IsNullOrWhiteSpace(_config.OpenCommand) ? "report" : _config.OpenCommand.Trim();
AddCovalenceCommand(cmd, nameof(CmdOpenReport));
}
private void OnServerInitialized()
{
if (_config.AutoGrantUseToDefaultGroup)
{
const string defaultGroup = "default";
if (!permission.GroupExists(defaultGroup))
{
PrintWarning(
$"Player Report UI: Oxide group '{defaultGroup}' not found — players may lack {PermUse}. Create it or grant the permission manually.");
}
else if (!permission.GroupHasPermission(defaultGroup, PermUse))
{
permission.GrantGroupPermission(defaultGroup, PermUse, this);
Puts($"Player Report UI: Granted {PermUse} to group '{defaultGroup}' (players can use /{_config.OpenCommand ?? "report"}).");
}
}
var hasDiscord = !string.IsNullOrWhiteSpace(_config.DiscordWebhookUrl);
var hasCollector = _config.SendCollectorEvent && !string.IsNullOrWhiteSpace(_config.CollectorUrl);
if (!hasDiscord && !hasCollector)
{
PrintWarning(
"Player Report UI: Neither Discord Webhook nor Collector URL configured — reports cannot be delivered. Edit PlayerReportUI.json.");
}
LoadReportHistory();
}
private void Unload()
{
foreach (var p in BasePlayer.activePlayerList)
{
CuiHelper.DestroyUi(p, UiRoot);
CuiHelper.DestroyUi(p, UiDropdown);
}
_drafts.Clear();
_cooldownUntil.Clear();
}
private void OnPlayerDisconnected(BasePlayer player, string reason)
{
if (player == null) return;
_drafts.Remove(player.userID);
_cooldownUntil.Remove(player.userID);
}
private void CmdOpenReport(IPlayer iPlayer, string command, string[] args)
{
var player = iPlayer?.Object as BasePlayer;
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, PermUse) && !player.IsAdmin)
{
player.ChatMessage(T("Chat.NoPermission", player.UserIDString, _config.OpenCommand ?? "report"));
return;
}
if (args != null && args.Length > 0)
player.ChatMessage(T("Chat.UseWithoutArgs", player.UserIDString, _config.OpenCommand ?? "report"));
OpenOrRefreshUi(player, true);
}
private void OpenOrRefreshUi(BasePlayer player, bool resetDraft)
{
if (!_drafts.TryGetValue(player.userID, out var draft))
_drafts[player.userID] = draft = new ReportDraft();
if (resetDraft)
{
draft.Category = _config.Categories.Count > 0 ? _config.Categories[0] : string.Empty;
draft.TargetSteamId = null;
draft.TargetName = string.Empty;
draft.Details = string.Empty;
draft.ScreenshotUrls = string.Empty;
draft.PlayerPage = 0;
draft.ReasonDropdownOpen = false;
}
CuiHelper.DestroyUi(player, UiRoot);
CuiHelper.DestroyUi(player, UiDropdown);
var uid = player.UserIDString;
var c = new CuiElementContainer();
c.Add(new CuiPanel
{
Image = { Color = "0.08 0.08 0.1 0.97" },
RectTransform = { AnchorMin = "0.18 0.06", AnchorMax = "0.82 0.94" },
CursorEnabled = true
}, "Overlay", UiRoot);
c.Add(new CuiLabel
{
Text = { Text = T("UI.Title", uid), FontSize = 22, Align = TextAnchor.MiddleLeft, Color = "0.95 0.95 1 1" },
RectTransform = { AnchorMin = "0.03 0.91", AnchorMax = "0.55 0.98" }
}, UiRoot);
c.Add(new CuiButton
{
Button = { Color = "0.45 0.15 0.15 0.95", Command = "reportui.close", FadeIn = 0f },
RectTransform = { AnchorMin = "0.9 0.92", AnchorMax = "0.97 0.98" },
Text = { Text = "X", FontSize = 18, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" }
}, UiRoot);
// Category dropdown
c.Add(new CuiLabel
{
Text = { Text = T("UI.CategoryLabel", uid), FontSize = 14, Align = TextAnchor.MiddleLeft, Color = "0.75 0.78 0.9 1" },
RectTransform = { AnchorMin = "0.03 0.84", AnchorMax = "0.28 0.89" }
}, UiRoot);
var catLabel = string.IsNullOrEmpty(draft.Category) ? T("UI.CategoryPlaceholder", uid) : draft.Category;
if (catLabel.Length > 42) catLabel = catLabel.Substring(0, 40) + "…";
c.Add(new CuiButton
{
Button = { Color = "0.2 0.22 0.3 0.95", Command = "reportui.ddtoggle", FadeIn = 0f },
RectTransform = { AnchorMin = "0.28 0.835", AnchorMax = "0.92 0.895" },
Text = { Text = catLabel + " ▼", FontSize = 13, Align = TextAnchor.MiddleLeft, Color = "1 1 1 1" }
}, UiRoot);
// Target player
c.Add(new CuiLabel
{
Text =
{
Text = _config.RequireTargetPlayer ? T("UI.TargetRequired", uid) : T("UI.TargetOptional", uid),
FontSize = 14,
Align = TextAnchor.MiddleLeft,
Color = "0.75 0.78 0.9 1"
},
RectTransform = { AnchorMin = "0.03 0.745", AnchorMax = "0.55 0.8" }
}, UiRoot);
c.Add(new CuiButton
{
Button = { Color = "0.25 0.25 0.3 0.95", Command = "reportui.clearplayer", FadeIn = 0f },
RectTransform = { AnchorMin = "0.58 0.75", AnchorMax = "0.78 0.795" },
Text = { Text = T("UI.ClearSelection", uid), FontSize = 12, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" }
}, UiRoot);
// Player list
var online = new List<BasePlayer>(BasePlayer.activePlayerList.Count);
foreach (var p in BasePlayer.activePlayerList)
{
if (p != null && p.userID != player.userID)
online.Add(p);
}
online.Sort((a, b) => string.Compare(a.displayName, b.displayName, StringComparison.OrdinalIgnoreCase));
int perPage = _config.PlayersPerPage;
int pages = Mathf.Max(1, Mathf.CeilToInt(online.Count / (float)perPage));
if (draft.PlayerPage >= pages) draft.PlayerPage = pages - 1;
if (draft.PlayerPage < 0) draft.PlayerPage = 0;
int start = draft.PlayerPage * perPage;
int end = Mathf.Min(start + perPage, online.Count);
float py = 0.68f;
for (int i = start; i < end; i++)
{
var other = online[i];
bool pick = draft.TargetSteamId == other.userID;
c.Add(new CuiButton
{
Button =
{
Color = pick ? "0.3 0.35 0.55 0.95" : "0.18 0.19 0.24 0.95",
Command = "reportui.pick " + other.userID,
FadeIn = 0f
},
RectTransform = { AnchorMin = $"0.03 {py:F3}", AnchorMax = $"0.48 {py + 0.048f:F3}" },
Text =
{
Text = other.displayName + " (" + other.userID + ")",
FontSize = 12,
Align = TextAnchor.MiddleLeft,
Color = "1 1 1 1"
}
}, UiRoot);
py -= 0.052f;
}
if (pages > 1)
{
c.Add(new CuiButton
{
Button = { Color = "0.22 0.22 0.28 0.95", Command = "reportui.ppage -1", FadeIn = 0f },
RectTransform = { AnchorMin = "0.5 0.68", AnchorMax = "0.56 0.73" },
Text = { Text = "◀", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" }
}, UiRoot);
c.Add(new CuiButton
{
Button = { Color = "0.22 0.22 0.28 0.95", Command = "reportui.ppage 1", FadeIn = 0f },
RectTransform = { AnchorMin = "0.58 0.68", AnchorMax = "0.64 0.73" },
Text = { Text = "▶", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" }
}, UiRoot);
c.Add(new CuiLabel
{
Text =
{
Text = T("UI.Page", uid, draft.PlayerPage + 1, pages),
FontSize = 12,
Align = TextAnchor.MiddleLeft,
Color = "0.8 0.8 0.85 1"
},
RectTransform = { AnchorMin = "0.66 0.68", AnchorMax = "0.95 0.73" }
}, UiRoot);
}
// Evidence links
c.Add(new CuiLabel
{
Text = { Text = T("UI.EvidenceLabel", uid), FontSize = 14, Align = TextAnchor.MiddleLeft, Color = "0.75 0.78 0.9 1" },
RectTransform = { AnchorMin = "0.03 0.555", AnchorMax = "0.55 0.6" }
}, UiRoot);
c.Add(new CuiLabel
{
Text = { Text = T("UI.EvidenceHint", uid), FontSize = 11, Align = TextAnchor.UpperLeft, Color = "0.65 0.68 0.75 1" },
RectTransform = { AnchorMin = "0.52 0.52", AnchorMax = "0.97 0.6" }
}, UiRoot);
c.Add(new CuiPanel
{
Image = { Color = InputBorderColor },
RectTransform = { AnchorMin = "0.026 0.456", AnchorMax = "0.974 0.548" }
}, UiRoot, UiShotUrlsBorder);
c.Add(new CuiPanel
{
Image = { Color = InputFillColor },
RectTransform = { AnchorMin = "0.006 0.08", AnchorMax = "0.994 0.92" }
}, UiShotUrlsBorder, UiShotUrlsFill);
c.Add(new CuiElement
{
Name = "ShotUrlsInput",
Parent = UiShotUrlsFill,
Components =
{
new CuiInputFieldComponent
{
Align = TextAnchor.UpperLeft,
CharsLimit = _config.MaxScreenshotUrlChars,
Command = "reportui.shoturls ",
FontSize = 12,
IsPassword = false,
Text = draft.ScreenshotUrls ?? string.Empty,
NeedsKeyboard = true,
Color = InputTextColor
},
new CuiRectTransformComponent { AnchorMin = "0.03 0.08", AnchorMax = "0.97 0.92" }
}
});
// Description
c.Add(new CuiLabel
{
Text =
{
Text = T("UI.DescriptionLabel", uid, _config.MinDetailsLength),
FontSize = 14,
Align = TextAnchor.MiddleLeft,
Color = "0.75 0.78 0.9 1"
},
RectTransform = { AnchorMin = "0.03 0.405", AnchorMax = "0.7 0.445" }
}, UiRoot);
c.Add(new CuiPanel
{
Image = { Color = InputBorderColor },
RectTransform = { AnchorMin = "0.026 0.138", AnchorMax = "0.974 0.398" }
}, UiRoot, UiDetailsBorder);
c.Add(new CuiPanel
{
Image = { Color = InputFillColor },
RectTransform = { AnchorMin = "0.006 0.04", AnchorMax = "0.994 0.96" }
}, UiDetailsBorder, UiDetailsFill);
c.Add(new CuiElement
{
Name = "DetailsInput",
Parent = UiDetailsFill,
Components =
{
new CuiInputFieldComponent
{
Align = TextAnchor.UpperLeft,
CharsLimit = _config.MaxDetailsChars,
Command = "reportui.details ",
FontSize = 13,
IsPassword = false,
Text = draft.Details ?? string.Empty,
NeedsKeyboard = true,
Color = InputTextColor
},
new CuiRectTransformComponent { AnchorMin = "0.02 0.04", AnchorMax = "0.98 0.96" }
}
});
if (_config.EnableSurroundSnapshot)
{
c.Add(new CuiLabel
{
Text =
{
Text = T("UI.SnapshotHint", uid,
_config.SnapshotRadius.ToString(CultureInfo.InvariantCulture)),
FontSize = 11,
Align = TextAnchor.MiddleLeft,
Color = "0.55 0.7 0.55 1"
},
RectTransform = { AnchorMin = "0.03 0.08", AnchorMax = "0.97 0.125" }
}, UiRoot);
}
c.Add(new CuiButton
{
Button = { Color = "0.2 0.45 0.28 0.95", Command = "reportui.submit", FadeIn = 0f },
RectTransform = { AnchorMin = "0.03 0.02", AnchorMax = "0.32 0.075" },
Text = { Text = T("UI.Submit", uid), FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" }
}, UiRoot);
CuiHelper.AddUi(player, c);
if (draft.ReasonDropdownOpen)
DrawReasonDropdown(player);
}
private void DrawReasonDropdown(BasePlayer player)
{
var uid = player.UserIDString;
var dc = new CuiElementContainer();
dc.Add(new CuiPanel
{
Image = { Color = "0.05 0.05 0.08 0.92" },
RectTransform = { AnchorMin = "0.32 0.35", AnchorMax = "0.68 0.82" },
CursorEnabled = true
}, "Overlay", UiDropdown);
dc.Add(new CuiLabel
{
Text = { Text = T("UI.DropdownTitle", uid), FontSize = 16, Align = TextAnchor.MiddleLeft, Color = "1 1 1 1" },
RectTransform = { AnchorMin = "0.04 0.88", AnchorMax = "0.7 0.97" }
}, UiDropdown);
dc.Add(new CuiButton
{
Button = { Color = "0.35 0.15 0.15 0.95", Command = "reportui.ddclose", FadeIn = 0f },
RectTransform = { AnchorMin = "0.82 0.88", AnchorMax = "0.96 0.97" },
Text = { Text = "×", FontSize = 18, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" }
}, UiDropdown);
float y = 0.82f;
foreach (var cat in _config.Categories)
{
var safe = Uri.EscapeDataString(cat);
dc.Add(new CuiButton
{
Button = { Color = "0.18 0.2 0.26 0.95", Command = "reportui.cat " + safe, FadeIn = 0f },
RectTransform = { AnchorMin = $"0.04 {y - 0.09f:F3}", AnchorMax = $"0.96 {y:F3}" },
Text =
{
Text = cat.Length > 48 ? cat.Substring(0, 46) + "…" : cat,
FontSize = 13,
Align = TextAnchor.MiddleLeft,
Color = "1 1 1 1"
}
}, UiDropdown);
y -= 0.095f;
if (y < 0.12f) break;
}
CuiHelper.AddUi(player, dc);
}
[ConsoleCommand("reportui.close")]
private void CmdUiClose(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null) return;
CuiHelper.DestroyUi(player, UiRoot);
CuiHelper.DestroyUi(player, UiDropdown);
}
[ConsoleCommand("reportui.ddtoggle")]
private void CmdDdToggle(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || !CanUse(player)) return;
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
d.ReasonDropdownOpen = !d.ReasonDropdownOpen;
OpenOrRefreshUi(player, false);
}
[ConsoleCommand("reportui.ddclose")]
private void CmdDdClose(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || !CanUse(player)) return;
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
d.ReasonDropdownOpen = false;
OpenOrRefreshUi(player, false);
}
[ConsoleCommand("reportui.cat")]
private void CmdCat(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || arg.Args == null || arg.Args.Length < 1 || !CanUse(player)) return;
var cat = Uri.UnescapeDataString(string.Join(" ", arg.Args));
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
d.Category = cat;
d.ReasonDropdownOpen = false;
OpenOrRefreshUi(player, false);
}
[ConsoleCommand("reportui.pick")]
private void CmdPick(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || arg.Args == null || arg.Args.Length < 1 || !CanUse(player)) return;
if (!ulong.TryParse(arg.Args[0], out var sid)) return;
BasePlayer target = null;
foreach (var p in BasePlayer.activePlayerList)
{
if (p != null && p.userID == sid) { target = p; break; }
}
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
d.TargetSteamId = sid;
d.TargetName = target != null ? target.displayName : sid.ToString();
OpenOrRefreshUi(player, false);
}
[ConsoleCommand("reportui.clearplayer")]
private void CmdClearPlayer(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || !CanUse(player)) return;
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
d.TargetSteamId = null;
d.TargetName = string.Empty;
OpenOrRefreshUi(player, false);
}
[ConsoleCommand("reportui.ppage")]
private void CmdPlayerPage(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || arg.Args == null || arg.Args.Length < 1 || !CanUse(player)) return;
if (!int.TryParse(arg.Args[0], out var delta)) return;
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
d.PlayerPage += delta;
if (d.PlayerPage < 0) d.PlayerPage = 0;
OpenOrRefreshUi(player, false);
}
[ConsoleCommand("reportui.details")]
private void CmdDetails(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || !CanUse(player)) return;
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
d.Details = arg.Args != null && arg.Args.Length > 0 ? string.Join(" ", arg.Args) : string.Empty;
}
[ConsoleCommand("reportui.shoturls")]
private void CmdShotUrls(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || !CanUse(player)) return;
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
d.ScreenshotUrls = arg.Args != null && arg.Args.Length > 0 ? string.Join(" ", arg.Args) : string.Empty;
}
[ConsoleCommand("reportui.submit")]
private void CmdSubmit(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || !CanUse(player)) return;
var uid = player.UserIDString;
if (string.IsNullOrWhiteSpace(_config.DiscordWebhookUrl) &&
(!_config.SendCollectorEvent || string.IsNullOrWhiteSpace(_config.CollectorUrl)))
{
player.ChatMessage(T("Chat.NoDestination", uid));
return;
}
var now = UnityEngine.Time.realtimeSinceStartupAsDouble;
if (_cooldownUntil.TryGetValue(player.userID, out var until) && now < until)
{
player.ChatMessage(T("Chat.Cooldown", uid, Mathf.CeilToInt((float)(until - now))));
return;
}
if (!_drafts.TryGetValue(player.userID, out var d))
_drafts[player.userID] = d = new ReportDraft();
if (string.IsNullOrWhiteSpace(d.Category))
{
player.ChatMessage(T("Chat.SelectCategory", uid));
return;
}
if (_config.RequireTargetPlayer && !d.TargetSteamId.HasValue)
{
player.ChatMessage(T("Chat.SelectTarget", uid));
return;
}
var details = (d.Details ?? string.Empty).Trim();
if (details.Length < _config.MinDetailsLength)
{
player.ChatMessage(T("Chat.DescriptionTooShort", uid, _config.MinDetailsLength));
return;
}
var traceId = Guid.NewGuid().ToString("N");
Dictionary<string, object> snapshot = null;
if (_config.EnableSurroundSnapshot)
{
try
{
snapshot = BuildSurroundSnapshot(player);
}
catch (Exception ex)
{
PrintWarning($"Snapshot failed: {ex.Message}");
snapshot = new Dictionary<string, object> { ["error"] = ex.Message };
}
if (_config.SaveSnapshotDataFile && snapshot != null)
TryPersistSnapshot(traceId, snapshot);
}
var shotUrls = (d.ScreenshotUrls ?? string.Empty).Trim();
if (!string.IsNullOrWhiteSpace(_config.DiscordWebhookUrl))
SendDiscordWebhook(player, d, details, traceId, snapshot, shotUrls);
if (_config.SendCollectorEvent && !string.IsNullOrWhiteSpace(_config.CollectorUrl))
SendCollectorReport(player, d, details, traceId, snapshot, shotUrls);
_cooldownUntil[player.userID] = now + _config.CooldownSeconds;
CuiHelper.DestroyUi(player, UiRoot);
CuiHelper.DestroyUi(player, UiDropdown);
_drafts.Remove(player.userID);
PushReportHistory(player, d, details, traceId);
player.ChatMessage(T("Chat.Submitted", uid));
}
private void LoadReportHistory()
{
try
{
_reportHistory = Interface.Oxide.DataFileSystem.ReadObject<ReportHistoryFile>(HistoryDataPath);
if (_reportHistory?.Entries == null)
_reportHistory = new ReportHistoryFile();
}
catch
{
_reportHistory = new ReportHistoryFile();
}
}
private void PushReportHistory(BasePlayer reporter, ReportDraft d, string details, string traceId)
{
if (_config.DisableAdminReportFeatures) return;
try
{
if (_reportHistory == null) LoadReportHistory();
var targetShort = d.TargetSteamId.HasValue
? (string.IsNullOrEmpty(d.TargetName) ? d.TargetSteamId.ToString() : d.TargetName)
: "—";
var prev = details.Length > 120 ? details.Substring(0, 117) + "..." : details;
_reportHistory.Entries.Insert(0, new ReportHistoryEntry
{
TraceId = traceId,
UtcIso = DateTime.UtcNow.ToString("o"),
ReporterName = reporter.displayName,
ReporterId = reporter.UserIDString,
Category = d.Category,
TargetShort = targetShort,
DetailsPreview = prev
});
var max = Mathf.Clamp(_config.MaxReportHistoryEntries, 5, 500);
while (_reportHistory.Entries.Count > max)
_reportHistory.Entries.RemoveAt(_reportHistory.Entries.Count - 1);
if (!_config.ReportHistoryMemoryOnly)
Interface.Oxide.DataFileSystem.WriteObject(HistoryDataPath, _reportHistory);
}
catch (Exception ex)
{
PrintWarning($"Report history error: {ex.Message}");
}
}
[ChatCommand("reportadmin")]
private void CmdReportAdmin(BasePlayer player, string command, string[] args)
{
if (player == null) return;
var uid = player.UserIDString;
if (_config.DisableAdminReportFeatures)
{
player.ChatMessage(T("Chat.AdminDisabled", uid));
return;
}
if (!player.IsAdmin && !permission.UserHasPermission(uid, PermAdmin))
{
player.ChatMessage(T("Chat.AdminNoPermission", uid));
return;
}
if (_reportHistory == null) LoadReportHistory();
var n = 15;
if (args != null && args.Length > 0 && int.TryParse(args[0], out var parsed))
n = Mathf.Clamp(parsed, 5, 30);
var list = _reportHistory?.Entries;
if (list == null || list.Count == 0)
{
player.ChatMessage(T("Chat.AdminNoReports", uid));
return;
}
player.ChatMessage(T("Chat.AdminHeader", uid, n));
var take = Mathf.Min(n, list.Count);
for (var i = 0; i < take; i++)
{
var e = list[i];
player.ChatMessage(
$"<color=#cccccc>{i + 1}.</color> <color=#ffd93d>{e.TraceId}</color> | {e.Category} | from {e.ReporterName}");
var det = e.DetailsPreview ?? string.Empty;
if (det.Length > 220) det = det.Substring(0, 217) + "...";
player.ChatMessage(T("Chat.AdminEntry", uid, e.TargetShort, det));
}
}
private bool CanUse(BasePlayer player)
{
return player != null && (player.IsAdmin || permission.UserHasPermission(player.UserIDString, PermUse));
}
private List<object> SerializeContainer(ItemContainer c, int maxItems)
{
var list = new List<object>();
if (c == null || c.itemList == null) return list;
var n = 0;
foreach (var it in c.itemList)
{
if (it == null || it.info == null) continue;
if (n++ >= maxItems) break;
list.Add(new Dictionary<string, object>
{
["shortname"] = it.info.shortname,
["amount"] = it.amount,
["skin"] = it.skin,
["displayName"] = it.name ?? string.Empty,
["position"] = it.position
});
}
return list;
}
private Dictionary<string, object> BuildSurroundSnapshot(BasePlayer reporter)
{
var center = reporter.transform.position;
var r = _config.SnapshotRadius;
var maxI = _config.SnapshotMaxItemsPerContainer;
var seen = new HashSet<string>(StringComparer.Ordinal);
var players = new List<object>();
var vehicles = new List<object>();
var budget = _config.SnapshotMaxVehicles;
var seenVehicleIds = new HashSet<ulong>();
void TryAddPlayer(BasePlayer p, string sourceTag)
{