修改协议工具
This commit is contained in:
49
Hotfix/Game/Role/RoleManagerComponentSystem.cs
Normal file
49
Hotfix/Game/Role/RoleManagerComponentSystem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB;
|
||||
|
||||
public sealed class RoleManagerComponentDestroySystem : DestroySystem<RoleManagerComponent>
|
||||
{
|
||||
protected override void Destroy(RoleManagerComponent self)
|
||||
{
|
||||
foreach (var (_, role) in self.Roles)
|
||||
{
|
||||
role.Dispose();
|
||||
}
|
||||
|
||||
self.Roles.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static class RoleManagerComponentSystem
|
||||
{
|
||||
public static void Add(this RoleManagerComponent self, Role account)
|
||||
{
|
||||
self.Roles.Add(account.Id, account);
|
||||
}
|
||||
|
||||
public static Role Get(this RoleManagerComponent self, long accountId)
|
||||
{
|
||||
return self.Roles.GetValueOrDefault(accountId);
|
||||
}
|
||||
|
||||
public static bool TryGet(this RoleManagerComponent self, long accountId, out Role account)
|
||||
{
|
||||
return self.Roles.TryGetValue(accountId, out account);
|
||||
}
|
||||
|
||||
public static void Remove(this RoleManagerComponent self, long accountId, bool isDispose = true)
|
||||
{
|
||||
if (!self.Roles.Remove(accountId, out var account))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDispose)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
account.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public sealed class C2G_GetAccountInfoRequestHandler : MessageRPC<C2G_GetAccount
|
||||
return;
|
||||
}
|
||||
|
||||
Player account = gameAccountFlagComponent.Account;
|
||||
Player account = gameAccountFlagComponent.Player;
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ public sealed class C2G_LoginRequestHandler : MessageRPC<C2G_LoginRequest, G2C_L
|
||||
|
||||
var gameAccountFlagComponent = oldSession.GetComponent<PlayerFlagComponent>();
|
||||
gameAccountFlagComponent.AccountID = 0;
|
||||
gameAccountFlagComponent.Account = null;
|
||||
gameAccountFlagComponent.Player = null;
|
||||
// 给客户端发送一个重复登录的消息,如果当前客户端是自己上次登录的,发送也不会收到。
|
||||
oldSession.Send(new G2C_RepeatLogin());
|
||||
// 给当前Session做一个定时销毁的任务,因为不做这个定时销毁,直接销毁的话,有可能消息还没有发送过去就销毁了
|
||||
@@ -90,10 +90,12 @@ public sealed class C2G_LoginRequestHandler : MessageRPC<C2G_LoginRequest, G2C_L
|
||||
// 给当前Session添加一个组件,当Session销毁的时候会销毁这个组件。
|
||||
var accountFlagComponent = session.AddComponent<PlayerFlagComponent>();
|
||||
accountFlagComponent.AccountID = accountId;
|
||||
accountFlagComponent.Account = account;
|
||||
accountFlagComponent.Player = account;
|
||||
|
||||
account.SessionRunTimeId = session.RuntimeId;
|
||||
response.GameAccountInfo = account.GetGameAccountInfo();
|
||||
Log.Debug($"当前的Gate服务器:{session.Scene.SceneConfigId} accountId:{accountId}");
|
||||
|
||||
//连接到游戏中心服
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@ public sealed class PlayerFlagComponentDestroySystem : DestroySystem<PlayerFlagC
|
||||
self.AccountID = 0;
|
||||
}
|
||||
|
||||
self.Account = null;
|
||||
self.Player = null;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public static class PlayerHelper
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="accountId">账号Id</param>
|
||||
/// <returns></returns>
|
||||
public static async FTask<Player?> LoadDataBase(Scene scene, long accountId)
|
||||
public static async FTask<Player> LoadDataBase(Scene scene, long accountId)
|
||||
{
|
||||
var account = await scene.World.DataBase.First<Player>(d => d.Id == accountId);
|
||||
if (account == null)
|
||||
@@ -29,7 +29,7 @@ public static class PlayerHelper
|
||||
/// 保存账号到数据库中
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
public static async FTask SaveDataBase(this Player self)
|
||||
public static async FTask SaveDataBase(this Player self)
|
||||
{
|
||||
await self.Scene.World.DataBase.Save(self);
|
||||
}
|
||||
@@ -12,8 +12,4 @@
|
||||
<ProjectReference Include="..\Fantasy\Fantasy.Net\Fantasy.Net\Fantasy.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Outer\Gate\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class G2A_TestMessageHandler : Route<Scene,G2A_TestMessage>
|
||||
{
|
||||
protected override async FTask Run(Scene entity, G2A_TestMessage message)
|
||||
{
|
||||
|
||||
|
||||
Log.Debug($"G2A_TestMessageHandler :{message.Tag}");
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class G2A_TestRequestHandler : RouteRPC<Scene, G2A_TestRequest, G2A_TestResponse>
|
||||
{
|
||||
private static int Count;
|
||||
protected override async FTask Run(Scene entity, G2A_TestRequest request, G2A_TestResponse response, Action reply)
|
||||
{
|
||||
if (++Count % 1000000 == 0)
|
||||
{
|
||||
Log.Debug($"count:1000000");
|
||||
}
|
||||
// Log.Debug($"{Count}");
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public sealed class G2Chat_CreateRouteRequestHandler : RouteRPC<Scene, G2Chat_CreateRouteRequest, Chat2G_CreateRouteResponse>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, G2Chat_CreateRouteRequest request, Chat2G_CreateRouteResponse response, Action reply)
|
||||
{
|
||||
// 接收到Gate消息后,首先建立一个实体用来后面接收Route消息。
|
||||
// 这里就拿ChatUnit来做这个。
|
||||
var chatUnit = Entity.Create<ChatUnit>(scene, true, true);
|
||||
// 把Gate传递过来的RouteId保存住,以便后面可以直接给Gate发送消息。
|
||||
// 例如断线等操作,都可以通过这个GateRouteId发送到Gate的Session上。
|
||||
chatUnit.GateRouteId = request.GateRouteId;
|
||||
// 把chatUnit的RunTimeId发送给Gate。
|
||||
// 正如之前所说任何实体的RunTimeId都可以当做RouteId使用。
|
||||
response.ChatRouteId = chatUnit.RouteId;
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,16 @@ public class OnSceneCreate_Init : AsyncEventSystem<OnCreateScene>
|
||||
{
|
||||
// 用于验证JWT是否合法的组件
|
||||
scene.AddComponent<GateJWTComponent>();
|
||||
// 用于管理GameAccount的组件
|
||||
// 用于管理玩家的组件
|
||||
scene.AddComponent<PlayerManageComponent>();
|
||||
break;
|
||||
}
|
||||
case SceneType.Game:
|
||||
{
|
||||
//游戏服用于管理用户的组件
|
||||
scene.AddComponent<RoleManagerComponent>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
|
||||
Reference in New Issue
Block a user