Beispiel #1
0
        /// <summary>
        /// Performs a client sync tick.
        /// </summary>
        /// <param name="Tick">The number of the tick, which can be used to determine a few things, like when to sync certain things.</param>
        public override void PerformTick(int Tick)
        {
            ClientSyncPkt SyncPkt = new ClientSyncPkt();

            var PlayerCharacter = Client.GetConnectedPlayer().Character;

            SyncPkt.ClientSyncID  = NextSyncID();
            SyncPkt.MoveDirection = PlayerCharacter.GetMovementDirection();
            SyncPkt.Rotation      = PlayerCharacter.GetRotation();

            Client.SendByChannel(PktType.ClientSync, SyncPkt, NetworkChannelID.Unreliable);
        }
Beispiel #2
0
        /// <summary>
        /// Handle the given sync from a client. Must be checked to be <see cref="PktType.ClientSync"/> first.
        /// </summary>
        /// <param name="message"></param>
        public void HandleSyncPkt(NetworkMessage message)
        {
            ClientSyncPkt SyncPkt = new ClientSyncPkt();

            SyncPkt.Deserialize(message.reader);
            int LastID = -1;

            if (LastSyncIDReceived.ContainsKey(message.conn.connectionId))
            {
                LastID = LastSyncIDReceived[message.conn.connectionId];
            }
            if (SyncPkt.ClientSyncID > LastID)
            {
                SyncPkt.ReadTheRest(message.reader);
                LastSyncIDReceived[message.conn.connectionId] = SyncPkt.ClientSyncID;

                Character PlayerCharacter = Players[message.conn.connectionId].Character;
                PlayerCharacter.Move(SyncPkt.MoveDirection);
                PlayerCharacter.SetRotation(SyncPkt.Rotation);
            }
            // Disregard the package, it's too old.
        }