public static void Identify(LogNetClient client) { var packet = new PacketIn(client, client.IncomingLogNetStream.GetPacketHeader()); if (packet.Header.ServiceId == ServiceReply) { ProcessReply(client, packet); } else { ProcessMessage(client, packet); } }
private static void ProcessReply(LogNetClient client, PacketIn packet) { if (client.RPCCallbacks.ContainsKey(packet.Header.Token)) { var callback = client.RPCCallbacks[packet.Header.Token]; Logger.Trace("RPCReply => {0}", callback.Action.Target); callback.Action(packet.ReadMessage(callback.Builder)); client.RPCCallbacks.Remove(packet.Header.Token); } else { Logger.Warn("RPC callback contains unexpected token: {0}", packet.Header.Token); client.Connection.Disconnect(); } }
private static void ProcessMessage(LogNetClient client, PacketIn packet) { var service = Service.GetByID(packet.Header.ServiceId); if (service == null) { Logger.Error("No service exists with id: 0x{0}", packet.Header.ServiceId.ToString("X2")); return; } var method = service.DescriptorForType.Methods.Single(m => GetMethodId(m) == packet.Header.MethodId); var proto = service.GetRequestPrototype(method); var builder = proto.WeakCreateBuilderForType(); var message = packet.ReadMessage(builder); Logger.LogIncomingPacket(message, packet.Header); try { lock (service) // lock the service so that its in-context client does not get changed.. { ((IServerService)service).Client = client; ((IServerService)service).LastCallHeader = packet.Header; ((IServerService)service).Status = 0; service.CallMethod(method, null, message, (msg => SendRPCResponse(client.Connection, packet.Header.Token, msg, ((IServerService)service).Status))); } } catch (NotImplementedException) { Logger.Warn("Unimplemented service method: {0}.{1}", service.GetType().Name, method.Name); } catch (UninitializedMessageException e) { Logger.Debug("Failed to parse message: {0}", e.Message); } catch (Exception e) { Logger.DebugException(e, string.Empty); } }