Пример #1
0
        public async Task <ConnectionResult> Login(String LoginName, String LoginPass, String Server, int VServerID = 1)
        {
            TSClient       = new TeamSpeakClient(Server);
            this.VServerID = VServerID <= 0 ? VServerID : 1;

            try
            {
                //TSClient.
                await TSClient.Connect();

                await TSClient.Login(LoginName, LoginPass);

                await TSClient.UseServer(this.VServerID);
            }
            catch (SocketException e)
            {
                Console.WriteLine(e.Message);
                return(ConnectionResult.SOCKET);
            }
            catch (TeamSpeak3QueryApi.Net.QueryException e)
            {
                Console.WriteLine(e.Error.Message);
                return(ConnectionResult.QUERY);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(ConnectionResult.UNKNOWN);
            }
            return(ConnectionResult.OK);
        }
Пример #2
0
        private async Task InitTSQuery()
        {
            tsQuery = new TeamSpeakClient(TeamspeakQueryAddress, TeamspeakQueryPort); // Create rich client instance

            try
            {
                await tsQuery.Connect();                                // connect to the server

                await tsQuery.Login(TeamspeakLogin, TeamspeakPassword); // login to do some stuff that requires permission

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

                var me = await tsQuery.WhoAmI();                        // Get information about yourself!

                var channel = (await tsQuery.FindChannel(TeamspeakChannel)).FirstOrDefault();

                Utils.Delay(100, false, async() =>
                            await UpdateTeamspeak(channel)
                            );
            }
            catch (QueryException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #3
0
        private async Task InternalStart()
        {
            _teamSpeakClient = new TeamSpeakClient(_settings.Teamspeak.Host, _settings.Teamspeak.Port);
            _logger.LogInformation("Starting teamspeak client...");
            await _teamSpeakClient.Connect();

            await _teamSpeakClient.Login(_settings.Teamspeak.Username, _settings.Teamspeak.Key);

            _logger.LogInformation("Teamspeak bot connected");

            await _teamSpeakClient.UseServer(1);

            _logger.LogInformation("Server changed");

            var me = await _teamSpeakClient.WhoAmI();

            _logger.LogInformation($"Connected using username {me.NickName}");

            _nicknamesCache.Clear();
            var clients = await _teamSpeakClient.GetClients();

            foreach (var client in clients)
            {
                _nicknamesCache.AddOrUpdate(client.Id, client.NickName, (i, s) => client.NickName);
            }

            await _teamSpeakClient.RegisterServerNotification();

            _teamSpeakClient.Subscribe <ClientEnterView>(UserEntered);
            _teamSpeakClient.Subscribe <ClientLeftView>(UserLeft);
            _system.Actor <TelegramMessageChannel>().Tell(new MessageArgs <string>(_settings.Telegram.HostGroupId, "[TEAMSPEAK_ACTOR] I'm alive"));
        }
Пример #4
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);
        }
Пример #7
0
        private static async Task <TeamSpeakClient> GetConnectedClient()
        {
            var bot = new TeamSpeakClient(ConfigManager.Config.Host, ConfigManager.Config.Port);
            await bot.Connect();

            await bot.Login(ConfigManager.Config.QueryUsername, ConfigManager.Config.QueryPassword);

            await bot.UseServer((await bot.GetServers()).FirstOrDefault().Id);

            return(bot);
        }
Пример #8
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);
            }
        }
Пример #9
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");
        }
Пример #10
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();
        }
Пример #11
0
        private async Task <TeamSpeakClient> CreateConnection()
        {
            try
            {
                var conn = new TeamSpeakClient(_serverIp, _serverPort);
                await conn.Connect();

                await conn.Login(_username, _password);

                await conn.UseServer(1);

                return(conn);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(null);
        }
Пример #12
0
        private async Task <TeamSpeakClient> ConnectToTeamspeak()
        {
            try
            {
                var rc = new TeamSpeakClient(ConfigurationManager.AppSettings["TS_IP"]);                                      // Create rich client instance
                await rc.Connect();                                                                                           // connect to the server

                await rc.Login(ConfigurationManager.AppSettings["TS_USER"], ConfigurationManager.AppSettings["TS_PASSWORD"]); // login to do some stuff that requires permission

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

                await rc.RegisterServerNotification();

                //rc.Subscribe<ClientEnterView>(Test);
                return(rc);
            }
            catch (Exception ex)
            {
                _eventLog1?.WriteEntry($"Failed to connect to ts3: {ex.Message}", EventLogEntryType.Error);
                return(null);
            }
        }
Пример #13
0
        private async void Run()
        {
            var loginData = File.ReadAllLines("..\\..\\..\\logindata.secret");

            var token = loginData[0].Trim();

            var rc = new TeamSpeakClient();
            await rc.Connect();

            await rc.Auth(token);

            await rc.RegisterNotification(Event.Any);

            var whoami = await rc.WhoAmI();

            Console.WriteLine($"I am client {whoami.ClientId} in channel {whoami.ChannelId}.");

            var selected = await rc.Use();

            Console.WriteLine($"Currently looking at connection {selected.ServerConnectionHandlerId}.");

            var serverVariable = await rc.GetServerVariable(ServerVariable.Name,
                                                            ServerVariable.Platform,
                                                            ServerVariable.Version,
                                                            ServerVariable.Created,
                                                            ServerVariable.CodecEncryptionMode,
                                                            ServerVariable.DefaultServerGroup,
                                                            ServerVariable.DefaultChannelGroup,
                                                            ServerVariable.HostbannerUrl,
                                                            ServerVariable.HostbannerGfxUrl,
                                                            ServerVariable.HostbannerGfxInterval,
                                                            ServerVariable.PrioritySpeakerDimmModificator,
                                                            ServerVariable.Id,
                                                            ServerVariable.HostbuttonTooltip,
                                                            ServerVariable.HostbuttonUrl,
                                                            ServerVariable.HostbuttonGfxUrl,
                                                            ServerVariable.NamePhonetic,
                                                            ServerVariable.IconId,
                                                            ServerVariable.Ip,
                                                            ServerVariable.AskForPrivilegekey,
                                                            ServerVariable.HostbannerMode);

            Console.WriteLine($"My server is called {serverVariable.Name} running version {serverVariable.Version}.");

            var connections = await rc.GetConnectionList();

            Console.WriteLine($"I have {connections.Count} active connections.");

            var myChannel = await rc.GetChannelInfo(whoami.ChannelId);

            Console.WriteLine($"I am currently in channel {myChannel.Path} on {serverVariable.Name}.");

            var channelClients = await rc.GetChannelClients(whoami.ChannelId);

            Console.WriteLine($"There are {channelClients.Count} users in my channel.");

            rc.Subscribe <CurrentServerConnectionChanged>(data =>
                                                          Console.WriteLine($"Switched active connection to {data.First().ServerConnectionHandlerId}"));

            rc.Subscribe <TalkStatusChange>(data =>
            {
                var stuff = data.First();
                if (stuff.ServerConnectionHandlerId != selected.ServerConnectionHandlerId)
                {
                    return;
                }

                var clientName = channelClients.First(c => c.ClientId == stuff.Id).Name ?? $"Unknown {stuff.Id}";
                if (stuff.IsTalking)
                {
                    Console.WriteLine($"{serverVariable.Name}: {clientName} started talking");
                }
                else
                {
                    Console.WriteLine($"{serverVariable.Name}: {clientName} stopped talking");
                }
            });
        }
Пример #14
0
        private async Task CheckSpeakingClients()
        {
            var rc = new TeamSpeakClient(TeamspeakQueryAddress, TeamspeakQueryPort); // Create rich client instance

            try
            {
                await rc.Connect();                                // connect to the server

                await rc.Login(TeamspeakLogin, TeamspeakPassword); // login to do some stuff that requires permission

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

                var me = await rc.WhoAmI();                        // Get information about yourself!
            }
            catch (QueryException ex)
            {
                //Console.WriteLine(ex.ToString());
            }

            var channel = (await rc.FindChannel(TeamspeakChannel)).FirstOrDefault();

            while (rc.Client.IsConnected)
            {
                var clients = await rc.GetClients(GetClientOptions.Voice);

                var clientschannel = clients.ToList().FindAll(c => c.ChannelId == channel.Id);

                var players = NAPI.Pools.GetAllPlayers().FindAll(p => p.Exists && p.HasSharedData("TsName"));

                for (int i = 0; i < players.Count; i++)
                {
                    if (players[i] == null)
                    {
                        continue;
                    }

                    var name     = players[i].GetSharedData <string>("TsName");
                    var tsplayer = clientschannel.Find(p => p.NickName == name);
                    var player   = players[i];

                    if (!player.Exists)
                    {
                        continue;
                    }

                    if (tsplayer != null)
                    {
                        if (tsplayer.Talk && !player.HasData("IS_SPEAKING"))
                        {
                            players.FindAll(p => p.Exists && p.Position.DistanceTo2D(player.Position) < 5f)
                            .ForEach((client) => client.TriggerEvent("Teamspeak_LipSync", player.Handle.Value, true));

                            player.SetData("IS_SPEAKING", true);
                        }
                        else if (!tsplayer.Talk && player.HasData("IS_SPEAKING"))
                        {
                            players.FindAll(p => p.Exists && p.Position.DistanceTo2D(player.Position) < 5f)
                            .ForEach((client) => client.TriggerEvent("Teamspeak_LipSync", player.Handle.Value, false));

                            player.ResetData("IS_SPEAKING");
                        }
                    }
                    await Task.Delay(10);
                }
                await Task.Delay(50);
            }
        }
 internal static async Task ConnectAndInitConnection(this TeamSpeakClient teamSpeakClient, TS3ServerInfo serverInfo)
 {
     await teamSpeakClient.Connect()
     .ContinueWith(o => teamSpeakClient.Login(serverInfo.QueryUsername, serverInfo.QueryPassword))
     .ContinueWith(o => teamSpeakClient.UseServer(serverInfo.ServerIndex));
 }