Skip to content

Commit 57af77d

Browse files
authored
Adds username validation upon logging (SubnauticaNitrox#1285)
* Added username validation upon login * Numbers wasn't display * Updated text
1 parent 6539cf6 commit 57af77d

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

NitroxClient/MonoBehaviours/Gui/MainMenu/JoinServer.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Diagnostics;
4+
using System.Text.RegularExpressions;
45
using NitroxClient.Communication.Abstract;
56
using NitroxClient.Communication.Exceptions;
67
using NitroxClient.Communication.MultiplayerSession;
@@ -380,9 +381,10 @@ private void OnJoinClick()
380381

381382
string playerName = playerNameText.text;
382383

383-
if (string.IsNullOrEmpty(playerName))
384+
//https://regex101.com/r/eTWiEs/2/
385+
if (!Regex.IsMatch(playerName, @"^[a-zA-Z0-9._-]{3,25}$"))
384386
{
385-
NotifyUser("Please enter a player name and colour before trying to join a server");
387+
NotifyUser("Please enter a valid player name !\n\n It must not contain any space or doubtful characters\n Allowed characters : A-Z a-z 0-9 _ . -\nLength : [3, 25]");
386388
return;
387389
}
388390

@@ -416,8 +418,9 @@ private void SessionConnectionStateChangedHandler(IMultiplayerSessionConnectionS
416418
case MultiplayerSessionConnectionStage.ESTABLISHING_SERVER_POLICY:
417419
Log.InGame("Requesting session policy information...");
418420
break;
421+
419422
case MultiplayerSessionConnectionStage.AWAITING_RESERVATION_CREDENTIALS:
420-
Log.InGame("Waiting for User Input...");
423+
Log.InGame("Waiting for user input...");
421424
RightSideMainMenu.OpenGroup("Join Server");
422425
FocusPlayerNameTextbox();
423426
break;
@@ -434,6 +437,7 @@ private void SessionConnectionStateChangedHandler(IMultiplayerSessionConnectionS
434437
LoadingScreenVersionText.Initialize();
435438

436439
break;
440+
437441
case MultiplayerSessionConnectionStage.SESSION_RESERVATION_REJECTED:
438442
Log.InGame("Reservation rejected...");
439443

@@ -450,6 +454,7 @@ private void SessionConnectionStateChangedHandler(IMultiplayerSessionConnectionS
450454
});
451455

452456
break;
457+
453458
case MultiplayerSessionConnectionStage.DISCONNECTED:
454459
Log.Info("Disconnected from server");
455460
break;
@@ -463,14 +468,12 @@ private void NotifyUser(string notificationMessage, Action continuationAction =
463468
return;
464469
}
465470

466-
Action wrappedAction = () =>
471+
MainMenuNotification notificationDialog = gameObject.AddComponent<MainMenuNotification>();
472+
notificationDialog.ShowNotification(notificationMessage, () =>
467473
{
468474
continuationAction?.Invoke();
469475
Destroy(gameObject.GetComponent<MainMenuNotification>(), 0.0001f);
470-
};
471-
472-
MainMenuNotification notificationDialog = gameObject.AddComponent<MainMenuNotification>();
473-
notificationDialog.ShowNotification(notificationMessage, wrappedAction);
476+
});
474477
}
475478

476479
private void StopMultiplayerClient()

NitroxClient/MonoBehaviours/Gui/MainMenu/MainMenuNotification.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ private GUISkin GetGUISkin(string skinName, int labelWidth)
6666
{
6767
return GUISkinUtils.RegisterDerivedOnce(skinName, s =>
6868
{
69-
s.textField.fontSize = 14;
69+
s.textField.fontSize = 20;
7070
s.textField.richText = false;
71-
s.textField.alignment = TextAnchor.MiddleLeft;
71+
s.textField.alignment = TextAnchor.MiddleCenter;
7272
s.textField.wordWrap = true;
7373
s.textField.stretchHeight = true;
7474
s.textField.padding = new RectOffset(10, 10, 5, 5);
7575

76-
s.label.fontSize = 14;
77-
s.label.alignment = TextAnchor.MiddleRight;
76+
s.label.fontSize = 20;
77+
s.label.alignment = TextAnchor.MiddleCenter;
7878
s.label.stretchHeight = true;
7979
s.label.fixedWidth = labelWidth;
8080

81-
s.button.fontSize = 14;
81+
s.button.fontSize = 16;
8282
s.button.stretchHeight = true;
8383
});
8484
}

NitroxServer/Communication/Packets/Processors/MultiplayerSessionReservationRequestProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public MultiplayerSessionReservationRequestProcessor(PlayerManager playerManager
1818

1919
public override void Process(MultiplayerSessionReservationRequest packet, NitroxConnection connection)
2020
{
21-
Log.Info("Processing reservation request...");
21+
Log.Info($"Processing reservation request from {packet.AuthenticationContext.Username}");
2222

2323
string correlationId = packet.CorrelationId;
2424
PlayerSettings playerSettings = packet.PlayerSettings;
@@ -29,7 +29,7 @@ public override void Process(MultiplayerSessionReservationRequest packet, Nitrox
2929
authenticationContext,
3030
correlationId);
3131

32-
Log.Info($"Reservation processed successfully: {reservation}...");
32+
Log.Info($"Reservation processed successfully: Username: {packet.AuthenticationContext.Username} - {reservation}");
3333

3434
connection.SendPacket(reservation);
3535
}

0 commit comments

Comments
 (0)