From 88e16a890de540aead93362e61bcdd20d9e5fdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 28 Jun 2015 22:18:48 +0200 Subject: [PATCH 1/4] extract Launch args for automatic manpage creation --- .../LoadScreens/BlankLoadScreen.cs | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index 7de5e8f276..d765cb411a 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -20,6 +20,20 @@ namespace OpenRA.Mods.Common.LoadScreens { public class BlankLoadScreen : ILoadScreen { + public class LaunchArgs + { + [Desc("Connect to the following server given as IP:PORT on startup.")] + public string Connect; + + [Desc("Connect to the unified resource identifier openra://IP:PORT on startup.")] + public string URI; + + [Desc("Automatically start playing the given replay file.")] + public string Replay; + } + + public LaunchArgs Launch = new LaunchArgs(); + public virtual void Init(Manifest m, Dictionary info) { } public virtual void Display() @@ -34,6 +48,10 @@ namespace OpenRA.Mods.Common.LoadScreens public void StartGame(Arguments args) { + foreach (var f in Launch.GetType().GetFields()) + if (args.Contains("Launch" + "." + f.Name)) + FieldLoader.LoadField(Launch, f.Name, args.GetValue("Launch" + "." + f.Name, "")); + Ui.ResetAll(); Game.Settings.Save(); @@ -63,21 +81,12 @@ namespace OpenRA.Mods.Common.LoadScreens // Join a server directly var connect = string.Empty; - if (args != null) - { - if (args.Contains("Launch.Connect")) - connect = args.GetValue("Launch.Connect", null); - if (args.Contains("Launch.URI")) - { - connect = args.GetValue("Launch.URI", null); - if (connect != null) - { - connect = connect.Replace("openra://", ""); - connect = connect.TrimEnd('/'); - } - } - } + if (!string.IsNullOrEmpty(Launch.Connect)) + connect = Launch.Connect; + + if (!string.IsNullOrEmpty(Launch.URI)) + connect = Launch.URI.Replace("openra://", "").TrimEnd('/'); if (!string.IsNullOrEmpty(connect)) { @@ -94,12 +103,11 @@ namespace OpenRA.Mods.Common.LoadScreens } // Load a replay directly - var replayFilename = args != null ? args.GetValue("Launch.Replay", null) : null; - if (!string.IsNullOrEmpty(replayFilename)) + if (!string.IsNullOrEmpty(Launch.Replay)) { - var replayMeta = ReplayMetadata.Read(replayFilename); + var replayMeta = ReplayMetadata.Read(Launch.Replay); if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap)) - Game.JoinReplay(replayFilename); + Game.JoinReplay(Launch.Replay); if (replayMeta != null) { From ec7912eaac2c3d93f005008ce5efc5e6425d7c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 4 Jul 2015 19:59:12 +0200 Subject: [PATCH 2/4] remove unused variable --- OpenRA.Game/Settings.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 1e4c66c6ee..066a615742 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -40,7 +40,6 @@ namespace OpenRA public bool Dedicated = false; public bool DedicatedLoop = true; public bool LockBots = false; - public bool AllowVersionMismatch = false; public string TimestampFormat = "HH:mm"; public ServerSettings() { } @@ -64,7 +63,6 @@ namespace OpenRA Dedicated = other.Dedicated; DedicatedLoop = other.DedicatedLoop; LockBots = other.LockBots; - AllowVersionMismatch = other.AllowVersionMismatch; } } From baa798d8313733c566f9f265330aeca354f1d5b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 4 Jul 2015 21:13:00 +0200 Subject: [PATCH 3/4] autogenerate and install a UNIX man page --- .gitignore | 1 + Makefile | 9 +++ OpenRA.Game/Settings.cs | 41 +++++++++-- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../UtilityCommands/CreateManPage.cs | 68 +++++++++++++++++++ packaging/linux/buildpackage.sh | 1 + 6 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs diff --git a/.gitignore b/.gitignore index b6069737a3..2042aa7c8c 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,7 @@ OpenRA.Launcher.Mac/OpenRA.xcodeproj/*.mode1v3 DOCUMENTATION.md Lua-API.md *.html +openra.6 # StyleCop *.Cache diff --git a/Makefile b/Makefile index b1ec5246e8..e6bc54600c 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,7 @@ endif prefix ?= /usr/local datarootdir ?= $(prefix)/share datadir ?= $(datarootdir) +mandir ?= $(datarootdir)/man/ bindir ?= $(prefix)/bin libdir ?= $(prefix)/lib gameinstalldir ?= $(libdir)/openra @@ -320,6 +321,9 @@ docs: utility mods version @mono --debug OpenRA.Utility.exe all --docs > DOCUMENTATION.md @mono --debug OpenRA.Utility.exe ra --lua-docs > Lua-API.md +man-page: utility mods + @mono --debug OpenRA.Utility.exe all --man-page > openra.6 + install: install-core install-all: install-core install-tools @@ -389,6 +393,10 @@ install-linux-appdata: @$(INSTALL_DIR) "$(DESTDIR)$(datadir)/appdata/" @$(INSTALL_DATA) packaging/linux/openra.appdata.xml "$(DESTDIR)$(datadir)/appdata/" +install-man-page: man-page + @$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man6/" + @$(INSTALL_DATA) openra.6 "$(DESTDIR)$(mandir)/man6/" + install-linux-scripts: @echo "#!/bin/sh" > openra @echo 'cd "$(gameinstalldir)"' >> openra @@ -419,6 +427,7 @@ uninstall: @-$(RM_F) "$(DESTDIR)$(datadir)/icons/hicolor/128x128/apps/openra.png" @-$(RM_F) "$(DESTDIR)$(datadir)/mime/packages/openra.xml" @-$(RM_F) "$(DESTDIR)$(datadir)/appdata/openra.appdata.xml" + @-$(RM_F) "$(DESTDIR)$(mandir)/man6/openra.6" help: @echo to compile, run: diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 066a615742..297f93b2c6 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -23,23 +23,55 @@ namespace OpenRA public class ServerSettings { + [Desc("Sets the server name.")] public string Name = "OpenRA Game"; + + [Desc("Sets the internal port.")] public int ListenPort = 1234; + + [Desc("Sets the port advertised to the master server.")] public int ExternalPort = 1234; + + [Desc("Reports the game to the master server list.")] public bool AdvertiseOnline = true; + + [Desc("Locks the game with a password.")] public string Password = ""; + public string MasterServer = "http://master.openra.net/"; - public bool DiscoverNatDevices = false; // Allow users to disable NAT discovery if problems occur - public bool AllowPortForward = true; // let the user disable it even if compatible devices are found + + [Desc("Allow users to enable NAT discovery for external IP detection and automatic port forwarding.")] + public bool DiscoverNatDevices = false; + + [Desc("Set this to false to disable UPnP even if compatible devices are found.")] + public bool AllowPortForward = true; + public bool NatDeviceAvailable = false; // internal check if discovery succeeded - public int NatDiscoveryTimeout = 1000; // ms to search for UPnP enabled NATs - public bool VerboseNatDiscovery = false; // print very detailed logs for debugging + + [Desc("Time in miliseconds to search for UPnP enabled NAT devices.")] + public int NatDiscoveryTimeout = 1000; + + [Desc("Print very detailed logs for debugging issues with routers.")] + public bool VerboseNatDiscovery = false; + + [Desc("Starts the game with a default map. Input as hash that can be obtained by the utility.")] public string Map = null; + + [Desc("Takes a comma separated list of IP addresses that are not allowed to join.")] public string[] Ban = { }; + + [Desc("Value in miliseconds when to terminate the game. Needs to be at least 10000 (10 s) to enable the timer.")] public int TimeOut = 0; + + [Desc("Run in headless mode with an empty renderer and without sound output.")] public bool Dedicated = false; + + [Desc("Automatically restart when a game ends. Disable this when something else already takes care about it.")] public bool DedicatedLoop = true; + + [Desc("Disallow AI bots.")] public bool LockBots = false; + public string TimestampFormat = "HH:mm"; public ServerSettings() { } @@ -122,6 +154,7 @@ namespace OpenRA public class GameSettings { + [Desc("Load a specific mod on startup. Shipped ones include: ra, cnc and d2k")] public string Mod = "modchooser"; public string PreviousMod = "ra"; diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 687d3c95b4..564ab510c2 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -529,6 +529,7 @@ + diff --git a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs new file mode 100644 index 0000000000..880f146a2a --- /dev/null +++ b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs @@ -0,0 +1,68 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Linq; + +namespace OpenRA.Mods.Common.UtilityCommands +{ + class CreateManPage : IUtilityCommand + { + public string Name { get { return "--man-page"; } } + + [Desc("Create a man page in troff format.")] + public void Run(ModData modData, string[] args) + { + Console.WriteLine(".TH OPENRA 6"); + Console.WriteLine(".SH NAME"); + Console.WriteLine("openra \\- An Open Source modernization of the early 2D Command & Conquer games."); + Console.WriteLine(".SH SYNOPSIS"); + Console.WriteLine(".B openra"); + Console.WriteLine("[\\fB\\Game.Mod=\\fR\\fImodchooser\\fR]"); + Console.WriteLine(".SH DESCRIPTION"); + Console.WriteLine(".B openra"); + Console.WriteLine("starts the game."); + Console.WriteLine(".SH OPTIONS"); + + var sections = Game.Settings.Sections; + sections.Add("Launch", new OpenRA.Mods.Common.LoadScreens.BlankLoadScreen.LaunchArgs()); + foreach (var section in sections.OrderBy(s => s.Key)) + { + var fields = section.Value.GetType().GetFields(); + foreach (var field in fields) + { + if (!field.HasAttribute()) + continue; + + Console.WriteLine(".TP"); + + Console.Write(".BR {0}.{1}=".F(section.Key, field.Name)); + var value = field.GetValue(section.Value); + if (value != null && !value.ToString().StartsWith("System.")) + Console.WriteLine("\\fI{0}\\fR".F(value)); + else + Console.WriteLine(); + + var lines = field.GetCustomAttributes(false).SelectMany(d => d.Lines); + foreach (var line in lines) + Console.WriteLine(line); + } + } + + Console.WriteLine(".SH FILES"); + Console.WriteLine("Settings are stored in the ~/.openra user folder."); + Console.WriteLine(".SH BUGS"); + Console.WriteLine("Known issues are tracked at http://bugs.openra.net"); + Console.WriteLine(".SH COPYRIGHT"); + Console.WriteLine("Copyright 2007-2015 The OpenRA Developers (see AUTHORS)"); + Console.WriteLine("This manual is part of OpenRA, which is free software. It is GNU GPL v3 licensed. See COPYING for details."); + } + } +} diff --git a/packaging/linux/buildpackage.sh b/packaging/linux/buildpackage.sh index c26f43b7b3..38908d459b 100755 --- a/packaging/linux/buildpackage.sh +++ b/packaging/linux/buildpackage.sh @@ -24,6 +24,7 @@ make install-all prefix="/usr" DESTDIR="$PWD/packaging/linux/$ROOTDIR" make install-linux-shortcuts prefix="/usr" DESTDIR="$PWD/packaging/linux/$ROOTDIR" make install-linux-mime prefix="/usr" DESTDIR="$PWD/packaging/linux/$ROOTDIR" make install-linux-appdata prefix="/usr" DESTDIR="$PWD/packaging/linux/$ROOTDIR" +make install-man-page prefix="/usr" DESTDIR="$PWD/packaging/linux/$ROOTDIR" # Documentation mkdir -p $PWD/packaging/linux/$ROOTDIR/usr/share/doc/openra/ From 7c86519242f5faeb5f13ee2e8329fa2be36a448a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 26 Jul 2015 11:54:47 +0200 Subject: [PATCH 4/4] organize launch arguments in it's own class --- OpenRA.Game/OpenRA.Game.csproj | 1 + OpenRA.Game/Support/LaunchArguments.cs | 44 +++++++++++++++++++ .../LoadScreens/BlankLoadScreen.cs | 28 ++---------- .../UtilityCommands/CreateManPage.cs | 2 +- 4 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 OpenRA.Game/Support/LaunchArguments.cs diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index ea74fbb26a..f0e91d291e 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -164,6 +164,7 @@ + diff --git a/OpenRA.Game/Support/LaunchArguments.cs b/OpenRA.Game/Support/LaunchArguments.cs new file mode 100644 index 0000000000..16c5cae8e3 --- /dev/null +++ b/OpenRA.Game/Support/LaunchArguments.cs @@ -0,0 +1,44 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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. For more information, + * see COPYING. + */ +#endregion + +namespace OpenRA +{ + public class LaunchArguments + { + [Desc("Connect to the following server given as IP:PORT on startup.")] + public string Connect; + + [Desc("Connect to the unified resource identifier openra://IP:PORT on startup.")] + public string URI; + + [Desc("Automatically start playing the given replay file.")] + public string Replay; + + public LaunchArguments(Arguments args) + { + foreach (var f in this.GetType().GetFields()) + if (args.Contains("Launch" + "." + f.Name)) + FieldLoader.LoadField(this, f.Name, args.GetValue("Launch" + "." + f.Name, "")); + } + + public string GetConnectAddress() + { + var connect = string.Empty; + + if (!string.IsNullOrEmpty(Connect)) + connect = Connect; + + if (!string.IsNullOrEmpty(URI)) + connect = URI.Replace("openra://", "").TrimEnd('/'); + + return connect; + } + } +} diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index d765cb411a..f356025ac8 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -20,19 +20,7 @@ namespace OpenRA.Mods.Common.LoadScreens { public class BlankLoadScreen : ILoadScreen { - public class LaunchArgs - { - [Desc("Connect to the following server given as IP:PORT on startup.")] - public string Connect; - - [Desc("Connect to the unified resource identifier openra://IP:PORT on startup.")] - public string URI; - - [Desc("Automatically start playing the given replay file.")] - public string Replay; - } - - public LaunchArgs Launch = new LaunchArgs(); + public LaunchArguments Launch; public virtual void Init(Manifest m, Dictionary info) { } @@ -48,10 +36,7 @@ namespace OpenRA.Mods.Common.LoadScreens public void StartGame(Arguments args) { - foreach (var f in Launch.GetType().GetFields()) - if (args.Contains("Launch" + "." + f.Name)) - FieldLoader.LoadField(Launch, f.Name, args.GetValue("Launch" + "." + f.Name, "")); - + Launch = new LaunchArguments(args); Ui.ResetAll(); Game.Settings.Save(); @@ -80,14 +65,7 @@ namespace OpenRA.Mods.Common.LoadScreens } // Join a server directly - var connect = string.Empty; - - if (!string.IsNullOrEmpty(Launch.Connect)) - connect = Launch.Connect; - - if (!string.IsNullOrEmpty(Launch.URI)) - connect = Launch.URI.Replace("openra://", "").TrimEnd('/'); - + var connect = Launch.GetConnectAddress(); if (!string.IsNullOrEmpty(connect)) { var parts = connect.Split(':'); diff --git a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs index 880f146a2a..6f8a6090b2 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.UtilityCommands Console.WriteLine(".SH OPTIONS"); var sections = Game.Settings.Sections; - sections.Add("Launch", new OpenRA.Mods.Common.LoadScreens.BlankLoadScreen.LaunchArgs()); + sections.Add("Launch", new LaunchArguments(new Arguments(new string[0]))); foreach (var section in sections.OrderBy(s => s.Key)) { var fields = section.Value.GetType().GetFields();