コード例 #1
0
        public BaseServer()
        {
            DrawAscii();

            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();

            socketListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            Config = new XmlConfig(configFilePath);
            Config.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            if (!File.Exists(configFilePath))
            {
                Config.Create();
                Logger.Info("config file created & loaded !");
            }
            else
            {
                Config.Load();
                Logger.Info("config file loaded !");
            }

            GCSettings.LatencyMode = GCLatencyMode.Batch;

            IOTaskPool = new CyclicTaskRunner(100, "Server");
            IOTaskPool.Start();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Mixi59/Stump
        static void Main(string[] args)
        {
            MessageReceiver.Initialize();
            ProtocolTypeManager.Initialize();
            NLogHelper.DefineLogProfile(false, true);
            NLogHelper.EnableLogging();
            Handler = new FakeClientPacketHandler();
            Handler.RegisterAll(Assembly.GetExecutingAssembly());


            var client1 = new FakeClient(1)
            {
                AccountName     = "loom",
                AccountPassword = "******"
            };

            client1.Connect("31.220.41.13", 5555);
        }
コード例 #3
0
ファイル: SimpleServer.cs プロジェクト: ImranJagari/Janus
        public static void Initialize()
        {
            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();

            ConnectedClients = new List <SimpleClient>();

            logger.Info("Initializing Configuration !");

            Config = new XmlConfig(configFilePath);
            Config.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies().ToDictionary(entry => entry.GetName().Name).Values.ToArray());

            if (!File.Exists(configFilePath))
            {
                Config.Create();
                logger.Info("Config file created !");
            }
            else
            {
                Config.Load();
                //Config.Save();
            }
            logger.Info("Loading protocol messages !");
            MessageReceiver.Initialize();

            logger.Info("Loading handlers !");
            PacketManager.Initialize(Assembly.GetExecutingAssembly());

            logger.Info("Loading Database !");
            DBAccessor = new DatabaseAccessor(DatabaseConfiguration);
            DBAccessor.RegisterMappingAssembly(Assembly.GetExecutingAssembly());
            DBAccessor.Initialize();
            DBAccessor.OpenConnection();
            DataManagerAllocator.Assembly   = System.Reflection.Assembly.GetExecutingAssembly();
            DatabaseManager.DefaultDatabase = DBAccessor.Database;

            logger.Info("Loading database features !");
            InitManager = Singleton <InitializationManager> .Instance;
            InitManager.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            InitManager.Initialize(InitializationPass.Database);
            InitManager.InitializeAll();
        }
コード例 #4
0
        public void Initialize()
        {
            Instance = this;

            GCSettings.LatencyMode = GCSettings.IsServerGC ? GCLatencyMode.Batch : GCLatencyMode.Interactive;

            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();

            logger.Info("Initializing Database...");
            DBAccessor = new DatabaseAccessor(DatabaseConfiguration);
            DBAccessor.RegisterMappingAssembly(Assembly.GetExecutingAssembly());
            DBAccessor.Initialize();

            logger.Info("Opening Database...");
            DBAccessor.OpenConnection();
            DBAccessor.Database.ExecutingCommand += OnExecutingDBCommand;

            MessageReceiver.Initialize();
            ProtocolTypeManager.Initialize();

            HandlerManager = ServerPacketHandler.Instance;
            HandlerManager.RegisterAll(Assembly.GetExecutingAssembly());

            ClientManager.Instance.Initialize(CreateClient);
            ClientManager.Instance.Start("x.x.x.x", 9250);

            WebServer.Initialize();

            IOTaskPool = new SelfRunningTaskPool(50, "Main TaskPool");
            IOTaskPool.CallPeriodically((int)TimeSpan.FromSeconds(10).TotalMilliseconds, KeepSQLConnectionAlive);
            IOTaskPool.CallPeriodically((int)TimeSpan.FromSeconds(10).TotalMilliseconds, WriteBufferLogs);

            IOTaskPool.Start();

            logger.Info("Server listening at port 9250");
            logger.Info("WebServer listening at port 9251");


            //     TeknoServer server = new TeknoServer("test", "test");
        }
コード例 #5
0
        public virtual void Initialize()
        {
            InstanceAsBase = this;
            Initializing   = true;

            Version = ((AssemblyInformationalVersionAttribute)System.Reflection.Assembly.GetExecutingAssembly()
                       .GetCustomAttributes <AssemblyInformationalVersionAttribute>().FirstOrDefault())
                      .InformationalVersion;

            /* Initialize Logger */
            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();
            logger = LogManager.GetCurrentClassLogger();

            if (!Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
                TaskScheduler.UnobservedTaskException      += OnUnobservedTaskException;
                Contract.ContractFailed += OnContractFailed;
            }
            else
            {
                logger.Warn("Exceptions not handled cause Debugger is attatched");
            }

            PreLoadReferences(Assembly.GetCallingAssembly());
            LoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToDictionary(entry => entry.GetName().Name);
            AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;

            if (Environment.GetCommandLineArgs().Contains("-config"))
            {
                UpdateConfigFiles();
            }

            ConsoleBase.DrawAsciiLogo();
            Console.WriteLine();

            InitializeGarbageCollector();

            logger.Info("Initializing Configuration...");
            /* Initialize Config File */
            Config = new XmlConfig(ConfigFilePath);
            Config.AddAssemblies(LoadedAssemblies.Values.ToArray());

            if (!File.Exists(ConfigFilePath))
            {
                Config.Create();
                logger.Info("Config file created");
            }
            else
            {
                Config.Load();
            }

            logger.Info("Initialize Task Pool");
            IOTaskPool = new BenchmarkedTaskPool(IOTaskInterval, "IO Task Pool");

            CommandManager = CommandManager.Instance;
            CommandManager.RegisterAll(Assembly.GetExecutingAssembly());

            logger.Info("Initializing Network Interfaces...");
            ClientManager = ClientManager.Instance;
            ClientManager.Initialize(CreateClient);

            if (Settings.InactivityDisconnectionTime.HasValue)
            {
                IOTaskPool.CallPeriodically(Settings.InactivityDisconnectionTime.Value / 4 * 1000, DisconnectAfkClient);
            }

            ClientManager.ClientConnected    += OnClientConnected;
            ClientManager.ClientDisconnected += OnClientDisconnected;

            logger.Info("Register Plugins...");
            // the plugins add them themself to the initializer
            InitializationManager = InitializationManager.Instance;
            InitializationManager.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());

            PluginManager                = PluginManager.Instance;
            PluginManager.PluginAdded   += OnPluginAdded;
            PluginManager.PluginRemoved += OnPluginRemoved;

            logger.Info("Loading Plugins...");
            PluginManager.Instance.LoadAllPlugins();

            if (IsExceptionLoggerEnabled)
            {
                ExceptionLogger         = new RavenClient(ExceptionLoggerDSN);
                ExceptionLogger.Release = Version;
#if DEBUG
                ExceptionLogger.Environment = "DEBUG";
#else
                ExceptionLogger.Environment = "RELEASE";
#endif
            }
        }
コード例 #6
0
        public virtual void Initialize()
        {
            ServerBase.InstanceAsBase = this;
            this.Initializing         = true;
            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();
            this.logger = LogManager.GetCurrentClassLogger();
            if (!Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.OnUnhandledException);
                TaskScheduler.UnobservedTaskException      += new EventHandler <UnobservedTaskExceptionEventArgs>(this.OnUnobservedTaskException);
                Contract.ContractFailed += new EventHandler <ContractFailedEventArgs>(this.OnContractFailed);
            }
            else
            {
                this.logger.Warn("Exceptions not handled cause Debugger is attatched");
            }
            ServerBase.PreLoadReferences(Assembly.GetCallingAssembly());
            this.LoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToDictionary((Assembly entry) => entry.GetName().Name);
            AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(this.OnAssemblyLoad);
            if (Environment.GetCommandLineArgs().Contains("-config"))
            {
                this.UpdateConfigFiles();
            }
            ConsoleBase.DrawAsciiLogo();
            Console.WriteLine();
            ServerBase.InitializeGarbageCollector();
            this.logger.Info("Initializing Configuration...");
            this.Config = new XmlConfig(this.ConfigFilePath);
            this.Config.AddAssemblies(this.LoadedAssemblies.Values.ToArray <Assembly>());
            if (!File.Exists(this.ConfigFilePath))
            {
                this.Config.Create(false);
                this.logger.Info("Config file created");
            }
            else
            {
                this.Config.Load();
            }
            this.logger.Info("Initialize Task Pool");
            this.IOTaskPool     = new SelfRunningTaskPool(ServerBase.IOTaskInterval, "IO Task Pool");
            this.CommandManager = Singleton <CommandManager> .Instance;
            this.CommandManager.RegisterAll(Assembly.GetExecutingAssembly());
            this.logger.Info("Initializing Network Interfaces...");
            this.ClientManager = Singleton <ClientManager> .Instance;
            this.ClientManager.Initialize(new ClientManager.CreateClientHandler(this.CreateClient));
            if (Settings.InactivityDisconnectionTime.HasValue)
            {
                this.IOTaskPool.CallPeriodically(Settings.InactivityDisconnectionTime.Value / 4 * 1000, new Action(this.DisconnectAfkClient));
            }
            this.ClientManager.ClientConnected    += new Action <BaseClient>(this.OnClientConnected);
            this.ClientManager.ClientDisconnected += new Action <BaseClient>(this.OnClientDisconnected);
            this.logger.Info("Register Plugins...");
            this.InitializationManager = Singleton <InitializationManager> .Instance;
            this.InitializationManager.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            this.PluginManager                = Singleton <PluginManager> .Instance;
            this.PluginManager.PluginAdded   += new PluginManager.PluginContextHandler(this.OnPluginAdded);
            this.PluginManager.PluginRemoved += new PluginManager.PluginContextHandler(this.OnPluginRemoved);
            this.logger.Info("Loading Plugins...");
            Singleton <PluginManager> .Instance.LoadAllPlugins();

            this.CommandManager.LoadOrCreateCommandsInfo(ServerBase.CommandsInfoFilePath);
        }