Exemplo n.º 1
0
        /// <summary>
        /// 时间戳检查(可以防止客户端游戏过程中修改时间)
        /// </summary>
        /// <param name="context"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        bool CheckTime(IChannelHandlerContext context, long time)
        {
            var _time = context.Channel.GetAttribute(LAST_RECV_TIME).Get();

            if (_time != null)
            {
                long lastTime = _time.value;
                if (lastTime > time)
                {
                    LOGGER.Error("时间戳出错,time=" + time + ", lastTime=" + lastTime + " " + context);
                    return(false);
                }
                _time.value = time;
            }
            else
            {
                _time = new OneParam <long>(time);
            }
            context.Channel.GetAttribute(LAST_RECV_TIME).Set(_time);
            return(true);
        }
Exemplo n.º 2
0
        bool CheckMagicNumber(IChannelHandlerContext context, int order, int msgLen)
        {
            order ^= (0x1234 << 8);
            order ^= msgLen;
            var _order = context.Channel.GetAttribute(LAST_RECV_ORDER).Get();

            if (_order != null)
            {
                int lastOrder = _order.value;
                if (order != lastOrder + 1)
                {
                    LOGGER.Error("包序列出错, order=" + order + ", lastOrder=" + lastOrder);
                    return(false);
                }
                _order.value = order;
            }
            else
            {
                _order = new OneParam <int>(order);
            }
            context.Channel.GetAttribute(LAST_RECV_ORDER).Set(_order);
            return(true);
        }