예제 #1
0
 /// <summary>
 /// Dispose all background worker for the thread to dispose.
 /// </summary>
 public static void Dispose()
 {
     if (Listener != null)
     {
         Listener.Dispose();
     }
     if (RCONListener != null)
     {
         RCONListener.Dispose();
     }
     if (SCONListener != null)
     {
         SCONListener.Dispose();
     }
     NancyImpl.Stop();
     if (Logger != null)
     {
         Logger.Dispose();
     }
 }
예제 #2
0
        /// <summary>
        /// Server Main Entry Point - Initialize as many things as possible here.
        /// Order is important here, any additional initialization should be place at the bottom.
        /// </summary>
        /// <param name="Directory">Start Directory.</param>
        public static void Start(string Directory)
        {
            try
            {
                // Initialize Setting
                Setting = new Setting(Directory);

                // Initialize Logger.
                Logger = new LoggerCollection();
                Logger.Start();

                if (Setting.Load())
                {
                    Setting.Save();
                }
                else
                {
                    Setting.Save();
                    Environment.Exit(0);
                    return;
                }

                // Initialize Updater
                if (Setting.CheckForUpdate)
                {
                    Updater = new Updater();
                    Updater.Update();
                }

                if (Setting.MainEntryPoint == Setting.MainEntryPointType.jianmingyong_Server)
                {
                    // Initialize Listener.
                    Listener = new Server_Client_Listener.Servers.Listener();
                    Listener.Start();

                    // Initialize RCONListener.
                    if (Setting.RCONEnable)
                    {
                        RCONListener = new RCON_Client_Listener.Servers.Listener();
                        RCONListener.Start();
                    }

                    // Initialize SCONListener.
                    if (Setting.SCONEnable)
                    {
                        SCONListener = new SCON_Client_Listener.Servers.ModuleSCON();
                        SCONListener.Start();
                        //Logger.Log("SCON have been disabled due to incompatible update. Sorry for the inconvience caused.", Server_Client_Listener.Loggers.Logger.LogTypes.Info);
                    }

                    // Initialize Nancy.
                    if (Setting.NancyEnable)
                    {
                        var dataApi = new NancyData();
                        dataApi.Add("online", GetOnlineClients);

                        NancyImpl.SetDataApi(dataApi);
                        NancyImpl.Start(Setting.NancyHost, Setting.NancyPort);
                    }
                }

                // Initialize Command.
                Command = new CommandCollection();
                Command.AddCommand();
            }
            catch (Exception ex)
            {
                ex.CatchError();
            }
        }