Ejemplo n.º 1
0
 private void TS3_ConnectionClosed(object sender, EventArgs <string> e)
 {
     if (!_running)
     {
         RankingBot.Logger.Info(_file + " Sucessfully shutdown");
         Environment.Exit(0);
     }
     else
     {
         RankingBot.TryReconnect();
         return;
     }
 }
Ejemplo n.º 2
0
        public TS3Handler(bool recon = false)
        {
            _recon = recon;

            RankingBot.Logger.Debug(_file + " Init TS3 Handler");
            NotificationHub notify = new NotificationHub();

            notify.ClientJoined.Triggered    += TS3_ClientJoined;
            notify.ClientLeft.Banned         += TS3_ClientLeft_Banned;
            notify.ClientLeft.ConnectionLost += TS3_ClientLeft_ConnectionLost;
            notify.ClientLeft.Disconnected   += TS3_ClientLeft_Disconnected;
            notify.ClientLeft.Kicked         += TS3_ClientLeft_Kicked;

            RankingBot.ConnectTS3((string)RankingBot.Config.teamspeak.sq_ip, (ushort)RankingBot.Config.teamspeak.sq_port, notify);
            RankingBot.TS3.BanDetected      += TS3_BanDetected;
            RankingBot.TS3.ConnectionClosed += TS3_ConnectionClosed;

            try
            {
                RankingBot.TS3.Connect();
                RankingBot.Logger.Debug(_file + " Connected to TS3 server");
            }
            catch (SocketException e)
            {
                RankingBot.Logger.Error(_file + " Error connecting to TS3 server: " + e.Message);
                if (!_recon)
                {
                    Environment.Exit(1);
                }
                RankingBot.TryReconnect();
                return;
            }

            RankingBot.Logger.Debug(_file + " Logging in to ServerQuery");
            if (new LoginCommand((string)RankingBot.Config.teamspeak.username, (string)RankingBot.Config.teamspeak.password).Execute(RankingBot.TS3).IsErroneous)
            {
                RankingBot.Logger.Error(_file + " ServerQuery username/password invalid");
                Environment.Exit(1);
            }

            RankingBot.Logger.Debug(_file + " Selecting virtual server");
            if (new UseCommand((ushort)RankingBot.Config.teamspeak.ts_port).Execute(RankingBot.TS3).IsErroneous)
            {
                RankingBot.Logger.Error(_file + " Unable to access TS3 server running on port '" + RankingBot.Config.teamspeak.ts_port + "'");
                if (!_recon)
                {
                    Environment.Exit(1);
                }
                RankingBot.TryReconnect();
                return;
            }

            _clients = new Dictionary <uint, Client>();
            RankingBot.Logger.Debug(_file + " Registering for notifications");
            if (new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.Server).Execute(RankingBot.TS3).IsErroneous)
            {
                RankingBot.Logger.Error(_file + " Unable to register for server notifications");
                Environment.Exit(1);
            }

            RankingBot.Logger.Info(_file + " Connected to TS3");
            _keepAlive = new Timer(TS3_KeepAlive, null, 30000, 30000);
            RegisterConnectedClients();
            Console.CancelKeyPress += Console_CancelKeyPress;

            new UpdateChecker();

            while (_running)
            {
                MenuInput(Console.ReadLine());
            }
        }