fix : 맵 이동시 유저 진입 동기화버그 수정

This commit is contained in:
qornwh1
2026-03-16 16:07:49 +09:00
parent 523247c9b1
commit 943302c2f1
2 changed files with 28 additions and 4 deletions

View File

@@ -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);

View File

@@ -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)