Skip to content

Commit 6a3b52e

Browse files
authored
fix: log and disconnect hostile users with prejudice (AscensionGameDev#2131)
1 parent c6333da commit 6a3b52e

File tree

38 files changed

+502
-292
lines changed

38 files changed

+502
-292
lines changed

Intersect (Core)/Config/DatabaseOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.ComponentModel;
2-
using System.Diagnostics.CodeAnalysis;
32

43
using Newtonsoft.Json;
54
using Newtonsoft.Json.Converters;
@@ -8,6 +7,12 @@ namespace Intersect.Config
87
{
98
public partial class DatabaseOptions
109
{
10+
#if DEBUG
11+
private const bool DefaultKillServerOnConcurrencyException = true;
12+
#else
13+
private const bool DefaultKillServerOnConcurrencyException = false;
14+
#endif
15+
1116
[JsonConverter(typeof(StringEnumConverter))]
1217
public DatabaseType Type { get; set; } = DatabaseType.SQLite;
1318

@@ -28,5 +33,7 @@ public partial class DatabaseOptions
2833
)]
2934
[DefaultValue(Logging.LogLevel.Error)]
3035
public Logging.LogLevel LogLevel { get; set; } = Logging.LogLevel.Error;
36+
37+
public bool KillServerOnConcurrencyException { get; set; } = DefaultKillServerOnConcurrencyException;
3138
}
3239
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System;
1+
namespace Intersect.Network.Events;
22

3-
namespace Intersect.Network.Events
3+
public partial class ConnectionEventArgs : EventArgs
44
{
5-
public partial class ConnectionEventArgs : EventArgs
6-
{
7-
public NetworkStatus NetworkStatus { get; set; }
5+
public Guid EventId { get; set; }
86

9-
public IConnection Connection { get; set; }
10-
}
11-
}
7+
public NetworkStatus NetworkStatus { get; set; }
8+
9+
public IConnection Connection { get; set; }
10+
}

Intersect.Client/Core/Main.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ private static void ProcessGame()
195195
if (Globals.ConnectionLost)
196196
{
197197
Main.Logout(false);
198-
Interface.Interface.MsgboxErrors.Add(
199-
new KeyValuePair<string, string>("", Strings.Errors.lostconnection)
200-
);
198+
Interface.Interface.ShowError(Strings.Errors.lostconnection);
201199

202200
Globals.ConnectionLost = false;
203201

Intersect.Client/Interface/Interface.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ namespace Intersect.Client.Interface
1818
public static partial class Interface
1919
{
2020

21-
public static readonly List<KeyValuePair<string, string>> MsgboxErrors = new();
21+
private static readonly Queue<KeyValuePair<string, string>> _errorMessages = new();
22+
23+
public static bool TryDequeueErrorMessage(out KeyValuePair<string, string> message) => _errorMessages.TryDequeue(out message);
2224

2325
public static void ShowError(string message, string? header = default)
2426
{
25-
MsgboxErrors.Add(new KeyValuePair<string, string>(header ?? string.Empty, message));
27+
_errorMessages.Enqueue(new KeyValuePair<string, string>(header ?? string.Empty, message));
2628
}
2729

2830
public static ErrorHandler ErrorMsgHandler;

Intersect.Client/Interface/Menu/CreateCharacterWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void Update()
204204
{
205205
Hide();
206206
mMainMenu.Show();
207-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.lostconnection));
207+
Interface.ShowError(Strings.Errors.lostconnection);
208208

209209
return;
210210
}
@@ -492,7 +492,7 @@ void TryCreateCharacter(int gender)
492492
}
493493
else
494494
{
495-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.CharacterCreation.invalidname));
495+
Interface.ShowError(Strings.CharacterCreation.invalidname);
496496
}
497497
}
498498

Intersect.Client/Interface/Menu/ForgotPasswordWindow.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void Update()
102102
{
103103
Hide();
104104
mMainMenu.Show();
105-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.lostconnection));
105+
Interface.ShowError(Strings.Errors.lostconnection);
106106
}
107107

108108
// Re-Enable our buttons if we're not waiting for the server anymore with it disabled.
@@ -150,16 +150,15 @@ public void TrySendCode()
150150
{
151151
if (!Networking.Network.IsConnected)
152152
{
153-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.notconnected));
153+
Interface.ShowError(Strings.Errors.notconnected);
154154

155155
return;
156156
}
157157

158158
if (!FieldChecking.IsValidUsername(mInputTextbox?.Text, Strings.Regex.username) &&
159159
!FieldChecking.IsWellformedEmailAddress(mInputTextbox?.Text, Strings.Regex.email))
160160
{
161-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.usernameinvalid));
162-
161+
Interface.ShowError(Strings.Errors.usernameinvalid);
163162
return;
164163
}
165164

Intersect.Client/Interface/Menu/LoginWindow.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public void Update()
160160
{
161161
Hide();
162162
mMainMenu.Show();
163-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.lostconnection));
164163
return;
165164
}
166165

@@ -233,24 +232,21 @@ public void TryLogin()
233232

234233
if (!Networking.Network.IsConnected)
235234
{
236-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.notconnected));
237-
235+
Interface.ShowError(Strings.Errors.notconnected);
238236
return;
239237
}
240238

241239
if (!FieldChecking.IsValidUsername(mUsernameTextbox?.Text, Strings.Regex.username))
242240
{
243-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.usernameinvalid));
244-
241+
Interface.ShowError(Strings.Errors.usernameinvalid);
245242
return;
246243
}
247244

248245
if (!FieldChecking.IsValidPassword(mPasswordTextbox?.Text, Strings.Regex.password))
249246
{
250247
if (!mUseSavedPass)
251248
{
252-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.passwordinvalid));
253-
249+
Interface.ShowError(Strings.Errors.passwordinvalid);
254250
return;
255251
}
256252
}

Intersect.Client/Interface/Menu/RegisterWindow.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Update()
153153
{
154154
Hide();
155155
mMainMenu.Show();
156-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.lostconnection));
156+
Interface.ShowError(Strings.Errors.lostconnection);
157157
}
158158

159159
// Re-Enable our buttons if we're not waiting for the server anymore with it disabled.
@@ -220,33 +220,27 @@ void TryRegister()
220220
}
221221
else
222222
{
223-
Interface.MsgboxErrors.Add(
224-
new KeyValuePair<string, string>("", Strings.Registration.emailinvalid)
225-
);
223+
Interface.ShowError(Strings.Registration.emailinvalid);
226224
}
227225
}
228226
else
229227
{
230-
Interface.MsgboxErrors.Add(
231-
new KeyValuePair<string, string>("", Strings.Errors.passwordinvalid)
232-
);
228+
Interface.ShowError(Strings.Errors.passwordinvalid);
233229
}
234230
}
235231
else
236232
{
237-
Interface.MsgboxErrors.Add(
238-
new KeyValuePair<string, string>("", Strings.Registration.passwordmatch)
239-
);
233+
Interface.ShowError(Strings.Registration.passwordmatch);
240234
}
241235
}
242236
else
243237
{
244-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.usernameinvalid));
238+
Interface.ShowError(Strings.Errors.usernameinvalid);
245239
}
246240
}
247241
else
248242
{
249-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.notconnected));
243+
Interface.ShowError(Strings.Errors.notconnected);
250244
}
251245
}
252246

Intersect.Client/Interface/Menu/ResetPasswordWindow.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ private void Textbox_Clicked(Base sender, ClickedEventArgs arguments)
139139
//Methods
140140
public void Update()
141141
{
142+
// ReSharper disable once InvertIf
142143
if (!Networking.Network.IsConnected)
143144
{
144145
Hide();
145146
mMainMenu.Show();
146-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.lostconnection));
147+
Interface.ShowError(Strings.Errors.lostconnection);
147148
}
148149
}
149150

@@ -195,29 +196,25 @@ public void TrySendCode()
195196

196197
if (!Networking.Network.IsConnected)
197198
{
198-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.notconnected));
199-
199+
Interface.ShowError(Strings.Errors.notconnected);
200200
return;
201201
}
202202

203203
if (string.IsNullOrEmpty(mCodeInputTextbox?.Text))
204204
{
205-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.ResetPass.inputcode));
206-
205+
Interface.ShowError(Strings.ResetPass.inputcode);
207206
return;
208207
}
209208

210209
if (mPasswordTextbox.Text != mPasswordTextbox2.Text)
211210
{
212-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Registration.passwordmatch));
213-
211+
Interface.ShowError(Strings.Registration.passwordmatch);
214212
return;
215213
}
216214

217215
if (!FieldChecking.IsValidPassword(mPasswordTextbox.Text, Strings.Regex.password))
218216
{
219-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.passwordinvalid));
220-
217+
Interface.ShowError(Strings.Errors.passwordinvalid);
221218
return;
222219
}
223220

Intersect.Client/Interface/Menu/SelectCharacterWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void Update()
123123
{
124124
Hide();
125125
mMainMenu.Show();
126-
Interface.MsgboxErrors.Add(new KeyValuePair<string, string>("", Strings.Errors.lostconnection));
126+
Interface.ShowError(Strings.Errors.lostconnection);
127127
}
128128

129129
// Re-Enable our buttons if we're not waiting for the server anymore with it disabled.

0 commit comments

Comments
 (0)