Esempio n. 1
0
        private void InitializeDedimaniaClient()
        {
            AuthenticateParameters authParams = new AuthenticateParameters
            {
                Game     = Context.ServerInfo.Version.GetShortName(),
                Login    = Context.ServerInfo.ServerLogin,
                Packmask = Context.ServerInfo.ServerPackMask,
                Nation   = Context.ServerInfo.ServerNation,
                Password = Context.ServerInfo.ServerLoginPassword,
                Tool     = TOOL_NAME,
                Version  = Version.ToString(2)
            };

            // set default timeout of dedimania requests to 10 seconds
            DedimaniaClient = new DedimaniaClient(Settings.AuthUrl, authParams)
            {
                Timeout = 10000
            };
        }
Esempio n. 2
0
        private AuthResult TryAuthentication()
        {
            try
            {
                if (!DedimaniaClient.Authenticate())
                {
                    Logger.ErrorToUI("Authentication failed. Stopping Plugin!");
                    return(AuthResult.Failed);
                }

                return(AuthResult.Success);
            }
            catch (Exception ex)
            {
                Logger.ErrorToUI("Error starting dedimania plugin: " + ex.Message);
                Logger.Error("Error starting dedimania plugin: " + ex);

                return(AuthResult.Erroneous);
            }
        }
Esempio n. 3
0
        private void Callbacks_EndRace(object sender, EndRaceEventArgs e)
        {
            RunCatchLog(() =>
            {
                if (e.Rankings.Count == 0 || !e.Rankings.Exists(ranking => ranking.BestTime != -1))
                {
                    return;
                }

                List <DedimaniaTime> times = new List <DedimaniaTime>();

                foreach (PlayerRank ranking in e.Rankings)
                {
                    if (ranking.BestTime >= 6 * 1000 && CheckpointsValid(ranking.BestCheckpoints))
                    {
                        times.Add(new DedimaniaTime(ranking.Login, ranking.BestTime, ranking.BestCheckpoints));
                    }
                }

                if (times.Count == 0)
                {
                    return;
                }

                GameMode?currentGameMode = GetCurrentGameModeCached(this);
                if (!currentGameMode.HasValue)
                {
                    return;
                }

                ResetUpdateServerPlayersTimer();
                DedimaniaChallengeRaceTimesReply challengeRaceTimesReply = DedimaniaClient.ChallengeRaceTimes(e.Challenge.UId, e.Challenge.Name, e.Challenge.Environnement, e.Challenge.Author, Context.ServerInfo.Version.GetShortName(), (int)currentGameMode.Value, e.Challenge.NumberOfCheckpoints, (int)DedimaniaSettings.MAX_RECORDS_TO_REPORT, times.ToArray());

                if (challengeRaceTimesReply == null)
                {
                    Logger.WarnToUI("Error while calling ChallengeRaceTimes!");
                }
            }, "Error in Callbacks_EndChallenge Method.", true);
        }
Esempio n. 4
0
        private void ReportCurrentChallenge(ICollection <PlayerRank> currentRankings, ChallengeListSingleInfo currentChallenge)
        {
            if (currentChallenge == null)
            {
                return;
            }

            ServerOptions serverOptions = GetServerOptionsCached(this);

            if (serverOptions == null)
            {
                return;
            }

            GameMode?currentGameMode = GetCurrentGameModeCached(this);

            if (!currentGameMode.HasValue)
            {
                return;
            }

            List <PlayerSettings> currentPlayers = Context.PlayerSettings.GetAllAsList();

            List <PlayerSettings>      nonSpectators   = currentPlayers.FindAll(player => !player.SpectatorStatus.IsSpectator);
            List <DedimaniaPlayerInfo> playersToReport = new List <DedimaniaPlayerInfo>();

            foreach (PlayerSettings playerSettings in nonSpectators)
            {
                playersToReport.Add(new DedimaniaPlayerInfo(playerSettings.Login, string.Empty, string.Empty, playerSettings.TeamID, playerSettings.SpectatorStatus.IsSpectator, playerSettings.LadderRanking, playerSettings.IsInOfficialMode));
            }

            int playersCount               = playersToReport.Count;
            int spectatorsCount            = currentPlayers.Count - playersCount;
            DedimaniaServerInfo serverInfo = new DedimaniaServerInfo(serverOptions.Name, serverOptions.Comment, serverOptions.Password.Length > 0, string.Empty, 0, Context.ServerInfo.ServerXMLRpcPort, playersCount, serverOptions.CurrentMaxPlayers, spectatorsCount, serverOptions.CurrentMaxSpectators, serverOptions.CurrentLadderMode, string.Empty);

            DedimaniaCurrentChallengeReply currentChallengeReply = null;

            try
            {
                currentChallengeReply = DedimaniaClient.CurrentChallenge(currentChallenge.UId, currentChallenge.Name, currentChallenge.Environnement, currentChallenge.Author, Context.ServerInfo.Version.GetShortName(), (int)currentGameMode.Value, serverInfo, (int)DedimaniaSettings.MAX_RECORDS_TO_REPORT, playersToReport.ToArray());
                IsDedimaniaResponsive = true;
            }
            catch (Exception ex)
            {
                Logger.ErrorToUI("Could not report current challenge: " + ex.Message);
                Logger.Error("Could not report current challenge: " + ex);
                IsDedimaniaResponsive = false;
            }

            if (currentChallengeReply != null)
            {
                FillRankingsFromDedimania(currentChallengeReply.Records, currentRankings);
                BestTime = Rankings.Length == 0 ? null : (uint?)Rankings[0].TimeOrScore;
            }
            else
            {
                Rankings = new DedimaniaRanking[] {};
                BestTime = null;

                if (IsDedimaniaResponsive)
                {
                    Logger.Debug("Error while calling CurrentChallenge!");
                }
            }

            OnRankingsChanged(Rankings);
        }