Ejemplo n.º 1
0
        public void Connect()
        {
            //Console.WriteLine(
            //"Background Thread: SynchronizationContext.Current is " +
            //(SynchronizationContext.Current != null ?
            //SynchronizationContext.Current.ToString() : "null"));

            AsyncTcpDispatcher.Connect();
            connectionChange.WaitOne();

            //TODO: Add logic here that checks if socket is null. That can mean many things..
            //      But apparently one of them is that you have been banned (for not being whitelisted mainly)
            if (AsyncTcpDispatcher.Socket == null)
            {
                throw new Exception("Socket did not initialize: Are you whitelisted?");
            }
            if (AsyncTcpDispatcher.Socket.Connected)
            {
                logger.Debug("Connected");
            }
            else
            {
                throw new Exception("Could not connect to teamspeak server");
            }
        }
Ejemplo n.º 2
0
        public void Connect()
        {
            // do not connect when already connected or during connection establishing
            if (QueryDispatcher != null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(ServerAddressTextBox.Text))
            {
                MessageBox.Show("Please provide a server address!");
                return;
            }

            ushort port;


            if (!ushort.TryParse(ServerPort.Text, out port))
            {
                MessageBox.Show("Please provide a valid query port!");
                return;
            }

            UpdateUI(ConnectionState.Connecting);
            QueryDispatcher                          = new AsyncTcpDispatcher(ServerAddressTextBox.Text.Trim(), port);
            QueryDispatcher.BanDetected             += QueryDispatcher_BanDetected;
            QueryDispatcher.ReadyForSendingCommands += QueryDispatcher_ReadyForSendingCommands;
            QueryDispatcher.ServerClosedConnection  += QueryDispatcher_ServerClosedConnection;
            QueryDispatcher.SocketError             += QueryDispatcher_SocketError;
            QueryDispatcher.Connect();
        }
Ejemplo n.º 3
0
        public void Connect()
        {
            // do not connect when already connected or during connection establishing
            if (QueryDispatcher != null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(Model.ServerAddress))
            {
                MessageBox.Show("Please provide a server address!");
                return;
            }

            if (!Model.ServerPort.HasValue)
            {
                MessageBox.Show("Please provide a valid query port!");
                return;
            }

            Model.ConnectionState                    = ConnectionState.Connecting;
            QueryDispatcher                          = new AsyncTcpDispatcher(Model.ServerAddress, Model.ServerPort.Value);
            QueryDispatcher.BanDetected             += QueryDispatcher_BanDetected;
            QueryDispatcher.ReadyForSendingCommands += QueryDispatcher_ReadyForSendingCommands;
            QueryDispatcher.ServerClosedConnection  += QueryDispatcher_ServerClosedConnection;
            QueryDispatcher.SocketError             += QueryDispatcher_SocketError;
            QueryDispatcher.Connect();
        }
Ejemplo n.º 4
0
 private void Connect()
 {
     QueryDispatcher                          = new AsyncTcpDispatcher(ServerAddress, Port);
     QueryDispatcher.BanDetected             += QueryDispatcher_BanDetected;
     QueryDispatcher.ReadyForSendingCommands += QueryDispatcher_ReadyForSendingCommands;
     QueryDispatcher.ServerClosedConnection  += QueryDispatcher_ServerClosedConnection;
     QueryDispatcher.SocketError             += QueryDispatcher_SocketError;
     QueryDispatcher.Connect();
 }
Ejemplo n.º 5
0
 public void Run()
 {
     _stopwatch.Start();
     QueryDispatcher                          = new AsyncTcpDispatcher(Ts3Config.Host, Ts3Config.Port);
     QueryDispatcher.BanDetected             += QueryDispatcher_BanDetected;
     QueryDispatcher.ReadyForSendingCommands += QueryDispatcher_ReadyForSendingCommands;
     QueryDispatcher.ServerClosedConnection  += QueryDispatcher_ServerClosedConnection;
     QueryDispatcher.SocketError             += QueryDispatcher_SocketError;
     QueryDispatcher.Connect();
     Connected = true;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Inits the credential.
        /// </summary>
        private void InitCredential()
        {
            TcpDispatcher = new SyncTcpDispatcher(BotInstance.Settings);
            QueryRunner   = new QueryRunner(TcpDispatcher);
            QueryRunner.Login(BotInstance.Settings.TeamSpeak.Username, BotInstance.Settings.TeamSpeak.Password);
            if (BotInstance.Settings.TeamSpeak.InstancePort.GetValueOrDefault() > 0)
            {
                QueryRunner.SelectVirtualServerByPort(BotInstance.Settings.TeamSpeak.InstancePort.GetValueOrDefault());
            }
            else
            {
                QueryRunner.SelectVirtualServerById(BotInstance.Settings.TeamSpeak.Instance.GetValueOrDefault());
            }
            Self = QueryRunner.SendWhoAmI();

            WorkerTcpDispatcher = new SyncTcpDispatcher(BotInstance.Settings);
            WorkerQueryRunner   = new QueryRunner(WorkerTcpDispatcher);
            WorkerQueryRunner.Login(BotInstance.Settings.TeamSpeak.Username, BotInstance.Settings.TeamSpeak.Password);

            if (BotInstance.Settings.TeamSpeak.InstancePort.GetValueOrDefault() > 0)
            {
                WorkerQueryRunner.SelectVirtualServerByPort(BotInstance.Settings.TeamSpeak.InstancePort.GetValueOrDefault());
            }
            else
            {
                WorkerQueryRunner.SelectVirtualServerById(BotInstance.Settings.TeamSpeak.Instance.GetValueOrDefault());
            }

            WorkerQueryRunner.UpdateCurrentQueryClient(new ClientModification {
                Nickname = BotInstance.Settings.Global.BotNickname
            });
            SelfWorker = WorkerQueryRunner.SendWhoAmI();
            WorkerQueryRunner.AddLogEntry(new LogEntryLight(LogLevel.Info, string.Format("TS3-Bot '{0}' connected.", BotInstance.Settings.Global.BotNickname)));

            NotificationTcpDispatcher = new AsyncTcpDispatcher(BotInstance.Settings);
            NotificationQueryRunner   = new QueryRunner(NotificationTcpDispatcher);

            NotificationTcpDispatcher.ServerClosedConnection             += notificationDispatcher_ServerClosedConnection;
            NotificationTcpDispatcher.ReadyForSendingCommands            += notificationDispatcher_ReadyForSendingCommands;
            NotificationQueryRunner.Notifications.ClientJoined           += BotInstance.Notifications_ClientJoined;
            NotificationQueryRunner.Notifications.ClientMoved            += BotInstance.Notifications_ClientMoved;
            NotificationQueryRunner.Notifications.ClientMoveForced       += BotInstance.Notifications_ClientMoveForced;
            NotificationQueryRunner.Notifications.ClientDisconnect       += BotInstance.Notifications_ClientDisconnect;
            NotificationQueryRunner.Notifications.ClientConnectionLost   += BotInstance.Notifications_ClientConnectionLost;
            NotificationQueryRunner.Notifications.ServerMessageReceived  += BotInstance.Notifications_MessageReceived;
            NotificationQueryRunner.Notifications.ChannelMessageReceived += BotInstance.Notifications_MessageReceived;
            NotificationQueryRunner.Notifications.ClientMessageReceived  += BotInstance.Notifications_MessageReceived;

            TcpDispatcher.Connect();
            WorkerTcpDispatcher.Connect();
            NotificationTcpDispatcher.Connect();
            Initialized = true;
        }
Ejemplo n.º 7
0
            // Öffne die Verbindung zum TeamSpeak Server
            public void OpenConnection()
            {
                // Logging
                Logging.Log("Baue Verbindung zu " + host + ":" + queryPort + " auf...");

                // Verbindung
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
                tcpSocket = new AsyncTcpDispatcher(host, queryPort);
                tcpSocket.ReadyForSendingCommands += OnReadyToSendCommands;
                tcpSocket.BanDetected             += OnBanDetected;
                tcpSocket.NotificationReceived    += OnNotificationReceived;
                tcpSocket.ServerClosedConnection  += OnServerClosedConnection;
                tcpSocket.Connect();
            }
Ejemplo n.º 8
0
        public void Connect()
        {
            // do not connect when already connected or during connection establishing
            if (QueryDispatcher != null)
            {
                return;
            }

            Model.ConnectionState                    = ConnectionState.Connecting;
            QueryDispatcher                          = new AsyncTcpDispatcher("localhost", 25639);
            QueryDispatcher.BanDetected             += QueryDispatcher_BanDetected;
            QueryDispatcher.ReadyForSendingCommands += QueryDispatcher_ReadyForSendingCommands;
            QueryDispatcher.ServerClosedConnection  += QueryDispatcher_ServerClosedConnection;
            QueryDispatcher.SocketError             += QueryDispatcher_SocketError;
            QueryDispatcher.NotificationReceived    += QueryDispatcher_NotificationReceived;
            QueryDispatcher.Connect();
        }
 private void Connect()
 {
     API.Log(API.LogType.Debug, "Teamspeak.ddl: Connecting");
     // do not connect when already connected or during connection establishing
     if (QueryDispatcher != null)
     {
         API.Log(API.LogType.Debug, "Teamspeak.ddl: QueryDispatcher not null");
         return;
     }
     lock (ThreadLocker)
     {
         Connected                                = ConnectionState.Connecting;
         QueryDispatcher                          = new AsyncTcpDispatcher("localhost", 25639);
         QueryDispatcher.BanDetected             += QueryDispatcher_BanDetected;
         QueryDispatcher.ReadyForSendingCommands += QueryDispatcher_ReadyForSendingCommands;
         QueryDispatcher.ServerClosedConnection  += QueryDispatcher_ServerClosedConnection;
         QueryDispatcher.SocketError             += QueryDispatcher_SocketError;
         QueryDispatcher.NotificationReceived    += QueryDispatcher_NotificationReceived;
         API.Log(API.LogType.Debug, "Teamspeak.ddl: linked events");
         QueryDispatcher.Connect();
         Keep_Alive_Timer.Start();
     }
 }
Ejemplo n.º 10
0
            // Öffne die Verbindung zum TeamSpeak Server
            public void OpenConnection()
            {
                // Logging
                Logging.Log("Baue Verbindung zu " + host + ":" + queryPort + " auf...");

                // Verbindung
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
                tcpSocket = new AsyncTcpDispatcher(host, queryPort);
                tcpSocket.ReadyForSendingCommands += OnReadyToSendCommands;
                tcpSocket.BanDetected += OnBanDetected;
                tcpSocket.NotificationReceived += OnNotificationReceived;
                tcpSocket.ServerClosedConnection += OnServerClosedConnection;
                tcpSocket.Connect();
            }
        /// <summary>
        /// Inits the credential.
        /// </summary>
        private void InitCredential()
        {
            TcpDispatcher = new SyncTcpDispatcher(BotInstance.Settings);
            QueryRunner = new QueryRunner(TcpDispatcher);
            QueryRunner.Login(BotInstance.Settings.TeamSpeak.Username, BotInstance.Settings.TeamSpeak.Password);
            if (BotInstance.Settings.TeamSpeak.InstancePort.GetValueOrDefault() > 0)
                QueryRunner.SelectVirtualServerByPort(BotInstance.Settings.TeamSpeak.InstancePort.GetValueOrDefault());
            else
                QueryRunner.SelectVirtualServerById(BotInstance.Settings.TeamSpeak.Instance.GetValueOrDefault());
            Self = QueryRunner.SendWhoAmI();

            WorkerTcpDispatcher = new SyncTcpDispatcher(BotInstance.Settings);
            WorkerQueryRunner = new QueryRunner(WorkerTcpDispatcher);
            WorkerQueryRunner.Login(BotInstance.Settings.TeamSpeak.Username, BotInstance.Settings.TeamSpeak.Password);

            if (BotInstance.Settings.TeamSpeak.InstancePort.GetValueOrDefault() > 0)
                WorkerQueryRunner.SelectVirtualServerByPort(BotInstance.Settings.TeamSpeak.InstancePort.GetValueOrDefault());
            else
                WorkerQueryRunner.SelectVirtualServerById(BotInstance.Settings.TeamSpeak.Instance.GetValueOrDefault());

            WorkerQueryRunner.UpdateCurrentQueryClient(new ClientModification { Nickname = BotInstance.Settings.Global.BotNickname });
            SelfWorker = WorkerQueryRunner.SendWhoAmI();
            WorkerQueryRunner.AddLogEntry(new LogEntryLight(LogLevel.Info, string.Format("TS3-Bot '{0}' connected.", BotInstance.Settings.Global.BotNickname)));

            NotificationTcpDispatcher = new AsyncTcpDispatcher(BotInstance.Settings);
            NotificationQueryRunner = new QueryRunner(NotificationTcpDispatcher);

            NotificationTcpDispatcher.ServerClosedConnection += notificationDispatcher_ServerClosedConnection;
            NotificationTcpDispatcher.ReadyForSendingCommands += notificationDispatcher_ReadyForSendingCommands;
            NotificationQueryRunner.Notifications.ClientJoined += BotInstance.Notifications_ClientJoined;
            NotificationQueryRunner.Notifications.ClientMoved += BotInstance.Notifications_ClientMoved;
            NotificationQueryRunner.Notifications.ClientMoveForced += BotInstance.Notifications_ClientMoveForced;
            NotificationQueryRunner.Notifications.ClientDisconnect += BotInstance.Notifications_ClientDisconnect;
            NotificationQueryRunner.Notifications.ClientConnectionLost += BotInstance.Notifications_ClientConnectionLost;
            NotificationQueryRunner.Notifications.ServerMessageReceived += BotInstance.Notifications_MessageReceived;
            NotificationQueryRunner.Notifications.ChannelMessageReceived += BotInstance.Notifications_MessageReceived;
            NotificationQueryRunner.Notifications.ClientMessageReceived += BotInstance.Notifications_MessageReceived;

            TcpDispatcher.Connect();
            WorkerTcpDispatcher.Connect();
            NotificationTcpDispatcher.Connect();
            Initialized = true;
        }