Exemple #1
0
        public void Awake()
        {
            StartConfig startConfig = StartConfigComponent.Instance.StartConfig;

            this.HttpConfig = startConfig.GetComponent <HttpConfig>();

            this.Load();
        }
Exemple #2
0
        public void Awake(StartConfig allConfig, long id)
        {
            Instance              = this;
            this.AllConfig        = allConfig;
            this.AllConfig.Parent = this;

            // 每个进程的配置
            foreach (StartConfig s in this.AllConfig.List)
            {
                s.SceneInstanceId = (s.Id << IdGenerater.HeadPos) + s.Id;

                if (s.Id == id)
                {
                    this.StartConfig = s;
                }

                InnerConfig innerConfig = s.GetComponent <InnerConfig>();
                if (innerConfig != null)
                {
                    this.innerAddressDict.Add(s.Id, innerConfig.Address);
                }

                // 每个进程里面domain的配置
                foreach (StartConfig startConfig in s.List)
                {
                    startConfig.SceneInstanceId = (startConfig.Parent.Id << IdGenerater.HeadPos) + startConfig.Id;

                    this.configDict.Add(startConfig.Id, startConfig);

                    SceneConfig sceneConfig = startConfig.GetComponent <SceneConfig>();

                    switch (sceneConfig.SceneType)
                    {
                    case SceneType.Gate:
                        this.Gates.Add(startConfig);
                        break;

                    case SceneType.Map:
                        this.nameDict.Add(sceneConfig.Name, startConfig);
                        break;

                    default:
                        this.typeDict.Add((int)sceneConfig.SceneType, startConfig);
                        break;
                    }
                }
            }
        }
Exemple #3
0
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            base.Dispose();

            Instance = null;

            this.configDict.Clear();
            this.innerAddressDict.Clear();
            this.Gates.Clear();
            this.Agents.Clear();
            this.typeDict.Clear();
            this.nameDict.Clear();
            this.StartConfig = null;
        }
Exemple #4
0
        protected override async Task Run(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            // 随机分配一个Gate
            StartConfig config = RealmGateAddressHelper.GetGate();
            //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");

            // 向gate请求一个key,客户端可以拿着这个key连接gate
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await ActorMessageSenderComponent.Instance.Call(
                config.SceneInstanceId, new R2G_GetLoginKey()
            {
                Account = request.Account
            });

            string outerAddress = config.GetParent <StartConfig>().GetComponent <OuterConfig>().Address2;

            response.Address = outerAddress;
            response.Key     = g2RGetLoginKey.Key;
            response.GateId  = g2RGetLoginKey.GateId;
            reply();
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            // 异步方法全部会回掉到主线程
            SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);

            try
            {
                TypeHelper.InitAllType();
                MongoHelper.LookupTypes(Game.EventSystem.GetAllType());
                Game.EventSystem.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)
                {
                    Log.Debug("ip:" + outerConfig.Address);
                    // 外网消息组件
                    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.Exception(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Exception(e);
            }
        }
Exemple #6
0
 public void Remove(StartConfig startConfig)
 {
     this.List.Remove(startConfig);
 }
Exemple #7
0
 public void Add(StartConfig startConfig)
 {
     startConfig.parent = this;
     this.List.Add(startConfig);
 }