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 1 commit
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
Prev Previous commit
Next Next commit
Changed enum names to follow upper snake case convention
  • Loading branch information
OhmV-IR committed Feb 24, 2024
commit 5ca499cbd2c1bb5aac6f9d5c91d38b69b6de16f9
2 changes: 1 addition & 1 deletion Nitrox.Test/Model/StatusCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void ThrowStatusCodesNonFatal()
public void ThrowStatusCodesLongException()
{
// Test if the text will wrap or if the messageBox will expand to accomodate for a long exception message
DisplayStatusCode(StatusCode.fileSystemErr, false, "This is a testing exception that is super long to test if text will wrap to fit the message box space, or potentially expand the message box as needed. Did you know that you are wasting your time reading this? Like actually there is nothing here you can stop reading, just run the test and you will see this text there. Alright this is probably long enough hopefully it works :) and btw Crabsnake is the best mod.");
DisplayStatusCode(StatusCoe.FILE_SYSTEM_ERR, false, "This is a testing exception that is super long to test if text will wrap to fit the message box space, or potentially expand the message box as needed. Did you know that you are wasting your time reading this? Like actually there is nothing here you can stop reading, just run the test and you will see this text there. Alright this is probably long enough hopefully it works :) and btw Crabsnake is the best mod.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ 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);
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, 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);
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "Client failed to connect to the server and has been disconnected" + message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void ClientIsConnected(IMultiplayerSessionConnectionContext sessi
{
if (!sessionConnectionContext.Client.IsConnected)
{
DisplayStatusCode(StatusCode.invalidPacket, false, "The client is not connected.");
DisplayStatusCode(StatusCode.INVALID_PACKET, false, "The client is not connected.");
}
}

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

Expand All @@ -80,7 +80,7 @@ private static void AuthenticationContextIsNotNull(IMultiplayerSessionConnection
}
catch (ArgumentNullException ex)
{
DisplayStatusCode(StatusCode.invalidPacket, false, "The context does not contain an authentication context." + ex);
DisplayStatusCode(StatusCode.INVALID_PACKET, false, "The context does not contain an authentication context." + ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ private static void ReservationIsNotNull(IMultiplayerSessionConnectionContext se
}
catch (ArgumentNullException ex)
{
DisplayStatusCode(StatusCode.invalidPacket, false, "The context does not have a reservation." + ex.ToString());
DisplayStatusCode(StatusCode.INVALID_PACKET, 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());
DisplayStatusCode(StatusCode.INVALID_PACKET, false, sessionConnectionContext.Reservation.ToString() + reservationCorrelationId.ToString());
throw new UncorrelatedPacketException(sessionConnectionContext.Reservation, reservationCorrelationId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public virtual void Disconnect(IMultiplayerSessionConnectionContext sessionConne
{
sessionConnectionContext.ClearSessionState();
sessionConnectionContext.Client.Stop();
DisplayStatusCode(StatusCode.connectionFailClient, false, "Client was disconnected.");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "Client was disconnected.");
Disconnected newConnectionState = new Disconnected();
sessionConnectionContext.UpdateConnectionState(newConnectionState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class ConnectionNegotiatedState : CommunicatingState
{
public override Task NegotiateReservationAsync(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "Unable to negotiate a session connection in the current state.");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "Unable to negotiate a session connection in the current state.");
throw new Exception();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class ConnectionNegotiatingState : CommunicatingState
{
public override void JoinSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "Cannot join a session until a reservation has been negotiated with the server.");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "Cannot join a session until a reservation has been negotiated with the server.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private void ValidateState(IMultiplayerSessionConnectionContext sessionConnectio
}
catch (ArgumentNullException ex)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "The context is missing an IP address." + ex.ToString());
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, 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)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "The client must be set on the connection context before trying to negotiate a session reservation." + ex.ToString());
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, 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)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "The client failed to connect without providing a reason why.");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, 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)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "Cannot join a session until a reservation has been negotiated with the server.");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "Cannot join a session until a reservation has been negotiated with the server.");
}

public void Disconnect(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "Not connected to a multiplayer server.");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "Not connected to a multiplayer server.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ private static void SessionPolicyIsNotNull(IMultiplayerSessionConnectionContext
}
catch (ArgumentNullException ex)
{
DisplayStatusCode(StatusCode.invalidPacket, false, "The context is missing a session policy." + ex.ToString());
DisplayStatusCode(StatusCode.INVALID_PACKET, false, "The context is missing a session policy." + ex.ToString());
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SessionJoined : ConnectionNegotiatedState

public override void JoinSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
DisplayStatusCode(StatusCode.outboundConnectionAlreadyOpen, false, "The session is already in progress.");
DisplayStatusCode(StatusCode.OUTBOUND_CONNECTION_ALREADY_OPEN, false, "The session is already in progress.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SessionReservationRejected : ConnectionNegotiatedState

public override void JoinSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "The session has rejected the reserveration request.");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "The session has rejected the reserveration request.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static void ValidateState(IMultiplayerSessionConnectionContext sessionCo
{
if (!sessionConnectionContext.Client.IsConnected)
{
DisplayStatusCode(StatusCode.connectionFailClient, false, "The client is not connected.");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "The client is not connected.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +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}");
DisplayStatusCode(StatusCode.VERSION_MISMATCH, 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}");
DisplayStatusCode(StatusCode.VERSION_MISMATCH, false, $"Server is out of date. Server: {SessionPolicy.NitroxVersionAllowed}, Client: {localVersion}");
return;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +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");
DisplayStatusCode(StatusCode.CONNECTION_FAIL_CLIENT, false, "The client was disconnected from the server");
}

IsConnected = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public IEnumerator ResyncBuildingEntities(Dictionary<BuildEntity, int> buildEnti
Stopwatch stopwatch = Stopwatch.StartNew();
BuildingHandler.Main.StartResync(buildEntities);
yield return UpdateEntities<Base, BuildEntity>(buildEntities.Keys.ToList(), OverwriteBase, IsInCloseProximity).OnYieldError((exception) => {
DisplayStatusCode(StatusCode.syncFail, false, exception.ToString() + $"Encountered an exception while resyncing BuildEntities");
DisplayStatusCode(StatusCode.SYNC_FAIL, false, exception.ToString() + $"Encountered an exception while resyncing BuildEntities");
});

BuildingHandler.Main.StartResync(moduleEntities);
yield return UpdateEntities<Constructable, ModuleEntity>(moduleEntities.Keys.ToList(), OverwriteModule, IsInCloseProximity).OnYieldError( (exception)=> {
DisplayStatusCode(StatusCode.syncFail, false, exception.ToString() + $"Encountered an exception while resyncing ModuleEntities");
DisplayStatusCode(StatusCode.SYNC_FAIL, false, exception.ToString() + $"Encountered an exception while resyncing ModuleEntities");
});
BuildingHandler.Main.StopResync();

Expand Down Expand Up @@ -120,7 +120,7 @@ public IEnumerator ResyncBuildingEntities(Dictionary<BuildEntity, int> buildEnti
Log.Info($"[{typeof(E)} RESYNC] spawning entity {entity.Id}");
yield return entities.SpawnEntityAsync(entity).OnYieldError((ex) => {
Log.Error(ex);
DisplayStatusCode(StatusCode.syncFail, false, "Error while trying to sync: " + ex.ToString());
DisplayStatusCode(StatusCode.SYNC_FAIL, false, "Error while trying to sync: " + ex.ToString());
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void LogClientMessage(ChatMessage message)
if (!remotePlayer.HasValue)
{
string playerTableFormatted = string.Join("\n", remotePlayerManager.GetAll().Select(ply => $"Name: '{ply.PlayerName}', Id: {ply.PlayerId}"));
DisplayStatusCode(StatusCode.remotePlayerErr, true, $"Tried to add chat message for remote player that could not be found with id '${message.PlayerId}' and message: '{message.Text}'.\nAll remote players right now:\n{playerTableFormatted}");
DisplayStatusCode(StatusCode.REMOTE_PLAYER_ERR, true, $"Tried to add chat message for remote player that could not be found with id '${message.PlayerId}' and message: '{message.Text}'.\nAll remote players right now:\n{playerTableFormatted}");
}

playerName = remotePlayer.Value.PlayerName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void SetActiveDamagePoints(SubRoot cyclops, int[] damagePointIndexes)
// Looks like the list came in unordered. I've uttered "That shouldn't happen" enough to do sanity checks for what should be impossible.
if (packetDamagePointsIndex < damagePointIndexes.Length)
{
DisplayStatusCode(StatusCode.invalidVariableVal, false, $"[CyclopsDamageProcessor packet.DamagePointIds did not fully iterate! Id: {damagePointIndexes[packetDamagePointsIndex]} had no matching Id in damageManager.damagePoints, or the order is incorrect!]");
DisplayStatusCode(StatusCode.INVALID_VARIABLE_VAL, false, $"[CyclopsDamageProcessor packet.DamagePointIds did not fully iterate! Id: {damagePointIndexes[packetDamagePointsIndex]} had no matching Id in damageManager.damagePoints, or the order is incorrect!]");
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void Process(EntityDestroyed packet)
entities.RemoveEntity(packet.Id);
if (!NitroxEntity.TryGetObjectFrom(packet.Id, out GameObject gameObject))
{
DisplayStatusCode(StatusCode.invalidPacket, false, $"[{nameof(EntityDestroyedProcessor)}] Could not find entity with id: {packet.Id} to destroy.");
DisplayStatusCode(StatusCode.INVALID_PACKET, false, $"[{nameof(EntityDestroyedProcessor)}] Could not find entity with id: {packet.Id} to destroy.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void Process(EntityReparented packet)
// In some cases, the affected entity may be pending spawning or out of range.
// we only require the parent (in this case, the visible entity is undergoing
// some change that must be shown, and if not is an error).
DisplayStatusCode(StatusCode.invalidPacket, false, "The entity this process was trying to process was null");
DisplayStatusCode(StatusCode.INVALID_PACKET, false, "The entity this process was trying to process was null");
return;
}
// Get the soon-to-be new parent of the gameObject from the packet
Expand Down Expand Up @@ -79,7 +79,7 @@ private void InventoryItemReparented(GameObject entity, GameObject newParent)

if (!opContainer.HasValue)
{
DisplayStatusCode(StatusCode.invalidVariableVal, false, $"Could not find container field on GameObject {newParent.GetFullHierarchyPath()}");
DisplayStatusCode(StatusCode.INVALID_VARIABLE_VAL, false, $"Could not find container field on GameObject {newParent.GetFullHierarchyPath()}");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void Process(EntityTransformUpdates packet)
continue;
} else
{
DisplayStatusCode(StatusCode.invalidPacket, false, "GameObject provided to the packet processor was null");
DisplayStatusCode(StatusCode.INVALID_PACKET, false, "GameObject provided to the packet processor was null");
}

RemotelyControlled remotelyControlled = opGameObject.Value.GetComponent<RemotelyControlled>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void Process(EscapePodChanged packet)
escapePod = sub.GetComponent<EscapePod>();
} else
{
DisplayStatusCode(StatusCode.invalidPacket, false, "EscapePodId was null");
DisplayStatusCode(StatusCode.INVALID_PACKET, false, "EscapePodId was null");
}

remotePlayer.Value.SetEscapePod(escapePod);
Expand Down
Loading