Example #1
0
        internal static void Initialize()
        {
            Console.Clear();
            DateTime Start = DateTime.Now;

            SystemMute = false;

            IrcEnabled           = false;
            ServerStarted        = DateTime.Now;
            Console.Title        = PiciEnvironment.Title + " " + PiciEnvironment.Version;
            Console.WindowHeight = 30;
            DefaultEncoding      = Encoding.Default;

            Console.ForegroundColor = ConsoleColor.Green;

            Console.WriteLine("");
            Console.WriteLine("          ______ _       _    _______             ");
            Console.WriteLine("         (_____ (_)     (_)  (_______)            ");
            Console.WriteLine("          _____) )  ____ _    _____   ____  _   _ ");
            Console.WriteLine(@"         |  ____/ |/ ___) |  |  ___) |    \| | | |");
            Console.WriteLine(@"         | |    | ( (___| |  | |_____| | | | |_| |");
            Console.WriteLine(@"         |_|    |_|\____)_|  |_______)_|_|_|____/ ");


            Console.ForegroundColor = ConsoleColor.Green;

            Console.WriteLine("                              " + PiciEnvironment.Title + " " + PiciEnvironment.Version + " (Build " + PiciEnvironment.Build + ")");


            Console.WriteLine();

            Console.ResetColor();
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine();

            cultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
            LanguageLocale.Init();

            try
            {
                ChatCommandRegister.Init();
                PetCommandHandeler.Init();
                PetLocale.Init();
                Configuration = new ConfigurationData(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"config.conf"));

                DateTime Starts = DateTime.Now;

                dbType = DatabaseType.MySQL;

                manager = new DatabaseManager(uint.Parse(PiciEnvironment.GetConfig().data["db.pool.maxsize"]), uint.Parse(PiciEnvironment.GetConfig().data["db.pool.minsize"]), int.Parse(PiciEnvironment.GetConfig().data["db.pool.minsize"]), dbType);
                manager.setServerDetails(
                    PiciEnvironment.GetConfig().data["db.hostname"],
                    uint.Parse(PiciEnvironment.GetConfig().data["db.port"]),
                    PiciEnvironment.GetConfig().data["db.username"],
                    PiciEnvironment.GetConfig().data["db.password"],
                    PiciEnvironment.GetConfig().data["db.name"]);
                manager.init();

                TimeSpan TimeUsed2 = DateTime.Now - Starts;

                LanguageLocale.InitSwearWord();

                Game = new Game(int.Parse(PiciEnvironment.GetConfig().data["game.tcp.conlimit"]));
                Game.ContinueLoading();

                ConnectionManager = new ConnectionHandeling(int.Parse(PiciEnvironment.GetConfig().data["game.tcp.port"]),
                                                            int.Parse(PiciEnvironment.GetConfig().data["game.tcp.conlimit"]),
                                                            int.Parse(PiciEnvironment.GetConfig().data["game.tcp.conperip"]),
                                                            PiciEnvironment.GetConfig().data["game.tcp.enablenagles"].ToLower() == "true");
                ConnectionManager.init();

                ConnectionManager.Start();

                StaticClientMessageHandler.Initialize();
                ClientMessageFactory.Init();

                string[] arrayshit = PiciEnvironment.GetConfig().data["mus.tcp.allowedaddr"].Split(Convert.ToChar(","));

                MusSystem = new MusSocket(PiciEnvironment.GetConfig().data["mus.tcp.bindip"], int.Parse(PiciEnvironment.GetConfig().data["mus.tcp.port"]), arrayshit, 0);

                //InitIRC();

                groupsEnabled = true;

                useSSO = true;

                TimeSpan TimeUsed = DateTime.Now - Start;

                Logging.WriteLine("Server -> Started! (" + TimeUsed.Seconds + " s, " + TimeUsed.Milliseconds + " ms)");
                isLive = true;

                Console.Beep();


                if (bool_0_12)
                {
                    Console.WriteLine("Coffee team, I appreciate you testing. ;-*");
                    System.Threading.Thread.Sleep(2500);
                    PreformShutDown(true);
                    return;
                }
            }
            catch (KeyNotFoundException e)
            {
                Logging.WriteLine("Please check your configuration file - some values appear to be missing.");
                Logging.WriteLine("Press any key to shut down ...");
                Logging.WriteLine(e.ToString());
                Console.ReadKey(true);
                PiciEnvironment.Destroy();

                return;
            }
            catch (InvalidOperationException e)
            {
                Logging.WriteLine("Failed to initialize PiciEmulator: " + e.Message);
                Logging.WriteLine("Press any key to shut down ...");

                Console.ReadKey(true);
                PiciEnvironment.Destroy();

                return;
            }

            catch (Exception e)
            {
                Console.WriteLine("Fatal error during startup: " + e.ToString());
                Console.WriteLine("Press a key to exit");

                Console.ReadKey();
                Environment.Exit(1);
            }
        }
        internal static void Initialize()
        {
            ServerStarted = DateTime.Now;
            //Console.ForegroundColor = ConsoleColor.DarkBlue;
            //Console.WriteLine("\n                                                                 ");
            //Console.WriteLine(@"        $$$$$$\    $$\                         $$\                ");
            //Console.WriteLine(@"       $$  __$$\   $$ |                        \__|               ");
            //Console.WriteLine(@"       $$ /  $$ |$$$$$$\    $$$$$$\  $$$$$$$\  $$\ $$\   $$\      ");
            //Console.WriteLine(@"       $$ |  $$ |\_$$  _|   \____$$\ $$  __$$\ $$ |\$$\ $$  |     ");
            //Console.WriteLine(@"       $$ |  $$ |  $$ |     $$$$$$$ |$$ |  $$ |$$ | \$$$$  /      ");
            //Console.WriteLine(@"       $$ |  $$ |  $$ |$$\ $$  __$$ |$$ |  $$ |$$ | $$  $$<       ");
            //Console.WriteLine(@"        $$$$$$  |  \$$$$  |\$$$$$$$ |$$ |  $$ |$$ |$$  /\$$\      ");
            //Console.WriteLine(@"        \______/    \____/  \_______|\__|  \__|\__|\__/  \__|     ");
            //Console.WriteLine("\n                                                                 ");
            //Console.ForegroundColor = ConsoleColor.DarkGreen;
            //Console.WriteLine(@"   © 2016 - 2017 - Todos os direitos reservados ao Thiago Araujo.");
            //Console.WriteLine(@"                                                                 ");
            Console.ForegroundColor = ConsoleColor.Gray;

            try
            {
                #region Starting
                Configuration = new ConfigurationData(Path.Combine(Application.StartupPath, @"Settings/configuration.ini"));

                UsersCache.Initialize();
                LowPriorityWorker.Init();
                APIexterna.InitStatus();
                LanguageLocale.Init();
                ChatCommandRegister.Init();
                PetLocale.Init();
                #endregion
                #region MySQL Configuration
                var starts = DateTime.Now;
                Logging.WriteLine("[Otanix] @ Conectando na database...");

                manager = new DatabaseManager(uint.Parse(GetConfig().data["db.pool.maxsize"]),
                                              int.Parse(GetConfig().data["db.pool.minsize"]));
                manager.setServerDetails(
                    GetConfig().data["db.hostname"],
                    uint.Parse(GetConfig().data["db.port"]),
                    GetConfig().data["db.username"],
                    GetConfig().data["db.password"],
                    GetConfig().data["db.name"]);
                manager.init();

                var timeUsed2 = DateTime.Now - starts;
                Logging.WriteLine("[Otanix] @ Conectado com sucesso na database! (" + timeUsed2.Seconds + " s, " + timeUsed2.Milliseconds + " ms)");
                #endregion
                #region Cycles Configuration
                starts = DateTime.Now;

                StaticClientMessageHandler.Initialize();
                ClientMessageFactory.Init();

                var timeUsed3 = DateTime.Now - starts;
                Logging.WriteLine("[Otanix] @ Iniciando os ciclos! (" + timeUsed3.Seconds + " s, " + timeUsed3.Milliseconds +
                                  " ms)");

                Game = new Game();
                Game.ContinueLoading();
                #endregion
                #region Connections Configuration
                ConnectionManager = new ConnectionHandeling(int.Parse(GetConfig().data["game.tcp.port"]),
                                                            int.Parse(GetConfig().data["game.tcp.conlimit"]),
                                                            int.Parse(GetConfig().data["game.tcp.conperip"]),
                                                            GetConfig().data["game.tcp.enablenagles"].ToLower() == "true");
                ConnectionManager.init();
                ConnectionManager.Start();

                Handler.Initialize(RsaKeyHolder.N, RsaKeyHolder.D, RsaKeyHolder.E);
                Logging.WriteLine("[Otanix] @ RSA Crypto iniciada!");

                if (GetConfig().data["mus.enable"].ToLower() == "true")
                {
                    MusSystem = new MusSocket(int.Parse(GetConfig().data["mus.tcp.port"]));
                }
                #endregion
                #region Last Process
                var TimeUsed = DateTime.Now - ServerStarted;
                Logging.WriteLine("[Otanix] @ ENVIRONMENT -> PRONTO! (" + TimeUsed.Seconds + " s, " + TimeUsed.Milliseconds + " ms)");
                Console.Title = "Otanix Emulador ~ Versão privada por Thiago Araujo para " + EmuSettings.HOTEL_LINK;

                if (Debugger.IsAttached)
                {
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Logging.WriteLine("[Otanix] @ Alerta: Servidor está em DEBUG, console ativado!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Logging.WriteLine("[Otanix] @ Alerta: Servidor não está em DEBUG, console desativado!");
                    Logging.DisablePrimaryWriting(false);
                }

                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("[Otanix] @ Alerta: Pressione alguma tecla para ativar o console de comandos.");
                Console.ForegroundColor = ConsoleColor.White;
                #endregion
            }
            catch (KeyNotFoundException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Logging.WriteLine("Avviso: controlla il file di configurazione, alcuni valori sembrano mancare.");
                Logging.WriteLine("Avviso: premere un tasto qualsiasi per terminare il programma...");
                Logging.WriteLine(e.ToString());
                Console.ReadKey(true);
                Destroy();
            }
            catch (InvalidOperationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Logging.WriteLine("Avviso: impossibile avviare il programma, " + e.Message);
                Logging.WriteLine("Avviso: premere un tasto qualsiasi per terminare il programma...");

                Console.ReadKey(true);
                Destroy();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Avviso: errore di avvio irreversibile, " + e);
                Console.WriteLine("Avviso: premere un tasto qualsiasi per terminare il programma...");

                Console.ReadKey();
                Environment.Exit(1);
            }
            Console.ForegroundColor = ConsoleColor.White;
        }
Example #3
0
        internal static void Initialize()
        {
            Console.Clear();
            DateTime Start = DateTime.Now;

            SystemMute = false;

            ServerStarted   = DateTime.Now;
            Console.Title   = "Loading Butterfly Emulator";
            DefaultEncoding = Encoding.Default;
            //Logging.rzFlag();
            Logging.WriteLine();
            Logging.WriteLine(PrettyVersion);



            cultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
            LanguageLocale.Init();

            try
            {
                ChatCommandRegister.Init();
                PetCommandHandeler.Init();
                PetLocale.Init();
                Configuration = new ConfigurationData(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"Settings/configuration.ini"));
                if (ButterflyEnvironment.GetConfig().data["db.password"] == "changeme")
                {
                    throw new ArgumentException("Your MySQL password may not be 'changeme'.\nChange your password to start the server.");
                }

                DateTime Starts = DateTime.Now;
                Logging.WriteLine("Connecting to database...");

                dbType = GetConfig().data.ContainsKey("db.mssql") && GetConfig().data["db.mssql"] == "true" ? DatabaseType.MSSQL : DatabaseType.MySQL;

                manager = new DatabaseManager(uint.Parse(ButterflyEnvironment.GetConfig().data["db.pool.maxsize"]), int.Parse(ButterflyEnvironment.GetConfig().data["db.pool.minsize"]), dbType);
                manager.setServerDetails(
                    ButterflyEnvironment.GetConfig().data["db.hostname"],
                    uint.Parse(ButterflyEnvironment.GetConfig().data["db.port"]),
                    ButterflyEnvironment.GetConfig().data["db.username"],
                    ButterflyEnvironment.GetConfig().data["db.password"],
                    ButterflyEnvironment.GetConfig().data["db.name"]);
                manager.init();

                TimeSpan TimeUsed2 = DateTime.Now - Starts;
                Logging.WriteLine("Connected to database! (" + TimeUsed2.Seconds + " s, " + TimeUsed2.Milliseconds + " ms)");

                LanguageLocale.InitSwearWord();

                Game = new Game(int.Parse(ButterflyEnvironment.GetConfig().data["game.tcp.conlimit"]));
                Game.ContinueLoading();

                ConnectionManager = new ConnectionHandeling(int.Parse(ButterflyEnvironment.GetConfig().data["game.tcp.port"]),
                                                            int.Parse(ButterflyEnvironment.GetConfig().data["game.tcp.conlimit"]),
                                                            int.Parse(ButterflyEnvironment.GetConfig().data["game.tcp.conperip"]),
                                                            ButterflyEnvironment.GetConfig().data["game.tcp.enablenagles"].ToLower() == "true");
                ConnectionManager.init();

                ConnectionManager.Start();

                StaticClientMessageHandler.Initialize();
                ClientMessageFactory.Init();

                string[] arrayshit = ButterflyEnvironment.GetConfig().data["mus.tcp.allowedaddr"].Split(Convert.ToChar(","));

                MusSystem = new MusSocket(ButterflyEnvironment.GetConfig().data["mus.tcp.bindip"], int.Parse(ButterflyEnvironment.GetConfig().data["mus.tcp.port"]), arrayshit, 0);

                groupsEnabled = false;
                if (Configuration.data.ContainsKey("groups.enabled"))
                {
                    if (Configuration.data["groups.enabled"] == "true")
                    {
                        groupsEnabled = true;
                    }
                }

                useSSO = true;
                if (Configuration.data.ContainsKey("auth.ssodisabled"))
                {
                    if (Configuration.data["auth.ssodisabled"] == "false")
                    {
                        useSSO = false;
                    }
                }

                TimeSpan TimeUsed = DateTime.Now - Start;

                Logging.WriteLine("ENVIRONMENT -> READY! (" + TimeUsed.Seconds + " s, " + TimeUsed.Milliseconds + " ms)");
                isLive = true;
                if (System.Diagnostics.Debugger.IsAttached || Configuration.data["debug.console"] == "1")
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Logging.WriteLine("Server is debugging: Console writing enabled");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Logging.WriteLine("Server is not debugging: Console writing disabled");
                    Logging.DisablePrimaryWriting(false);
                }
            }
            catch (KeyNotFoundException e)
            {
                Logging.WriteLine("Please check your configuration file - some values appear to be missing.");
                Logging.WriteLine("Press any key to shut down ...");
                Logging.WriteLine(e.ToString());
                Console.ReadKey(true);
                ButterflyEnvironment.Destroy();

                return;
            }
            catch (InvalidOperationException e)
            {
                Logging.WriteLine("Failed to initialize ButterflyEmulator: " + e.Message);
                Logging.WriteLine("Press any key to shut down ...");

                Console.ReadKey(true);
                ButterflyEnvironment.Destroy();

                return;
            }

            catch (Exception e)
            {
                Console.WriteLine("Fatal error during startup: " + e.ToString());
                Console.WriteLine("Press a key to exit");

                Console.ReadKey();
                Environment.Exit(1);
            }
        }