public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId, MessageBase extraMessage)
{
if (playerControllerId < 0)
{
if (LogFilter.logError)
{
Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is negative");
}
return(false);
}
if (playerControllerId > 32)
{
if (LogFilter.logError)
{
Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is too high, max is " + 32);
}
return(false);
}
if (playerControllerId > 16 && LogFilter.logWarn)
{
Debug.LogWarning("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is unusually high");
}
while (playerControllerId >= s_LocalPlayers.Count)
{
s_LocalPlayers.Add(new PlayerController());
}
if (readyConn == null)
{
if (!s_IsReady)
{
if (LogFilter.logError)
{
Debug.LogError("Must call AddPlayer() with a connection the first time to become ready.");
}
return(false);
}
}
else
{
s_IsReady = true;
s_ReadyConnection = readyConn;
}
PlayerController playerController;
if (s_ReadyConnection.GetPlayerController(playerControllerId, out playerController) && 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("ClientScene::AddPlayer() for ID " + playerControllerId + " called with connection [" + s_ReadyConnection + "]");
}
AddPlayerMessage addPlayerMessage = new AddPlayerMessage();
addPlayerMessage.playerControllerId = playerControllerId;
if (extraMessage != null)
{
NetworkWriter networkWriter = new NetworkWriter();
extraMessage.Serialize(networkWriter);
addPlayerMessage.msgData = networkWriter.ToArray();
addPlayerMessage.msgSize = networkWriter.Position;
}
s_ReadyConnection.Send(37, addPlayerMessage);
return(true);
}