Пример #1
0
        protected void ConnectButton_OnClick(object sender, EventArgs e)
        {
            ResultLabel.Text = null;
            ErrorLabel.Text = null;

            string host = ServerAddressTextBox.Text.Trim();
            ushort port = Convert.ToUInt16(ServerPortTextBox.Text);

            try
            {
                using (QueryRunner queryRunner = new QueryRunner(new SyncTcpDispatcher(host, port)))  // host and port
                {
                    // connection to the TS3-Server is established with the first query command

                    VersionResponse versionResponse = queryRunner.GetVersion();

                    if (versionResponse.IsErroneous)
                    {
                        ErrorLabel.Text = "Could not get server version: " + versionResponse.ErrorMessage;
                        return;
                    }

                    ResultLabel.Text = string.Format("Server version:<br>Platform: {0}<br>Version: {1}<br>Build: {2}", versionResponse.Platform, versionResponse.Version, versionResponse.Build);
                }

            }
            catch (Exception ex)
            {
                ErrorLabel.Text = ex.Message;
            }
        }
Пример #2
0
        internal QueryUtils(QueryRunner queryRunner)
        {
            if (queryRunner == null)
                throw new ArgumentNullException("queryRunner");

            QueryRunner = queryRunner;
        }
Пример #3
0
    private void QueryDispatcher_ReadyForSendingCommands(object sender, System.EventArgs e)
    {
      // you can only run commands on the queryrunner when this event has been raised first!
      QueryRunner = new QueryRunner(QueryDispatcher);

      VersionResponse versionResponse = QueryRunner.GetVersion();

      if (versionResponse.IsErroneous)
      {
        Console.WriteLine("Could not get server version: " + versionResponse.ErrorMessage);
        return;
      }

      Console.WriteLine("Server version:\n\nPlatform: {0}\nVersion: {1}\nBuild: {2}", versionResponse.Platform, versionResponse.Version, versionResponse.Build);
    }
Пример #4
0
        private void QueryDispatcher_ReadyForSendingCommands(object sender, EventArgs e)
        {
            UpdateUI(ConnectionState.Connected);
            // you can only run commands on the queryrunner when this event has been raised first!
            QueryRunner = new QueryRunner(QueryDispatcher);

            VersionResponse versionResponse = QueryRunner.GetVersion();

            if (versionResponse.IsErroneous)
            {
                MessageBox.Show("Could not get server version: " + versionResponse.ErrorMessage);
                return;
            }

            MessageBox.Show(string.Format("Server version:\n\nPlatform: {0}\nVersion: {1}\nBuild: {2}", versionResponse.Platform, versionResponse.Version, versionResponse.Build));
        }
Пример #5
0
        protected void RunQueries(Action<QueryRunner> action)
        {
            if (action == null)
                throw new ArgumentNullException("action");

            string host = ConfigurationManager.AppSettings["host"];

            if (host == null)
                throw new ConfigurationErrorsException("host could not be found in web.config");

            string portString = ConfigurationManager.AppSettings["port"];

            if (portString == null)
                throw new ConfigurationErrorsException("port could not be found in web.config");

            ushort port;

            if (!ushort.TryParse(portString, NumberStyles.Integer, CultureInfo.InvariantCulture, out port))
                throw new ConfigurationErrorsException("port in web.config has invalid an invalid format.");

            string login = ConfigurationManager.AppSettings["login"];
            string password = ConfigurationManager.AppSettings["password"];


            using (QueryRunner queryRunner = new QueryRunner(new SyncTcpDispatcher(host, port)))  // host and port
            {
                // connection to the TS3-Server is established with the first query command

                if (!login.IsNullOrTrimmedEmpty() && !password.IsNullOrTrimmedEmpty())
                {
                    SimpleResponse loginResponse = queryRunner.Login(login, password); // login using the provided username and password and show a dump-output of the response in a textbox

                    if (loginResponse.IsErroneous)
                        throw new NotSupportedException("Login failed for the given username and password!");
                }

                action(queryRunner);
            }
        }
Пример #6
0
        public void Disconnect()
        {
            // QueryRunner disposes the Dispatcher too
            if (QueryRunner != null)
                QueryRunner.Dispose();

            QueryDispatcher = null;
            QueryRunner = null;
            UpdateUI(ConnectionState.Disconnected);
        }
Пример #7
0
        private void QueryDispatcher_ReadyForSendingCommands(object sender, EventArgs e)
        {
            QueryRunner = new QueryRunner(QueryDispatcher);

            QueryRunner.Login("Obama", "maTf15+J");
            QueryRunner.SelectVirtualServerById(1);

            QueryRunner.Notifications.ServerMessageReceived += Notifications_ServerMessageReceived;
            QueryRunner.RegisterForNotifications(ServerNotifyRegisterEvent.TextServer, 1);

            QueryRunner.Notifications.ChannelMessageReceived += Notifications_ChannelMessageReceived;
            QueryRunner.RegisterForNotifications(ServerNotifyRegisterEvent.TextChannel, 1);

            QueryDispatcher.BanDetected += QueryDispatcher_BanDetected;

            QueryDispatcher.ServerClosedConnection += QueryDispatcher_ServerClosedConnection;
        }
        /// <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;
        }
 public void Initialise(Nini.Config.IConfigSource source)
 {
     TS3Server = new QueryRunner(new SyncTcpDispatcher(m_server, (ushort)m_port));
 }