Пример #1
0
        public static async Task InitBot(ConnectionConfig config)
        {
            Header();
            Logger.Warn("Loading TSQB...");
            _tsClient = new TeamSpeakClient(config.Ip, config.QueryPort);
            try
            {
                await _tsClient.Connect();

                await _tsClient.Login(config.QueryLogin, config.QueryPassword);

                await _tsClient.UseServer(config.ServerId);

                await _tsClient.ChangeNickName(config.QueryNickname);

                await _tsClient.RegisterServerNotification();

                await _tsClient.RegisterTextPrivateNotification();

                await _tsClient.RegisterChannelNotification(0);

                await EventsManager.HandleEvents(_tsClient);

                await CommandsManager.HandleCommands(_tsClient);

                Logger.Info("Welcome abort captain, all systems online.");
                await KeepAlive();
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex, "An error has been detected!");
                Environment.Exit(-1);
            }
        }
        public async static Task <IReadOnlyList <TeamSpeak3QueryApi.Net.Specialized.Responses.GetServerListInfo> > GetServerinfo()
        {
            try
            {
                var rc = new TeamSpeakClient(host);

                await rc.Connect();

                await rc.Login(username, pass);

                await rc.UseServer(1);

                await rc.WhoAmI();

                await rc.RegisterServerNotification();

                await rc.RegisterChannelNotification(30);

                var servers = await rc.GetServers();

                await rc.Logout();

                return(servers);
            }
            catch { }
            return(null);
        }
        public async static Task <List <TeamSpeak3QueryApi.Net.Specialized.Responses.GetClientInfo> > GetClients()
        {
            try
            {
                var rc = new TeamSpeakClient(host);

                await rc.Connect();

                await rc.Login(username, pass);

                await rc.UseServer(1);

                await rc.WhoAmI();

                await rc.RegisterServerNotification();

                await rc.RegisterChannelNotification(30);

                var serverGroups = await rc.GetServerGroups();

                var firstNormalGroup = serverGroups?.FirstOrDefault(s => s.ServerGroupType == ServerGroupType.NormalGroup);
                var groupClients     = await rc.GetServerGroupClientList(firstNormalGroup.Id);

                var currentClients = await rc.GetClients();

                var fullClients = currentClients.Where(c => c.Type == ClientType.FullClient).ToList();
                await rc.Logout();

                return(fullClients);
            }
            catch { }
            return(null);
        }
Пример #4
0
        public async Task ConnectAndLogin()
        {
            try
            {
                dbid = Convert.ToInt32(configuration.GetSection("Teamspeak:DatabaseID").Value);

                string server   = configuration.GetSection("Teamspeak:Server").Value;
                string port     = configuration.GetSection("Teamspeak:Port").Value;
                string username = configuration.GetSection("Teamspeak:Username").Value;
                string password = configuration.GetSection("Teamspeak:Password").Value;
                nickname = configuration.GetSection("Nickname").Value;

                tsClient = new TeamSpeakClient(server, Convert.ToInt32(port));

                // Create rich client instance
                await tsClient.Connect();                 // connect to the server

                await tsClient.Login(username, password); // login to do some stuff that requires permission

                await tsClient.UseServer(1);              // Use the server with id '1'

#if DEBUG
                await tsClient.ChangeNickName(nickname + "_DEBUG");
#else
                await tsClient.ChangeNickName(nickname);
#endif


                botClient = await tsClient.WhoAmI();

                await tsClient.MoveClient(botClient.ClientId, 1);

                await tsClient.RegisterChannelNotification(1);

                tsClient.Subscribe <ClientMoved>(ClientMoved);

                await tsClient.RegisterTextChannelNotification();

                tsClient.Subscribe <TextMessage>(ChatMessageReceived);

                var pChannel = await tsClient.GetChannels();
            }
            catch (Exception e)
            {
                logger.LogWarning(e.Message);
                logger.LogWarning(e.StackTrace);
            }
        }
Пример #5
0
        static async void DoItRich()
        {
            var loginData = File.ReadAllLines("..\\..\\..\\logindata.secret");

            var host     = loginData[0].Trim();
            var user     = loginData[1].Trim();
            var password = loginData[2].Trim();

            var rc = new TeamSpeakClient(host);

            await rc.Connect();

            await rc.Login(user, password);

            await rc.UseServer(1);

            await rc.WhoAmI();

            await rc.RegisterServerNotification();

            await rc.RegisterChannelNotification(30);

            var currentClients = await rc.GetClients();

            var fullClients = currentClients.Where(c => c.Type == ClientType.FullClient).ToList();
            //var fullClients = from c
            //                  in currentClients
            //                  where c.Type == ClientType.FullClient
            //                  select c;
            //fullClients.ForEach(async c=> await rc.KickClient(c, KickOrigin.Channel));
            await rc.KickClient(fullClients, KickOrigin.Channel);

            //foreach (var client in fullClients)
            //    await rc.KickClient(client.ClientId, KickTarget.Channel);

            // await rc.MoveClient(1, 1);
            // await rc.KickClient(1, KickTarget.Server);

            rc.Subscribe <ClientEnterView>(data => data.ForEach(c => Trace.WriteLine("Client " + c.NickName + " joined.")));
            rc.Subscribe <ClientLeftView>(data => data.ForEach(c => Trace.WriteLine("Client with id " + c.Id + " left (kicked/banned/left).")));
            rc.Subscribe <ServerEdited>(data => Debugger.Break());
            rc.Subscribe <ChannelEdited>(data => Debugger.Break());
            rc.Subscribe <ClientMoved>(data => Debugger.Break());

            Console.WriteLine("Done1");
        }
Пример #6
0
        static async Task Main(string[] args)
        {
            var loginData = File.ReadAllLines("..\\..\\..\\logindata.secret");

            var host     = loginData[0].Trim();
            var user     = loginData[1].Trim();
            var password = loginData[2].Trim();

            var rc = new TeamSpeakClient(host);

            await rc.Connect();

            await rc.Login(user, password);

            await rc.UseServer(1);

            await rc.WhoAmI();

            await rc.RegisterServerNotification();

            await rc.RegisterChannelNotification(30);

            var serverGroups = await rc.GetServerGroups();

            var firstNormalGroup = serverGroups?.FirstOrDefault(s => s.ServerGroupType == ServerGroupType.NormalGroup);
            var groupClients     = await rc.GetServerGroupClientList(firstNormalGroup.Id);

            var currentClients = await rc.GetClients();

            var fullClients = currentClients.Where(c => c.Type == ClientType.FullClient).ToList();
            await rc.KickClient(fullClients, KickOrigin.Channel);

            // await rc.MoveClient(1, 1);
            // await rc.KickClient(1, KickTarget.Server);

            rc.Subscribe <ClientEnterView>(data => data.ForEach(c => Debug.WriteLine($"Client {c.NickName} joined.")));
            rc.Subscribe <ClientLeftView>(data => data.ForEach(c => Debug.WriteLine($"Client with id {c.Id} left (kicked/banned/left).")));
            rc.Subscribe <ServerEdited>(data => Debugger.Break());
            rc.Subscribe <ChannelEdited>(data => Debugger.Break());
            rc.Subscribe <ClientMoved>(data => Debugger.Break());

            Console.WriteLine("Done");
            Console.ReadLine();
        }