协议修改
This commit is contained in:
@@ -53,9 +53,7 @@ public class G2Common_ExitRequestHandler : RouteRPC<Scene, G2Common_ExitRequest,
|
||||
|
||||
private async FTask RunMap(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response)
|
||||
{
|
||||
// 在缓存中检查该账号是否存在
|
||||
var chatUnitManageComponent = scene.GetComponent<MapUnitManageComponent>();
|
||||
await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId);
|
||||
await MapHelper.Offline(scene, request.AccountId, request.GateRouteId);
|
||||
Log.Info("退出房间服成功==");
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ public class C2Map_LookHandler : Route<MapUnit, C2Map_Look>
|
||||
|
||||
foreach (var (_, unit) in room.Units)
|
||||
{
|
||||
// if (unit.Id == entity.Id) continue;
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ public class C2Map_MoveHandler : Route<MapUnit, C2Map_Move>
|
||||
|
||||
foreach (var (_, unit) in room.Units)
|
||||
{
|
||||
// if (unit.Id == entity.Id) continue;
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
|
||||
}
|
||||
|
||||
|
||||
34
Hotfix/Map/Handler/C2Map_RolePropertyChangeHandler.cs
Normal file
34
Hotfix/Map/Handler/C2Map_RolePropertyChangeHandler.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
|
||||
public class C2Map_RolePropertyChangeHandler : Route<MapUnit, C2Map_RolePropertyChange>
|
||||
{
|
||||
protected override async FTask Run(MapUnit entity, C2Map_RolePropertyChange message)
|
||||
{
|
||||
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
|
||||
var roomId = entity.RoomId;
|
||||
var room = roomManageComponent.Get(roomId);
|
||||
if (room == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var notifyMessage = new Map2C_RolePropertyChangeNotify()
|
||||
{
|
||||
Id = entity.Id,
|
||||
Propertys = message.Propertys,
|
||||
};
|
||||
|
||||
|
||||
foreach (var (_, unit) in room.Units)
|
||||
{
|
||||
if (unit.Id == entity.Id) continue;
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
30
Hotfix/Map/Helper/MapHelper.cs
Normal file
30
Hotfix/Map/Helper/MapHelper.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
|
||||
namespace NB.Map;
|
||||
|
||||
public static class MapHelper
|
||||
{
|
||||
public static async FTask Offline(Scene scene, long accountId, long gateRouteId)
|
||||
{
|
||||
// 在缓存中检查该账号是否存在
|
||||
var chatUnitManageComponent = scene.GetComponent<MapUnitManageComponent>();
|
||||
if (chatUnitManageComponent == null) return;
|
||||
var mapUnit = chatUnitManageComponent.Get(accountId);
|
||||
if (mapUnit == null) return;
|
||||
|
||||
var roomManageComponent = scene.GetComponent<RoomManageComponent>();
|
||||
|
||||
if (mapUnit.RoomId > 0)
|
||||
{
|
||||
var room = roomManageComponent.Get(mapUnit.RoomId);
|
||||
if (room != null)
|
||||
{
|
||||
await room.Exit(accountId);
|
||||
roomManageComponent.Check(mapUnit.RoomId);
|
||||
}
|
||||
}
|
||||
|
||||
await chatUnitManageComponent.Offline(scene, accountId, gateRouteId);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,12 @@ public static class MapRoomSystem
|
||||
return ErrorCode.Successful;
|
||||
}
|
||||
|
||||
public static async FTask Exit(this MapRoom self, long id)
|
||||
{
|
||||
self.Units.Remove(id);
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
|
||||
public static List<MapUnitInfo> ToMapUnitInfo(this MapRoom self)
|
||||
{
|
||||
List<MapUnitInfo> ret = new List<MapUnitInfo>();
|
||||
|
||||
@@ -66,11 +66,23 @@ public static class RoomManageComponentSystem
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Check(this RoomManageComponent self, int roomId)
|
||||
{
|
||||
if (self.Rooms.TryGetValue(roomId, out var room))
|
||||
{
|
||||
if (room.Units.Count < 1)
|
||||
{
|
||||
Log.Info($"房间没人了,解散房间,id={roomId}");
|
||||
// self.Remove(roomId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MapRoom? Get(this RoomManageComponent self, int roomId)
|
||||
{
|
||||
return self.Rooms.GetValueOrDefault(roomId);
|
||||
}
|
||||
|
||||
|
||||
// public static MapRoom? Get(this RoomManageComponent self, long roomId)
|
||||
// {
|
||||
// return self.Rooms.GetValueOrDefault(roomId);
|
||||
|
||||
Reference in New Issue
Block a user