public void C2S_PING(GameConnection conn, Packet packet)
        {
            Log.Info("Received ping from " + conn.Character.Name);
            var currentServerTick = (uint)(int.MaxValue & (Environment.TickCount - conn.Character.Handle));
            var cTick             = new MSG_CHK_TIMETICK();
            var buffer            = packet.GetBuffer();

            cTick.Deserialize(ref buffer);

            if (conn.Character.ClientTick == 0)
            {
                conn.Character.PreviousServerTick = currentServerTick;
                conn.Character.ClientTick         = cTick.ClientTick;
                conn.Character.PreviousTickCount  = cTick.TickCount;
                return;
            }

            if (cTick.TickCount - conn.Character.PreviousTickCount != 1)
            {
                Log.Info(string.Format("[Index] {0} {1} {2} Pre:{3} now:{4} SendTime:{5} {6}", conn.Character.Account.Username, conn.Character.Name, conn.Character.IPAddress, conn.Character.CurrentTickCount, cTick.TickCount, cTick.ClientTick - conn.Character.ClientTick, currentServerTick - conn.Character.CurrentServerTick));
                conn.Character.CurrentTickCount = cTick.TickCount++;
                conn.Character.CurrentTickCount = cTick.TickCount;
                return;
            }

            if (cTick.ServerTick != conn.Character.CurrentServerTick)
            {
                Log.Info(string.Format("[Hack] {0} {1} {2} Changed SvrTick:{3}->{4} {5}", conn.Character.Account.Username, conn.Character.Name, conn.Character.IPAddress, conn.Character.CurrentServerTick, cTick.ServerTick, currentServerTick - conn.Character.CurrentServerTick));

                // TODO: Handle speed hackers
                return;
            }

            var serverTickDiff = Math.Abs(currentServerTick - conn.Character.PreviousServerTick);
            var clientTickDiff = Math.Abs(cTick.ClientTick - conn.Character.ClientTick);

            if (Math.Abs(serverTickDiff - clientTickDiff) > 500)
            {
                if (++conn.Character.TickErrorCount > 1)
                {
                    Log.Info(string.Format("[Hack] {0} {1} {2} {3} {4} {5}", conn.Character.Account.Username, conn.Character.Name, conn.Character.IPAddress, serverTickDiff, clientTickDiff, currentServerTick - conn.Character.CurrentServerTick));

                    // TODO: Handle speed hackers
                    return;
                }

                conn.Character.PreviousTickCount  = cTick.TickCount;
                conn.Character.ClientTick         = cTick.ClientTick;
                conn.Character.PreviousServerTick = currentServerTick;
                return;
            }

            conn.Character.PreviousTickCount  = cTick.TickCount;
            conn.Character.ClientTick         = cTick.ClientTick;
            conn.Character.PreviousServerTick = currentServerTick;
            conn.Character.TickErrorCount     = 0;
        }
Example #2
0
        public void PingCharacters()
        {
            foreach (var character in this._characters.Values)
            {
                if (character.CurrentState == Shared.Const.PlayerState.STANDBY)
                {
                    continue;
                }

                var msg = new MSG_CHK_TIMETICK();
                character.CurrentServerTick = (uint)(int.MaxValue & (Environment.TickCount - character.Handle));
                msg.TickCount  = character.CurrentTickCount++;
                msg.ServerTick = character.CurrentServerTick;
                character.GameConnection.NoEncryptSend(msg.Serialize());
                Shared.Util.Log.Info("Sent ping to " + character.Name);
            }
        }