public static bool SendReconnectMessage(MessageBase extraMessage) { bool result; if (!ClientScene.hasMigrationPending()) { result = false; } else { if (LogFilter.logDebug) { Debug.Log("ClientScene::AddPlayer reconnect " + ClientScene.s_ReconnectId); } if (ClientScene.s_Peers == null) { ClientScene.SetReconnectId(-1, null); if (LogFilter.logError) { Debug.LogError("ClientScene::AddPlayer: reconnecting, but no peers."); } result = false; } else { for (int i = 0; i < ClientScene.s_Peers.Length; i++) { PeerInfoMessage peerInfoMessage = ClientScene.s_Peers[i]; if (peerInfoMessage.playerIds != null) { if (peerInfoMessage.connectionId == ClientScene.s_ReconnectId) { for (int j = 0; j < peerInfoMessage.playerIds.Length; j++) { ReconnectMessage reconnectMessage = new ReconnectMessage(); reconnectMessage.oldConnectionId = ClientScene.s_ReconnectId; reconnectMessage.netId = peerInfoMessage.playerIds[j].netId; reconnectMessage.playerControllerId = peerInfoMessage.playerIds[j].playerControllerId; if (extraMessage != null) { NetworkWriter networkWriter = new NetworkWriter(); extraMessage.Serialize(networkWriter); reconnectMessage.msgData = networkWriter.ToArray(); reconnectMessage.msgSize = (int)networkWriter.Position; } ClientScene.s_ReadyConnection.Send(47, reconnectMessage); } } } } ClientScene.SetReconnectId(-1, null); result = true; } } return(result); }
public void Reset(int reconnectId) { m_OldServerConnectionId = -1; m_WaitingToBecomeNewHost = false; m_WaitingReconnectToNewHost = false; m_DisconnectedFromHost = false; m_HostWasShutdown = false; ClientScene.SetReconnectId(reconnectId, m_Peers); if (NetworkManager.singleton != null) { NetworkManager.singleton.SetupMigrationManager(this); } }
/// <summary> /// <para>Resets the migration manager, and sets the ClientScene's ReconnectId.</para> /// </summary> /// <param name="reconnectId">The connectionId for the ClientScene to use when reconnecting.</param> public void Reset(int reconnectId) { this.m_OldServerConnectionId = -1; this.m_WaitingToBecomeNewHost = false; this.m_WaitingReconnectToNewHost = false; this.m_DisconnectedFromHost = false; this.m_HostWasShutdown = false; ClientScene.SetReconnectId(reconnectId, this.m_Peers); if (!((Object)NetworkManager.singleton != (Object)null)) { return; } NetworkManager.singleton.SetupMigrationManager(this); }
/// <summary> /// <para>This adds a player object for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer will be called. If an extra message was passed to AddPlayer, then OnServerAddPlayer will be called with a NetworkReader that contains the contents of the message.</para> /// </summary> /// <param name="readyConn">The connection to become ready for this client.</param> /// <param name="playerControllerId">The local player ID number.</param> /// <param name="extraMessage">An extra message object that can be passed to the server for this player.</param> /// <returns> /// <para>True if player was added.</para> /// </returns> public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId, MessageBase extraMessage) { if ((int)playerControllerId < 0) { if (LogFilter.logError) { Debug.LogError((object)("ClientScene::AddPlayer: playerControllerId of " + (object)playerControllerId + " is negative")); } return(false); } if ((int)playerControllerId > 32) { if (LogFilter.logError) { Debug.LogError((object)("ClientScene::AddPlayer: playerControllerId of " + (object)playerControllerId + " is too high, max is " + (object)32)); } return(false); } if ((int)playerControllerId > 16 && LogFilter.logWarn) { Debug.LogWarning((object)("ClientScene::AddPlayer: playerControllerId of " + (object)playerControllerId + " is unusually high")); } while ((int)playerControllerId >= ClientScene.s_LocalPlayers.Count) { ClientScene.s_LocalPlayers.Add(new PlayerController()); } if (readyConn == null) { if (!ClientScene.s_IsReady) { if (LogFilter.logError) { Debug.LogError((object)"Must call AddPlayer() with a connection the first time to become ready."); } return(false); } } else { ClientScene.s_IsReady = true; ClientScene.s_ReadyConnection = readyConn; } PlayerController playerController; if (ClientScene.s_ReadyConnection.GetPlayerController(playerControllerId, out playerController) && playerController.IsValid && (Object)playerController.gameObject != (Object)null) { if (LogFilter.logError) { Debug.LogError((object)("ClientScene::AddPlayer: playerControllerId of " + (object)playerControllerId + " already in use.")); } return(false); } if (LogFilter.logDebug) { Debug.Log((object)("ClientScene::AddPlayer() for ID " + (object)playerControllerId + " called with connection [" + (object)ClientScene.s_ReadyConnection + "]")); } if (ClientScene.s_ReconnectId == -1) { AddPlayerMessage addPlayerMessage = new AddPlayerMessage(); addPlayerMessage.playerControllerId = playerControllerId; if (extraMessage != null) { NetworkWriter writer = new NetworkWriter(); extraMessage.Serialize(writer); addPlayerMessage.msgData = writer.ToArray(); addPlayerMessage.msgSize = (int)writer.Position; } ClientScene.s_ReadyConnection.Send((short)37, (MessageBase)addPlayerMessage); } else { if (LogFilter.logDebug) { Debug.Log((object)("ClientScene::AddPlayer reconnect " + (object)ClientScene.s_ReconnectId)); } if (ClientScene.s_Peers == null) { ClientScene.SetReconnectId(-1, (PeerInfoMessage[])null); if (LogFilter.logError) { Debug.LogError((object)"ClientScene::AddPlayer: reconnecting, but no peers."); } return(false); } foreach (PeerInfoMessage peer in ClientScene.s_Peers) { if (peer.playerIds != null && peer.connectionId == ClientScene.s_ReconnectId) { foreach (PeerInfoPlayer playerId in peer.playerIds) { ReconnectMessage reconnectMessage = new ReconnectMessage(); reconnectMessage.oldConnectionId = ClientScene.s_ReconnectId; reconnectMessage.netId = playerId.netId; reconnectMessage.playerControllerId = playerId.playerControllerId; if (extraMessage != null) { NetworkWriter writer = new NetworkWriter(); extraMessage.Serialize(writer); reconnectMessage.msgData = writer.ToArray(); reconnectMessage.msgSize = (int)writer.Position; } ClientScene.s_ReadyConnection.Send((short)47, (MessageBase)reconnectMessage); } } } ClientScene.SetReconnectId(-1, (PeerInfoMessage[])null); } return(true); }