public static void writeInfo(SendPacket s, ReceivePacket p, bool genLog)
        {
            Struct info = ReadInfo(p, genLog);

            writeInfo(s, info);
            info = null;
        }
Beispiel #2
0
 private static code1_GrenadeSync.Struct BaseReadInfo(ReceivePacket p, bool OnlyBytes, bool genLog)
 {
     code1_GrenadeSync.Struct @struct = new code1_GrenadeSync.Struct()
     {
         _weaponInfo    = p.readUH(),
         _weaponSlot    = p.readC(),
         _unk           = p.readUH(),
         _objPos_x      = p.readUH(),
         _objPos_y      = p.readUH(),
         _objPos_z      = p.readUH(),
         _unk5          = p.readUH(),
         _unk6          = p.readUH(),
         _unk7          = p.readUH(),
         _grenadesCount = p.readUH()
     };
     @struct._unk8 = p.readB(6);
     if (!OnlyBytes)
     {
         @struct.WeaponNumber = (int)@struct._weaponInfo >> 6;
         @struct.WeaponClass  = (int)@struct._weaponInfo & 47;
     }
     if (genLog)
     {
         Logger.warning("[code1_GrenadeSync] " + BitConverter.ToString(p.getBuffer()), false);
         Logger.warning("[code1_GrenadeSync] wInfo: " + (object)@struct._weaponInfo + "; wSlot: " + (object)@struct._weaponSlot + "; u: " + (object)@struct._unk + "; obpX: " + (object)@struct._objPos_x + "; obpY: " + (object)@struct._objPos_y + "; obpZ: " + (object)@struct._objPos_z + "; u5: " + (object)@struct._unk5 + "; u6: " + (object)@struct._unk6 + "; u7: " + (object)@struct._unk7 + "; u8: " + (object)@struct._unk8, false);
     }
     return(@struct);
 }
        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int           readlength;
            Object        response = null;
            ReceivePacket packet   = null;

            try
            {
                packet = this._protocol.TryToTranslateMessage(connection, e.Buffer, DefaultConfigure.MaxMessageSize, out readlength);
            }
            catch (Exception ex)
            {
                this.OnError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            if (response != null)
            {
                this.OnResponse(connection, response);
            }
            e.SetReadlength(readlength);
        }
Beispiel #4
0
        public static List <a4000_BotHitData.HitData> ReadInfo(ReceivePacket p, bool genLog)
        {
            List <a4000_BotHitData.HitData> hitDataList = new List <a4000_BotHitData.HitData>();
            int num = (int)p.readC();

            for (int index = 0; index < num; ++index)
            {
                a4000_BotHitData.HitData hitData = new a4000_BotHitData.HitData()
                {
                    _hitInfo    = p.readUD(),
                    _weaponInfo = p.readUH(),
                    _weaponSlot = p.readC(),
                    _unk        = p.readUH(),
                    _eixoX      = p.readUH(),
                    _eixoY      = p.readUH(),
                    _eixoZ      = p.readUH()
                };
                if (genLog)
                {
                    Logger.warning("P: " + (object)hitData._eixoX + ";" + (object)hitData._eixoY + ";" + (object)hitData._eixoZ, false);
                    Logger.warning("[" + (object)index + "] 16384: " + BitConverter.ToString(p.getBuffer()), false);
                }
                hitDataList.Add(hitData);
            }
            return(hitDataList);
        }
Beispiel #5
0
    /// <summary>
    /// 读取二进制转换为结构
    /// </summary>
    /// <returns></returns>
    public ReceivePacket Read(int cmd, ByteStream recvStream, int len)
    {
        ServerMessage msg = serverMessageData.GetServerMessage(cmd);

        if (msg == null)
        {
            return(null);
        }
        ReceivePacket p = new ReceivePacket
        {
            cmd      = cmd,
            callback = msg.callback.Method,
        };

        byte[] msgbody = recvStream.ReadByte(len);
        if (msgbody == null || msgbody.Length == 0)
        {
            p.protoObj = Activator.CreateInstance(msg.msgType);
            return(p);
        }

        MemoryStream stream = new MemoryStream(msgbody);

        stream.SetLength(msgbody.Length);
        try
        {
            p.protoObj = RuntimeTypeModel.Default.Deserialize(stream, null, msg.msgType);
        }
        catch (Exception)
        {
            Debug.LogError("protobuf反序列化失败");
        }

        return(p);
    }
        private static List <a20000_InvalidHitData.HitData> BaseReadInfo(ReceivePacket p, bool OnlyBytes, bool genLog)
        {
            List <a20000_InvalidHitData.HitData> hitDataList = new List <a20000_InvalidHitData.HitData>();
            int num = (int)p.readC();

            for (int index = 0; index < num; ++index)
            {
                a20000_InvalidHitData.HitData hitData = new a20000_InvalidHitData.HitData()
                {
                    _hitInfo = p.readUH(),
                    FirePos  = p.readUHVector(),
                    HitPos   = p.readUHVector()
                };
                if (!OnlyBytes)
                {
                    hitData.HitEnum = (HitType)AllUtils.getHitHelmet((uint)hitData._hitInfo);
                }
                if (!genLog)
                {
                    ;
                }
                hitDataList.Add(hitData);
            }
            return(hitDataList);
        }
        private static List <HitData> BaseReadInfo(ReceivePacket p, bool OnlyBytes, bool genLog)
        {
            List <HitData> hits      = new List <HitData>();
            int            objsCount = p.readC();

            for (int ob = 0; ob < objsCount; ob++)
            {
                HitData hit = new HitData
                {
                    _hitInfo = p.readUH(),
                    FirePos  = p.readUHVector(),
                    HitPos   = p.readUHVector()
                };
                if (!OnlyBytes)
                {
                    hit.HitEnum = (HitType)AllUtils.getHitHelmet(hit._hitInfo);
                }
                if (genLog)
                {
                    //Logger.warning("StartBulletAxis: " + hit._startBulletX + ";" + hit._startBulletY + ";" + hit._startBulletZ);
                    //Logger.warning("EndBulletAxis: " + hit._endBulletX + ";" + hit._endBulletY + ";" + hit._endBulletZ);
                }
                hits.Add(hit);
            }
            return(hits);
        }
        public void TestSocketParse()
        {
            byte[]      data       = ("这是一条测试数据").ToBytes();
            SendPacket  sendPacket = new SendPacket(data);
            List <byte> dataList   = new List <byte>();

            dataList.AddRange(sendPacket.PackData());
            dataList.AddRange(sendPacket.PackData());
            data = dataList.ToArray();
            ReceivePacket ReceivePacket = new ReceivePacket();

            while (data.Length > 0)
            {
                if (ReceivePacket.ParseData(ref data))
                {
                    string str = ReceivePacket.GetBytes().ToStringUnicode();
                    Console.WriteLine(str);
                    Assert.AreEqual("这是一条测试数据", str);
                    ReceivePacket = new ReceivePacket();
                }
                else
                {
                    Assert.Fail();
                    break;
                }
            }
        }
        private static List <HitData> BaseReadInfo(ReceivePacket p, bool OnlyBytes, bool genLog)
        {
            List <HitData> hits  = new List <HitData>();
            int            count = p.readC();

            for (int i = 0; i < count; i++)
            {
                HitData hit = new HitData
                {
                    _hitInfo    = p.readUD(),
                    _weaponInfo = p.readUH(),
                    _weaponSlot = p.readC(),
                    PlayerPos   = p.readUHVector()
                };
                if (!OnlyBytes)
                {
                    hit.WeaponClass = (ClassType)((hit._weaponInfo >> 32) & 63); //Funcional? Antigo = >> 32) & 31 | Novo = >> 32) & 63
                    hit.WeaponId    = (hit._weaponInfo >> 6);
                }
                if (genLog)
                {
                    Printf.warning("[" + i + "] Committed suicide: hitinfo,weaponinfo,weaponslot,camX,camY,camZ (" + hit._hitInfo + ";" + hit._weaponInfo + ";" + hit._weaponSlot + ";" + hit.PlayerPos.X + ";" + hit.PlayerPos.Y + ";" + hit.PlayerPos.Z + ")");
                }
                hits.Add(hit);
            }
            return(hits);
        }
Beispiel #10
0
 public ReceiveDeliveryRunnable(BlinkListener listener, ReceivePacket entity, ProgressStatus status, bool isEnd)
 {
     this.listener = listener;
     this.entity   = entity;
     this.status   = status;
     this.isEnd    = isEnd;
 }
Beispiel #11
0
 public void AddReceivePacket(ReceivePacket p)
 {
     lock (recvPool)
     {
         recvPool.Enqueue(p);
     }
 }
Beispiel #12
0
        public static void writeInfo(SendPacket s, ReceivePacket p, bool genLog)
        {
            List <HitData> hits = ReadInfo(p, genLog, true);

            writeInfo(s, hits);
            hits = null;
        }
Beispiel #13
0
        private static Struct BaseReadInfo(ReceivePacket p, bool OnlyBytes, bool genLog)
        {
            Struct info = new Struct
            {
                _weaponInfo    = p.readUH(),
                _weaponSlot    = p.readC(),
                _unk           = p.readUH(),
                _objPos_x      = p.readUH(),
                _objPos_y      = p.readUH(),
                _objPos_z      = p.readUH(),
                _unk5          = p.readUH(),
                _unk6          = p.readUH(),
                _unk7          = p.readUH(),
                _grenadesCount = p.readUH()
            };                       //id do item do mapa

            info._unk8 = p.readB(6); //Null 1.15.37

            /*
             * 1.15.42 - p.readB(6);
             */
            if (!OnlyBytes)
            {
                info.WeaponNumber = (info._weaponInfo >> 6);
                info.WeaponClass  = (info._weaponInfo & 47);
            }
            if (genLog)
            {
                Printf.warning("[code1_GrenadeSync] " + BitConverter.ToString(p.getBuffer()));
                Printf.warning("[code1_GrenadeSync] wInfo: " + info._weaponInfo + "; wSlot: " + info._weaponSlot + "; u: " + info._unk + "; obpX: " + info._objPos_x + "; obpY: " + info._objPos_y + "; obpZ: " + info._objPos_z + "; u5: " + info._unk5 + "; u6: " + info._unk6 + "; u7: " + info._unk7 + "; u8: " + info._unk8);
            }
            return(info);
        }
Beispiel #14
0
        private void Receive(object state)
        {
            while (true)
            {
                var result = _service.Receive();

                var hexStr = Util.ToHex(result.Data);
                hexStr = hexStr.Substring(0, hexStr.LastIndexOf("03 00") + 2);
                //包装到ByteBuffer
                var tempBuf = Util.HexStringToByteArray(hexStr);
                //需要一个基础包
                var receivePacket = new ReceivePacket(tempBuf, _user, null);
                //接收消息后触发事件
                var receiveEvent = new QQEventArgs <ReceivePacket>(_service, _user, receivePacket);
                if (QQGlobal.DebugLog)
                {
                    _service.MessageLog($"接收数据:{Util.ToHex(receiveEvent.ReceivePacket.Buffer)}");
                }

                // 通过Command, 利用反射+Attribute, 分发到管理具体某个包的Command中,最后直接调用Receive方法即可。
                // 将对包的处理移到具体Command中,此处只负责分发。
                var receiveCommand = DispatchPacketToCommand.Of(tempBuf, _service, _transponder, _user)
                                     .dispatch_receive_packet(receivePacket.Command);
                receiveCommand.Process();
            }
        }
Beispiel #15
0
        public ReceivePacket ParseReceive(byte type, long len)
        {
            long          id     = ++mId;
            ReceivePacket packet = null;

            switch (type)
            {
            case BlinkPacket.PacketType.STRING:
                packet = new StringReceivePacket(id, type, len);
                break;

            case BlinkPacket.PacketType.BYTES:
                packet = new ByteReceivePacket(id, type, len);;
                break;

            case BlinkPacket.PacketType.FILE:
                String file = mResource.Create(id);
                if (file != null)
                {
                    packet = new FileReceivePacket(id, type, len, file);
                }
                break;
            }
            return(packet);
        }
        public static void writeInfo(SendPacket s, ReceivePacket p, bool genLog)
        {
            Struct info = readSyncInfo(p, genLog);

            s.writeB(info._unk);
            info = null;
        }
Beispiel #17
0
        private static void LoadPacket(byte[] buffer)
        {
            ReceivePacket p = new ReceivePacket(buffer);

            switch (p.readH())
            {
            case 1:
                RespawnSync.Load(p);
                break;

            case 2:
                RemovePlayerSync.Load(p);
                break;

            case 3:
                uint UniqueRoomId = p.readUD();
                int  gen2         = p.readD();
                int  num          = (int)p.readC();
                Room room         = RoomsManager.getRoom(UniqueRoomId, gen2);
                if (room != null)
                {
                    room._serverRound = num;
                }
                break;
            }
        }
Beispiel #18
0
 public ReceiveDeliveryRunnable(ReceiveListener listener, ReceivePacket entity, float progress, bool isEnd)
 {
     this.listener = listener;
     this.entity   = entity;
     this.progress = progress;
     this.isEnd    = isEnd;
 }
Beispiel #19
0
        /// <summary>
        ///     匹配对应的Command命令
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="packet"></param>
        /// <returns></returns>
        public static P2PCommand FindCommand(P2PTcpClient tcpClient, ReceivePacket packet)
        {
            P2PCommand command = null;

            if (Global.AllowAnonymous.Contains(packet.CommandType) || tcpClient.IsAuth)
            {
                if (Global.CommandDict.ContainsKey(packet.CommandType))
                {
                    Type type = Global.CommandDict[packet.CommandType];
                    command = Activator.CreateInstance(type, tcpClient, packet.GetBytes()) as P2PCommand;
                }
                else
                {
                    LogUtils.Warning($"{tcpClient.RemoteEndPoint}请求了未知命令{packet.CommandType}");
                }
            }
            else
            {
                tcpClient.Close();
                if (tcpClient.ToClient != null && tcpClient.ToClient.Connected)
                {
                    tcpClient.ToClient.Close();
                }
                LogUtils.Warning($"拦截{tcpClient.RemoteEndPoint}未授权命令");
            }
            return(command);
        }
Beispiel #20
0
        public static void writeInfo(SendPacket s, ActionModel ac, ReceivePacket p, bool genLog)
        {
            Struct info = ReadInfo(ac, p, genLog);

            s.writeH(info._unkV);
            info = null;
        }
        /// <summary>
        ///     匹配对应的Command命令
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="packet"></param>
        /// <returns></returns>
        public static P2PCommand FindCommand(P2PTcpClient tcpClient, ReceivePacket packet)
        {
            P2PCommand command   = null;
            AppCenter  appCenter = EasyInject.Get <AppCenter>();

            if (appCenter.AllowAnonymous.Contains(packet.CommandType) || tcpClient.IsAuth)
            {
                if (appCenter.CommandDict.ContainsKey(packet.CommandType))
                {
                    Type type = appCenter.CommandDict[packet.CommandType];
                    command = Activator.CreateInstance(type, tcpClient, packet.Data.Select(t => t).ToArray()) as P2PCommand;
                }
                else
                {
                    LogUtils.Warning($"{tcpClient.RemoteEndPoint}请求了未知命令{packet.CommandType}");
                }
            }
            else
            {
                tcpClient?.SafeClose();
                tcpClient.ToClient?.SafeClose();
                LogUtils.Warning($"拦截{tcpClient.RemoteEndPoint}未授权命令");
            }
            return(command);
        }
        public static List <HitData> ReadInfo(ReceivePacket p, bool genLog)
        {
            List <HitData> hits  = new List <HitData>();
            int            count = p.readC();

            for (int k = 0; k < count; k++)
            {
                HitData hit = new HitData
                {
                    _hitInfo    = p.readUD(),
                    _weaponInfo = p.readUH(),
                    _weaponSlot = p.readC(),
                    _unk        = p.readUH(),
                    _eixoX      = p.readUH(),
                    _eixoY      = p.readUH(),
                    _eixoZ      = p.readUH()
                };
                if (genLog)
                {
                    Printf.warning("P: " + hit._eixoX + ";" + hit._eixoY + ";" + hit._eixoZ);
                    Printf.warning("[" + k + "] 16384: " + BitConverter.ToString(p.getBuffer()));
                }
                hits.Add(hit);
            }
            return(hits);
        }
        /// <summary>
        /// Escreve os dados para envio.
        /// <para>Retorna True em caso de não uso do evento 64.</para>
        /// <para>Retorna False caso a ação 64 seja usada.</para>
        /// </summary>
        /// <param name="s"></param>
        /// <param name="ac"></param>
        /// <param name="p"></param>
        /// <param name="genLog"></param>
        /// <returns></returns>
        public static void writeInfo(SendPacket s, ActionModel ac, ReceivePacket p, bool genLog)
        {
            Struct info = ReadInfo(ac, p, genLog, true);

            writeInfo(s, info);
            info = null;
        }
Beispiel #24
0
        public static void Load(ReceivePacket p)
        {
            uint UniqueRoomId = p.readUD();
            int  gen2         = p.readD();
            int  slot         = (int)p.readC();
            int  num          = (int)p.readC();
            Room room         = RoomsManager.getRoom(UniqueRoomId, gen2);

            if (room == null)
            {
                return;
            }
            if (num == 0)
            {
                RoomsManager.RemoveRoom(UniqueRoomId);
            }
            else
            {
                Player player = room.getPlayer(slot, false);
                if (player != null)
                {
                    player.ResetAllInfos();
                }
            }
        }
Beispiel #25
0
        private static List <a200_SuicideDamage.HitData> BaseReadInfo(ReceivePacket p, bool OnlyBytes, bool genLog)
        {
            List <a200_SuicideDamage.HitData> hitDataList = new List <a200_SuicideDamage.HitData>();
            int num = (int)p.readC();

            for (int index = 0; index < num; ++index)
            {
                a200_SuicideDamage.HitData hitData = new a200_SuicideDamage.HitData()
                {
                    _hitInfo    = p.readUD(),
                    _weaponInfo = p.readUH(),
                    _weaponSlot = p.readC(),
                    PlayerPos   = p.readUHVector()
                };
                if (!OnlyBytes)
                {
                    hitData.WeaponClass = (ClassType)((int)hitData._weaponInfo & 63);
                    hitData.WeaponId    = (int)hitData._weaponInfo >> 6;
                }
                if (genLog)
                {
                    Logger.warning("[" + (object)index + "] Committed suicide: hitinfo,weaponinfo,weaponslot,camX,camY,camZ (" + (object)hitData._hitInfo + ";" + (object)hitData._weaponInfo + ";" + (object)hitData._weaponSlot + ";" + (object)hitData.PlayerPos.X + ";" + (object)hitData.PlayerPos.Y + ";" + (object)hitData.PlayerPos.Z + ")", false);
                }
                hitDataList.Add(hitData);
            }
            return(hitDataList);
        }
Beispiel #26
0
        public static void writeInfo(SendPacket s, ReceivePacket p, bool genLog)
        {
            Struct info = ReadInfo(p, genLog);

            s.writeH(info.Life);
            s.writeC(info.DestroyedBySlot);
            info = null;
        }
        public static void writeInfo(SendPacket s, ActionModel ac, ReceivePacket p, bool genLog)
        {
            Struct info = readSyncInfo(ac, p, genLog);

            s.writeC(info._radioId);
            s.writeC(info._areaId);
            info = null;
        }
Beispiel #28
0
        public static void writeInfo(SendPacket s, ReceivePacket p, bool genLog)
        {
            Struct info = ReadInfo(p, genLog);

            s.writeC((byte)info.state);
            s.writeB(info._unk);
            info = null;
        }
Beispiel #29
0
 public static void writeInfo(SendPacket s, ReceivePacket p, bool genLog)
 {
     code6_ObjectAnim.Struct @struct = code6_ObjectAnim.ReadInfo(p, genLog);
     s.writeH(@struct._life);
     s.writeC(@struct._anim1);
     s.writeC(@struct._anim2);
     s.writeT(@struct._syncDate);
 }
Beispiel #30
0
        public void PostReceiveProgress(ReceivePacket entity, float progress)
        {
            ReceiveListener listener = mReceiveListener;

            if (listener != null)
            {
                PostBlink(new ReceiveDeliveryRunnable(listener, entity, progress, false));
            }
        }