fix: BossRaid 토큰 처리 수정 및 merge conflict 해결
- RestApi.cs: Tokens를 Dictionary<string, string>?으로 수정 - BossRaidResult.cs: Tokens를 Dictionary<string, string>?으로 수정 - GameServer.cs: SendTo(peer) → SendTo(memberPeer) 버그 수정, 각 파티원에게 개별 토큰 전송 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ using LiteNetLib;
|
||||
using LiteNetLib.Utils;
|
||||
using MMOserver.Api;
|
||||
using MMOserver.Game.Channel;
|
||||
using MMOserver.Game.Channel.Maps;
|
||||
using MMOserver.Game.Party;
|
||||
using MMOserver.Packet;
|
||||
using MMOserver.Utils;
|
||||
@@ -15,7 +16,7 @@ namespace MMOserver.Game;
|
||||
public class GameServer : ServerBase
|
||||
{
|
||||
private readonly Dictionary<ushort, Action<NetPeer, int, byte[]>> packetHandlers;
|
||||
private UuidGenerator userUuidGenerator;
|
||||
private readonly UuidGenerator userUuidGenerator;
|
||||
|
||||
public GameServer(int port, string connectionString) : base(port, connectionString)
|
||||
{
|
||||
@@ -27,8 +28,11 @@ public class GameServer : ServerBase
|
||||
[(ushort)PacketCode.TRANSFORM_PLAYER] = OnTransformPlayer,
|
||||
[(ushort)PacketCode.ACTION_PLAYER] = OnActionPlayer,
|
||||
[(ushort)PacketCode.STATE_PLAYER] = OnStatePlayer,
|
||||
[(ushort)PacketCode.CHANGE_MAP] = OnChangeMap,
|
||||
[(ushort)PacketCode.PARTY_CHANGE_MAP] = OnPartyChangeMap,
|
||||
[(ushort)PacketCode.INTO_BOSS_RAID] = OnIntoBossRaid,
|
||||
[(ushort)PacketCode.REQUEST_PARTY] = OnRequestParty,
|
||||
[(ushort)PacketCode.CHAT] = OnChat,
|
||||
[(ushort)PacketCode.CHAT] = OnChat
|
||||
};
|
||||
userUuidGenerator = new UuidGenerator();
|
||||
}
|
||||
@@ -42,7 +46,7 @@ public class GameServer : ServerBase
|
||||
}
|
||||
|
||||
// 세션에 넣지는 않는다.
|
||||
NetDataReader reader = new NetDataReader(payload);
|
||||
NetDataReader reader = new(payload);
|
||||
short code = reader.GetShort();
|
||||
short bodyLength = reader.GetShort();
|
||||
|
||||
@@ -74,11 +78,12 @@ public class GameServer : ServerBase
|
||||
{
|
||||
// 더미 클라다.
|
||||
ChannelManager cm = ChannelManager.Instance;
|
||||
Player newPlayer = new Player
|
||||
Player newPlayer = new()
|
||||
{
|
||||
HashKey = hashKey,
|
||||
PlayerId = hashKey,
|
||||
Nickname = hashKey.ToString()
|
||||
Nickname = hashKey.ToString(),
|
||||
CurrentMapId = 1
|
||||
};
|
||||
|
||||
cm.AddUser(1, hashKey, newPlayer, peer);
|
||||
@@ -134,6 +139,7 @@ public class GameServer : ServerBase
|
||||
if (verifiedUsername != null)
|
||||
{
|
||||
((Session)peer.Tag).Username = verifiedUsername;
|
||||
((Session)peer.Tag).UserName = verifiedUsername;
|
||||
}
|
||||
sessions[hashKey] = peer;
|
||||
tokenHash[token] = hashKey;
|
||||
@@ -214,7 +220,7 @@ public class GameServer : ServerBase
|
||||
|
||||
private void SendLoadChannelPacket(NetPeer peer, int hashKey)
|
||||
{
|
||||
LoadChannelPacket loadChannelPacket = new LoadChannelPacket();
|
||||
LoadChannelPacket loadChannelPacket = new();
|
||||
foreach (Channel.Channel channel in ChannelManager.Instance.GetChannels().Values)
|
||||
{
|
||||
if (channel.ChannelId <= 0)
|
||||
@@ -227,26 +233,26 @@ public class GameServer : ServerBase
|
||||
continue;
|
||||
}
|
||||
|
||||
ChannelInfo info = new ChannelInfo();
|
||||
ChannelInfo info = new();
|
||||
info.ChannelId = channel.ChannelId;
|
||||
info.ChannelUserCount = channel.UserCount;
|
||||
info.ChannelUserMax = channel.UserCountMax;
|
||||
loadChannelPacket.Channels.Add(info);
|
||||
}
|
||||
|
||||
byte[] data = PacketSerializer.Serialize<LoadChannelPacket>((ushort)PacketCode.LOAD_CHANNEL, loadChannelPacket);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.LOAD_CHANNEL, loadChannelPacket);
|
||||
SendTo(peer, data);
|
||||
}
|
||||
|
||||
// 나간 유저를 같은 채널 유저들에게 알림 (UPDATE_CHANNEL_USER IsAdd=false)
|
||||
private void SendExitChannelPacket(NetPeer peer, int hashKey, int channelId, Player player)
|
||||
{
|
||||
UpdateChannelUserPacket packet = new UpdateChannelUserPacket
|
||||
UpdateChannelUserPacket packet = new()
|
||||
{
|
||||
Players = ToPlayerInfo(player),
|
||||
IsAdd = false
|
||||
};
|
||||
byte[] data = PacketSerializer.Serialize<UpdateChannelUserPacket>((ushort)PacketCode.UPDATE_CHANNEL_USER, packet);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_CHANNEL_USER, packet);
|
||||
// 이미 채널에서 제거된 후라 나간 본인에게는 전송되지 않음
|
||||
BroadcastToChannel(channelId, data);
|
||||
}
|
||||
@@ -267,7 +273,7 @@ public class GameServer : ServerBase
|
||||
Player? myPlayer = channel.GetPlayer(hashKey);
|
||||
|
||||
// 1. 새 유저에게: 자신을 제외한 기존 채널 유저 목록 + 파티 목록 전송
|
||||
IntoChannelPacket response = new IntoChannelPacket { ChannelId = channelId };
|
||||
IntoChannelPacket response = new() { ChannelId = channelId };
|
||||
foreach (int userId in channel.GetConnectUsers())
|
||||
{
|
||||
if (userId == hashKey)
|
||||
@@ -293,18 +299,18 @@ public class GameServer : ServerBase
|
||||
});
|
||||
}
|
||||
|
||||
byte[] toNewUser = PacketSerializer.Serialize<IntoChannelPacket>((ushort)PacketCode.INTO_CHANNEL, response);
|
||||
byte[] toNewUser = PacketSerializer.Serialize((ushort)PacketCode.INTO_CHANNEL, response);
|
||||
SendTo(peer, toNewUser);
|
||||
|
||||
// 2. 기존 유저들에게: 새 유저 입장 알림
|
||||
if (myPlayer != null)
|
||||
{
|
||||
UpdateChannelUserPacket notify = new UpdateChannelUserPacket
|
||||
UpdateChannelUserPacket notify = new()
|
||||
{
|
||||
Players = ToPlayerInfo(myPlayer),
|
||||
IsAdd = true
|
||||
};
|
||||
byte[] toOthers = PacketSerializer.Serialize<UpdateChannelUserPacket>((ushort)PacketCode.UPDATE_CHANNEL_USER, notify);
|
||||
byte[] toOthers = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_CHANNEL_USER, notify);
|
||||
BroadcastToChannel(channelId, toOthers, peer);
|
||||
}
|
||||
}
|
||||
@@ -321,19 +327,19 @@ public class GameServer : ServerBase
|
||||
{
|
||||
Log.Warning("[GameServer] LOAD_GAME 플레이어 없음 HashKey={Key}", hashKey);
|
||||
byte[] denied =
|
||||
PacketSerializer.Serialize<LoadGamePacket>((ushort)PacketCode.LOAD_GAME, new LoadGamePacket { IsAccepted = false });
|
||||
PacketSerializer.Serialize((ushort)PacketCode.LOAD_GAME, new LoadGamePacket { IsAccepted = false });
|
||||
SendTo(peer, denied);
|
||||
return;
|
||||
}
|
||||
|
||||
LoadGamePacket packet = new LoadGamePacket
|
||||
LoadGamePacket packet = new()
|
||||
{
|
||||
IsAccepted = true,
|
||||
Player = ToPlayerInfo(player),
|
||||
MaplId = channelId,
|
||||
MaplId = channelId
|
||||
};
|
||||
|
||||
byte[] data = PacketSerializer.Serialize<LoadGamePacket>((ushort)PacketCode.LOAD_GAME, packet);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.LOAD_GAME, packet);
|
||||
SendTo(peer, data);
|
||||
Log.Debug("[GameServer] LOAD_GAME HashKey={Key} PlayerId={PlayerId} ChannelId={ChannelId}", hashKey, player.PlayerId, channelId);
|
||||
}
|
||||
@@ -359,6 +365,32 @@ public class GameServer : ServerBase
|
||||
}
|
||||
}
|
||||
|
||||
// 특정 맵의 유저들에게 전송 (exclude 지정 시 해당 피어 제외)
|
||||
private void BroadcastToMap(int channelId, int mapId, byte[] data, NetPeer? exclude = null,
|
||||
DeliveryMethod method = DeliveryMethod.ReliableOrdered)
|
||||
{
|
||||
AMap? map = ChannelManager.Instance.GetChannel(channelId).GetMap(mapId);
|
||||
if (map == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (int userId in map.GetUsers().Keys)
|
||||
{
|
||||
if (!sessions.TryGetValue(userId, out NetPeer? targetPeer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (exclude != null && targetPeer.Id == exclude.Id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SendTo(targetPeer, data, method);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Player ↔ PlayerInfo 변환 (패킷 전송 시에만 사용)
|
||||
// ============================================================
|
||||
@@ -421,7 +453,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
Log.Warning("[GameServer] INTO_CHANNEL 채널 인원 초과 HashKey={Key} ChannelId={ChannelId} UserCount={Count}/{Max}",
|
||||
hashKey, packet.ChannelId, newChannel.UserCount, newChannel.UserCountMax);
|
||||
byte[] full = PacketSerializer.Serialize<IntoChannelPacket>((ushort)PacketCode.INTO_CHANNEL,
|
||||
byte[] full = PacketSerializer.Serialize((ushort)PacketCode.INTO_CHANNEL,
|
||||
new IntoChannelPacket { ChannelId = -1 });
|
||||
SendTo(peer, full);
|
||||
return;
|
||||
@@ -432,7 +464,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
HashKey = hashKey,
|
||||
PlayerId = hashKey,
|
||||
Nickname = hashKey.ToString()
|
||||
Nickname = ((Session)peer.Tag).UserName
|
||||
};
|
||||
|
||||
Session? session = peer.Tag as Session;
|
||||
@@ -479,6 +511,34 @@ 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)
|
||||
@@ -500,15 +560,15 @@ public class GameServer : ServerBase
|
||||
}
|
||||
|
||||
// 새로운 파티를 복사한다
|
||||
PartyInfo newParty = new PartyInfo();
|
||||
newParty.DeepCopySemi(preParty);
|
||||
PartyInfo tempParty = new();
|
||||
tempParty.DeepCopySemi(preParty);
|
||||
|
||||
// 최대 인원 체크
|
||||
if (newChannel.UserCount + newParty.PartyMemberIds.Count >= newChannel.UserCountMax)
|
||||
if (newChannel.UserCount + preParty.PartyMemberIds.Count >= newChannel.UserCountMax)
|
||||
{
|
||||
Log.Warning("[GameServer] INTO_CHANNEL_PARTY 채널 인원 초과 HashKey={Key} ChannelId={ChannelId} UserCount={Count}/{Max}",
|
||||
hashKey, packet.ChannelId, newChannel.UserCount, newChannel.UserCountMax);
|
||||
byte[] full = PacketSerializer.Serialize<IntoChannelPacket>((ushort)PacketCode.INTO_CHANNEL,
|
||||
byte[] full = PacketSerializer.Serialize((ushort)PacketCode.INTO_CHANNEL,
|
||||
new IntoChannelPacket { ChannelId = -1 });
|
||||
SendTo(peer, full);
|
||||
return;
|
||||
@@ -520,42 +580,43 @@ public class GameServer : ServerBase
|
||||
Player? player = preChannel.GetPlayer(memberId);
|
||||
if (player != null)
|
||||
{
|
||||
UpdateChannelUserPacket exitNotify = new UpdateChannelUserPacket
|
||||
UpdateChannelUserPacket exitNotify = new()
|
||||
{
|
||||
Players = ToPlayerInfo(player),
|
||||
IsAdd = false
|
||||
};
|
||||
byte[] exitData = PacketSerializer.Serialize<UpdateChannelUserPacket>((ushort)PacketCode.UPDATE_CHANNEL_USER, exitNotify);
|
||||
byte[] exitData = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_CHANNEL_USER, exitNotify);
|
||||
BroadcastToChannel(preChannelId, exitData);
|
||||
|
||||
// 이전 채널에서 제거
|
||||
preChannel.RemoveUser(memberId);
|
||||
|
||||
// 현재 존재하는 파티원만 추가한다.
|
||||
newParty.PartyMemberIds.Add(memberId);
|
||||
tempParty.PartyMemberIds.Add(memberId);
|
||||
}
|
||||
}
|
||||
|
||||
// 이전채널에서 파티를 지운다.
|
||||
preChannel.GetPartyManager().DeleteParty(hashKey, packet.PartyId, out preParty);
|
||||
UpdatePartyPacket notify = new UpdatePartyPacket
|
||||
UpdatePartyPacket notify = new()
|
||||
{
|
||||
PartyId = preParty!.PartyId,
|
||||
Type = PartyUpdateType.DELETE,
|
||||
LeaderId = preParty.LeaderId,
|
||||
LeaderId = preParty.LeaderId
|
||||
};
|
||||
BroadcastToChannel(preChannelId,
|
||||
PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify)); // 채널 전체 파티 목록 갱신
|
||||
|
||||
// 채널 전체 파티 목록 갱신
|
||||
BroadcastToChannel(preChannelId, PacketSerializer.Serialize((ushort)PacketCode.UPDATE_PARTY, notify));
|
||||
|
||||
// 새로운 채널에 파티원 넣기
|
||||
foreach (int memberId in newParty.PartyMemberIds)
|
||||
foreach (int memberId in tempParty.PartyMemberIds)
|
||||
{
|
||||
sessions.TryGetValue(memberId, out NetPeer? memberPeer);
|
||||
|
||||
if (memberPeer != null)
|
||||
{
|
||||
// 새 채널에 유저 추가
|
||||
Player newPlayer = new Player
|
||||
Player newPlayer = new()
|
||||
{
|
||||
HashKey = memberId,
|
||||
PlayerId = memberId,
|
||||
@@ -572,17 +633,25 @@ public class GameServer : ServerBase
|
||||
}
|
||||
|
||||
// 새로운 채널에 파티를 추가한다.
|
||||
newChannel.GetPartyManager().CreateParty(newParty.LeaderId, newParty.PartyName, out newParty, newParty.PartyMemberIds);
|
||||
|
||||
// 새 채널 기존 유저들에게 파티 생성 알림
|
||||
UpdatePartyPacket createNotify = new UpdatePartyPacket
|
||||
if (newChannel.GetPartyManager()
|
||||
.CreateParty(tempParty.LeaderId, tempParty.PartyName, out PartyInfo? createdParty, tempParty.PartyMemberIds) &&
|
||||
createdParty != null)
|
||||
{
|
||||
PartyId = newParty.PartyId,
|
||||
Type = PartyUpdateType.CREATE,
|
||||
LeaderId = newParty.LeaderId,
|
||||
PartyName = newParty.PartyName,
|
||||
};
|
||||
BroadcastToChannel(packet.ChannelId, PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, createNotify));
|
||||
// 새 채널 기존 유저들에게 파티 생성 알림
|
||||
UpdatePartyPacket createNotify = new()
|
||||
{
|
||||
PartyId = createdParty.PartyId,
|
||||
Type = PartyUpdateType.CREATE,
|
||||
LeaderId = createdParty.LeaderId,
|
||||
PartyName = createdParty.PartyName
|
||||
};
|
||||
BroadcastToChannel(packet.ChannelId,
|
||||
PacketSerializer.Serialize((ushort)PacketCode.UPDATE_PARTY, createNotify));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warning("[GameServer] 파티생성 실패 !!!");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExitChannel(NetPeer peer, int hashKey, byte[] payload)
|
||||
@@ -624,17 +693,19 @@ public class GameServer : ServerBase
|
||||
|
||||
// 채널 내 플레이어 위치/방향 상태 갱신
|
||||
Player? player = cm.GetChannel(channelId).GetPlayer(hashKey);
|
||||
if (player != null)
|
||||
if (player == null)
|
||||
{
|
||||
player.PosX = packet.Position.X;
|
||||
player.PosY = packet.Position.Y;
|
||||
player.PosZ = packet.Position.Z;
|
||||
player.RotY = packet.RotY;
|
||||
return;
|
||||
}
|
||||
|
||||
// 같은 채널 유저들에게 위치/방향 브로드캐스트 (나 제외)
|
||||
byte[] data = PacketSerializer.Serialize<TransformPlayerPacket>((ushort)PacketCode.TRANSFORM_PLAYER, packet);
|
||||
BroadcastToChannel(channelId, data, peer, DeliveryMethod.Unreliable);
|
||||
player.PosX = packet.Position.X;
|
||||
player.PosY = packet.Position.Y;
|
||||
player.PosZ = packet.Position.Z;
|
||||
player.RotY = packet.RotY;
|
||||
|
||||
// 같은 맵 유저들에게 위치/방향 브로드캐스트 (나 제외)
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.TRANSFORM_PLAYER, packet);
|
||||
BroadcastToMap(channelId, player.CurrentMapId, data, peer, DeliveryMethod.Unreliable);
|
||||
}
|
||||
|
||||
private void OnActionPlayer(NetPeer peer, int hashKey, byte[] payload)
|
||||
@@ -648,9 +719,15 @@ public class GameServer : ServerBase
|
||||
return;
|
||||
}
|
||||
|
||||
// 같은 채널 유저들에게 행동 브로드캐스트 (나 제외)
|
||||
byte[] data = PacketSerializer.Serialize<ActionPlayerPacket>((ushort)PacketCode.ACTION_PLAYER, packet);
|
||||
BroadcastToChannel(channelId, data, peer);
|
||||
Player? player = cm.GetChannel(channelId).GetPlayer(hashKey);
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 같은 맵 유저들에게 행동 브로드캐스트 (나 제외)
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.ACTION_PLAYER, packet);
|
||||
BroadcastToMap(channelId, player.CurrentMapId, data, peer);
|
||||
}
|
||||
|
||||
private void OnStatePlayer(NetPeer peer, int hashKey, byte[] payload)
|
||||
@@ -666,17 +743,19 @@ public class GameServer : ServerBase
|
||||
|
||||
// 채널 내 플레이어 HP/MP 상태 갱신
|
||||
Player? player = cm.GetChannel(channelId).GetPlayer(hashKey);
|
||||
if (player != null)
|
||||
if (player == null)
|
||||
{
|
||||
player.Hp = packet.Hp;
|
||||
player.MaxHp = packet.MaxHp;
|
||||
player.Mp = packet.Mp;
|
||||
player.MaxMp = packet.MaxMp;
|
||||
return;
|
||||
}
|
||||
|
||||
// 같은 채널 유저들에게 스테이트 브로드캐스트 (나 제외)
|
||||
byte[] data = PacketSerializer.Serialize<StatePlayerPacket>((ushort)PacketCode.STATE_PLAYER, packet);
|
||||
BroadcastToChannel(channelId, data, peer);
|
||||
player.Hp = packet.Hp;
|
||||
player.MaxHp = packet.MaxHp;
|
||||
player.Mp = packet.Mp;
|
||||
player.MaxMp = packet.MaxMp;
|
||||
|
||||
// 같은 맵 유저들에게 스테이트 브로드캐스트 (나 제외)
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.STATE_PLAYER, packet);
|
||||
BroadcastToMap(channelId, player.CurrentMapId, data, peer);
|
||||
}
|
||||
|
||||
private void OnRequestParty(NetPeer peer, int hashKey, byte[] payload)
|
||||
@@ -702,15 +781,15 @@ public class GameServer : ServerBase
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePartyPacket notify = new UpdatePartyPacket
|
||||
UpdatePartyPacket notify = new()
|
||||
{
|
||||
PartyId = party!.PartyId,
|
||||
Type = PartyUpdateType.CREATE,
|
||||
LeaderId = party.LeaderId,
|
||||
PlayerId = hashKey,
|
||||
PartyName = party.PartyName,
|
||||
PartyName = party.PartyName
|
||||
};
|
||||
byte[] data = PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
BroadcastToChannel(channelId, data); // 채널 전체 파티 목록 갱신
|
||||
break;
|
||||
}
|
||||
@@ -722,28 +801,28 @@ public class GameServer : ServerBase
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePartyPacket notify = new UpdatePartyPacket
|
||||
UpdatePartyPacket notify = new()
|
||||
{
|
||||
PartyId = party!.PartyId,
|
||||
Type = PartyUpdateType.JOIN,
|
||||
LeaderId = party.LeaderId,
|
||||
PlayerId = hashKey,
|
||||
PlayerId = hashKey
|
||||
};
|
||||
byte[] data = PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
BroadcastToChannel(channelId, data); // 채널 전체 파티 목록 갱신
|
||||
break;
|
||||
}
|
||||
case PartyUpdateType.LEAVE:
|
||||
{
|
||||
if (!pm.LeaveParty(hashKey, out PartyInfo? party))
|
||||
if (!pm.LeaveParty(hashKey, out PartyInfo? party) || party == null)
|
||||
{
|
||||
SendError(peer, ErrorCode.PARTY_NOT_IN_PARTY);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePartyPacket notify = new UpdatePartyPacket
|
||||
UpdatePartyPacket notify = new()
|
||||
{
|
||||
PartyId = party.PartyId, Type = PartyUpdateType.DELETE, LeaderId = party?.LeaderId ?? 0, PlayerId = hashKey,
|
||||
PartyId = party.PartyId, Type = PartyUpdateType.DELETE, LeaderId = party.LeaderId, PlayerId = hashKey
|
||||
};
|
||||
|
||||
// 파티가 남아있으면 살린다.
|
||||
@@ -752,7 +831,7 @@ public class GameServer : ServerBase
|
||||
notify.Type = PartyUpdateType.LEAVE;
|
||||
}
|
||||
|
||||
byte[] data = PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
BroadcastToChannel(channelId, data); // 채널 전체 파티 목록 갱신 (탈퇴자 포함)
|
||||
break;
|
||||
}
|
||||
@@ -764,13 +843,13 @@ public class GameServer : ServerBase
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePartyPacket notify = new UpdatePartyPacket
|
||||
UpdatePartyPacket notify = new()
|
||||
{
|
||||
PartyId = party!.PartyId,
|
||||
Type = PartyUpdateType.DELETE,
|
||||
LeaderId = party.LeaderId,
|
||||
LeaderId = party.LeaderId
|
||||
};
|
||||
byte[] data = PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
BroadcastToChannel(channelId, data); // 채널 전체 파티 목록 갱신
|
||||
break;
|
||||
}
|
||||
@@ -782,15 +861,15 @@ public class GameServer : ServerBase
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePartyPacket notify = new UpdatePartyPacket
|
||||
UpdatePartyPacket notify = new()
|
||||
{
|
||||
PartyId = req.PartyId,
|
||||
Type = PartyUpdateType.UPDATE,
|
||||
LeaderId = party?.LeaderId ?? 0,
|
||||
PlayerId = hashKey,
|
||||
PartyName = req.PartyName,
|
||||
PartyName = req.PartyName
|
||||
};
|
||||
byte[] data = PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
BroadcastToChannel(channelId, data); // 채널 전체 파티 목록 갱신
|
||||
break;
|
||||
}
|
||||
@@ -815,16 +894,16 @@ public class GameServer : ServerBase
|
||||
}
|
||||
|
||||
// 서버에서 발신자 정보 채워줌 (클라 위조 방지)
|
||||
ChatPacket res = new ChatPacket
|
||||
ChatPacket res = new()
|
||||
{
|
||||
Type = req.Type,
|
||||
SenderId = sender.PlayerId,
|
||||
SenderNickname = sender.Nickname,
|
||||
TargetId = req.TargetId,
|
||||
Message = req.Message,
|
||||
Message = req.Message
|
||||
};
|
||||
|
||||
byte[] data = PacketSerializer.Serialize<ChatPacket>((ushort)PacketCode.CHAT, res);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.CHAT, res);
|
||||
|
||||
switch (req.Type)
|
||||
{
|
||||
@@ -866,6 +945,259 @@ public class GameServer : ServerBase
|
||||
}
|
||||
}
|
||||
|
||||
private void OnChangeMap(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
ChangeMapPacket packet = Serializer.Deserialize<ChangeMapPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
|
||||
ChannelManager cm = ChannelManager.Instance;
|
||||
int channelId = cm.HasUser(hashKey);
|
||||
if (channelId < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Channel.Channel channel = cm.GetChannel(channelId);
|
||||
Player? player = channel.GetPlayer(hashKey);
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int oldMapId = player.CurrentMapId;
|
||||
|
||||
if (!channel.ChangeMap(hashKey, player, packet.MapId))
|
||||
{
|
||||
Log.Warning("[GameServer] CHANGE_MAP 유효하지 않은 맵 HashKey={Key} MapId={MapId}", hashKey, packet.MapId);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInfo playerInfo = ToPlayerInfo(player);
|
||||
|
||||
// 기존 맵 유저들에게 퇴장 알림
|
||||
ChangeMapPacket exitNotify = new() { MapId = oldMapId, IsAdd = false, Player = playerInfo };
|
||||
BroadcastToMap(channelId, oldMapId, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, exitNotify));
|
||||
|
||||
// 새 맵 유저들에게 입장 알림 (본인 제외)
|
||||
ChangeMapPacket enterNotify = new() { MapId = packet.MapId, IsAdd = true, Player = playerInfo };
|
||||
BroadcastToMap(channelId, packet.MapId, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, enterNotify), peer);
|
||||
|
||||
// 본인에게 새 맵 플레이어 목록 전달
|
||||
ChangeMapPacket response = new() { MapId = packet.MapId };
|
||||
AMap? newMap = channel.GetMap(packet.MapId);
|
||||
if (newMap != null)
|
||||
{
|
||||
foreach ((int uid, Player p) in newMap.GetUsers())
|
||||
{
|
||||
if (uid == hashKey)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
response.Players.Add(ToPlayerInfo(p));
|
||||
}
|
||||
}
|
||||
|
||||
SendTo(peer, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, response));
|
||||
Log.Debug("[GameServer] CHANGE_MAP HashKey={Key} OldMap={OldMapId} NewMap={MapId}", hashKey, oldMapId, packet.MapId);
|
||||
}
|
||||
|
||||
private void OnPartyChangeMap(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
PartyChangeMapPacket packet = Serializer.Deserialize<PartyChangeMapPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
|
||||
ChannelManager cm = ChannelManager.Instance;
|
||||
int channelId = cm.HasUser(hashKey);
|
||||
if (channelId < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Channel.Channel channel = cm.GetChannel(channelId);
|
||||
|
||||
// 맵 유효성 체크
|
||||
if (channel.GetMap(packet.MapId) == null)
|
||||
{
|
||||
Log.Warning("[GameServer] PARTY_CHANGE_MAP 유효하지 않은 맵 HashKey={Key} MapId={MapId}", hashKey, packet.MapId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 파티 확인
|
||||
PartyInfo? party = channel.GetPartyManager().GetParty(packet.PartyId);
|
||||
if (party == null)
|
||||
{
|
||||
Log.Warning("[GameServer] PARTY_CHANGE_MAP 파티 없음 HashKey={Key} PartyId={PartyId}", hashKey, packet.PartyId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 파티원 전체 맵 이동 + 각자에게 알림
|
||||
foreach (int memberId in party.PartyMemberIds)
|
||||
{
|
||||
Player? memberPlayer = channel.GetPlayer(memberId);
|
||||
if (memberPlayer == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int oldMapId = memberPlayer.CurrentMapId;
|
||||
channel.ChangeMap(memberId, memberPlayer, packet.MapId);
|
||||
|
||||
if (!sessions.TryGetValue(memberId, out NetPeer? memberPeer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
PlayerInfo memberInfo = ToPlayerInfo(memberPlayer);
|
||||
|
||||
// 기존 맵 유저들에게 퇴장 알림
|
||||
ChangeMapPacket exitNotify = new() { MapId = oldMapId, IsAdd = false, Player = memberInfo };
|
||||
BroadcastToMap(channelId, oldMapId, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, exitNotify));
|
||||
|
||||
// 새 맵 유저들에게 입장 알림 (본인 제외)
|
||||
ChangeMapPacket enterNotify = new() { MapId = packet.MapId, IsAdd = true, Player = memberInfo };
|
||||
BroadcastToMap(channelId, packet.MapId, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, enterNotify), memberPeer);
|
||||
|
||||
// 본인에게 새 맵 플레이어 목록 전달
|
||||
ChangeMapPacket response = new() { MapId = packet.MapId };
|
||||
AMap? newMap = channel.GetMap(packet.MapId);
|
||||
if (newMap != null)
|
||||
{
|
||||
foreach ((int uid, Player p) in newMap.GetUsers())
|
||||
{
|
||||
if (uid == memberId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
response.Players.Add(ToPlayerInfo(p));
|
||||
}
|
||||
}
|
||||
|
||||
SendTo(memberPeer, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, response));
|
||||
}
|
||||
|
||||
Log.Debug("[GameServer] PARTY_CHANGE_MAP HashKey={Key} PartyId={PartyId} MapId={MapId}", hashKey, packet.PartyId, packet.MapId);
|
||||
}
|
||||
|
||||
private async void OnIntoBossRaid(NetPeer peer, int hashKey, byte[] payload)
|
||||
{
|
||||
IntoBossRaidPacket packet = Serializer.Deserialize<IntoBossRaidPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
|
||||
ChannelManager cm = ChannelManager.Instance;
|
||||
int channelId = cm.HasUser(hashKey);
|
||||
if (channelId < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Channel.Channel channel = cm.GetChannel(channelId);
|
||||
|
||||
// 파티 조회
|
||||
PartyInfo? party = channel.GetPartyManager().GetPartyByPlayer(hashKey);
|
||||
if (party == null)
|
||||
{
|
||||
Log.Warning("[GameServer] INTO_BOSS_RAID 파티 없음 HashKey={Key}", hashKey);
|
||||
SendTo(peer, PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
||||
new IntoBossRaidPacket { RaidId = packet.RaidId, IsSuccess = false }));
|
||||
return;
|
||||
}
|
||||
|
||||
// 파티장만 요청 가능
|
||||
if (party.LeaderId != hashKey)
|
||||
{
|
||||
Log.Warning("[GameServer] INTO_BOSS_RAID 파티장 아님 HashKey={Key} LeaderId={LeaderId}", hashKey, party.LeaderId);
|
||||
SendTo(peer, PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
||||
new IntoBossRaidPacket { RaidId = packet.RaidId, IsSuccess = false }));
|
||||
return;
|
||||
}
|
||||
|
||||
// API로 접속 체크
|
||||
List<string> userNames = new List<string>();
|
||||
foreach (int memberId in party.PartyMemberIds)
|
||||
{
|
||||
userNames.Add(channel.GetPlayer(memberId).Nickname);
|
||||
}
|
||||
|
||||
BossRaidResult? result = await RestApi.Instance.BossRaidAccesssAsync(userNames, 1);
|
||||
|
||||
// 입장 실패
|
||||
if (result == null || result.BossId <= 0)
|
||||
{
|
||||
SendTo(peer,
|
||||
PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
||||
new IntoBossRaidPacket { RaidId = -1, IsSuccess = false }));
|
||||
|
||||
Log.Debug("[GameServer] INTO_BOSS_RAID HashKey={Key} PartyId={PartyId} AssignedRaidMapId={RaidId} Failed", hashKey,
|
||||
party.PartyId, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
// 레이드 맵 할당 (미사용 맵 탐색 → 없으면 동적 생성)
|
||||
int assignedRaidMapId = channel.GetOrCreateAvailableRaidMap();
|
||||
|
||||
// 진행중 맵으로 등록
|
||||
channel.AddInstanceMap(assignedRaidMapId);
|
||||
|
||||
// 파티원 전체 레이드 맵으로 이동 + 각자에게 알림
|
||||
foreach (int memberId in party.PartyMemberIds)
|
||||
{
|
||||
Player? memberPlayer = channel.GetPlayer(memberId);
|
||||
if (memberPlayer == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 이전 맵 캐싱 (레이드 종료 후 복귀용)
|
||||
memberPlayer.PreviousMapId = memberPlayer.CurrentMapId;
|
||||
|
||||
int oldMapId = memberPlayer.CurrentMapId;
|
||||
channel.ChangeMap(memberId, memberPlayer, assignedRaidMapId);
|
||||
|
||||
if (!sessions.TryGetValue(memberId, out NetPeer? memberPeer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
PlayerInfo memberInfo = ToPlayerInfo(memberPlayer);
|
||||
|
||||
// 기존 맵 유저들에게 퇴장 알림
|
||||
ChangeMapPacket exitNotify = new() { MapId = oldMapId, IsAdd = false, Player = memberInfo };
|
||||
BroadcastToMap(channelId, oldMapId, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, exitNotify));
|
||||
|
||||
// 새 맵 유저들에게 입장 알림 (본인 제외)
|
||||
ChangeMapPacket enterNotify = new() { MapId = assignedRaidMapId, IsAdd = true, Player = memberInfo };
|
||||
BroadcastToMap(channelId, assignedRaidMapId, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, enterNotify),
|
||||
memberPeer);
|
||||
|
||||
// 본인에게 새 맵 플레이어 목록 전달
|
||||
ChangeMapPacket response = new() { MapId = assignedRaidMapId };
|
||||
AMap? raidMap = channel.GetMap(assignedRaidMapId);
|
||||
if (raidMap != null)
|
||||
{
|
||||
foreach ((int uid, Player p) in raidMap.GetUsers())
|
||||
{
|
||||
if (uid != memberId)
|
||||
{
|
||||
response.Players.Add(ToPlayerInfo(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SendTo(memberPeer, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, response));
|
||||
|
||||
// 각 멤버에게 개별 토큰과 함께 레이드 이동 알림
|
||||
string? memberToken = null;
|
||||
result.Tokens?.TryGetValue(memberPlayer.Nickname, out memberToken);
|
||||
|
||||
SendTo(memberPeer,
|
||||
PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
||||
new IntoBossRaidPacket
|
||||
{ RaidId = assignedRaidMapId, IsSuccess = true, Session = result.SessionName, Token = memberToken }));
|
||||
}
|
||||
|
||||
Log.Debug("[GameServer] INTO_BOSS_RAID HashKey={Key} PartyId={PartyId} AssignedRaidMapId={RaidId}", hashKey, party.PartyId,
|
||||
assignedRaidMapId);
|
||||
}
|
||||
|
||||
// 채널 퇴장/연결 해제 시 파티 자동 탈퇴 처리
|
||||
private void HandlePartyLeaveOnExit(int channelId, int hashKey)
|
||||
{
|
||||
@@ -886,24 +1218,24 @@ public class GameServer : ServerBase
|
||||
PartyId = partyId.Value,
|
||||
Type = PartyUpdateType.LEAVE,
|
||||
LeaderId = remaining.LeaderId,
|
||||
PlayerId = hashKey,
|
||||
PlayerId = hashKey
|
||||
}
|
||||
: new UpdatePartyPacket
|
||||
{
|
||||
PartyId = partyId.Value,
|
||||
Type = PartyUpdateType.DELETE,
|
||||
LeaderId = -1,
|
||||
PlayerId = hashKey,
|
||||
PlayerId = hashKey
|
||||
};
|
||||
|
||||
byte[] data = PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.UPDATE_PARTY, notify);
|
||||
BroadcastToChannel(channelId, data);
|
||||
}
|
||||
|
||||
private void SendError(NetPeer peer, ErrorCode code)
|
||||
{
|
||||
ErrorPacket err = new ErrorPacket { Code = code };
|
||||
byte[] data = PacketSerializer.Serialize<ErrorPacket>((ushort)PacketCode.ERROR, err);
|
||||
ErrorPacket err = new() { Code = code };
|
||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.ERROR, err);
|
||||
SendTo(peer, data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user