Exemplo n.º 1
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;
        }
        /// <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;
        }