public void OnCreatableInstantiated(NetCreatableInfo info, NetConnectionSnapshotState state)
        {
            ServerMPPlayer player = info.Creatable as ServerMPPlayer;

            if (player != null)
            {
                NetConnection owner = state.Connection;
                WriteDebug("[CSS] Created MPPlayer for {0}.", owner);

                // Create the worldsnapshot for the the player
                WorldSnapshot ws = state.WorldSnapshot;

                // Add the current players to the snapshot
                foreach (ServerMPPlayer plr in players.Values)
                {
                    if (!ws.IsPlayerAdded(plr.StateInfo.Id))
                    {
                        ws.AddPlayer(plr.StateInfo.Id, false, true);
                    }
                }

                // Add the new player
                players.Add(info.Id, player);
                playersFromConnection.Add(player.StateInfo.Owner, player);

                // Add the new player to each players state (including the new player's state)
                foreach (NetConnectionSnapshotState otherState in snapshotComponent.ConnectionStates.Values)
                {
                    otherState.WorldSnapshot.AddPlayer(info.Id, state == otherState, true);
                }
            }
        }
Пример #2
0
        public void OnCreatableInstantiated(NetCreatableInfo info, WorldSnapshot ws)
        {
            ClientPlayer player = info.Creatable as ClientPlayer;

            // Add the new player
            if (player != null)
            {
                players.Add(info.Id, player);

                if (info.IsAppOwner)
                {
                    // Setup player as our own
                    if (ourPlayer != null)
                    {
                        DashCMD.WriteError("[CSS] Received client player instantiation twice!");
                    }
                    else
                    {
                        // Setup our gamestate
                        // Copy each existing player to the worldsnapshot
                        foreach (ClientPlayer plr in players.Values)
                        {
                            if (plr == player)
                            {
                                // The new player doesn't have stateinfo setup yet
                                ws.AddPlayer(info.Id, true, false);
                            }
                            else if (!ws.PlayerFieldExists(plr.StateInfo.Id))
                            {
                                ws.AddPlayer(plr.StateInfo.Id, false, false);
                            }
                        }

                        // Set our player and our new world snapshot
                        ourPlayer = (ClientMPPlayer)player;
                    }
                }
                else
                {
                    ws.AddPlayer(info.Id, false, false);
                }
            }
        }