Exemplo n.º 1
0
        private void IdentifiedClient_OnNewMessage(Message message, string sender)
        {
            Debug.Print("Message {0} - sender {1}", message, sender);

            _moduleProvider.Dispatch(m => m.Handle(message, sender));

            m_form.AddMessageToListView(message, sender);
        }
Exemplo n.º 2
0
 public void Send(IdentifiedClient dest, Message message)
 {
     /*message = new CharacterNameSuggestionRequestMessage();
      * var src = dest == m_player ? m_server : m_player;
      *
      * using (var writer = new BigEndianStream.BigEndianWriter())
      * {
      *  // We need to create all the packet layers.
      *
      *  // LinkLayer -> Ethernet
      *  var ethernetLayer = new EthernetLayer()
      *                          {
      *                              Source = src.Mac,
      *                              Destination = dest.Mac
      *                          };
      *
      *  // InternetLayer -> IPv4
      *  src.Ipv4Id += 2;
      *  var ipv4Layer = new IpV4Layer()
      *                      {
      *                          Source = src.Ip,
      *                          Destination = dest.Ip,
      *                          Ttl = 128,
      *                          Identification = src.Ipv4Id
      *                      };
      *
      *  // TransportLayer -> TCP
      *  var tcpLayer = new TcpLayer()
      *                     {
      *                         SourcePort = src.Port,
      *                         DestinationPort = dest.Port,
      *                         SequenceNumber = src.TcpId,
      *                         AcknowledgmentNumber = src.AckId,
      *                         ControlBits = TcpControlBits.Push | TcpControlBits.Acknowledgment,
      *                         Window = 4140
      *                     };
      *
      *  //Write Message in Buffer
      *  message.Pack(writer);
      *
      *  // PayloadLayer
      *  var payloadLayer = new PayloadLayer()
      *                         {
      *                             Data = new Datagram(writer.Data)
      *                         };
      *
      *  // Build Packet
      *  var builder = new PacketBuilder(ethernetLayer, ipv4Layer, tcpLayer, payloadLayer);
      *  var packet = builder.Build(DateTime.Now);
      *
      *  //Add to Sended
      *  dest.Sended.Add(src.AckId);
      *
      *  m_communicator.SendPacket(packet);
      * }*/
 }
Exemplo n.º 3
0
 public override void Dispatch(WorldClient client, Stump.DofusProtocol.Messages.Message message)
 {
     if (message is BasicPingMessage)
     {
         client.Send(new BasicPongMessage((message as BasicPingMessage).quiet));
     }
     else
     {
         List <MessageHandler> Handlers;
         if (this.m_handlers.TryGetValue(message.MessageId, out Handlers))
         {
             if (!Handlers.Any(entry => entry.Container.CanHandleMessage(client, message.MessageId)))
             {
                 this.m_logger.Warn(string.Concat(new object[]
                 {
                     client,
                     " tried to send ",
                     message,
                     " but predicate didn't success"
                 }));
             }
             else
             {
                 IContextHandler contextHandler = this.GetContextHandler(Handlers.First().Attribute, client, message);
                 if (contextHandler != null)
                 {
                     foreach (var handler in Handlers)
                     {
                         contextHandler.AddMessage(new HandledMessage <WorldClient>(handler.Action, client, message));
                     }
                 }
             }
         }
         else
         {
             this.m_logger.Debug("Received Unknown packet : " + message);
         }
     }
 }
Exemplo n.º 4
0
        public IContextHandler GetContextHandler(WorldHandlerAttribute attr, WorldClient client, Stump.DofusProtocol.Messages.Message message)
        {
            IContextHandler result;

            if (!attr.IsGamePacket)
            {
                result = ServerBase <WorldServer> .Instance.IOTaskPool;
            }
            else
            {
                if (client.Character == null || client.Account == null)
                {
                    this.m_logger.Warn <WorldClient, Stump.DofusProtocol.Messages.Message>("Client {0} sent {1} before being logged", client, message);
                    client.Disconnect();
                    result = null;
                }
                else
                {
                    if (client.Character.Area == null)
                    {
                        this.m_logger.Warn <WorldClient, Stump.DofusProtocol.Messages.Message>("Client {0} sent {1} while not in world", client, message);
                        client.Disconnect();
                        result = null;
                    }
                    else
                    {
                        result = client.Character.Area;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        public IContextHandler GetContextHandler(WorldHandlerAttribute attr, WorldClient client, Message message)
        {
            if (!attr.IsGamePacket)
            {
                return(WorldServer.Instance.IOTaskPool);
            }

            if (client.Character == null || client.Account == null)
            {
                m_logger.Warn("Client {0} sent {1} before being logged", client, message);
                client.Disconnect();
                return(null);
            }

            if (client.Character.Area != null)
            {
                return(client.Character.Area);
            }

            m_logger.Warn("Client {0} sent {1} while not in world", client, message);
            client.Disconnect();
            return(null);
        }
Exemplo n.º 6
0
        public override void Dispatch(WorldClient client, Message message)
        {
            if (message is BasicPingMessage) // pong immediately
            {
                client.Send(new BasicPongMessage((message as BasicPingMessage).quiet));
                return;
            }


            List <MessageHandler> handlers;

            if (m_handlers.TryGetValue(message.MessageId, out handlers))
            {
                foreach (var handler in handlers)
                {
                    if (!handler.Container.CanHandleMessage(client, message.MessageId))
                    {
                        m_logger.Warn(client + " tried to send " + message + " but predicate didn't success");
                        return;
                    }

                    if (client.Character == null && handler.Attribute.ShouldBeLogged)
                    {
                        if (handler.Attribute.IgnorePredicate)
                        {
                            continue;
                        }

                        m_logger.Warn(
                            "Handler id = {0} cannot handle this message because the client {1} is not logged and should be",
                            message, client);
                        client.Disconnect();
                        break;
                    }

                    if (client.Character != null && !handler.Attribute.ShouldBeLogged)
                    {
                        if (handler.Attribute.IgnorePredicate)
                        {
                            continue;
                        }

                        m_logger.Warn(
                            "Handler id = {0} cannot handle this message because the client {1} is already logged and should be not",
                            message, client);
                        client.Disconnect();
                        break;
                    }

                    var context = GetContextHandler(handler.Attribute, client, message);
                    if (context != null)
                    {
                        if (!context.IsRunning)
                        {
                            context.Start();
                        }

                        context.AddMessage(new HandledMessage <WorldClient>(handler.Action, client, message));
                    }
                }
            }
            else
            {
                m_logger.Debug("Received Unknown packet : " + message);
            }
        }
 public HandledMessage(Action <object, T, Stump.DofusProtocol.Messages.Message> callback, T client, Stump.DofusProtocol.Messages.Message message) : base(null, client, message, callback)
 {
 }