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());

                Options     options     = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;

                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = startConfig.AppType.ToString();
                LogManager.Configuration.Variables["appId"]         = startConfig.AppId.ToString();
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:D3}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();

                switch (startConfig.AppType)
                {
                case AppType.Manager:
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                case AppType.Realm:
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    break;

                case AppType.Gate:
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    break;

                case AppType.Location:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <LocationComponent>();
                    break;

                case AppType.Map:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <UnitComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    break;

                case AppType.AllServer:
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <UnitComponent>();
                    //数据库管理组件 管理数据库链接地址,数据库名称等
                    Game.Scene.AddComponent <DBComponent>();
                    //数据库调用组件 调用DB数据库组件 增删改查
                    Game.Scene.AddComponent <DBProxyComponent>();
                    //数据库缓存 当数据反复使用中,把这个数据放在内存中,不再向数据库读取
                    Game.Scene.AddComponent <DBCacheComponent>();
                    Game.Scene.AddComponent <LocationComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    // Game.Scene.AddComponent<HttpComponent>();
                    break;

                case AppType.Benchmark:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <BenchmarkComponent, string>(clientConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketServer:
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketClient:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <WebSocketBenchmarkComponent, string>(clientConfig.Address);
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }

                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
        private static void Main(string[] args)
        {
            // 异步方法全部会回掉到主线程
            OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext();

            SynchronizationContext.SetSynchronizationContext(contex);

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

                Options     options     = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;

                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = startConfig.AppType.ToString();
                LogManager.Configuration.Variables["appId"]         = startConfig.AppId.ToString();
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:D3}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();

                switch (startConfig.AppType)
                {
                case AppType.Manager:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <AppManagerComponent>();
                    break;

                case AppType.Realm:
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    break;

                case AppType.Gate:
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    break;

                case AppType.Location:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationComponent>();
                    break;

                case AppType.Map:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <UnitComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    break;

                case AppType.AllServer:
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <UnitComponent>();
                    //PS:如果启动闪退有可能是服务器配置文件没有填数据库配置,请正确填写
                    //这里需要将DBComponent的Awake注释去掉才能连接MongoDB
                    Game.Scene.AddComponent <DBComponent>();
                    //这里需要加上DBCacheComponent才能操作MongoDB
                    Game.Scene.AddComponent <DBCacheComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <LocationComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    // Game.Scene.AddComponent<HttpComponent>();

                    //以下是斗地主服务端自定义全局组件

                    //GateGlobalComponent
                    Game.Scene.AddComponent <UserComponent>();
                    Game.Scene.AddComponent <LandlordsGateSessionKeyComponent>();

                    //MapGlobalComponent
                    Game.Scene.AddComponent <RoomComponent>();

                    //MatchGlobalComponent
                    Game.Scene.AddComponent <AllotMapComponent>();
                    Game.Scene.AddComponent <MatchComponent>();
                    Game.Scene.AddComponent <MatcherComponent>();
                    Game.Scene.AddComponent <MatchRoomComponent>();

                    //RealmGlobalComponent
                    Game.Scene.AddComponent <OnlineComponent>();
                    break;

                case AppType.Benchmark:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <BenchmarkComponent, IPEndPoint>(clientConfig.IPEndPoint);
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        contex.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#3
0
        private void OnGUI()
        {
            {
                GUILayout.BeginHorizontal();
                string[] filesArray = this.files.ToArray();
                this.selectedIndex = EditorGUILayout.Popup(this.selectedIndex, filesArray);

                string lastFile = this.fileName;
                this.fileName = this.files[this.selectedIndex];

                if (this.fileName != lastFile)
                {
                    this.LoadConfig();
                }

                this.newFileName = EditorGUILayout.TextField("文件名", this.newFileName);

                if (GUILayout.Button("添加"))
                {
                    this.fileName    = this.newFileName;
                    this.newFileName = "";
                    File.WriteAllText(this.GetFilePath(), "");
                    this.files         = this.GetConfigFiles();
                    this.selectedIndex = this.files.IndexOf(this.fileName);
                    this.LoadConfig();
                }

                if (GUILayout.Button("复制"))
                {
                    this.fileName = $"{this.fileName}-copy";
                    this.Save();
                    this.files         = this.GetConfigFiles();
                    this.selectedIndex = this.files.IndexOf(this.fileName);
                    this.newFileName   = "";
                }

                if (GUILayout.Button("重命名"))
                {
                    if (this.newFileName == "")
                    {
                        Log.Debug("请输入新名字!");
                    }
                    else
                    {
                        File.Delete(this.GetFilePath());
                        this.fileName = this.newFileName;
                        this.Save();
                        this.files         = this.GetConfigFiles();
                        this.selectedIndex = this.files.IndexOf(this.fileName);
                        this.newFileName   = "";
                    }
                }

                if (GUILayout.Button("删除"))
                {
                    File.Delete(this.GetFilePath());
                    this.files         = this.GetConfigFiles();
                    this.selectedIndex = 0;
                    this.newFileName   = "";
                }

                GUILayout.EndHorizontal();
            }

            scrollPos = GUILayout.BeginScrollView(this.scrollPos, true, true);
            for (int i = 0; i < this.startConfigs.Count; ++i)
            {
                StartConfig startConfig = this.startConfigs[i];


                GUILayout.BeginHorizontal();
                {
                    GUILayout.BeginHorizontal(GUILayout.Width(1700));
                    {
                        GUILayout.BeginHorizontal(GUILayout.Width(350));
                        GUILayout.Label($"AppId:");
                        startConfig.AppId = EditorGUILayout.IntField(startConfig.AppId, GUILayout.Width(30));
                        GUILayout.Label($"服务器IP:");
                        startConfig.ServerIP = EditorGUILayout.TextField(startConfig.ServerIP, GUILayout.Width(100));
                        GUILayout.Label($"AppType:");
                        startConfig.AppType = (AppType)EditorGUILayout.EnumPopup(startConfig.AppType);
                        GUILayout.EndHorizontal();
                    }
                    {
                        GUILayout.BeginHorizontal(GUILayout.Width(150));
                        InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                        if (innerConfig != null)
                        {
                            GUILayout.Label($"内网地址:");
                            innerConfig.Address = EditorGUILayout.TextField(innerConfig.Address, GUILayout.Width(120));
                        }

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

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

                        HttpConfig httpConfig = startConfig.GetComponent <HttpConfig>();
                        if (httpConfig != null)
                        {
                            GUILayout.Label($"AppId:");
                            httpConfig.AppId = EditorGUILayout.IntField(httpConfig.AppId, GUILayout.Width(20));
                            GUILayout.Label($"AppKey:");
                            httpConfig.AppKey = EditorGUILayout.TextField(httpConfig.AppKey);
                            GUILayout.Label($"Url:");
                            httpConfig.Url = EditorGUILayout.TextField(httpConfig.Url);
                            GUILayout.Label($"ManagerSystemUrl:");
                            httpConfig.ManagerSystemUrl = EditorGUILayout.TextField(httpConfig.ManagerSystemUrl);
                        }

                        DBConfig dbConfig = startConfig.GetComponent <DBConfig>();
                        if (dbConfig != null)
                        {
                            GUILayout.Label($"Connection:");
                            dbConfig.ConnectionString = EditorGUILayout.TextField(dbConfig.ConnectionString);

                            GUILayout.Label($"DBName:");
                            dbConfig.DBName = EditorGUILayout.TextField(dbConfig.DBName);
                        }

                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndHorizontal();
                }

                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("删除"))
                    {
                        this.startConfigs.Remove(startConfig);
                        break;
                    }

                    if (GUILayout.Button("复制"))
                    {
                        for (int j = 1; j < this.copyNum + 1; ++j)
                        {
                            StartConfig newStartConfig = MongoHelper.FromBson <StartConfig>(startConfig.ToBson());
                            newStartConfig.AppId += j;
                            this.startConfigs.Add(newStartConfig);
                        }

                        break;
                    }

                    if (i >= 0)
                    {
                        if (GUILayout.Button("上移"))
                        {
                            if (i == 0)
                            {
                                break;
                            }
                            StartConfig s = this.startConfigs[i];
                            this.startConfigs.RemoveAt(i);
                            this.startConfigs.Insert(i - 1, s);
                            for (int j = 0; j < startConfigs.Count; ++j)
                            {
                                this.startConfigs[j].AppId = j + 1;
                            }

                            break;
                        }
                    }

                    if (i <= this.startConfigs.Count - 1)
                    {
                        if (GUILayout.Button("下移"))
                        {
                            if (i == this.startConfigs.Count - 1)
                            {
                                break;
                            }
                            StartConfig s = this.startConfigs[i];
                            this.startConfigs.RemoveAt(i);
                            this.startConfigs.Insert(i + 1, s);
                            for (int j = 0; j < startConfigs.Count; ++j)
                            {
                                this.startConfigs[j].AppId = j + 1;
                            }

                            break;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();



            GUILayout.Label("");

            GUILayout.BeginHorizontal();
            this.copyNum = EditorGUILayout.IntField("复制数量: ", this.copyNum);

            GUILayout.Label($"添加的AppType:");
            this.AppType = (AppType)EditorGUILayout.EnumPopup(this.AppType);

            if (GUILayout.Button("添加一行配置"))
            {
                StartConfig newStartConfig = new StartConfig();

                newStartConfig.AppType = this.AppType;

                if (this.AppType.Is(AppType.Gate | AppType.Realm | AppType.Manager))
                {
                    newStartConfig.AddComponent <OuterConfig>();
                }

                if (this.AppType.Is(AppType.Gate | AppType.Realm | AppType.Manager | AppType.Http | AppType.DB | AppType.Map | AppType.Location | AppType.Match))
                {
                    newStartConfig.AddComponent <InnerConfig>();
                }

                if (this.AppType.Is(AppType.Http))
                {
                    newStartConfig.AddComponent <HttpConfig>();
                }

                if (this.AppType.Is(AppType.DB))
                {
                    newStartConfig.AddComponent <DBConfig>();
                }

                if (this.AppType.Is(AppType.Benchmark))
                {
                    newStartConfig.AddComponent <ClientConfig>();
                }

                if (this.AppType.Is(AppType.BenchmarkWebsocketServer))
                {
                    newStartConfig.AddComponent <OuterConfig>();
                }

                if (this.AppType.Is(AppType.BenchmarkWebsocketClient))
                {
                    newStartConfig.AddComponent <ClientConfig>();
                }

                this.startConfigs.Add(newStartConfig);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("保存"))
            {
                this.Save();
            }

            if (GUILayout.Button("启动"))
            {
                StartConfig startConfig = null;
                foreach (StartConfig config in this.startConfigs)
                {
                    if (config.AppType.Is(AppType.Manager))
                    {
                        startConfig = config;
                    }
                }

                if (startConfig == null)
                {
                    Log.Error("没有配置Manager!");
                    return;
                }

                string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config=../Config/StartConfig/{this.fileName}";
                ProcessHelper.Run("dotnet", arguments, "../Bin/");
            }
            GUILayout.EndHorizontal();
        }
示例#4
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());

                Options     options     = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;
                ConfigHelper.ConfigPath = options.ConfigOther;

                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = $"{startConfig.AppType}";
                LogManager.Configuration.Variables["appId"]         = $"{startConfig.AppId}";
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:0000}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <TimerComponent>();
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatcherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();

                DBHelper.Initialize();
                CacheHelper.Initialize();
                ETHotfix.MessageHelper.Initialize();
                CryptographyHelper.Initialize(string.Empty);

                const long pingWaitTime = 5000;
                const long pingOvertime = 60000;

                Log.Info($"Server[AppType: {startConfig.AppType}, AppId: {startConfig.AppId}]> start to initialize server!");

                switch (startConfig.AppType)
                {
                case AppType.Master:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <MasterComponent>();
                    Game.Scene.AddComponent <ProfileComponent>();
                    break;

                case AppType.Manager:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <CacheProxyComponent>();
                    Game.Scene.AddComponent <ProfileComponent>();
                    Game.Scene.AddComponent <ConsoleComponent>();
                    break;

                case AppType.DB:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <DBComponent>();
                    Game.Scene.AddComponent <DBUpgradeComponent>();
                    Game.Scene.AddComponent <CacheComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <CacheProxyComponent>();
                    Game.Scene.AddComponent <ProfileComponent>();
                    Game.Scene.AddComponent <ConsoleComponent>();
                    break;

                case AppType.Realm:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <CacheProxyComponent>();
                    Game.Scene.AddComponent <PingComponent, long, long, Action <long> >(pingWaitTime, pingOvertime, ETHotfix.NetworkHelper.OnheartbeatFailed);
                    Game.Scene.AddComponent <ProfileComponent>();
                    Game.Scene.AddComponent <ConsoleComponent>();
                    Game.Scene.AddComponent <FirebaseComponent>();
                    break;

                case AppType.Gate:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <CacheProxyComponent>();
                    Game.Scene.AddComponent <PingComponent, long, long, Action <long> >(pingWaitTime, pingOvertime, ETHotfix.NetworkHelper.OnheartbeatFailed);
                    Game.Scene.AddComponent <ProfileComponent>();
                    Game.Scene.AddComponent <ConsoleComponent>();
                    Game.Scene.AddComponent <RelationshipComponent>();
                    Game.Scene.AddComponent <FirebaseComponent>();
                    Game.Scene.AddComponent <LanguageComponent>();
                    break;

                case AppType.Location:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <LocationComponent>();
                    Game.Scene.AddComponent <ProfileComponent>();
                    Game.Scene.AddComponent <ConsoleComponent>();
                    break;

                case AppType.Lobby:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <CacheProxyComponent>();
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <LobbyComponent>();
                    Game.Scene.AddComponent <ReservationComponent>();
                    Game.Scene.AddComponent <InviteComponent>();
                    Game.Scene.AddComponent <FirebaseComponent>();
                    Game.Scene.AddComponent <LanguageComponent>();
                    Game.Scene.AddComponent <ProfileComponent>();
                    Game.Scene.AddComponent <ConsoleComponent>();
                    break;

                case AppType.Map:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <MapUnitComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <PathfindingComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <CacheProxyComponent>();
                    Game.Scene.AddComponent <ProfileComponent>();
                    Game.Scene.AddComponent <ConsoleComponent>();
                    Game.Scene.AddComponent <RoomComponent>();
                    break;

                case AppType.Http:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <HttpComponent>();
                    break;

                case AppType.AllServer:
                    // 内网消息组件
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    // 外网消息组件
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    // 发送普通actor消息
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();

                    // 发送location actor消息
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();

                    Game.Scene.AddComponent <DBComponent>();
                    Game.Scene.AddComponent <CacheComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <CacheProxyComponent>();

                    // location server需要的组件
                    Game.Scene.AddComponent <LocationComponent>();

                    // 访问location server的组件
                    Game.Scene.AddComponent <LocationProxyComponent>();

                    // 这两个组件是处理actor消息使用的
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();

                    // manager server组件,用来管理其它进程使用
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();

                    // 配置管理
                    Game.Scene.AddComponent <ConfigComponent>();

                    // recast寻路组件
                    Game.Scene.AddComponent <PathfindingComponent>();
                    Game.Scene.AddComponent <LobbyComponent>();
                    Game.Scene.AddComponent <PlayerComponent>();
                    //Game.Scene.AddComponent<UnitComponent>();
                    Game.Scene.AddComponent <RoomComponent>();
                    Game.Scene.AddComponent <MapUnitComponent>();
                    Game.Scene.AddComponent <InviteComponent>();
                    Game.Scene.AddComponent <ReservationComponent>();
                    Game.Scene.AddComponent <RelationshipComponent>();
                    Game.Scene.AddComponent <FirebaseComponent>();

                    Game.Scene.AddComponent <ConsoleComponent>();
                    Game.Scene.AddComponent <PingComponent, long, long, Action <long> >(pingWaitTime, pingOvertime, ETHotfix.NetworkHelper.OnheartbeatFailed);
                    Game.Scene.AddComponent <LanguageComponent>();
                    Game.Scene.AddComponent <DBUpgradeComponent>();

                    // 監控效能用
                    Game.Scene.AddComponent <ProfileComponent>();
                    // 熱更新用WebServer
                    Game.Scene.AddComponent <HttpComponent>();

                    break;

                case AppType.Benchmark:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <ConsoleComponent>();
                    Game.Scene.AddComponent <BenchmarkComponent, ClientConfig>(clientConfig);
                    break;

                case AppType.BenchmarkWebsocketServer:
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketClient:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <WebSocketBenchmarkComponent, string>(clientConfig.Address);
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }

                Log.Info($"Server[AppType: {startConfig.AppType}, AppId: {startConfig.AppId}]> initializes server completely!");

                if (startConfig.AppType != AppType.AllServer && startConfig.AppType != AppType.Master &&
                    startConfig.AppType != AppType.Benchmark)
                {
                    // 跟Master Server註冊位置
                    Game.Scene.GetComponent <StartConfigComponent>().RegisterService().Coroutine();
                }

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
        private void OnGUI()
        {
            GUILayout.BeginHorizontal();
            string[] filesArray = this.files.ToArray();
            this.selectedIndex = EditorGUILayout.Popup(this.selectedIndex, filesArray);

            string lastFile = this.fileName;

            this.fileName = this.files[this.selectedIndex];

            if (this.fileName != lastFile)
            {
                this.LoadConfig();
            }

            this.newFileName = EditorGUILayout.TextField("文件名", this.newFileName);

            if (GUILayout.Button("添加"))
            {
                this.fileName    = this.newFileName;
                this.newFileName = "";
                File.WriteAllText(this.GetFilePath(), "");
                this.files         = this.GetConfigFiles();
                this.selectedIndex = this.files.IndexOf(this.fileName);
                this.LoadConfig();
            }

            if (GUILayout.Button("复制"))
            {
                this.fileName = $"{this.fileName}-copy";
                this.Save();
                this.files         = this.GetConfigFiles();
                this.selectedIndex = this.files.IndexOf(this.fileName);
                this.newFileName   = "";
            }

            if (GUILayout.Button("重命名"))
            {
                if (this.newFileName == "")
                {
                    Log.Debug("请输入新名字!");
                }
                else
                {
                    File.Delete(this.GetFilePath());
                    this.fileName = this.newFileName;
                    this.Save();
                    this.files         = this.GetConfigFiles();
                    this.selectedIndex = this.files.IndexOf(this.fileName);
                    this.newFileName   = "";
                }
            }

            if (GUILayout.Button("删除"))
            {
                File.Delete(this.GetFilePath());
                this.files         = this.GetConfigFiles();
                this.selectedIndex = 0;
                this.newFileName   = "";
            }

            GUILayout.EndHorizontal();

            GUILayout.Label("配置内容:");
            for (int i = 0; i < this.startConfigs.Count; ++i)
            {
                StartConfig startConfig = this.startConfigs[i];
                GUILayout.BeginHorizontal();
                GUILayout.Label($"AppId:");
                startConfig.AppId = EditorGUILayout.IntField(startConfig.AppId);
                GUILayout.Label($"服务器IP:");
                startConfig.ServerIP = EditorGUILayout.TextField(startConfig.ServerIP);
                GUILayout.Label($"AppType:");
                startConfig.AppType = (AppType)EditorGUILayout.EnumPopup(startConfig.AppType);

                InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                if (innerConfig != null)
                {
                    GUILayout.Label($"InnerHost:");
                    innerConfig.Host = EditorGUILayout.TextField(innerConfig.Host);
                    GUILayout.Label($"InnerPort:");
                    innerConfig.Port = EditorGUILayout.IntField(innerConfig.Port);
                }

                OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>();
                if (outerConfig != null)
                {
                    GUILayout.Label($"OuterHost:");
                    outerConfig.Host = EditorGUILayout.TextField(outerConfig.Host);
                    GUILayout.Label($"OuterHost2:");
                    outerConfig.Host2 = EditorGUILayout.TextField(outerConfig.Host2);
                    GUILayout.Label($"OuterPort:");
                    outerConfig.Port = EditorGUILayout.IntField(outerConfig.Port);
                }

                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();
                if (clientConfig != null)
                {
                    GUILayout.Label($"Host:");
                    clientConfig.Host = EditorGUILayout.TextField(clientConfig.Host);
                    GUILayout.Label($"Port:");
                    clientConfig.Port = EditorGUILayout.IntField(clientConfig.Port);
                }

                HttpConfig httpConfig = startConfig.GetComponent <HttpConfig>();
                if (httpConfig != null)
                {
                    GUILayout.Label($"AppId:");
                    httpConfig.AppId = EditorGUILayout.IntField(httpConfig.AppId);
                    GUILayout.Label($"AppKey:");
                    httpConfig.AppKey = EditorGUILayout.TextField(httpConfig.AppKey);
                    GUILayout.Label($"Url:");
                    httpConfig.Url = EditorGUILayout.TextField(httpConfig.Url);
                    GUILayout.Label($"ManagerSystemUrl:");
                    httpConfig.ManagerSystemUrl = EditorGUILayout.TextField(httpConfig.ManagerSystemUrl);
                }

                DBConfig dbConfig = startConfig.GetComponent <DBConfig>();
                if (dbConfig != null)
                {
                    GUILayout.Label($"Connection:");
                    dbConfig.ConnectionString = EditorGUILayout.TextField(dbConfig.ConnectionString);

                    GUILayout.Label($"DBName:");
                    dbConfig.DBName = EditorGUILayout.TextField(dbConfig.DBName);
                }

                if (GUILayout.Button("删除"))
                {
                    this.startConfigs.Remove(startConfig);
                    break;
                }
                if (GUILayout.Button("复制"))
                {
                    for (int j = 1; j < this.copyNum + 1; ++j)
                    {
                        StartConfig newStartConfig = MongoHelper.FromBson <StartConfig>(startConfig.ToBson());
                        newStartConfig.AppId += j;
                        this.startConfigs.Add(newStartConfig);
                    }
                    break;
                }

                if (i > 0)
                {
                    if (GUILayout.Button("上移"))
                    {
                        StartConfig s = this.startConfigs[i];
                        this.startConfigs.RemoveAt(i);
                        this.startConfigs.Insert(i - 1, s);
                        for (int j = 0; j < startConfigs.Count; ++j)
                        {
                            this.startConfigs[j].AppId = j + 1;
                        }
                        break;
                    }
                }

                if (i < this.startConfigs.Count - 1)
                {
                    if (GUILayout.Button("下移"))
                    {
                        StartConfig s = this.startConfigs[i];
                        this.startConfigs.RemoveAt(i);
                        this.startConfigs.Insert(i + 1, s);
                        for (int j = 0; j < startConfigs.Count; ++j)
                        {
                            this.startConfigs[j].AppId = j + 1;
                        }
                        break;
                    }
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.Label("");

            GUILayout.BeginHorizontal();
            this.copyNum = EditorGUILayout.IntField("复制数量: ", this.copyNum);

            GUILayout.Label($"添加的AppType:");
            this.AppType = (AppType)EditorGUILayout.EnumPopup(this.AppType);

            if (GUILayout.Button("添加一行配置"))
            {
                StartConfig newStartConfig = new StartConfig();

                newStartConfig.AppType = this.AppType;

                if (this.AppType.Is(AppType.Gate | AppType.Realm | AppType.Manager))
                {
                    newStartConfig.AddComponent <OuterConfig>();
                }

                if (this.AppType.Is(AppType.Gate | AppType.Realm | AppType.Manager | AppType.Http | AppType.DB | AppType.Map | AppType.Match | AppType.Location))
                {
                    newStartConfig.AddComponent <InnerConfig>();
                }

                if (this.AppType.Is(AppType.Benchmark))
                {
                    newStartConfig.AddComponent <ClientConfig>();
                }

                if (this.AppType.Is(AppType.Http))
                {
                    newStartConfig.AddComponent <HttpConfig>();
                }

                if (this.AppType.Is(AppType.DB))
                {
                    newStartConfig.AddComponent <DBConfig>();
                }

                this.startConfigs.Add(newStartConfig);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("保存"))
            {
                this.Save();
            }

            if (GUILayout.Button("启动"))
            {
                StartConfig startConfig = null;
                foreach (StartConfig config in this.startConfigs)
                {
                    if (config.AppType.Is(AppType.Manager))
                    {
                        startConfig = config;
                    }
                }

                if (startConfig == null)
                {
                    Log.Error("没有配置Manager!");
                    return;
                }

                string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config=../Config/StartConfig/{this.fileName}";

                ProcessStartInfo info = new ProcessStartInfo("dotnet", arguments)
                {
                    UseShellExecute = true, WorkingDirectory = @"..\netcoreapp2.0\"
                };
                Process.Start(info);
            }
            GUILayout.EndHorizontal();
        }
示例#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());

                Options     options     = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;


                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = startConfig.AppType.ToString();
                LogManager.Configuration.Variables["appId"]         = startConfig.AppId.ToString();
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:D3}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatherComponent>();

                Game.Scene.AddComponent <ActorMessageSenderComponent>();    //发送Actor消息
                Game.Scene.AddComponent <ActorMessageDispatherComponent>(); //接收Actor消息并处理
                Game.Scene.AddComponent <LocationProxyComponent>();         //实体添加MailBoxComponent组件接收Actor消息 需要这个
                Game.Scene.AddComponent <DBProxyComponent>();               //用于操作数据库
                Game.Scene.AddComponent <ConfigComponent>();                //配置文件读取组件
                //Game.Scene.AddComponent<ActorLocationSenderComponent>();//也是发送Actor消息 但是仅限于当前服务器 用不着
                //自己添加组件
                Game.Scene.AddComponent <NetInnerSessionComponent>();//获取服务器内部之间的Session

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();

                Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);           //不需要测试服务器 所有服务器必须要有这个 内网组件
                switch (startConfig.AppType)
                {
                case AppType.Manager:
                    Game.Scene.AddComponent <AppManagerComponent>();

                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                case AppType.Realm:
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    //与客户端有连接都要加
                    Game.Scene.AddComponent <HeartbeatMgrComponent>();                       //心跳管理组件 验证服 也是要加的
                    break;

                case AppType.Gate:
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    //网关
                    Game.Scene.AddComponent <GateUserComponent>();                       //网关管理用户的组件
                    //与客户端有连接都要加
                    Game.Scene.AddComponent <HeartbeatMgrComponent>();                   //心跳管理组件 验证服 也是要加的
                    break;

                case AppType.Location:
                    Game.Scene.AddComponent <LocationComponent>();
                    break;

                case AppType.Map:
                    Game.Scene.AddComponent <UnitComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    //与客户端有连接都要加
                    Game.Scene.AddComponent <HeartbeatMgrComponent>();                       //心跳管理组件 验证服 也是要加的
                    break;

                case AppType.AllServer:
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <UnitComponent>();


                    Game.Scene.AddComponent <LocationComponent>();                            //本地实体组件 没用过

                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address); //外网地址组件
                    Game.Scene.AddComponent <AppManagerComponent>();                          //服务器管理组件
                    Game.Scene.AddComponent <RealmGateAddressComponent>();                    //验证服组件
                    Game.Scene.AddComponent <GateSessionKeyComponent>();                      //网关秘钥组件
                    Game.Scene.AddComponent <ServerFrameComponent>();                         //帧同步组件

                    //DB服
                    Game.Scene.AddComponent <DBComponent>();
                    Game.Scene.AddComponent <DBCacheComponent>();
                    //Game.Scene.AddComponent<HttpComponent>();

                    //自己添加组件
                    //网关
                    Game.Scene.AddComponent <GateUserComponent>();            //网关管理用户的组件
                    //用户服
                    Game.Scene.AddComponent <UserComponent>();                //用户服管理组件
                    Game.Scene.AddComponent <UserConfigComponent>();          //用户配置组件
                    //大厅服
                    Game.Scene.AddComponent <ShoppingCommodityComponent>();   //商品配置组件
                    Game.Scene.AddComponent <GameLobby>();                    //游戏大厅
                    Game.Scene.AddComponent <TopUpComponent>();               //充值组件
                    //匹配服
                    Game.Scene.AddComponent <GameMatchRoomConfigComponent>(); //匹配游戏房间配置表
                    Game.Scene.AddComponent <MatchRoomComponent>();           //匹配服房间组件
                    //卡五星游戏服
                    Game.Scene.AddComponent <FiveStarRoomComponent>();        //卡五星房间组件
                    //亲友圈服
                    Game.Scene.AddComponent <FriendsCircleComponent>();       //亲友圈组件
                    //与客户端有连接都要加
                    Game.Scene.AddComponent <HeartbeatMgrComponent>();        //心跳管理组件 验证服 也是要加的
                    break;

                case AppType.Benchmark:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <BenchmarkComponent, string>(clientConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketServer:
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketClient:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <WebSocketBenchmarkComponent, string>(clientConfig.Address);
                    break;

                case AppType.Lobby:
                    //大厅服
                    Game.Scene.AddComponent <ShoppingCommodityComponent>();   //商品配置组件
                    Game.Scene.AddComponent <GameLobby>();                    //游戏大厅
                    Game.Scene.AddComponent <TopUpComponent>();               //充值组件
                    Game.Scene.AddComponent <GameMatchRoomConfigComponent>(); //匹配游戏房间配置表 玩家获取匹配房间列表 所有也是要加
                    break;

                case AppType.User:
                    //用户服
                    Game.Scene.AddComponent <UserComponent>();       //用户服管理组件
                    Game.Scene.AddComponent <UserConfigComponent>(); //用户配置组件
                    break;

                case AppType.Match:
                    //匹配服
                    Game.Scene.AddComponent <GameMatchRoomConfigComponent>();         //匹配游戏房间配置表
                    Game.Scene.AddComponent <MatchRoomComponent>();                   //匹配服房间组件
                    break;

                case AppType.CardFiveStar:
                    //卡五星游戏服
                    Game.Scene.AddComponent <FiveStarRoomComponent>();   //卡五星房间组件
                    break;

                case AppType.FriendsCircle:
                    //亲友圈服
                    Game.Scene.AddComponent <FriendsCircleComponent>();   //亲友圈组件
                    break;

                case AppType.DB:
                    //DB服
                    Game.Scene.AddComponent <DBComponent>();
                    Game.Scene.AddComponent <DBCacheComponent>();
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#7
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());

                Options     options     = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;

                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = $"{startConfig.AppType}";
                LogManager.Configuration.Variables["appId"]         = $"{startConfig.AppId}";
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType, -8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:0000}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <TimerComponent>();
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatcherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();

                Log.Debug("服务器创建");

                switch (startConfig.AppType)
                {
                case AppType.Manager:
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                case AppType.Realm:
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    break;

                case AppType.Gate:
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    break;

                case AppType.Location:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <LocationComponent>();
                    break;

                case AppType.Map:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <UnitComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <PathfindingComponent>();
                    break;

                case AppType.AllServer:
                    // 发送普通actor消息
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();

                    // 发送location actor消息
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();

                    //数据库组件 mangodb
                    Game.Scene.AddComponent <DBComponent>();
                    //数据库组件 增删改查
                    Game.Scene.AddComponent <DBProxyComponent>();

                    // location server需要的组件
                    Game.Scene.AddComponent <LocationComponent>();

                    // 访问location server的组件
                    Game.Scene.AddComponent <LocationProxyComponent>();

                    // 这两个组件是处理actor消息使用的
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();

                    // 内网消息组件
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);

                    // 外网消息组件
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);

                    // manager server组件,用来管理其它进程使用
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();

                    // 配置管理
                    Game.Scene.AddComponent <ConfigComponent>();

                    // recast寻路组件
                    Game.Scene.AddComponent <PathfindingComponent>();

                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <UnitComponent>();

                    Game.Scene.AddComponent <ConsoleComponent>();
                    // Game.Scene.AddComponent<HttpComponent>();
                    break;

                case AppType.Benchmark:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <BenchmarkComponent, string>(clientConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketServer:
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketClient:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <WebSocketBenchmarkComponent, string>(clientConfig.Address);
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#8
0
文件: Program.cs 项目: LJM74520/nice
        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());

                // 命令行参数
                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("", 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)
                {
                    // 内网消息组件
                    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);
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            // 异步方法全部会回掉到主线程
            //OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);

            try
            {
                int    AppId      = Convert.ToInt32(args[0]);
                string configFile = "../../Config/StartConfig/LocalAllServer.json";
                if (args.Length >= 2)
                {
                    configFile = args[1];
                }
                Game.EventSystem.Add(DLLType.Model, typeof(Game).Assembly);
                //Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly());
                Game.EventSystem.Add(DLLType.Hotfix, typeof(Hotfix).Assembly);
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(configFile, AppId).StartConfig;
                IdGenerater.AppId = AppId;
                if (startConfig.AppType != AppType.Client)
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }


                LogManager.Configuration.Variables["appType"]       = startConfig.AppType.ToString();
                LogManager.Configuration.Variables["appId"]         = startConfig.AppId.ToString();
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:D3}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <OpcodeTypeComponent>();

                Game.Scene.AddComponent <MessageDispatherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();
                Game.Scene.AddComponent <NetOuterComponent>();
                Game.Scene.AddComponent <BenchmarkComponent, IPEndPoint>(clientConfig.IPEndPoint);

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#10
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());
                Game.EventSystem.Add(DLLType.Hotfix, typeof(Hotfix).Assembly);

                Options options = Game.Scene.AddComponent <OptionComponent, Options>(new Options {
                    AppId = 1, AppType = AppType.Location, Config = "../../Config/StartConfig/LocalAllServer.json"
                }).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;

                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }



                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = startConfig.AppType.ToString();
                LogManager.Configuration.Variables["appId"]         = startConfig.AppId.ToString();
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:D3}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();
                DBConfig     dbConfig     = startConfig.GetComponent <DBConfig>();
                switch (startConfig.AppType)
                {
                case AppType.Manager:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <AppManagerComponent>();
                    break;

                case AppType.Realm:
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    break;

                case AppType.Gate:
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    break;

                case AppType.Location:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationComponent>();
                    break;

                case AppType.Map:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <UnitComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    break;

                case AppType.AllServer:
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    //Game.Scene.AddComponent<PlayerComponent>();
                    Game.Scene.AddComponent <UnitComponent>();
                    Game.Scene.AddComponent <DBComponent>();
                    Game.Scene.AddComponent <DBProxyComponent>();
                    Game.Scene.AddComponent <DBCacheComponent>();
                    Game.Scene.AddComponent <LocationComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    Game.Scene.AddComponent <UnitManageComponent>();
                    Game.Scene.AddComponent <SqlComponent, string>(dbConfig.ConnectionString);
                    // Game.Scene.AddComponent<HttpComponent>();
                    break;

                case AppType.Benchmark:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <BenchmarkComponent, IPEndPoint>(clientConfig.IPEndPoint);
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }
                var locationProxyComponent = Game.Scene.GetComponent <LocationProxyComponent>();
                if (locationProxyComponent != null && startConfig.AppType != AppType.AllServer) //需要注册
                {
                    var a = locationProxyComponent.RegisterServer().Result;
                    Log.Debug(">>>" + a);
                }



                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#11
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());

                Options     options     = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;

                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = $"{startConfig.AppType}";
                LogManager.Configuration.Variables["appId"]         = $"{startConfig.AppId}";
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType, -8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:0000}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <TimerComponent>();
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatcherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();

                switch (startConfig.AppType)
                {
                //管理服务器
                //连接客户端的外网和连接内部服务器的内网,对服务器进程进行管理,自动检测和启动服务器进程
                case AppType.Manager:
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                //登录服务器,客户端连接的第一个服务器
                //对ActorMessage消息进行管理(添加,移除,分发等)
                //连接内网和外网,对内网服务器进程进行操作
                //随机分发Gate服务器地址
                case AppType.Realm:
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    break;

                //对玩家进行管理
                //对ActorMessage消息进行管理(添加,移除,分发)
                //连接内网和外网,对内网服务器进程进行操作
                //随机分配Gate服务器地址
                //对Actor消息进程进行管理
                //对玩家ID登陆后的Key进行管理
                case AppType.Gate:
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    break;

                //连接内网
                //服务器进程状态集中管理(Actor消息IP管理服务器)
                //对客户端的登陆消息进行验证和客户端登陆后连接的服务器
                //登陆后通过此服务器进行消息互动,也可称为验证服务器
                case AppType.Location:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <LocationComponent>();
                    break;

                //连接内网
                //对ActorMessage消息进行管理(添加,移除,分发等)
                //对场景内现在的活动物体存储管理
                //对内网服务器进程进行操作
                //对Actor消息进程进行管理
                //服务器帧率管理
                case AppType.Map:
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                    Game.Scene.AddComponent <UnitComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                    Game.Scene.AddComponent <PathfindingComponent>();
                    break;

                //以上服务器功能集中合并成一个服务器  另外增加DB连接组件  DB管理组件
                case AppType.AllServer:
                    // 发送普通actor消息
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();

                    // 发送location actor消息
                    Game.Scene.AddComponent <ActorLocationSenderComponent>();

                    //Game.Scene.AddComponent<DBComponent>();
                    //Game.Scene.AddComponent<DBProxyComponent>();

                    // location server需要的组件
                    Game.Scene.AddComponent <LocationComponent>();

                    // 访问location server的组件
                    Game.Scene.AddComponent <LocationProxyComponent>();

                    // 这两个组件是处理actor消息使用的
                    Game.Scene.AddComponent <MailboxDispatcherComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatcherComponent>();

                    // 内网消息组件
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);

                    // 外网消息组件
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);

                    // manager server组件,用来管理其它进程使用
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();

                    // 配置管理
                    Game.Scene.AddComponent <ConfigComponent>();

                    // recast寻路组件
                    Game.Scene.AddComponent <PathfindingComponent>();

                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <UnitComponent>();

                    Game.Scene.AddComponent <ConsoleComponent>();
                    // Game.Scene.AddComponent<HttpComponent>();
                    break;

                //连接内网和测试服务器承受力
                case AppType.Benchmark:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <BenchmarkComponent, string>(clientConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketServer:
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                    break;

                case AppType.BenchmarkWebsocketClient:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <WebSocketBenchmarkComponent, string>(clientConfig.Address);
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            if (args.Length <= 0)
            {
                Log.Fatal("请输入服务器编号");
                return;
            }
            // 异步方法全部会回掉到主线程
            SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);
            try
            {
                int    AppId      = Convert.ToInt32(args[0]);
                string configFile = "../../Config/StartConfig/LocalAllServer.json";
                if (args.Length >= 2)
                {
                    configFile = args[1];
                }
                Game.EventSystem.Add(DLLType.Model, typeof(Game).Assembly);
                //Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly());
                Game.EventSystem.Add(DLLType.Hotfix, typeof(Hotfix).Assembly);
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(configFile, AppId).StartConfig;
                IdGenerater.AppId = AppId;

                if (startConfig.AppType != AppType.Gate)
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }



                LogManager.Configuration.Variables["appType"]       = startConfig.AppType.ToString();
                LogManager.Configuration.Variables["appId"]         = startConfig.AppId.ToString();
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:D3}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatherComponent>();

                InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>();
                DBConfig    dbConfig    = startConfig.GetComponent <DBConfig>();


                Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                Game.Scene.AddComponent <LocationProxyComponent>();
                Game.Scene.AddComponent <ActorMessageSenderComponent>();
                //Game.Scene.AddComponent<GateSessionKeyComponent>();
                Game.Scene.AddComponent <PlayerManagerComponent>();



                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Log.Error(e);
            }
        }
示例#13
0
        private static void Main(string[] args)
        {
            // 异步方法全部会回掉到主线程
            OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext();

            SynchronizationContext.SetSynchronizationContext(contex);

            try
            {
                /*string strConn = "Database=usersdata;Data Source=127.0.0.1;";
                 * strConn += "User Id=root;Password=066047;port=3306;";
                 * MySqlConnection sqlConn_ = new MySqlConnection(strConn);
                 * try
                 * {
                 *  sqlConn_.Open();
                 *  Console.WriteLine("[数据库]连接成功");
                 * }
                 * catch (Exception e)
                 * {
                 *  Console.WriteLine("[数据库]连接失败" + e.Message);
                 *  return;
                 * }*/

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

                Options     options     = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;

                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = startConfig.AppType.ToString();
                LogManager.Configuration.Variables["appId"]         = startConfig.AppId.ToString();
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:D3}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();

                switch (startConfig.AppType)
                {
                case AppType.Manager:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <AppManagerComponent>();
                    break;

                case AppType.Realm:
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    break;

                case AppType.Gate:
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    break;

                case AppType.Location:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationComponent>();
                    break;

                case AppType.Map:
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <UnitComponent>();
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    break;

                case AppType.AllServer:
                    Game.Scene.AddComponent <ActorMessageSenderComponent>();
                    Game.Scene.AddComponent <PlayerComponent>();
                    Game.Scene.AddComponent <UnitComponent>();
                    //Game.Scene.AddComponent<DBComponent>();
                    //Game.Scene.AddComponent<DBProxyComponent>();
                    //Game.Scene.AddComponent<DBCacheComponent>();
                    Game.Scene.AddComponent <MySqlComponent>();
                    Game.Scene.AddComponent <LocationComponent>();
                    Game.Scene.AddComponent <ActorMessageDispatherComponent>();
                    Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
                    Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
                    Game.Scene.AddComponent <LocationProxyComponent>();
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    Game.Scene.AddComponent <ConfigComponent>();
                    Game.Scene.AddComponent <ServerFrameComponent>();
                    // Game.Scene.AddComponent<HttpComponent>();
                    break;

                case AppType.Benchmark:
                    Game.Scene.AddComponent <NetOuterComponent>();
                    Game.Scene.AddComponent <BenchmarkComponent, IPEndPoint>(clientConfig.IPEndPoint);
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        contex.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#14
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());

                Options     options     = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;

                if (!options.AppType.Is(startConfig.AppType))
                {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                IdGenerater.AppId = options.AppId;

                LogManager.Configuration.Variables["appType"]       = $"{startConfig.AppType}";
                LogManager.Configuration.Variables["appId"]         = $"{startConfig.AppId}";
                LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType, -8}";
                LogManager.Configuration.Variables["appIdFormat"]   = $"{startConfig.AppId:0000}";

                Log.Info($"server start........................ {startConfig.AppId} {startConfig.AppType}");

                Game.Scene.AddComponent <TimerComponent>();
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatcherComponent>();

                // 根据不同的AppType添加不同的组件
                OuterConfig  outerConfig  = startConfig.GetComponent <OuterConfig>();
                InnerConfig  innerConfig  = startConfig.GetComponent <InnerConfig>();
                ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>();


                // 发送普通actor消息
                Game.Scene.AddComponent <ActorMessageSenderComponent>();
                // 发送location actor消息
                Game.Scene.AddComponent <ActorLocationSenderComponent>();

                //PS:如果启动闪退有可能是服务器配置文件没有填数据库配置,请正确填写
                Game.Scene.AddComponent <DBComponent>();
                //这里需要加上DBCacheComponent才能操作MongoDB
                Game.Scene.AddComponent <DBCacheComponent>();
                Game.Scene.AddComponent <DBProxyComponent>();

                // location server需要的组件
                Game.Scene.AddComponent <LocationComponent>();
                // 访问location server的组件
                Game.Scene.AddComponent <LocationProxyComponent>();

                // 这两个组件是处理actor消息使用的
                Game.Scene.AddComponent <MailboxDispatcherComponent>();
                Game.Scene.AddComponent <ActorMessageDispatcherComponent>();

                // 内网消息组件
                Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                // 外网消息组件
                Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);

                // manager server组件,用来管理其它进程使用
                Game.Scene.AddComponent <AppManagerComponent>();
                Game.Scene.AddComponent <RealmGateAddressComponent>();
                Game.Scene.AddComponent <GateSessionKeyComponent>();
                Game.Scene.AddComponent <PlayerComponent>();
                Game.Scene.AddComponent <UnitComponent>();

                // 配置管理
                Game.Scene.AddComponent <ConfigComponent>();
                Game.Scene.AddComponent <ConsoleComponent>();

                Game.Scene.AddComponent <UserComponent>();
                Game.Scene.AddComponent <SessionKeyComponent>();
                Game.Scene.AddComponent <SessionUserComponent>();

                //斗地主服务端组件
                Game.Scene.AddComponent <OnlineComponent>();
                Game.Scene.AddComponent <LandMatchComponent>();

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#15
0
        private static void Main(string[] args)
        {
            try
            {
                BsonClassMapRegister.Register();

                Object.ObjectManager.Register("Base", typeof(Game).Assembly);
                Object.ObjectManager.Register("Model", typeof(ErrorCode).Assembly);
                Object.ObjectManager.Register("Controller", DllHelper.GetController());

                StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string[]>(args).MyConfig;

                IdGenerater.AppId = startConfig.AppId;

                LogManager.Configuration.Variables["appType"] = startConfig.AppType.ToString();
                LogManager.Configuration.Variables["appId"]   = startConfig.AppId.ToString();

                Log.Info("server start........................");

                Game.Scene.AddComponent <EventComponent>();
                Game.Scene.AddComponent <TimerComponent>();

                InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port);
                Game.Scene.AddComponent <MessageDispatherComponent, AppType>(startConfig.AppType);

                // 根据不同的AppType添加不同的组件
                OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>();
                switch (startConfig.AppType)
                {
                case AppType.Manager:
                    Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
                    Game.Scene.AddComponent <AppManagerComponent>();
                    break;

                case AppType.Realm:
                    Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    break;

                case AppType.Gate:
                    Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    break;

                case AppType.AllServer:
                    Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
                    Game.Scene.AddComponent <AppManagerComponent>();
                    Game.Scene.AddComponent <RealmGateAddressComponent>();
                    Game.Scene.AddComponent <GateSessionKeyComponent>();
                    break;

                case AppType.Robot:
                    Game.Scene.AddComponent <RobotComponent>();
                    break;

                default:
                    throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
                }

                while (true)
                {
                    Object.ObjectManager.Update();
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }