Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
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);
            }
        }