public void OnServerInbound(NetInboundPacket packet, NetConnectionSnapshotState state)
        {
            bool playerSentData = packet.ReadBool();

            if (!playerSentData)
            {
                return;
            }

            ushort entId = packet.ReadUInt16();

            ServerMPPlayer player;

            if (players.TryGetValue(entId, out player))
            {
                // Read packet to snapshot
                player.ClientSnapshot.Deserialize(packet);
                // Update player
                player.OnServerInbound();
            }
            else if (DashCMD.GetCVar <bool>("log_css"))
            {
                DashCMD.WriteError("[CSS] Received client snapshot for player with id {0}, which does not exist!", entId);
            }
        }
        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);
                }
            }
        }
Example #3
0
        public void SendInstantiationPackets(NetConnection to)
        {
            foreach (NetOutboundPacket packet in instPackets.Values)
            {
                to.SendPacket(packet.Clone());
            }

            foreach (NetCreatableInfo info in netObjects.Entities.Values)
            {
                NetConnectionSnapshotState state = snapshotComponent.ConnectionStates[to];
                state.WorldSnapshot.NetEntityListSnapshot.AddNetEntity(info, (INetEntity)info.Creatable);
            }
        }
        public void OnServerOutbound(NetOutboundPacket packet, NetConnectionSnapshotState state)
        {
            // Write each player to the snapshot
            WorldSnapshot worldSnapshot = state.WorldSnapshot;

            foreach (ServerMPPlayer plr in players.Values)
            {
                PlayerSnapshot playerSnapshot;
                if (worldSnapshot.TryGetPlayer(plr.StateInfo.Id, out playerSnapshot))
                {
                    plr.OnServerOutbound(playerSnapshot);
                }
            }
        }
        public void OnHandshakeComplete(Handshake h)
        {
            // Notify gamemode
            currentGamemode.OnConnectionReady(h.With);

            // Add late changes in terrain to players snapshot
            NetConnectionSnapshotState state = snapshotComponent.ConnectionStates[h.With];

            foreach (BlockChange change in h.TerrainChanges)
            {
                state.WorldSnapshot.TerrainSnapshot.AddChange(change);
            }

            // And...were good.
            state.Ready = true;
        }
        void SendSnapshotTo(NetConnection conn, NetConnectionSnapshotState connState, float deltaTime)
        {
            WorldSnapshot worldSnapshot = connState.WorldSnapshot;

            ushort epid = connState.OutboundSnapshotId;

            connState.OutboundSnapshotId++;

            //connState.TimeSinceLastSend -= deltaTime;
            //connState.GotPacket = false;

            connState.WorldSnapshot.MaxClientTickrate  = DashCMD.GetCVar <ushort>("ag_max_cl_tickrate");
            connState.WorldSnapshot.ForceSnapshotAwait = DashCMD.GetCVar <bool>("ag_cl_force_await_snap");

            NetOutboundPacket packet = new NetOutboundPacket(NetDeliveryMethod.Unreliable);

            packet.SendImmediately = true;
            int size = packet.Length;

            packet.Write((byte)CustomPacketType.Snapshot);
            packet.Write(epid);
            int _packetheader = packet.Length - size; size = packet.Length;

            // Write snapshot system data
            snapshotSystem.OnOutbound(packet, conn);
            int _acks = packet.Length - size; size = packet.Length;

            // Write players
            charSnapshotSystem.OnServerOutbound(packet, connState);

            // Invoke event
            if (OnWorldSnapshotOutbound != null)
            {
                OnWorldSnapshotOutbound(this, worldSnapshot);
            }

            // Serialize snapshot
            NetBuffer buffer = new NetBuffer();

            worldSnapshot.Serialize(buffer);

            packet.Write((ushort)buffer.Length);
            packet.WriteBytes(buffer.Data, 0, buffer.Length);


            int _playerdata  = packet.Length - size; size = packet.Length;
            int _terraindata = connState.WorldSnapshot.TerrainSnapshot.LastByteSize;

            _playerdata -= _terraindata;

            // Send packet
            conn.SendPacket(packet);

            if (connState != null)
            {
                SnapshotStats stats = connState.Stats;
                stats.PacketHeader = _packetheader;
                stats.Acks         = _acks;
                stats.PlayerData   = _playerdata;
                stats.TerrainData  = _terraindata;
            }
        }