mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Remove LogFactory
This commit is contained in:
parent
8901da0683
commit
5a8c822683
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d97731cd74ac8b4b8aad808548ef9cd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,70 +0,0 @@
|
||||
using Mirror.Logging;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.EditorScripts.Logging
|
||||
{
|
||||
public class LogLevelWindow : EditorWindow
|
||||
{
|
||||
[Header("Log Settings Asset")]
|
||||
[SerializeField] LogSettings settings = null;
|
||||
|
||||
SerializedObject serializedObject;
|
||||
SerializedProperty settingsProp;
|
||||
Vector2 dictionaryScrollPosition;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
serializedObject = new SerializedObject(this);
|
||||
settingsProp = serializedObject.FindProperty(nameof(settings));
|
||||
|
||||
LogSettings existingSettings = EditorLogSettingsLoader.FindLogSettings();
|
||||
if (existingSettings != null)
|
||||
{
|
||||
settingsProp.objectReferenceValue = existingSettings;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
using (EditorGUILayout.ScrollViewScope scrollScope = new EditorGUILayout.ScrollViewScope(dictionaryScrollPosition, GUIStyle.none, GUI.skin.verticalScrollbar))
|
||||
{
|
||||
dictionaryScrollPosition = scrollScope.scrollPosition;
|
||||
|
||||
using (new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
using (new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(settingsProp);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (settings == null)
|
||||
{
|
||||
LogSettings newSettings = LogLevelsGUI.DrawCreateNewButton();
|
||||
if (newSettings != null)
|
||||
{
|
||||
settingsProp.objectReferenceValue = newSettings;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogLevelsGUI.DrawLogFactoryDictionary(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Window/Analysis/Mirror Log Levels", priority = 20002)]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
LogLevelWindow window = GetWindow<LogLevelWindow>();
|
||||
window.minSize = new Vector2(200, 100);
|
||||
window.titleContent = new GUIContent("Mirror Log Levels");
|
||||
window.Show();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3dbf48190d77d243b87962a82c3b164
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,61 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Mirror.Logging;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.EditorScripts.Logging
|
||||
{
|
||||
public static class LogLevelsGUI
|
||||
{
|
||||
public static LogSettings DrawCreateNewButton()
|
||||
{
|
||||
if (GUILayout.Button("Create New"))
|
||||
{
|
||||
return ScriptableObjectUtility.CreateAsset<LogSettings>(nameof(LogSettings));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void DrawLogFactoryDictionary(LogSettings settings)
|
||||
{
|
||||
using (EditorGUI.ChangeCheckScope scope = new EditorGUI.ChangeCheckScope())
|
||||
{
|
||||
if (LogFactory.loggers.Count == 0)
|
||||
{
|
||||
EditorGUILayout.LabelField("No Keys found in LogFactory.loggers\nPlay the game for default log values to be added to LogFactory", EditorStyles.wordWrappedLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Logging Components", EditorStyles.boldLabel);
|
||||
|
||||
foreach (KeyValuePair<string, ILogger> item in LogFactory.loggers)
|
||||
{
|
||||
DrawLoggerField(item);
|
||||
}
|
||||
|
||||
if (scope.changed)
|
||||
{
|
||||
settings.SaveFromDictionary(LogFactory.loggers);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void DrawLoggerField(KeyValuePair<string, ILogger> item)
|
||||
{
|
||||
ILogger logger = item.Value;
|
||||
string name = item.Key;
|
||||
|
||||
const float fieldWidth = 100f;
|
||||
const float inspectorMargin = 25f;
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.LabelField(new GUIContent(ObjectNames.NicifyVariableName(name)), GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth - fieldWidth - inspectorMargin));
|
||||
logger.filterLogType = (LogType)EditorGUILayout.EnumPopup(logger.filterLogType, GUILayout.Width(fieldWidth));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d6ce9d62a2d2ec4d8cef8a0d22b8dd2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,24 +0,0 @@
|
||||
using Mirror.Logging;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.EditorScripts.Logging
|
||||
{
|
||||
[CustomEditor(typeof(LogSettings))]
|
||||
public class LogSettingsEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
CurrentScriptField();
|
||||
|
||||
LogLevelsGUI.DrawLogFactoryDictionary(target as LogSettings);
|
||||
}
|
||||
|
||||
public void CurrentScriptField()
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script"));
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f4ecb3d81ce9ff44b91f311ee46d4ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,31 +0,0 @@
|
||||
using Mirror.Logging;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Mirror.EditorScripts.Logging
|
||||
{
|
||||
[CustomEditor(typeof(NetworkLogSettings))]
|
||||
public class NetworkLogSettingsEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
NetworkLogSettings target = this.target as NetworkLogSettings;
|
||||
|
||||
if (target.settings == null)
|
||||
{
|
||||
LogSettings newSettings = LogLevelsGUI.DrawCreateNewButton();
|
||||
if (newSettings != null)
|
||||
{
|
||||
SerializedProperty settingsProp = serializedObject.FindProperty("settings");
|
||||
settingsProp.objectReferenceValue = newSettings;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogLevelsGUI.DrawLogFactoryDictionary(target.settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37fb96d5bbf965d47acfc5c8589a1b71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -6,8 +6,6 @@ namespace Mirror.Examples.Chat
|
||||
{
|
||||
public class ChatWindow : MonoBehaviour
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(ChatWindow));
|
||||
|
||||
public InputField chatMessage;
|
||||
public Text chatHistory;
|
||||
public Scrollbar scrollbar;
|
||||
@ -24,7 +22,7 @@ void OnPlayerMessage(Player player, string message)
|
||||
$"<color=blue>{player.playerName}: </color> {message}";
|
||||
AppendMessage(prettyMessage);
|
||||
|
||||
logger.Log(message);
|
||||
Debug.Log(message);
|
||||
}
|
||||
|
||||
public void OnSend()
|
||||
|
@ -18,8 +18,6 @@ namespace Mirror
|
||||
/// </summary>
|
||||
public static class ClientScene
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(ClientScene));
|
||||
|
||||
static bool isSpawnFinished;
|
||||
static NetworkIdentity _localPlayer;
|
||||
|
||||
@ -90,7 +88,7 @@ internal static void Shutdown()
|
||||
/// <param name="identity"></param>
|
||||
internal static void InternalAddPlayer(NetworkIdentity identity)
|
||||
{
|
||||
logger.Log("ClientScene.InternalAddPlayer");
|
||||
Debug.Log("ClientScene.InternalAddPlayer");
|
||||
|
||||
// NOTE: It can be "normal" when changing scenes for the player to be destroyed and recreated.
|
||||
// But, the player structures are not cleaned up, we'll just replace the old player
|
||||
@ -106,7 +104,7 @@ internal static void InternalAddPlayer(NetworkIdentity identity)
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("No ready connection found for setting player controller during InternalAddPlayer");
|
||||
Debug.LogWarning("No ready connection found for setting player controller during InternalAddPlayer");
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +114,7 @@ internal static void InternalAddPlayer(NetworkIdentity identity)
|
||||
/// </summary>
|
||||
internal static void ClearLocalPlayer()
|
||||
{
|
||||
logger.Log("ClientScene.ClearLocalPlayer");
|
||||
Debug.Log("ClientScene.ClearLocalPlayer");
|
||||
|
||||
localPlayer = null;
|
||||
}
|
||||
@ -138,17 +136,17 @@ public static bool AddPlayer(NetworkConnection readyConn)
|
||||
|
||||
if (!ready)
|
||||
{
|
||||
logger.LogError("Must call AddPlayer() with a connection the first time to become ready.");
|
||||
Debug.LogError("Must call AddPlayer() with a connection the first time to become ready.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (readyConnection.identity != null)
|
||||
{
|
||||
logger.LogError("ClientScene.AddPlayer: a PlayerController was already added. Did you call AddPlayer twice?");
|
||||
Debug.LogError("ClientScene.AddPlayer: a PlayerController was already added. Did you call AddPlayer twice?");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("ClientScene.AddPlayer() called with connection [" + readyConnection + "]");
|
||||
// Debug.Log("ClientScene.AddPlayer() called with connection [" + readyConnection + "]");
|
||||
|
||||
readyConnection.Send(new AddPlayerMessage());
|
||||
return true;
|
||||
@ -171,11 +169,11 @@ public static bool Ready(NetworkConnection conn)
|
||||
{
|
||||
if (ready)
|
||||
{
|
||||
logger.LogError("A connection has already been set as ready. There can only be one.");
|
||||
Debug.LogError("A connection has already been set as ready. There can only be one.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("ClientScene.Ready() called with connection [" + conn + "]");
|
||||
// Debug.Log("ClientScene.Ready() called with connection [" + conn + "]");
|
||||
|
||||
if (conn != null)
|
||||
{
|
||||
@ -190,7 +188,7 @@ public static bool Ready(NetworkConnection conn)
|
||||
|
||||
return true;
|
||||
}
|
||||
logger.LogError("Ready() called with invalid connection object: conn=null");
|
||||
Debug.LogError("Ready() called with invalid connection object: conn=null");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -257,34 +255,34 @@ static void RegisterPrefabIdentity(NetworkIdentity prefab)
|
||||
{
|
||||
if (prefab.assetId == Guid.Empty)
|
||||
{
|
||||
logger.LogError($"Can not Register '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead");
|
||||
Debug.LogError($"Can not Register '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead");
|
||||
return;
|
||||
}
|
||||
|
||||
if (prefab.sceneId != 0)
|
||||
{
|
||||
logger.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
||||
Debug.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity[] identities = prefab.GetComponentsInChildren<NetworkIdentity>();
|
||||
if (identities.Length > 1)
|
||||
{
|
||||
logger.LogWarning($"Prefab '{prefab.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
||||
Debug.LogWarning($"Prefab '{prefab.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
||||
}
|
||||
|
||||
if (prefabs.ContainsKey(prefab.assetId))
|
||||
{
|
||||
GameObject existingPrefab = prefabs[prefab.assetId];
|
||||
logger.LogWarning($"Replacing existing prefab with assetId '{prefab.assetId}'. Old prefab '{existingPrefab.name}', New prefab '{prefab.name}'");
|
||||
Debug.LogWarning($"Replacing existing prefab with assetId '{prefab.assetId}'. Old prefab '{existingPrefab.name}', New prefab '{prefab.name}'");
|
||||
}
|
||||
|
||||
if (spawnHandlers.ContainsKey(prefab.assetId) || unspawnHandlers.ContainsKey(prefab.assetId))
|
||||
{
|
||||
logger.LogWarning($"Adding prefab '{prefab.name}' with assetId '{prefab.assetId}' when spawnHandlers with same assetId already exists.");
|
||||
Debug.LogWarning($"Adding prefab '{prefab.name}' with assetId '{prefab.assetId}' when spawnHandlers with same assetId already exists.");
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log($"Registering prefab '{prefab.name}' as asset:{prefab.assetId}");
|
||||
// Debug.Log($"Registering prefab '{prefab.name}' as asset:{prefab.assetId}");
|
||||
|
||||
prefabs[prefab.assetId] = prefab.gameObject;
|
||||
}
|
||||
@ -302,26 +300,26 @@ public static void RegisterPrefab(GameObject prefab, Guid newAssetId)
|
||||
{
|
||||
if (prefab == null)
|
||||
{
|
||||
logger.LogError("Could not register prefab because it was null");
|
||||
Debug.LogError("Could not register prefab because it was null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (newAssetId == Guid.Empty)
|
||||
{
|
||||
logger.LogError($"Could not register '{prefab.name}' with new assetId because the new assetId was empty");
|
||||
Debug.LogError($"Could not register '{prefab.name}' with new assetId because the new assetId was empty");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
}
|
||||
|
||||
if (identity.assetId != Guid.Empty && identity.assetId != newAssetId)
|
||||
{
|
||||
logger.LogError($"Could not register '{prefab.name}' to {newAssetId} because it already had an AssetId, Existing assetId {identity.assetId}");
|
||||
Debug.LogError($"Could not register '{prefab.name}' to {newAssetId} because it already had an AssetId, Existing assetId {identity.assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -341,14 +339,14 @@ public static void RegisterPrefab(GameObject prefab)
|
||||
{
|
||||
if (prefab == null)
|
||||
{
|
||||
logger.LogError("Could not register prefab because it was null");
|
||||
Debug.LogError("Could not register prefab because it was null");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -371,7 +369,7 @@ public static void RegisterPrefab(GameObject prefab, Guid newAssetId, SpawnDeleg
|
||||
// We need this check here because we don't want a null handler in the lambda expression below
|
||||
if (spawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null SpawnHandler for {newAssetId}");
|
||||
Debug.LogError($"Can not Register null SpawnHandler for {newAssetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -391,20 +389,20 @@ public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler,
|
||||
{
|
||||
if (prefab == null)
|
||||
{
|
||||
logger.LogError("Could not register handler for prefab because the prefab was null");
|
||||
Debug.LogError("Could not register handler for prefab because the prefab was null");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError("Could not register handler for '" + prefab.name + "' since it contains no NetworkIdentity component");
|
||||
Debug.LogError("Could not register handler for '" + prefab.name + "' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
}
|
||||
|
||||
if (identity.sceneId != 0)
|
||||
{
|
||||
logger.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
||||
Debug.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -412,14 +410,14 @@ public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler,
|
||||
|
||||
if (assetId == Guid.Empty)
|
||||
{
|
||||
logger.LogError($"Can not Register handler for '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead");
|
||||
Debug.LogError($"Can not Register handler for '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead");
|
||||
return;
|
||||
}
|
||||
|
||||
// We need this check here because we don't want a null handler in the lambda expression below
|
||||
if (spawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
Debug.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -441,32 +439,32 @@ public static void RegisterPrefab(GameObject prefab, Guid newAssetId, SpawnHandl
|
||||
{
|
||||
if (newAssetId == Guid.Empty)
|
||||
{
|
||||
logger.LogError($"Could not register handler for '{prefab.name}' with new assetId because the new assetId was empty");
|
||||
Debug.LogError($"Could not register handler for '{prefab.name}' with new assetId because the new assetId was empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if (prefab == null)
|
||||
{
|
||||
logger.LogError("Could not register handler for prefab because the prefab was null");
|
||||
Debug.LogError("Could not register handler for prefab because the prefab was null");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError("Could not register handler for '" + prefab.name + "' since it contains no NetworkIdentity component");
|
||||
Debug.LogError("Could not register handler for '" + prefab.name + "' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
}
|
||||
|
||||
if (identity.assetId != Guid.Empty && identity.assetId != newAssetId)
|
||||
{
|
||||
logger.LogError($"Could not register Handler for '{prefab.name}' to {newAssetId} because it already had an AssetId, Existing assetId {identity.assetId}");
|
||||
Debug.LogError($"Could not register Handler for '{prefab.name}' to {newAssetId} because it already had an AssetId, Existing assetId {identity.assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (identity.sceneId != 0)
|
||||
{
|
||||
logger.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
||||
Debug.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -475,34 +473,34 @@ public static void RegisterPrefab(GameObject prefab, Guid newAssetId, SpawnHandl
|
||||
|
||||
if (spawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
Debug.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (unspawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null UnSpawnHandler for {assetId}");
|
||||
Debug.LogError($"Can not Register null UnSpawnHandler for {assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawnHandlers.ContainsKey(assetId) || unspawnHandlers.ContainsKey(assetId))
|
||||
{
|
||||
logger.LogWarning($"Replacing existing spawnHandlers for prefab '{prefab.name}' with assetId '{assetId}'");
|
||||
Debug.LogWarning($"Replacing existing spawnHandlers for prefab '{prefab.name}' with assetId '{assetId}'");
|
||||
}
|
||||
|
||||
if (prefabs.ContainsKey(assetId))
|
||||
{
|
||||
// this is error because SpawnPrefab checks prefabs before handler
|
||||
logger.LogError($"assetId '{assetId}' is already used by prefab '{prefabs[assetId].name}', unregister the prefab first before trying to add handler");
|
||||
Debug.LogError($"assetId '{assetId}' is already used by prefab '{prefabs[assetId].name}', unregister the prefab first before trying to add handler");
|
||||
}
|
||||
|
||||
NetworkIdentity[] identities = prefab.GetComponentsInChildren<NetworkIdentity>();
|
||||
if (identities.Length > 1)
|
||||
{
|
||||
logger.LogWarning($"Prefab '{prefab.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
||||
Debug.LogWarning($"Prefab '{prefab.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("Registering custom prefab '" + prefab.name + "' as asset:" + assetId + " " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
|
||||
// Debug.Log("Registering custom prefab '" + prefab.name + "' as asset:" + assetId + " " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
|
||||
|
||||
spawnHandlers[assetId] = spawnHandler;
|
||||
unspawnHandlers[assetId] = unspawnHandler;
|
||||
@ -521,20 +519,20 @@ public static void RegisterPrefab(GameObject prefab, SpawnHandlerDelegate spawnH
|
||||
{
|
||||
if (prefab == null)
|
||||
{
|
||||
logger.LogError("Could not register handler for prefab because the prefab was null");
|
||||
Debug.LogError("Could not register handler for prefab because the prefab was null");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError("Could not register handler for '" + prefab.name + "' since it contains no NetworkIdentity component");
|
||||
Debug.LogError("Could not register handler for '" + prefab.name + "' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
}
|
||||
|
||||
if (identity.sceneId != 0)
|
||||
{
|
||||
logger.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
||||
Debug.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -542,40 +540,40 @@ public static void RegisterPrefab(GameObject prefab, SpawnHandlerDelegate spawnH
|
||||
|
||||
if (assetId == Guid.Empty)
|
||||
{
|
||||
logger.LogError($"Can not Register handler for '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead");
|
||||
Debug.LogError($"Can not Register handler for '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead");
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
Debug.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (unspawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null UnSpawnHandler for {assetId}");
|
||||
Debug.LogError($"Can not Register null UnSpawnHandler for {assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawnHandlers.ContainsKey(assetId) || unspawnHandlers.ContainsKey(assetId))
|
||||
{
|
||||
logger.LogWarning($"Replacing existing spawnHandlers for prefab '{prefab.name}' with assetId '{assetId}'");
|
||||
Debug.LogWarning($"Replacing existing spawnHandlers for prefab '{prefab.name}' with assetId '{assetId}'");
|
||||
}
|
||||
|
||||
if (prefabs.ContainsKey(assetId))
|
||||
{
|
||||
// this is error because SpawnPrefab checks prefabs before handler
|
||||
logger.LogError($"assetId '{assetId}' is already used by prefab '{prefabs[assetId].name}', unregister the prefab first before trying to add handler");
|
||||
Debug.LogError($"assetId '{assetId}' is already used by prefab '{prefabs[assetId].name}', unregister the prefab first before trying to add handler");
|
||||
}
|
||||
|
||||
NetworkIdentity[] identities = prefab.GetComponentsInChildren<NetworkIdentity>();
|
||||
if (identities.Length > 1)
|
||||
{
|
||||
logger.LogWarning($"Prefab '{prefab.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
||||
Debug.LogWarning($"Prefab '{prefab.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("Registering custom prefab '" + prefab.name + "' as asset:" + assetId + " " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
|
||||
// Debug.Log("Registering custom prefab '" + prefab.name + "' as asset:" + assetId + " " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
|
||||
|
||||
spawnHandlers[assetId] = spawnHandler;
|
||||
unspawnHandlers[assetId] = unspawnHandler;
|
||||
@ -589,14 +587,14 @@ public static void UnregisterPrefab(GameObject prefab)
|
||||
{
|
||||
if (prefab == null)
|
||||
{
|
||||
logger.LogError("Could not unregister prefab because it was null");
|
||||
Debug.LogError("Could not unregister prefab because it was null");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError("Could not unregister '" + prefab.name + "' since it contains no NetworkIdentity component");
|
||||
Debug.LogError("Could not unregister '" + prefab.name + "' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -619,7 +617,7 @@ public static void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler
|
||||
// We need this check here because we don't want a null handler in the lambda expression below
|
||||
if (spawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
Debug.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -637,34 +635,34 @@ public static void RegisterSpawnHandler(Guid assetId, SpawnHandlerDelegate spawn
|
||||
{
|
||||
if (spawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
Debug.LogError($"Can not Register null SpawnHandler for {assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (unspawnHandler == null)
|
||||
{
|
||||
logger.LogError($"Can not Register null UnSpawnHandler for {assetId}");
|
||||
Debug.LogError($"Can not Register null UnSpawnHandler for {assetId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (assetId == Guid.Empty)
|
||||
{
|
||||
logger.LogError("Can not Register SpawnHandler for empty Guid");
|
||||
Debug.LogError("Can not Register SpawnHandler for empty Guid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawnHandlers.ContainsKey(assetId) || unspawnHandlers.ContainsKey(assetId))
|
||||
{
|
||||
logger.LogWarning($"Replacing existing spawnHandlers for {assetId}");
|
||||
Debug.LogWarning($"Replacing existing spawnHandlers for {assetId}");
|
||||
}
|
||||
|
||||
if (prefabs.ContainsKey(assetId))
|
||||
{
|
||||
// this is error because SpawnPrefab checks prefabs before handler
|
||||
logger.LogError($"assetId '{assetId}' is already used by prefab '{prefabs[assetId].name}'");
|
||||
Debug.LogError($"assetId '{assetId}' is already used by prefab '{prefabs[assetId].name}'");
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("RegisterSpawnHandler asset '" + assetId + "' " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
|
||||
// Debug.Log("RegisterSpawnHandler asset '" + assetId + "' " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
|
||||
|
||||
spawnHandlers[assetId] = spawnHandler;
|
||||
unspawnHandlers[assetId] = unspawnHandler;
|
||||
@ -734,8 +732,8 @@ public static void DestroyAllClientObjects()
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
logger.LogException(e);
|
||||
logger.LogError("Could not DestroyAllClientObjects because spawned list was modified during loop, make sure you are not modifying NetworkIdentity.spawned by calling NetworkServer.Destroy or NetworkServer.Spawn in OnDestroy or OnDisable.");
|
||||
Debug.LogException(e);
|
||||
Debug.LogError("Could not DestroyAllClientObjects because spawned list was modified during loop, make sure you are not modifying NetworkIdentity.spawned by calling NetworkServer.Destroy or NetworkServer.Spawn in OnDestroy or OnDisable.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -782,7 +780,7 @@ internal static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage ms
|
||||
|
||||
internal static void OnSpawn(SpawnMessage msg)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId:X} pos={msg.position}");
|
||||
// Debug.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId:X} pos={msg.position}");
|
||||
|
||||
if (FindOrSpawnObject(msg, out NetworkIdentity identity))
|
||||
{
|
||||
@ -806,7 +804,7 @@ internal static bool FindOrSpawnObject(SpawnMessage msg, out NetworkIdentity ide
|
||||
|
||||
if (msg.assetId == Guid.Empty && msg.sceneId == 0)
|
||||
{
|
||||
logger.LogError($"OnSpawn message with netId '{msg.netId}' has no AssetId or sceneId");
|
||||
Debug.LogError($"OnSpawn message with netId '{msg.netId}' has no AssetId or sceneId");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -814,7 +812,7 @@ internal static bool FindOrSpawnObject(SpawnMessage msg, out NetworkIdentity ide
|
||||
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError($"Could not spawn assetId={msg.assetId} scene={msg.sceneId:X} netId={msg.netId}");
|
||||
Debug.LogError($"Could not spawn assetId={msg.assetId} scene={msg.sceneId:X} netId={msg.netId}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -832,10 +830,7 @@ static NetworkIdentity SpawnPrefab(SpawnMessage msg)
|
||||
if (GetPrefab(msg.assetId, out GameObject prefab))
|
||||
{
|
||||
GameObject obj = Object.Instantiate(prefab, msg.position, msg.rotation);
|
||||
if (logger.LogEnabled())
|
||||
{
|
||||
logger.Log("Client spawn handler instantiating [netId:" + msg.netId + " asset ID:" + msg.assetId + " pos:" + msg.position + " rotation: " + msg.rotation + "]");
|
||||
}
|
||||
// Debug.Log("Client spawn handler instantiating [netId:" + msg.netId + " asset ID:" + msg.assetId + " pos:" + msg.position + " rotation: " + msg.rotation + "]");
|
||||
|
||||
return obj.GetComponent<NetworkIdentity>();
|
||||
}
|
||||
@ -844,18 +839,18 @@ static NetworkIdentity SpawnPrefab(SpawnMessage msg)
|
||||
GameObject obj = handler(msg);
|
||||
if (obj == null)
|
||||
{
|
||||
logger.LogError($"Spawn Handler returned null, Handler assetId '{msg.assetId}'");
|
||||
Debug.LogError($"Spawn Handler returned null, Handler assetId '{msg.assetId}'");
|
||||
return null;
|
||||
}
|
||||
NetworkIdentity identity = obj.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError($"Object Spawned by handler did not have a NetworkIdentity, Handler assetId '{msg.assetId}'");
|
||||
Debug.LogError($"Object Spawned by handler did not have a NetworkIdentity, Handler assetId '{msg.assetId}'");
|
||||
return null;
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
logger.LogError($"Failed to spawn server object, did you forget to add it to the NetworkManager? assetId={msg.assetId} netId={msg.netId}");
|
||||
Debug.LogError($"Failed to spawn server object, did you forget to add it to the NetworkManager? assetId={msg.assetId} netId={msg.netId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -864,19 +859,16 @@ static NetworkIdentity SpawnSceneObject(SpawnMessage msg)
|
||||
NetworkIdentity identity = GetAndRemoveSceneObject(msg.sceneId);
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError($"Spawn scene object not found for {msg.sceneId:X} SpawnableObjects.Count={spawnableObjects.Count}");
|
||||
Debug.LogError($"Spawn scene object not found for {msg.sceneId:X} SpawnableObjects.Count={spawnableObjects.Count}");
|
||||
|
||||
// dump the whole spawnable objects dict for easier debugging
|
||||
if (logger.LogEnabled())
|
||||
{
|
||||
foreach (KeyValuePair<ulong, NetworkIdentity> kvp in spawnableObjects)
|
||||
logger.Log($"Spawnable: SceneId={kvp.Key:X} name={kvp.Value.name}");
|
||||
}
|
||||
// foreach (KeyValuePair<ulong, NetworkIdentity> kvp in spawnableObjects)
|
||||
// Debug.Log($"Spawnable: SceneId={kvp.Key:X} name={kvp.Value.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// only log this when successful
|
||||
if (logger.LogEnabled()) logger.Log($"Client spawn for [netId:{msg.netId}] [sceneId:{msg.sceneId:X}] obj:{identity}");
|
||||
// Debug.Log($"Client spawn for [netId:{msg.netId}] [sceneId:{msg.sceneId:X}] obj:{identity}");
|
||||
}
|
||||
|
||||
return identity;
|
||||
@ -894,7 +886,7 @@ static NetworkIdentity GetAndRemoveSceneObject(ulong sceneId)
|
||||
|
||||
internal static void OnObjectSpawnStarted(ObjectSpawnStartedMessage _)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("SpawnStarted");
|
||||
// Debug.Log("SpawnStarted");
|
||||
|
||||
PrepareToSpawnSceneObjects();
|
||||
isSpawnFinished = false;
|
||||
@ -902,7 +894,7 @@ internal static void OnObjectSpawnStarted(ObjectSpawnStartedMessage _)
|
||||
|
||||
internal static void OnObjectSpawnFinished(ObjectSpawnFinishedMessage _)
|
||||
{
|
||||
logger.Log("SpawnFinished");
|
||||
Debug.Log("SpawnFinished");
|
||||
|
||||
ClearNullFromSpawned();
|
||||
|
||||
@ -922,7 +914,7 @@ internal static void OnObjectSpawnFinished(ObjectSpawnFinishedMessage _)
|
||||
static void ClearNullFromSpawned()
|
||||
{
|
||||
// spawned has null objects after changing scenes on client using NetworkManager.ServerChangeScene
|
||||
// remove them here so that 2nd loop below does not get NullReferenceException
|
||||
// remove them here so that 2nd loop below does not get NullReferenceException
|
||||
// see https://github.com/vis2k/Mirror/pull/2240
|
||||
// TODO fix scene logic so that client scene doesn't have null objects
|
||||
foreach (KeyValuePair<uint, NetworkIdentity> kvp in NetworkIdentity.spawned)
|
||||
@ -953,7 +945,7 @@ internal static void OnObjectDestroy(ObjectDestroyMessage msg)
|
||||
|
||||
static void DestroyObject(uint netId)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ClientScene.OnObjDestroy netId:" + netId);
|
||||
// Debug.Log("ClientScene.OnObjDestroy netId:" + netId);
|
||||
|
||||
if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity localObject) && localObject != null)
|
||||
{
|
||||
@ -978,20 +970,20 @@ static void DestroyObject(uint netId)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.LogEnabled()) logger.LogWarning("Did not find target for destroy message for " + netId);
|
||||
// Debug.LogWarning("Did not find target for destroy message for " + netId);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void OnHostClientObjectDestroy(ObjectDestroyMessage msg)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ClientScene.OnLocalObjectObjDestroy netId:" + msg.netId);
|
||||
// Debug.Log("ClientScene.OnLocalObjectObjDestroy netId:" + msg.netId);
|
||||
|
||||
NetworkIdentity.spawned.Remove(msg.netId);
|
||||
}
|
||||
|
||||
internal static void OnHostClientObjectHide(ObjectHideMessage msg)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ClientScene::OnLocalObjectObjHide netId:" + msg.netId);
|
||||
// Debug.Log("ClientScene::OnLocalObjectObjHide netId:" + msg.netId);
|
||||
|
||||
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity localObject) && localObject != null)
|
||||
{
|
||||
@ -1016,7 +1008,7 @@ internal static void OnHostClientSpawn(SpawnMessage msg)
|
||||
|
||||
internal static void OnUpdateVarsMessage(UpdateVarsMessage msg)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ClientScene.OnUpdateVarsMessage " + msg.netId);
|
||||
// Debug.Log("ClientScene.OnUpdateVarsMessage " + msg.netId);
|
||||
|
||||
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity localObject) && localObject != null)
|
||||
{
|
||||
@ -1025,13 +1017,13 @@ internal static void OnUpdateVarsMessage(UpdateVarsMessage msg)
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("Did not find target for sync message for " + msg.netId + " . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message.");
|
||||
Debug.LogWarning("Did not find target for sync message for " + msg.netId + " . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message.");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void OnRPCMessage(RpcMessage msg)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ClientScene.OnRPCMessage hash:" + msg.functionHash + " netId:" + msg.netId);
|
||||
// Debug.Log("ClientScene.OnRPCMessage hash:" + msg.functionHash + " netId:" + msg.netId);
|
||||
|
||||
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity identity))
|
||||
{
|
||||
@ -1048,7 +1040,7 @@ static void CheckForLocalPlayer(NetworkIdentity identity)
|
||||
identity.connectionToServer = readyConnection;
|
||||
identity.OnStartLocalPlayer();
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("ClientScene.OnOwnerMessage - player=" + identity.name);
|
||||
// Debug.Log("ClientScene.OnOwnerMessage - player=" + identity.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,8 +81,6 @@ public void ResetBuffer()
|
||||
// send messages on this connection causes the server's handler function to be invoked directly.
|
||||
internal class ULocalConnectionToServer : NetworkConnectionToServer
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(ULocalConnectionToClient));
|
||||
|
||||
internal ULocalConnectionToClient connectionToClient;
|
||||
internal readonly LocalConnectionBuffer buffer = new LocalConnectionBuffer();
|
||||
|
||||
@ -92,7 +90,7 @@ internal override bool Send(ArraySegment<byte> segment, int channelId = Channels
|
||||
{
|
||||
if (segment.Count == 0)
|
||||
{
|
||||
logger.LogError("LocalConnection.SendBytes cannot send zero bytes");
|
||||
Debug.LogError("LocalConnection.SendBytes cannot send zero bytes");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace Mirror
|
||||
{
|
||||
public static class LogFilter
|
||||
{
|
||||
public static bool Debug = false;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6928b080072948f7b2909b4025fcc79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63d647500ca1bfa4a845bc1f4cff9dcc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,44 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Logging
|
||||
{
|
||||
public class ConsoleColorLogHandler : ILogHandler
|
||||
{
|
||||
readonly bool showExceptionStackTrace;
|
||||
|
||||
public ConsoleColorLogHandler(bool showExceptionStackTrace)
|
||||
{
|
||||
this.showExceptionStackTrace = showExceptionStackTrace;
|
||||
}
|
||||
|
||||
public void LogException(Exception exception, UnityEngine.Object context)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Exception: {exception.Message}");
|
||||
if (showExceptionStackTrace)
|
||||
{
|
||||
Console.WriteLine($" {exception.StackTrace}");
|
||||
}
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
|
||||
{
|
||||
switch (logType)
|
||||
{
|
||||
case LogType.Exception:
|
||||
case LogType.Error:
|
||||
case LogType.Assert:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
break;
|
||||
case LogType.Warning:
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine(string.Format(format, args));
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a9618569c20a504aa86feb5913c70e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,50 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Logging
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
public static class EditorLogSettingsLoader
|
||||
{
|
||||
[InitializeOnLoadMethod]
|
||||
static void Init()
|
||||
{
|
||||
// load settings first time LogFactory is used in the editor
|
||||
LoadLogSettingsIntoDictionary();
|
||||
}
|
||||
|
||||
public static void LoadLogSettingsIntoDictionary()
|
||||
{
|
||||
LogSettings settings = FindLogSettings();
|
||||
if (settings != null)
|
||||
{
|
||||
settings.LoadIntoDictionary(LogFactory.loggers);
|
||||
}
|
||||
}
|
||||
|
||||
static LogSettings cache;
|
||||
public static LogSettings FindLogSettings()
|
||||
{
|
||||
if (cache != null)
|
||||
return cache;
|
||||
|
||||
string[] assetGuids = AssetDatabase.FindAssets("t:" + nameof(LogSettings));
|
||||
if (assetGuids.Length == 0)
|
||||
return null;
|
||||
|
||||
string firstGuid = assetGuids[0];
|
||||
|
||||
string path = AssetDatabase.GUIDToAssetPath(firstGuid);
|
||||
cache = AssetDatabase.LoadAssetAtPath<LogSettings>(path);
|
||||
|
||||
if (assetGuids.Length > 2)
|
||||
{
|
||||
Debug.LogWarning("Found more than one LogSettings, Delete extra settings. Using first asset found: " + path);
|
||||
}
|
||||
Debug.Assert(cache != null, "Failed to load asset at: " + path);
|
||||
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a39aa1e48aa54eb4e964f0191c1dcdce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,100 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
public static class LogFactory
|
||||
{
|
||||
internal static readonly SortedDictionary<string, ILogger> loggers = new SortedDictionary<string, ILogger>();
|
||||
|
||||
public static SortedDictionary<string, ILogger>.ValueCollection AllLoggers => loggers.Values;
|
||||
|
||||
/// <summary>
|
||||
/// logHandler used for new loggers
|
||||
/// </summary>
|
||||
static ILogHandler defaultLogHandler = Debug.unityLogger;
|
||||
|
||||
/// <summary>
|
||||
/// if true sets all log level to LogType.Log
|
||||
/// </summary>
|
||||
static bool debugMode = false;
|
||||
|
||||
public static ILogger GetLogger<T>(LogType defaultLogLevel = LogType.Warning)
|
||||
{
|
||||
return GetLogger(typeof(T).Name, defaultLogLevel);
|
||||
}
|
||||
|
||||
public static ILogger GetLogger(System.Type type, LogType defaultLogLevel = LogType.Warning)
|
||||
{
|
||||
return GetLogger(type.Name, defaultLogLevel);
|
||||
}
|
||||
|
||||
public static ILogger GetLogger(string loggerName, LogType defaultLogLevel = LogType.Warning)
|
||||
{
|
||||
if (loggers.TryGetValue(loggerName, out ILogger logger))
|
||||
{
|
||||
return logger;
|
||||
}
|
||||
|
||||
logger = new Logger(defaultLogHandler)
|
||||
{
|
||||
// by default, log warnings and up
|
||||
filterLogType = debugMode ? LogType.Log : defaultLogLevel
|
||||
};
|
||||
|
||||
loggers[loggerName] = logger;
|
||||
return logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes all log levels LogType.Log, this is so that NetworkManger.showDebugMessages can still be used
|
||||
/// </summary>
|
||||
public static void EnableDebugMode()
|
||||
{
|
||||
debugMode = true;
|
||||
|
||||
foreach (ILogger logger in loggers.Values)
|
||||
{
|
||||
logger.filterLogType = LogType.Log;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replacing log handler for all existing loggers and sets defaultLogHandler for new loggers
|
||||
/// </summary>
|
||||
/// <param name="logHandler"></param>
|
||||
public static void ReplaceLogHandler(ILogHandler logHandler)
|
||||
{
|
||||
defaultLogHandler = logHandler;
|
||||
|
||||
foreach (ILogger logger in loggers.Values)
|
||||
{
|
||||
logger.logHandler = logHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ILoggerExtensions
|
||||
{
|
||||
public static void LogError(this ILogger logger, object message)
|
||||
{
|
||||
logger.Log(LogType.Error, message);
|
||||
}
|
||||
|
||||
public static void Assert(this ILogger logger, bool condition, string message)
|
||||
{
|
||||
if (!condition)
|
||||
logger.Log(LogType.Assert, message);
|
||||
}
|
||||
|
||||
public static void LogWarning(this ILogger logger, object message)
|
||||
{
|
||||
logger.Log(LogType.Warning, message);
|
||||
}
|
||||
|
||||
public static bool LogEnabled(this ILogger logger) => logger.IsLogTypeAllowed(LogType.Log);
|
||||
public static bool WarnEnabled(this ILogger logger) => logger.IsLogTypeAllowed(LogType.Warning);
|
||||
public static bool ErrorEnabled(this ILogger logger) => logger.IsLogTypeAllowed(LogType.Error);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d06522432d5a44e1587967a4731cd279
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,67 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Logging
|
||||
{
|
||||
public class LogSettings : ScriptableObject
|
||||
{
|
||||
public List<LoggerSettings> loglevels = new List<LoggerSettings>();
|
||||
|
||||
[Serializable]
|
||||
public struct LoggerSettings
|
||||
{
|
||||
public string name;
|
||||
public LogType logLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LogSettingsExt
|
||||
{
|
||||
public static void SaveFromDictionary(this LogSettings settings, SortedDictionary<string, ILogger> dictionary)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
Debug.LogWarning("Could not SaveFromDictionary because LogSettings were null");
|
||||
return;
|
||||
}
|
||||
|
||||
settings.loglevels.Clear();
|
||||
|
||||
foreach (KeyValuePair<string, ILogger> kvp in dictionary)
|
||||
{
|
||||
settings.loglevels.Add(new LogSettings.LoggerSettings { name = kvp.Key, logLevel = kvp.Value.filterLogType });
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(settings);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void LoadIntoDictionary(this LogSettings settings, SortedDictionary<string, ILogger> dictionary)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
Debug.LogWarning("Could not LoadIntoDictionary because LogSettings were null");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (LogSettings.LoggerSettings logLevel in settings.loglevels)
|
||||
{
|
||||
if (dictionary.TryGetValue(logLevel.name, out ILogger logger))
|
||||
{
|
||||
logger.filterLogType = logLevel.logLevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger = new Logger(Debug.unityLogger)
|
||||
{
|
||||
filterLogType = logLevel.logLevel
|
||||
};
|
||||
|
||||
dictionary[logLevel.name] = logger;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 633889a39717fde4fa28dd6b948dfac7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,24 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to replace log hanlder with Console Color LogHandler
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Network/NetworkHeadlessLogger")]
|
||||
[HelpURL("https://mirror-networking.com/docs/Components/NetworkHeadlessLogger.html")]
|
||||
public class NetworkHeadlessLogger : MonoBehaviour
|
||||
{
|
||||
#pragma warning disable CS0414 // unused private members
|
||||
[SerializeField] bool showExceptionStackTrace = false;
|
||||
#pragma warning restore CS0414 // unused private members
|
||||
|
||||
void Awake()
|
||||
{
|
||||
#if UNITY_SERVER
|
||||
LogFactory.ReplaceLogHandler(new ConsoleColorLogHandler(showExceptionStackTrace));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7627623f2b9fad4484082517cd73e67
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,46 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to load LogSettings in build
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Network/NetworkLogSettings")]
|
||||
[HelpURL("https://mirror-networking.com/docs/Components/NetworkLogSettings.html")]
|
||||
public class NetworkLogSettings : MonoBehaviour
|
||||
{
|
||||
[Header("Log Settings Asset")]
|
||||
[SerializeField] internal LogSettings settings;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// called when component is added to GameObject
|
||||
void Reset()
|
||||
{
|
||||
LogSettings existingSettings = EditorLogSettingsLoader.FindLogSettings();
|
||||
if (existingSettings != null)
|
||||
{
|
||||
settings = existingSettings;
|
||||
|
||||
UnityEditor.EditorUtility.SetDirty(this);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Awake()
|
||||
{
|
||||
RefreshDictionary();
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
// if settings field is changed
|
||||
RefreshDictionary();
|
||||
}
|
||||
|
||||
void RefreshDictionary()
|
||||
{
|
||||
settings.LoadIntoDictionary(LogFactory.loggers);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac6e8eccf4b6f4dc7b24c276ef47fde8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -16,8 +16,6 @@ namespace Mirror
|
||||
// (probably even shorter)
|
||||
public static class MessagePacker
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(MessagePacker));
|
||||
|
||||
public static int GetId<T>() where T : IMessageBase
|
||||
{
|
||||
return GetId(typeof(T));
|
||||
@ -107,7 +105,7 @@ internal static NetworkMessageDelegate MessageHandler<T, C>(Action<C, T> handler
|
||||
if (requireAuthenication && !conn.isAuthenticated)
|
||||
{
|
||||
// message requires authentication, but the connection was not authenticated
|
||||
logger.LogWarning($"Closing connection: {conn}. Received message {typeof(T)} that required authentication, but the user has not authenticated yet");
|
||||
Debug.LogWarning($"Closing connection: {conn}. Received message {typeof(T)} that required authentication, but the user has not authenticated yet");
|
||||
conn.Disconnect();
|
||||
return;
|
||||
}
|
||||
@ -119,7 +117,7 @@ internal static NetworkMessageDelegate MessageHandler<T, C>(Action<C, T> handler
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError("Closed connection: " + conn + ". This can happen if the other side accidentally (or an attacker intentionally) sent invalid data. Reason: " + exception);
|
||||
Debug.LogError("Closed connection: " + conn + ". This can happen if the other side accidentally (or an attacker intentionally) sent invalid data. Reason: " + exception);
|
||||
conn.Disconnect();
|
||||
return;
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ public enum SyncMode { Observers, Owner }
|
||||
[HelpURL("https://mirror-networking.com/docs/Guides/NetworkBehaviour.html")]
|
||||
public abstract class NetworkBehaviour : MonoBehaviour
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkBehaviour));
|
||||
|
||||
internal float lastSyncTime;
|
||||
|
||||
// hidden because NetworkBehaviourInspector shows it only if has OnSerialize.
|
||||
@ -131,7 +129,7 @@ public NetworkIdentity netIdentity
|
||||
// do this 2nd check inside first if so that we are not checking == twice on unity Object
|
||||
if (netIdentityCache == null)
|
||||
{
|
||||
logger.LogError("There is no NetworkIdentity on " + name + ". Please add one.");
|
||||
Debug.LogError("There is no NetworkIdentity on " + name + ". Please add one.");
|
||||
}
|
||||
}
|
||||
return netIdentityCache;
|
||||
@ -154,7 +152,7 @@ public int ComponentIndex
|
||||
}
|
||||
|
||||
// this should never happen
|
||||
logger.LogError("Could not find component in GameObject. You should not add/remove components in networked objects dynamically", this);
|
||||
Debug.LogError("Could not find component in GameObject. You should not add/remove components in networked objects dynamically", this);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -177,19 +175,19 @@ protected void SendCommandInternal(Type invokeClass, string cmdName, NetworkWrit
|
||||
// to avoid Wrapper functions. a lot of people requested this.
|
||||
if (!NetworkClient.active)
|
||||
{
|
||||
logger.LogError($"Command Function {cmdName} called without an active client.");
|
||||
Debug.LogError($"Command Function {cmdName} called without an active client.");
|
||||
return;
|
||||
}
|
||||
// local players can always send commands, regardless of authority, other objects must have authority.
|
||||
if (!(ignoreAuthority || isLocalPlayer || hasAuthority))
|
||||
{
|
||||
logger.LogWarning($"Trying to send command for object without authority. {invokeClass.ToString()}.{cmdName}");
|
||||
Debug.LogWarning($"Trying to send command for object without authority. {invokeClass.ToString()}.{cmdName}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ClientScene.readyConnection == null)
|
||||
{
|
||||
logger.LogError("Send command attempted with no client running [client=" + connectionToServer + "].");
|
||||
Debug.LogError("Send command attempted with no client running [client=" + connectionToServer + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -216,13 +214,13 @@ protected void SendRPCInternal(Type invokeClass, string rpcName, NetworkWriter w
|
||||
// this was in Weaver before
|
||||
if (!NetworkServer.active)
|
||||
{
|
||||
logger.LogError("RPC Function " + rpcName + " called on Client.");
|
||||
Debug.LogError("RPC Function " + rpcName + " called on Client.");
|
||||
return;
|
||||
}
|
||||
// This cannot use NetworkServer.active, as that is not specific to this object.
|
||||
if (!isServer)
|
||||
{
|
||||
logger.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
|
||||
Debug.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -249,7 +247,7 @@ protected void SendTargetRPCInternal(NetworkConnection conn, Type invokeClass, s
|
||||
// this was in Weaver before
|
||||
if (!NetworkServer.active)
|
||||
{
|
||||
logger.LogError("TargetRPC Function " + rpcName + " called on client.");
|
||||
Debug.LogError("TargetRPC Function " + rpcName + " called on client.");
|
||||
return;
|
||||
}
|
||||
// connection parameter is optional. assign if null.
|
||||
@ -260,13 +258,13 @@ protected void SendTargetRPCInternal(NetworkConnection conn, Type invokeClass, s
|
||||
// this was in Weaver before
|
||||
if (conn is NetworkConnectionToServer)
|
||||
{
|
||||
logger.LogError("TargetRPC Function " + rpcName + " called on connection to server");
|
||||
Debug.LogError("TargetRPC Function " + rpcName + " called on connection to server");
|
||||
return;
|
||||
}
|
||||
// This cannot use NetworkServer.active, as that is not specific to this object.
|
||||
if (!isServer)
|
||||
{
|
||||
logger.LogWarning("TargetRpc " + rpcName + " called on un-spawned object: " + name);
|
||||
Debug.LogWarning("TargetRpc " + rpcName + " called on un-spawned object: " + name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -303,7 +301,7 @@ protected bool SyncVarGameObjectEqual(GameObject newGameObject, uint netIdField)
|
||||
newNetId = identity.netId;
|
||||
if (newNetId == 0)
|
||||
{
|
||||
logger.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?");
|
||||
Debug.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -327,12 +325,12 @@ protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gam
|
||||
newNetId = identity.netId;
|
||||
if (newNetId == 0)
|
||||
{
|
||||
logger.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?");
|
||||
Debug.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("SetSyncVar GameObject " + GetType().Name + " bit [" + dirtyBit + "] netfieldId:" + netIdField + "->" + newNetId);
|
||||
// logger.Log("SetSyncVar GameObject " + GetType().Name + " bit [" + dirtyBit + "] netfieldId:" + netIdField + "->" + newNetId);
|
||||
SetDirtyBit(dirtyBit);
|
||||
// assign new one on the server, and in case we ever need it on client too
|
||||
gameObjectField = newGameObject;
|
||||
@ -369,7 +367,7 @@ protected bool SyncVarNetworkIdentityEqual(NetworkIdentity newIdentity, uint net
|
||||
newNetId = newIdentity.netId;
|
||||
if (newNetId == 0)
|
||||
{
|
||||
logger.LogWarning("SetSyncVarNetworkIdentity NetworkIdentity " + newIdentity + " has a zero netId. Maybe it is not spawned yet?");
|
||||
Debug.LogWarning("SetSyncVarNetworkIdentity NetworkIdentity " + newIdentity + " has a zero netId. Maybe it is not spawned yet?");
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,11 +388,11 @@ protected void SetSyncVarNetworkIdentity(NetworkIdentity newIdentity, ref Networ
|
||||
newNetId = newIdentity.netId;
|
||||
if (newNetId == 0)
|
||||
{
|
||||
logger.LogWarning("SetSyncVarNetworkIdentity NetworkIdentity " + newIdentity + " has a zero netId. Maybe it is not spawned yet?");
|
||||
Debug.LogWarning("SetSyncVarNetworkIdentity NetworkIdentity " + newIdentity + " has a zero netId. Maybe it is not spawned yet?");
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("SetSyncVarNetworkIdentity NetworkIdentity " + GetType().Name + " bit [" + dirtyBit + "] netIdField:" + netIdField + "->" + newNetId);
|
||||
// logger.Log("SetSyncVarNetworkIdentity NetworkIdentity " + GetType().Name + " bit [" + dirtyBit + "] netIdField:" + netIdField + "->" + newNetId);
|
||||
SetDirtyBit(dirtyBit);
|
||||
netIdField = newNetId;
|
||||
// assign new one on the server, and in case we ever need it on client too
|
||||
@ -428,7 +426,7 @@ protected bool SyncVarEqual<T>(T value, ref T fieldValue)
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
protected void SetSyncVar<T>(T value, ref T fieldValue, ulong dirtyBit)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("SetSyncVar " + GetType().Name + " bit [" + dirtyBit + "] " + fieldValue + "->" + value);
|
||||
// logger.Log("SetSyncVar " + GetType().Name + " bit [" + dirtyBit + "] " + fieldValue + "->" + value);
|
||||
SetDirtyBit(dirtyBit);
|
||||
fieldValue = value;
|
||||
}
|
||||
|
@ -20,8 +20,6 @@ public enum ConnectState
|
||||
/// </summary>
|
||||
public static class NetworkClient
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkClient));
|
||||
|
||||
/// <summary>
|
||||
/// The registered network message handlers.
|
||||
/// </summary>
|
||||
@ -62,8 +60,7 @@ public static class NetworkClient
|
||||
/// <param name="address"></param>
|
||||
public static void Connect(string address)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Client Connect: " + address);
|
||||
logger.Assert(Transport.activeTransport != null, "There was no active transport when calling NetworkClient.Connect, If you are calling Connect manually then make sure to set 'Transport.activeTransport' first");
|
||||
// Debug.Log("Client Connect: " + address);
|
||||
|
||||
RegisterSystemHandlers(false);
|
||||
Transport.activeTransport.enabled = true;
|
||||
@ -83,8 +80,7 @@ public static void Connect(string address)
|
||||
/// <param name="uri">Address of the server to connect to</param>
|
||||
public static void Connect(Uri uri)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Client Connect: " + uri);
|
||||
logger.Assert(Transport.activeTransport != null, "There was no active transport when calling NetworkClient.Connect, If you are calling Connect manually then make sure to set 'Transport.activeTransport' first");
|
||||
// Debug.Log("Client Connect: " + uri);
|
||||
|
||||
RegisterSystemHandlers(false);
|
||||
Transport.activeTransport.enabled = true;
|
||||
@ -100,7 +96,7 @@ public static void Connect(Uri uri)
|
||||
|
||||
public static void ConnectHost()
|
||||
{
|
||||
logger.Log("Client Connect Host to Server");
|
||||
Debug.Log("Client Connect Host to Server");
|
||||
|
||||
RegisterSystemHandlers(true);
|
||||
|
||||
@ -155,7 +151,7 @@ static void InitializeTransportHandlers()
|
||||
|
||||
static void OnError(Exception exception)
|
||||
{
|
||||
logger.LogException(exception);
|
||||
Debug.LogException(exception);
|
||||
}
|
||||
|
||||
static void OnDisconnected()
|
||||
@ -173,7 +169,7 @@ internal static void OnDataReceived(ArraySegment<byte> data, int channelId)
|
||||
{
|
||||
connection.TransportReceive(data, channelId);
|
||||
}
|
||||
else logger.LogError("Skipped Data message handling because connection is null.");
|
||||
else Debug.LogError("Skipped Data message handling because connection is null.");
|
||||
}
|
||||
|
||||
static void OnConnected()
|
||||
@ -189,7 +185,7 @@ static void OnConnected()
|
||||
NetworkTime.UpdateClient();
|
||||
connection.InvokeHandler(new ConnectMessage(), -1);
|
||||
}
|
||||
else logger.LogError("Skipped Connect message handling because connection is null.");
|
||||
else Debug.LogError("Skipped Connect message handling because connection is null.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -246,12 +242,12 @@ public static bool Send<T>(T message, int channelId = Channels.DefaultReliable)
|
||||
{
|
||||
if (connectState != ConnectState.Connected)
|
||||
{
|
||||
logger.LogError("NetworkClient Send when not connected to a server");
|
||||
Debug.LogError("NetworkClient Send when not connected to a server");
|
||||
return false;
|
||||
}
|
||||
return connection.Send(message, channelId);
|
||||
}
|
||||
logger.LogError("NetworkClient Send with no connection");
|
||||
Debug.LogError("NetworkClient Send with no connection");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -315,7 +311,7 @@ internal static void RegisterSystemHandlers(bool hostMode)
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
if (handlers.ContainsKey(msgType))
|
||||
{
|
||||
logger.LogWarning($"NetworkClient.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning.");
|
||||
Debug.LogWarning($"NetworkClient.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning.");
|
||||
}
|
||||
handlers[msgType] = MessagePacker.MessageHandler(handler, requireAuthentication);
|
||||
}
|
||||
@ -374,7 +370,7 @@ public static bool UnregisterHandler<T>() where T : IMessageBase
|
||||
/// </summary>
|
||||
public static void Shutdown()
|
||||
{
|
||||
logger.Log("Shutting down client.");
|
||||
Debug.Log("Shutting down client.");
|
||||
ClientScene.Shutdown();
|
||||
connectState = ConnectState.None;
|
||||
handlers.Clear();
|
||||
|
@ -17,7 +17,6 @@ namespace Mirror
|
||||
public abstract class NetworkConnection : IDisposable
|
||||
{
|
||||
public const int LocalConnectionId = 0;
|
||||
static readonly ILogger logger = LogFactory.GetLogger<NetworkConnection>();
|
||||
|
||||
// internal so it can be tested
|
||||
internal readonly HashSet<NetworkIdentity> visList = new HashSet<NetworkIdentity>();
|
||||
@ -94,7 +93,7 @@ public abstract class NetworkConnection : IDisposable
|
||||
/// </summary>
|
||||
internal NetworkConnection()
|
||||
{
|
||||
// set lastTime to current time when creating connection to make sure it isn't instantly kicked for inactivity
|
||||
// set lastTime to current time when creating connection to make sure it isn't instantly kicked for inactivity
|
||||
lastMessageTime = Time.time;
|
||||
}
|
||||
|
||||
@ -166,14 +165,14 @@ protected internal static bool ValidatePacketSize(ArraySegment<byte> segment, in
|
||||
{
|
||||
if (segment.Count > Transport.activeTransport.GetMaxPacketSize(channelId))
|
||||
{
|
||||
logger.LogError("NetworkConnection.ValidatePacketSize: cannot send packet larger than " + Transport.activeTransport.GetMaxPacketSize(channelId) + " bytes");
|
||||
Debug.LogError("NetworkConnection.ValidatePacketSize: cannot send packet larger than " + Transport.activeTransport.GetMaxPacketSize(channelId) + " bytes");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (segment.Count == 0)
|
||||
{
|
||||
// zero length packets getting into the packet queues are bad.
|
||||
logger.LogError("NetworkConnection.ValidatePacketSize: cannot send zero bytes");
|
||||
Debug.LogError("NetworkConnection.ValidatePacketSize: cannot send zero bytes");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -225,7 +224,7 @@ internal bool InvokeHandler(int msgType, NetworkReader reader, int channelId)
|
||||
msgDelegate(this, reader, channelId);
|
||||
return true;
|
||||
}
|
||||
if (logger.LogEnabled()) logger.Log("Unknown message ID " + msgType + " " + this + ". May be due to no existing RegisterHandler for this message.");
|
||||
// Debug.Log("Unknown message ID " + msgType + " " + this + ". May be due to no existing RegisterHandler for this message.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -271,7 +270,7 @@ internal void TransportReceive(ArraySegment<byte> buffer, int channelId)
|
||||
if (MessagePacker.UnpackMessage(networkReader, out int msgType))
|
||||
{
|
||||
// logging
|
||||
if (logger.LogEnabled()) logger.Log("ConnectionRecv " + this + " msgType:" + msgType + " content:" + BitConverter.ToString(buffer.Array, buffer.Offset, buffer.Count));
|
||||
// Debug.Log("ConnectionRecv " + this + " msgType:" + msgType + " content:" + BitConverter.ToString(buffer.Array, buffer.Offset, buffer.Count));
|
||||
|
||||
// try to invoke the handler for that message
|
||||
if (InvokeHandler(msgType, networkReader, channelId))
|
||||
@ -281,7 +280,7 @@ internal void TransportReceive(ArraySegment<byte> buffer, int channelId)
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("Closed connection: " + this + ". Invalid message header.");
|
||||
Debug.LogError("Closed connection: " + this + ". Invalid message header.");
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,6 @@ namespace Mirror
|
||||
{
|
||||
public class NetworkConnectionToClient : NetworkConnection
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger<NetworkConnectionToClient>();
|
||||
|
||||
public NetworkConnectionToClient(int networkConnectionId) : base(networkConnectionId) { }
|
||||
|
||||
public override string address => Transport.activeTransport.ServerGetClientAddress(connectionId);
|
||||
@ -23,7 +21,7 @@ public NetworkConnectionToClient(int networkConnectionId) : base(networkConnecti
|
||||
|
||||
internal override bool Send(ArraySegment<byte> segment, int channelId = Channels.DefaultReliable)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ConnectionSend " + this + " bytes:" + BitConverter.ToString(segment.Array, segment.Offset, segment.Count));
|
||||
Debug.Log("ConnectionSend " + this + " bytes:" + BitConverter.ToString(segment.Array, segment.Offset, segment.Count));
|
||||
|
||||
// validate packet size first.
|
||||
if (ValidatePacketSize(segment, channelId))
|
||||
|
@ -1,17 +1,14 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
public class NetworkConnectionToServer : NetworkConnection
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger<NetworkConnectionToServer>();
|
||||
|
||||
public override string address => "";
|
||||
|
||||
internal override bool Send(ArraySegment<byte> segment, int channelId = Channels.DefaultReliable)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ConnectionSend " + this + " bytes:" + BitConverter.ToString(segment.Array, segment.Offset, segment.Count));
|
||||
// logger.Log("ConnectionSend " + this + " bytes:" + BitConverter.ToString(segment.Array, segment.Offset, segment.Count));
|
||||
|
||||
// validate packet size first.
|
||||
if (ValidatePacketSize(segment, channelId))
|
||||
|
@ -106,8 +106,6 @@ namespace Mirror
|
||||
[HelpURL("https://mirror-networking.com/docs/Components/NetworkIdentity.html")]
|
||||
public sealed class NetworkIdentity : MonoBehaviour
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger<NetworkIdentity>();
|
||||
|
||||
NetworkBehaviour[] networkBehavioursCache;
|
||||
|
||||
/// <summary>
|
||||
@ -241,7 +239,7 @@ void CreateNetworkBehavioursCache()
|
||||
networkBehavioursCache = GetComponents<NetworkBehaviour>();
|
||||
if (NetworkBehaviours.Length > 64)
|
||||
{
|
||||
logger.LogError($"Only 64 NetworkBehaviour components are allowed for NetworkIdentity: {name} because of the dirtyComponentMask", this);
|
||||
Debug.LogError($"Only 64 NetworkBehaviour components are allowed for NetworkIdentity: {name} because of the dirtyComponentMask", this);
|
||||
// Log error once then resize array so that NetworkIdentity does not throw exceptions later
|
||||
Array.Resize(ref networkBehavioursCache, 64);
|
||||
}
|
||||
@ -313,21 +311,21 @@ internal set
|
||||
// new is empty
|
||||
if (string.IsNullOrEmpty(newAssetIdString))
|
||||
{
|
||||
logger.LogError($"Can not set AssetId to empty guid on NetworkIdentity '{name}', old assetId '{oldAssetIdSrting}'");
|
||||
Debug.LogError($"Can not set AssetId to empty guid on NetworkIdentity '{name}', old assetId '{oldAssetIdSrting}'");
|
||||
return;
|
||||
}
|
||||
|
||||
// old not empty
|
||||
if (!string.IsNullOrEmpty(oldAssetIdSrting))
|
||||
{
|
||||
logger.LogError($"Can not Set AssetId on NetworkIdentity '{name}' becasue it already had an assetId, current assetId '{oldAssetIdSrting}', attempted new assetId '{newAssetIdString}'");
|
||||
Debug.LogError($"Can not Set AssetId on NetworkIdentity '{name}' becasue it already had an assetId, current assetId '{oldAssetIdSrting}', attempted new assetId '{newAssetIdString}'");
|
||||
return;
|
||||
}
|
||||
|
||||
// old is empty
|
||||
m_AssetId = newAssetIdString;
|
||||
|
||||
if (logger.LogEnabled()) logger.Log($"Settings AssetId on NetworkIdentity '{name}', new assetId '{newAssetIdString}'");
|
||||
// Debug.Log($"Settings AssetId on NetworkIdentity '{name}', new assetId '{newAssetIdString}'");
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,7 +350,7 @@ internal void SetClientOwner(NetworkConnection conn)
|
||||
// do nothing if it already has an owner
|
||||
if (connectionToClient != null && conn != connectionToClient)
|
||||
{
|
||||
logger.LogError($"Object {this} netId={netId} already has an owner. Use RemoveClientAuthority() first", this);
|
||||
Debug.LogError($"Object {this} netId={netId} already has an owner. Use RemoveClientAuthority() first", this);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -402,7 +400,7 @@ void Awake()
|
||||
{
|
||||
if (hasSpawned)
|
||||
{
|
||||
logger.LogError($"{name} has already spawned. Don't call Instantiate for NetworkIdentities that were in the scene since the beginning (aka scene objects). Otherwise the client won't know which object to use for a SpawnSceneObject message.");
|
||||
Debug.LogError($"{name} has already spawned. Don't call Instantiate for NetworkIdentities that were in the scene since the beginning (aka scene objects). Otherwise the client won't know which object to use for a SpawnSceneObject message.");
|
||||
|
||||
SpawnedFromInstantiate = true;
|
||||
Destroy(gameObject);
|
||||
@ -440,7 +438,7 @@ bool ThisIsASceneObjectWithPrefabParent(out GameObject prefab)
|
||||
|
||||
if (prefab == null)
|
||||
{
|
||||
logger.LogError("Failed to find prefab parent for scene object [name:" + gameObject.name + "]");
|
||||
Debug.LogError("Failed to find prefab parent for scene object [name:" + gameObject.name + "]");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -543,7 +541,7 @@ void AssignSceneID()
|
||||
if (!duplicate)
|
||||
{
|
||||
sceneId = randomId;
|
||||
//logger.Log(name + " in scene=" + gameObject.scene.name + " sceneId assigned to: " + m_SceneId.ToString("X"));
|
||||
//Debug.Log(name + " in scene=" + gameObject.scene.name + " sceneId assigned to: " + m_SceneId.ToString("X"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,7 +575,7 @@ public void SetSceneIdSceneHashPartInternal()
|
||||
sceneId = (sceneId & 0xFFFFFFFF) | shiftedHash;
|
||||
|
||||
// log it. this is incredibly useful to debug sceneId issues.
|
||||
if (logger.LogEnabled()) logger.Log(name + " in scene=" + gameObject.scene.name + " scene index hash(" + pathHash.ToString("X") + ") copied into sceneId: " + sceneId.ToString("X"));
|
||||
// Debug.Log(name + " in scene=" + gameObject.scene.name + " scene index hash(" + pathHash.ToString("X") + ") copied into sceneId: " + sceneId.ToString("X"));
|
||||
}
|
||||
|
||||
void SetupIDs()
|
||||
@ -610,7 +608,7 @@ void SetupIDs()
|
||||
{
|
||||
// force 0 for prefabs
|
||||
sceneId = 0;
|
||||
//logger.Log(name + " @ scene: " + gameObject.scene.name + " sceneid reset to 0 because CurrentPrefabStage=" + PrefabStageUtility.GetCurrentPrefabStage() + " PrefabStage=" + PrefabStageUtility.GetPrefabStage(gameObject));
|
||||
//Debug.Log(name + " @ scene: " + gameObject.scene.name + " sceneid reset to 0 because CurrentPrefabStage=" + PrefabStageUtility.GetCurrentPrefabStage() + " PrefabStage=" + PrefabStageUtility.GetPrefabStage(gameObject));
|
||||
// NOTE: might make sense to use GetPrefabStage for asset
|
||||
// path, but let's not touch it while it works.
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
@ -686,7 +684,7 @@ internal void OnStartServer()
|
||||
netId = GetNextNetworkId();
|
||||
observers = new Dictionary<int, NetworkConnection>();
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("OnStartServer " + this + " NetId:" + netId + " SceneId:" + sceneId);
|
||||
// Debug.Log("OnStartServer " + this + " NetId:" + netId + " SceneId:" + sceneId);
|
||||
|
||||
// add to spawned (note: the original EnableIsServer isn't needed
|
||||
// because we already set m_isServer=true above)
|
||||
@ -712,7 +710,7 @@ internal void OnStartServer()
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnStartServer:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnStartServer:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -732,7 +730,7 @@ internal void OnStopServer()
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnStopServer:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnStopServer:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -746,7 +744,7 @@ internal void OnStartClient()
|
||||
|
||||
isClient = true;
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("OnStartClient " + gameObject + " netId:" + netId);
|
||||
// Debug.Log("OnStartClient " + gameObject + " netId:" + netId);
|
||||
foreach (NetworkBehaviour comp in NetworkBehaviours)
|
||||
{
|
||||
// an exception in OnStartClient should be caught, so that one
|
||||
@ -761,7 +759,7 @@ internal void OnStartClient()
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnStartClient:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnStartClient:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -786,7 +784,7 @@ internal void OnStartLocalPlayer()
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnStartLocalPlayer:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnStartLocalPlayer:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -816,7 +814,7 @@ internal void OnStartAuthority()
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnStartAuthority:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnStartAuthority:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -836,7 +834,7 @@ internal void OnStopAuthority()
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnStopAuthority:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnStopAuthority:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -851,7 +849,7 @@ internal void OnSetHostVisibility(bool visible)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnSetLocalVisibility:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnSetLocalVisibility:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -879,7 +877,7 @@ internal bool OnCheckObserver(NetworkConnection conn)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnCheckObserver:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnCheckObserver:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -900,7 +898,7 @@ internal void OnStopClient()
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Exception in OnNetworkDestroy:" + e.Message + " " + e.StackTrace);
|
||||
Debug.LogError("Exception in OnNetworkDestroy:" + e.Message + " " + e.StackTrace);
|
||||
}
|
||||
isServer = false;
|
||||
}
|
||||
@ -929,7 +927,7 @@ bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, bool initial
|
||||
catch (Exception e)
|
||||
{
|
||||
// show a detailed error and let the user know what went wrong
|
||||
logger.LogError("OnSerialize failed for: object=" + name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + "\n\n" + e);
|
||||
Debug.LogError("OnSerialize failed for: object=" + name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + "\n\n" + e);
|
||||
}
|
||||
int endPosition = writer.Position;
|
||||
|
||||
@ -938,7 +936,7 @@ bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, bool initial
|
||||
writer.WriteInt32(endPosition - contentPosition);
|
||||
writer.Position = endPosition;
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("OnSerializeSafely written for object=" + comp.name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + "header@" + headerPosition + " content@" + contentPosition + " end@" + endPosition + " contentSize=" + (endPosition - contentPosition));
|
||||
// Debug.Log("OnSerializeSafely written for object=" + comp.name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + "header@" + headerPosition + " content@" + contentPosition + " end@" + endPosition + " contentSize=" + (endPosition - contentPosition));
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -986,7 +984,7 @@ internal void OnSerializeAllSafely(bool initialState, ulong dirtyComponentsMask,
|
||||
// -> note: IsDirty() is false if the component isn't dirty or sendInterval isn't elapsed yet
|
||||
if (initialState || comp.IsDirty())
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("OnSerializeAllSafely: " + name + " -> " + comp.GetType() + " initial=" + initialState);
|
||||
// Debug.Log("OnSerializeAllSafely: " + name + " -> " + comp.GetType() + " initial=" + initialState);
|
||||
|
||||
// serialize into ownerWriter first
|
||||
// (owner always gets everything!)
|
||||
@ -1075,13 +1073,13 @@ void OnDeserializeSafely(NetworkBehaviour comp, NetworkReader reader, bool initi
|
||||
// way to mess up another component's deserialization
|
||||
try
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("OnDeserializeSafely: " + comp.name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + " length=" + contentSize);
|
||||
// Debug.Log("OnDeserializeSafely: " + comp.name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + " length=" + contentSize);
|
||||
comp.OnDeserialize(reader, initialState);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// show a detailed error and let the user know what went wrong
|
||||
logger.LogError($"OnDeserialize failed for: object={name} component={comp.GetType()} sceneId={sceneId:X} length={contentSize}. Possible Reasons:\n" +
|
||||
Debug.LogError($"OnDeserialize failed for: object={name} component={comp.GetType()} sceneId={sceneId:X} length={contentSize}. Possible Reasons:\n" +
|
||||
$" * Do {comp.GetType()}'s OnSerialize and OnDeserialize calls write the same amount of data({contentSize} bytes)? \n" +
|
||||
$" * Was there an exception in {comp.GetType()}'s OnSerialize/OnDeserialize code?\n" +
|
||||
$" * Are the server and client the exact same project?\n" +
|
||||
@ -1095,7 +1093,7 @@ void OnDeserializeSafely(NetworkBehaviour comp, NetworkReader reader, bool initi
|
||||
{
|
||||
// warn the user
|
||||
int bytesRead = reader.Position - chunkStart;
|
||||
logger.LogWarning("OnDeserialize was expected to read " + contentSize + " instead of " + bytesRead + " bytes for object:" + name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + ". Make sure that OnSerialize and OnDeserialize write/read the same amount of data in all cases.");
|
||||
Debug.LogWarning("OnDeserialize was expected to read " + contentSize + " instead of " + bytesRead + " bytes for object:" + name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + ". Make sure that OnSerialize and OnDeserialize write/read the same amount of data in all cases.");
|
||||
|
||||
// fix the position, so the following components don't all fail
|
||||
reader.Position = chunkEnd;
|
||||
@ -1133,14 +1131,14 @@ internal void HandleRemoteCall(int componentIndex, int functionHash, MirrorInvok
|
||||
// check if unity object has been destroyed
|
||||
if (this == null)
|
||||
{
|
||||
logger.LogWarning($"{invokeType} [{functionHash}] received for deleted object [netId={netId}]");
|
||||
Debug.LogWarning($"{invokeType} [{functionHash}] received for deleted object [netId={netId}]");
|
||||
return;
|
||||
}
|
||||
|
||||
// find the right component to invoke the function on
|
||||
if (componentIndex < 0 || componentIndex >= NetworkBehaviours.Length)
|
||||
{
|
||||
logger.LogWarning($"Component [{componentIndex}] not found for [netId={netId}]");
|
||||
Debug.LogWarning($"Component [{componentIndex}] not found for [netId={netId}]");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1149,7 +1147,7 @@ internal void HandleRemoteCall(int componentIndex, int functionHash, MirrorInvok
|
||||
|
||||
if (!RemoteCallHelper.InvokeHandlerDelegate(functionHash, invokeType, reader, invokeComponent, senderConnection))
|
||||
{
|
||||
logger.LogError($"Found no receiver for incoming {invokeType} [{functionHash}] on {gameObject.name}, the server and client should have the same NetworkBehaviour instances [netId={netId}].");
|
||||
Debug.LogError($"Found no receiver for incoming {invokeType} [{functionHash}] on {gameObject.name}, the server and client should have the same NetworkBehaviour instances [netId={netId}].");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1200,7 +1198,7 @@ internal void AddObserver(NetworkConnection conn)
|
||||
{
|
||||
if (observers == null)
|
||||
{
|
||||
logger.LogError("AddObserver for " + gameObject + " observer list is null");
|
||||
Debug.LogError("AddObserver for " + gameObject + " observer list is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1211,7 +1209,7 @@ internal void AddObserver(NetworkConnection conn)
|
||||
return;
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("Added observer " + conn.address + " added for " + gameObject);
|
||||
// Debug.Log("Added observer " + conn.address + " added for " + gameObject);
|
||||
|
||||
observers[conn.connectionId] = conn;
|
||||
conn.AddToVisList(this);
|
||||
@ -1312,7 +1310,7 @@ public void RebuildObservers(bool initialize)
|
||||
{
|
||||
// new observer
|
||||
conn.AddToVisList(this);
|
||||
if (logger.LogEnabled()) logger.Log("New Observer for " + gameObject + " " + conn);
|
||||
// Debug.Log("New Observer for " + gameObject + " " + conn);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@ -1325,7 +1323,7 @@ public void RebuildObservers(bool initialize)
|
||||
{
|
||||
// removed observer
|
||||
conn.RemoveFromVisList(this, false);
|
||||
if (logger.LogEnabled()) logger.Log("Removed Observer for " + gameObject + " " + conn);
|
||||
// Debug.Log("Removed Observer for " + gameObject + " " + conn);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@ -1381,19 +1379,19 @@ public bool AssignClientAuthority(NetworkConnection conn)
|
||||
{
|
||||
if (!isServer)
|
||||
{
|
||||
logger.LogError("AssignClientAuthority can only be called on the server for spawned objects.");
|
||||
Debug.LogError("AssignClientAuthority can only be called on the server for spawned objects.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (conn == null)
|
||||
{
|
||||
logger.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
|
||||
Debug.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (connectionToClient != null && conn != connectionToClient)
|
||||
{
|
||||
logger.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first.");
|
||||
Debug.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1417,13 +1415,13 @@ public void RemoveClientAuthority()
|
||||
{
|
||||
if (!isServer)
|
||||
{
|
||||
logger.LogError("RemoveClientAuthority can only be called on the server for spawned objects.");
|
||||
Debug.LogError("RemoveClientAuthority can only be called on the server for spawned objects.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (connectionToClient?.identity == this)
|
||||
{
|
||||
logger.LogError("RemoveClientAuthority cannot remove authority for a player object");
|
||||
Debug.LogError("RemoveClientAuthority cannot remove authority for a player object");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,6 @@ public enum NetworkManagerMode { Offline, ServerOnly, ClientOnly, Host }
|
||||
[HelpURL("https://mirror-networking.com/docs/Components/NetworkManager.html")]
|
||||
public class NetworkManager : MonoBehaviour
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger<NetworkManager>();
|
||||
|
||||
/// <summary>
|
||||
/// A flag to control whether the NetworkManager object is destroyed when the scene changes.
|
||||
/// <para>This should be set if your game has a single NetworkManager that exists for the lifetime of the process. If there is a NetworkManager in each scene, then this should not be set.</para>
|
||||
@ -46,7 +44,7 @@ public class NetworkManager : MonoBehaviour
|
||||
/// <summary>
|
||||
/// Automatically invoke StartServer()
|
||||
/// <para>If the application is a Server Build, StartServer is automatically invoked.</para>
|
||||
/// <para>Server build is true when "Server build" is checked in build menu, or BuildOptions.EnableHeadlessMode flag is in BuildOptions</para>
|
||||
/// <para>Server build is true when "Server build" is checked in build menu, or BuildOptions.EnableHeadlessMode flag is in BuildOptions</para>
|
||||
/// </summary>
|
||||
[Tooltip("Should the server auto-start when 'Server Build' is checked in build settings")]
|
||||
[FormerlySerializedAs("startOnHeadless")]
|
||||
@ -216,7 +214,7 @@ public virtual void OnValidate()
|
||||
if (transport == null)
|
||||
{
|
||||
transport = gameObject.AddComponent<TelepathyTransport>();
|
||||
logger.Log("NetworkManager: added default Transport because there was none yet.");
|
||||
Debug.Log("NetworkManager: added default Transport because there was none yet.");
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.Undo.RecordObject(gameObject, "Added default Transport");
|
||||
@ -228,7 +226,7 @@ public virtual void OnValidate()
|
||||
|
||||
if (playerPrefab != null && playerPrefab.GetComponent<NetworkIdentity>() == null)
|
||||
{
|
||||
logger.LogError("NetworkManager - playerPrefab must have a NetworkIdentity.");
|
||||
Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity.");
|
||||
playerPrefab = null;
|
||||
}
|
||||
}
|
||||
@ -241,7 +239,7 @@ public virtual void Awake()
|
||||
// Don't allow collision-destroyed second instance to continue.
|
||||
if (!InitializeSingleton()) return;
|
||||
|
||||
logger.Log("Thank you for using Mirror! https://mirror-networking.com");
|
||||
Debug.Log("Thank you for using Mirror! https://mirror-networking.com");
|
||||
|
||||
// Set the networkSceneName to prevent a scene reload
|
||||
// if client connection to server fails.
|
||||
@ -304,7 +302,7 @@ public static bool IsSceneActive(string scene)
|
||||
// full server setup code, without spawning objects yet
|
||||
void SetupServer()
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("NetworkManager SetupServer");
|
||||
// Debug.Log("NetworkManager SetupServer");
|
||||
InitializeSingleton();
|
||||
|
||||
if (runInBackground)
|
||||
@ -403,10 +401,10 @@ public void StartClient()
|
||||
|
||||
if (string.IsNullOrEmpty(networkAddress))
|
||||
{
|
||||
logger.LogError("Must set the Network Address field in the manager");
|
||||
Debug.LogError("Must set the Network Address field in the manager");
|
||||
return;
|
||||
}
|
||||
if (logger.LogEnabled()) logger.Log("NetworkManager StartClient address:" + networkAddress);
|
||||
// Debug.Log("NetworkManager StartClient address:" + networkAddress);
|
||||
|
||||
NetworkClient.Connect(networkAddress);
|
||||
|
||||
@ -439,7 +437,7 @@ public void StartClient(Uri uri)
|
||||
|
||||
RegisterClientMessages();
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("NetworkManager StartClient address:" + uri);
|
||||
// Debug.Log("NetworkManager StartClient address:" + uri);
|
||||
networkAddress = uri.Host;
|
||||
|
||||
NetworkClient.Connect(uri);
|
||||
@ -547,13 +545,13 @@ void FinishStartHost()
|
||||
// loaded and all objects were spawned.
|
||||
// DO NOT do this earlier. it would cause race conditions where a
|
||||
// client will do things before the server is even fully started.
|
||||
logger.Log("StartHostClient called");
|
||||
Debug.Log("StartHostClient called");
|
||||
StartHostClient();
|
||||
}
|
||||
|
||||
void StartHostClient()
|
||||
{
|
||||
logger.Log("NetworkManager ConnectLocalClient");
|
||||
Debug.Log("NetworkManager ConnectLocalClient");
|
||||
|
||||
if (authenticator != null)
|
||||
{
|
||||
@ -604,7 +602,7 @@ public void StopServer()
|
||||
|
||||
OnStopServer();
|
||||
|
||||
logger.Log("NetworkManager StopServer");
|
||||
Debug.Log("NetworkManager StopServer");
|
||||
isNetworkActive = false;
|
||||
NetworkServer.Shutdown();
|
||||
|
||||
@ -632,7 +630,7 @@ public void StopClient()
|
||||
|
||||
OnStopClient();
|
||||
|
||||
logger.Log("NetworkManager StopClient");
|
||||
Debug.Log("NetworkManager StopClient");
|
||||
isNetworkActive = false;
|
||||
|
||||
// shutdown client
|
||||
@ -686,7 +684,7 @@ public virtual void ConfigureServerFrameRate()
|
||||
// only set framerate for server build
|
||||
#if UNITY_SERVER
|
||||
Application.targetFrameRate = serverTickRate;
|
||||
if (logger.logEnabled) logger.Log("Server Tick Rate set to: " + Application.targetFrameRate + " Hz.");
|
||||
if (logger.logEnabled) Debug.Log("Server Tick Rate set to: " + Application.targetFrameRate + " Hz.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -694,30 +692,23 @@ bool InitializeSingleton()
|
||||
{
|
||||
if (singleton != null && singleton == this) return true;
|
||||
|
||||
// do this early
|
||||
LogFilter.Debug = showDebugMessages;
|
||||
if (LogFilter.Debug)
|
||||
{
|
||||
LogFactory.EnableDebugMode();
|
||||
}
|
||||
|
||||
if (dontDestroyOnLoad)
|
||||
{
|
||||
if (singleton != null)
|
||||
{
|
||||
logger.LogWarning("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will be destroyed.");
|
||||
Debug.LogWarning("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will be destroyed.");
|
||||
Destroy(gameObject);
|
||||
|
||||
// Return false to not allow collision-destroyed second instance to continue.
|
||||
return false;
|
||||
}
|
||||
logger.Log("NetworkManager created singleton (DontDestroyOnLoad)");
|
||||
Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)");
|
||||
singleton = this;
|
||||
if (Application.isPlaying) DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Log("NetworkManager created singleton (ForScene)");
|
||||
Debug.Log("NetworkManager created singleton (ForScene)");
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
@ -782,7 +773,7 @@ public static void Shutdown()
|
||||
/// </summary>
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
logger.Log("NetworkManager destroyed");
|
||||
Debug.Log("NetworkManager destroyed");
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -810,11 +801,11 @@ public virtual void ServerChangeScene(string newSceneName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(newSceneName))
|
||||
{
|
||||
logger.LogError("ServerChangeScene empty scene name");
|
||||
Debug.LogError("ServerChangeScene empty scene name");
|
||||
return;
|
||||
}
|
||||
|
||||
if (logger.logEnabled) logger.Log("ServerChangeScene " + newSceneName);
|
||||
// Debug.Log("ServerChangeScene " + newSceneName);
|
||||
NetworkServer.SetAllClientsNotReady();
|
||||
networkSceneName = newSceneName;
|
||||
|
||||
@ -848,16 +839,16 @@ internal void ClientChangeScene(string newSceneName, SceneOperation sceneOperati
|
||||
{
|
||||
if (string.IsNullOrEmpty(newSceneName))
|
||||
{
|
||||
logger.LogError("ClientChangeScene empty scene name");
|
||||
Debug.LogError("ClientChangeScene empty scene name");
|
||||
return;
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("ClientChangeScene newSceneName:" + newSceneName + " networkSceneName:" + networkSceneName);
|
||||
// Debug.Log("ClientChangeScene newSceneName:" + newSceneName + " networkSceneName:" + networkSceneName);
|
||||
|
||||
// vis2k: pause message handling while loading scene. otherwise we will process messages and then lose all
|
||||
// the state as soon as the load is finishing, causing all kinds of bugs because of missing state.
|
||||
// (client may be null after StopClient etc.)
|
||||
if (logger.LogEnabled()) logger.Log("ClientChangeScene: pausing handlers while scene is loading to avoid data loss after scene was loaded.");
|
||||
// Debug.Log("ClientChangeScene: pausing handlers while scene is loading to avoid data loss after scene was loaded.");
|
||||
Transport.activeTransport.enabled = false;
|
||||
|
||||
// Let client prepare for scene change
|
||||
@ -885,7 +876,7 @@ internal void ClientChangeScene(string newSceneName, SceneOperation sceneOperati
|
||||
loadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName, LoadSceneMode.Additive);
|
||||
else
|
||||
{
|
||||
logger.LogWarning($"Scene {newSceneName} is already loaded");
|
||||
Debug.LogWarning($"Scene {newSceneName} is already loaded");
|
||||
|
||||
// Re-enable the transport that we disabled before entering this switch
|
||||
Transport.activeTransport.enabled = true;
|
||||
@ -898,7 +889,7 @@ internal void ClientChangeScene(string newSceneName, SceneOperation sceneOperati
|
||||
loadingSceneAsync = SceneManager.UnloadSceneAsync(newSceneName, UnloadSceneOptions.UnloadAllEmbeddedSceneObjects);
|
||||
else
|
||||
{
|
||||
logger.LogWarning($"Cannot unload {newSceneName} with UnloadAdditive operation");
|
||||
Debug.LogWarning($"Cannot unload {newSceneName} with UnloadAdditive operation");
|
||||
|
||||
// Re-enable the transport that we disabled before entering this switch
|
||||
Transport.activeTransport.enabled = true;
|
||||
@ -928,12 +919,12 @@ void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
// TODO only respawn the server objects from that scene later!
|
||||
NetworkServer.SpawnObjects();
|
||||
if (logger.LogEnabled()) logger.Log("Respawned Server objects after additive scene load: " + scene.name);
|
||||
// Debug.Log("Respawned Server objects after additive scene load: " + scene.name);
|
||||
}
|
||||
if (NetworkClient.active)
|
||||
{
|
||||
ClientScene.PrepareToSpawnSceneObjects();
|
||||
if (logger.LogEnabled()) logger.Log("Rebuild Client spawnableObjects after additive scene load: " + scene.name);
|
||||
// Debug.Log("Rebuild Client spawnableObjects after additive scene load: " + scene.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -942,7 +933,7 @@ static void UpdateScene()
|
||||
{
|
||||
if (singleton != null && loadingSceneAsync != null && loadingSceneAsync.isDone)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ClientChangeScene done readyCon:" + clientReadyConnection);
|
||||
// Debug.Log("ClientChangeScene done readyCon:" + clientReadyConnection);
|
||||
singleton.FinishLoadScene();
|
||||
loadingSceneAsync.allowSceneActivation = true;
|
||||
loadingSceneAsync = null;
|
||||
@ -954,7 +945,7 @@ void FinishLoadScene()
|
||||
// NOTE: this cannot use NetworkClient.allClients[0] - that client may be for a completely different purpose.
|
||||
|
||||
// process queued messages that we received while loading the scene
|
||||
logger.Log("FinishLoadScene: resuming handlers after scene was loading.");
|
||||
Debug.Log("FinishLoadScene: resuming handlers after scene was loading.");
|
||||
Transport.activeTransport.enabled = true;
|
||||
|
||||
// host mode?
|
||||
@ -983,7 +974,7 @@ void FinishLoadSceneHost()
|
||||
{
|
||||
// debug message is very important. if we ever break anything then
|
||||
// it's very obvious to notice.
|
||||
logger.Log("Finished loading scene in host mode.");
|
||||
Debug.Log("Finished loading scene in host mode.");
|
||||
|
||||
if (clientReadyConnection != null)
|
||||
{
|
||||
@ -1034,7 +1025,7 @@ void FinishLoadSceneServerOnly()
|
||||
{
|
||||
// debug message is very important. if we ever break anything then
|
||||
// it's very obvious to notice.
|
||||
logger.Log("Finished loading scene in server-only mode.");
|
||||
Debug.Log("Finished loading scene in server-only mode.");
|
||||
|
||||
NetworkServer.SpawnObjects();
|
||||
OnServerSceneChanged(networkSceneName);
|
||||
@ -1046,7 +1037,7 @@ void FinishLoadSceneClientOnly()
|
||||
{
|
||||
// debug message is very important. if we ever break anything then
|
||||
// it's very obvious to notice.
|
||||
logger.Log("Finished loading scene in client-only mode.");
|
||||
Debug.Log("Finished loading scene in client-only mode.");
|
||||
|
||||
if (clientReadyConnection != null)
|
||||
{
|
||||
@ -1079,7 +1070,7 @@ void FinishLoadSceneClientOnly()
|
||||
/// <param name="start">Transform to register.</param>
|
||||
public static void RegisterStartPosition(Transform start)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("RegisterStartPosition: (" + start.gameObject.name + ") " + start.position);
|
||||
// Debug.Log("RegisterStartPosition: (" + start.gameObject.name + ") " + start.position);
|
||||
startPositions.Add(start);
|
||||
|
||||
// reorder the list so that round-robin spawning uses the start positions
|
||||
@ -1096,7 +1087,7 @@ public static void RegisterStartPosition(Transform start)
|
||||
/// <param name="start">Transform to unregister.</param>
|
||||
public static void UnRegisterStartPosition(Transform start)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("UnRegisterStartPosition: (" + start.gameObject.name + ") " + start.position);
|
||||
// Debug.Log("UnRegisterStartPosition: (" + start.gameObject.name + ") " + start.position);
|
||||
startPositions.Remove(start);
|
||||
}
|
||||
|
||||
@ -1131,7 +1122,7 @@ public Transform GetStartPosition()
|
||||
|
||||
void OnServerConnectInternal(NetworkConnection conn, ConnectMessage connectMsg)
|
||||
{
|
||||
logger.Log("NetworkManager.OnServerConnectInternal");
|
||||
Debug.Log("NetworkManager.OnServerConnectInternal");
|
||||
|
||||
if (authenticator != null)
|
||||
{
|
||||
@ -1148,7 +1139,7 @@ void OnServerConnectInternal(NetworkConnection conn, ConnectMessage connectMsg)
|
||||
// called after successful authentication
|
||||
void OnServerAuthenticated(NetworkConnection conn)
|
||||
{
|
||||
logger.Log("NetworkManager.OnServerAuthenticated");
|
||||
Debug.Log("NetworkManager.OnServerAuthenticated");
|
||||
|
||||
// set connection to authenticated
|
||||
conn.isAuthenticated = true;
|
||||
@ -1165,35 +1156,35 @@ void OnServerAuthenticated(NetworkConnection conn)
|
||||
|
||||
void OnServerDisconnectInternal(NetworkConnection conn, DisconnectMessage msg)
|
||||
{
|
||||
logger.Log("NetworkManager.OnServerDisconnectInternal");
|
||||
Debug.Log("NetworkManager.OnServerDisconnectInternal");
|
||||
OnServerDisconnect(conn);
|
||||
}
|
||||
|
||||
void OnServerReadyMessageInternal(NetworkConnection conn, ReadyMessage msg)
|
||||
{
|
||||
logger.Log("NetworkManager.OnServerReadyMessageInternal");
|
||||
Debug.Log("NetworkManager.OnServerReadyMessageInternal");
|
||||
OnServerReady(conn);
|
||||
}
|
||||
|
||||
void OnServerAddPlayerInternal(NetworkConnection conn, AddPlayerMessage msg)
|
||||
{
|
||||
logger.Log("NetworkManager.OnServerAddPlayer");
|
||||
Debug.Log("NetworkManager.OnServerAddPlayer");
|
||||
|
||||
if (autoCreatePlayer && playerPrefab == null)
|
||||
{
|
||||
logger.LogError("The PlayerPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object.");
|
||||
Debug.LogError("The PlayerPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (autoCreatePlayer && playerPrefab.GetComponent<NetworkIdentity>() == null)
|
||||
{
|
||||
logger.LogError("The PlayerPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab.");
|
||||
Debug.LogError("The PlayerPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (conn.identity != null)
|
||||
{
|
||||
logger.LogError("There is already a player for this connection.");
|
||||
Debug.LogError("There is already a player for this connection.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1209,7 +1200,7 @@ void OnServerRemovePlayerMessageInternal(NetworkConnection conn, RemovePlayerMes
|
||||
|
||||
void OnServerErrorInternal(NetworkConnection conn, ErrorMessage msg)
|
||||
{
|
||||
logger.Log("NetworkManager.OnServerErrorInternal");
|
||||
Debug.Log("NetworkManager.OnServerErrorInternal");
|
||||
OnServerError(conn, msg.value);
|
||||
}
|
||||
|
||||
@ -1219,7 +1210,7 @@ void OnServerErrorInternal(NetworkConnection conn, ErrorMessage msg)
|
||||
|
||||
void OnClientConnectInternal(NetworkConnection conn, ConnectMessage message)
|
||||
{
|
||||
logger.Log("NetworkManager.OnClientConnectInternal");
|
||||
Debug.Log("NetworkManager.OnClientConnectInternal");
|
||||
|
||||
if (authenticator != null)
|
||||
{
|
||||
@ -1236,7 +1227,7 @@ void OnClientConnectInternal(NetworkConnection conn, ConnectMessage message)
|
||||
// called after successful authentication
|
||||
void OnClientAuthenticated(NetworkConnection conn)
|
||||
{
|
||||
logger.Log("NetworkManager.OnClientAuthenticated");
|
||||
Debug.Log("NetworkManager.OnClientAuthenticated");
|
||||
|
||||
// set connection to authenticated
|
||||
conn.isAuthenticated = true;
|
||||
@ -1257,13 +1248,13 @@ void OnClientAuthenticated(NetworkConnection conn)
|
||||
|
||||
void OnClientDisconnectInternal(NetworkConnection conn, DisconnectMessage msg)
|
||||
{
|
||||
logger.Log("NetworkManager.OnClientDisconnectInternal");
|
||||
Debug.Log("NetworkManager.OnClientDisconnectInternal");
|
||||
OnClientDisconnect(conn);
|
||||
}
|
||||
|
||||
void OnClientNotReadyMessageInternal(NetworkConnection conn, NotReadyMessage msg)
|
||||
{
|
||||
logger.Log("NetworkManager.OnClientNotReadyMessageInternal");
|
||||
Debug.Log("NetworkManager.OnClientNotReadyMessageInternal");
|
||||
|
||||
ClientScene.ready = false;
|
||||
OnClientNotReady(conn);
|
||||
@ -1273,13 +1264,13 @@ void OnClientNotReadyMessageInternal(NetworkConnection conn, NotReadyMessage msg
|
||||
|
||||
void OnClientErrorInternal(NetworkConnection conn, ErrorMessage msg)
|
||||
{
|
||||
logger.Log("NetworkManager:OnClientErrorInternal");
|
||||
Debug.Log("NetworkManager:OnClientErrorInternal");
|
||||
OnClientError(conn, msg.value);
|
||||
}
|
||||
|
||||
void OnClientSceneInternal(NetworkConnection conn, SceneMessage msg)
|
||||
{
|
||||
logger.Log("NetworkManager.OnClientSceneInternal");
|
||||
Debug.Log("NetworkManager.OnClientSceneInternal");
|
||||
|
||||
if (NetworkClient.isConnected && !NetworkServer.active)
|
||||
{
|
||||
@ -1306,7 +1297,7 @@ public virtual void OnServerConnect(NetworkConnection conn) { }
|
||||
public virtual void OnServerDisconnect(NetworkConnection conn)
|
||||
{
|
||||
NetworkServer.DestroyPlayerForConnection(conn);
|
||||
logger.Log("OnServerDisconnect: Client disconnected.");
|
||||
Debug.Log("OnServerDisconnect: Client disconnected.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1319,7 +1310,7 @@ public virtual void OnServerReady(NetworkConnection conn)
|
||||
if (conn.identity == null)
|
||||
{
|
||||
// this is now allowed (was not for a while)
|
||||
logger.Log("Ready with no player object");
|
||||
Debug.Log("Ready with no player object");
|
||||
}
|
||||
NetworkServer.SetClientReady(conn);
|
||||
}
|
||||
|
@ -114,8 +114,6 @@ public override string ToString()
|
||||
// but they do all need to be extensions.
|
||||
public static class NetworkReaderExtensions
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkReaderExtensions));
|
||||
|
||||
// cache encoding instead of creating it each time
|
||||
// 1000 readers before: 1MB GC, 30ms
|
||||
// 1000 readers after: 0.8MB GC, 18ms
|
||||
@ -365,7 +363,7 @@ public static NetworkIdentity ReadNetworkIdentity(this NetworkReader reader)
|
||||
return identity;
|
||||
}
|
||||
|
||||
if (logger.WarnEnabled()) logger.LogFormat(LogType.Warning, "ReadNetworkIdentity netId:{0} not found in spawned", netId);
|
||||
// logger.LogFormat(LogType.Warning, "ReadNetworkIdentity netId:{0} not found in spawned", netId);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@ public void Dispose()
|
||||
/// </summary>
|
||||
public static class NetworkReaderPool
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkReaderPool), LogType.Error);
|
||||
|
||||
/// <summary>
|
||||
/// Size of the pool
|
||||
/// <para>If pool is too small getting readers will causes memory allocation</para>
|
||||
@ -115,7 +113,7 @@ public static void Recycle(PooledNetworkReader reader)
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("NetworkReaderPool.Recycle, Pool was full leaving extra reader for GC");
|
||||
Debug.LogWarning("NetworkReaderPool.Recycle, Pool was full leaving extra reader for GC");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,6 @@ namespace Mirror
|
||||
/// </remarks>
|
||||
public static class NetworkServer
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkServer));
|
||||
|
||||
static bool initialized;
|
||||
static int maxConnections;
|
||||
|
||||
@ -73,7 +71,7 @@ public static class NetworkServer
|
||||
public static float disconnectInactiveTimeout = 60f;
|
||||
|
||||
/// <summary>
|
||||
/// cache the Send(connectionIds) list to avoid allocating each time
|
||||
/// cache the Send(connectionIds) list to avoid allocating each time
|
||||
/// </summary>
|
||||
static readonly List<int> connectionIdsCache = new List<int>();
|
||||
|
||||
@ -147,12 +145,11 @@ static void Initialize()
|
||||
return;
|
||||
|
||||
initialized = true;
|
||||
if (logger.LogEnabled()) logger.Log("NetworkServer Created version " + Version.Current);
|
||||
// Debug.Log("NetworkServer Created version " + Version.Current);
|
||||
|
||||
//Make sure connections are cleared in case any old connections references exist from previous sessions
|
||||
connections.Clear();
|
||||
|
||||
logger.Assert(Transport.activeTransport != null, "There was no active transport when calling NetworkServer.Listen, If you are calling Listen manually then make sure to set 'Transport.activeTransport' first");
|
||||
Transport.activeTransport.OnServerDisconnected.AddListener(OnDisconnected);
|
||||
Transport.activeTransport.OnServerConnected.AddListener(OnConnected);
|
||||
Transport.activeTransport.OnServerDataReceived.AddListener(OnDataReceived);
|
||||
@ -179,7 +176,7 @@ public static void Listen(int maxConns)
|
||||
if (!dontListen)
|
||||
{
|
||||
Transport.activeTransport.ServerStart();
|
||||
logger.Log("Server started listening");
|
||||
Debug.Log("Server started listening");
|
||||
}
|
||||
|
||||
active = true;
|
||||
@ -217,14 +214,14 @@ public static bool RemoveConnection(int connectionId)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called by LocalClient to add itself. dont call directly.
|
||||
/// called by LocalClient to add itself. dont call directly.
|
||||
/// </summary>
|
||||
/// <param name="conn"></param>
|
||||
internal static void SetLocalConnection(ULocalConnectionToClient conn)
|
||||
{
|
||||
if (localConnection != null)
|
||||
{
|
||||
logger.LogError("Local Connection already exists");
|
||||
Debug.LogError("Local Connection already exists");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -248,7 +245,7 @@ public static void ActivateHostScene()
|
||||
{
|
||||
if (!identity.isClient)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("ActivateHostScene " + identity.netId + " " + identity);
|
||||
// Debug.Log("ActivateHostScene " + identity.netId + " " + identity);
|
||||
|
||||
identity.OnStartClient();
|
||||
}
|
||||
@ -266,7 +263,7 @@ public static void ActivateHostScene()
|
||||
/// <param name="channelId"></param>
|
||||
static void SendToObservers<T>(NetworkIdentity identity, T msg, int channelId = Channels.DefaultReliable) where T : IMessageBase
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Server.SendToObservers id:" + typeof(T));
|
||||
// Debug.Log("Server.SendToObservers id:" + typeof(T));
|
||||
|
||||
if (identity == null || identity.observers == null || identity.observers.Count == 0)
|
||||
return;
|
||||
@ -314,11 +311,11 @@ public static bool SendToAll<T>(T msg, int channelId = Channels.DefaultReliable,
|
||||
{
|
||||
if (!active)
|
||||
{
|
||||
logger.LogWarning("Can not send using NetworkServer.SendToAll<T>(T msg) because NetworkServer is not active");
|
||||
Debug.LogWarning("Can not send using NetworkServer.SendToAll<T>(T msg) because NetworkServer is not active");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("Server.SendToAll id:" + typeof(T));
|
||||
// Debug.Log("Server.SendToAll id:" + typeof(T));
|
||||
|
||||
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
|
||||
{
|
||||
@ -371,7 +368,7 @@ public static bool SendToReady<T>(T msg, int channelId = Channels.DefaultReliabl
|
||||
{
|
||||
if (!active)
|
||||
{
|
||||
logger.LogWarning("Can not send using NetworkServer.SendToReady<T>(T msg) because NetworkServer is not active");
|
||||
Debug.LogWarning("Can not send using NetworkServer.SendToReady<T>(T msg) because NetworkServer is not active");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -390,7 +387,7 @@ public static bool SendToReady<T>(T msg, int channelId = Channels.DefaultReliabl
|
||||
/// <returns></returns>
|
||||
public static bool SendToReady<T>(NetworkIdentity identity, T msg, bool includeOwner = true, int channelId = Channels.DefaultReliable) where T : IMessageBase
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Server.SendToReady msgType:" + typeof(T));
|
||||
// Debug.Log("Server.SendToReady msgType:" + typeof(T));
|
||||
|
||||
if (identity == null || identity.observers == null || identity.observers.Count == 0)
|
||||
return false;
|
||||
@ -505,7 +502,7 @@ public static void Update()
|
||||
{
|
||||
if (!conn.IsClientAlive())
|
||||
{
|
||||
logger.LogWarning($"Disconnecting {conn} for inactivity!");
|
||||
Debug.LogWarning($"Disconnecting {conn} for inactivity!");
|
||||
conn.Disconnect();
|
||||
}
|
||||
}
|
||||
@ -523,19 +520,19 @@ public static void Update()
|
||||
{
|
||||
// spawned list should have no null entries because we
|
||||
// always call Remove in OnObjectDestroy everywhere.
|
||||
logger.LogWarning("Found 'null' entry in spawned list for netId=" + kvp.Key + ". Please call NetworkServer.Destroy to destroy networked objects. Don't use GameObject.Destroy.");
|
||||
Debug.LogWarning("Found 'null' entry in spawned list for netId=" + kvp.Key + ". Please call NetworkServer.Destroy to destroy networked objects. Don't use GameObject.Destroy.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OnConnected(int connectionId)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Server accepted client:" + connectionId);
|
||||
// Debug.Log("Server accepted client:" + connectionId);
|
||||
|
||||
// connectionId needs to be > 0 because 0 is reserved for local player
|
||||
if (connectionId <= 0)
|
||||
{
|
||||
logger.LogError("Server.HandleConnect: invalid connectionId: " + connectionId + " . Needs to be >0, because 0 is reserved for local player.");
|
||||
Debug.LogError("Server.HandleConnect: invalid connectionId: " + connectionId + " . Needs to be >0, because 0 is reserved for local player.");
|
||||
Transport.activeTransport.ServerDisconnect(connectionId);
|
||||
return;
|
||||
}
|
||||
@ -544,7 +541,7 @@ static void OnConnected(int connectionId)
|
||||
if (connections.ContainsKey(connectionId))
|
||||
{
|
||||
Transport.activeTransport.ServerDisconnect(connectionId);
|
||||
if (logger.LogEnabled()) logger.Log("Server connectionId " + connectionId + " already in use. kicked client:" + connectionId);
|
||||
// Debug.Log("Server connectionId " + connectionId + " already in use. kicked client:" + connectionId);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -563,13 +560,13 @@ static void OnConnected(int connectionId)
|
||||
{
|
||||
// kick
|
||||
Transport.activeTransport.ServerDisconnect(connectionId);
|
||||
if (logger.LogEnabled()) logger.Log("Server full, kicked client:" + connectionId);
|
||||
// Debug.Log("Server full, kicked client:" + connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void OnConnected(NetworkConnectionToClient conn)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Server accepted client:" + conn);
|
||||
// Debug.Log("Server accepted client:" + conn);
|
||||
|
||||
// add connection and invoke connected event
|
||||
AddConnection(conn);
|
||||
@ -578,13 +575,13 @@ internal static void OnConnected(NetworkConnectionToClient conn)
|
||||
|
||||
internal static void OnDisconnected(int connectionId)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Server disconnect client:" + connectionId);
|
||||
// Debug.Log("Server disconnect client:" + connectionId);
|
||||
|
||||
if (connections.TryGetValue(connectionId, out NetworkConnectionToClient conn))
|
||||
{
|
||||
conn.Disconnect();
|
||||
RemoveConnection(connectionId);
|
||||
if (logger.LogEnabled()) logger.Log("Server lost client:" + connectionId);
|
||||
// Debug.Log("Server lost client:" + connectionId);
|
||||
|
||||
OnDisconnected(conn);
|
||||
}
|
||||
@ -593,7 +590,7 @@ internal static void OnDisconnected(int connectionId)
|
||||
static void OnDisconnected(NetworkConnection conn)
|
||||
{
|
||||
conn.InvokeHandler(new DisconnectMessage(), -1);
|
||||
if (logger.LogEnabled()) logger.Log("Server lost client:" + conn);
|
||||
// Debug.Log("Server lost client:" + conn);
|
||||
}
|
||||
|
||||
static void OnDataReceived(int connectionId, ArraySegment<byte> data, int channelId)
|
||||
@ -604,14 +601,14 @@ static void OnDataReceived(int connectionId, ArraySegment<byte> data, int channe
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("HandleData Unknown connectionId:" + connectionId);
|
||||
Debug.LogError("HandleData Unknown connectionId:" + connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnError(int connectionId, Exception exception)
|
||||
{
|
||||
// TODO Let's discuss how we will handle errors
|
||||
logger.LogException(exception);
|
||||
Debug.LogException(exception);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -626,7 +623,7 @@ static void OnError(int connectionId, Exception exception)
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
if (handlers.ContainsKey(msgType))
|
||||
{
|
||||
logger.LogWarning($"NetworkServer.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning.");
|
||||
Debug.LogWarning($"NetworkServer.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning.");
|
||||
}
|
||||
handlers[msgType] = MessagePacker.MessageHandler(handler, requireAuthentication);
|
||||
}
|
||||
@ -700,7 +697,7 @@ public static void SendToClientOfPlayer<T>(NetworkIdentity identity, T msg, int
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("SendToClientOfPlayer: player has no NetworkIdentity: " + identity);
|
||||
Debug.LogError("SendToClientOfPlayer: player has no NetworkIdentity: " + identity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -754,7 +751,7 @@ public static bool AddPlayerForConnection(NetworkConnection conn, GameObject pla
|
||||
|
||||
static void SpawnObserversForConnection(NetworkConnection conn)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Spawning " + NetworkIdentity.spawned.Count + " objects for conn " + conn);
|
||||
// Debug.Log("Spawning " + NetworkIdentity.spawned.Count + " objects for conn " + conn);
|
||||
|
||||
if (!conn.isReady)
|
||||
{
|
||||
@ -773,7 +770,7 @@ static void SpawnObserversForConnection(NetworkConnection conn)
|
||||
// try with far away ones in ummorpg!
|
||||
if (identity.gameObject.activeSelf) //TODO this is different
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Sending spawn message for current server objects name='" + identity.name + "' netId=" + identity.netId + " sceneId=" + identity.sceneId);
|
||||
// Debug.Log("Sending spawn message for current server objects name='" + identity.name + "' netId=" + identity.netId + " sceneId=" + identity.sceneId);
|
||||
|
||||
bool visible = identity.OnCheckObserver(conn);
|
||||
if (visible)
|
||||
@ -801,14 +798,14 @@ public static bool AddPlayerForConnection(NetworkConnection conn, GameObject pla
|
||||
NetworkIdentity identity = player.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogWarning("AddPlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + player);
|
||||
Debug.LogWarning("AddPlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + player);
|
||||
return false;
|
||||
}
|
||||
|
||||
// cannot have a player object in "Add" version
|
||||
if (conn.identity != null)
|
||||
{
|
||||
logger.Log("AddPlayer: player object already exists");
|
||||
Debug.Log("AddPlayer: player object already exists");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -829,7 +826,7 @@ public static bool AddPlayerForConnection(NetworkConnection conn, GameObject pla
|
||||
// set ready if not set yet
|
||||
SetClientReady(conn);
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("Adding new playerGameObject object netId: " + identity.netId + " asset ID " + identity.assetId);
|
||||
// Debug.Log("Adding new playerGameObject object netId: " + identity.netId + " asset ID " + identity.assetId);
|
||||
|
||||
Respawn(identity);
|
||||
return true;
|
||||
@ -854,18 +851,18 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn,
|
||||
NetworkIdentity identity = player.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError("ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + player);
|
||||
Debug.LogError("ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + player);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (identity.connectionToClient != null && identity.connectionToClient != conn)
|
||||
{
|
||||
logger.LogError("Cannot replace player for connection. New player is already owned by a different connection" + player);
|
||||
Debug.LogError("Cannot replace player for connection. New player is already owned by a different connection" + player);
|
||||
return false;
|
||||
}
|
||||
|
||||
//NOTE: there can be an existing player
|
||||
logger.Log("NetworkServer ReplacePlayer");
|
||||
Debug.Log("NetworkServer ReplacePlayer");
|
||||
|
||||
NetworkIdentity previousPlayer = conn.identity;
|
||||
|
||||
@ -888,7 +885,7 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn,
|
||||
// IMPORTANT: do this in AddPlayerForConnection & ReplacePlayerForConnection!
|
||||
SpawnObserversForConnection(conn);
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("Replacing playerGameObject object netId: " + player.GetComponent<NetworkIdentity>().netId + " asset ID " + player.GetComponent<NetworkIdentity>().assetId);
|
||||
// Debug.Log("Replacing playerGameObject object netId: " + player.GetComponent<NetworkIdentity>().netId + " asset ID " + player.GetComponent<NetworkIdentity>().assetId);
|
||||
|
||||
Respawn(identity);
|
||||
|
||||
@ -903,7 +900,7 @@ internal static bool GetNetworkIdentity(GameObject go, out NetworkIdentity ident
|
||||
identity = go.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError($"GameObject {go.name} doesn't have NetworkIdentity.");
|
||||
Debug.LogError($"GameObject {go.name} doesn't have NetworkIdentity.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -916,7 +913,7 @@ internal static bool GetNetworkIdentity(GameObject go, out NetworkIdentity ident
|
||||
/// <param name="conn">The connection of the client to make ready.</param>
|
||||
public static void SetClientReady(NetworkConnection conn)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("SetClientReadyInternal for conn:" + conn);
|
||||
// Debug.Log("SetClientReadyInternal for conn:" + conn);
|
||||
|
||||
// set ready
|
||||
conn.isReady = true;
|
||||
@ -962,7 +959,7 @@ public static void SetClientNotReady(NetworkConnection conn)
|
||||
{
|
||||
if (conn.isReady)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("PlayerNotReady " + conn);
|
||||
// Debug.Log("PlayerNotReady " + conn);
|
||||
conn.isReady = false;
|
||||
conn.RemoveObservers();
|
||||
|
||||
@ -971,13 +968,13 @@ public static void SetClientNotReady(NetworkConnection conn)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// default ready handler.
|
||||
/// default ready handler.
|
||||
/// </summary>
|
||||
/// <param name="conn"></param>
|
||||
/// <param name="msg"></param>
|
||||
static void OnClientReadyMessage(NetworkConnection conn, ReadyMessage msg)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("Default handler for ready message from " + conn);
|
||||
// Debug.Log("Default handler for ready message from " + conn);
|
||||
SetClientReady(conn);
|
||||
}
|
||||
|
||||
@ -1006,7 +1003,7 @@ public static void RemovePlayerForConnection(NetworkConnection conn, bool destro
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log($"Connection {conn} has no identity");
|
||||
// Debug.Log($"Connection {conn} has no identity");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1019,7 +1016,7 @@ static void OnCommandMessage(NetworkConnection conn, CommandMessage msg)
|
||||
{
|
||||
if (!NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity identity))
|
||||
{
|
||||
logger.LogWarning("Spawned object not found when handling Command message [netId=" + msg.netId + "]");
|
||||
Debug.LogWarning("Spawned object not found when handling Command message [netId=" + msg.netId + "]");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1031,11 +1028,11 @@ static void OnCommandMessage(NetworkConnection conn, CommandMessage msg)
|
||||
bool needAuthority = !commandInfo.ignoreAuthority;
|
||||
if (needAuthority && identity.connectionToClient != conn)
|
||||
{
|
||||
logger.LogWarning("Command for object without authority [netId=" + msg.netId + "]");
|
||||
Debug.LogWarning("Command for object without authority [netId=" + msg.netId + "]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("OnCommandMessage for netId=" + msg.netId + " conn=" + conn);
|
||||
// Debug.Log("OnCommandMessage for netId=" + msg.netId + " conn=" + conn);
|
||||
|
||||
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(msg.payload))
|
||||
identity.HandleRemoteCall(msg.componentIndex, msg.functionHash, MirrorInvokeType.Command, networkReader, conn as NetworkConnectionToClient);
|
||||
@ -1045,14 +1042,14 @@ internal static void SpawnObject(GameObject obj, NetworkConnection ownerConnecti
|
||||
{
|
||||
if (!active)
|
||||
{
|
||||
logger.LogError("SpawnObject for " + obj + ", NetworkServer is not active. Cannot spawn objects without an active server.");
|
||||
Debug.LogError("SpawnObject for " + obj + ", NetworkServer is not active. Cannot spawn objects without an active server.");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = obj.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError("SpawnObject " + obj + " has no NetworkIdentity. Please add a NetworkIdentity to " + obj);
|
||||
Debug.LogError("SpawnObject " + obj + " has no NetworkIdentity. Please add a NetworkIdentity to " + obj);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1072,7 +1069,7 @@ internal static void SpawnObject(GameObject obj, NetworkConnection ownerConnecti
|
||||
|
||||
identity.OnStartServer();
|
||||
|
||||
if (logger.LogEnabled()) logger.Log("SpawnObject instance ID " + identity.netId + " asset ID " + identity.assetId);
|
||||
// Debug.Log("SpawnObject instance ID " + identity.netId + " asset ID " + identity.assetId);
|
||||
|
||||
identity.RebuildObservers(true);
|
||||
}
|
||||
@ -1083,7 +1080,7 @@ internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnectio
|
||||
return;
|
||||
|
||||
// for easier debugging
|
||||
if (logger.LogEnabled()) logger.Log("Server SendSpawnMessage: name=" + identity.name + " sceneId=" + identity.sceneId.ToString("X") + " netid=" + identity.netId);
|
||||
// Debug.Log("Server SendSpawnMessage: name=" + identity.name + " sceneId=" + identity.sceneId.ToString("X") + " netid=" + identity.netId);
|
||||
|
||||
// one writer for owner, one for observers
|
||||
using (PooledNetworkWriter ownerWriter = NetworkWriterPool.GetWriter(), observersWriter = NetworkWriterPool.GetWriter())
|
||||
@ -1173,13 +1170,13 @@ public static void Spawn(GameObject obj, GameObject ownerPlayer)
|
||||
NetworkIdentity identity = ownerPlayer.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
{
|
||||
logger.LogError("Player object has no NetworkIdentity");
|
||||
Debug.LogError("Player object has no NetworkIdentity");
|
||||
return;
|
||||
}
|
||||
|
||||
if (identity.connectionToClient == null)
|
||||
{
|
||||
logger.LogError("Player object is not a player.");
|
||||
Debug.LogError("Player object is not a player.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1224,7 +1221,7 @@ static bool VerifyCanSpawn(GameObject obj)
|
||||
{
|
||||
if (CheckForPrefab(obj))
|
||||
{
|
||||
logger.LogFormat(LogType.Error, "GameObject {0} is a prefab, it can't be spawned. This will cause errors in builds.", obj.name);
|
||||
Debug.LogError($"GameObject {obj.name} is a prefab, it can't be spawned. This will cause errors in builds.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1233,7 +1230,7 @@ static bool VerifyCanSpawn(GameObject obj)
|
||||
|
||||
static void DestroyObject(NetworkIdentity identity, bool destroyServerObject)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("DestroyObject instance:" + identity.netId);
|
||||
// Debug.Log("DestroyObject instance:" + identity.netId);
|
||||
NetworkIdentity.spawned.Remove(identity.netId);
|
||||
|
||||
identity.connectionToClient?.RemoveOwnedObject(identity);
|
||||
@ -1275,7 +1272,7 @@ public static void Destroy(GameObject obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
logger.Log("NetworkServer DestroyObject is null");
|
||||
Debug.Log("NetworkServer DestroyObject is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1295,7 +1292,7 @@ public static void UnSpawn(GameObject obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
logger.Log("NetworkServer UnspawnObject is null");
|
||||
Debug.Log("NetworkServer UnspawnObject is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1336,7 +1333,7 @@ public static bool SpawnObjects()
|
||||
{
|
||||
if (ValidateSceneObject(identity))
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("SpawnObjects sceneId:" + identity.sceneId.ToString("X") + " name:" + identity.gameObject.name);
|
||||
// Debug.Log("SpawnObjects sceneId:" + identity.sceneId.ToString("X") + " name:" + identity.gameObject.name);
|
||||
identity.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ namespace Mirror
|
||||
/// </summary>
|
||||
public static class NetworkTime
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkTime));
|
||||
|
||||
/// <summary>
|
||||
/// how often are we sending ping messages
|
||||
/// used to calculate network time and RTT
|
||||
@ -68,7 +66,7 @@ internal static void UpdateClient()
|
||||
// and time from the server
|
||||
internal static void OnServerPing(NetworkConnection conn, NetworkPingMessage msg)
|
||||
{
|
||||
if (logger.LogEnabled()) logger.Log("OnPingServerMessage conn=" + conn);
|
||||
// Debug.Log("OnPingServerMessage conn=" + conn);
|
||||
|
||||
NetworkPongMessage pongMsg = new NetworkPongMessage
|
||||
{
|
||||
|
@ -161,8 +161,6 @@ public void WriteUInt64(ulong value)
|
||||
// but they do all need to be extensions.
|
||||
public static class NetworkWriterExtensions
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkWriterExtensions));
|
||||
|
||||
// cache encoding instead of creating it with BinaryWriter each time
|
||||
// 1000 readers before: 1MB GC, 30ms
|
||||
// 1000 readers after: 0.8MB GC, 18ms
|
||||
@ -507,7 +505,7 @@ public static void WriteTransform(this NetworkWriter writer, Transform value)
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("NetworkWriter " + value + " has no NetworkIdentity");
|
||||
Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity");
|
||||
writer.WritePackedUInt32(0);
|
||||
}
|
||||
}
|
||||
@ -526,7 +524,7 @@ public static void WriteGameObject(this NetworkWriter writer, GameObject value)
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("NetworkWriter " + value + " has no NetworkIdentity");
|
||||
Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity");
|
||||
writer.WritePackedUInt32(0);
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ public void Dispose()
|
||||
/// </summary>
|
||||
public static class NetworkWriterPool
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkWriterPool), LogType.Error);
|
||||
|
||||
/// <summary>
|
||||
/// Size of the pool
|
||||
/// <para>If pool is too small getting writers will causes memory allocation</para>
|
||||
@ -91,7 +89,7 @@ public static void Recycle(PooledNetworkWriter writer)
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("NetworkWriterPool.Recycle, Pool was full leaving extra writer for GC");
|
||||
Debug.LogWarning("NetworkWriterPool.Recycle, Pool was full leaving extra writer for GC");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,6 @@ public struct CommandInfo
|
||||
/// </summary>
|
||||
public static class RemoteCallHelper
|
||||
{
|
||||
static readonly ILogger logger = LogFactory.GetLogger(typeof(RemoteCallHelper));
|
||||
|
||||
static readonly Dictionary<int, Invoker> cmdHandlerDelegates = new Dictionary<int, Invoker>();
|
||||
|
||||
/// <summary>
|
||||
@ -85,11 +83,8 @@ internal static int RegisterDelegate(Type invokeClass, string cmdName, MirrorInv
|
||||
|
||||
cmdHandlerDelegates[cmdHash] = invoker;
|
||||
|
||||
if (logger.LogEnabled())
|
||||
{
|
||||
string ingoreAuthorityMessage = invokerType == MirrorInvokeType.Command ? $" IgnoreAuthority:{cmdIgnoreAuthority}" : "";
|
||||
logger.Log($"RegisterDelegate hash: {cmdHash} invokerType: {invokerType} method: {func.GetMethodName()}{ingoreAuthorityMessage}");
|
||||
}
|
||||
// string ingoreAuthorityMessage = invokerType == MirrorInvokeType.Command ? $" IgnoreAuthority:{cmdIgnoreAuthority}" : "";
|
||||
// Debug.Log($"RegisterDelegate hash: {cmdHash} invokerType: {invokerType} method: {func.GetMethodName()}{ingoreAuthorityMessage}");
|
||||
|
||||
return cmdHash;
|
||||
}
|
||||
@ -106,7 +101,7 @@ static bool CheckIfDeligateExists(Type invokeClass, MirrorInvokeType invokerType
|
||||
return true;
|
||||
}
|
||||
|
||||
logger.LogError($"Function {oldInvoker.invokeClass}.{oldInvoker.invokeFunction.GetMethodName()} and {invokeClass}.{func.GetMethodName()} have the same hash. Please rename one of them");
|
||||
Debug.LogError($"Function {oldInvoker.invokeClass}.{oldInvoker.invokeFunction.GetMethodName()} and {invokeClass}.{func.GetMethodName()} have the same hash. Please rename one of them");
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -147,7 +142,7 @@ static bool GetInvokerForHash(int cmdHash, MirrorInvokeType invokeType, out Invo
|
||||
// debug message if not found, or null, or mismatched type
|
||||
// (no need to throw an error, an attacker might just be trying to
|
||||
// call an cmd with an rpc's hash)
|
||||
if (logger.LogEnabled()) logger.Log("GetInvokerForHash hash:" + cmdHash + " not found");
|
||||
// Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Tests
|
||||
{
|
||||
public class LogFactoryTests
|
||||
{
|
||||
// A Test behaves as an ordinary method
|
||||
[Test]
|
||||
public void SameClassSameLogger()
|
||||
{
|
||||
ILogger logger1 = LogFactory.GetLogger<LogFactoryTests>();
|
||||
ILogger logger2 = LogFactory.GetLogger<LogFactoryTests>();
|
||||
Assert.That(logger1, Is.SameAs(logger2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DifferentClassDifferentLogger()
|
||||
{
|
||||
ILogger logger1 = LogFactory.GetLogger<LogFactoryTests>();
|
||||
ILogger logger2 = LogFactory.GetLogger<NetworkManager>();
|
||||
Assert.That(logger1, Is.Not.SameAs(logger2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LogDebugIgnore()
|
||||
{
|
||||
ILogger logger = LogFactory.GetLogger<LogFactoryTests>();
|
||||
logger.filterLogType = LogType.Warning;
|
||||
|
||||
ILogHandler mockHandler = Substitute.For<ILogHandler>();
|
||||
logger.logHandler = mockHandler;
|
||||
logger.Log("This message should not be logged");
|
||||
mockHandler.DidNotReceiveWithAnyArgs().LogFormat(LogType.Log, null, null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LogDebugFull()
|
||||
{
|
||||
ILogger logger = LogFactory.GetLogger<LogFactoryTests>();
|
||||
logger.filterLogType = LogType.Log;
|
||||
|
||||
ILogHandler mockHandler = Substitute.For<ILogHandler>();
|
||||
logger.logHandler = mockHandler;
|
||||
logger.Log("This message be logged");
|
||||
mockHandler.Received().LogFormat(LogType.Log, null, "{0}", "This message be logged");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b978d8a846ffa48109a9e4c5e9e2c0c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -42,13 +42,11 @@ protected void HasWarning(string messsage, string atType)
|
||||
[Category("Weaver")]
|
||||
public abstract class WeaverTests
|
||||
{
|
||||
public static readonly ILogger logger = LogFactory.GetLogger<WeaverTests>(LogType.Exception);
|
||||
|
||||
protected List<string> weaverErrors = new List<string>();
|
||||
void HandleWeaverError(string msg)
|
||||
{
|
||||
LogAssert.ignoreFailingMessages = true;
|
||||
logger.LogError(msg);
|
||||
Debug.LogError(msg);
|
||||
LogAssert.ignoreFailingMessages = false;
|
||||
|
||||
weaverErrors.Add(msg);
|
||||
@ -57,7 +55,7 @@ void HandleWeaverError(string msg)
|
||||
protected List<string> weaverWarnings = new List<string>();
|
||||
void HandleWeaverWarning(string msg)
|
||||
{
|
||||
logger.LogWarning(msg);
|
||||
Debug.LogWarning(msg);
|
||||
weaverWarnings.Add(msg);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user