private static void UpdateServerPlayers(object state) { DedimaniaPlugin plugin = (DedimaniaPlugin)state; RunCatchLog(() => { ServerOptions serverOptions = GetServerOptionsCached(plugin); if (serverOptions == null) { return; } GameMode?currentGameMode = GetCurrentGameModeCached(plugin); if (!currentGameMode.HasValue) { return; } List <PlayerSettings> currentPlayers = plugin.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, plugin.Context.ServerInfo.ServerXMLRpcPort, playersCount, serverOptions.CurrentMaxPlayers, spectatorsCount, serverOptions.CurrentMaxSpectators, serverOptions.CurrentLadderMode, string.Empty); if (!plugin.DedimaniaClient.UpdateServerPlayers(plugin.Context.ServerInfo.Version.GetShortName(), (int)currentGameMode.Value, serverInfo, playersToReport.ToArray())) { plugin.Logger.WarnToUI("Error while calling UpdateServerPlayers!"); } }, "Error in Callbacks_BeginRace Method.", true, plugin.Logger); }
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); }