/// <summary> /// Dispatches a recieved packet. Each game implementation needs to supply its own dispatch /// method as the protocol may be very different and have additional requirements beyond a /// simple text match. /// </summary> /// <param name="identifer"></param> /// <param name="request"></param> /// <param name="response"></param> public virtual void Dispatch(IPacketDispatch identifer, IPacketWrapper request, IPacketWrapper response) { var dispatchMethods = this.Handlers.Where(dispatcher => dispatcher.Key.Name == identifer.Name) .Where(dispatcher => dispatcher.Key.Origin == PacketOrigin.None || dispatcher.Key.Origin == identifer.Origin) .Select(dispatcher => dispatcher.Value) .ToList(); if (dispatchMethods.Any()) { foreach (Action<IPacketWrapper, IPacketWrapper> handler in dispatchMethods) { handler(request, response); } } else { this.MissingDispatch(identifer, request, response); } }
/// <summary> /// Called when dispatching, but no method matches the exact identifier used. /// </summary> /// <param name="identifier"></param> /// <param name="request"></param> /// <param name="response"></param> public virtual void MissingDispatch(IPacketDispatch identifier, IPacketWrapper request, IPacketWrapper response) { if (this.MissingDispatchHandler != null) { this.MissingDispatchHandler(identifier, request, response); } }