|
|
@@ -1,9 +1,11 @@
|
|
|
using System;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.IO;
|
|
|
using System.Threading;
|
|
|
-using ETModel;
|
|
|
+using CommandLine;
|
|
|
using NLog;
|
|
|
|
|
|
-namespace App
|
|
|
+namespace ETModel
|
|
|
{
|
|
|
internal static class Program
|
|
|
{
|
|
|
@@ -13,140 +15,73 @@ namespace App
|
|
|
SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);
|
|
|
|
|
|
try
|
|
|
- {
|
|
|
+ {
|
|
|
Game.EventSystem.Add(DLLType.Model, typeof(Game).Assembly);
|
|
|
Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly());
|
|
|
+
|
|
|
+ MongoHelper.Init();
|
|
|
+
|
|
|
+ // 命令行参数
|
|
|
+ Parser.Default.ParseArguments<Options>(args)
|
|
|
+ .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
|
|
|
+ .WithParsed(o => { Game.Options = o; });
|
|
|
|
|
|
- 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;
|
|
|
+ IdGenerater.AppId = Game.Options.Id;
|
|
|
+
|
|
|
+ // 启动配置
|
|
|
+ StartConfig allConfig = MongoHelper.FromJson<StartConfig>(File.ReadAllText(Path.Combine("../Config/StartConfig/", Game.Options.Config)));
|
|
|
|
|
|
- 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}";
|
|
|
+ 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........................ {startConfig.AppId} {startConfig.AppType}");
|
|
|
+ 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>();
|
|
|
+ // 这两个组件是处理actor消息使用的
|
|
|
+ Game.Scene.AddComponent<MailboxDispatcherComponent>();
|
|
|
+ Game.Scene.AddComponent<ActorMessageDispatcherComponent>();
|
|
|
+ // manager server组件,用来管理其它进程使用
|
|
|
+ Game.Scene.AddComponent<NumericWatcherComponent>();
|
|
|
+ Game.Scene.AddComponent<ConsoleComponent>();
|
|
|
|
|
|
- // 根据不同的AppType添加不同的组件
|
|
|
- OuterConfig outerConfig = startConfig.GetComponent<OuterConfig>();
|
|
|
- InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
|
|
|
- ClientConfig clientConfig = startConfig.GetComponent<ClientConfig>();
|
|
|
+
|
|
|
+ OuterConfig outerConfig = startConfig.GetComponent<OuterConfig>();
|
|
|
+ if (outerConfig != null)
|
|
|
+ {
|
|
|
+ // 外网消息组件
|
|
|
+ Game.Scene.AddComponent<NetOuterComponent, string>(outerConfig.Address);
|
|
|
+ }
|
|
|
|
|
|
- switch (startConfig.AppType)
|
|
|
+ InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
|
|
|
+ if (innerConfig != null)
|
|
|
{
|
|
|
- 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<PathfindingComponent>();
|
|
|
- Game.Scene.AddComponent<CoroutineLockComponent>();
|
|
|
- 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<ConsoleComponent>();
|
|
|
+ // 内网消息组件
|
|
|
+ Game.Scene.AddComponent<NetInnerComponent, string>(innerConfig.Address);
|
|
|
+ }
|
|
|
|
|
|
- Game.Scene.AddComponent<CoroutineLockComponent>();
|
|
|
- // 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}");
|
|
|
+ DBConfig dbConfig = startConfig.GetComponent<DBConfig>();
|
|
|
+ if (dbConfig != null)
|
|
|
+ {
|
|
|
+ Game.Scene.AddComponent<DBComponent, DBConfig>(dbConfig);
|
|
|
}
|
|
|
|
|
|
+ // 先加这里,后面删掉
|
|
|
+ Game.EventSystem.Run(EventIdType.AfterScenesAdd);
|
|
|
+
|
|
|
while (true)
|
|
|
{
|
|
|
try
|