Example #1
0
        /// <summary>
        /// Displays the search results.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <param name="server">The server.</param>
        private async Task DisplaySearchResults(Cmd c, Server server)
        {
            var qlLoc   = new QlLocations();
            var country = qlLoc.GetLocationNameFromId(server.location_id);

            StatusMessage = string.Format("^6[PLAYERFINDER] ^7Found ^3{0}^7 on [^5{1}^7] {2} (^2{3}/{4}^7) @ ^4{5}",
                                          Helpers.GetArgVal(c, 1), country, server.map, server.num_clients, server.max_clients,
                                          server.host_address);
            await SendServerSay(c, StatusMessage);

            Log.Write(string.Format(
                          "Found player {0} on ({1} | {2}, {3}/{4}) at {5}",
                          Helpers.GetArgVal(c, 1), country, server.map, server.num_clients, server.max_clients,
                          server.host_address), _logClassType, _logPrefix);
        }
Example #2
0
        /// <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);
        }