Example #1
0
        static void Main()
        {
            // 모든 handler 등록
            HandlerHelper.Register(Assembly.GetExecutingAssembly());

            // Network 시작
            var listener = MessageSessionManager.Instance.CreateListener();
            Task.Factory.StartNew(() => listener.Start(Configuration.PylonPort), TaskCreationOptions.LongRunning);

            try
            {
                // Web Service 시작
                var webServer = new DataHttpServer(Configuration.PylonWebPort, false);
                webServer.RegisterHandler(_instance);
                webServer.ApiResourceName = "/";
                // webServer.OnLog += Logger.Write;
                webServer.OnError += Logger.Write;
                webServer.Start();
            }
            catch (Exception e)
            {
                Logger.Write("Cannot start web-server.");
                Logger.Write(e);
            }

            Logger.Write("Server is ready.");
            Console.ReadLine();

            if (_instance != null)
            {
                _instance.SaveInterChatUsers();
            }
        }
Example #2
0
        private static void Main(string[] args)
        {
            var options = new CommandOptions(args);

            // Configuration 읽기
            Configuration.Load(options.Get("--config", @"Config.xml"));

            // 설정 덮어쓰기
            options.Override("--port", ref Configuration.Port);
            options.Override("--pylonHost", ref Configuration.PylonHost);
            options.Override("--pylonPort", ref Configuration.PylonPort);
            options.Override("--mongodb", ref Configuration.UseMongoDatabase);
            options.Override("--xmldb", ref Configuration.UseXmlDatabase);
            options.Override("--sync", ref Configuration.UseDatabaseSync);

            // Sync를 사용할 경우에는 모든 EntityBind가 등록되어야 한다.
            if (Configuration.UseDatabaseSync)
            {
                Configuration.UseMongoDatabase = true;
                Configuration.UseXmlDatabase   = true;
            }

            // Datasheet 읽기
            DataCenter.Instance.Load(Configuration.DatasheetFileDirectory, Configuration.DatasheetFilePattern);

            // 모든 handler 등록 (Sync 쓸 때는 Handler 실행 안되도록 한다.)
            if (!Configuration.UseDatabaseSync)
            {
                HandlerHelper.Register(Assembly.GetExecutingAssembly());
            }

            // System Entity 생성
            EntityManager.Instance.Create(EntityManager.SystemId, DataCenter.Instance.GetCreateInfo(EntityTemplate.Ids.System));

            // Database 연결
            if (Configuration.UseMongoDatabase)
            {
                EntityBinder.Instance.AddBinder(new MongoBind(
                                                    Configuration.MongoDatabaseHost, Configuration.MongoDatabasePort,
                                                    Configuration.MongoDatabaseName, Configuration.MongoDatabaseCollectionName));
            }

            if (Configuration.UseXmlDatabase)
            {
                EntityBinder.Instance.AddBinder(new XmlBind(Configuration.XmlDatabaseDirectory));
            }

            if (Configuration.UseDatabaseSync)
            {
                EntityBinder.Instance.Sync(Configuration.SyncFromDatabaseType, Configuration.SyncToDatabaseType);

                Logger.Write("Sync Completed.");
                Console.ReadLine();
                return;
            }

            // EntityManager caching 및 준비
            EntityBinder.Instance.ForEach(each =>
            {
                if (each.Has <Player>())
                {
                    each.Get <Player>().Logged = false;

                    if (each.Has <Nameplate>())
                    {
                        var playerName = each.Get <Nameplate>().Name;
                        NameCache.Instance.Add(playerName, each.Id);
                    }
                }

                if (!each.Has <Player>() && each.Has <Pos>())
                {
                    PositionSystem.Global.Appear(each);
                }

                EntityManager.Instance.Add(each);
            });
            EntityManager.Instance.TrimIdSerial();
            Logger.Write("Player [{0}] loaded.", NameCache.Instance.Count);

            // Network 시작
            var listener = MessageSessionManager.Instance.CreateListener();

            Task.Factory.StartNew(() => listener.Start(Configuration.Port), TaskCreationOptions.LongRunning);

            // Pylon 등록
            PylonConnector.Instance.Start();

            Logger.Write("Server is ready.");
            Console.ReadLine();
        }