Ejemplo n.º 1
0
 private void checkIfMsgTypeExists(GameMessage msg)
 {
     if (_messageTypes.All(t => t.Name != msg.GetType().Name))
     {
         throw new MissingMessageException($"Message '{msg.GetType().Name}' was not found.");
     }
 }
Ejemplo n.º 2
0
        private Type getActionFromMessage(GameMessage msg)
        {
            var expectedActionName = msg.GetType().Name.Replace("Message", "Action");
            var actionType         = _actionTypes.FirstOrDefault(t => t.Name == expectedActionName);

            if (actionType == null)
            {
                throw new MissingActionException($"Action for Message {msg.GetType().Name} was not found. I tried '{expectedActionName}' with no luck.");
            }

            return(actionType);
        }
Ejemplo n.º 3
0
 public MessageNode(GameMessage message, int start, int end)
 {
     this.gameMessage = message;
     this.mStart = start;
     this.mEnd = end;
     Text = String.Join(".", (message.GetType().ToString().Split('.').Skip(5)));
 }
Ejemplo n.º 4
0
    public static void dispatch(GameMessage msg)
    {
        List <Action <GameMessage> > ls = MessageManager.getLs(msg.GetType());

        foreach (Action <GameMessage> current in ls)
        {
            current(msg);
        }
    }
Ejemplo n.º 5
0
 public static void SendMessage(GameMessage message, Socket socketClient)
 {
     try
     {
         socketClient.Send(messageSerializer.Serialize(message, message.GetType(),
                                                       new Type[] { typeof(Player) }));
     }
     catch
     {
     }
 }
Ejemplo n.º 6
0
 public bool SendMessage(GameMessage message)
 {
     byte[] buffer = messageSerializer.Serialize(message, message.GetType());
     try
     {
         socketServerHandler.Send(buffer);
     }
     catch
     {
         Disconnect();
     }
     return(true);
 }
Ejemplo n.º 7
0
        private void OnGameEngineMessage(GameMessage message)
        {
            message = BeforeMessageProcessing(message);
            var eventData = ProtobufSerializerUtil.Serialize(message);
            var data      = new Dictionary <byte, object>()
            {
                { 245, eventData }, { 245, 0 }
            };

            // Broadcast the message to the client, the event code will be similar to the message code
            if (!_isEndGame || message.GetType() == typeof(MessageGameResult))
            {
                BroadcastEvent((byte)message.Code, data);
            }
        }
Ejemplo n.º 8
0
        public async Task ProcessMessage(GameMessage message)
        {
            Type type = message.GetType();

            if (!handlers.ContainsKey(type))
            {
                this.logger.LogInformation($"GameActionMessageHandler message type not recognised");
                return;
            }

            Func <GameMessage, Task> handler = handlers[type];

            await handler(message);

            this.logger.LogInformation($"GameActionMessage Processed: {message}");
        }
Ejemplo n.º 9
0
 public void Log(GameMessage msg, Common.SchemaWrapper.Player p)
 {
     if (gameEnded)
     {
         return;
     }
     string[] s =
     {
         msg.GetType().ToString().Split('.').Last(),
         DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff"),
         msg.gameId.ToString(),
         p.Id.ToString(),
         msg.playerGuid,
         p.Team.Color.ToString(),
         p.Team.Leader?.Guid == msg.playerGuid ? "leader" : "member"
     };
     Log(s);
 }
Ejemplo n.º 10
0
 public MessageNode(GameMessage message)
 {
     this.gameMessage = message;
     Text = String.Join(".", (message.GetType().ToString().Split('.').Skip(5)));
 }
Ejemplo n.º 11
0
        public bool Parse()
        {
            //allNodes.Clear();

            while (Buffer.IsPacketAvailable())
            {
                int end = Buffer.Position;
                end += Buffer.ReadInt(32) * 8;
                if (end < Buffer.Position)
                {
                    break;
                }

                while ((end - Buffer.Position) >= 9)
                {
                    int start = Buffer.Position;

                    #region Try parsing a message
                    try
                    {
                        GameMessage message = Buffer.ParseMessage();
                        if (message != null)
                        {
                            if (message is ACDEnterKnownMessage)
                            {
                                String hex = (message as ACDEnterKnownMessage).ActorID.ToString("X8");
                                //string name;
                                //SNOAliases.Aliases.TryGetValue((message as ACDEnterKnownMessage).ActorSNOId.ToString(), out name);
                                string name = SNOAliases.GetAlias((message as ACDEnterKnownMessage).ActorSNOId);
                                if (!actors.ContainsKey(hex))
                                {
                                    TreeNode actorNode = new TreeNode(hex + "  " + name);
                                    actors.Add(hex, actorNode);
                                    actorMap.Add((message as ACDEnterKnownMessage).ActorID, actorNode);
                                    actorNode.Tag = hex;
                                }
                            }

                            if (message is QuestUpdateMessage)
                            {
                                string name = SNOAliases.GetAlias((message as QuestUpdateMessage).snoQuest);
                                //SNOAliases.Aliases.TryGetValue(.ToString(), out name);
                                if (!quests.ContainsKey((message as QuestUpdateMessage).snoQuest.ToString("X8")))
                                {
                                    TreeNode questNode = new TreeNode(name);
                                    questNode.Tag = (message as QuestUpdateMessage).snoQuest.ToString("X8");
                                    quests.Add(questNode.Tag.ToString(), questNode);
                                }
                            }

                            MessageNode node = new MessageNode(message);
                            allNodes.Add(node);

                            /// THIS IS FOR QUICKER PARSING BUT IM TOO LAZY TO DO THAT FOR ALL MESSAGES
                            #region quickparse

                            // skip messages without actor or quest id
                            if (message is GameTickMessage ||
                                message is SNODataMessage ||
                                message is SNONameDataMessage ||
                                message is SimpleMessage ||
                                message is RevealSceneMessage ||
                                message is DestroySceneMessage ||
                                message is MapRevealSceneMessage
                                )
                            {
                                continue;
                            }

                            try
                            {
                                if (gg.ContainsKey(message.GetType()))
                                {
                                    gg[message.GetType()]++;
                                }
                                else
                                {
                                    gg.Add(message.GetType(), 1);
                                }

                                if (message is ANNDataMessage)
                                {
                                    if (actorMap.ContainsKey((uint)(message as ANNDataMessage).ActorID))
                                    {
                                        actorMap[(uint)(message as ANNDataMessage).ActorID].Nodes.Add(node.Clone());
                                    }
                                    continue;
                                }
                                if (message is ACDTranslateFacingMessage)
                                {
                                    actorMap[(uint)(message as ACDTranslateFacingMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }

                                if (message is AttributeSetValueMessage)
                                {
                                    var msg = message as AttributeSetValueMessage;
                                    actorMap[(uint)(message as AttributeSetValueMessage).ActorID].Nodes.Add(node.Clone());

                                    if (msg.Field1.Attribute != GameAttribute.Attached_To_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Attachment_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Banner_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Follow_Target_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Forced_Enemy_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Gizmo_Operator_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Guard_Object_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Item_Bound_To_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Last_Damage_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Last_ACD_Attacked &&
                                        msg.Field1.Attribute != GameAttribute.Last_ACD_Attacked_By &&
                                        msg.Field1.Attribute != GameAttribute.Attached_To_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Last_Blocked_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Loading_Player_ACD &&
                                        msg.Field1.Attribute != GameAttribute.RootTargetACD &&
                                        msg.Field1.Attribute != GameAttribute.Script_Target_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Spawned_by_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Summoned_By_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Taunt_Target_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Wizard_Slowtime_Proxy_ACD)
                                    {
                                        //actorMap[(uint)(message as AttributeSetValueMessage).Field1.Int].Nodes.Add(node.Clone());
                                        continue;
                                    }
                                }

                                if (message is NotifyActorMovementMessage)
                                {
                                    actorMap[(uint)(message as NotifyActorMovementMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is PlayerMovementMessage)
                                {
                                    // If the client sends a PlayerMoveMessage, but the actor is not yet in the
                                    // actor list, its due to a broken cap that starts too late...add the node for speed (and grouping)
                                    if (!actorMap.ContainsKey((uint)(message as PlayerMovementMessage).ActorId))
                                    {
                                        String hex = (message as PlayerMovementMessage).ActorId.ToString("X8");

                                        if (!actors.ContainsKey(hex))
                                        {
                                            TreeNode actorNode = new TreeNode(hex + " Capper");
                                            actorMap.Add((uint)(message as PlayerMovementMessage).ActorId, actorNode);
                                            actorNode.Tag = hex;
                                            actors.Add(hex, actorNode);
                                        }
                                    }

                                    actorMap[(uint)(message as PlayerMovementMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }

                                if (message is ACDGroupMessage)
                                {
                                    actorMap[(uint)(message as ACDGroupMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDCollFlagsMessage)
                                {
                                    actorMap[(uint)(message as ACDCollFlagsMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is AffixMessage)
                                {
                                    actorMap[(uint)(message as AffixMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is TrickleMessage)
                                {
                                    if (actorMap.ContainsKey((uint)(message as TrickleMessage).ActorId))
                                    {
                                        actorMap[(uint)(message as TrickleMessage).ActorId].Nodes.Add(node.Clone());
                                    }
                                    continue;
                                }
                                if (message is ACDEnterKnownMessage)
                                {
                                    actorMap[(uint)(message as ACDEnterKnownMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDCreateActorMessage)
                                {
                                    actorMap[(uint)(message as ACDCreateActorMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDDestroyActorMessage)
                                {
                                    actorMap[(uint)(message as ACDDestroyActorMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDTranslateFixedMessage)
                                {
                                    actorMap[(uint)(message as ACDTranslateFixedMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is AttributesSetValuesMessage)
                                {
                                    actorMap[(uint)(message as AttributesSetValuesMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is SetIdleAnimationMessage)
                                {
                                    actorMap[(uint)(message as SetIdleAnimationMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDWorldPositionMessage)
                                {
                                    actorMap[(uint)(message as ACDWorldPositionMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is PlayEffectMessage)
                                {
                                    actorMap[(uint)(message as PlayEffectMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is PlayAnimationMessage)
                                {
                                    actorMap[(uint)(message as PlayAnimationMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is FloatingNumberMessage)
                                {
                                    actorMap[(uint)(message as FloatingNumberMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDTranslateSyncMessage)
                                {
                                    actorMap[(uint)(message as ACDTranslateSyncMessage).Field0].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDTranslateDetPathMessage)
                                {
                                    actorMap[(uint)(message as ACDTranslateDetPathMessage).Field0].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is PlayHitEffectMessage)
                                {
                                    actorMap[(uint)(message as PlayHitEffectMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is AimTargetMessage)
                                {
                                    actorMap[(uint)(message as AimTargetMessage).Field0].Nodes.Add(node.Clone());
                                    if ((message as AimTargetMessage).Field2 != -1)
                                    {
                                        actorMap[(uint)(message as AimTargetMessage).Field2].Nodes.Add(node.Clone());
                                    }
                                    continue;
                                }
                                if (message is TargetMessage)
                                {
                                    if ((message as TargetMessage).TargetID != 0xFFFFFFFF)
                                    {
                                        actorMap[(uint)(message as TargetMessage).TargetID].Nodes.Add(node.Clone());
                                    }
                                    continue;
                                }
                            }
                            catch (Exception) {}

                            #endregion

                            // Bruteforce find actor ID and add to actor tree
                            string text = message.AsText();
                            foreach (TreeNode an in actors.Values)
                            {
                                if (text.Contains((string)an.Tag))
                                {
                                    MessageNode nodeb = node.Clone();
                                    nodeb.BackColor = this.BackColor;
                                    an.Nodes.Add(nodeb);
                                }
                            }

                            // Bruteforce find quest SNO and add to quest tree
                            foreach (TreeNode qn in quests.Values)
                            {
                                if (text.Contains(qn.Tag.ToString()))
                                {
                                    MessageNode nodeb = node.Clone();
                                    nodeb.BackColor = this.BackColor;
                                    qn.Nodes.Add(nodeb);
                                }
                            }
                        }
                        else
                        {
                            int pos = Buffer.Position;
                            Buffer.Position = start;
                            ErrorNode errorNode = new ErrorNode(String.Format("No message handler found for message id {0}", (Opcodes)Buffer.ReadInt(9)), "");
                            errorNode.BackColor = Color.Pink;
                            allNodes.Add(errorNode);
                            Buffer.Position = pos;
                        }
                    }

                    catch (Exception e)
                    {
                        int pos = Buffer.Position;
                        Buffer.Position = start;
                        ErrorNode errorNode = new ErrorNode(String.Format("Error parsing messsage {0}", (Opcodes)Buffer.ReadInt(9)), e.Message);
                        errorNode.BackColor = Color.Pink;
                        allNodes.Add(errorNode);
                        Buffer.Position = pos;
                    }
                    #endregion
                }

                Buffer.Position = end;
            }

            return(Buffer.Position != Buffer.Length);
        }
Ejemplo n.º 12
0
        public void Parse(ConnectionDataEventArgs e)
        {
            //Console.WriteLine(e.Data.Dump());

            _incomingBuffer.AppendData(e.Data.ToArray());

            while (_incomingBuffer.IsPacketAvailable())
            {
                int end = _incomingBuffer.Position;
                end += _incomingBuffer.ReadInt(32) * 8;

                while ((end - _incomingBuffer.Position) >= 9)
                {
                    try
                    {
                        GameMessage message = _incomingBuffer.ParseMessage();
                        if (message == null)
                        {
                            continue;
                        }

                        if (message.Consumer != Consumers.None)
                        {
                            this.Universe.Route(this, message);
                        }
                        else if (message is ISelfHandler)
                        {
                            (message as ISelfHandler).Handle(this);                               // if message is able to handle itself, let it do so.
                        }
                        else
                        {
                            Logger.Warn("Got an incoming message that has no consumer or self-handler " + message.GetType());
                        }

                        //Logger.LogIncoming(msg);
                    }
                    catch (NotImplementedException)
                    {
                        //Logger.Debug("Unhandled game message: 0x{0:X4} {1}", msg.Id, msg.GetType().Name);
                    }
                }

                _incomingBuffer.Position = end;
            }
            _incomingBuffer.ConsumeData();
            FlushOutgoingBuffer();
        }
Ejemplo n.º 13
0
 public MessageNode(GameMessage message)
 {
     this.gameMessage = message;
     Text             = String.Join(".", (message.GetType().ToString().Split('.').Skip(5)));
 }
Ejemplo n.º 14
0
        public async Task PlayerShoot(GameMessage message)
        {
            ShootMessage shootMsg = message as ShootMessage;

            if (shootMsg == null)
            {
                throw new Exception($"Player shoot recieved a message that was not of type {typeof(ShootMessage)} but was {message.GetType()}");
            }

            logger.LogInformation($"Player {shootMsg.PlayerId} shot in direction {shootMsg.Direction}");

            await stream.OnNextAsync(message);
        }
Ejemplo n.º 15
0
        public async Task PlayerMove(GameMessage message)
        {
            MoveMessage moveMsg = message as MoveMessage;

            if (moveMsg == null)
            {
                throw new Exception($"Player move recieved a message that was not of type {typeof(MoveMessage)} but was {message.GetType()}");
            }

            logger.LogInformation($"Player {moveMsg.PlayerId} moved in direction {moveMsg.Direction}");

            await stream.OnNextAsync(message);
        }