-
Notifications
You must be signed in to change notification settings - Fork 461
fix: client throws a not server exception when destroying a NetworkObject while shutting down [MTT-6210] #2510
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
519df67
6602304
c80fa8b
c2c09dd
9c707ef
0ec3d0d
580dac3
ad7e527
5fa144c
ca7913d
155e1cc
df28f73
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 |
|---|---|---|
|
|
@@ -51,35 +51,58 @@ public static class NetworkLog | |
| /// <param name="message">The message to log</param> | ||
| public static void LogErrorServer(string message) => LogServer(message, LogType.Error); | ||
|
|
||
| internal static NetworkManager NetworkManagerOverride; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this strictly for tests?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is indeed. Since it was always using the singleton, up until this we have never fully tested server network logs generated clients. |
||
|
|
||
| private static void LogServer(string message, LogType logType) | ||
| { | ||
| var networkManager = NetworkManagerOverride ??= NetworkManager.Singleton; | ||
| // Get the sender of the local log | ||
| ulong localId = NetworkManager.Singleton != null ? NetworkManager.Singleton.LocalClientId : 0; | ||
|
|
||
| ulong localId = networkManager?.LocalClientId ?? 0; | ||
| bool isServer = networkManager?.IsServer ?? true; | ||
| switch (logType) | ||
| { | ||
| case LogType.Info: | ||
| LogInfoServerLocal(message, localId); | ||
| if (isServer) | ||
| { | ||
| LogInfoServerLocal(message, localId); | ||
| } | ||
| else | ||
| { | ||
| LogInfo(message); | ||
| } | ||
| break; | ||
| case LogType.Warning: | ||
| LogWarningServerLocal(message, localId); | ||
| if (isServer) | ||
| { | ||
| LogWarningServerLocal(message, localId); | ||
| } | ||
| else | ||
| { | ||
| LogWarning(message); | ||
| } | ||
| break; | ||
| case LogType.Error: | ||
| LogErrorServerLocal(message, localId); | ||
| if (isServer) | ||
| { | ||
| LogErrorServerLocal(message, localId); | ||
| } | ||
| else | ||
| { | ||
| LogError(message); | ||
| } | ||
|
Comment on lines
-62
to
+92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if these changes are necessary |
||
| break; | ||
| } | ||
|
|
||
| if (NetworkManager.Singleton != null && !NetworkManager.Singleton.IsServer && NetworkManager.Singleton.NetworkConfig.EnableNetworkLogs) | ||
| if (!isServer && networkManager.NetworkConfig.EnableNetworkLogs) | ||
| { | ||
|
|
||
| var networkMessage = new ServerLogMessage | ||
| { | ||
| LogType = logType, | ||
| Message = message | ||
| }; | ||
| var size = NetworkManager.Singleton.ConnectionManager.SendMessage(ref networkMessage, NetworkDelivery.ReliableFragmentedSequenced, NetworkManager.ServerClientId); | ||
| var size = networkManager.ConnectionManager.SendMessage(ref networkMessage, NetworkDelivery.ReliableFragmentedSequenced, NetworkManager.ServerClientId); | ||
|
|
||
| NetworkManager.Singleton.NetworkMetrics.TrackServerLogSent(NetworkManager.ServerClientId, (uint)logType, size); | ||
| networkManager.NetworkMetrics.TrackServerLogSent(NetworkManager.ServerClientId, (uint)logType, size); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,6 +147,7 @@ public void LogWasReceived(LogType type, Regex messageRegex) | |
| if (logEvent.LogType == type && messageRegex.IsMatch(logEvent.Message)) | ||
| { | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -157,6 +158,23 @@ public void LogWasReceived(LogType type, Regex messageRegex) | |
| } | ||
| } | ||
|
|
||
| public bool HasLogBeenReceived(LogType type, string message) | ||
| { | ||
| var found = false; | ||
| lock (m_Lock) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit scared to see |
||
| { | ||
| foreach (var logEvent in AllLogs) | ||
| { | ||
| if (logEvent.LogType == type && message.Equals(logEvent.Message)) | ||
| { | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return found; | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| lock (m_Lock) | ||
|
|
||
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.
could this just simply be replaced with an error log without changing things around it too much?
if we're only trying to error-and-continue instead of exception-throw to keep the shutdown sequence running, let's "just" do that and nothing else as the minimal fix?