Exemplo n.º 1
0
        /// <summary>
        /// Occurs when the engine receives a packet from the client
        /// </summary>
        protected void NetHooks_GetData(GetDataEventArgs args)
        {
            byte index = default(byte);
            PlayerControlFlags playerState = default(PlayerControlFlags);
            Player             player;

            if (args.MsgID != PacketTypes.PlayerUpdate ||
                (index = args.Msg.readBuffer[args.Index]) < 0 ||
                (player = Main.player.ElementAtOrDefault(args.Msg.whoAmI)) == null)
            {
                return;
            }

            if ((playerState = (PlayerControlFlags)args.Msg.readBuffer[args.Index + 1]) != PlayerControlFlags.Idle)
            {
                Parent.UpdatePlayerIdle(player);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Occurs when the server receives data from the client.
        /// </summary>
        void NetHooks_GetData(Hooks.GetDataEventArgs e)
        {
            if (e.MsgID == PacketTypes.PlayerUpdate)
            {
                byte playerIndex = e.Msg.readBuffer[e.Index];
                PlayerControlFlags    playerState   = (PlayerControlFlags)e.Msg.readBuffer[e.Index + 1];
                Economy.EconomyPlayer currentPlayer = GetEconomyPlayerSafe(playerIndex);

                //The idea behind this logic is that IdleSince resets to now any time the server an action from the client.
                //If the client never updates, or updates to 0 (Idle) then "IdleSince" never changes.
                //When you want to get the amount of time the player has been idle, just subtract it from DateTime.Now
                //And voila, you get a TimeSpan with how long the user has been idle for.
                if (playerState != PlayerControlFlags.Idle)
                {
                    currentPlayer.IdleSince = DateTime.Now;
                }

                currentPlayer.LastKnownState = playerState;
            }
        }