Пример #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>();

                Game.Scene.AddComponent <HttpComponent>();

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

                InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                if (innerConfig != null)
                {
                    // 内网消息组件
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                }

                DBConfig dbConfig = startConfig.GetComponent <DBConfig>();
                if (dbConfig != null)
                {
                    Game.Scene.AddComponent <DBComponent, DBConfig>(dbConfig);
                }

                // 先加这里,后面删掉
                Game.EventSystem.Run(EventIdType.AfterScenesAdd);

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Пример #2
0
 public static string ToJson(object obj)
 {
     return(MongoHelper.ToJson(obj));
 }
Пример #3
0
 public static T ToObject <T>(string str)
 {
     return(MongoHelper.FromJson <T>(str));
 }
Пример #4
0
 public static void Msg(object message)
 {
     Debug(MongoHelper.ToJson(message));
 }
Пример #5
0
 public static object FromJson(Type type, string str)
 {
     return(MongoHelper.FromJson(type, str));
 }
Пример #6
0
 public override string ToString()
 {
     return(MongoHelper.ToJson(this));
 }
Пример #7
0
        public void Awake(string path, int appId)
        {
            Instance = this;

            this.configDict           = new Dictionary <int, StartConfig>();
            this.GateConfigs          = new List <StartConfig>();
            this.JoyLandlordsConfigs  = new List <StartConfig>();
            this.CardFiveStartConfigs = new List <StartConfig>();
            this.MapConfigs           = 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.User))
                    {
                        this.UserConfig = startConfig;
                    }

                    if (startConfig.AppType.Is(AppType.Lobby))
                    {
                        this.LobbyConfig = startConfig;
                    }

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

                    if (startConfig.AppType.Is(AppType.Match))
                    {
                        this.MatchConfig = startConfig;
                    }

                    if (startConfig.AppType.Is(AppType.FriendsCircle))
                    {
                        this.FriendsCircleConfig = startConfig;
                    }

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

                    if (startConfig.AppType.Is(AppType.JoyLandlords))
                    {
                        this.JoyLandlordsConfigs.Add(startConfig);
                    }

                    if (startConfig.AppType.Is(AppType.CardFiveStar))
                    {
                        this.CardFiveStartConfigs.Add(startConfig);
                    }



                    if (startConfig.AppType.Is(AppType.Gate))
                    {
                        this.GateConfigs.Add(startConfig);
                    }
                }
                catch (Exception e)
                {
                    Log.Error($"config错误: {s2} {e}");
                }
            }

            this.StartConfig = this.Get(appId);
        }
Пример #8
0
 public object DeserializeFrom(Type type, string str)
 {
     return(MongoHelper.FromJson(type, str));
 }
Пример #9
0
 public byte[] SerializeToByteArray(object obj)
 {
     return(MongoHelper.ToBson(obj));
 }
Пример #10
0
 public T DeserializeFrom <T>(byte[] bytes, int index, int count)
 {
     return(MongoHelper.FromBson <T>(bytes, index, count));
 }
Пример #11
0
 public T DeserializeFrom <T>(string str)
 {
     return(MongoHelper.FromJson <T>(str));
 }
Пример #12
0
 public T DeserializeFrom <T>(byte[] bytes)
 {
     return(MongoHelper.FromBson <T>(bytes));
 }
Пример #13
0
 public object DeserializeFrom(Type type, byte[] bytes, int index, int count)
 {
     return(MongoHelper.FromBson(type, bytes, index, count));
 }
Пример #14
0
 public object DeserializeFrom(Type type, Stream stream)
 {
     return(MongoHelper.FromStream(type, stream));
 }
Пример #15
0
 public object DeserializeFrom(Type type, byte[] bytes)
 {
     return(MongoHelper.FromBson(type, bytes));
 }
Пример #16
0
 public string SerializeToText(object obj)
 {
     return(MongoHelper.ToJson(obj));
 }