Exemple #1
0
        public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId, MessageBase extraMessage)
        {
            bool result;

            if (playerControllerId < 0)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is negative");
                }
                result = false;
            }
            else if (playerControllerId > 32)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError(string.Concat(new object[]
                    {
                        "ClientScene::AddPlayer: playerControllerId of ",
                        playerControllerId,
                        " is too high, max is ",
                        32
                    }));
                }
                result = false;
            }
            else
            {
                if (playerControllerId > 16)
                {
                    if (LogFilter.logWarn)
                    {
                        Debug.LogWarning("ClientScene::AddPlayer: playerControllerId of " + 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("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))
                {
                    if (playerController.IsValid && playerController.gameObject != null)
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " already in use.");
                        }
                        return(false);
                    }
                }
                if (LogFilter.logDebug)
                {
                    Debug.Log(string.Concat(new object[]
                    {
                        "ClientScene::AddPlayer() for ID ",
                        playerControllerId,
                        " called with connection [",
                        ClientScene.s_ReadyConnection,
                        "]"
                    }));
                }
                if (!ClientScene.hasMigrationPending())
                {
                    AddPlayerMessage addPlayerMessage = new AddPlayerMessage();
                    addPlayerMessage.playerControllerId = playerControllerId;
                    if (extraMessage != null)
                    {
                        NetworkWriter networkWriter = new NetworkWriter();
                        extraMessage.Serialize(networkWriter);
                        addPlayerMessage.msgData = networkWriter.ToArray();
                        addPlayerMessage.msgSize = (int)networkWriter.Position;
                    }
                    ClientScene.s_ReadyConnection.Send(37, addPlayerMessage);
                    result = true;
                }
                else
                {
                    result = ClientScene.SendReconnectMessage(extraMessage);
                }
            }
            return(result);
        }