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); }
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")); }
private static async Task CollectOnlineTime(TeamSpeakClient bot, DateTime lastRun) { Console.WriteLine("[>] Collecting online time"); var clients = await bot.GetClients(); var clientInfos = new List <GetClientDetailedInfo>(); foreach (var cl in clients.Where(c => c.Type == ClientType.FullClient)) { clientInfos.Add(await bot.GetClientInfo(cl.Id)); } var trackedClients = new List <GetClientDetailedInfo>(); foreach (var cl in clientInfos.Where(c => c.ServerGroupIds.Any(id => ConfigManager.Config.UserGroups.Contains(id)))) { trackedClients.Add(cl); } bool anyChange = false; foreach (var ci in trackedClients) { anyChange |= UpdateClientTime(lastRun, ci); } if (anyChange) { ClientManager.Save(); } }
private static async Task PokeAdmins(TeamSpeakClient tsClient, ClientMoved client) { var channelId = 2; var groupToPoke = 6; var clients = await tsClient.GetClients(); var toPoke = await tsClient.GetServerGroupClientList(groupToPoke); if (client.TargetChannel == channelId) { foreach (var clid in client.ClientIds) { var clientInfo = await tsClient.GetClientInfo(clid); await tsClient.SendMessage($"Witaj {clientInfo.NickName} na kanale pomocy!", MessageTarget.Private, clid); await tsClient.SendMessage($"Za chwilę jakiś administrator udzieli Ci pomocy.", MessageTarget.Private, clid); foreach (var admin in toPoke) { var seriuslyToPoke = clients.Where(c => c.DatabaseId == admin.ClientDatabaseId); foreach (var oknow in seriuslyToPoke) { await tsClient.PokeClient(oknow.Id, "Ktos czeka na kanale pomocy!"); } } } } }
public async Task RefreshSpeaker(FoundChannel channel, Client Player, List <Client> players) { if (!tsQuery.Client.IsConnected) { return; } try { //Alter kram der rumgebuggt hat //var clients = await tsQuery.GetClients(GetClientOptions.Voice); //var clientschannel = clients.ToList().FindAll(c => c.ChannelId == channel.Id); //var tsplayer = clientschannel.Find(p => p.NickName == name); var name = Player.GetSharedData("TsName"); var currentClients = await tsQuery.GetClients(GetClientOptions.Voice); var tsplayer = currentClients.SingleOrDefault(c => c.NickName == name); if (tsplayer != null) { if (tsplayer.Talk && Player.GetData("IS_SPEAKING") == 0) { 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", 1); } else if (!tsplayer.Talk && Player.GetData("IS_SPEAKING") == 1) { players.FindAll(p => p.Exists && p.Position.DistanceTo2D(Player.Position) < 5f) .ForEach((client) => client.TriggerEvent("Teamspeak_LipSync", Player.Handle.Value, false)); Player.SetData("IS_SPEAKING", 0); } } else { //DISCO falls man es so will später //if(Player.GetData("Eingeloggt") == 1 && NAPI.Player.IsPlayerConnected(Player)) //{ // Player.TriggerEvent("DisconnectTeamspeak"); // Funktionen.SpielerSpeichern(Player); // NAPI.Notification.SendNotificationToPlayer(Player, "~r~Du musst auf unserem Teamspeak sein um den Voice Chat nutzen zu können. IP: ts.strawberry-rp.de"); // //Log Eintrag // Funktionen.LogEintrag(Player, "Nicht auf dem Teamspeak"); // NAPI.Player.KickPlayer(Player, "Nicht auf dem Teamspeak"); //} } } catch (Exception ex) { Console.WriteLine("TS RefreshSpeaker Error: " + ex.ToString()); } }
public async Task <bool> AnyoneOnline() { try { var clients = await tsClient.GetClients(); var channelClients = clients.Where(x => x.Type == ClientType.FullClient && x.ChannelId == 1 && x.DatabaseId != 1045); previousTeamspeakUsers.Clear(); previousTeamspeakUsers.AddRange(Users); Users.Clear(); Users.AddRange(channelClients.Select(x => x.NickName)); var anyoneOnline = channelClients.Count() > 0; if (!anyoneOnline && (DateTime.Now - lastReboot).TotalMinutes > 60 && IsRunning) { await Reboot(); } if ((DateTime.Now - tsClientLifetime).TotalMinutes > 60) { await Reconnect(); } return(anyoneOnline); } catch (Exception e) { logger.LogWarning(e.Message); logger.LogWarning(e.StackTrace); await Reconnect(); } return(false); }
private async Task <List <GetClientInfo> > GetClients() { try { var clients = await _teamSpeakClient.GetClients(GetClientOptions.Uid).TimeoutAfter(TimeSpan.FromSeconds(10)); _cachedClients = clients.ToList(); return(clients.ToList()); } catch (Exception e) { _eventLog1.WriteEntry($"Failed to retrieve CurrentClients using cached version message: {e.Message}", EventLogEntryType.Error); return(_cachedClients); } }
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"); }
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(); }
public async Task RefreshSpeaker(FoundChannel channel, Client player, List <Client> players) { if (!tsQuery.Client.IsConnected) { return; } try { var clients = await tsQuery.GetClients(GetClientOptions.Voice); var clientschannel = clients.ToList().FindAll(c => c.ChannelId == channel.Id); var name = player.GetSharedData("TsName"); var tsplayer = clientschannel.Find(p => p.NickName == name); 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"); } } } catch (Exception ex) { Console.WriteLine("TS RefreshSpeaker Error: " + ex.ToString()); } }
private async Task RespondWhoIsInTeamspeak(MessageArgs arg) { try { var clients = await _teamSpeakClient.GetClients(); var clientNicknames = clients .Where(x => x.Type == ClientType.FullClient) .Select(x => x.NickName) .OrderBy(x => x) .ToArray(); var message = clientNicknames.Length == 0 ? "there are no clients connected" : string.Join("\r\n", clientNicknames); _system.Actor <TelegramMessageChannel>().Tell(new MessageArgs <string>(arg.ChatId, message)); } catch (Exception e) { _logger.LogError(e, "Error occured during querying teamspeak server"); throw; } }
public async Task ExecuteAsync() { if (!await EnsureConnected()) { return; } var clients = await _tsClientConnection.GetClients(); var newClients = clients.Where(c => !c.NickName.Contains(_username) && _clients.Count(i => i.NickName.Equals(c.NickName)) == 0).ToList(); var removedClients = _clients.Where(c => !c.NickName.Contains(_username) && clients.Count(i => i.NickName.Equals(c.NickName)) == 0).ToList(); foreach (var client in newClients) { MessageSender.SendMessage($"{client.NickName} Connected!!"); _clients.Add(client); } foreach (var client in removedClients) { MessageSender.SendMessage($"{client.NickName} Disconnected!!"); _clients.Remove(client); } }
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); } }