AddChannel() public static method

public static AddChannel ( string channelName, string baseFilename ) : void
channelName string
baseFilename string
return void
Example #1
0
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;

            Settings = new Settings(Platform.SupportDir + "settings.yaml", args);
            Settings.Save();

            Log.LogPath = Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar;
            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("sync", "syncreport.log");

            FileSystem.Mount(".");             // Needed to access shaders
            Renderer.Initialize(Game.Settings.Graphics.Mode);
            Renderer = new Renderer();

            Console.WriteLine("Available mods:");
            foreach (var mod in Mod.AllMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            Sound.Create(Settings.Sound.Engine);
            InitializeWithMods(Settings.Game.Mods);
        }
Example #2
0
        public static void HandleFatalError(Exception ex)
        {
            var exceptionName = "exception-" + DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture) + ".log";

            Log.AddChannel("exception", exceptionName);

            if (Game.EngineVersion != null)
            {
                Log.Write("exception", "OpenRA engine version {0}", Game.EngineVersion);
            }

            if (Game.ModData != null)
            {
                var mod = Game.ModData.Manifest.Metadata;
                Log.Write("exception", "{0} mod version {1}", mod.Title, mod.Version);
            }

            if (Game.OrderManager != null && Game.OrderManager.World != null && Game.OrderManager.World.Map != null)
            {
                var map = Game.OrderManager.World.Map;
                Log.Write("exception", "on map {0} ({1} by {2}).", map.Uid, map.Title, map.Author);
            }

            Log.Write("exception", "Date: {0:u}", DateTime.UtcNow);
            Log.Write("exception", "Operating System: {0} ({1})", Platform.CurrentPlatform, Environment.OSVersion);
            Log.Write("exception", "Runtime Version: {0}", Platform.RuntimeVersion);
            var rpt = BuildExceptionReport(ex).ToString();

            Log.Write("exception", "{0}", rpt);
            Console.Error.WriteLine(rpt);
        }
Example #3
0
        static void LogException(Exception e)
        {
            Log.AddChannel("exception", "exception.log");
            var rpt = BuildExceptionReport(e).ToString();

            Log.Write("exception", "{0}", rpt);
            Console.Error.WriteLine(rpt);
        }
Example #4
0
 public void PrintReport()
 {
     Log.AddChannel("traitreport", "traitreport.log");
     foreach (var t in traits.OrderByDescending(t => t.Value.Queries).TakeWhile(t => t.Value.Queries > 0))
     {
         Log.Write("traitreport", "{0}: {1}", t.Key.Name, t.Value.Queries);
     }
 }
Example #5
0
        static void FatalError(Exception e)
        {
            Log.AddChannel("exception", "exception.log");
            var rpt = BuildExceptionReport(e).ToString();

            Log.Write("exception", "{0}", rpt);
            Console.Error.WriteLine(rpt);

            if (Game.Settings.Debug.ShowFatalErrorDialog && !Game.Settings.Server.Dedicated)
            {
                Game.Renderer.Device.Quit();
                FatalErrorDialog.Show();
            }
        }
Example #6
0
        static void FatalError(Exception e)
        {
            Log.AddChannel("exception", "exception.log");

            if (Game.ModData != null)
            {
                var mod = Game.ModData.Manifest.Mod;
                Log.Write("exception", "{0} Mod at Version {1}", mod.Title, mod.Version);
            }

            Log.Write("exception", "Operating System: {0} ({1})", Platform.CurrentPlatform, Environment.OSVersion);
            Log.Write("exception", "Runtime Version: {0}", Platform.RuntimeVersion);
            var rpt = BuildExceptionReport(e).ToString();

            Log.Write("exception", "{0}", rpt);
            Console.Error.WriteLine(rpt);
        }
Example #7
0
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;

            Settings = new Settings(Platform.SupportDir + "settings.yaml", args);

            Log.LogPath = Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar;
            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("sync", "syncreport.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");

            if (Settings.Server.DiscoverNatDevices)
            {
                UPnP.TryNatDiscovery();
            }
            else
            {
                Settings.Server.NatDeviceAvailable = false;
                Settings.Server.AllowPortForward   = false;
            }

            FileSystem.Mount(".");             // Needed to access shaders
            Renderer.Initialize(Game.Settings.Graphics.Mode);
            Renderer = new Renderer();

            Console.WriteLine("Available mods:");
            foreach (var mod in Mod.AllMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            Sound.Create(Settings.Sound.Engine);
            InitializeWithMods(Settings.Game.Mods);

            if (Settings.Server.DiscoverNatDevices)
            {
                RunAfterDelay(Settings.Server.NatDiscoveryTimeout, () =>
                              UPnP.TryStoppingNatDiscovery()
                              );
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            // brutal hack
            Application.CurrentCulture = CultureInfo.InvariantCulture;

            if (Debugger.IsAttached || args.Contains("--just-die"))
            {
                Run(args);
                return;
            }

            try
            {
                Run(args);
            }
            catch (Exception e)
            {
                Log.AddChannel("exception", "exception.log");
                Log.Write("exception", "{0}", e.ToString());
                throw;
            }
        }
Example #9
0
        static void FatalError(Exception e)
        {
            Log.AddChannel("exception", "exception.log");

            if (Game.modData != null)
            {
                var mod = Game.modData.Manifest.Mod;
                Log.Write("exception", "{0} Mod at Version {1}", mod.Title, mod.Version);
            }

            Log.Write("exception", "Operating System: {0} ({1})", Platform.CurrentPlatform, Environment.OSVersion);
            Log.Write("exception", "Runtime Version: {0}", Platform.RuntimeVersion);
            var rpt = BuildExceptionReport(e).ToString();

            Log.Write("exception", "{0}", rpt);
            Console.Error.WriteLine(rpt);

            if (Game.Settings.Debug.ShowFatalErrorDialog && !Game.Settings.Server.Dedicated)
            {
                Game.Renderer.Device.Dispose();
                Platform.ShowFatalErrorDialog();
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            // brutal hack
            Application.CurrentCulture = CultureInfo.InvariantCulture;

            if (Debugger.IsAttached || args.Contains("--just-die"))
            {
                Run(args);
                return;
            }

            try
            {
                Run(args);
            }
            catch (Exception e)
            {
                Log.AddChannel("exception", "exception.log");
                var rpt = BuildExceptionReport(e).ToString();
                Log.Write("exception", "{0}", rpt);
                Console.Error.WriteLine(rpt);
            }
        }
Example #11
0
        static void FatalError(Exception e)
        {
            Log.AddChannel("exception", "exception.log");

            if (Game.ModData != null)
            {
                var mod = Game.ModData.Manifest.Mod;
                Log.Write("exception", "{0} Mod at Version {1}", mod.Title, mod.Version);
            }

            if (Game.OrderManager != null && Game.OrderManager.World != null && Game.OrderManager.World.Map != null)
            {
                var map = Game.OrderManager.World.Map;
                Log.Write("exception", "on map {0} ({1} by {2}).", map.Uid, map.Title, map.Author);
            }

            Log.Write("exception", "Date: {0:u}", DateTime.UtcNow);
            Log.Write("exception", "Operating System: {0} ({1})", Platform.CurrentPlatform, Environment.OSVersion);
            Log.Write("exception", "Runtime Version: {0}", Platform.RuntimeVersion);
            var rpt = BuildExceptionReport(e).ToString();

            Log.Write("exception", "{0}", rpt);
            Console.Error.WriteLine(rpt);
        }
Example #12
0
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("sync", "syncreport.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");
            Log.AddChannel("irc", "irc.log");

            if (Settings.Server.DiscoverNatDevices)
            {
                UPnP.TryNatDiscovery();
            }
            else
            {
                Settings.Server.NatDeviceAvailable = false;
                Settings.Server.AllowPortForward   = false;
            }

            GeoIP.Initialize();

            var renderers = new[] { Settings.Graphics.Renderer, "Default", null };

            foreach (var r in renderers)
            {
                if (r == null)
                {
                    throw new InvalidOperationException("No suitable renderers were found. Check graphics.log for details.");
                }

                Settings.Graphics.Renderer = r;
                try
                {
                    Renderer = new Renderer(Settings.Graphics, Settings.Server);
                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Fallback in place. Check graphics.log for details.");
                }
            }

            Sound = new Sound(Settings.Sound.Engine);

            GlobalChat = new GlobalChat();

            Console.WriteLine("Available mods:");
            foreach (var mod in ModMetadata.AllMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(Settings.Game.Mod, args);

            if (Settings.Server.DiscoverNatDevices)
            {
                RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.StoppingNatDiscovery);
            }
        }
Example #13
0
        static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            // Load the engine version as early as possible so it can be written to exception logs
            try
            {
                EngineVersion = File.ReadAllText(Platform.ResolvePath(Path.Combine(".", "VERSION"))).Trim();
            }
            catch { }

            if (string.IsNullOrEmpty(EngineVersion))
            {
                EngineVersion = "Unknown";
            }

            Console.WriteLine("Engine version is {0}", EngineVersion);

            // Special case handling of Game.Mod argument: if it matches a real filesystem path
            // then we use this to override the mod search path, and replace it with the mod id
            var modID            = args.GetValue("Game.Mod", null);
            var explicitModPaths = new string[0];

            if (modID != null && (File.Exists(modID) || Directory.Exists(modID)))
            {
                explicitModPaths = new[] { modID };
                modID            = Path.GetFileNameWithoutExtension(modID);
            }

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");
            Log.AddChannel("irc", "irc.log");
            Log.AddChannel("nat", "nat.log");

            Sound    = new Sound();
            Renderer = new Renderer(Settings.Graphics);
            GeoIP.Initialize();

            if (Settings.Server.DiscoverNatDevices)
            {
                discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);
            }

            var modSearchArg   = args.GetValue("Engine.ModSearchPaths", null);
            var modSearchPaths = modSearchArg != null?
                                 FieldLoader.GetValue <string[]>("Engine.ModsPath", modSearchArg) :
                                     new[] { Path.Combine(".", "mods") };

            Mods = new InstalledMods(modSearchPaths, explicitModPaths);
            Console.WriteLine("Internal mods:");
            foreach (var mod in Mods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);
            }

            ExternalMods = new ExternalMods();

            Manifest currentMod;

            if (modID != null && Mods.TryGetValue(modID, out currentMod))
            {
                var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location);

                // Sanitize input from platform-specific launchers
                // Process.Start requires paths to not be quoted, even if they contain spaces
                if (launchPath.First() == '"' && launchPath.Last() == '"')
                {
                    launchPath = launchPath.Substring(1, launchPath.Length - 2);
                }

                ExternalMods.Register(Mods[modID], launchPath, ModRegistration.User);

                ExternalMod activeMod;
                if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out activeMod))
                {
                    ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User);
                }
            }

            Console.WriteLine("External mods:");
            foreach (var mod in ExternalMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(modID, args);
        }
Example #14
0
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly;

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("sync", "syncreport.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");

            if (Settings.Server.DiscoverNatDevices)
            {
                UPnP.TryNatDiscovery();
            }
            else
            {
                Settings.Server.NatDeviceAvailable = false;
                Settings.Server.AllowPortForward   = false;
            }

            try
            {
                GeoIpDatabase = new DatabaseReader("GeoLite2-Country.mmdb");
            }
            catch (Exception e)
            {
                Log.Write("geoip", "DatabaseReader failed: {0}", e);
            }

            GlobalFileSystem.Mount(Platform.GameDir);             // Needed to access shaders
            var renderers = new[] { Settings.Graphics.Renderer, "Sdl2", null };

            foreach (var r in renderers)
            {
                if (r == null)
                {
                    throw new InvalidOperationException("No suitable renderers were found. Check graphics.log for details.");
                }

                Settings.Graphics.Renderer = r;
                try
                {
                    Renderer = new Renderer(Settings.Graphics, Settings.Server);
                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Fallback in place. Check graphics.log for details.");
                }
            }

            try
            {
                Sound.Create(Settings.Sound.Engine);
            }
            catch (Exception e)
            {
                Log.Write("sound", "{0}", e);
                Console.WriteLine("Creating the sound engine failed. Fallback in place. Check sound.log for details.");
                Settings.Sound.Engine = "Null";
                Sound.Create(Settings.Sound.Engine);
            }

            Console.WriteLine("Available mods:");
            foreach (var mod in ModMetadata.AllMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(Settings.Game.Mod, args);

            if (Settings.Server.DiscoverNatDevices)
            {
                RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.StoppingNatDiscovery);
            }
        }
Example #15
0
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;

            Settings = new Settings(Platform.SupportDir + "settings.yaml", args);

            Log.LogPath = Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar;
            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("sync", "syncreport.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");

            if (Settings.Server.DiscoverNatDevices)
            {
                UPnP.TryNatDiscovery();
            }
            else
            {
                Settings.Server.NatDeviceAvailable = false;
                Settings.Server.AllowPortForward   = false;
            }

            FileSystem.Mount(".");             // Needed to access shaders
            var renderers = new[] { Settings.Graphics.Renderer, "Sdl2", "Gl", "Cg", null };

            foreach (var r in renderers)
            {
                if (r == null)
                {
                    throw new InvalidOperationException("No suitable renderers were found. Check graphics.log for details.");
                }

                Settings.Graphics.Renderer = r;
                try
                {
                    Renderer.Initialize(Settings.Graphics.Mode);
                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Fallback in place. Check graphics.log for details.");
                }
            }

            Renderer = new Renderer();

            try
            {
                Sound.Create(Settings.Sound.Engine);
            }
            catch (Exception e)
            {
                Log.Write("sound", "{0}", e);
                Console.WriteLine("Creating the sound engine failed. Fallback in place. Check sound.log for details.");
                Settings.Sound.Engine = "Null";
                Sound.Create(Settings.Sound.Engine);
            }

            Console.WriteLine("Available mods:");
            foreach (var mod in Mod.AllMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeWithMod(Settings.Game.Mod);

            if (Settings.Server.DiscoverNatDevices)
            {
                RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.TryStoppingNatDiscovery);
            }
        }
Example #16
0
        static void Initialize(Arguments args)
        {
            var engineDirArg = args.GetValue("Engine.EngineDir", null);

            if (!string.IsNullOrEmpty(engineDirArg))
            {
                Platform.OverrideEngineDir(engineDirArg);
            }

            var supportDirArg = args.GetValue("Engine.SupportDir", null);

            if (!string.IsNullOrEmpty(supportDirArg))
            {
                Platform.OverrideSupportDir(supportDirArg);
            }

            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            // Load the engine version as early as possible so it can be written to exception logs
            try
            {
                EngineVersion = File.ReadAllText(Path.Combine(Platform.EngineDir, "VERSION")).Trim();
            }
            catch { }

            if (string.IsNullOrEmpty(EngineVersion))
            {
                EngineVersion = "Unknown";
            }

            Console.WriteLine("Engine version is {0}", EngineVersion);
            Console.WriteLine("Runtime: {0}", Platform.RuntimeVersion);

            // Special case handling of Game.Mod argument: if it matches a real filesystem path
            // then we use this to override the mod search path, and replace it with the mod id
            var modID            = args.GetValue("Game.Mod", null);
            var explicitModPaths = new string[0];

            if (modID != null && (File.Exists(modID) || Directory.Exists(modID)))
            {
                explicitModPaths = new[] { modID };
                modID            = Path.GetFileNameWithoutExtension(modID);
            }

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("server", "server.log", true);
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");
            Log.AddChannel("nat", "nat.log");
            Log.AddChannel("client", "client.log");

            var platforms = new[] { Settings.Game.Platform, "Default", null };

            foreach (var p in platforms)
            {
                if (p == null)
                {
                    throw new InvalidOperationException("Failed to initialize platform-integration library. Check graphics.log for details.");
                }

                Settings.Game.Platform = p;
                try
                {
                    var rendererPath = Path.Combine(Platform.BinDir, "OpenRA.Platforms." + p + ".dll");

#if !MONO
                    var loader       = new AssemblyLoader(rendererPath);
                    var platformType = loader.LoadDefaultAssembly().GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t));
#else
                    var assembly     = Assembly.LoadFile(rendererPath);
                    var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t));
#endif

                    if (platformType == null)
                    {
                        throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation.");
                    }

                    var platform = (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null);
                    Renderer = new Renderer(platform, Settings.Graphics);
                    Sound    = new Sound(platform, Settings.Sound);

                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Check graphics.log for details.");

                    Renderer?.Dispose();

                    Sound?.Dispose();
                }
            }

            Nat.Initialize();

            var modSearchArg   = args.GetValue("Engine.ModSearchPaths", null);
            var modSearchPaths = modSearchArg != null?
                                 FieldLoader.GetValue <string[]>("Engine.ModsPath", modSearchArg) :
                                     new[] { Path.Combine(Platform.EngineDir, "mods") };

            Mods = new InstalledMods(modSearchPaths, explicitModPaths);
            Console.WriteLine("Internal mods:");
            foreach (var mod in Mods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);
            }

            modLaunchWrapper = args.GetValue("Engine.LaunchWrapper", null);

            ExternalMods = new ExternalMods();

            if (modID != null && Mods.TryGetValue(modID, out _))
            {
                var launchPath = args.GetValue("Engine.LaunchPath", null);
                var launchArgs = new List <string>();

                // Sanitize input from platform-specific launchers
                // Process.Start requires paths to not be quoted, even if they contain spaces
                if (launchPath != null && launchPath.First() == '"' && launchPath.Last() == '"')
                {
                    launchPath = launchPath.Substring(1, launchPath.Length - 2);
                }

                if (launchPath == null)
                {
                    // When launching the assembly directly we must propagate the Engine.EngineDir argument if defined
                    // Platform-specific launchers are expected to manage this internally.
                    launchPath = Assembly.GetEntryAssembly().Location;
                    if (!string.IsNullOrEmpty(engineDirArg))
                    {
                        launchArgs.Add("Engine.EngineDir=\"" + engineDirArg + "\"");
                    }
                }

                ExternalMods.Register(Mods[modID], launchPath, launchArgs, ModRegistration.User);

                if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out var activeMod))
                {
                    ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User);
                }
            }

            Console.WriteLine("External mods:");
            foreach (var mod in ExternalMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(modID, args);
            Ui.InitializeTranslation();
        }
Example #17
0
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("sync", "syncreport.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");
            Log.AddChannel("irc", "irc.log");
            Log.AddChannel("nat", "nat.log");

            var platforms = new[] { Settings.Game.Platform, "Default", null };

            foreach (var p in platforms)
            {
                if (p == null)
                {
                    throw new InvalidOperationException("Failed to initialize platform-integration library. Check graphics.log for details.");
                }

                Settings.Game.Platform = p;
                try
                {
                    var rendererPath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + p + ".dll"));
                    var assembly     = Assembly.LoadFile(rendererPath);

                    var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t));
                    if (platformType == null)
                    {
                        throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation.");
                    }

                    var platform = (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null);
                    Renderer = new Renderer(platform, Settings.Graphics);
                    Sound    = new Sound(platform, Settings.Sound);

                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Check graphics.log for details.");

                    if (Renderer != null)
                    {
                        Renderer.Dispose();
                    }

                    if (Sound != null)
                    {
                        Sound.Dispose();
                    }
                }
            }

            GeoIP.Initialize();

            if (!Game.Settings.Server.DiscoverNatDevices)
            {
                Game.Settings.Server.AllowPortForward = false;
            }
            else
            {
                discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);
                Game.Settings.Server.AllowPortForward = true;
            }

            GlobalChat = new GlobalChat();

            Console.WriteLine("Available mods:");
            foreach (var mod in ModMetadata.AllMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(Settings.Game.Mod, args);
        }
Example #18
0
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            // Special case handling of Game.Mod argument: if it matches a real filesystem path
            // then we use this to override the mod search path, and replace it with the mod id
            var    modArgument   = args.GetValue("Game.Mod", null);
            string customModPath = null;

            if (modArgument != null && (File.Exists(modArgument) || Directory.Exists(modArgument)))
            {
                customModPath = modArgument;
                args.ReplaceValue("Game.Mod", Path.GetFileNameWithoutExtension(modArgument));
            }

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");
            Log.AddChannel("irc", "irc.log");
            Log.AddChannel("nat", "nat.log");

            var platforms = new[] { Settings.Game.Platform, "Default", null };

            foreach (var p in platforms)
            {
                if (p == null)
                {
                    throw new InvalidOperationException("Failed to initialize platform-integration library. Check graphics.log for details.");
                }

                Settings.Game.Platform = p;
                try
                {
                    var rendererPath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + p + ".dll"));
                    var assembly     = Assembly.LoadFile(rendererPath);

                    var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t));
                    if (platformType == null)
                    {
                        throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation.");
                    }

                    var platform = (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null);
                    Renderer = new Renderer(platform, Settings.Graphics);
                    Sound    = new Sound(platform, Settings.Sound);

                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Check graphics.log for details.");

                    if (Renderer != null)
                    {
                        Renderer.Dispose();
                    }

                    if (Sound != null)
                    {
                        Sound.Dispose();
                    }
                }
            }

            GeoIP.Initialize();

            if (!Settings.Server.DiscoverNatDevices)
            {
                Settings.Server.AllowPortForward = false;
            }
            else
            {
                discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);
                Settings.Server.AllowPortForward = true;
            }

            GlobalChat = new GlobalChat();

            Mods = new InstalledMods(customModPath);
            Console.WriteLine("Available mods:");
            foreach (var mod in Mods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);
            }

            InitializeMod(Settings.Game.Mod, args);
        }
Example #19
0
        static void Main(string[] args)
        {
            Log.AddChannel("perf", null);
            Log.AddChannel("debug", null);

            Game.InitializeSettings(Arguments.Empty);

            if (args.Length == 0)
            {
                PrintUsage(new InstalledMods(null), null);
                return;
            }

            var    modId         = args[0];
            string customModPath = null;

            if (File.Exists(modId) || Directory.Exists(modId))
            {
                customModPath = modId;
                modId         = Path.GetFileNameWithoutExtension(modId);
            }

            var mods = new InstalledMods(customModPath);

            if (!mods.Keys.Contains(modId))
            {
                PrintUsage(mods, null);
                return;
            }

            var modData = new ModData(mods[modId], mods);
            var utility = new Utility(modData, mods);

            args = args.Skip(1).ToArray();
            var actions = new UtilityActions();

            foreach (var commandType in modData.ObjectCreator.GetTypesImplementing <IUtilityCommand>())
            {
                var command = (IUtilityCommand)Activator.CreateInstance(commandType);
                var kvp     = new KeyValuePair <Action <Utility, string[]>, Func <string[], bool> >(command.Run, command.ValidateArguments);
                actions.Add(command.Name, kvp);
            }

            if (args.Length == 0)
            {
                PrintUsage(mods, actions);
                return;
            }

            try
            {
                var command = args[0];
                if (!actions.ContainsKey(command))
                {
                    throw new NoSuchCommandException(command);
                }

                var action             = actions[command].Key;
                var validateActionArgs = actions[command].Value;

                if (validateActionArgs.Invoke(args))
                {
                    action.Invoke(utility, args);
                }
                else
                {
                    Console.WriteLine("Invalid arguments for '{0}'", command);
                    GetActionUsage(command, action);
                }
            }
            catch (Exception e)
            {
                Log.AddChannel("utility", "utility.log");
                Log.Write("utility", "Received args: {0}", args.JoinWith(" "));
                Log.Write("utility", "{0}", e);

                if (e is NoSuchCommandException)
                {
                    Console.WriteLine(e.Message);
                }
                else
                {
                    Console.WriteLine("Error: Utility application crashed. See utility.log for details");
                    throw;
                }
            }
        }
Example #20
0
        static void Main(string[] args)
        {
            var engineDir = Environment.GetEnvironmentVariable("ENGINE_DIR");

            if (!string.IsNullOrEmpty(engineDir))
            {
                Platform.OverrideEngineDir(engineDir);
            }

            Log.AddChannel("perf", null);
            Log.AddChannel("debug", null);

            Game.InitializeSettings(Arguments.Empty);

            var envModSearchPaths = Environment.GetEnvironmentVariable("MOD_SEARCH_PATHS");
            var modSearchPaths    = !string.IsNullOrWhiteSpace(envModSearchPaths) ?
                                    FieldLoader.GetValue <string[]>("MOD_SEARCH_PATHS", envModSearchPaths) :
                                    new[] { Path.Combine(Platform.EngineDir, "mods") };

            if (args.Length == 0)
            {
                PrintUsage(new InstalledMods(modSearchPaths, new string[0]), null);
                return;
            }

            var modId            = args[0];
            var explicitModPaths = new string[0];

            if (File.Exists(modId) || Directory.Exists(modId))
            {
                explicitModPaths = new[] { modId };
                modId            = Path.GetFileNameWithoutExtension(modId);
            }

            var mods = new InstalledMods(modSearchPaths, explicitModPaths);

            if (!mods.Keys.Contains(modId))
            {
                PrintUsage(mods, null);
                return;
            }

            var modData = new ModData(mods[modId], mods);
            var utility = new Utility(modData, mods);

            args = args.Skip(1).ToArray();
            var actions = new UtilityActions();

            foreach (var commandType in modData.ObjectCreator.GetTypesImplementing <IUtilityCommand>())
            {
                var command = (IUtilityCommand)Activator.CreateInstance(commandType);
                var kvp     = new KeyValuePair <Action <Utility, string[]>, Func <string[], bool> >(command.Run, command.ValidateArguments);
                actions.Add(command.Name, kvp);
            }

            if (args.Length == 0)
            {
                PrintUsage(mods, actions);
                return;
            }

            try
            {
                var command = args[0];
                if (!actions.ContainsKey(command))
                {
                    throw new NoSuchCommandException(command);
                }

                var action             = actions[command].Key;
                var validateActionArgs = actions[command].Value;

                if (validateActionArgs.Invoke(args))
                {
                    action.Invoke(utility, args);
                }
                else
                {
                    Console.WriteLine("Invalid arguments for '{0}'", command);
                    GetActionUsage(command, action);
                }
            }
            catch (Exception e)
            {
                Log.AddChannel("utility", "utility.log");
                Log.Write("utility", "Received args: {0}", args.JoinWith(" "));
                Log.Write("utility", "{0}", e);

                if (e is NoSuchCommandException)
                {
                    Console.WriteLine(e.Message);
                }
                else
                {
                    Console.WriteLine("Error: Utility application crashed. See utility.log for details");
                    throw;
                }
            }
        }
Example #21
0
        static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            // Load the engine version as early as possible so it can be written to exception logs
            try
            {
                EngineVersion = File.ReadAllText(Platform.ResolvePath(Path.Combine(".", "VERSION"))).Trim();
            }
            catch { }

            if (string.IsNullOrEmpty(EngineVersion))
            {
                EngineVersion = "Unknown";
            }

            Console.WriteLine("Engine version is {0}", EngineVersion);

            // Special case handling of Game.Mod argument: if it matches a real filesystem path
            // then we use this to override the mod search path, and replace it with the mod id
            var modID            = args.GetValue("Game.Mod", null);
            var explicitModPaths = new string[0];

            if (modID != null && (File.Exists(modID) || Directory.Exists(modID)))
            {
                explicitModPaths = new[] { modID };
                modID            = Path.GetFileNameWithoutExtension(modID);
            }

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");
            Log.AddChannel("irc", "irc.log");
            Log.AddChannel("nat", "nat.log");

            var platforms = new[] { Settings.Game.Platform, "Default", null };

            foreach (var p in platforms)
            {
                if (p == null)
                {
                    throw new InvalidOperationException("Failed to initialize platform-integration library. Check graphics.log for details.");
                }

                Settings.Game.Platform = p;
                try
                {
                    var rendererPath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + p + ".dll"));
                    var assembly     = Assembly.LoadFile(rendererPath);

                    var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t));
                    if (platformType == null)
                    {
                        throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation.");
                    }

                    var platform = (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null);
                    Renderer = new Renderer(platform, Settings.Graphics);
                    Sound    = new Sound(platform, Settings.Sound);

                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Check graphics.log for details.");

                    if (Renderer != null)
                    {
                        Renderer.Dispose();
                    }

                    if (Sound != null)
                    {
                        Sound.Dispose();
                    }
                }
            }

            GeoIP.Initialize();

            if (Settings.Server.DiscoverNatDevices)
            {
                discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);
            }

            var modSearchArg   = args.GetValue("Engine.ModSearchPaths", null);
            var modSearchPaths = modSearchArg != null?
                                 FieldLoader.GetValue <string[]>("Engine.ModsPath", modSearchArg) :
                                     new[] { Path.Combine(".", "mods") };

            Mods = new InstalledMods(modSearchPaths, explicitModPaths);
            Console.WriteLine("Internal mods:");
            foreach (var mod in Mods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);
            }

            ExternalMods = new ExternalMods();

            Manifest currentMod;

            if (modID != null && Mods.TryGetValue(modID, out currentMod))
            {
                var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location);

                // Sanitize input from platform-specific launchers
                // Process.Start requires paths to not be quoted, even if they contain spaces
                if (launchPath.First() == '"' && launchPath.Last() == '"')
                {
                    launchPath = launchPath.Substring(1, launchPath.Length - 2);
                }

                ExternalMods.Register(Mods[modID], launchPath, ModRegistration.User);

                ExternalMod activeMod;
                if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out activeMod))
                {
                    ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User);
                }
            }

            Console.WriteLine("External mods:");
            foreach (var mod in ExternalMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(modID, args);
        }