Example #1
0
        private static void Main(string[] args)
        {
            // 异步方法全部会回掉到主线程
            SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);

            try
            {
                Game.EventSystem.Add(DLLType.Model, typeof(Game).Assembly);
                Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly());

                MongoHelper.Init();

                // 命令行参数
                Parser.Default.ParseArguments <Options>(args)
                .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
                .WithParsed(o => { Game.Options = o; });

                IdGenerater.AppId = Game.Options.Id;

                // 启动配置
                StartConfig allConfig = MongoHelper.FromJson <StartConfig>(File.ReadAllText(Path.Combine("../Config/StartConfig/", Game.Options.Config)));

                StartConfig startConfig = allConfig.Get(Game.Options.Id);
                Game.Scene = EntityFactory.CreateScene(0, "Process", SceneType.Process);

                LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Scene.Id:0000}";

                Game.Scene.AddComponent <StartConfigComponent, StartConfig, long>(allConfig, startConfig.Id);

                Log.Info($"server start........................ {Game.Scene.Id}");

                Game.Scene.AddComponent <TimerComponent>();
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatcherComponent>();
                Game.Scene.AddComponent <ConfigComponent>();
                Game.Scene.AddComponent <CoroutineLockComponent>();
                // 发送普通actor消息
                Game.Scene.AddComponent <ActorMessageSenderComponent>();
                // 发送location actor消息
                Game.Scene.AddComponent <ActorLocationSenderComponent>();
                // 访问location server的组件
                Game.Scene.AddComponent <LocationProxyComponent>();
                Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                // 数值订阅组件
                Game.Scene.AddComponent <NumericWatcherComponent>();
                // 控制台组件
                Game.Scene.AddComponent <ConsoleComponent>();


                OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>();
                if (outerConfig != null)
                {
                    // 外网消息组件
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                }

                InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                if (innerConfig != null)
                {
                        << << << < HEAD
                        case AppType.Manager:
                        Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;
Example #2
0
 public object DeserializeFrom(Type type, string str)
 {
     return(MongoHelper.FromJson(type, str));
 }
Example #3
0
 public T DeserializeFrom <T>(string str)
 {
     return(MongoHelper.FromJson <T>(str));
 }
Example #4
0
        public void Awake(string path, int appId)
        {
            Instance = this;

            this.configDict  = new Dictionary <int, StartConfig>();
            this.MapConfigs  = new List <StartConfig>();
            this.GateConfigs = new List <StartConfig>();

            string[] ss = File.ReadAllText(path).Split('\n');
            foreach (string s in ss)
            {
                string s2 = s.Trim();
                if (s2 == "")
                {
                    continue;
                }
                try
                {
                    StartConfig startConfig = MongoHelper.FromJson <StartConfig>(s2);
                    this.configDict.Add(startConfig.AppId, startConfig);

                    InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                    if (innerConfig != null)
                    {
                        this.innerAddressDict.Add(startConfig.AppId, innerConfig.IPEndPoint);
                    }

                    if (startConfig.AppType.Is(AppType.Realm))
                    {
                        this.RealmConfig = startConfig;
                    }

                    if (startConfig.AppType.Is(AppType.Location))
                    {
                        this.LocationConfig = startConfig;
                    }

                    if (startConfig.AppType.Is(AppType.DB))
                    {
                        this.DBConfig = startConfig;
                    }

                    if (startConfig.AppType.Is(AppType.Map))
                    {
                        this.MapConfigs.Add(startConfig);
                    }

                    if (startConfig.AppType.Is(AppType.Gate))
                    {
                        this.GateConfigs.Add(startConfig);
                    }

                    if (startConfig.AppType.Is(AppType.Match))
                    {
                        this.MatchConfigs = startConfig;
                    }
                }
                catch (Exception e)
                {
                    Log.Error($"config错误: {s2} {e}");
                }
            }

            this.StartConfig = this.Get(appId);
        }
Example #5
0
 public static T ToObject <T>(string str)
 {
     return(MongoHelper.FromJson <T>(str));
 }
Example #6
0
 public static object FromJson(Type type, string str)
 {
     return(MongoHelper.FromJson(type, str));
 }