Merge pull request #13141 from pchote/mod-urls

Move web urls from user config to mod config.
This commit is contained in:
Oliver Brakmann
2017-04-17 17:13:52 +02:00
committed by GitHub
11 changed files with 54 additions and 23 deletions

View File

@@ -113,7 +113,7 @@ namespace OpenRA
} }
} }
public void QueryRemoteMapDetails(IEnumerable<string> uids, Action<MapPreview> mapDetailsReceived = null, Action queryFailed = null) public void QueryRemoteMapDetails(string repositoryUrl, IEnumerable<string> uids, Action<MapPreview> mapDetailsReceived = null, Action queryFailed = null)
{ {
var maps = uids.Distinct() var maps = uids.Distinct()
.Select(uid => previews[uid]) .Select(uid => previews[uid])
@@ -126,7 +126,7 @@ namespace OpenRA
foreach (var p in maps.Values) foreach (var p in maps.Values)
p.UpdateRemoteSearch(MapStatus.Searching, null); 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<DownloadDataCompletedEventArgs> onInfoComplete = i => Action<DownloadDataCompletedEventArgs> onInfoComplete = i =>
{ {

View File

@@ -123,8 +123,8 @@ namespace OpenRA
} }
static readonly CPos[] NoSpawns = new CPos[] { }; static readonly CPos[] NoSpawns = new CPos[] { };
MapCache cache; readonly MapCache cache;
ModData modData; readonly ModData modData;
public readonly string Uid; public readonly string Uid;
public IReadOnlyPackage Package { get; private set; } public IReadOnlyPackage Package { get; private set; }
@@ -416,7 +416,7 @@ namespace OpenRA
innerData = newData; innerData = newData;
} }
public void Install(Action onSuccess) public void Install(string mapRepositoryUrl, Action onSuccess)
{ {
if (Status != MapStatus.DownloadAvailable || !Game.Settings.Game.AllowDownloading) if (Status != MapStatus.DownloadAvailable || !Game.Settings.Game.AllowDownloading)
return; return;
@@ -431,12 +431,11 @@ namespace OpenRA
} }
var mapInstallPackage = installLocation.Key as IReadWritePackage; var mapInstallPackage = installLocation.Key as IReadWritePackage;
var modData = Game.ModData;
new Thread(() => new Thread(() =>
{ {
// Request the filename from the server // Request the filename from the server
// Run in a worker thread to avoid network delays // Run in a worker thread to avoid network delays
var mapUrl = Game.Settings.Game.MapRepository + Uid; var mapUrl = mapRepositoryUrl + Uid;
var mapFilename = string.Empty; var mapFilename = string.Empty;
try try
{ {

View File

@@ -51,8 +51,6 @@ namespace OpenRA
[Desc("Locks the game with a password.")] [Desc("Locks the game with a password.")]
public string 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.")] [Desc("Allow users to enable NAT discovery for external IP detection and automatic port forwarding.")]
public bool DiscoverNatDevices = false; public bool DiscoverNatDevices = false;
@@ -175,13 +173,11 @@ namespace OpenRA
public bool DrawTargetLine = true; public bool DrawTargetLine = true;
public bool AllowDownloading = true; public bool AllowDownloading = true;
public string MapRepository = "http://resource.openra.net/map/";
public bool AllowZoom = true; public bool AllowZoom = true;
public Modifiers ZoomModifier = Modifiers.Ctrl; public Modifiers ZoomModifier = Modifiers.Ctrl;
public bool FetchNews = true; public bool FetchNews = true;
public string NewsUrl = "http://master.openra.net/gamenews";
public MPGameFilters MPGameFilters = MPGameFilters.Waiting | MPGameFilters.Empty | MPGameFilters.Protected | MPGameFilters.Started; public MPGameFilters MPGameFilters = MPGameFilters.Waiting | MPGameFilters.Empty | MPGameFilters.Protected | MPGameFilters.Started;
} }

View File

@@ -801,6 +801,7 @@
<Compile Include="Traits\Attack\AttackCharges.cs" /> <Compile Include="Traits\Attack\AttackCharges.cs" />
<Compile Include="Traits\Render\WithChargeAnimation.cs" /> <Compile Include="Traits\Render\WithChargeAnimation.cs" />
<Compile Include="Traits\Render\WithChargeOverlay.cs" /> <Compile Include="Traits\Render\WithChargeOverlay.cs" />
<Compile Include="WebServices.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild"> <Target Name="AfterBuild">

View File

@@ -420,7 +420,8 @@ namespace OpenRA.Mods.Common.Server
else if (server.Settings.QueryMapRepository) else if (server.Settings.QueryMapRepository)
{ {
server.SendOrderTo(conn, "Message", "Searching for map on the Resource Center..."); 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<WebServices>().MapRepository;
server.ModData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { s }, selectMap, queryFailed);
} }
else else
queryFailed(); queryFailed();

View File

@@ -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}"; 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"; if (isInitialPing) url += "&new=1";
var serverList = server.ModData.Manifest.Get<WebServices>().ServerList;
using (var wc = new WebClient()) using (var wc = new WebClient())
{ {
wc.Proxy = null; wc.Proxy = null;
var masterResponse = wc.DownloadData( var masterResponse = wc.DownloadData(
server.Settings.MasterServer + url.F( serverList + url.F(
server.Settings.ExternalPort, Uri.EscapeUriString(server.Settings.Name), server.Settings.ExternalPort, Uri.EscapeUriString(server.Settings.Name),
(int)server.State, (int)server.State,
numPlayers, numPlayers,

View File

@@ -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";
}
}

View File

@@ -36,6 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly bool skirmishMode; readonly bool skirmishMode;
readonly Ruleset modRules; readonly Ruleset modRules;
readonly World shellmapWorld; readonly World shellmapWorld;
readonly WebServices services;
enum PanelType { Players, Options, Music, Kick, ForceStart } enum PanelType { Players, Options, Music, Kick, ForceStart }
PanelType panel = PanelType.Players; PanelType panel = PanelType.Players;
@@ -117,6 +118,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
this.modRules = modData.DefaultRules; this.modRules = modData.DefaultRules;
shellmapWorld = worldRenderer.World; shellmapWorld = worldRenderer.World;
services = modData.Manifest.Get<WebServices>();
orderManager.AddChatLine += AddChatLine; orderManager.AddChatLine += AddChatLine;
Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList; Game.LobbyInfoChanged += UpdatePlayerList;
@@ -655,7 +658,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
else if (Map.Status == MapStatus.DownloadAvailable) else if (Map.Status == MapStatus.DownloadAvailable)
LoadMapPreviewRules(Map); LoadMapPreviewRules(Map);
else if (Game.Settings.Game.AllowDownloading) else if (Game.Settings.Game.AllowDownloading)
modData.MapCache.QueryRemoteMapDetails(new[] { uid }, LoadMapPreviewRules); modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { uid }, LoadMapPreviewRules);
} }
void UpdatePlayerList() void UpdatePlayerList()

View File

@@ -24,6 +24,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
internal LobbyMapPreviewLogic(Widget widget, ModData modData, OrderManager orderManager, LobbyLogic lobby) internal LobbyMapPreviewLogic(Widget widget, ModData modData, OrderManager orderManager, LobbyLogic lobby)
{ {
var mapRepository = modData.Manifest.Get<WebServices>().MapRepository;
var available = widget.GetOrNull("MAP_AVAILABLE"); var available = widget.GetOrNull("MAP_AVAILABLE");
if (available != null) if (available != null)
{ {
@@ -109,11 +111,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var install = download.GetOrNull<ButtonWidget>("MAP_INSTALL"); var install = download.GetOrNull<ButtonWidget>("MAP_INSTALL");
if (install != null) if (install != null)
{ {
install.OnClick = () => lobby.Map.Install(() => install.OnClick = () => lobby.Map.Install(mapRepository, () =>
{ {
lobby.Map.PreloadRules(); lobby.Map.PreloadRules();
Game.RunAfterTick(() => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)))); Game.RunAfterTick(() => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady))));
}); });
install.IsHighlighted = () => installHighlighted; install.IsHighlighted = () => installHighlighted;
} }
} }
@@ -178,9 +181,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
retry.OnClick = () => retry.OnClick = () =>
{ {
if (lobby.Map.Status == MapStatus.DownloadError) 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) 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"; retry.GetText = () => lobby.Map.Status == MapStatus.DownloadError ? "Retry Install" : "Retry Search";

View File

@@ -235,6 +235,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.OnRemoteDirectConnect += OnRemoteDirectConnect; Game.OnRemoteDirectConnect += OnRemoteDirectConnect;
var newsURL = modData.Manifest.Get<WebServices>().GameNews;
// System information opt-out prompt // System information opt-out prompt
var sysInfoPrompt = widget.Get("SYSTEM_INFO_PROMPT"); var sysInfoPrompt = widget.Get("SYSTEM_INFO_PROMPT");
sysInfoPrompt.IsVisible = () => menuType == MenuType.SystemInfoPrompt; sysInfoPrompt.IsVisible = () => menuType == MenuType.SystemInfoPrompt;
@@ -263,14 +265,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.Settings.Debug.SystemInformationVersionPrompt = SystemInformationVersion; Game.Settings.Debug.SystemInformationVersionPrompt = SystemInformationVersion;
Game.Settings.Save(); Game.Settings.Save();
SwitchMenu(MenuType.Main); SwitchMenu(MenuType.Main);
LoadAndDisplayNews(newsBG); LoadAndDisplayNews(newsURL, newsBG);
}; };
} }
else else
LoadAndDisplayNews(newsBG); LoadAndDisplayNews(newsURL, newsBG);
} }
void LoadAndDisplayNews(Widget newsBG) void LoadAndDisplayNews(string newsURL, Widget newsBG)
{ {
if (newsBG != null) if (newsBG != null)
{ {
@@ -285,7 +287,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (!fetchedNews) if (!fetchedNews)
{ {
// Send the mod and engine version to support version-filtered news (update prompts) // 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.Mods["modchooser"].Metadata.Version),
Uri.EscapeUriString(Game.ModData.Manifest.Id), Uri.EscapeUriString(Game.ModData.Manifest.Id),
Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version)); Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version));

View File

@@ -38,6 +38,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly Color gameStartedColor; readonly Color gameStartedColor;
readonly Color incompatibleGameColor; readonly Color incompatibleGameColor;
readonly ModData modData; readonly ModData modData;
readonly WebServices services;
GameServer currentServer; GameServer currentServer;
MapPreview currentMap; MapPreview currentMap;
@@ -70,6 +71,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
this.onStart = onStart; this.onStart = onStart;
this.onExit = onExit; this.onExit = onExit;
services = modData.Manifest.Get<WebServices>();
incompatibleVersionColor = ChromeMetrics.Get<Color>("IncompatibleVersionColor"); incompatibleVersionColor = ChromeMetrics.Get<Color>("IncompatibleVersionColor");
incompatibleGameColor = ChromeMetrics.Get<Color>("IncompatibleGameColor"); incompatibleGameColor = ChromeMetrics.Get<Color>("IncompatibleGameColor");
incompatibleProtectedGameColor = ChromeMetrics.Get<Color>("IncompatibleProtectedGameColor"); incompatibleProtectedGameColor = ChromeMetrics.Get<Color>("IncompatibleProtectedGameColor");
@@ -322,7 +325,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.RunAfterTick(() => RefreshServerListInner(games)); 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.Mods["modchooser"].Metadata.Version),
Uri.EscapeUriString(Game.ModData.Manifest.Id), Uri.EscapeUriString(Game.ModData.Manifest.Id),
Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version)); Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version));
@@ -476,7 +479,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Search for any unknown maps // Search for any unknown maps
if (Game.Settings.Game.AllowDownloading) 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) foreach (var row in rows)
serverList.AddChild(row); serverList.AddChild(row);