Exemplo n.º 1
0
        public static void Identify(IClient client, CodedInputStream stream)
        {
            var header = new Header(stream);
            var payload = new byte[header.PayloadLength];
            payload = stream.ReadRawBytes((int)header.PayloadLength);

            var packet = new Packet(header, payload);
            var service = Service.GetByID(header.ServiceID);

            if (service == null)
            {
                Logger.Error("No service exists with id: 0x{0}", header.ServiceID.ToString("X2"));
                return;
            }

            var method = service.DescriptorForType.Methods[(int)header.MethodID - 1];
            var proto = service.GetRequestPrototype(method);
            var builder = proto.WeakCreateBuilderForType();

            try
            {
                var message = builder.WeakMergeFrom(CodedInputStream.CreateInstance(packet.Payload.ToArray())).WeakBuild();

                ((IServerService) service).Client = client;
                service.CallMethod(method, null, message, (msg => SendResponse(client, header.RequestID, msg)));
            }
            catch (NotImplementedException)
            {
                Logger.Debug(string.Format("Unimplemented service method: {0} {1}", service.GetType().Name, method.Name));
            }
            catch(Exception e)
            {
                Logger.DebugException(e,string.Empty);
            }
        }
Exemplo n.º 2
0
        public static int Identify(IClient client, CodedInputStream stream)
        {
            var header = new Header(stream);
            var payload = new byte[header.PayloadLength];
            payload = stream.ReadRawBytes((int)header.PayloadLength);
            
            var packet = new Packet(header, payload);
            var service = ServiceManager.GetServerServiceByID(header.ServiceID);

            if(service!=null)
            {
                service.CallMethod(header.MethodID, client, packet);
                return packet.Length;
            }

            Console.WriteLine("\n===========[Unknown Crap]===========\nHeader\t: {0}Payload\t: {1}", header.Data.Dump(), payload.Dump());
            return 0;
        }
Exemplo n.º 3
0
        public static int Identify(IClient client, byte[] buffer)
        {
            var header = new Header(buffer.Take(6));
            var payload = new byte[header.PayloadLength];
            // if our packet contains a payload, get it.
            if (header.PayloadLength > 0)
                Array.Copy(buffer, 6, payload, 0, header.PayloadLength);


            var packet = new Packet(header, payload);
            var service = ServiceManager.GetServerServiceByID(header.ServiceID);

            if(service!=null)
            {
                service.CallMethod(header.MethodID, client, packet);
                return packet.Lenght;
            }

            Console.WriteLine("\n===========[Unknown Crap]===========\nHeader\t: {0}Payload\t: {1}", header.Data.Dump(), payload.Dump());
            return 0;
        }
Exemplo n.º 4
0
 public Packet(Header header, byte[] payload)
 {
     this.Header = header;
     this.Payload = payload;
 }