-
Notifications
You must be signed in to change notification settings - Fork 383
fix: Admin Client disconnect and closed when ban or mute a player #2783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,47 +8,23 @@ namespace Intersect.Client.Interface.Game.Admin; | |||||||||||||
| public partial class BanMuteBox : WindowControl | ||||||||||||||
| { | ||||||||||||||
| private readonly TextBox _textboxReason; | ||||||||||||||
| private readonly ComboBox _comboboxDuration; | ||||||||||||||
| private readonly ComboBox? _comboboxDuration; | ||||||||||||||
| private readonly LabeledCheckBox _checkboxIP; | ||||||||||||||
|
|
||||||||||||||
| private readonly Dictionary<string, int> _dayCount = new() | ||||||||||||||
| private static readonly List<(string Label, int Days)> _durationOptions = new() | ||||||||||||||
| { | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.OneDay, 1 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.TwoDays, 2 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.ThreeDays, 3 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.FourDays, 4 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.FiveDays, 5 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.OneWeek, 7 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.TwoWeeks, 14 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.OneMonth, 30 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.TwoMonths, 60 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.SixMonths, 180 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.OneYear, 365 | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| Strings.BanMute.Forever, 999999 | ||||||||||||||
| }, | ||||||||||||||
| (Strings.BanMute.OneDay, 1), | ||||||||||||||
| (Strings.BanMute.TwoDays, 2), | ||||||||||||||
| (Strings.BanMute.ThreeDays, 3), | ||||||||||||||
| (Strings.BanMute.FourDays, 4), | ||||||||||||||
| (Strings.BanMute.FiveDays, 5), | ||||||||||||||
| (Strings.BanMute.OneWeek, 7), | ||||||||||||||
| (Strings.BanMute.TwoWeeks, 14), | ||||||||||||||
| (Strings.BanMute.OneMonth, 30), | ||||||||||||||
| (Strings.BanMute.TwoMonths, 60), | ||||||||||||||
| (Strings.BanMute.SixMonths, 180), | ||||||||||||||
| (Strings.BanMute.OneYear, 365), | ||||||||||||||
| (Strings.BanMute.Forever, 999999), | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| public BanMuteBox(string title, string prompt, EventHandler okayHandler) : base( | ||||||||||||||
|
|
@@ -84,9 +60,9 @@ public BanMuteBox(string title, string prompt, EventHandler okayHandler) : base( | |||||||||||||
|
|
||||||||||||||
| // Duration combobox | ||||||||||||||
| _comboboxDuration = new ComboBox(this, "ComboBoxDuration"); | ||||||||||||||
| foreach (var day in _dayCount) | ||||||||||||||
| foreach (var option in _durationOptions) | ||||||||||||||
| { | ||||||||||||||
| _ = _comboboxDuration.AddItem(day.Key, userData: day.Value); | ||||||||||||||
| _ = _comboboxDuration.AddItem(option.Label, userData: option.Days); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Include IP checkbox | ||||||||||||||
|
|
@@ -103,17 +79,23 @@ public BanMuteBox(string title, string prompt, EventHandler okayHandler) : base( | |||||||||||||
| buttonOkay.Clicked += (s, e) => | ||||||||||||||
| { | ||||||||||||||
| okayHandler?.Invoke(this, EventArgs.Empty); | ||||||||||||||
| Dispose(); | ||||||||||||||
| Close(); | ||||||||||||||
|
Comment on lines
81
to
+82
|
||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| var buttonCancel = new Button(this, "ButtonCancel") | ||||||||||||||
| { | ||||||||||||||
| Text = Strings.BanMute.Cancel, | ||||||||||||||
| }; | ||||||||||||||
| buttonCancel.Clicked += (s, e) => Dispose(); | ||||||||||||||
| buttonCancel.Clicked += (s, e) => Close(); | ||||||||||||||
|
|
||||||||||||||
| LoadJsonUi(UI.InGame, Graphics.Renderer?.GetResolutionString(), true); | ||||||||||||||
|
|
||||||||||||||
| // Set the first element by default after loading the UI (ensures deterministic selection). | ||||||||||||||
| if (_comboboxDuration != null && _durationOptions.Count > 0) | ||||||||||||||
| { | ||||||||||||||
| _ = _comboboxDuration.SelectByUserData(_durationOptions[0].Days); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| richLabelPrompt.ClearText(); | ||||||||||||||
| richLabelPrompt.Width = promptContainer.Width - promptContainer.VerticalScrollBar.Width; | ||||||||||||||
| richLabelPrompt.AddText(prompt, labelPrompt); | ||||||||||||||
|
|
@@ -122,24 +104,34 @@ public BanMuteBox(string title, string prompt, EventHandler okayHandler) : base( | |||||||||||||
|
|
||||||||||||||
| protected override void Dispose(bool disposing) | ||||||||||||||
| { | ||||||||||||||
| Close(); | ||||||||||||||
| Interface.GameUi.GameCanvas.RemoveChild(this, false); | ||||||||||||||
| Interface.InputBlockingComponents.Remove(this); | ||||||||||||||
|
|
||||||||||||||
| if (_textboxReason != null) | ||||||||||||||
| { | ||||||||||||||
| Interface.FocusComponents.Remove(_textboxReason); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
Comment on lines
+108
to
113
|
||||||||||||||
| if (_textboxReason != null) | |
| { | |
| Interface.FocusComponents.Remove(_textboxReason); | |
| } | |
| Interface.FocusComponents.Remove(_textboxReason); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1295,23 +1295,27 @@ private static void PropagateDrawDebugOutlinesToChildren(Base @this, bool drawDe | |||||
| /// </summary> | ||||||
| public void Dispose() | ||||||
| { | ||||||
| try | ||||||
| // TODO : GWEN: We need to spend more time on this. | ||||||
| if (_disposed) | ||||||
| { | ||||||
| ObjectDisposedException.ThrowIf(_disposed, this); | ||||||
| } | ||||||
| catch | ||||||
| { | ||||||
| throw; | ||||||
| return; | ||||||
|
||||||
| return; | |
| throw new ObjectDisposedException(GetType().FullName); |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The braces were removed from these if statements, making the code more compact but potentially less maintainable. While this follows some coding styles, it can increase the risk of bugs if additional statements are later added without re-adding braces. Consider whether consistency with the project's style guide is maintained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _comboboxDuration field is marked as nullable (ComboBox?), but it's initialized in the constructor on line 62 and should never be null during the object's lifetime. Making it nullable adds unnecessary null-checking overhead (lines 94, 119) without providing value. Consider making this field non-nullable to better reflect its actual behavior.