Skip to content

Commit 2eedd33

Browse files
committed
refactor(startup): 更新启动逻辑以使用 Aspire 服务发现
移除 DiscoveryCenter 相关配置和逻辑: - AppStartUpByServer 移除服务注册逻辑 - AppSetting 移除 DiscoveryCenter 配置项 - LauncherOptions 移除 DiscoveryCenter 选项 - 移除项目对 DiscoveryCenterManager 的引用 - 更新本地化资源,移除 DiscoveryCenter 相关消息 - AppHost 添加 Launcher 项目引用
1 parent 8a872db commit 2eedd33

23 files changed

Lines changed: 66 additions & 604 deletions

File tree

GameFrameX.AppHost/GameFrameX.AppHost.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<ItemGroup>
1616
<ProjectReference Include="..\GameFrameX.Localization\GameFrameX.Localization.csproj" IsAspireProjectResource="false"/>
17+
<ProjectReference Include="..\GameFrameX.Launcher\GameFrameX.Launcher.csproj" />
1718
<ProjectReference Include="..\GameFrameX.StartUp\GameFrameX.StartUp.csproj" IsAspireProjectResource="false"/>
1819
</ItemGroup>
1920

GameFrameX.AppHost/Program.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,19 @@ private static async Task Main(string[] args)
105105

106106
var mongoDb = builder.AddMongoDB("mongo").WithLifetime(ContainerLifetime.Persistent);
107107
mongoDb.AddDatabase("mongodb");
108-
// mongoDb.AddDatabase(launcherOptions.DataBaseName, launcherOptions.DataBasePassword);
109-
// var myService = builder.AddProject<DataBaseProject>()
110-
// .WithReference(mongoDb)
111-
// .WaitFor(mongoDb);
108+
var gameService = builder
109+
.AddProject<Projects.GameFrameX_Launcher>("game-service")
110+
.WithArgs($"--{nameof(LauncherOptions.ServerType)}=Game")
111+
.WithReference(mongoDb)
112+
.WaitFor(mongoDb);
113+
114+
var socialService = builder
115+
.AddProject<Projects.GameFrameX_Launcher>("social-service")
116+
.WithArgs($"--{nameof(LauncherOptions.ServerType)}=Social")
117+
.WithReference(mongoDb)
118+
.WaitFor(mongoDb);
119+
120+
gameService.WaitFor(socialService);
112121
await builder.Build().RunAsync();
113122
}
114-
}
123+
}

GameFrameX.Hotfix/GameFrameX.Hotfix.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<ProjectReference Include="..\GameFrameX.Config\GameFrameX.Config.csproj" />
2020
<ProjectReference Include="..\GameFrameX.Core\GameFrameX.Core.csproj" />
2121
<ProjectReference Include="..\GameFrameX.NetWork.HTTP\GameFrameX.NetWork.HTTP.csproj" />
22-
<ProjectReference Include="..\GameFrameX.DiscoveryCenterManager\GameFrameX.DiscoveryCenterManager.csproj" />
2322
<ProjectReference Include="..\GameFrameX.StartUp\GameFrameX.StartUp.csproj" />
2423
<ProjectReference Include="..\GameFrameX.Utility\GameFrameX.Utility.csproj" />
2524
<ProjectReference Include="..\GameFrameX.CodeGenerator\GameFrameX.CodeGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

GameFrameX.Hotfix/Logic/Player/Login/LoginComponentAgent.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
using GameFrameX.Apps.Account.Login.Component;
3333
using GameFrameX.Apps.Account.Login.Entity;
3434
using GameFrameX.Apps.Common.Session;
35-
using GameFrameX.Hotfix.Logic.DiscoveryCenter;
3635
using GameFrameX.Hotfix.Logic.Server;
3736
using GameFrameX.Proto.BuiltIn;
3837

@@ -60,4 +59,4 @@ public async Task OnPlayerLogin(INetWorkChannel workChannel, ReqPlayerLogin reqL
6059
var playerComponentAgent = await ActorManager.GetComponentAgent<PlayerComponentAgent>(playerState.Id);
6160
await playerComponentAgent.OnPlayerLogin(workChannel, playerState, response);
6261
}
63-
}
62+
}

GameFrameX.Hotfix/Logic/Player/Login/PlayerComponentAgent.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ==========================================================================================
1+
// ==========================================================================================
22
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
33
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
44
// 均受中华人民共和国及相关国际法律法规保护。
@@ -31,10 +31,11 @@
3131

3232

3333
using GameFrameX.Apps.Common.Session;
34+
using GameFrameX.Apps.Common.Event;
3435
using GameFrameX.Apps.Player.Player.Component;
3536
using GameFrameX.Apps.Player.Player.Entity;
36-
using GameFrameX.Hotfix.Logic.DiscoveryCenter;
3737
using GameFrameX.Hotfix.Logic.Server;
38+
using GameFrameX.Core.Events;
3839
using GameFrameX.Proto.BuiltIn;
3940

4041
namespace GameFrameX.Hotfix.Logic.Player.Login;
@@ -46,15 +47,7 @@ public async Task OnLogout()
4647
//移除在线玩家
4748
var serverComp = await ActorManager.GetComponentAgent<ServerComponentAgent>();
4849
await serverComp.RemoveOnlineRole(ActorId);
49-
50-
var reqRegisterPlayer = new NotifyPlayerOffLine
51-
{
52-
PlayerId = ActorId,
53-
ServerId = GlobalSettings.CurrentSetting.ServerId,
54-
ServerInstanceId = GlobalSettings.CurrentSetting.ServerInstanceId,
55-
};
56-
var discoveryCenterComponentAgent = await ActorManager.GetComponentAgent<DiscoveryCenterComponentAgent>();
57-
discoveryCenterComponentAgent.SendToDiscoveryCenter(reqRegisterPlayer);
50+
EventDispatcher.Dispatch(ActorId, (int)EventId.OnRoleOffline);
5851
//下线后会被自动回收
5952
SetAutoRecycle(true);
6053
QuartzTimer.Remove(ScheduleIdSet);
@@ -85,14 +78,6 @@ public async Task OnPlayerLogin(INetWorkChannel workChannel, PlayerState playerS
8578
//加入在线玩家
8679
var serverComp = await ActorManager.GetComponentAgent<ServerComponentAgent>();
8780
await serverComp.AddOnlineRole(ActorId);
88-
89-
var reqRegisterPlayer = new NotifyPlayerOnLine()
90-
{
91-
PlayerId = ActorId,
92-
ServerId = GlobalSettings.CurrentSetting.ServerId,
93-
ServerInstanceId = GlobalSettings.CurrentSetting.ServerInstanceId,
94-
};
95-
var discoveryCenterComponentAgent = await ActorManager.GetComponentAgent<DiscoveryCenterComponentAgent>();
96-
discoveryCenterComponentAgent.SendToDiscoveryCenter(reqRegisterPlayer);
81+
EventDispatcher.Dispatch(ActorId, (int)EventId.OnRoleOnline);
9782
}
98-
}
83+
}

GameFrameX.Hotfix/StartUp/AppStartUpHotfixGameByEntry.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ==========================================================================================
1+
// ==========================================================================================
22
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
33
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
44
// 均受中华人民共和国及相关国际法律法规保护。
@@ -29,15 +29,15 @@
2929
// Official Documentation: https://gameframex.doc.alianblank.com/
3030
// ==========================================================================================
3131

32-
using GameFrameX.Hotfix.Logic.DiscoveryCenter;
3332
using GameFrameX.StartUp;
33+
using GameFrameX.Apps.Common.Event;
34+
using GameFrameX.Apps.Common.EventData;
35+
using GameFrameX.Core.Events;
3436

3537
namespace GameFrameX.Hotfix.StartUp;
3638

3739
internal partial class AppStartUpHotfixGame : AppStartUpBase, IHotfixBridge
3840
{
39-
protected override bool IsRegisterToDiscoveryCenter { get; set; } = true;
40-
4141
public async Task<bool> OnLoadSuccess(AppSetting setting, bool reload)
4242
{
4343
if (reload)
@@ -51,17 +51,12 @@ public async Task<bool> OnLoadSuccess(AppSetting setting, bool reload)
5151
// 启动定时器
5252
GlobalTimer.Start();
5353
await ComponentRegister.ActiveGlobalComponents();
54-
var discoveryCenterComponentAgent = await ActorManager.GetComponentAgent<DiscoveryCenterComponentAgent>();
55-
if (discoveryCenterComponentAgent.IsNotNull())
56-
{
57-
discoveryCenterComponentAgent.SetAppStartUp(this);
58-
}
59-
54+
EventDispatcher.Dispatch(0, (int)EventId.ServiceOnline, new ServiceOnlineEventArgs(setting.ServerType, setting.ServerInstanceId, DateTime.UtcNow));
6055
return true;
6156
}
6257

6358
public async Task Stop(string message = "")
6459
{
6560
await StopAsync(message);
6661
}
67-
}
62+
}

GameFrameX.Hotfix/StartUp/AppStartUpHotfixGameByMain.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ==========================================================================================
1+
// ==========================================================================================
22
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
33
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
44
// 均受中华人民共和国及相关国际法律法规保护。
@@ -30,6 +30,9 @@
3030
// ==========================================================================================
3131

3232
using GameFrameX.Apps.Common.Session;
33+
using GameFrameX.Apps.Common.Event;
34+
using GameFrameX.Apps.Common.EventData;
35+
using GameFrameX.Core.Events;
3336
using GameFrameX.SuperSocket.Connection;
3437
using GameFrameX.SuperSocket.Server.Abstractions.Session;
3538
using GameFrameX.SuperSocket.WebSocket.Server;
@@ -143,6 +146,7 @@ protected override async ValueTask PackageHandler(IAppSession appSession, IMessa
143146

144147
public override async Task StopAsync(string message = "")
145148
{
149+
EventDispatcher.Dispatch(0, (int)EventId.ServiceOffline, new ServiceOfflineEventArgs(Setting.ServerType, Setting.ServerInstanceId, "Stopped", DateTime.UtcNow));
146150
await base.StopAsync(message);
147151
// 断开所有连接
148152
await SessionManager.RemoveAll();
@@ -155,4 +159,4 @@ public override async Task StopAsync(string message = "")
155159
// 删除所有actor
156160
await ActorManager.RemoveAll();
157161
}
158-
}
162+
}

GameFrameX.Launcher/GameFrameX.Launcher.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
<ProjectReference Include="..\GameFrameX.Monitor\GameFrameX.Monitor.csproj"/>
3535
<ProjectReference Include="..\GameFrameX.NetWork.Message\GameFrameX.NetWork.Message.csproj"/>
3636
<ProjectReference Include="..\GameFrameX.Proto\GameFrameX.Proto.csproj"/>
37-
<ProjectReference Include="..\GameFrameX.DiscoveryCenterManager\GameFrameX.DiscoveryCenterManager.csproj"/>
3837
<ProjectReference Include="..\GameFrameX.StartUp\GameFrameX.StartUp.csproj"/>
3938
<ProjectReference Include="..\GameFrameX.Utility\GameFrameX.Utility.csproj"/>
4039
</ItemGroup>

GameFrameX.Launcher/StartUp/AppStartUpGame.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ==========================================================================================
1+
// ==========================================================================================
22
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
33
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
44
// 均受中华人民共和国及相关国际法律法规保护。
@@ -41,8 +41,6 @@ namespace GameFrameX.Launcher.StartUp;
4141
[StartUpTag(GlobalConst.GameServiceName)]
4242
internal sealed class AppStartUpGame : AppStartUpBase
4343
{
44-
protected override bool IsRegisterToDiscoveryCenter { get; set; } = false;
45-
4644
public override async Task StartAsync()
4745
{
4846
string exitMessage = null;
@@ -108,14 +106,12 @@ protected override void Init()
108106
MinModuleId = 10,
109107
HttpIsDevelopment = true,
110108
MaxModuleId = 9999,
111-
DiscoveryCenterHost = "127.0.0.1",
112109
TagName = "GameFrameX",
113-
DiscoveryCenterPort = 21001,
114110
DataBaseUrl = "mongodb+srv://gameframex:f9v42aU9DVeFNfAF@gameframex.8taphic.mongodb.net/?retryWrites=true&w=majority",
115111
DataBaseName = "gameframex",
116112
};
117113
}
118114

119115
base.Init();
120116
}
121-
}
117+
}

GameFrameX.Launcher/StartUp/Social/AppStartUpSocial.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
using GameFrameX.Core.Components;
1+
using GameFrameX.Core.Components;
22
using GameFrameX.DataBase.Abstractions;
33
using GameFrameX.NetWork.Abstractions;
44
using GameFrameX.NetWork.HTTP;
55
using GameFrameX.NetWork.Message;
66
using GameFrameX.Foundation.Localization.Core;
7+
using GameFrameX.Apps.Common.Event;
8+
using GameFrameX.Apps.Common.EventData;
9+
using GameFrameX.Core.Events;
710

811
namespace GameFrameX.Launcher.StartUp.Social;
912

@@ -13,8 +16,6 @@ namespace GameFrameX.Launcher.StartUp.Social;
1316
[StartUpTag(GlobalConst.SocialServiceName)]
1417
internal sealed partial class AppStartUpSocial : AppStartUpBase
1518
{
16-
protected override bool IsRegisterToDiscoveryCenter { get; set; } = true;
17-
1819
public override async Task StartAsync()
1920
{
2021
try
@@ -34,6 +35,7 @@ public override async Task StartAsync()
3435
await ComponentRegister.Init(typeof(AppsHandler).Assembly);
3536
HotfixManager.LoadHotfix(Setting);
3637
await StartServerAsync<DefaultMessageDecoderHandler, DefaultMessageEncoderHandler>(new DefaultMessageCompressHandler(), new DefaultMessageDecompressHandler(), HotfixManager.GetListHttpHandler(), HotfixManager.GetHttpHandler, aopHandlerTypes);
38+
EventDispatcher.Dispatch(0, (int)EventId.ServiceOnline, new ServiceOnlineEventArgs(Setting.ServerType, Setting.ServerInstanceId, DateTime.UtcNow));
3739

3840
await AppExitToken;
3941
}
@@ -66,6 +68,12 @@ protected override async ValueTask PackageHandler(IAppSession session, IMessage
6668
}
6769
}
6870

71+
public override async Task StopAsync(string message = "")
72+
{
73+
EventDispatcher.Dispatch(0, (int)EventId.ServiceOffline, new ServiceOfflineEventArgs(Setting.ServerType, Setting.ServerInstanceId, "Stopped", DateTime.UtcNow));
74+
await base.StopAsync(message);
75+
}
76+
6977
protected override void Init()
7078
{
7179
if (Setting == null)
@@ -88,4 +96,4 @@ protected override void Init()
8896

8997
base.Init();
9098
}
91-
}
99+
}

0 commit comments

Comments
 (0)