/// <summary> /// A Main függvény. Itt indul el a program. /// </summary> private static void Main(string[] args) { sRuntime.SetProcessName(Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().ManifestModule.Name)); bool help = false; string configdir = "Configs"; string configfile = "Server.yml"; string console_encoding = Encoding.UTF8.BodyName; string localization = "start"; bool colorbindmode = false; bool updateignore = false; Console.CursorVisible = false; Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; var os = new OptionSet() { { "h|?|help", "Display help.", v => help = true }, { "config-dir=", "Set up the config folder's path and name.", v => configdir = v }, { "config-file=", "Set up the config file's place.", v => configfile = v }, { "console-encoding=", "Set up the program's character encoding.", v => console_encoding = v }, { "console-localization=", "Set up the program's console language settings.", v => localization = v }, { "colorbind-mode=", "Set colorbind.", v => colorbindmode = v.ToBoolean() }, { "update-ignore", "Update ignore.", v => updateignore = true }, }; try { os.Parse(args); if(help) { ShowHelp(os); return; } } catch(OptionException oe) { Console.Error.WriteLine("{0} for options '{1}'", oe.Message, oe.OptionName); return; } if(!console_encoding.IsNumber()) Console.OutputEncoding = Encoding.GetEncoding(console_encoding); else Console.OutputEncoding = Encoding.GetEncoding(console_encoding.ToInt32()); Console.Title = "Schumix2 Server"; if(colorbindmode) Console.ForegroundColor = ConsoleColor.Gray; else Console.ForegroundColor = ConsoleColor.Blue; if(localization != "start") sLConsole.SetLocale(localization); Console.WriteLine("[Server]"); Console.WriteLine(sLConsole.GetString("To shut down the program use the <Ctrl+C> or the <quit> command!")); Console.WriteLine(sLConsole.GetString("Schumix Version: {0}"), sUtilities.GetVersion()); Console.WriteLine(sLConsole.GetString("Website: {0}"), Consts.SchumixWebsite); Console.WriteLine(sLConsole.GetString("Programmed by: {0}"), Consts.SchumixProgrammedBy); Console.WriteLine(sLConsole.GetString("Developers: {0}"), Consts.SchumixDevelopers); Console.WriteLine("================================================================================"); // 80 Console.ForegroundColor = ConsoleColor.Gray; if(!sPlatform.IsWindows) Console.WriteLine(); new Server.Config.Config(configdir, configfile, colorbindmode); sUtilities.CreatePidFile(Server.Config.ServerConfig.ConfigFile); if(localization == "start") sLConsole.SetLocale(Server.Config.LocalizationConfig.Locale); if(sPlatform.IsWindows && console_encoding == Encoding.UTF8.BodyName && CultureInfo.CurrentCulture.Name == "hu-HU" && sLConsole.Locale == "huHU") Console.OutputEncoding = Encoding.GetEncoding(852); Log.Notice("Main", sLConsole.GetString("System is starting...")); if(colorbindmode) Log.Notice("Main", sLConsole.GetString("Colorblind mode is on!")); Log.Debug("Main", sLConsole.GetString("CleanManager is starting...")); sCleanManager = new CleanManager(true); sCleanManager.Initialize(); if(updateignore) Log.Warning("Main", sLConsole.GetString("The automatic update is disabled.")); else new Update(Server.Config.ServerConfig.ConfigDirectory); sUtilities.CleanHomeDirectory(true); if(sPlatform.IsWindows) sWindows.Init(); else if(sPlatform.IsLinux) sLinux.Init(); AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { if(sListener.Exit) { Log.LargeError(sLConsole.GetString("FATAL ERROR")); Log.Error("Main", sLConsole.GetString("An unhandled exception has been thrown. ({0})"), eventArgs.ExceptionObject as Exception); sCrashDumper.CreateCrashDump(eventArgs.ExceptionObject); sRuntime.Exit(); } else Shutdown(eventArgs.ExceptionObject as Exception); }; sListener = new ServerListener(ServerConfigs.ListenerPort); sListener.Listen(); }
public SchumixBase() { try { ExitStatus = false; if(ServerConfig.Enabled) { var listener = new ClientSocket(ServerConfig.Host, ServerConfig.Port, ServerConfig.Password); Log.Debug("SchumixServer", sLConsole.GetString("Initiating connection.")); listener.Socket(); while(ThreadStop) Thread.Sleep(100); } if(ListenerConfig.Enabled) { Log.Debug("SchumixBot", sLConsole.GetString("SchumixListener starting...")); var sListener = new SchumixListener(ListenerConfig.Port); new Thread(() => sListener.Listen()).Start(); } if(sPlatform.IsLinux) ServicePointManager.ServerCertificateValidationCallback += (s,ce,ca,p) => true; WebRequest.DefaultWebProxy = null; Log.Debug("SchumixBase", sLConsole.GetString("Timer is starting...")); sTimer = new Timer(); sTimer.Start(); Log.Debug("SchumixBase", sLConsole.GetString("MySql is starting...")); DManager = new DatabaseManager(); Log.Debug("SchumixBase", sLConsole.GetString("CacheDB is starting...")); sCacheDB = new CacheDB(); sCacheDB.Load(); Log.Notice("SchumixBase", sLConsole.GetString("Successfully connected to the database.")); sLManager.Locale = LocalizationConfig.Locale; SqlInfoReConfig(); Log.Debug("SchumixBase", sLConsole.GetString("CleanManager is starting...")); sCleanManager = new CleanManager(); sCleanManager.Initialize(); if(AddonsConfig.Enabled) { Log.Debug("SchumixBase", sLConsole.GetString("AddonManager is loading...")); sAddonManager.Initialize(); sAddonManager.LoadPluginsFromDirectory(AddonsConfig.Directory); } } catch(Exception e) { Log.Error("SchumixBase", sLConsole.GetString("Failure details: {0}"), e.Message); } }