private async Task <StatusModel> GetServerStatusAsync(Configuration.Server server) { if (_cache.TryGetValue(server.Id, out StatusModel model)) { return(model); } model = new StatusModel() { Name = server.Name, Address = $"byond://{server.Host}:{server.Port}" }; var response = await ByondTopic.SendTopicCommandAsync(server.Host, server.Port.ToString(), StatusCommand); if (response == null || string.IsNullOrWhiteSpace(response)) { model.Online = false; } else { var parsedResponse = QueryHelpers.ParseQuery(response); model.Players = int.Parse(parsedResponse["players"]); model.Admins = int.Parse(parsedResponse["admins"]); model.RoundDuration = parsedResponse["roundduration"]; model.Online = true; } _cache.Set(server.Id, model, TimeSpan.FromSeconds(5)); return(model); }
private async Task UpdatePlayersInternalAsync() { if (DateTime.Now - _playersUpdatedTimestamp >= TimeSpan.FromSeconds(30)) { string response = await ByondTopic.GetDataAsync("127.0.0.1", Status.Port.ToString(), "status"); if (response == null) { return; } var parsedResponse = QueryHelpers.ParseQuery(response); Status.Players = int.Parse(parsedResponse["players"]); Status.Admins = int.Parse(parsedResponse["admins"]); _playersUpdatedTimestamp = DateTime.Now; } }
public async Task <ServerInfoModel> GetInfo(ServerMonitorModel serverMonitor) { var responce = await ByondTopic.GetData(serverMonitor.Ip, serverMonitor.Port, GetStatusCommand); return(ParseByondResponce(responce)); }