예제 #1
0
        public static void PrintLogo()
        {
            if (mLines.Count == 0)
            {
                LogoPrinter.Initialize();
            }

            PrintColoredLine(mLogoStart, mPrefixColor);
            while (PrintNextLine())
            {
                ;
            }
            PrintColoredLine(mLogoEnd, mPrefixColor);
        }
예제 #2
0
        public static void Main(string[] args)
        {
#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
#endif
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);

            try {
                mThread   = Thread.CurrentThread;
                mProcess  = Process.GetCurrentProcess();
                mAssembly = Assembly.GetEntryAssembly();
                if (mThread != null)
                {
                    mThread.Name = "Core Thread";
                }

                Timer.TimerThread ttObj = new Timer.TimerThread();
                mTimerThread      = new Thread(new ThreadStart(ttObj.TimerMain));
                mTimerThread.Name = "Timer Thread";

                int width = Math.Min(100, Console.LargestWindowWidth - 2);
                Console.CursorVisible = false;
                Console.Clear();
                Console.WindowLeft = Console.WindowTop = 0;
                if (Console.WindowWidth < width)
                {
                    Console.WindowWidth = width;
                }

                LogoPrinter.PrefixColor = EConsoleColor.Blue;
                LogoPrinter.SufixColor  = EConsoleColor.Blue;
                LogoPrinter.TextColor   = EConsoleColor.Gray;
                LogoPrinter.PrintLogo();

                Version ver = mAssembly.GetName().Version;
                CConsole.StatusLine("Shaiya.Extended Server - Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);

                mConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent);
                SetConsoleCtrlHandler(mConsoleEventHandler, true);

                mAppConf = new ApplicationSettings();
                mAppConf.ReadAll();

                Stopwatch watch = Stopwatch.StartNew();
                CConsole.Info("Connecting to SQL Server {0}...", mAppConf.Network["DB Server"]);
                mDatabase = new MySqlWrapper(mAppConf.Network["DB Server"], int.Parse(mAppConf.Network["DB Port"]), mAppConf.Network["DB User"], mAppConf.Network["DB Password"], mAppConf.Network["DB Database"]);
                MysqlError conRes = mDatabase.Prepare();
                if (conRes != MysqlError.None)
                {
                    CConsole.WriteLine(EConsoleColor.Error, " failed!");
                    throw new Exception("Failed to open Database Connection! Type: " + conRes.ToString());
                }
                watch.Stop();
                CConsole.WriteLine(EConsoleColor.Status, " done! Needed {0:F2} sec", watch.Elapsed.TotalSeconds);
                watch = null;

                ScriptDatabase.Initialize(@"Scripts\ScriptList.xml");
                ScriptCompiler.Compile(AppDomain.CurrentDomain.BaseDirectory + Path.Combine(Settings.Default.MainConfDir, Settings.Default.ScriptAssemblies), true, true);

                World.Load();

                // testing CallMethod
                ScriptCompiler.CallMethod("Initialize");

                SocketPool.Create();
                mSocketConnector = new SocketConnector(mAppConf.Network["Server IP"], mAppConf.Network.GetInt("Server Port"));
                PacketHandlers.Initialize();

                // start Timer Thread
                mTimerThread.Start();

                NetState.Initialize();

                // finished Loading
                Events.InvokeServerStarted();


                DateTime    now, last = DateTime.Now;
                const int   sampleInterval = 100;
                const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);
                int         sample         = 0;

                while (mSignal.WaitOne())
                {
                    Timer.Slice();
                    mSocketConnector.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if (Slice != null)
                    {
                        Slice();
                    }

                    // just for Diagnostics
                    if ((++sample % sampleInterval) == 0)
                    {
                        now = DateTime.Now;
                        mCyclesPerSecond[mCycleIndex++ % mCyclesPerSecond.Length] = ticksPerSecond / (now.Ticks - last.Ticks);
                        last = now;
                    }
                }
            } catch (Exception e) {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }
        }