/// <summary> /// Does the server query. /// </summary> /// <param name="player">The player.</param> /// <param name="usePrivate"> /// if set to <c>true</c> then query private (private 1) servers. otherwise query public /// (private 0) servers. /// </param> /// <returns>The results of the query as a <see cref="FilterObject"/> object.</returns> private async Task <FilterObject> DoServerQuery(string player, bool usePrivate) { var qlInfoRetriever = new QlRemoteInfoRetriever(); var query = await qlInfoRetriever.GetServerDataFromFilter(MakeEncodedFilter(player, usePrivate)); return(query); }
/// <summary> /// Gets the server details from the QL API. /// </summary> /// <param name="serverId">The server identifier.</param> /// <returns>The server as a <see cref="Server"/> object.</returns> private async Task <Server> GetServerDetails(string serverId) { if (string.IsNullOrEmpty(serverId)) { return(null); } var qlRetr = new QlRemoteInfoRetriever(); var srv = await qlRetr.QueryQlServer(serverId); return(srv); }
/// <summary> /// Lists the active servers. /// </summary> /// <param name="c">The command argument information.</param> private async Task ListActiveServers(Cmd c) { // StringBuilder so we can send multiple servers to IRC var gameTypeInfo = GetGameTypesFromAbreviation(Helpers.GetArgVal(c, 1)); var location = GetLocationFromRegion(Helpers.GetArgVal(c, 2)); var encodedFilter = Convert.ToBase64String( Encoding.UTF8.GetBytes("{\"filters\":{\"group\":\"any\",\"game_type\":\"" + gameTypeInfo[0] + "\",\"arena\":\"any\",\"state\":\"POPULATED\",\"difficulty\":\"any\",\"location\":\"" + location + "\",\"private\":0,\"premium_only\":0,\"ranked\":\"any\",\"invitation_only\":0}," + "\"arena_type\":\"\",\"players\":[],\"game_types\":" + gameTypeInfo[1] + ",\"ig\":0}")); var qlInfoRetriever = new QlRemoteInfoRetriever(); var fObj = await qlInfoRetriever.GetServerDataFromFilter(encodedFilter); if (fObj == null) { StatusMessage = "^1[ERROR]^3 Problem retrieving server list, try again later."; // send as /say (success) to let everyone know in this case await SendServerSay(c, StatusMessage); Log.Write("Error retrieving server list.", _logClassType, _logPrefix); return; } if (fObj.servers.Count == 0) { StatusMessage = string.Format("^4[ACTIVESERVERS]^7 There are ^1NO^7 active ^2{0}^7 servers in ^2{1}", Helpers.GetArgVal(c, 1), location); await SendServerSay(c, StatusMessage); Log.Write(string.Format("No active servers matched the user's query: {0} {1}", Helpers.GetArgVal(c, 1), Helpers.GetArgVal(c, 2)), _logClassType, _logPrefix); return; } var qlLoc = new QlLocations(); // StringBuilder so we can send multiple servers to IRC var sb = new StringBuilder(); sb.Append( string.Format("^4[ACTIVESERVERS]^7 Showing up to^2 {0} ^7active ^2{1}^7 servers in ^2{2}:{3}", _sst.Mod.Servers.MaxServersToDisplay, Helpers.GetArgVal(c, 1).ToUpper(), location, Environment.NewLine)); for (var i = 0; i < fObj.servers.Count; i++) { if (i == _sst.Mod.Servers.MaxServersToDisplay) { break; } var country = qlLoc.GetLocationNameFromId(fObj.servers[i].location_id); sb.Append(string.Format("^7{0}[^5{1}^7] {2} (^2{3}/{4}^7) @ ^4{5}{6}", (fObj.servers[i].g_needpass == 1 ? "[PW]" : string.Empty), country, fObj.servers[i].map, fObj.servers[i].num_clients, fObj.servers[i].max_clients, fObj.servers[i].host_address, Environment.NewLine)); } StatusMessage = sb.ToString(); await SendServerSay(c, StatusMessage); Log.Write(string.Format( "Displayed up to {0} servers that matched users query: {1} {2}", _sst.Mod.Servers.MaxServersToDisplay, Helpers.GetArgVal(c, 1), Helpers.GetArgVal(c, 2)), _logClassType, _logPrefix); }