/// <summary> /// Get configured modules from the module manager /// </summary> /// <param name="gameStats">GameStats module will be returned in this variable</param> /// <param name="cdKeyValidator">CD Key Validator module will be returned in this variable</param> /// <returns>True if all modules were loaded correctly</returns> private static bool LoadConfiguredModules(out IGameStatsLog gameStats, out ICDKeyValidator cdKeyValidator) { Console.WriteLine("Initialising log writer module..."); logWriter = ModuleManager.GetModule <ILogWriter>(); ConsoleColor oldColour = Console.ForegroundColor; // Warn if the CD key validator module was not loaded if (logWriter == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Configuration error: the specified log writer module was not loaded"); Console.ForegroundColor = oldColour; MasterServer.Log("Configuration error: the specified log writer module was not loaded"); if (!ConsoleUtilities.InConsoleSession()) { WinForms.MessageBox.Show("Configuration error: the specified log writer module was not loaded", "Configuration error", WinForms.MessageBoxButtons.OK); } } Console.WriteLine("Initialising GameStats module..."); gameStats = ModuleManager.GetModule <IGameStatsLog>(); // Warn if the GameStats module was not loaded if (gameStats == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Configuration error: the specified gamestats module was not loaded"); Console.ForegroundColor = oldColour; MasterServer.Log("Configuration error: the specified gamestats module was not loaded"); if (!ConsoleUtilities.InConsoleSession()) { WinForms.MessageBox.Show("Configuration error: the specified gamestats module was not loaded", "Configuration error", WinForms.MessageBoxButtons.OK); } } Console.WriteLine("Initialising CD key validator module..."); cdKeyValidator = ModuleManager.GetModule <ICDKeyValidator>(); // Can't continue without a CD key validator module if (cdKeyValidator == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Configuration error: the specified CD key validator module was not loaded"); Console.WriteLine("Critical. Master server shutting down"); Console.ForegroundColor = oldColour; if (!ConsoleUtilities.InConsoleSession()) { WinForms.MessageBox.Show("Configuration error: the specified CD key validator module was not loaded", "Critical error", WinForms.MessageBoxButtons.OK); } ReleaseModules(); return(false); } Console.WriteLine(); return(true); }
/// <summary> /// Unhandled exceptions, try to gracefully stop the master server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { MasterServer.Log("CRITICAL: {0}", (e.ExceptionObject as Exception).Message); MasterServer.Log("CRITICAL: {0}", (e.ExceptionObject as Exception).StackTrace); MasterServer.Stop(); }
/// <summary> /// Handle a "link" command /// </summary> /// <param name="command"></param> protected void LinkCommand(string[] command) { if (command.Length < 2) { MasterServer.LogMessage("link list Displays current remote links"); MasterServer.LogMessage("link user Set username password for this server"); MasterServer.LogMessage("link add Add a new master server link"); MasterServer.LogMessage("link remove Remove a master server link"); MasterServer.LogMessage("link test Test a master server link"); return; } switch (command[1].ToLower()) { #if !WCF #warning "WCF functionality disabled - ServerList RPC will not function" #else case "list": MasterServer.LogMessage("Configured links:"); int serverIndex = 0; foreach (RemoteMasterServer remoteMaster in remoteMasters) { MasterServer.LogMessage("{0,2} -> {1}", serverIndex++, remoteMaster.InnerChannel.RemoteAddress.Uri.ToString()); } break; #endif case "user": if (command.Length > 3) { MasterServer.Settings.SyncServiceUsername = command[2]; MasterServer.Settings.SyncServicePassword = command[3]; MasterServer.Settings.Save(); MasterServer.Log("[RPC] Local user/pass updated"); } else { MasterServer.LogMessage("link user <user> <pass>"); } break; case "add": if (command.Length > 7) { ushort port = 0; if (ushort.TryParse(command[3], out port) && port > 0) { if (AddLink(command[2], port, command[4], command[5], command[6], command[7])) { MasterServer.Log("[RPC] Add link succeeded"); } else { MasterServer.LogMessage("[RPC] Add link failed"); } } else { MasterServer.LogMessage("Error: port must be a valid number"); MasterServer.LogMessage("link add <host> <port> <endpoint> <svc> <user> <pass>"); } } else { MasterServer.LogMessage("link add <host> <port> <endpoint> <svc> <user> <pass>"); } break; case "remove": if (command.Length > 2) { int index = 0; if (int.TryParse(command[2], out index) && index >= 0 && index < remoteMasters.Count) { if (RemoveLink(index)) { MasterServer.Log("[RPC] Remove link succeeded"); } else { MasterServer.LogMessage("[RPC] Remove link failed"); } } else { MasterServer.LogMessage("Error: index must be a valid index number"); } } else { MasterServer.LogMessage("link remove <index>"); MasterServer.LogMessage("Hint: use \"link list\" to determine link index"); } break; case "test": if (command.Length > 2) { int index = 0; if (int.TryParse(command[2], out index) && index >= 0 && index < remoteMasters.Count) { TestLink(index); } else { MasterServer.LogMessage("Error: index must be a valid index number"); } } else { MasterServer.LogMessage("link test <index>"); MasterServer.LogMessage("Hint: use \"link list\" to determine link index"); } break; } }
/// <summary> /// Handle application shutting down /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void CurrentDomain_ProcessExit(object sender, EventArgs e) { MasterServer.Log("ProcessExit()"); ModuleManager.ReleaseAllModules(); }
/// <summary> /// Callback from the module manager when a console command is issued /// </summary> /// <param name="command"></param> public void Command(string[] command) { if (command.Length > 0 && command[0].Trim() != "") { if (commandInterface == null || commandInterface.EchoCommands) { LogCommand(command); } switch (command[0].ToLower()) { case "stop": BeginStop(); break; case "ver": MasterServer.LogMessage("[INFO] Application : {0}", MasterServer.Title); MasterServer.LogMessage("[INFO] Version : {0}", MasterServer.Version); MasterServer.LogMessage("[INFO] NetVersion : {0}", MasterServer.NetVersion); MasterServer.LogMessage("[INFO] Copyright : {0}", MasterServer.Copyright); MasterServer.LogMessage("[INFO] Legal Notice : Unreal and the Unreal logo are registered trademarks of Epic"); MasterServer.LogMessage(" Games, Inc. ALL RIGHTS RESERVED."); break; case "clear": case "cls": log.Clear(); if (commandInterface != null) { commandInterface.Notify("LOG", "\u001B[2J"); } break; case "ls": MasterServer.LogMessage("List what?"); break; case "dir": MasterServer.LogMessage("This isn't DOS..."); break; case "motd": if (command.Length > 1) { string locale = command[1].ToLower(); if (command.Length > 2) { if (!MasterServer.SetMOTD(locale, String.Join(" ", command, 2, command.Length - 2))) { MasterServer.LogMessage("[MOTD] Error, locale \"{0}\" is not defined. MOTD was not updated.", locale); } } MasterServer.LogMessage("[MOTD] {0} = \"{1}\"", locale, MasterServer.GetMOTD(locale, false)); } else { MasterServer.LogMessage("motd <locale> <message>"); } break; case "stat": if (command.Length > 1) { switch (command[1].ToLower()) { case "clear": MasterServer.Log("Total Queries = {0}", TotalQueries); MasterServer.Log("Total Web Queries = {0}", TotalWebQueries); Stats.Default.TotalQueries = 0; Stats.Default.TotalWebQueries = 0; Stats.Default.Save(); MasterServer.Log("Stats cleared"); break; } } else { MasterServer.LogMessage("stat clear Clear statistics"); } break; case "log": if (command.Length > 1) { switch (command[1].ToLower()) { case "clear": log.Clear(); break; case "commit": if (logWriter != null) { logWriter.Commit(); } break; } } else { MasterServer.LogMessage("log clear Clear log buffer"); MasterServer.LogMessage("log commit Commit unsaved log"); } break; case "mslist": if (command.Length > 1) { switch (command[1].ToLower()) { case "on": MasterServer.Settings.MSListEnabled = true; MasterServer.Settings.Save(); MasterServer.LogMessage("MSLIST function turned ON"); break; case "off": MasterServer.Settings.MSListEnabled = false; MasterServer.Settings.Save(); MasterServer.LogMessage("MSLIST function turned OFF"); break; case "add": if (command.Length > 3) { ushort portNumber = 0; if (ushort.TryParse(command[3], out portNumber)) { } else { MasterServer.LogMessage("Invalid port number specified"); } } else { MasterServer.LogMessage("mslist add <host> <port>"); } break; case "port": if (command.Length > 2) { ushort portNumber = 0; if (ushort.TryParse(command[2], out portNumber)) { if (MasterServer.Settings.MSListInterfaces == null) { MasterServer.Settings.MSListInterfaces = new List <ushort>(); } if (MasterServer.Settings.MSListInterfaces.Contains(portNumber)) { if (MasterServer.Settings.ListenPorts.Contains(portNumber)) { MasterServer.Settings.MSListInterfaces.Remove(portNumber); MasterServer.Settings.Save(); } else { MasterServer.LogMessage("Error adding MSLIST port, the specified port is not bound"); } } else { MasterServer.Settings.MSListInterfaces.Add(portNumber); MasterServer.Settings.Save(); } break; } else { MasterServer.LogMessage("Invalid port number specified"); } } else { MasterServer.LogMessage("mslist port <port>"); List <string> boundPorts = new List <string>(); if (MasterServer.Settings.MSListInterfaces != null) { foreach (ushort port in MasterServer.Settings.MSListInterfaces) { boundPorts.Add(port.ToString()); } } MasterServer.LogMessage("Current MSLIST port bindings: {0}", String.Join(",", boundPorts.ToArray())); } break; } } else { MasterServer.LogMessage("--------------------------------"); MasterServer.LogMessage("MSLIST function is currently {0}", MasterServer.Settings.MSListEnabled ? "ON" : "OFF"); MasterServer.LogMessage("--------------------------------"); MasterServer.LogMessage("mslist on Turn MSLIST on"); MasterServer.LogMessage("mslist off Turn MSLIST off"); MasterServer.LogMessage("mslist port Set MSLIST ports"); MasterServer.LogMessage("mslist add Add MSLIST entries"); MasterServer.LogMessage("mslist remove Remove MSLIST entries"); } break; case "port": if (command.Length > 1 && (command[1].ToLower() == "bind" || command[1].ToLower() == "unbind")) { if (command.Length > 2) { ushort portNumber = 0; if (ushort.TryParse(command[2], out portNumber)) { switch (command[1].ToLower()) { case "bind": if (!MasterServer.Settings.ListenPorts.Contains(portNumber)) { MasterServer.Settings.ListenPorts.Add(portNumber); MasterServer.Settings.Save(); } Bind(portNumber); break; case "unbind": if (MasterServer.Settings.ListenPorts.Contains(portNumber)) { MasterServer.Settings.ListenPorts.Remove(portNumber); MasterServer.Settings.Save(); } if (MasterServer.Settings.MSListInterfaces != null && MasterServer.Settings.MSListInterfaces.Contains(portNumber)) { MasterServer.Settings.MSListInterfaces.Remove(portNumber); MasterServer.Settings.Save(); } UnBind(portNumber); break; } } else { MasterServer.LogMessage("[NET] Invalid port number specified"); } } else { MasterServer.LogMessage("port {0} <port>", command[1]); MasterServer.LogMessage("Current listen ports: {0}", MasterServer.ListenPorts); } } else { MasterServer.LogMessage("port bind Bind a new listen port"); MasterServer.LogMessage("port unbind Unbind a listen port"); MasterServer.LogMessage("Current listen ports: {0}", MasterServer.ListenPorts); } break; case "help": case "?": MasterServer.LogMessage("help Displays this message"); MasterServer.LogMessage("stop Gracefully stops the master server"); MasterServer.LogMessage("motd Set the Message of the Day (MOTD)"); MasterServer.LogMessage("stat Statistics commands"); MasterServer.LogMessage("log Server log commands"); break; } } }