Пример #1
0
        /// <summary>
        /// Request current online players from the gameserver
        /// <para>This includes players who are still in process of joining the server but aren't actually in the server yet e.g. loading the map</para>
        /// </summary>
        /// <param name="currentBotHelper">Instance of the BotHelper to be able to send inbetween Telegram messages when failures occur</param>
        /// <param name="chatId">Id of the current chat request to be able to send inbetween Telegram messages when failures occur</param>
        /// <param name="playerMessage">Id of the current chat request to be able to send inbetween Telegram messages when failures occur</param>
        /// <returns></returns>
        public List <PlayerInfo> GetPlayers(BotHelper currentBotHelper, long chatId, string playerMessage)
        {
            Config.Log("GetPlayers(): Called");
            int retries = 0;
            QueryMasterCollection <PlayerInfo> playerList = new QueryMasterCollection <PlayerInfo>(new List <PlayerInfo>());

            while (playerList.Count < 1 && retries < attemptRetries)
            {
                playerList = CurrentServer.GetPlayers();
                if (playerList == null)
                {
                    playerList = new QueryMasterCollection <PlayerInfo>(new List <PlayerInfo>());
                }

                CurrentServer.Dispose();

                if (retries == 1 && playerList.Count < 1)
                {
                    currentBotHelper.SendMessageNew(chatId, $"{playerMessage} Unable to request playerlist\r\n\r\nRetrying...please wait\r\n");
                    CurrentServer = ServerQuery.GetServerInstance(EngineType.Source, Config.ServerIP, Config.ServerPort, false, serverSendTimeOut + 1000, serverReceiveTimeOut + 1000, requestAmount + 2, false);
                }
                else
                {
                    CurrentServer = ServerQuery.GetServerInstance(EngineType.Source, Config.ServerIP, Config.ServerPort, false, serverSendTimeOut, serverReceiveTimeOut, requestAmount, false);
                }

                retries++;
                Config.Log($"GetPlayers(): List count: {playerList.Count}  Try {retries}");
            }

            List <PlayerInfo> sortedList = new List <PlayerInfo>();

            if (playerList.Count > 1)
            {
                Config.Log("GetPlayers(): Sorting list...");
                sortedList = playerList.ToList();
                sortedList = sortedList.OrderBy(playerInfo => playerInfo.Name).ToList();
            }

            Config.Log($"GetPlayers(): Done. {retries} retries needed");

            return(sortedList);
        }
Пример #2
0
        /// <summary>
        /// Request current ruleset from the gameserver
        /// <para>Be aware that this can be an instensive request and in general could take a few tries.
        /// It's an extensive set, atm only used for finding the next map. You could use it to provide more information/functionality to the Telegram user</para></summary>
        /// <param name="currentBotHelper">Instance of the BotHelper to be able to send inbetween Telegram messages when failures occur</param>
        /// <param name="chatId">Id of the current chat request to be able to send inbetween Telegram messages when failures occur</param>
        /// <param name="playerMessage">Id of the current chat request to be able to send inbetween Telegram messages when failures occur</param>
        /// <returns></returns>
        public List <Rule> GetRules(BotHelper currentBotHelper, long chatId, string mapMessage)
        {
            int retries = 0;

            QueryMasterCollection <Rule> rulesCollection = new QueryMasterCollection <Rule>(new List <Rule>());

            while (rulesCollection.Count < 1 && retries < attemptRetries)
            {
                rulesCollection = CurrentServer.GetRules();
                if (rulesCollection == null)
                {
                    rulesCollection = new QueryMasterCollection <Rule>(new List <Rule>());
                }

                CurrentServer.Dispose();
                CurrentServer = ServerQuery.GetServerInstance(EngineType.Source, Config.ServerIP, Config.ServerPort, false, serverSendTimeOut, serverReceiveTimeOut, requestAmount, false);

                if (retries == 1 && rulesCollection.Count < 1)
                {
                    currentBotHelper.SendMessageNew(chatId, mapMessage + "Unable to request rulesset\r\n\r\nRetrying...please wait\r\n");
                    CurrentServer = ServerQuery.GetServerInstance(EngineType.Source, Config.ServerIP, Config.ServerPort, false, serverSendTimeOut + 1000, serverReceiveTimeOut + 1000, requestAmount + 2, false);
                }
                else
                {
                    CurrentServer = ServerQuery.GetServerInstance(EngineType.Source, Config.ServerIP, Config.ServerPort, false, serverSendTimeOut, serverReceiveTimeOut, requestAmount, false);
                }

                retries++;
                Config.Log($"GetRules(): List count: {rulesCollection.Count} Try {retries}");
            }

            List <Rule> rulesList = new List <Rule>();

            if (rulesCollection.Count > 1)
            {
                Config.Log("GetRules(): Sorting list...");
                rulesList = rulesCollection.ToList();
            }

            Config.Log($"GetRules(): Done. {retries} retries needed");

            return(rulesList);
        }