From ce8ede3db391eebd82728c6d4a0cc69008265906 Mon Sep 17 00:00:00 2001 From: vis2k Date: Fri, 18 Jan 2019 13:08:19 +0100 Subject: [PATCH] OnServerAddPlayer uses NetworkMessage parameter instead of NetworkReader. Removes last dependency on NetworkReader.ReadMessage (#307) --- Assets/Mirror/Runtime/ClientScene.cs | 1 + Assets/Mirror/Runtime/NetworkManager.cs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Assets/Mirror/Runtime/ClientScene.cs b/Assets/Mirror/Runtime/ClientScene.cs index 6a07ae73f..0e8fe8ef4 100644 --- a/Assets/Mirror/Runtime/ClientScene.cs +++ b/Assets/Mirror/Runtime/ClientScene.cs @@ -78,6 +78,7 @@ public static bool AddPlayer(NetworkConnection readyConn) } // use this to implicitly become ready + // -> extraMessage can contain character selection, etc. public static bool AddPlayer(NetworkConnection readyConn, MessageBase extraMessage) { // ensure valid ready connection diff --git a/Assets/Mirror/Runtime/NetworkManager.cs b/Assets/Mirror/Runtime/NetworkManager.cs index 8f291dabf..1fc48fd2b 100644 --- a/Assets/Mirror/Runtime/NetworkManager.cs +++ b/Assets/Mirror/Runtime/NetworkManager.cs @@ -518,8 +518,12 @@ internal void OnServerAddPlayerMessageInternal(NetworkMessage netMsg) if (msg.value != null && msg.value.Length > 0) { - NetworkReader reader = new NetworkReader(msg.value); - OnServerAddPlayer(netMsg.conn, reader); + // convert payload to extra message and call OnServerAddPlayer + // (usually for character selection information) + NetworkMessage extraMessage = new NetworkMessage(); + extraMessage.reader = new NetworkReader(msg.value); + extraMessage.conn = netMsg.conn; + OnServerAddPlayer(netMsg.conn, extraMessage); } else { @@ -629,7 +633,7 @@ public virtual void OnServerReady(NetworkConnection conn) NetworkServer.SetClientReady(conn); } - public virtual void OnServerAddPlayer(NetworkConnection conn, NetworkReader extraMessageReader) + public virtual void OnServerAddPlayer(NetworkConnection conn, NetworkMessage extraMessage) { OnServerAddPlayerInternal(conn); }