/// <summary> /// Handles 'command' events of the Fabric layer. /// </summary> /// <param name="server">The server which is sending the command.</param> /// <param name="packet">The packet containing the data.</param> /// <returns>The processing state of the event.</returns> internal ProcessingState OnEvent(IServer server, MeshEvent packet) { int count = this.Registry.RawCount; for (int i = 0; i < count; ++i) { if (this.Registry.HasElementAt(i)) { var handler = this.Registry.Get(i); var result = handler.ProcessEvent(server, packet); if (result == ProcessingState.Failure) { continue; } // On anything else, we're done here // We might as well release the packet to reduce memory pressure if (packet.Lifetime == PacketLifetime.Automatic) { packet.TryRelease(); } return(result); } } // We failed processing return(ProcessingState.Failure); }
/// <summary> /// Handles the custom commands, JSON-encoded. /// </summary> /// <param name="server">The server sending the command.</param> /// <param name="packet">The event payload.</param> /// <returns>The processing state of the event.</returns> public ProcessingState ProcessEvent(IServer server, MeshEvent packet) { // Must be emitter event var ev = packet as MeshEmitterEvent; if (ev == null) { return(ProcessingState.Failure); } Service.Logger.Log("Event: " + ev + " from " + server.EndPoint); switch (ev.Type) { // Handles subscribe event case MeshEventType.Subscribe: Subscription.Register(server, ev.Contract, ev.Channel); return(ProcessingState.Success); // Handles unsubscribe event case MeshEventType.Unsubscribe: Subscription.Unregister(server, ev.Contract, ev.Channel); return(ProcessingState.Success); default: Service.Logger.Log(LogLevel.Info, "Unknown event: " + packet); return(ProcessingState.Failure); } }