protected override async ETTask Run(Session session, M2A_Reload request, A2M_Reload response, Action reply) { Log.Debug("服务器DLL热更新开始"); Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly()); Log.Debug("服务器DLL热更新完成"); reply(); await ETTask.CompletedTask; }
public async ETTask Run(ModeContex contex, string content) { switch (content) { case ConsoleMode.ReloadDll: contex.Parent.RemoveComponent <ModeContex>(); Game.EventSystem.Add(DllHelper.GetHotfixAssembly()); Game.EventSystem.Load(); break; } await ETTask.CompletedTask; }
protected override void Run(Session session, M2A_Reload message, Action <A2M_Reload> reply) { A2M_Reload response = new A2M_Reload(); try { Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly()); reply(response); } catch (Exception e) { response.Error = ErrorCode.ERR_ReloadFail; StartConfig myStartConfig = Game.Scene.GetComponent <StartConfigComponent>().StartConfig; InnerConfig innerConfig = myStartConfig.GetComponent <InnerConfig>(); response.Message = $"{innerConfig.IPEndPoint} reload fail, {e}"; reply(response); } }
protected override void Run(Session session, M2A_Reload message, Action <A2M_Reload> reply) { A2M_Reload response = new A2M_Reload(); try { ObjectEvents.Instance.Register("Hotfix", DllHelper.GetHotfixAssembly()); reply(response); } catch (Exception e) { response.Error = ErrorCode.ERR_ReloadFail; StartConfig myStartConfig = Game.Scene.GetComponent <StartConfigComponent>().StartConfig; InnerConfig innerConfig = myStartConfig.GetComponent <InnerConfig>(); response.Message = $"{innerConfig.Address} reload fail, {e}"; reply(response); } }
protected override async void Run(Session session, C2G_UpdateServer message, Action <G2C_UpdateServer> reply) { Log.Debug("收到C2G_UpdateServer:" + JsonHelper.ToJson(message)); G2C_UpdateServer response = new G2C_UpdateServer(); try { Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly()); reply(response); } catch (Exception e) { response.Error = ErrorCode.ERR_ReloadFail; StartConfig myStartConfig = Game.Scene.GetComponent <StartConfigComponent>().StartConfig; InnerConfig innerConfig = myStartConfig.GetComponent <InnerConfig>(); response.Message = $"{innerConfig.IPEndPoint} reload fail, {e}"; reply(response); } // G2C_UpdateServer response = new G2C_UpdateServer(); // try // { // StartConfigComponent startConfigComponent = Game.Scene.GetComponent<StartConfigComponent>(); // Log.Debug("startConfigComponent:" + JsonHelper.ToJson(startConfigComponent)); // NetInnerComponent netInnerComponent = Game.Scene.GetComponent<NetInnerComponent>(); // foreach (StartConfig startConfig in startConfigComponent.GetAll()) // { //// if (!message.AppType.Is(startConfig.AppType)) //// { //// continue; //// } // InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>(); // Session serverSession = netInnerComponent.Get(innerConfig.IPEndPoint); // Log.Debug("发送M2A_Reload"); // await serverSession.Call(new M2A_Reload()); // } // } // catch (Exception e) // { // ReplyError(response, e, reply); // } }
private static void Main(string[] args) { // 异步方法全部会回掉到主线程 SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); try { BsonHelper.Init(); //添加Model.dll到字典维护 Game.EventSystem.Add(DLLType.Model, typeof(Game).Assembly); //添加Hotfix.dll到字典维护 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}"; Console.WriteLine($"server start........................ {startConfig.AppId} {startConfig.AppType}"); //增加计时器组件 Game.Scene.AddComponent <TimerComponent>(); //增加OpcodeType组件(是双端通讯协议的重要组成部分) 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; 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>(); Game.Scene.AddComponent <CoroutineLockComponent>(); break; case AppType.Location: Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); Game.Scene.AddComponent <LocationComponent>(); Game.Scene.AddComponent <CoroutineLockComponent>(); 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 <RecastPathComponent>(); Game.Scene.AddComponent <CoroutineLockComponent>(); break; case AppType.AllServer: // 发送普通actor消息 Game.Scene.AddComponent <ActorMessageSenderComponent>(); // 发送location actor消息 Game.Scene.AddComponent <ActorLocationSenderComponent>(); //添加MongoDB组件,处理与服务器的交互 Game.Scene.AddComponent <DBComponent>(); //添加MongoDB代理组件,代理服务端对数据库的操作 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 <RecastPathComponent>(); //添加玩家组件(使用字典维护,可当做抽象化的玩家,处于不同的游戏流程会有不同的身份) Game.Scene.AddComponent <PlayerComponent>(); //添加单位组件(这是游戏中物体的最小单元,继承自Entity) Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <ConsoleComponent>(); //RealmGlobalComponent,增加在线组件,记录在线玩家 Game.Scene.AddComponent <OnlineComponent>(); //添加碰撞实例管理者 TODO 待优化,一场游戏一个碰撞实例管理者 Game.Scene.AddComponent <B2S_WorldColliderManagerComponent>(); //添加物理世界 TODO 待优化,一场游戏一个物理世界 Game.Scene.AddComponent <B2S_WorldComponent>(); //添加碰撞检测监听者 TODO 待优化,一场游戏一个碰撞检测监听者 Game.Scene.AddComponent <B2S_CollisionListenerComponent>(); //增加碰撞体数据仓库 Game.Scene.AddComponent <B2S_ColliderDataRepositoryComponent>(); Game.Scene.AddComponent <B2S_CollisionRelationRepositoryComponent>(); //增加英雄基础数据仓库组件 Game.Scene.AddComponent <HeroBaseDataRepositoryComponent>(); Game.Scene.AddComponent <CoroutineLockComponent>(); Game.Scene.AddComponent <NP_SyncComponent>(); Game.Scene.AddComponent <NP_TreeDataRepository>(); //战斗系统中的事件系统组件 TODO 待优化,一场游戏挂载一个战斗系统的事件系统 Game.Scene.AddComponent <BattleEventSystem>(); //增加Buff池组件 Game.Scene.AddComponent <BuffPoolComponent>(); 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}"); } //用于FixedUpdate FixedUpdate fixedUpdate = new FixedUpdate() { UpdateCallback = () => Game.EventSystem.FixedUpdate() }; while (true) { try { Thread.Sleep(1); OneThreadSynchronizationContext.Instance.Update(); Game.EventSystem.Update(); fixedUpdate.Tick(); } catch (Exception e) { Log.Error(e); } } } catch (Exception e) { Log.Error(e); } }
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); } }
private static void Main(string[] args) { new Boostrap() .AddAssemblyPart(typeof(OuterOpcode).Assembly, DllHelper.GetHotfixAssembly("Game.Hotfix")) .Run(args); }
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 <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; 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>(); 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<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); } }
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; } Log.WriteLine($"启动服务器类型:{startConfig.AppType},ip:{startConfig.ServerIP}"); Log.Debug("启动服务器类型:" + startConfig.AppType); 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; case AppType.Realm: //玩家的初次连接对象,实际上可能存在多个,但是对于单个玩家来说他只会遇到其中一个。 // 有可能被攻击,需要改多个的话,改RealmGateAddressComponent组件 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: //消息转发服务器,直接处理玩家的请求和转发Actor消息。 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>(); Game.Scene.AddComponent <PingComponent>(); break; case AppType.Location: //连接内网,匹配服务器,在玩家更换游戏地图时,通知Gate更新ActorID。 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>(); Game.Scene.AddComponent <PingComponent>(); break; case AppType.AllServer: // 发送普通actor消息 Game.Scene.AddComponent <ActorMessageSenderComponent>(); // 发送location actor消息 Game.Scene.AddComponent <ActorLocationSenderComponent>(); // 数据库管理组件(管理数据库连接地址,数据库名称等) Game.Scene.AddComponent <DBComponent>(); // 数据库调用组件(调用DB数据库的组件,添加、查询、修改、删除等操作) 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 <PingComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <ConsoleComponent>(); // Game.Scene.AddComponent<HttpComponent>(); //以下是牛牛服务端自定义全局组件 Game.Scene.AddComponent <UserInfoComponent>(); Game.Scene.AddComponent <CowCowGateSessionKeyComponent>(); Game.Scene.AddComponent <RoomComponent>(); Game.Scene.AddComponent <OnlineComponent>(); 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); } }
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 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); } }
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); } }
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); } }
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; 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>(); 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>(); #region ///20190621 // 调用方法 //Game.Scene.AddComponent<PingComponent, long, long, Action<long>>(5000, 6, OnExit); // 调用匿名方法 Game.Scene.AddComponent <BongComponent, long, long, Action <long> >(5000, 10, sessionId => { Game.Scene.GetComponent <NetOuterComponent>().Remove(sessionId); Game.Scene.GetComponent <NetInnerComponent>().Remove(sessionId); }); Game.Scene.AddComponent <NumericWatcherComponent>(); //创建数值组件NumericWatcherComponent Game.Scene.AddComponent <AoiGridComponent>(); //创建 AOI 组件 Game.Scene.AddComponent <InventoryComponent>(); //创建 Inventory 组件 Game.Scene.AddComponent <SkillComponent>(); //创建 Skill 组件 #endregion // recast寻路组件 Game.Scene.AddComponent <PathfindingComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <ConsoleComponent>(); // Game.Scene.AddComponent<HttpComponent>(); Console.WriteLine(" 内网: " + innerConfig.Address + " 外网: " + outerConfig.Address); #region ///20190613 Game.Scene.AddComponent <MonsterUnitComponent>(); Game.Scene.AddComponent <MonsterComponent>(); Game.Scene.AddComponent <UserComponent>(); Game.Scene.AddComponent <TestComponent>(); Game.Scene.AddComponent <SpawnComponent>(); #endregion Console.WriteLine(" 服务器配置完成: " + AppType.AllServer + " " + DateTime.Now.ToString("yyyy MM dd HH:mm:ss")); 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); } }
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()); for (int i = 0; i < args.Length; i++) { Log.Info("启动信息:" + args[i]); } //初始化选项 Options options = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options; //Console.WriteLine("打印日志:" + options.Config + " || " + options.AppId); //得到初始化的配置 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($"服务器运行开始........................ {startConfig.AppId} {startConfig.AppType}"); //添加计时组件 Game.Scene.AddComponent <TimerComponent>(); //添加安全码,通过特性遍历获取的 Game.Scene.AddComponent <OpcodeTypeComponent>(); //添加消息分发组件 Game.Scene.AddComponent <MessageDispatcherComponent>(); //获取外网配置IP OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>(); //获取内外配置IP InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>(); //获取客户端链接地址IP 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); Log.Info("Manager服务器启动"); break; case AppType.Map: //协程锁组件 Game.Scene.AddComponent <CoroutineLockComponent>(); // 内网消息组件 Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); // 发送普通actor消息 Game.Scene.AddComponent <ActorMessageSenderComponent>(); // 这两个组件是处理actor消息使用的 Game.Scene.AddComponent <MailboxDispatcherComponent>(); Game.Scene.AddComponent <ActorMessageDispatcherComponent>(); //添加单位管理组件 Game.Scene.AddComponent <UnitComponent>(); //添加热更层的一些组件 Game.Scene.AddComponent <AddHotfixComponent>(); //控制台组件 Game.Scene.AddComponent <ConsoleComponent>(); Log.Info("Map服务器启动"); break; case AppType.DB: // 内网消息组件 Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); //数据服务器需要的组件 Game.Scene.AddComponent <DBComponent>(); //注册数据序列化实体类 Game.Scene.AddComponent <RegisterMapComponent>(); //控制台组件 Game.Scene.AddComponent <ConsoleComponent>(); Log.Info("数据库服务器启动"); break; case AppType.Location: // 内网消息组件 Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); //location server需要的组件 Game.Scene.AddComponent <LocationComponent>(); Log.Info("Location服务器启动"); break; case AppType.Gate: //协程锁组件 Game.Scene.AddComponent <CoroutineLockComponent>(); // 内网消息组件 Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); // 外网消息组件 Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address); // 发送普通actor消息 Game.Scene.AddComponent <ActorMessageSenderComponent>(); // 这两个组件是处理actor消息使用的 Game.Scene.AddComponent <MailboxDispatcherComponent>(); Game.Scene.AddComponent <ActorMessageDispatcherComponent>(); //访问location server的组件 Game.Scene.AddComponent <LocationProxyComponent>(); //发送location actor消息 Game.Scene.AddComponent <ActorLocationSenderComponent>(); //操作数据库的组件 Game.Scene.AddComponent <DBProxyComponent>(); // 配置管理 Game.Scene.AddComponent <ConfigComponent>(); //控制台组件 Game.Scene.AddComponent <ConsoleComponent>(); //添加玩家管理组件 Game.Scene.AddComponent <PlayerComponent>(); Log.Info("Gate服务器启动"); break; case AppType.AllServer: //协程锁组件 Game.Scene.AddComponent <CoroutineLockComponent>(); // 内网消息组件 Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); // 外网消息组件 Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address); // 发送普通actor消息 Game.Scene.AddComponent <ActorMessageSenderComponent>(); // 这两个组件是处理actor消息使用的 Game.Scene.AddComponent <MailboxDispatcherComponent>(); Game.Scene.AddComponent <ActorMessageDispatcherComponent>(); //location server需要的组件 Game.Scene.AddComponent <LocationComponent>(); //访问location server的组件 Game.Scene.AddComponent <LocationProxyComponent>(); //发送location actor消息 Game.Scene.AddComponent <ActorLocationSenderComponent>(); //数据服务器需要的组件 Game.Scene.AddComponent <DBComponent>(); //操作数据库的组件 Game.Scene.AddComponent <DBProxyComponent>(); // 配置管理 Game.Scene.AddComponent <ConfigComponent>(); //控制台组件 Game.Scene.AddComponent <ConsoleComponent>(); //添加单位管理组件 Game.Scene.AddComponent <UnitComponent>(); //添加玩家管理组件 Game.Scene.AddComponent <PlayerComponent>(); //添加热更层的一些组件 Game.Scene.AddComponent <AddHotfixComponent>(); Log.Info("AllServer服务器启动"); break; default: Log.Error("启动了没有定义的服务器:" + startConfig.AppType); Console.ReadKey(); return; } //这里就开始循环监听信息了 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 static void Main(string[] args) { try { Game.EntityEventManager.Register("Model", typeof(Game).Assembly); Game.EntityEventManager.Register("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; IdGenerater.AppId = options.AppId; LogManager.Configuration.Variables["appType"] = startConfig.AppType.ToString(); LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString(); Log.Info("server start........................"); Game.Scene.AddComponent <MessageDispatherComponent, AppType>(startConfig.AppType); // 根据不同的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, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <AppManagerComponent>(); break; case AppType.Realm: Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <RealmGateAddressComponent>(); break; case AppType.Gate: Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <GateSessionKeyComponent>(); break; case AppType.AllServer: Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); 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.Benchmark: Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <BenchmarkComponent, string>(clientConfig.Address); break; default: throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}"); } while (true) { try { Game.EntityEventManager.Update(); } catch (Exception e) { Log.Error(e.ToString()); } } } catch (Exception e) { Log.Error(e.ToString()); } }
private static void Main(string[] args) { // 异步方法全部会回掉到主线程 OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(contex); try { ObjectEvents.Instance.Add("Model", typeof(Game).Assembly); ObjectEvents.Instance.Add("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; IdGenerater.AppId = options.AppId; LogManager.Configuration.Variables["appType"] = startConfig.AppType.ToString(); LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString(); Log.Info("server start........................"); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatherComponent, AppType>(startConfig.AppType); // 根据不同的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, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <AppManagerComponent>(); break; case AppType.Realm: Game.Scene.AddComponent <ActorMessageDispatherComponent>(); Game.Scene.AddComponent <ActorManagerComponent>(); Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <ActorComponent>(); Game.Scene.AddComponent <RealmGateAddressComponent>(); break; case AppType.Gate: Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <ActorMessageDispatherComponent>(); Game.Scene.AddComponent <ActorManagerComponent>(); Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <ActorComponent>(); Game.Scene.AddComponent <ActorProxyComponent>(); Game.Scene.AddComponent <GateSessionKeyComponent>(); break; case AppType.Location: Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <LocationComponent>(); break; case AppType.Map: Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <ActorManagerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <ActorComponent>(); Game.Scene.AddComponent <ActorProxyComponent>(); Game.Scene.AddComponent <ActorMessageDispatherComponent>(); break; case AppType.AllServer: Game.Scene.AddComponent <ActorProxyComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <DBComponent>(); Game.Scene.AddComponent <DBProxyComponent>(); Game.Scene.AddComponent <LocationComponent>(); Game.Scene.AddComponent <ActorMessageDispatherComponent>(); Game.Scene.AddComponent <ActorManagerComponent>(); Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <ActorComponent>(); Game.Scene.AddComponent <AppManagerComponent>(); Game.Scene.AddComponent <RealmGateAddressComponent>(); Game.Scene.AddComponent <GateSessionKeyComponent>(); break; case AppType.Benchmark: Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <BenchmarkComponent, string>(clientConfig.Address); break; default: throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}"); } while (true) { try { Thread.Sleep(1); contex.Update(); ObjectEvents.Instance.Update(); } catch (Exception e) { Log.Error(e.ToString()); } } } catch (Exception e) { Log.Error(e.ToString()); } }
private static void Main(string[] args) { // 异步方法全部会回掉到主线程 SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); try { Game.EventSystem.Add(DLLType.Core, 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>(); // 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 <NetSyncComponent, SyncType>(SyncType.State); 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 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()); //取出应用程序参数args 填充 Options 类 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: //连接客户端的外网和连接内部服务器的内网,对服务器进程进行管理,自动检测和启动服务器进程。 //加载有内网组件NetInnerComponent,外网组件NetOuterComponent,服务器进程管理组件。 //自动启动突然停止运行的服务器,保证此服务器管理的其它服务器崩溃后能及时自动启动运行。 Game.Scene.AddComponent <AppManagerComponent>(); Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address); break; case AppType.Realm: //对ActorMessage消息进行管理(添加、移除、分发等),连接内网和外网,对内网服务器进程进行操作, //随机分配Gate服务器地址。加载有ActorMessage消息分发组件ActorMessageDispatherComponent, //ActorManager消息管理组件ActorManagerComponent,内网组件NetInnerComponent,外网组件NetOuterComponent, //服务器进程管理组件LocationProxyComponent,Gate服务器随机分发组件。 //客户端登录时连接的第一个服务器,也可称为登录服务器。 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: //对玩家进行管理,对ActorMessage消息进行管理(添加、移除、分发等),连接内网和外网, //对内网服务器进程进行操作,随机分配Gate服务器地址,对Actor消息进程进行管理, //对玩家ID登录后的Key进行管理。加载有玩家管理组件PlayerComponent,ActorMessage消息分发组件ActorMessageDispatherComponent, //ActorManager消息管理组件ActorManagerComponent,内网组件NetInnerComponent,外网组件NetOuterComponent, //服务器进程管理组件LocationProxyComponent,Actor消息管理组件ActorProxyComponent, //管理登陆时联网的Key组件GateSessionKeyComponent。对客户端的登录信息进行验证和客户端登录后连接的服务器, //登录后通过此服务器进行消息互动,也可称为验证服务器。 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: //连接内网,服务器进程状态集中管理(Actor消息IP管理服务器)。 //加载有内网组件NetInnerComponent,服务器消息处理状态存储组件LocationComponent。 Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); Game.Scene.AddComponent <LocationComponent>(); break; case AppType.Map: //连接内网,对ActorMessage消息进行管理(添加、移除、分发等), //对场景内现在活动物体存储管理,对内网服务器进程进行操作,对Actor消息进程进行管理, //对ActorMessage消息进行管理(添加、移除、分发等),服务器帧率管理。 //ActorMessage消息分发组件ActorMessageDispatherComponent,ActorManager消息管理组件ActorManagerComponent, //内网组件NetInnerComponent,服务器进程管理组件LocationProxyComponent,服务器帧率管理组件ServerFrameComponent。 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: //将以上服务器功能集中合并成一个服务器。另外增加DB连接组件DBComponent,DB管理组件DBProxyComponent。 Game.Scene.AddComponent <ActorMessageSenderComponent>(); Game.Scene.AddComponent <ActorLocationSenderComponent>(); 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, 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: //连接内网和测试服务器承受力。加载有内网组件NetInnerComponent,服务器承受力测试组件BenchmarkComponent。 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); } }
public override async ETTask M2A_ReloadHandler(Scene scene, M2A_Reload request, A2M_Reload response, Action reply) { Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly()); reply(); await ETTask.CompletedTask; }
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>(); //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, 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>(); //以下是斗地主服务端自定义全局组件 //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, 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); } }
private static void Main(string[] args) { // 异步方法全部会回掉到主线程 OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(contex); MongoHelper.Init(); 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 <ActorProxyComponent>(); 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 <ActorProxyComponent>(); Game.Scene.AddComponent <ActorMessageDispatherComponent>(); Game.Scene.AddComponent <ServerFrameComponent>(); break; case AppType.AllServer: Game.Scene.AddComponent <ActorProxyComponent>(); 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>(); 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); } }
protected override async ETTask Run(Session session, M2A_Reload request, A2M_Reload response, Action reply) { Game.EventSystem.Add(DllHelper.GetHotfixAssembly()); reply(); await ETTask.CompletedTask; }