コード例 #1
0
        public void Awake()
        {
            DBConfig config           = Game.Scene.GetComponent <StartConfigComponent>().StartConfig.GetComponent <DBConfig>();
            string   connectionString = config.ConnectionString;

            mongoClient   = new MongoClient(connectionString);
            this.database = this.mongoClient.GetDatabase(config.DBName);
        }
コード例 #2
0
        //public static ETTask<T> Update<T>(this DBComponent db, string collectionName, T entity) where T : ComponentWithId
        //{
        //    ETTaskCompletionSource<T> tcs = new ETTaskCompletionSource<T>();
        //    DBUpdateTask<T> task = ComponentFactory.Create<DBUpdateTask<T>, string, T, ETTaskCompletionSource<T>>
        //        (collectionName, entity, tcs);
        //    db.tasks[(int)((ulong)task.Id % DBComponent.taskCount)].Add(task);
        //    return tcs.Task;
        //}

        //public static ETTask<T> Upsert<T>(this DBComponent db, string collectionName, T entity) where T : ComponentWithId
        //{
        //    ETTaskCompletionSource<T> tcs = new ETTaskCompletionSource<T>();
        //    DBUpsertTask<T> task = ComponentFactory.Create<DBUpsertTask<T>, string, T, ETTaskCompletionSource<T>>
        //        (collectionName, entity, tcs);
        //    db.tasks[(int)((ulong)task.Id % DBComponent.taskCount)].Add(task);
        //    return tcs.Task;
        //}

        //public static ETTask<bool> Delete<T>(this DBComponent db, string collectionName, long id) where T : ComponentWithId
        //{
        //    ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
        //    DBDeleteTask<T> task = ComponentFactory.CreateWithId<DBDeleteTask<T>, string, ETTaskCompletionSource<bool>>
        //        (id, collectionName, tcs);
        //    db.tasks[(int)((ulong)task.Id % DBComponent.taskCount)].Add(task);
        //    return tcs.Task;
        //}

        /// <summary>
        /// 建立連線
        /// </summary>
        private void BuildConnection()
        {
            DBConfig config           = StartConfigComponent.Instance.StartConfig.GetComponent <DBConfig>();
            string   connectionString = config.ConnectionString;

            mongoClient   = new MongoClient(connectionString);
            this.database = this.mongoClient.GetDatabase(config.DBName);
        }
コード例 #3
0
ファイル: DBComponent.cs プロジェクト: spadd/ET_Tank
        public void Awake()
        {
            DBConfig config           = StartConfigComponent.Instance.StartConfig.GetComponent <DBConfig>();
            string   connectionString = config.ConnectionString;

            mongoClient   = new MongoClient(connectionString);
            this.database = this.mongoClient.GetDatabase(config.DBName);
            for (int i = 0; i < taskCount; ++i)
            {
                DBTaskQueue taskQueue = ComponentFactory.Create <DBTaskQueue>();
                this.tasks.Add(taskQueue);
            }
        }
コード例 #4
0
        public bool OnGUI()
        {
            StartConfig startConfig = this.GetParent <StartConfig>();

            GUILayout.BeginHorizontal(GUILayout.Height(16));

            if (this.level > 0)
            {
                string s = "";
                for (int i = 1; i < this.level; ++i)
                {
                    s += $"    ";
                }
                GUILayout.Label(s, GUILayout.Width(20 * this.level));
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(240), GUILayout.Height(16));
                this.isFold = EditorGUILayout.Foldout(isFold, $"子配置数量:{startConfig.List.Count}");

                if (GUILayout.Button("添加子配置", GUILayout.Height(16), GUILayout.Width(75)))
                {
                    StartConfig s = new StartConfig();
                    startConfig.Add(s);
                    s.AddComponentNoPool <StartConfigDrawer, int>(this.level + 1);

                    for (int i = 0; i < startConfig.List.Count; ++i)
                    {
                        startConfig.List[i].Id = i + 1;
                    }

                    this.isFold = true;
                    return(false);
                }
                if (GUILayout.Button("上", GUILayout.Height(16), GUILayout.Width(30)))
                {
                    StartConfig parentStartConfig = startConfig.GetParent <StartConfig>();
                    int         index             = parentStartConfig.List.IndexOf(startConfig);
                    if (index == 0)
                    {
                        return(true);
                    }

                    parentStartConfig.List.Remove(startConfig);
                    parentStartConfig.List.Insert(index - 1, startConfig);
                    for (int i = 0; i < parentStartConfig.List.Count; ++i)
                    {
                        parentStartConfig.List[i].Id = i + 1;
                    }

                    return(false);
                }
                if (GUILayout.Button("下", GUILayout.Height(16), GUILayout.Width(30)))
                {
                    StartConfig parentStartConfig = startConfig.GetParent <StartConfig>();
                    int         index             = parentStartConfig.List.IndexOf(startConfig);
                    if (index == parentStartConfig.List.Count - 1)
                    {
                        return(true);
                    }
                    parentStartConfig.List.Remove(startConfig);
                    parentStartConfig.List.Insert(index + 1, startConfig);
                    for (int i = 0; i < parentStartConfig.List.Count; ++i)
                    {
                        parentStartConfig.List[i].Id = i + 1;
                    }
                    return(false);
                }
                GUILayout.EndHorizontal();
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(50));
                GUILayout.Label($"Id: ");
                startConfig.Id = EditorGUILayout.LongField(startConfig.Id, GUILayout.Width(30));
                GUILayout.EndHorizontal();
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(200));
                ProcessConfig processConfig = startConfig.GetComponent <ProcessConfig>();
                if (processConfig != null)
                {
                    GUILayout.Label($"  ProcessConfig(", this.style);
                    GUILayout.Label($"服务器IP: ");
                    processConfig.ServerIP = EditorGUILayout.TextField(processConfig.ServerIP, GUILayout.Width(100));
                    GUILayout.Label($"),", this.style);
                }
                GUILayout.EndHorizontal();
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(200));
                SceneConfig sceneConfig = startConfig.GetComponent <SceneConfig>();
                if (sceneConfig != null)
                {
                    GUILayout.Label($"  SceneConfig(", this.style);
                    GUILayout.Label($"SceneType: ");
                    sceneConfig.SceneType = (SceneType)EditorGUILayout.EnumPopup(sceneConfig.SceneType, GUILayout.Width(100));
                    GUILayout.Label($"Name: ");
                    sceneConfig.Name = EditorGUILayout.TextField(sceneConfig.Name, GUILayout.Width(100));
                    GUILayout.Label($"),", this.style);
                }
                GUILayout.EndHorizontal();
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(150));
                InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                if (innerConfig != null)
                {
                    GUILayout.Label($"  InnerConfig(", this.style);
                    GUILayout.Label($"内网地址:");
                    innerConfig.Address = EditorGUILayout.TextField(innerConfig.Address, GUILayout.Width(120));
                    GUILayout.Label($"),", this.style);
                }

                GUILayout.EndHorizontal();
            }
            {
                GUILayout.BeginHorizontal(GUILayout.Width(350));
                OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>();
                if (outerConfig != null)
                {
                    GUILayout.Label($"  OuterConfig(", this.style);
                    GUILayout.Label($"外网地址:");
                    outerConfig.Address = EditorGUILayout.TextField(outerConfig.Address, GUILayout.Width(120));
                    GUILayout.Label($"外网地址2:");
                    outerConfig.Address2 = EditorGUILayout.TextField(outerConfig.Address2, GUILayout.Width(120));
                    GUILayout.Label($"),", this.style);
                }

                GUILayout.EndHorizontal();
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(50));
                CopyConfig copyConfig = startConfig.GetComponent <CopyConfig>();
                if (copyConfig != null)
                {
                    GUILayout.Label($"  CopyConfig(", this.style);
                    GUILayout.Label($"),", this.style);
                }

                GUILayout.EndHorizontal();
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(50));
                MapConfig mapConfig = startConfig.GetComponent <MapConfig>();
                if (mapConfig != null)
                {
                    GUILayout.Label($"  MapConfig(", this.style);
                    GUILayout.Label($"MapType: ");
                    mapConfig.MapType = (MapType)EditorGUILayout.EnumPopup(mapConfig.MapType, GUILayout.Width(100));
                    GUILayout.Label($"),", this.style);
                }

                GUILayout.EndHorizontal();
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(350));
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();
                if (clientConfig != null)
                {
                    GUILayout.Label($"  ClientConfig(", this.style);
                    GUILayout.Label($"连接地址:");
                    clientConfig.Address = EditorGUILayout.TextField(clientConfig.Address, GUILayout.Width(120));
                    GUILayout.Label($"),", this.style);
                }

                DBConfig dbConfig = startConfig.GetComponent <DBConfig>();
                if (dbConfig != null)
                {
                    GUILayout.Label($"  DBConfig(", this.style);
                    GUILayout.Label($"连接串:");
                    dbConfig.ConnectionString = EditorGUILayout.TextField(dbConfig.ConnectionString);

                    GUILayout.Label($"DBName:");
                    dbConfig.DBName = EditorGUILayout.TextField(dbConfig.DBName);
                    GUILayout.Label($"),", this.style);
                }
                GUILayout.EndHorizontal();
            }

            {
                GUILayout.BeginHorizontal(GUILayout.Width(200), GUILayout.Height(16));
                this.st = (StartConfigComponentType)EditorGUILayout.EnumPopup(this.st, GUILayout.Width(100));

                if (GUILayout.Button("添加组件", GUILayout.Height(16)))
                {
                    Assembly assembly = Assembly.GetAssembly(typeof(Game));
                    Type     type     = assembly.GetType($"ETModel.{this.st.ToString()}");
                    startConfig.AddComponent(type);
                }

                if (GUILayout.Button("删除组件", GUILayout.Height(16)))
                {
                    Assembly assembly = Assembly.GetAssembly(typeof(Game));
                    Type     type     = assembly.GetType($"ETModel.{this.st.ToString()}");
                    startConfig.RemoveComponent(type);
                }

                if (GUILayout.Button("删除该行配置", GUILayout.Height(16)))
                {
                    startConfig.GetParent <StartConfig>().Remove(startConfig);
                    return(false);
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.EndHorizontal();

            if (this.isFold)
            {
                foreach (StartConfig child in startConfig.List)
                {
                    if (child.GetComponent <StartConfigDrawer>()?.OnGUI() == false)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #5
0
        //public StartConfig DBConfig { get; private set; }

        //public StartConfig RealmConfig { get; private set; }

        //public StartConfig LocationConfig { get; private set; }

        //public List<StartConfig> MapConfigs { get; private set; }

        //public List<StartConfig> GateConfigs { get; private set; }

        public void Awake(string path, int appId)
        {
            this.configDict = new Dictionary <int, StartConfig>();
            //this.MapConfigs = new List<StartConfig>();
            //this.GateConfigs = new List<StartConfig>();

            try
            {
                var    strData   = File.ReadAllText(path, encoding: System.Text.Encoding.UTF8);
                JArray jsonArray = JsonConvert.DeserializeObject <JArray>(strData);
                foreach (JObject jsonData in jsonArray)
                {
                    StartConfig startConfig = new StartConfig();
                    startConfig.AppId    = jsonData["AppId"].Value <int>();
                    startConfig.AppType  = Enum.Parse <AppType>(jsonData["AppType"].Value <string>(), true);
                    startConfig.ServerIP = jsonData["ServerIP"].Value <string>();
                    var outerConfig = jsonData["OuterConfig"]?.Value <JObject>();
                    if (outerConfig != null)
                    {
                        OuterConfig cfg = new OuterConfig();
                        cfg.Host = outerConfig["Host"].Value <string>();
                        cfg.Port = outerConfig["Port"].Value <int>();
                        cfg.BeginInit();
                        cfg.EndInit();
                        startConfig.AddComponent(cfg);
                    }
                    var innerConfig = jsonData["InnerConfig"]?.Value <JObject>();
                    if (innerConfig != null)
                    {
                        InnerConfig cfg = new InnerConfig();
                        cfg.Host = innerConfig["Host"].Value <string>();
                        cfg.Port = innerConfig["Port"].Value <int>();
                        cfg.BeginInit();
                        cfg.EndInit();
                        startConfig.AddComponent(cfg);
                    }
                    var locationConfig = jsonData["LocationConfig"]?.Value <JObject>();
                    if (locationConfig != null)
                    {
                        LocationConfig cfg = new LocationConfig();
                        cfg.Host = locationConfig["Host"].Value <string>();
                        cfg.Port = locationConfig["Port"].Value <int>();
                        cfg.BeginInit();
                        cfg.EndInit();
                        startConfig.AddComponent(cfg);
                    }


                    var httpConfig = jsonData["HttpConfig"]?.Value <JObject>();
                    if (httpConfig != null)
                    {
                        HttpConfig cfg = new HttpConfig();
                        cfg.Url              = httpConfig["Url"].Value <string>();
                        cfg.AppId            = httpConfig["AppId"].Value <int>();
                        cfg.AppKey           = httpConfig["AppKey"].Value <string>();
                        cfg.ManagerSystemUrl = httpConfig["ManagerSystemUrl"].Value <string>();
                        cfg.BeginInit();
                        cfg.EndInit();
                        startConfig.AddComponent(cfg);
                    }
                    var dbConfig = jsonData["DBConfig"]?.Value <JObject>();
                    if (dbConfig != null)
                    {
                        DBConfig cfg = new DBConfig();
                        cfg.ConnectionString = dbConfig["ConnectionString"].Value <string>();
                        cfg.DBName           = dbConfig["DBName"].Value <string>();
                        cfg.BeginInit();
                        cfg.EndInit();
                        startConfig.AddComponent(cfg);
                    }
                    var clientConfig = jsonData["ClientConfig"]?.Value <JObject>();
                    if (clientConfig != null)
                    {
                        ClientConfig cfg = new ClientConfig();
                        cfg.Host = clientConfig["Host"].Value <string>();
                        cfg.Port = clientConfig["Port"].Value <int>();
                        cfg.BeginInit();
                        cfg.EndInit();
                        startConfig.AddComponent(cfg);
                    }


                    startConfig.BeginInit();
                    startConfig.EndInit();
                    this.configDict.Add(startConfig.AppId, startConfig);
                }
            }
            catch (Exception e)
            {
                Log.Error($"config错误: {path} {e}");
            }

            this.StartConfig = this.Get(appId);
        }
コード例 #6
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);
            }
        }