Ejemplo n.º 1
0
        private static void __INTERN_EXIT()
        {
            if (__exited)
            {
                return;
            }
            __exited = true;

            logging.Eyecatch("Stopping...");
            //unloading all extensions
            foreach (var asm in ServerExtensionInitializer.EXTENSIONS.Keys)
            {
                if (asm == null)
                {
                    continue;
                }

                try
                {
                    foreach (var tstr in ServerExtensionInitializer.INTERACTION_CLASSES)
                    {
                        Type t = asm.GetType(tstr);
                        if (t == null)
                        {
                            continue;
                        }
                        MethodInfo minfo = t.GetMethod(ServerExtensionInitializer.UNLOAD_METHOD);
                        if (minfo == null)
                        {
                            continue;
                        }
                        minfo.Invoke(null, null);
                    }
                }
                catch (Exception) { }
            }

            //disconnecting all clients (also for logging)
            lock (Client._CLIENTS_LOCK)
            {
                foreach (var client in Client.Clients_collection)
                {
                    client.Disconnect("Server is stopping");
                }
            }

            logging.Eyecatch("Server has been successfully stopped");
            Environment.Exit(__exitCode);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            ServerData.Init();
            logging = Logging.Logging.GetLogging(ServerData.ServerAppName, new ServerJournal(ServerData.ServerAppName),
                                                 new FileLogger(ServerData.ServerAppName, ServerData.LOG_DIRECTORY + FileLogger.GetNowFile(), FLgType.OVERWRITE_DTOR));

            Console.Title = ServerData.ServerAppName + " - SERVER";
            Console.SetWindowSize((int)Math.Floor(Console.WindowWidth * 1.2), (int)Math.Floor(Console.WindowHeight * 1.2));

            if (!Directory.Exists(ServerData.LOG_DIRECTORY))
            {
                Directory.CreateDirectory(ServerData.LOG_DIRECTORY);
            }
            if (!Directory.Exists(ServerData.CUR_PACKET_LOG_DIRECTORY))
            {
                Directory.CreateDirectory(ServerData.CUR_PACKET_LOG_DIRECTORY);
            }

            logging.Eyecatch("Server starting...");

            Listener.Setup();
            PacketOperations.Setup();
            Client.SetAdminPwdHash(ServerData.ADMIN_HASH_PWD);
            SetConsoleCtrlHandler(__ctrl_eventHandler, true);

            //The current (main server) thread will hang until the signal is set using Stop
            __hanger.WaitOne();

            __INTERN_EXIT();
        }