From dec8c8ba4bd4deedbedb8d9b3cc9519d58eb5e60 Mon Sep 17 00:00:00 2001 From: Christer Ulfsparre Date: Sat, 22 Oct 2011 00:33:23 +0200 Subject: [PATCH] Added ability to join a server on startup, for gamelist apps. --- OpenRA.Game/Game.cs | 17 +++++++++++++++++ OpenRA.Game/GameRules/Settings.cs | 2 ++ OpenRA.Mods.Cnc/CncLoadScreen.cs | 6 +++++- OpenRA.Mods.RA/RALoadScreen.cs | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 341f9a0173..edde7307d1 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -388,5 +388,22 @@ namespace OpenRA { return orderManager != null && orderManager.world == world; } + + public static void JoinExternalGame() + { + var addressParts = Game.Settings.Game.ConnectTo.Split( + new [] { ':' }, StringSplitOptions.RemoveEmptyEntries); + + if (addressParts.Length < 1 || addressParts.Length > 2) + return; + + var host = addressParts[0]; + var port = Exts.WithDefault(1234, () => int.Parse(addressParts[1])); + + Game.Settings.Game.ConnectTo = ""; + Game.Settings.Save(); + + Game.JoinServer(host, port); + } } } diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index 7063cb9cf6..2a2e33c136 100755 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -97,6 +97,8 @@ namespace OpenRA.GameRules // Internal game settings public int Timestep = 40; + + public string ConnectTo = ""; } public class Settings diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index 07b02e405f..fa18cfeffd 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -115,7 +115,11 @@ namespace OpenRA.Mods.Cnc r.EndFrame(nih); } - public void StartGame() { TestAndContinue(); } + public void StartGame() + { + TestAndContinue(); + Game.JoinExternalGame(); + } void TestAndContinue() { diff --git a/OpenRA.Mods.RA/RALoadScreen.cs b/OpenRA.Mods.RA/RALoadScreen.cs index fb6ce1f9dd..be408ae374 100644 --- a/OpenRA.Mods.RA/RALoadScreen.cs +++ b/OpenRA.Mods.RA/RALoadScreen.cs @@ -98,6 +98,7 @@ namespace OpenRA.Mods.RA }; TestAndContinue(); + Game.JoinExternalGame(); } void TestAndContinue()