Ejemplo n.º 1
0
        public bool HandlePacket(Peer peer, byte[] data)
        {
            var message = new ChatMessage(data);

            Console.WriteLine("PlayerID: " + message.playerId);
            var split = message.msg.Split(' ');

            if (split.Length > 1)
            {
                int x, y = 0;
                if (int.TryParse(split[0], out x))
                {
                    if (int.TryParse(split[1], out y))
                    {
                        var response = new AttentionPingAns(
                            _playerManager.GetPeerInfo(peer),
                            new AttentionPing {
                            x = x, y = y, targetNetId = 0, type = 0
                        }
                            );
                        _game.PacketHandlerManager.broadcastPacketTeam(
                            _playerManager.GetPeerInfo(peer).Team, response, Channel.CHL_S2C
                            );
                    }
                }
            }

            #region Commands
            // Execute commands
            var CommandStarterCharacter = _chatCommandManager.CommandStarterCharacter;
            if (message.msg.StartsWith(CommandStarterCharacter))
            {
                message.msg = message.msg.Remove(0, 1);
                split       = message.msg.ToLower().Split(' ');

                ChatCommand command = _chatCommandManager.GetCommand(split[0]);
                if (command != null)
                {
                    try
                    {
                        command.Execute(peer, true, message.msg);
                    }
                    catch
                    {
                        _logger.LogCoreWarning(command + " sent an exception.");
                        var dm = new DebugMessage("Something went wrong...Did you wrote the command well ? ");
                        _game.PacketHandlerManager.sendPacket(peer, dm, Channel.CHL_S2C);
                    }
                    return(true);
                }
                else
                {
                    _chatCommandManager.SendDebugMsgFormatted(DebugMsgType.ERROR, "<font color =\"#E175FF\"><b>" + _chatCommandManager.CommandStarterCharacter + split[0] + "</b><font color =\"#AFBF00\"> is not a valid command.");
                    _chatCommandManager.SendDebugMsgFormatted(DebugMsgType.INFO, "Type <font color =\"#E175FF\"><b>" + _chatCommandManager.CommandStarterCharacter + "help</b><font color =\"#AFBF00\"> for a list of available commands");
                    return(true);
                }
            }
            #endregion

            var debugMessage = string.Format("{0} ({1}): </font><font color=\"#FFFFFF\">{2}",
                                             _playerManager.GetPeerInfo(peer).Name,
                                             _playerManager.GetPeerInfo(peer).Champion.Model,
                                             message.msg);
            var teamChatColor  = "<font color=\"#00FF00\">";
            var enemyChatColor = "<font color=\"#FF0000\">";
            var dmTeam         = new DebugMessage(teamChatColor + "[All] " + debugMessage);
            var dmEnemy        = new DebugMessage(enemyChatColor + "[All] " + debugMessage);
            var ownTeam        = _playerManager.GetPeerInfo(peer).Team;
            var enemyTeam      = CustomConvert.GetEnemyTeam(ownTeam);

            if (_game.Config.ChatCheatsEnabled)
            {
                _game.PacketHandlerManager.broadcastPacketTeam(ownTeam, dmTeam, Channel.CHL_S2C);
                _game.PacketHandlerManager.broadcastPacketTeam(enemyTeam, dmEnemy, Channel.CHL_S2C);
                return(true);
            }

            switch (message.type)
            {
            case ChatType.CHAT_ALL:
                _game.PacketHandlerManager.broadcastPacketTeam(ownTeam, dmTeam, Channel.CHL_S2C);
                _game.PacketHandlerManager.broadcastPacketTeam(enemyTeam, dmEnemy, Channel.CHL_S2C);
                return(true);

            case ChatType.CHAT_TEAM:
                dmTeam = new DebugMessage(teamChatColor + debugMessage);
                _game.PacketHandlerManager.broadcastPacketTeam(ownTeam, dmTeam, Channel.CHL_S2C);
                return(true);

            default:
                //Logging.errorLine("Unknown ChatMessageType");
                return(_game.PacketHandlerManager.sendPacket(peer, data, Channel.CHL_COMMUNICATION));
            }
        }
Ejemplo n.º 2
0
        public override bool HandlePacket(int userId, ChatMessageRequest req)
        {
            var split = req.Message.Split(' ');

            if (split.Length > 1)
            {
                if (int.TryParse(split[0], out var x))
                {
                    if (int.TryParse(split[1], out var y))
                    {
                        var client = _playerManager.GetPeerInfo(userId);
                        _game.PacketNotifier.NotifyPing(client, new Vector2(x, y), 0, Pings.PING_DEFAULT);
                    }
                }
            }

            // Execute commands
            var commandStarterCharacter = _chatCommandManager.CommandStarterCharacter;

            if (req.Message.StartsWith(commandStarterCharacter))
            {
                var msg = req.Message.Remove(0, 1);
                split = msg.ToLower().Split(' ');

                var command = _chatCommandManager.GetCommand(split[0]);
                if (command != null)
                {
                    try
                    {
                        command.Execute(userId, true, msg);
                    }
                    catch
                    {
                        _logger.Warn(command + " sent an exception.");
                        _game.PacketNotifier.NotifyDebugMessage(userId, "Something went wrong...Did you wrote the command well ? ");
                    }
                    return(true);
                }

                _chatCommandManager.SendDebugMsgFormatted(DebugMsgType.ERROR, "<font color =\"#E175FF\"><b>"
                                                          + _chatCommandManager.CommandStarterCharacter + split[0] + "</b><font color =\"#AFBF00\"> " +
                                                          "is not a valid command.");
                _chatCommandManager.SendDebugMsgFormatted(DebugMsgType.INFO, "Type <font color =\"#E175FF\"><b>"
                                                          + _chatCommandManager.CommandStarterCharacter + "help</b><font color =\"#AFBF00\"> " +
                                                          "for a list of available commands");
                return(true);
            }

            var debugMessage =
                $"{_playerManager.GetPeerInfo(userId).Name} ({_playerManager.GetPeerInfo(userId).Champion.Model}): </font><font color=\"#FFFFFF\">{req.Message}";
            var teamChatColor  = "<font color=\"#00FF00\">";
            var enemyChatColor = "<font color=\"#FF0000\">";
            var dmTeam         = teamChatColor + "[All] " + debugMessage;
            var dmEnemy        = enemyChatColor + "[All] " + debugMessage;
            var ownTeam        = _playerManager.GetPeerInfo(userId).Team;
            var enemyTeam      = CustomConvert.GetEnemyTeam(ownTeam);

            if (_game.Config.ChatCheatsEnabled)
            {
                _game.PacketNotifier.NotifyDebugMessage(ownTeam, dmTeam);
                _game.PacketNotifier.NotifyDebugMessage(enemyTeam, dmEnemy);
                return(true);
            }

            switch (req.Type)
            {
            case ChatType.CHAT_ALL:
                _game.PacketNotifier.NotifyDebugMessage(ownTeam, dmTeam);
                _game.PacketNotifier.NotifyDebugMessage(enemyTeam, dmEnemy);
                return(true);

            case ChatType.CHAT_TEAM:
                _game.PacketNotifier.NotifyDebugMessage(ownTeam, dmTeam);
                return(true);

            default:
                _logger.Error("Unknown ChatMessageType:" + req.Type.ToString());
                return(false);
            }
        }