Exemplo n.º 1
0
        void onBEMessageReceivedEvent(Message message)
        {
            if (!(
                    message.Type == Message.MessageType.ConnectLegacyGUID ||
                    message.Type == Message.MessageType.ConnectGUID ||
                    (_checkip && message.Type == Message.MessageType.ConnectIP)
                    ))
            {
                return;
            }
            Player player;

            try
            {
                player = new Player(message);
            }
            catch (Exception ex)
            {
                AppConsole.Log(String.Format("Error paring be message: {0}", ex.Message), ConsoleColor.Red);
                return;
            }

            bool check;

            try
            {
                check = _driver.CheckPlayer(player);
            }
            catch (Exception ex)
            {
                AppConsole.Log(String.Format("Error checking player: {0}", ex.Message), ConsoleColor.Red);
                Console.WriteLine(ex.StackTrace);
                return;
            }

            var kick = (check && _mode == Mode.Blacklist) || (!check && _mode == Mode.Whitelist);

            if (kick)
            {
                var cmd = new Command()
                {
                    Type       = Command.CmdType.Kick,
                    Parameters = String.Format("{0} {1}", player.Id, _kickMessage)
                };
                AppConsole.Log(String.Format("Kicking {0}", player.Name));
                _api.SendCommand(cmd);
            }
        }