示例#1
0
        public void QueueResponse(RPCContext context, IProtoBuf message)
        {
            if (message == null || context.Header == null)
            {
                this.m_logSource.LogError("QueueResponse: invalid response");
                return;
            }
            if (this.serviceHelper.GetImportedServiceById(context.Header.ServiceId) == null)
            {
                this.m_logSource.LogError("QueueResponse: error, unrecognized service id: " + context.Header.ServiceId);
                return;
            }
            this.m_logSource.LogDebug(string.Concat(new object[]
            {
                "QueueResponse: type=",
                this.serviceHelper.GetImportedServiceById(context.Header.ServiceId).GetMethodName(context.Header.MethodId),
                " data=",
                message
            }));
            Header header = context.Header;

            header.SetServiceId(254u);
            header.SetMethodId(0u);
            header.SetSize(message.GetSerializedSize());
            context.Header = header;
            BattleNetPacket packet = new BattleNetPacket(context.Header, message);

            this.QueuePacket(packet);
        }
 public static byte[] ToByteArray(IProtoBuf protobuf)
 {
     unsafe
     {
         byte[] numArray = new byte[protobuf.GetSerializedSize()];
         protobuf.Serialize(new MemoryStream(numArray));
         return(numArray);
     }
 }
示例#3
0
    public static byte[] ToByteArray(IProtoBuf protobuf)
    {
        uint serializedSize = protobuf.GetSerializedSize();

        byte[]       array  = new byte[serializedSize];
        MemoryStream stream = new MemoryStream(array);

        protobuf.Serialize(stream);
        return(array);
    }
 public override byte[] Encode()
 {
     if (this.Body is IProtoBuf)
     {
         IProtoBuf body = (IProtoBuf)this.Body;
         this.Size = (int)body.GetSerializedSize();
         byte[] destinationArray = new byte[(this.Size + 4) + 4];
         Array.Copy(BitConverter.GetBytes(this.Type), 0, destinationArray, 0, 4);
         Array.Copy(BitConverter.GetBytes(this.Size), 0, destinationArray, 4, 4);
         body.Serialize(new MemoryStream(destinationArray, 8, this.Size));
         return(destinationArray);
     }
     return(null);
 }
示例#5
0
        public override byte[] Encode()
        {
            if (!(this.body is IProtoBuf))
            {
                return(null);
            }
            IProtoBuf protoBuf        = (IProtoBuf)this.body;
            int       serializedSize  = (int)this.header.GetSerializedSize();
            int       serializedSize2 = (int)protoBuf.GetSerializedSize();

            byte[] array = new byte[2 + serializedSize + serializedSize2];
            array[0] = (byte)(serializedSize >> 8 & 255);
            array[1] = (byte)(serializedSize & 255);
            this.header.Serialize(new MemoryStream(array, 2, serializedSize));
            protoBuf.Serialize(new MemoryStream(array, 2 + serializedSize, serializedSize2));
            return(array);
        }
示例#6
0
    public override byte[] Encode()
    {
        if (!(this.body is IProtoBuf))
        {
            return(null);
        }
        IProtoBuf body           = (IProtoBuf)this.body;
        int       serializedSize = (int)this.header.GetSerializedSize();
        int       count          = (int)body.GetSerializedSize();

        byte[] buffer = new byte[(2 + serializedSize) + count];
        buffer[0] = (byte)((serializedSize >> 8) & 0xff);
        buffer[1] = (byte)(serializedSize & 0xff);
        this.header.Serialize(new MemoryStream(buffer, 2, serializedSize));
        body.Serialize(new MemoryStream(buffer, 2 + serializedSize, count));
        return(buffer);
    }
示例#7
0
    public RPCContext QueueRequest(uint serviceId, uint methodId, IProtoBuf message, RPCContextDelegate callback = null, uint objectId = 0)
    {
        uint nextToken;

        if (message == null)
        {
            return(null);
        }
        object tokenLock = this.tokenLock;

        lock (tokenLock)
        {
            nextToken = RPCConnection.nextToken;
            RPCConnection.nextToken++;
        }
        RPCContext context = new RPCContext();

        if (callback != null)
        {
            context.Callback = callback;
            this.waitingForResponse.Add(nextToken, context);
        }
        bnet.protocol.Header h    = this.CreateHeader(serviceId, methodId, objectId, nextToken, message.GetSerializedSize());
        BattleNetPacket      item = new BattleNetPacket(h, message);

        context.Header  = h;
        context.Request = message;
        if (!this.m_connMetering.AllowRPCCall(serviceId, methodId))
        {
            this.m_pendingOutboundPackets.Add(item);
            this.LogOutgoingPacket(item, true);
            return(context);
        }
        this.QueuePacket(item);
        return(context);
    }
示例#8
0
        public RPCContext QueueRequest(uint serviceId, uint methodId, IProtoBuf message, RPCContextDelegate callback = null, uint objectId = 0u)
        {
            if (message == null)
            {
                return(null);
            }
            object obj = this.tokenLock;
            uint   num;

            lock (obj)
            {
                num = RPCConnection.nextToken;
                RPCConnection.nextToken += 1u;
            }
            RPCContext rPCContext = new RPCContext();

            if (callback != null)
            {
                rPCContext.Callback = callback;
                this.waitingForResponse.Add(num, rPCContext);
            }
            Header          header          = this.CreateHeader(serviceId, methodId, objectId, num, message.GetSerializedSize());
            BattleNetPacket battleNetPacket = new BattleNetPacket(header, message);

            rPCContext.Header  = header;
            rPCContext.Request = message;
            if (!this.m_connMetering.AllowRPCCall(serviceId, methodId))
            {
                this.m_pendingOutboundPackets.Add(battleNetPacket);
                this.LogOutgoingPacket(battleNetPacket, true);
            }
            else
            {
                this.QueuePacket(battleNetPacket);
            }
            return(rPCContext);
        }