diff --git a/Makefile b/Makefile index ebe3b6244a..156c3df0d3 100644 --- a/Makefile +++ b/Makefile @@ -44,12 +44,6 @@ aftermath_KIND = library aftermath_DEPS = $(fileformats_TARGET) $(game_TARGET) aftermath_LIBS = $(COMMON_LIBS) $(aftermath_DEPS) -server_SRCS = $(shell find OpenRA.Server/ -iname '*.cs') -server_TARGET = OpenRA.Server.exe -server_KIND = winexe -server_DEPS = $(fileformats_TARGET) -server_LIBS = $(COMMON_LIBS) $(server_DEPS) - seqed_SRCS = $(shell find SequenceEditor/ -iname '*.cs') seqed_TARGET = SequenceEditor.exe seqed_KIND = winexe @@ -83,9 +77,8 @@ clean: @-rm *.exe *.dll *.mdb mods/**/*.dll mods/**/*.mdb mods: $(ra_TARGET) $(cnc_TARGET) $(aftermath_TARGET) -server: $(server_TARGET) seqed: $(seqed_TARGET) -all: $(fileformats_TARGET) $(gl_TARGET) $(game_TARGET) $(ra_TARGET) $(cnc_TARGET) $(aftermath_TARGET) $(server_TARGET) $(seqed_TARGET) +all: $(fileformats_TARGET) $(gl_TARGET) $(game_TARGET) $(ra_TARGET) $(cnc_TARGET) $(aftermath_TARGET) $(seqed_TARGET) dist-osx: packaging/osx/package.sh diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 530ba350b5..6f5426e3cc 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -231,14 +231,30 @@ namespace OpenRA public void DrawDialog(string text) { - var w = renderer.BoldFont.Measure(text).X + 120; - var h = 100; + DrawDialog(text, null, _ => { }, null, _ => { }); + } + + public void DrawDialog(string text, string button1String, Action button1Action, string button2String, Action button2Action) + { + var w = Math.Max(renderer.BoldFont.Measure(text).X + 120, 400); + var h = (button1String == null) ? 100 : 140; var r = new Rectangle((Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h); DrawDialogBackground(r, "dialog"); - DrawCentered(text, new int2(Game.viewport.Width / 2, Game.viewport.Height / 2 - 8), Color.White); + DrawCentered(text, new int2(Game.viewport.Width / 2, Game.viewport.Height / 2 - ((button1String == null) ? 8 : 28)), Color.White); // don't allow clicks through the dialog AddButton(r, _ => { }); + + if (button1String != null) + { + AddUiButton(new int2(r.Right - 300, r.Bottom - 40),button1String, button1Action); + } + + if (button2String != null) + { + AddUiButton(new int2(r.Right - 100, r.Bottom - 40),button2String, button2Action); + } + } class MapInfo @@ -411,6 +427,35 @@ namespace OpenRA } + public void DrawMainMenu( World world ) + { + buttons.Clear(); + + var w = 250; + var h = 200; + var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h ); + DrawDialogBackground(r, "dialog"); + DrawCentered("OpenRA Main Menu", new int2(r.Left + w / 2, r.Top + 20), Color.White); + + AddUiButton(new int2(r.Left + w/2, r.Top + 70), "Join Game", + _ => + { + Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort); + }); + + AddUiButton(new int2(r.Left + w/2, r.Top + 105), "Create Game", + _ => + { + Game.CreateServer(); + }); + + AddUiButton(new int2(r.Left + w/2, r.Top + 140), "Quit", + _ => + { + Game.Exit(); + }); + } + public void DrawLobby( World world ) { buttons.Clear(); diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 9a0a770089..082c772581 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -20,7 +20,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; +using System.IO; using System.Linq; using System.Windows.Forms; using OpenRA.FileFormats; @@ -30,8 +32,8 @@ using OpenRA.Network; using OpenRA.Support; using OpenRA.Traits; using Timer = OpenRA.Support.Timer; -using System.Runtime.InteropServices; -using System.IO; +using OpenRA.Server; +using System.Net; namespace OpenRA { @@ -54,6 +56,8 @@ namespace OpenRA static string mapName; internal static Session LobbyInfo = new Session(); static bool changePending; + + public static void LoadModPackages(Manifest manifest) { @@ -125,20 +129,39 @@ namespace OpenRA PerfHistory.items["batches"].hasNormalTick = false; PerfHistory.items["text"].hasNormalTick = false; Game.controller = controller; - + ChangeMap(mapName); if (Settings.Replay != "") throw new NotImplementedException(); else { - var connection = (string.IsNullOrEmpty(Settings.NetworkHost)) - ? new EchoConnection() - : new NetworkConnection( Settings.NetworkHost, Settings.NetworkPort ); - orderManager = new OrderManager(connection, "replay.rep"); + JoinLocal(); } } - + + internal static void JoinServer(string host, int port) + { + orderManager = new OrderManager(new NetworkConnection( host, port ), "replay.rep"); + } + + internal static void JoinLocal() + { + orderManager = new OrderManager(new EchoConnection()); + } + + internal static void CreateServer() + { + // todo: LobbyInfo is the wrong place for this. + InprocServer.Start(Game.LobbyInfo.GlobalSettings.Mods); + JoinServer(IPAddress.Loopback.ToString(), 1234); + } + + internal static void CloseServer() + { + InprocServer.Stop(); + } + static int lastTime = Environment.TickCount; public static void ResetTimer() @@ -312,15 +335,6 @@ namespace OpenRA throw new InvalidOperationException( "Desync in DispatchMouseInput" ); } - public static void HandleKeyDown( KeyEventArgs e ) - { - //int sync = Game.world.SyncHash(); - - - //if( sync != Game.world.SyncHash() ) - // throw new InvalidOperationException( "Desync in OnKeyDown" ); - } - public static bool IsHost { get { return orderManager.Connection.LocalClientId == 0; } diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index ba235b448e..de5f31ee1b 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -85,11 +85,15 @@ namespace OpenRA.Graphics switch( Game.orderManager.Connection.ConnectionState ) { + case ConnectionState.PreConnecting: + Game.chrome.DrawMainMenu( world ); + break; case ConnectionState.Connecting: Game.chrome.DrawDialog("Connecting to {0}:{1}...".F( Game.Settings.NetworkHost, Game.Settings.NetworkPort )); break; case ConnectionState.NotConnected: - Game.chrome.DrawDialog("Connection failed."); + // Todo: Hook these up + Game.chrome.DrawDialog("Connection failed.", "Retry", _ => {}, "Cancel",_ => {}); break; case ConnectionState.Connected: Game.chrome.DrawLobby( world ); diff --git a/OpenRA.Game/Network/Connection.cs b/OpenRA.Game/Network/Connection.cs index a6b3533bc0..7df72e25fb 100755 --- a/OpenRA.Game/Network/Connection.cs +++ b/OpenRA.Game/Network/Connection.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -29,6 +29,7 @@ namespace OpenRA.Network { enum ConnectionState { + PreConnecting, NotConnected, Connecting, Connected, @@ -58,7 +59,7 @@ namespace OpenRA.Network public virtual ConnectionState ConnectionState { - get { return ConnectionState.Connected; } + get { return ConnectionState.PreConnecting; } } public virtual void Send( byte[] packet ) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 16c5c88344..5065c891b2 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -1,4 +1,4 @@ - + Debug @@ -102,6 +102,10 @@ + + + + diff --git a/OpenRA.Server/Connection.cs b/OpenRA.Game/Server/Connection.cs similarity index 100% rename from OpenRA.Server/Connection.cs rename to OpenRA.Game/Server/Connection.cs diff --git a/OpenRA.Server/Exts.cs b/OpenRA.Game/Server/Exts.cs old mode 100755 new mode 100644 similarity index 100% rename from OpenRA.Server/Exts.cs rename to OpenRA.Game/Server/Exts.cs diff --git a/OpenRA.Server/Server.cs b/OpenRA.Game/Server/Server.cs similarity index 91% rename from OpenRA.Server/Server.cs rename to OpenRA.Game/Server/Server.cs index 2cc907f41c..55cbdfc14c 100644 --- a/OpenRA.Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -27,6 +27,7 @@ using System.Net; using System.Net.Sockets; using System.Security.Cryptography; using OpenRA.FileFormats; +using System.Threading; namespace OpenRA.Server { @@ -38,16 +39,17 @@ namespace OpenRA.Server = new Dictionary>(); static Session lobbyInfo; static bool GameStarted = false; - static string[] defaultMods = new string[] { "ra" }; + static string[] initialMods; const int DownloadChunkInterval = 20000; const int DownloadChunkSize = 16384; - public static int Main(string[] args) + public static int ServerMain(string[] mods, AutoResetEvent e) { - if (args.Length > 0) defaultMods = args; + initialMods = mods; + lobbyInfo = new Session(); - lobbyInfo.GlobalSettings.Mods = defaultMods; + lobbyInfo.GlobalSettings.Mods = mods; Console.WriteLine("Initial mods: "); foreach( var m in lobbyInfo.GlobalSettings.Mods ) @@ -63,6 +65,8 @@ namespace OpenRA.Server Console.WriteLine("Server failed to start."); return 1; } + + e.Set(); // we're done starting up for (; ; ) { @@ -510,7 +514,7 @@ namespace OpenRA.Server Console.WriteLine("Server emptied out; doing a bit of housekeeping to prepare for next game.."); inFlightFrames.Clear(); lobbyInfo = new Session(); - lobbyInfo.GlobalSettings.Mods = defaultMods; + lobbyInfo.GlobalSettings.Mods = initialMods; GameStarted = false; } @@ -538,4 +542,25 @@ namespace OpenRA.Server new ServerOrder("SyncInfo", clientData.WriteToString()).Serialize()); } } + + // temporary threaded inproc server wrapper. + public static class InprocServer + { + static Thread t; + + public static void Start( string[] mods ) + { + var e = new AutoResetEvent(false); + t = new Thread(() => Server.ServerMain(mods, e)) { IsBackground = true }; + + t.Start(); + e.WaitOne(); // when the event is signaled, the server is finished initializing + } + + public static void Stop() + { + if (t != null) + t.Abort(); + } + } } diff --git a/OpenRA.Server/ServerOrder.cs b/OpenRA.Game/Server/ServerOrder.cs similarity index 100% rename from OpenRA.Server/ServerOrder.cs rename to OpenRA.Game/Server/ServerOrder.cs diff --git a/OpenRA.Server/OpenRA.Server.csproj b/OpenRA.Server/OpenRA.Server.csproj index d3e07b5e65..7000149649 100644 --- a/OpenRA.Server/OpenRA.Server.csproj +++ b/OpenRA.Server/OpenRA.Server.csproj @@ -6,7 +6,7 @@ 9.0.30729 2.0 {76F621A1-3D8E-4A99-9F7E-B071EB657817} - Exe + Library Properties OpenRA.Server OpenRA.Server @@ -48,11 +48,7 @@ - - - - @@ -68,4 +64,8 @@ --> + + + + \ No newline at end of file diff --git a/OpenRA.sln b/OpenRA.sln index a3e27d272f..2ca505c31f 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -7,8 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Game", "OpenRA.Game\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SequenceEditor", "SequenceEditor\SequenceEditor.csproj", "{230F65CE-A6DE-4235-8B38-13A3D606C7F7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Server", "OpenRA.Server\OpenRA.Server.csproj", "{76F621A1-3D8E-4A99-9F7E-B071EB657817}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.RA", "OpenRA.Mods.RA\OpenRA.Mods.RA.csproj", "{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.Aftermath", "OpenRA.Mods.Aftermath\OpenRA.Mods.Aftermath.csproj", "{2E1F8D8B-AEF5-4BCE-A95C-50223A0C7331}" @@ -48,14 +46,6 @@ Global {230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Release|Any CPU.Build.0 = Release|Any CPU {230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Release|Mixed Platforms.ActiveCfg = Release|x86 {230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Release|Mixed Platforms.Build.0 = Release|x86 - {76F621A1-3D8E-4A99-9F7E-B071EB657817}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {76F621A1-3D8E-4A99-9F7E-B071EB657817}.Debug|Any CPU.Build.0 = Debug|Any CPU - {76F621A1-3D8E-4A99-9F7E-B071EB657817}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {76F621A1-3D8E-4A99-9F7E-B071EB657817}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {76F621A1-3D8E-4A99-9F7E-B071EB657817}.Release|Any CPU.ActiveCfg = Release|Any CPU - {76F621A1-3D8E-4A99-9F7E-B071EB657817}.Release|Any CPU.Build.0 = Release|Any CPU - {76F621A1-3D8E-4A99-9F7E-B071EB657817}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {76F621A1-3D8E-4A99-9F7E-B071EB657817}.Release|Mixed Platforms.Build.0 = Release|Any CPU {4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU diff --git a/packaging/osx/package.sh b/packaging/osx/package.sh index 26f2649294..ac0c03f685 100755 --- a/packaging/osx/package.sh +++ b/packaging/osx/package.sh @@ -54,9 +54,6 @@ export AS="as -arch i386" export CC="gcc -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk" export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig/ -# Package the server binary -mkbundle --deps --static -z -o openra_server OpenRA.Server.exe OpenRA.FileFormats.dll thirdparty/Tao/Tao.Sdl.dll - # Package the game binary mkbundle --deps --static -z -o OpenRA OpenRA.Game.exe OpenRA.Gl.dll OpenRA.FileFormats.dll thirdparty/Tao/Tao.Cg.dll thirdparty/Tao/Tao.OpenGl.dll thirdparty/Tao/Tao.OpenAl.dll thirdparty/Tao/Tao.FreeType.dll thirdparty/Tao/Tao.Sdl.dll diff --git a/packaging/osx/package_dmg.sh b/packaging/osx/package_dmg.sh index 40f03f699e..fefa706756 100755 --- a/packaging/osx/package_dmg.sh +++ b/packaging/osx/package_dmg.sh @@ -3,7 +3,6 @@ title=OpenRA size=70m dmgName=OpenRA.dmg -mv openra_server ${source} mv OpenRA.app ${source} hdiutil create -srcfolder "${source}" -volname "${title}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${size} temp.dmg @@ -23,7 +22,6 @@ echo ' set background picture of theViewOptions to file ".background:bg.png" make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"} set position of item "OpenRA.app" of container window to {100, 90} - set position of item "openra_server" of container window to {100, 210} set position of item "Applications" of container window to {375, 150} close open @@ -38,5 +36,4 @@ sync hdiutil detach ${device} hdiutil convert "./temp.dmg" -format UDZO -imagekey zlib-level=9 -o "${dmgName}" rm -f ./temp.dmg -rm -rf ${source}OpenRA.app -rm -f ${source}openra_server \ No newline at end of file +rm -rf ${source}OpenRA.app \ No newline at end of file