Merge pull request #7121 from pchote/switchmods

Add Launch.Connect command and on-connect mod switching.
This commit is contained in:
Oliver Brakmann
2014-12-24 16:06:00 +01:00
19 changed files with 193 additions and 116 deletions

View File

@@ -87,10 +87,16 @@ namespace OpenRA
public const int Timestep = 40;
public const int TimestepJankThreshold = 250; // Don't catch up for delays larger than 250ms
public static event Action<string, int> OnRemoteDirectConnect = (a, b) => { };
public static event Action<OrderManager> ConnectionStateChanged = _ => { };
static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
public static int LocalClientId { get { return orderManager.Connection.LocalClientId; } }
public static void RemoteDirectConnect(string host, int port)
{
OnRemoteDirectConnect(host, port);
}
// Hacky workaround for orderManager visibility
public static Widget OpenWindow(World world, string widget)
{
@@ -264,6 +270,9 @@ namespace OpenRA
LobbyInfoChanged = () => { };
ConnectionStateChanged = om => { };
BeforeGameStart = () => { };
OnRemoteDirectConnect = (a, b) => { };
delayedActions = new ActionQueue();
Ui.ResetAll();
if (worldRenderer != null)
@@ -356,45 +365,7 @@ namespace OpenRA
Environment.Exit(0);
}
else
{
var window = args != null ? args.GetValue("Launch.Window", null) : null;
if (!string.IsNullOrEmpty(window))
{
var installData = modData.Manifest.ContentInstaller;
if (installData.InstallerBackgroundWidget != null)
Ui.LoadWidget(installData.InstallerBackgroundWidget, Ui.Root, new WidgetArgs());
Widgets.Ui.OpenWindow(window, new WidgetArgs());
}
else
{
modData.LoadScreen.StartGame();
Settings.Save();
var replay = args != null ? args.GetValue("Launch.Replay", null) : null;
if (!string.IsNullOrEmpty(replay))
Game.JoinReplay(replay);
}
}
}
public static void TestAndContinue()
{
Ui.ResetAll();
var installData = modData.Manifest.ContentInstaller;
if (!installData.TestFiles.All(f => GlobalFileSystem.Exists(f)))
{
var args = new WidgetArgs()
{
{ "continueLoading", () => InitializeMod(Game.Settings.Game.Mod, null) },
};
if (installData.InstallerBackgroundWidget != null)
Ui.LoadWidget(installData.InstallerBackgroundWidget, Ui.Root, args);
Ui.OpenWindow(installData.InstallerMenuWidget, args);
}
else
LoadShellMap();
modData.LoadScreen.StartGame(args);
}
public static void LoadShellMap()

View File

@@ -20,8 +20,9 @@ namespace OpenRA
{
public class InstallData
{
public readonly string InstallerMenuWidget = null;
public readonly string InstallerBackgroundWidget = null;
public readonly string MenuWidget = null;
public readonly string MusicMenuWidget = null;
public readonly string BackgroundWidget = null;
public readonly string[] TestFiles = {};
public readonly string[] DiskTestFiles = {};
public readonly string PackageToExtractFromCD = null;

View File

@@ -180,6 +180,6 @@ namespace OpenRA
{
void Init(Manifest m, Dictionary<string, string> info);
void Display();
void StartGame();
void StartGame(Arguments args);
}
}

View File

@@ -51,6 +51,8 @@ namespace OpenRA.Network
public readonly ReadOnlyList<ChatLine> ChatCache;
bool disposed;
static void OutOfSync(int frame)
{
throw new InvalidOperationException("Out of sync in frame {0}.\n Compare syncreport.log with other players.".F(frame));
@@ -122,8 +124,16 @@ namespace OpenRA.Network
});
foreach (var p in immediatePackets)
{
foreach (var o in p.Second.ToOrderList(World))
{
UnitOrders.ProcessOrder(this, World, p.First, o);
// A mod switch or other event has pulled the ground from beneath us
if (disposed)
return;
}
}
}
Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>();
@@ -213,6 +223,7 @@ namespace OpenRA.Network
public void Dispose()
{
disposed = true;
if (Connection != null)
Connection.Dispose();
}

View File

@@ -33,9 +33,12 @@ namespace OpenRA.Network
public readonly int TickCount;
public readonly bool IsValid;
public readonly Session LobbyInfo;
public readonly string Filename;
public ReplayConnection(string replayFilename)
{
Filename = replayFilename;
// Parse replay data into a struct that can be fed to the game in chunks
// to avoid issues with all immediate orders being resolved on the first tick.
using (var rs = File.OpenRead(replayFilename))

View File

@@ -119,10 +119,27 @@ namespace OpenRA.Network
case "HandshakeRequest":
{
// TODO: Switch to the server's mod if we have it
// Otherwise send the handshake with our current settings and let the server reject us
// Switch to the server's mod if we need and are able to
var mod = Game.modData.Manifest.Mod;
var request = HandshakeRequest.Deserialize(order.TargetString);
ModMetadata serverMod;
if (request.Mod != mod.Id &&
ModMetadata.AllMods.TryGetValue(request.Mod, out serverMod) &&
serverMod.Version == request.Version)
{
var replay = orderManager.Connection as ReplayConnection;
var launchCommand = replay != null ?
"Launch.Replay=" + replay.Filename :
"Launch.Connect=" + orderManager.Host + ":" + orderManager.Port;
Game.modData.LoadScreen.Display();
Game.InitializeMod(request.Mod, new Arguments(launchCommand));
break;
}
// Otherwise send the handshake with our current settings and let the server reject us
var info = new Session.Client()
{
Name = Game.Settings.Player.Name,