From 1722f42f83275392bede9fb0015ad319f59775e5 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 17 Apr 2017 09:42:49 +0000 Subject: [PATCH] Move web urls from user config to mod config. --- OpenRA.Game/Map/MapCache.cs | 4 ++-- OpenRA.Game/Map/MapPreview.cs | 9 ++++---- OpenRA.Game/Settings.cs | 4 ---- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../ServerTraits/LobbyCommands.cs | 3 ++- .../ServerTraits/MasterServerPinger.cs | 3 ++- OpenRA.Mods.Common/WebServices.cs | 22 +++++++++++++++++++ .../Widgets/Logic/Lobby/LobbyLogic.cs | 5 ++++- .../Logic/Lobby/LobbyMapPreviewLogic.cs | 9 +++++--- .../Widgets/Logic/MainMenuLogic.cs | 10 +++++---- .../Widgets/Logic/MultiplayerLogic.cs | 7 ++++-- 11 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 OpenRA.Mods.Common/WebServices.cs diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index 6a1220d82b..288bac5d2a 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -113,7 +113,7 @@ namespace OpenRA } } - public void QueryRemoteMapDetails(IEnumerable uids, Action mapDetailsReceived = null, Action queryFailed = null) + public void QueryRemoteMapDetails(string repositoryUrl, IEnumerable uids, Action mapDetailsReceived = null, Action queryFailed = null) { var maps = uids.Distinct() .Select(uid => previews[uid]) @@ -126,7 +126,7 @@ namespace OpenRA foreach (var p in maps.Values) p.UpdateRemoteSearch(MapStatus.Searching, null); - var url = Game.Settings.Game.MapRepository + "hash/" + string.Join(",", maps.Keys) + "/yaml"; + var url = repositoryUrl + "hash/" + string.Join(",", maps.Keys) + "/yaml"; Action onInfoComplete = i => { diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index 376ec63f5a..ef0ca34c0e 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -123,8 +123,8 @@ namespace OpenRA } static readonly CPos[] NoSpawns = new CPos[] { }; - MapCache cache; - ModData modData; + readonly MapCache cache; + readonly ModData modData; public readonly string Uid; public IReadOnlyPackage Package { get; private set; } @@ -416,7 +416,7 @@ namespace OpenRA innerData = newData; } - public void Install(Action onSuccess) + public void Install(string mapRepositoryUrl, Action onSuccess) { if (Status != MapStatus.DownloadAvailable || !Game.Settings.Game.AllowDownloading) return; @@ -431,12 +431,11 @@ namespace OpenRA } var mapInstallPackage = installLocation.Key as IReadWritePackage; - var modData = Game.ModData; new Thread(() => { // Request the filename from the server // Run in a worker thread to avoid network delays - var mapUrl = Game.Settings.Game.MapRepository + Uid; + var mapUrl = mapRepositoryUrl + Uid; var mapFilename = string.Empty; try { diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index fdb85236b3..50923b1193 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -51,8 +51,6 @@ namespace OpenRA [Desc("Locks the game with a password.")] public string Password = ""; - public string MasterServer = "http://master.openra.net/"; - [Desc("Allow users to enable NAT discovery for external IP detection and automatic port forwarding.")] public bool DiscoverNatDevices = false; @@ -175,13 +173,11 @@ namespace OpenRA public bool DrawTargetLine = true; public bool AllowDownloading = true; - public string MapRepository = "http://resource.openra.net/map/"; public bool AllowZoom = true; public Modifiers ZoomModifier = Modifiers.Ctrl; public bool FetchNews = true; - public string NewsUrl = "http://master.openra.net/gamenews"; public MPGameFilters MPGameFilters = MPGameFilters.Waiting | MPGameFilters.Empty | MPGameFilters.Protected | MPGameFilters.Started; } diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 1d05253fa4..c3011d027e 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -799,6 +799,7 @@ + diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index 8afa8fcfdd..9fffa25a2b 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -420,7 +420,8 @@ namespace OpenRA.Mods.Common.Server else if (server.Settings.QueryMapRepository) { server.SendOrderTo(conn, "Message", "Searching for map on the Resource Center..."); - server.ModData.MapCache.QueryRemoteMapDetails(new[] { s }, selectMap, queryFailed); + var mapRepository = server.ModData.Manifest.Get().MapRepository; + server.ModData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { s }, selectMap, queryFailed); } else queryFailed(); diff --git a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs index 75b2c3d316..cb11758db8 100644 --- a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs +++ b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs @@ -70,11 +70,12 @@ namespace OpenRA.Mods.Common.Server var url = "ping?port={0}&name={1}&state={2}&players={3}&bots={4}&mods={5}&map={6}&maxplayers={7}&spectators={8}&protected={9}&clients={10}"; if (isInitialPing) url += "&new=1"; + var serverList = server.ModData.Manifest.Get().ServerList; using (var wc = new WebClient()) { wc.Proxy = null; var masterResponse = wc.DownloadData( - server.Settings.MasterServer + url.F( + serverList + url.F( server.Settings.ExternalPort, Uri.EscapeUriString(server.Settings.Name), (int)server.State, numPlayers, diff --git a/OpenRA.Mods.Common/WebServices.cs b/OpenRA.Mods.Common/WebServices.cs new file mode 100644 index 0000000000..f26075a3fc --- /dev/null +++ b/OpenRA.Mods.Common/WebServices.cs @@ -0,0 +1,22 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; + +namespace OpenRA +{ + public class WebServices : IGlobalModData + { + public readonly string ServerList = "http://master.openra.net/"; + public readonly string MapRepository = "http://resource.openra.net/map/"; + public readonly string GameNews = "http://master.openra.net/gamenews"; + } +} diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index b9500e8aac..30c70e0c58 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -36,6 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly bool skirmishMode; readonly Ruleset modRules; readonly World shellmapWorld; + readonly WebServices services; enum PanelType { Players, Options, Music, Kick, ForceStart } PanelType panel = PanelType.Players; @@ -117,6 +118,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic this.modRules = modData.DefaultRules; shellmapWorld = worldRenderer.World; + services = modData.Manifest.Get(); + orderManager.AddChatLine += AddChatLine; Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdatePlayerList; @@ -655,7 +658,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic else if (Map.Status == MapStatus.DownloadAvailable) LoadMapPreviewRules(Map); else if (Game.Settings.Game.AllowDownloading) - modData.MapCache.QueryRemoteMapDetails(new[] { uid }, LoadMapPreviewRules); + modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { uid }, LoadMapPreviewRules); } void UpdatePlayerList() diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyMapPreviewLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyMapPreviewLogic.cs index 124b5851d8..cde1c80dcd 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyMapPreviewLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyMapPreviewLogic.cs @@ -24,6 +24,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] internal LobbyMapPreviewLogic(Widget widget, ModData modData, OrderManager orderManager, LobbyLogic lobby) { + var mapRepository = modData.Manifest.Get().MapRepository; + var available = widget.GetOrNull("MAP_AVAILABLE"); if (available != null) { @@ -109,11 +111,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic var install = download.GetOrNull("MAP_INSTALL"); if (install != null) { - install.OnClick = () => lobby.Map.Install(() => + install.OnClick = () => lobby.Map.Install(mapRepository, () => { lobby.Map.PreloadRules(); Game.RunAfterTick(() => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)))); }); + install.IsHighlighted = () => installHighlighted; } } @@ -178,9 +181,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic retry.OnClick = () => { if (lobby.Map.Status == MapStatus.DownloadError) - lobby.Map.Install(() => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)))); + lobby.Map.Install(mapRepository, () => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)))); else if (lobby.Map.Status == MapStatus.Unavailable) - modData.MapCache.QueryRemoteMapDetails(new[] { lobby.Map.Uid }); + modData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { lobby.Map.Uid }); }; retry.GetText = () => lobby.Map.Status == MapStatus.DownloadError ? "Retry Install" : "Retry Search"; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index c73f074a57..7b98c42b00 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -235,6 +235,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.OnRemoteDirectConnect += OnRemoteDirectConnect; + var newsURL = modData.Manifest.Get().GameNews; + // System information opt-out prompt var sysInfoPrompt = widget.Get("SYSTEM_INFO_PROMPT"); sysInfoPrompt.IsVisible = () => menuType == MenuType.SystemInfoPrompt; @@ -263,14 +265,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.Settings.Debug.SystemInformationVersionPrompt = SystemInformationVersion; Game.Settings.Save(); SwitchMenu(MenuType.Main); - LoadAndDisplayNews(newsBG); + LoadAndDisplayNews(newsURL, newsBG); }; } else - LoadAndDisplayNews(newsBG); + LoadAndDisplayNews(newsURL, newsBG); } - void LoadAndDisplayNews(Widget newsBG) + void LoadAndDisplayNews(string newsURL, Widget newsBG) { if (newsBG != null) { @@ -285,7 +287,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (!fetchedNews) { // Send the mod and engine version to support version-filtered news (update prompts) - var newsURL = Game.Settings.Game.NewsUrl + "?version={0}&mod={1}&modversion={2}".F( + newsURL += "?version={0}&mod={1}&modversion={2}".F( Uri.EscapeUriString(Game.Mods["modchooser"].Metadata.Version), Uri.EscapeUriString(Game.ModData.Manifest.Id), Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version)); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs index b094b866f0..bc006f4f80 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs @@ -38,6 +38,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Color gameStartedColor; readonly Color incompatibleGameColor; readonly ModData modData; + readonly WebServices services; GameServer currentServer; MapPreview currentMap; @@ -70,6 +71,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic this.onStart = onStart; this.onExit = onExit; + services = modData.Manifest.Get(); + incompatibleVersionColor = ChromeMetrics.Get("IncompatibleVersionColor"); incompatibleGameColor = ChromeMetrics.Get("IncompatibleGameColor"); incompatibleProtectedGameColor = ChromeMetrics.Get("IncompatibleProtectedGameColor"); @@ -322,7 +325,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.RunAfterTick(() => RefreshServerListInner(games)); }; - var queryURL = Game.Settings.Server.MasterServer + "games?version={0}&mod={1}&modversion={2}".F( + var queryURL = services.ServerList + "games?version={0}&mod={1}&modversion={2}".F( Uri.EscapeUriString(Game.Mods["modchooser"].Metadata.Version), Uri.EscapeUriString(Game.ModData.Manifest.Id), Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version)); @@ -476,7 +479,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Search for any unknown maps if (Game.Settings.Game.AllowDownloading) - modData.MapCache.QueryRemoteMapDetails(games.Where(g => !Filtered(g)).Select(g => g.Map)); + modData.MapCache.QueryRemoteMapDetails(services.MapRepository, games.Where(g => !Filtered(g)).Select(g => g.Map)); foreach (var row in rows) serverList.AddChild(row);