@@ -458,5 +458,29 @@ namespace OpenRA
|
|||||||
|
|
||||||
Game.JoinServer(host, port);
|
Game.JoinServer(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool DownloadMap(string mapHash)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var mod = Game.CurrentMods.FirstOrDefault().Value.Id;
|
||||||
|
var dirPath = "{1}maps{0}{2}".F(Path.DirectorySeparatorChar, Platform.SupportDir, mod);
|
||||||
|
if(!Directory.Exists(dirPath))
|
||||||
|
Directory.CreateDirectory(dirPath);
|
||||||
|
var mapPath = "{1}{0}{2}".F(Path.DirectorySeparatorChar, dirPath, mapHash+".oramap");
|
||||||
|
Console.Write("Trying to download map to {0} ... ".F(mapPath));
|
||||||
|
WebClient webClient = new WebClient();
|
||||||
|
webClient.DownloadFile(Game.Settings.Game.MapRepository + mapHash, mapPath);
|
||||||
|
Game.modData.AvailableMaps.Add(mapHash, new Map(mapPath));
|
||||||
|
Console.WriteLine("done");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (WebException e)
|
||||||
|
{
|
||||||
|
Log.Write("debug", "Could not download map '{0}'", mapHash);
|
||||||
|
Log.Write("debug", e.ToString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ namespace OpenRA.GameRules
|
|||||||
public int Timestep = 40;
|
public int Timestep = 40;
|
||||||
|
|
||||||
public string ConnectTo = "";
|
public string ConnectTo = "";
|
||||||
|
public bool AllowDownloading = true;
|
||||||
|
public string MapRepository = "http://content.open-ra.org/map/";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class KeySettings
|
public class KeySettings
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
// Don't have the map locally
|
// Don't have the map locally
|
||||||
if (!Game.modData.AvailableMaps.ContainsKey(Map))
|
if (!Game.modData.AvailableMaps.ContainsKey(Map))
|
||||||
return false;
|
if (!Game.Settings.Game.AllowDownloading)
|
||||||
|
return false;
|
||||||
|
|
||||||
return CompatibleVersion();
|
return CompatibleVersion();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,12 @@ namespace OpenRA.Network
|
|||||||
throw new InvalidOperationException("Server's mod ({0}) and yours ({1}) don't match".F(localMods.FirstOrDefault().ToString().Split('@')[0], request.Mods.FirstOrDefault().ToString().Split('@')[0]));
|
throw new InvalidOperationException("Server's mod ({0}) and yours ({1}) don't match".F(localMods.FirstOrDefault().ToString().Split('@')[0], request.Mods.FirstOrDefault().ToString().Split('@')[0]));
|
||||||
// Check that the map exists on the client
|
// Check that the map exists on the client
|
||||||
if (!Game.modData.AvailableMaps.ContainsKey(request.Map))
|
if (!Game.modData.AvailableMaps.ContainsKey(request.Map))
|
||||||
throw new InvalidOperationException("Missing map {0}".F(request.Map));
|
{
|
||||||
|
if (Game.Settings.Game.AllowDownloading)
|
||||||
|
Game.DownloadMap(request.Map);
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException("Missing map {0}".F(request.Map));
|
||||||
|
}
|
||||||
|
|
||||||
var info = new Session.Client()
|
var info = new Session.Client()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -328,8 +328,18 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
void UpdateCurrentMap()
|
void UpdateCurrentMap()
|
||||||
{
|
{
|
||||||
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return;
|
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map)
|
||||||
|
return;
|
||||||
MapUid = orderManager.LobbyInfo.GlobalSettings.Map;
|
MapUid = orderManager.LobbyInfo.GlobalSettings.Map;
|
||||||
|
|
||||||
|
if (!Game.modData.AvailableMaps.ContainsKey (MapUid))
|
||||||
|
if (Game.Settings.Game.AllowDownloading)
|
||||||
|
{
|
||||||
|
Game.DownloadMap (MapUid);
|
||||||
|
Game.Debug("A new map has been downloaded...");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException("Server's new map doesn't exist on your system and Downloading turned off");
|
||||||
Map = new Map(Game.modData.AvailableMaps[MapUid].Path);
|
Map = new Map(Game.modData.AvailableMaps[MapUid].Path);
|
||||||
|
|
||||||
var title = Ui.Root.Get<LabelWidget>("TITLE");
|
var title = Ui.Root.Get<LabelWidget>("TITLE");
|
||||||
|
|||||||
Reference in New Issue
Block a user