Exemplo n.º 1
0
 public static void MoveSpeedChange(GameClient client, double newMoveSpeed)
 {
     if (Data.CheckPositionCheatSpeed)
     {
         long          startMoveTicks = ClientCmdCheck.GetClientTicks(client, 0L);
         ClientExtData clientExtData  = client.ClientData.ClientExtData;
         lock (clientExtData)
         {
             if (client.ClientData.MapCode == clientExtData.MapCode)
             {
                 if (!clientExtData.RunStoryboard)
                 {
                     if (clientExtData.EndMoveTicks > clientExtData.StartMoveTicks)
                     {
                         long   elapseTicks = startMoveTicks - clientExtData.StartMoveTicks;
                         double factor      = (double)elapseTicks / (double)(clientExtData.EndMoveTicks - clientExtData.StartMoveTicks);
                         if (factor < ClientCmdCheck.MinDistanceFactor)
                         {
                             int dx = (int)((double)(clientExtData.ToX - clientExtData.FromX) * (1.0 - factor));
                             int dy = (int)((double)(clientExtData.ToY - clientExtData.FromY) * (1.0 - factor));
                             if (Math.Abs(dx) + Math.Abs(dy) > 50)
                             {
                                 clientExtData.FromX = (client.ClientData.PosX = clientExtData.ToX - dx);
                                 clientExtData.FromY = (client.ClientData.PosY = clientExtData.ToY - dy);
                                 dx = clientExtData.ToX - clientExtData.FromX;
                                 dy = clientExtData.ToY - clientExtData.FromY;
                                 clientExtData.MaxDistance2   = dx * dx + dy * dy;
                                 clientExtData.StartMoveTicks = startMoveTicks;
                                 clientExtData.ReservedTicks  = 0L;
                                 if (newMoveSpeed >= 0.05)
                                 {
                                     clientExtData.MoveSpeed    = newMoveSpeed;
                                     clientExtData.EndMoveTicks = startMoveTicks + (long)(Math.Pow((double)clientExtData.MaxDistance2, 0.5) / (ClientCmdCheck.MoveSpeedPerMS * clientExtData.MoveSpeed));
                                 }
                                 else
                                 {
                                     clientExtData.StartMoveTicks = startMoveTicks;
                                     clientExtData.FromX          = client.ClientData.PosX;
                                     clientExtData.FromY          = client.ClientData.PosY;
                                 }
                             }
                             else
                             {
                                 clientExtData.StartMoveTicks = startMoveTicks;
                                 clientExtData.ToX            = client.ClientData.PosX;
                                 clientExtData.ToY            = client.ClientData.PosY;
                             }
                         }
                         else
                         {
                             clientExtData.StartMoveTicks = startMoveTicks;
                             clientExtData.ToX            = client.ClientData.PosX;
                             clientExtData.ToY            = client.ClientData.PosY;
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public static void StopClientStoryboard(GameClient client)
        {
            ClientExtData clientExtData = client.ClientData.ClientExtData;

            lock (clientExtData)
            {
                clientExtData.RunStoryboard = false;
            }
        }
Exemplo n.º 3
0
        public static bool ClientPosition(GameClient client, int x, int y, long startMoveTicks = 0L)
        {
            bool result;

            if (!Data.CheckPositionCheat)
            {
                result = true;
            }
            else
            {
                bool          resetPos      = false;
                ClientExtData clientExtData = client.ClientData.ClientExtData;
                lock (clientExtData)
                {
                    if (client.ClientData.MapCode != clientExtData.MapCode)
                    {
                        return(false);
                    }
                    int dx = x - clientExtData.ToX;
                    int dy = y - clientExtData.ToY;
                    if (dx != 0 || dy != 0)
                    {
                        if (!clientExtData.RunStoryboard)
                        {
                            if (clientExtData.StartMoveTicks < clientExtData.EndMoveTicks)
                            {
                                if (startMoveTicks >= clientExtData.EndMoveTicks)
                                {
                                    clientExtData.StartMoveTicks = startMoveTicks;
                                    client.ClientData.PosX       = clientExtData.ToX;
                                    client.ClientData.PosY       = clientExtData.ToY;
                                }
                            }
                            else if (Math.Abs(dx) + Math.Abs(dy) >= 500)
                            {
                                LogManager.WriteLog(LogTypes.Check, string.Format("ClientPosition位置不匹配#rid={0}", client.ClientData.RoleID), null, true);
                                client.ClientData.PosX = clientExtData.ToX;
                                client.ClientData.PosY = clientExtData.ToY;
                                resetPos = true;
                                clientExtData.StartMoveTicks = startMoveTicks;
                            }
                        }
                    }
                }
                if (resetPos)
                {
                    ClientCmdCheck.ResetClientPosition(client, client.ClientData.PosX, client.ClientData.PosY);
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        public static void ClientAction(GameClient client, long nowTicks, long reserveTicks)
        {
            ClientExtData clientExtData = client.ClientData.ClientExtData;

            lock (clientExtData)
            {
                if (client.ClientData.MapCode == clientExtData.MapCode)
                {
                    clientExtData.CanMoveTicks = ClientCmdCheck.GetClientTicks(client, 0L) + reserveTicks;
                }
            }
        }
Exemplo n.º 5
0
        public static void RecordClientPosition(GameClient client)
        {
            ClientExtData clientExtData = client.ClientData.ClientExtData;

            lock (clientExtData)
            {
                clientExtData.EndMoveTicks  = 0L;
                clientExtData.RunStoryboard = false;
                clientExtData.FromX         = client.ClientData.PosX;
                clientExtData.FromY         = client.ClientData.PosY;
                clientExtData.ToX           = client.ClientData.PosX;
                clientExtData.ToY           = client.ClientData.PosY;
                clientExtData.MapCode       = client.ClientData.MapCode;
                clientExtData.ReservedTicks = 0L;
            }
        }
Exemplo n.º 6
0
        public static bool ClientCheck(GameClient client)
        {
            ClientExtData clientExtData = client.ClientData.ClientExtData;

            if (Data.CheckTimeBoost && clientExtData.KeepAlive)
            {
                long nowTickCount = TimeUtil.NowTickCount64();
                long clientTicks  = (long)client.ClientSocket.ClientCmdSecs * 1000L + TimeUtil.Before1970Ticks;
                long diff         = nowTickCount - clientTicks;
                lock (clientExtData)
                {
                    if (diff < clientExtData.MinTimeDiff)
                    {
                        if (clientExtData.ClientLoginClientTicks == 0L)
                        {
                            clientExtData.ServerLoginTickCount   = nowTickCount;
                            clientExtData.ClientLoginClientTicks = clientTicks;
                            clientExtData.MinTimeDiff            = diff - 18000L;
                        }
                        else if (nowTickCount < clientExtData.ServerLoginTickCount + 20000L)
                        {
                            clientExtData.MinTimeDiff = diff - 18000L;
                        }
                        else if (diff < clientExtData.MinTimeDiff)
                        {
                            clientExtData.KeepAlive = false;
                            LogManager.WriteLog(LogTypes.Check, string.Format("客户端时钟偏差过大,可能是加速或调时钟#rid={0},login={1},MinTimeDiff={2},diff={3}", new object[]
                            {
                                client.ClientData.RoleID,
                                clientExtData.ServerLoginTickCount,
                                clientExtData.MinTimeDiff,
                                diff
                            }), null, true);
                        }
                    }
                    else
                    {
                        lock (clientExtData)
                        {
                            clientExtData.ServerClientTimeDiffTicks += (diff - clientExtData.ServerClientTimeDiffTicks) / (clientExtData.CalcNum += 1L);
                        }
                    }
                }
            }
            return(clientExtData.KeepAlive);
        }
Exemplo n.º 7
0
        public static bool SpriteMoveCmd(GameClient client, int fromX, int fromY, int toX, int toY, long startMoveTicks, double moveSpeed, List <Point> path, out bool stepMove)
        {
            stepMove = false;
            bool result;

            if (!Data.CheckPositionCheat)
            {
                ClientCmdCheck.SpritePreMove(client, fromX, fromY, toX, toY, startMoveTicks);
                result = true;
            }
            else
            {
                ClientExtData clientExtData = client.ClientData.ClientExtData;
                bool          resetPos;
                lock (clientExtData)
                {
                    if (client.ClientData.MapCode != clientExtData.MapCode)
                    {
                        return(false);
                    }
                    resetPos = ClientCmdCheck.MoveTo(client, fromX, fromY, startMoveTicks, false);
                    if (!resetPos)
                    {
                        ClientCmdCheck.SpritePreMove(client, fromX, fromY, toX, toY, startMoveTicks);
                        clientExtData.RunStoryboard = false;
                        if (moveSpeed < 0.05)
                        {
                            return(false);
                        }
                        if (path.Count < 2)
                        {
                            LogManager.WriteLog(LogTypes.Check, string.Format("SpriteMoveCmd路径点不足两个#rid={0}", client.ClientData.RoleID), null, true);
                            return(false);
                        }
                        if (path.Count == 2)
                        {
                            if (Math.Abs(path[0].X - path[1].X) > 1.0 || Math.Abs(path[0].Y - path[1].Y) > 1.0)
                            {
                                LogManager.WriteLog(LogTypes.Check, string.Format("SpriteMoveCmd,2点路径非法#rid={0}", client.ClientData.RoleID), null, true);
                                return(false);
                            }
                            toX = (int)path[1].X * 100 + 50;
                            toY = (int)path[1].Y * 100 + 50;
                        }
                        else if (path.Count == 3)
                        {
                            if (path[0].X == path[1].X && path[0].Y == path[1].Y)
                            {
                                if (Math.Abs(path[0].X - path[2].X) + Math.Abs(path[0].Y - path[2].Y) > 2.0)
                                {
                                    clientExtData.RunStoryboard = true;
                                }
                            }
                            else
                            {
                                if (path[0].X + path[2].X != path[1].X + path[1].X || path[0].Y + path[2].Y != path[1].Y + path[1].Y)
                                {
                                    LogManager.WriteLog(LogTypes.Check, string.Format("SpriteMoveCmd,3点路径非法#rid={0}", client.ClientData.RoleID), null, true);
                                    return(false);
                                }
                                if (Math.Abs(path[0].X - path[2].X) > 2.0 || Math.Abs(path[0].Y - path[2].Y) > 2.0)
                                {
                                    LogManager.WriteLog(LogTypes.Check, string.Format("SpriteMoveCmd,3点距离非法#rid={0}", client.ClientData.RoleID), null, true);
                                    return(false);
                                }
                            }
                            toX = (int)path[2].X * 100 + 50;
                            toY = (int)path[2].Y * 100 + 50;
                        }
                        else
                        {
                            clientExtData.RunStoryboard = true;
                        }
                        clientExtData.FromX          = fromX;
                        clientExtData.FromY          = fromY;
                        clientExtData.ToX            = toX;
                        clientExtData.ToY            = toY;
                        clientExtData.StartMoveTicks = startMoveTicks;
                        clientExtData.MaxDistance2   = (toX - fromX) * (toX - fromX) + (toY - fromY) * (toY - fromY);
                        clientExtData.MoveSpeed      = moveSpeed;
                        clientExtData.EndMoveTicks   = startMoveTicks + (long)(Math.Pow((double)clientExtData.MaxDistance2, 0.5) / (ClientCmdCheck.MoveSpeedPerMS * clientExtData.MoveSpeed));
                        stepMove = !clientExtData.RunStoryboard;
                    }
                }
                if (resetPos)
                {
                    ClientCmdCheck.ResetClientPosition(client, clientExtData.FromX, clientExtData.FromY);
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        private static bool MoveTo(GameClient client, int x, int y, long startMoveTicks, bool stop)
        {
            bool          resetPos      = false;
            ClientExtData clientExtData = client.ClientData.ClientExtData;

            lock (clientExtData)
            {
                if (client.ClientData.MapCode != clientExtData.MapCode)
                {
                    LogManager.WriteLog(LogTypes.Check, string.Format("MoveTo地图不匹配#rid={2},current={0},last={1}", client.ClientData.MapCode, clientExtData.MapCode, client.ClientData.RoleID), null, true);
                    return(false);
                }
                if (startMoveTicks < clientExtData.CanMoveTicks)
                {
                    LogManager.WriteLog(LogTypes.Check, string.Format("MoveTo未到可移动时间rid={1},#time={0}", clientExtData.CanMoveTicks - startMoveTicks, client.ClientData.RoleID), null, true);
                    return(false);
                }
                int dx2 = clientExtData.ToX - clientExtData.FromX;
                int dy2 = clientExtData.ToY - clientExtData.FromY;
                if (dx2 != 0 || dy2 != 0)
                {
                    int  dx3       = x - clientExtData.FromX;
                    int  dy3       = y - clientExtData.FromY;
                    long distance2 = (long)(dx3 * dx3 + dy3 * dy3);
                    if (distance2 > 0L)
                    {
                        long elapseTicks;
                        if (startMoveTicks < clientExtData.StopMoveTicks)
                        {
                            elapseTicks = startMoveTicks - clientExtData.StartMoveTicks - clientExtData.ReservedTicks;
                        }
                        else
                        {
                            elapseTicks = clientExtData.StopMoveTicks - clientExtData.StartMoveTicks - clientExtData.ReservedTicks;
                        }
                        if (!clientExtData.RunStoryboard && client.InSafeRegion)
                        {
                            clientExtData.ReservedTicks += (long)(Math.Pow((double)distance2, 0.5) / (ClientCmdCheck.MoveSpeedPerMS * clientExtData.MoveSpeed * 0.8) - (double)elapseTicks);
                        }
                        else
                        {
                            clientExtData.ReservedTicks += (long)(Math.Pow((double)distance2, 0.5) / (ClientCmdCheck.MoveSpeedPerMS * clientExtData.MoveSpeed) - (double)elapseTicks);
                        }
                        if (clientExtData.ReservedTicks > ClientCmdCheck.MaxReserveMs)
                        {
                            resetPos = true;
                            LogManager.WriteLog(LogTypes.Check, string.Format("MoveTo时间校验超限#rid={1},ticks={0}", clientExtData.ReservedTicks, client.ClientData.RoleID), null, true);
                        }
                        else if (clientExtData.ReservedTicks < -100L)
                        {
                            clientExtData.ReservedTicks = -100L;
                        }
                    }
                }
                else
                {
                    int  dx3       = x - clientExtData.FromX;
                    int  dy3       = y - clientExtData.FromY;
                    long distance2 = (long)(dx3 * dx3 + dy3 * dy3);
                    if (distance2 > 5000L)
                    {
                        x        = clientExtData.FromX;
                        y        = clientExtData.FromY;
                        resetPos = true;
                    }
                }
                if (resetPos)
                {
                    clientExtData.ToX          = x;
                    clientExtData.ToY          = y;
                    clientExtData.MaxDistance2 = (x - clientExtData.FromX) * (x - clientExtData.FromX) + (y - clientExtData.FromY) * (y - clientExtData.FromY);
                }
                else if (!clientExtData.RunStoryboard)
                {
                    client.ClientData.PosX = x;
                    client.ClientData.PosY = y;
                }
                if (stop)
                {
                    clientExtData.StopMoveTicks = startMoveTicks;
                }
                else
                {
                    clientExtData.StopMoveTicks = long.MaxValue;
                }
            }
            return(resetPos);
        }