Beispiel #1
0
        private XElement GetPlayerRecordElement(RankEntry rankingInfo, double currentY, uint currentRank, string login)
        {
            string templateXML = Settings.RecordListRecordTemplate;

            if (rankingInfo.Login == login)
            {
                templateXML = Settings.RecordListRecordHighlightTemplate;
            }
            else if (currentRank <= 3)
            {
                templateXML = Settings.RecordListTop3RecordTemplate;
            }

            TimeSpan time = TimeSpan.FromMilliseconds(rankingInfo.TimeOrScore);

            StringBuilder playerRecordXml = new StringBuilder(templateXML);

            playerRecordXml.Replace("{[Y]}", currentY.ToString(CultureInfo.InvariantCulture));
            playerRecordXml.Replace("{[Rank]}", currentRank + ".");
            playerRecordXml.Replace("{[TimeOrScore]}", rankingInfo.TimeOrScore == 0 ? "  --.--  " : string.Format("{0}:{1}.{2}", time.Minutes, time.Seconds.ToString("00"), (time.Milliseconds / 10).ToString("00")));

            string nickname = SecurityElement.Escape(rankingInfo.Nickname);

            if (Settings.StripNickFormatting)
            {
                nickname = StripTMColorsAndFormatting(nickname);
            }

            playerRecordXml.Replace("{[Nickname]}", nickname);

            return(XElement.Parse(playerRecordXml.ToString()));
        }
Beispiel #2
0
        protected override void Init()
        {
            LastRankings = new RankEntry[] { };
            Settings     = LocalRecordsUISettings.ReadFromFile(PluginSettingsFilePath);

            if (Settings.MaxRecordsToShow > HostPlugin.Settings.MaxRecordsToReport)
            {
                Settings.MaxRecordsToShow = HostPlugin.Settings.MaxRecordsToReport;
            }

            UpdateListTimer        = new TimedVolatileExecutionQueue <RankEntry[]>(TimeSpan.FromSeconds(Settings.UpdateInterval));
            UpdateLocalRecordTimer = new TimedVolatileExecutionQueue <string>(TimeSpan.FromSeconds(Settings.UpdateInterval));

            //SendPBManiaLinkPageToAll(null);
            HostPlugin.PlayerNewRecord                += HostPlugin_PlayerNewRecord;
            HostPlugin.LocalRecordsDetermined         += HostPlugin_LocalRecordsDetermined;
            HostPlugin.PlayerWins                     += HostPlugin_PlayerWins;
            Context.RPCClient.Callbacks.EndRace       += Callbacks_EndRace;
            Context.RPCClient.Callbacks.PlayerConnect += Callbacks_PlayerConnect;
            Context.RPCClient.Callbacks.PlayerChat    += Callbacks_PlayerChat;
        }
Beispiel #3
0
        private void SendPBManiaLinkPageToAll(RankEntry[] rankEntries)
        {
            if (rankEntries == null)
            {
                rankEntries = new RankEntry[] { }
            }
            ;

            foreach (PlayerSettings playerSettings in Context.PlayerSettings.GetAllAsList())
            {
                RankEntry rank = Array.Find(rankEntries, rankEntry => rankEntry.Login == playerSettings.Login);

                uint?personalBest = rank == null ? null : (uint?)rank.TimeOrScore;

                if (!personalBest.HasValue)
                {
                    personalBest = HostPlugin.RecordAdapter.GetBestTime(playerSettings.Login, HostPlugin.CurrentChallengeID);
                }


                SendPBManiaLinkPage(playerSettings.Login, personalBest);
            }
        }
Beispiel #4
0
        private bool CheckForListLocalLoginsCommand(PlayerChatEventArgs args)
        {
            if (args.IsServerMessage || args.Text.IsNullOrTimmedEmpty())
            {
                return(false);
            }

            ServerCommand command = ServerCommand.Parse(args.Text);

            if (!command.Is(Command.GetLocalLogins))
            {
                return(false);
            }

            if (!LoginHasRight(args.Login, true, Command.GetLocalLogins))
            {
                return(true);
            }

            DetermineLocalRecords();

            StringBuilder msg = new StringBuilder("Local logins: ");

            for (int i = 0; i < LocalRecords.Length; i++)
            {
                if (i != 0)
                {
                    msg.Append(", ");
                }
                RankEntry entry = LocalRecords[i];
                msg.AppendFormat("{0}. {1}$z[{2}]", i + 1, entry.Nickname, entry.Login);
            }

            SendFormattedMessageToLogin(args.Login, msg.ToString());
            return(true);
        }
Beispiel #5
0
        public static SortedList <uint, RankEntry> GetRankingsToShow(RankEntry[] rankings, string login, uint maxRecordsToShow, uint maxRecordsToReport)
        {
            // show at least the top 3
            maxRecordsToShow   = (uint)Math.Max(Math.Min(Math.Min(maxRecordsToShow, maxRecordsToReport), rankings.Length), 3);
            maxRecordsToReport = (uint)Math.Min(rankings.Length, maxRecordsToReport);

            // set maxRecordsToShow to amount of existing rankings when the amoutn of rankings is less than the value of maxRecordsToShow
            if (rankings.Length < maxRecordsToShow && rankings.Length > 3)
            {
                maxRecordsToShow = Convert.ToUInt32(rankings.Length);
            }

            int currentPlayerRankIndex = Array.FindIndex(rankings, ranking => ranking.Login == login);

            SortedList <uint, RankEntry> result = new SortedList <uint, RankEntry>();

            // always add the first 3 records, replace non existing records with empty ones
            for (uint i = 1; i <= 3; i++)
            {
                RankEntry currentRank = rankings.Length >= i ? rankings[i - 1] : new RankEntry((ushort)i, string.Empty, string.Empty, 0);
                result.Add(i, currentRank);
            }

            // leave if no more records left
            if (maxRecordsToShow <= 3)
            {
                return(result);
            }

            uint amountOfRecordsLeft = maxRecordsToShow - 3;
            uint upperLimitLeft      = 4 + ((maxRecordsToReport - 3) / 2) + ((maxRecordsToReport - 3) % 2);
            uint lowerLimitRight     = upperLimitLeft;

            if (currentPlayerRankIndex != -1 && currentPlayerRankIndex > 2 && currentPlayerRankIndex < maxRecordsToReport)
            {
                result.Add((uint)(currentPlayerRankIndex + 1), rankings[currentPlayerRankIndex]);
                amountOfRecordsLeft--;

                upperLimitLeft  = (uint)currentPlayerRankIndex + 1;
                lowerLimitRight = (uint)(currentPlayerRankIndex + 2);
            }

            List <uint> ranksBeforePlayerRank = new List <uint>();

            for (uint i = 4; i < upperLimitLeft; i++)
            {
                ranksBeforePlayerRank.Add(i);
            }

            List <uint> ranksAfterPlayerRank = new List <uint>();

            for (uint i = lowerLimitRight; i <= maxRecordsToReport; i++)
            {
                ranksAfterPlayerRank.Add(i);
            }

            uint leftAmount  = (amountOfRecordsLeft / 2) + (amountOfRecordsLeft % 2);
            uint rightAmount = (amountOfRecordsLeft / 2);

            if (leftAmount > ranksBeforePlayerRank.Count)
            {
                uint diff = leftAmount - (uint)ranksBeforePlayerRank.Count;
                leftAmount   = (uint)ranksBeforePlayerRank.Count;
                rightAmount += diff;
            }

            if (rightAmount > ranksAfterPlayerRank.Count)
            {
                uint diff = rightAmount - (uint)ranksAfterPlayerRank.Count;
                rightAmount = (uint)ranksAfterPlayerRank.Count;
                leftAmount += diff;
            }

            uint leftAmountStart = leftAmount, leftAmountEnd = 0;
            uint rightAmountStart = 0, rightAmountEnd = rightAmount;

            if (currentPlayerRankIndex != -1 && currentPlayerRankIndex > 2)
            {
                leftAmountStart  = (leftAmount / 2);
                leftAmountEnd    = (leftAmount / 2) + (leftAmount % 2);
                rightAmountStart = (rightAmount / 2);
                rightAmountEnd   = (rightAmount / 2) + (rightAmount % 2);
            }

            for (int i = 0; i < leftAmountStart; i++)
            {
                result.Add(ranksBeforePlayerRank[i], rankings[ranksBeforePlayerRank[i] - 1]);
            }

            for (int i = ranksBeforePlayerRank.Count - 1; i > (ranksBeforePlayerRank.Count - 1) - leftAmountEnd; i--)
            {
                result.Add(ranksBeforePlayerRank[i], rankings[ranksBeforePlayerRank[i] - 1]);
            }

            for (int i = 0; i < rightAmountStart; i++)
            {
                result.Add(ranksAfterPlayerRank[i], rankings[ranksAfterPlayerRank[i] - 1]);
            }

            for (int i = ranksAfterPlayerRank.Count - 1; i > (ranksAfterPlayerRank.Count - 1) - rightAmountEnd; i--)
            {
                result.Add(ranksAfterPlayerRank[i], rankings[ranksAfterPlayerRank[i] - 1]);
            }

            return(result);
        }