fix : 맵 이동시 유저 진입 동기화버그 수정
This commit is contained in:
@@ -67,9 +67,10 @@ public class Channel
|
||||
public void RemoveUser(int userId)
|
||||
{
|
||||
// 현재 맵에서도 제거
|
||||
if (connectUsers.TryGetValue(userId, out Player? player))
|
||||
if (connectUsers.TryGetValue(userId, out Player? player) &&
|
||||
maps.TryGetValue(player.CurrentMapId, out AMap? currentMap))
|
||||
{
|
||||
maps[player.CurrentMapId].RemoveUser(userId);
|
||||
currentMap.RemoveUser(userId);
|
||||
}
|
||||
|
||||
connectUsers.Remove(userId);
|
||||
|
||||
@@ -451,8 +451,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
HashKey = hashKey,
|
||||
PlayerId = hashKey,
|
||||
Nickname = hashKey.ToString(),
|
||||
CurrentMapId = 1
|
||||
Nickname = hashKey.ToString()
|
||||
};
|
||||
|
||||
// 채널에 추가
|
||||
@@ -464,6 +463,30 @@ public class GameServer : ServerBase
|
||||
|
||||
// 내 정보 전달
|
||||
SendLoadGame(peer, hashKey);
|
||||
|
||||
// 초기 맵(로비 1번) 진입 알림
|
||||
// Channel.AddUser → ChangeMap(1) 에서 이미 맵에 추가됨
|
||||
PlayerInfo playerInfo = ToPlayerInfo(newPlayer);
|
||||
int initMapId = newPlayer.CurrentMapId;
|
||||
|
||||
// 기존 맵 유저들에게 입장 알림 (본인 제외)
|
||||
ChangeMapPacket enterNotify = new() { MapId = initMapId, IsAdd = true, Player = playerInfo };
|
||||
BroadcastToMap(packet.ChannelId, initMapId,
|
||||
PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, enterNotify), peer);
|
||||
|
||||
// 본인에게 현재 맵의 플레이어 목록 전달
|
||||
ChangeMapPacket response = new() { MapId = initMapId };
|
||||
AMap? initMap = newChannel.GetMap(initMapId);
|
||||
if (initMap != null)
|
||||
{
|
||||
foreach (var (userId, p) in initMap.GetUsers())
|
||||
{
|
||||
if (userId == hashKey) continue;
|
||||
response.Players.Add(ToPlayerInfo(p));
|
||||
}
|
||||
}
|
||||
SendTo(peer, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, response));
|
||||
|
||||
}
|
||||
|
||||
private void OnIntoChannelParty(NetPeer peer, int hashKey, byte[] payload)
|
||||
|
||||
Reference in New Issue
Block a user