Skip to content
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

Adding popup messages for errors with status codes alongside the exception message #2116

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
59924de
Initial commit to open PR
OhmV-IR Jan 16, 2024
2bc36cb
Added enum for status codes and function to print them
OhmV-IR Jan 17, 2024
a4afd49
Use integer enum overload
OhmV-IR Jan 18, 2024
3651990
Added project reference and status codes for NitroxConfig.cs
OhmV-IR Jan 26, 2024
cd4392c
Added error messages in a popup for nitroxModel
OhmV-IR Feb 4, 2024
4aaf86d
fix missing import statements so the solution can build
OhmV-IR Feb 4, 2024
6fb3a87
added a better messageBox dialog to display status code errors
OhmV-IR Feb 4, 2024
7488213
moved display status code enum out of nitrox server into new files in…
OhmV-IR Feb 5, 2024
6b23109
MORE FUNCTION CALLS
OhmV-IR Feb 6, 2024
60e673a
added more descriptive names for statusCodes in the files and moved s…
OhmV-IR Feb 12, 2024
e76df2f
Finished adding statusCode calls to NitroxClient
OhmV-IR Feb 12, 2024
388fd96
Check if nitroxLauncher is in a oneDrive folder implementation
OhmV-IR Feb 14, 2024
741099a
Added fatal flag to statusCode function calls
OhmV-IR Feb 20, 2024
ca8a205
Added exception message to StatusCode messageBox
OhmV-IR Feb 20, 2024
051f09a
Added exception messages to PrintStatusCode <- server status codes fu…
OhmV-IR Feb 20, 2024
df46194
Merge pull request #1 from OhmV-IR/inDev
OhmV-IR Feb 20, 2024
2a03491
removed unused isPirate bool in CustomMessagebox.cs
OhmV-IR Feb 20, 2024
9f3e552
Added test fail case for FatalStatusCodes and removed success status …
OhmV-IR Feb 20, 2024
219ef4e
Added text wrapping so that the exception message does not exceed the…
OhmV-IR Feb 21, 2024
cb86f5c
Change statusCode enum to use HTTP status codes and condense redundan…
OhmV-IR Feb 22, 2024
5ca499c
Changed enum names to follow upper snake case convention
OhmV-IR Feb 22, 2024
4a2bf7c
Changed SYNC_FAIL to use a different code than MISSING_FEATURE
OhmV-IR Feb 22, 2024
973015b
Fixed a typo that caused build errors
OhmV-IR Feb 22, 2024
a23a8ed
Added some more comments and finished unit testing, just need to play…
OhmV-IR Feb 24, 2024
f778fe1
Change enum names, use HTTP status codes, unit tests, should be ready…
OhmV-IR Feb 24, 2024
81cce0e
Client disconnects are never recognized as fatal, even if they happen…
OhmV-IR Feb 24, 2024
fc0e7dd
Merge branch 'prod-status-codes' into polishing-status-codes
OhmV-IR Feb 27, 2024
3ba4bbf
Added missing using statement
OhmV-IR Feb 27, 2024
c0b9278
Removed unneeded comments
OhmV-IR Mar 12, 2024
ace18b4
removed a useless comment
OhmV-IR Mar 17, 2024
0b542eb
Removed some usings and fixed using assemblies that had not yet been …
OhmV-IR Mar 18, 2024
1b2cb10
Merge branch 'polishing-status-codes' into master
OhmV-IR Mar 19, 2024
57b8ea2
Merge pull request #6 from OhmV-IR/master
OhmV-IR Mar 19, 2024
0137f03
Removed fatal program closes(its just bad design to end execution so …
OhmV-IR Mar 20, 2024
2baf570
Use Log.InGame for less important codes when in InDev and ignore the …
OhmV-IR Mar 20, 2024
505da81
Fixed creating release builds
OhmV-IR Mar 20, 2024
20b28f7
Changed ingame log string + removed unneeded reference in NitroxLauncher
OhmV-IR Mar 20, 2024
5a1f315
Added more function calls
OhmV-IR Mar 24, 2024
5db1930
Small fixes
OhmV-IR Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Nitrox.Test/Model/StatusCodeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using static NitroxModel.DisplayStatusCodes;
namespace NitroxModel;

[TestClass]
public class StatusCodeTests
{
[TestMethod]
public void ThrowStatusCodesNonFatal()
{
// Display one of every status code once non-fatally, should display all of them once
for (int i = 0; i < Enum.GetNames(typeof(StatusCode)).Length; i++)
{
DisplayStatusCode((StatusCode)i, false, "Testing exception");
}
}
[TestMethod]
public void ThrowStatusCodesFatal()
{
// Display one of every status code once fatally, should only display the first one
for (int i = 0; i < Enum.GetNames(typeof(StatusCode)).Length; i++)
{
DisplayStatusCode((StatusCode)i, true, "Testing exception");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using System;

using System;
using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.Exceptions
{
public class ClientConnectionFailedException : Exception
{
public ClientConnectionFailedException(string message) : base(message)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "Client failed to connect to the server and has been disconnected" + message);
}

public ClientConnectionFailedException(string message, Exception innerException) : base(message, innerException)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "Client failed to connect to the server and has been disconnected" + message);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Threading.Tasks;
using NitroxClient.Communication.Abstract;
using NitroxModel.Helper;
using NitroxModel.MultiplayerSession;
using NitroxModel.Packets;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public class AwaitingReservationCredentials : ConnectionNegotiatingState
Expand Down Expand Up @@ -56,7 +56,7 @@ private static void ClientIsConnected(IMultiplayerSessionConnectionContext sessi
{
if (!sessionConnectionContext.Client.IsConnected)
{
throw new InvalidOperationException("The client is not connected.");
DisplayStatusCode(StatusCode.invalidPacket, false, "The client is not connected.");
}
}

Expand All @@ -68,7 +68,7 @@ private static void PlayerSettingsIsNotNull(IMultiplayerSessionConnectionContext
}
catch (ArgumentNullException ex)
{
throw new InvalidOperationException("The context does not contain player settings.", ex);
DisplayStatusCode(StatusCode.invalidPacket, false, "The context does not contain player settings." + ex);
}
}

Expand All @@ -80,7 +80,7 @@ private static void AuthenticationContextIsNotNull(IMultiplayerSessionConnection
}
catch (ArgumentNullException ex)
{
throw new InvalidOperationException("The context does not contain an authentication context.", ex);
DisplayStatusCode(StatusCode.invalidPacket, false, "The context does not contain an authentication context." + ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Threading.Tasks;
using NitroxClient.Communication.Abstract;
using NitroxModel.Helper;
using NitroxModel.MultiplayerSession;
using NitroxModel.Packets.Exceptions;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public class AwaitingSessionReservation : ConnectionNegotiatingState
Expand Down Expand Up @@ -59,14 +59,15 @@ private static void ReservationIsNotNull(IMultiplayerSessionConnectionContext se
}
catch (ArgumentNullException ex)
{
throw new InvalidOperationException("The context does not have a reservation.", ex);
DisplayStatusCode(StatusCode.invalidPacket, false, "The context does not have a reservation." + ex.ToString());
}
}

private void ReservationPacketIsCorrelated(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
if (!reservationCorrelationId.Equals(sessionConnectionContext.Reservation.CorrelationId))
{
DisplayStatusCode(StatusCode.invalidPacket, false, sessionConnectionContext.Reservation.ToString() + reservationCorrelationId.ToString());
throw new UncorrelatedPacketException(sessionConnectionContext.Reservation, reservationCorrelationId);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using NitroxClient.Communication.Abstract;

using NitroxModel;
using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public abstract class CommunicatingState : IMultiplayerSessionConnectionState
Expand All @@ -14,7 +15,7 @@ public virtual void Disconnect(IMultiplayerSessionConnectionContext sessionConne
{
sessionConnectionContext.ClearSessionState();
sessionConnectionContext.Client.Stop();

DisplayStatusCode(StatusCode.connectionFailClient, false, "Client was disconnected.");
Disconnected newConnectionState = new Disconnected();
sessionConnectionContext.UpdateConnectionState(newConnectionState);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System;
using System.Threading.Tasks;
using NitroxClient.Communication.Abstract;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public abstract class ConnectionNegotiatedState : CommunicatingState
{
public override Task NegotiateReservationAsync(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
throw new InvalidOperationException("Unable to negotiate a session connection in the current state.");
DisplayStatusCode(StatusCode.connectionFailClient, false, "Unable to negotiate a session connection in the current state.");
throw new Exception();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System;
using NitroxClient.Communication.Abstract;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public abstract class ConnectionNegotiatingState : CommunicatingState
{
public override void JoinSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
throw new InvalidOperationException("Cannot join a session until a reservation has been negotiated with the server.");
DisplayStatusCode(StatusCode.connectionFailClient, false, "Cannot join a session until a reservation has been negotiated with the server.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Threading.Tasks;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Exceptions;
using NitroxModel.Helper;
using NitroxModel.Packets;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public class Disconnected : IMultiplayerSessionConnectionState
Expand Down Expand Up @@ -32,7 +32,7 @@ private void ValidateState(IMultiplayerSessionConnectionContext sessionConnectio
}
catch (ArgumentNullException ex)
{
throw new InvalidOperationException("The context is missing an IP address.", ex);
DisplayStatusCode(StatusCode.connectionFailClient, false, "The context is missing an IP address." + ex.ToString());
}
}

Expand All @@ -44,7 +44,7 @@ private static void ValidateClient(IMultiplayerSessionConnectionContext sessionC
}
catch (ArgumentNullException ex)
{
throw new InvalidOperationException("The client must be set on the connection context before trying to negotiate a session reservation.", ex);
DisplayStatusCode(StatusCode.connectionFailClient, false, "The client must be set on the connection context before trying to negotiate a session reservation." + ex.ToString());
}
}

Expand All @@ -56,7 +56,7 @@ private static async Task StartClientAsync(string ipAddress, IClient client, int

if (!client.IsConnected)
{
throw new ClientConnectionFailedException("The client failed to connect without providing a reason why.");
DisplayStatusCode(StatusCode.connectionFailClient, false, "The client failed to connect without providing a reason why.");
}
}
}
Expand All @@ -74,12 +74,12 @@ private static void EstablishSessionPolicy(IMultiplayerSessionConnectionContext

public void JoinSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
throw new InvalidOperationException("Cannot join a session until a reservation has been negotiated with the server.");
DisplayStatusCode(StatusCode.connectionFailClient, false, "Cannot join a session until a reservation has been negotiated with the server.");
}

public void Disconnect(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
throw new InvalidOperationException("Not connected to a multiplayer server.");
DisplayStatusCode(StatusCode.connectionFailClient, false, "Not connected to a multiplayer server.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System;
using System.Threading.Tasks;
using NitroxClient.Communication.Abstract;
using NitroxModel.Helper;
using NitroxModel.Packets.Exceptions;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public class EstablishingSessionPolicy : ConnectionNegotiatingState
Expand Down Expand Up @@ -47,15 +47,15 @@ private static void SessionPolicyIsNotNull(IMultiplayerSessionConnectionContext
}
catch (ArgumentNullException ex)
{
throw new InvalidOperationException("The context is missing a session policy.", ex);
DisplayStatusCode(StatusCode.invalidPacket, false, "The context is missing a session policy." + ex.ToString());
}
}

private void SessionPolicyPacketCorrelation(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
if (!policyRequestCorrelationId.Equals(sessionConnectionContext.SessionPolicy.CorrelationId))
{
throw new UncorrelatedPacketException(sessionConnectionContext.SessionPolicy, policyRequestCorrelationId);
DisplayStatusCode(StatusCode.invalidPacket, false, "The packet was uncorrelated to the function of this processor: ");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System;
using NitroxClient.Communication.Abstract;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public class SessionJoined : ConnectionNegotiatedState
Expand All @@ -9,7 +9,7 @@ public class SessionJoined : ConnectionNegotiatedState

public override void JoinSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
throw new InvalidOperationException("The session is already in progress.");
DisplayStatusCode(StatusCode.outboundConnectionAlreadyOpen, false, "The session is already in progress.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System;
using NitroxClient.Communication.Abstract;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public class SessionReservationRejected : ConnectionNegotiatedState
Expand All @@ -9,7 +9,7 @@ public class SessionReservationRejected : ConnectionNegotiatedState

public override void JoinSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
throw new InvalidOperationException("The session has rejected the reserveration request.");
DisplayStatusCode(StatusCode.connectionFailClient, false, "The session has rejected the reserveration request.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using NitroxClient.Communication.Abstract;
using NitroxModel;
using NitroxModel.Packets;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
public class SessionReserved : ConnectionNegotiatedState
Expand All @@ -27,7 +28,7 @@ private static void ValidateState(IMultiplayerSessionConnectionContext sessionCo
{
if (!sessionConnectionContext.Client.IsConnected)
{
throw new InvalidOperationException("The client is not connected.");
DisplayStatusCode(StatusCode.connectionFailClient, false, "The client is not connected.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NitroxClient.Communication.Abstract;
Expand All @@ -9,7 +9,7 @@
using NitroxModel.MultiplayerSession;
using NitroxModel.Packets;
using NitroxModel.Serialization;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.MultiplayerSession
{
public class MultiplayerSessionManager : IMultiplayerSession, IMultiplayerSessionConnectionContext
Expand Down Expand Up @@ -68,13 +68,15 @@ public void ProcessSessionPolicy(MultiplayerSessionPolicy policy)
.Replace("{serverVersion}", SessionPolicy.NitroxVersionAllowed.ToString())
.Replace("{localVersion}", localVersion.ToString()));
CurrentState.Disconnect(this);
DisplayStatusCode(StatusCode.versionMismatch, false, $"Client is out of date. Server: {SessionPolicy.NitroxVersionAllowed}, Client: {localVersion}");
return;
case 1:
Log.Error($"Server is out of date. Server: {SessionPolicy.NitroxVersionAllowed}, Client: {localVersion}");
Log.InGame(Language.main.Get("Nitrox_OutOfDateServer")
.Replace("{serverVersion}", SessionPolicy.NitroxVersionAllowed.ToString())
.Replace("{localVersion}", localVersion.ToString()));
CurrentState.Disconnect(this);
DisplayStatusCode(StatusCode.versionMismatch, false, $"Server is out of date. Server: {SessionPolicy.NitroxVersionAllowed}, Client: {localVersion}");
return;
}

Expand Down Expand Up @@ -119,6 +121,7 @@ public void Disconnect()
if (CurrentState.CurrentStage != MultiplayerSessionConnectionStage.DISCONNECTED)
{
CurrentState.Disconnect(this);
DisplayStatusCode(StatusCode.connectionFailClient, false, "Client has been disconnected");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
using NitroxClient.Debuggers;
using NitroxClient.MonoBehaviours;
using NitroxClient.MonoBehaviours.Gui.Modals;
using NitroxModel;
using NitroxModel.Networking;
using NitroxModel.Packets;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxClient.Communication.NetworkingLayer.LiteNetLib;

public class LiteNetLibClient : IClient
Expand Down Expand Up @@ -111,6 +112,7 @@ private void Disconnected(NetPeer peer, DisconnectInfo disconnectInfo)
if (Multiplayer.Active)
{
Modal.Get<LostConnectionModal>()?.Show();
DisplayStatusCode(StatusCode.connectionFailClient, false, "The client was disconnected from the server");
}

IsConnected = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NitroxModel.Packets;
using NitroxModel.Packets;
using NitroxModel.Packets.Processors.Abstract;

namespace NitroxClient.Communication.Packets.Processors.Abstract
Expand All @@ -7,6 +7,7 @@ public abstract class ClientPacketProcessor<T> : PacketProcessor where T : Packe
{
public override void ProcessPacket(Packet packet, IProcessorContext context)
{
// Send the packet to the according processor script
Process((T)packet);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxModel.Packets;

namespace NitroxClient.Communication.Packets.Processors
Expand Down
Loading