fix: MMO 서버 버그 수정 및 안정성 개선 (20건)
- VerifyTokenAsync 인증 우회 차단 (빈 문자열→null 반환) - HandleAuth/OnIntoBossRaid async void→async Task 전환 - await 후 스레드 안전성 확보 (sessionLock 도입) - 보스레이드 파티원 세션/토큰 개별 전달 (tokens Dictionary 타입 수정) - 409 Conflict 처리 추가, bossId 하드코딩 제거 - 채널 이동 시 레이드 맵 해제, 플레이어 상태 보존 - 파티원 닉네임 손실 수정, HandlePartyLeaveOnExit 알림 타입 수정 - PacketCode enum 명시적 값 할당, MaplId→MapId/BossRaidAccesss→Access 오타 수정 - Channel.UserCount 음수 방지, HandleAuth 재연결 로직 수정 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,5 +9,5 @@ public sealed class BossRaidResult
|
|||||||
public int BossId { get; init; }
|
public int BossId { get; init; }
|
||||||
public List<string> Players { get; init; } = new();
|
public List<string> Players { get; init; } = new();
|
||||||
public string Status { get; init; } = string.Empty;
|
public string Status { get; init; } = string.Empty;
|
||||||
public string? Tokens { get; init; }
|
public Dictionary<string, string>? Tokens { get; init; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class RestApi : Singleton<RestApi>
|
|||||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
{
|
{
|
||||||
Log.Warning("[RestApi] 토큰 인증 실패 (401)");
|
Log.Warning("[RestApi] 토큰 인증 실패 (401)");
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
@@ -56,7 +56,7 @@ public class RestApi : Singleton<RestApi>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class AuthVerifyResponse
|
private sealed class AuthVerifyResponse
|
||||||
@@ -71,7 +71,7 @@ public class RestApi : Singleton<RestApi>
|
|||||||
|
|
||||||
// 레이드 채널 접속 여부 체크
|
// 레이드 채널 접속 여부 체크
|
||||||
// 성공 시 BossRaidResult 반환, 실패/거절 시 null 반환
|
// 성공 시 BossRaidResult 반환, 실패/거절 시 null 반환
|
||||||
public async Task<BossRaidResult?> BossRaidAccesssAsync(List<string> userNames, int bossId)
|
public async Task<BossRaidResult?> BossRaidAccessAsync(List<string> userNames, int bossId)
|
||||||
{
|
{
|
||||||
string url = AppConfig.RestApi.BaseUrl + "/api/internal/bossraid/entry";
|
string url = AppConfig.RestApi.BaseUrl + "/api/internal/bossraid/entry";
|
||||||
|
|
||||||
@@ -88,10 +88,12 @@ public class RestApi : Singleton<RestApi>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 400: 입장 조건 미충족 (레벨 부족, 이미 진행중 등)
|
// 400: 입장 조건 미충족 / 409: 이미 레이드 중 등
|
||||||
if (response.StatusCode == HttpStatusCode.BadRequest)
|
if (response.StatusCode == HttpStatusCode.BadRequest ||
|
||||||
|
response.StatusCode == HttpStatusCode.Conflict)
|
||||||
{
|
{
|
||||||
Log.Warning("[RestApi] 보스 레이드 입장 거절 (400) BossId={BossId}", bossId);
|
Log.Warning("[RestApi] 보스 레이드 입장 거절 ({Status}) BossId={BossId}",
|
||||||
|
(int)response.StatusCode, bossId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +168,7 @@ public class RestApi : Singleton<RestApi>
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonPropertyName("tokens")]
|
[JsonPropertyName("tokens")]
|
||||||
public string? Tokens
|
public Dictionary<string, string>? Tokens
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
|||||||
@@ -79,11 +79,14 @@ public class Channel
|
|||||||
currentMap.RemoveUser(userId);
|
currentMap.RemoveUser(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
connectUsers.Remove(userId);
|
if (connectUsers.Remove(userId))
|
||||||
connectPeers.Remove(userId);
|
{
|
||||||
UserCount--;
|
UserCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectPeers.Remove(userId);
|
||||||
|
}
|
||||||
|
|
||||||
// 맵 이동 (현재 맵 제거 → 새 맵 추가 → CurrentMapId 갱신)
|
// 맵 이동 (현재 맵 제거 → 새 맵 추가 → CurrentMapId 갱신)
|
||||||
public bool ChangeMap(int userId, Player player, int mapId)
|
public bool ChangeMap(int userId, Player player, int mapId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class GameServer : ServerBase
|
|||||||
OnSessionConnected(peer, hashKey);
|
OnSessionConnected(peer, hashKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async void HandleAuth(NetPeer peer, byte[] payload)
|
protected override async Task HandleAuth(NetPeer peer, byte[] payload)
|
||||||
{
|
{
|
||||||
AccTokenPacket accTokenPacket = Serializer.Deserialize<AccTokenPacket>(new ReadOnlyMemory<byte>(payload));
|
AccTokenPacket accTokenPacket = Serializer.Deserialize<AccTokenPacket>(new ReadOnlyMemory<byte>(payload));
|
||||||
string token = accTokenPacket.Token;
|
string token = accTokenPacket.Token;
|
||||||
@@ -118,13 +118,18 @@ public class GameServer : ServerBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string username = "";
|
string username = "";
|
||||||
tokenHash.TryGetValue(token, out int hashKey);
|
int hashKey;
|
||||||
if (hashKey <= 1000)
|
bool isReconnect;
|
||||||
|
|
||||||
|
lock (sessionLock)
|
||||||
|
{
|
||||||
|
isReconnect = tokenHash.TryGetValue(token, out hashKey) && hashKey > 1000;
|
||||||
|
if (!isReconnect)
|
||||||
{
|
{
|
||||||
hashKey = userUuidGenerator.Create();
|
hashKey = userUuidGenerator.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sessions.TryGetValue(hashKey, out NetPeer? existing))
|
if (isReconnect && sessions.TryGetValue(hashKey, out NetPeer? existing))
|
||||||
{
|
{
|
||||||
// WiFi → LTE 전환 등 재연결: 이전 피어 교체 (토큰 재검증 불필요)
|
// WiFi → LTE 전환 등 재연결: 이전 피어 교체 (토큰 재검증 불필요)
|
||||||
existing.Tag = null;
|
existing.Tag = null;
|
||||||
@@ -132,7 +137,9 @@ public class GameServer : ServerBase
|
|||||||
Log.Information("[Server] 재연결 HashKey={Key} Old={Old} New={New}", hashKey, existing.Id, peer.Id);
|
Log.Information("[Server] 재연결 HashKey={Key} Old={Old} New={New}", hashKey, existing.Id, peer.Id);
|
||||||
existing.Disconnect();
|
existing.Disconnect();
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
if (!isReconnect)
|
||||||
{
|
{
|
||||||
// 신규 연결: 웹서버에 JWT 검증 요청
|
// 신규 연결: 웹서버에 JWT 검증 요청
|
||||||
username = await RestApi.Instance.VerifyTokenAsync(token);
|
username = await RestApi.Instance.VerifyTokenAsync(token);
|
||||||
@@ -147,6 +154,9 @@ public class GameServer : ServerBase
|
|||||||
Log.Information("[Server] 토큰 검증 성공 Username={Username} PeerId={Id}", username, peer.Id);
|
Log.Information("[Server] 토큰 검증 성공 Username={Username} PeerId={Id}", username, peer.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// await 이후 — 공유 자원 접근 보호
|
||||||
|
lock (sessionLock)
|
||||||
|
{
|
||||||
peer.Tag = new Session(hashKey, peer);
|
peer.Tag = new Session(hashKey, peer);
|
||||||
((Session)peer.Tag).Token = token;
|
((Session)peer.Tag).Token = token;
|
||||||
if (username.Length > 0)
|
if (username.Length > 0)
|
||||||
@@ -157,6 +167,7 @@ public class GameServer : ServerBase
|
|||||||
sessions[hashKey] = peer;
|
sessions[hashKey] = peer;
|
||||||
tokenHash[token] = hashKey;
|
tokenHash[token] = hashKey;
|
||||||
pendingPeers.Remove(peer.Id);
|
pendingPeers.Remove(peer.Id);
|
||||||
|
}
|
||||||
|
|
||||||
Log.Information("[Server] 인증 완료 HashKey={Key} PeerId={Id}", hashKey, peer.Id);
|
Log.Information("[Server] 인증 완료 HashKey={Key} PeerId={Id}", hashKey, peer.Id);
|
||||||
OnSessionConnected(peer, hashKey);
|
OnSessionConnected(peer, hashKey);
|
||||||
@@ -357,7 +368,7 @@ public class GameServer : ServerBase
|
|||||||
{
|
{
|
||||||
IsAccepted = true,
|
IsAccepted = true,
|
||||||
Player = ToPlayerInfo(player),
|
Player = ToPlayerInfo(player),
|
||||||
MaplId = channelId
|
MapId = player.CurrentMapId
|
||||||
};
|
};
|
||||||
|
|
||||||
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.LOAD_GAME, packet);
|
byte[] data = PacketSerializer.Serialize((ushort)PacketCode.LOAD_GAME, packet);
|
||||||
@@ -444,14 +455,20 @@ public class GameServer : ServerBase
|
|||||||
|
|
||||||
// 이전에 다른 채널에 있었는지 체크
|
// 이전에 다른 채널에 있었는지 체크
|
||||||
int preChannelId = cm.HasUser(hashKey);
|
int preChannelId = cm.HasUser(hashKey);
|
||||||
|
Player? prevPlayer = preChannelId >= 0 ? cm.GetChannel(preChannelId).GetPlayer(hashKey) : null;
|
||||||
if (preChannelId >= 0)
|
if (preChannelId >= 0)
|
||||||
{
|
{
|
||||||
// 제거 전에 채널/플레이어 정보 저장 (브로드캐스트에 필요)
|
Player? player = prevPlayer;
|
||||||
Player? player = cm.GetChannel(preChannelId).GetPlayer(hashKey);
|
|
||||||
|
|
||||||
// 파티 자동 탈퇴
|
// 파티 자동 탈퇴
|
||||||
HandlePartyLeaveOnExit(preChannelId, hashKey);
|
HandlePartyLeaveOnExit(preChannelId, hashKey);
|
||||||
|
|
||||||
|
// 레이드 맵 해제 체크
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
TryReleaseRaidMap(cm.GetChannel(preChannelId), player.CurrentMapId);
|
||||||
|
}
|
||||||
|
|
||||||
cm.RemoveUser(hashKey);
|
cm.RemoveUser(hashKey);
|
||||||
Log.Debug("[GameServer] EXIT_CHANNEL HashKey={Key} PlayerId={PlayerId}", hashKey, preChannelId);
|
Log.Debug("[GameServer] EXIT_CHANNEL HashKey={Key} PlayerId={PlayerId}", hashKey, preChannelId);
|
||||||
|
|
||||||
@@ -471,15 +488,9 @@ public class GameServer : ServerBase
|
|||||||
hashKey, packet.ChannelId, newChannel.UserCount, newChannel.UserCountMax);
|
hashKey, packet.ChannelId, newChannel.UserCount, newChannel.UserCountMax);
|
||||||
|
|
||||||
// 이전 채널에서 이미 제거된 경우 → 이전 채널로 복귀
|
// 이전 채널에서 이미 제거된 경우 → 이전 채널로 복귀
|
||||||
if (preChannelId >= 0)
|
if (preChannelId >= 0 && prevPlayer != null)
|
||||||
{
|
{
|
||||||
Player? fallbackPlayer = new()
|
cm.AddUser(preChannelId, hashKey, prevPlayer, peer);
|
||||||
{
|
|
||||||
HashKey = hashKey,
|
|
||||||
PlayerId = hashKey,
|
|
||||||
Nickname = ((Session)peer.Tag).UserName
|
|
||||||
};
|
|
||||||
cm.AddUser(preChannelId, hashKey, fallbackPlayer, peer);
|
|
||||||
Log.Information("[GameServer] INTO_CHANNEL 만석 → 이전 채널({ChannelId})로 복귀 HashKey={Key}", preChannelId, hashKey);
|
Log.Information("[GameServer] INTO_CHANNEL 만석 → 이전 채널({ChannelId})로 복귀 HashKey={Key}", preChannelId, hashKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,12 +554,19 @@ public class GameServer : ServerBase
|
|||||||
ChannelManager cm = ChannelManager.Instance;
|
ChannelManager cm = ChannelManager.Instance;
|
||||||
|
|
||||||
int preChannelId = cm.HasUser(hashKey);
|
int preChannelId = cm.HasUser(hashKey);
|
||||||
|
|
||||||
|
// 이전에 다른 채널에 있었는지 체크 / 파티이동은 이미 접속한 상태여야 한다.
|
||||||
|
if (preChannelId < 0)
|
||||||
|
{
|
||||||
|
Log.Warning("[GameServer] INTO_CHANNEL_PARTY 채널에 접속하지 않은 유저");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Channel.Channel preChannel = cm.GetChannel(preChannelId);
|
Channel.Channel preChannel = cm.GetChannel(preChannelId);
|
||||||
Channel.Channel newChannel = cm.GetChannel(packet.ChannelId);
|
Channel.Channel newChannel = cm.GetChannel(packet.ChannelId);
|
||||||
PartyInfo? preParty = preChannel.GetPartyManager().GetParty(packet.PartyId);
|
PartyInfo? preParty = preChannel.GetPartyManager().GetParty(packet.PartyId);
|
||||||
|
|
||||||
// 이전에 다른 채널에 있었는지 체크 / 파티이동은 이미 접속한 상태여야 한다.
|
if (preParty == null)
|
||||||
if (preChannelId < 0 || preParty == null)
|
|
||||||
{
|
{
|
||||||
Log.Warning("[GameServer] INTO_CHANNEL_PARTY 해당 파티 없음");
|
Log.Warning("[GameServer] INTO_CHANNEL_PARTY 해당 파티 없음");
|
||||||
return;
|
return;
|
||||||
@@ -569,12 +587,15 @@ public class GameServer : ServerBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 기존 채널에서 제거 + 기존 채널 유저들에게 나감 알림
|
// 기존 채널에서 제거 전에 플레이어 정보 보존
|
||||||
|
Dictionary<int, Player> savedPlayers = new();
|
||||||
foreach (int memberId in preParty.PartyMemberIds)
|
foreach (int memberId in preParty.PartyMemberIds)
|
||||||
{
|
{
|
||||||
Player? player = preChannel.GetPlayer(memberId);
|
Player? player = preChannel.GetPlayer(memberId);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
|
savedPlayers[memberId] = player;
|
||||||
|
|
||||||
UpdateChannelUserPacket exitNotify = new()
|
UpdateChannelUserPacket exitNotify = new()
|
||||||
{
|
{
|
||||||
Players = ToPlayerInfo(player),
|
Players = ToPlayerInfo(player),
|
||||||
@@ -610,12 +631,13 @@ public class GameServer : ServerBase
|
|||||||
|
|
||||||
if (memberPeer != null)
|
if (memberPeer != null)
|
||||||
{
|
{
|
||||||
// 새 채널에 유저 추가
|
// 새 채널에 유저 추가 (보존된 플레이어 정보 사용)
|
||||||
|
string nickname = savedPlayers.TryGetValue(memberId, out Player? saved) ? saved.Nickname : memberId.ToString();
|
||||||
Player newPlayer = new()
|
Player newPlayer = new()
|
||||||
{
|
{
|
||||||
HashKey = memberId,
|
HashKey = memberId,
|
||||||
PlayerId = memberId,
|
PlayerId = memberId,
|
||||||
Nickname = memberId.ToString()
|
Nickname = nickname
|
||||||
};
|
};
|
||||||
cm.AddUser(packet.ChannelId, memberId, newPlayer, memberPeer);
|
cm.AddUser(packet.ChannelId, memberId, newPlayer, memberPeer);
|
||||||
|
|
||||||
@@ -663,6 +685,12 @@ public class GameServer : ServerBase
|
|||||||
if (channelId >= 0)
|
if (channelId >= 0)
|
||||||
{
|
{
|
||||||
HandlePartyLeaveOnExit(channelId, hashKey);
|
HandlePartyLeaveOnExit(channelId, hashKey);
|
||||||
|
|
||||||
|
// 레이드 맵 해제 체크
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
TryReleaseRaidMap(cm.GetChannel(channelId), player.CurrentMapId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.RemoveUser(hashKey);
|
cm.RemoveUser(hashKey);
|
||||||
@@ -1092,7 +1120,16 @@ public class GameServer : ServerBase
|
|||||||
Log.Debug("[GameServer] PARTY_CHANGE_MAP HashKey={Key} PartyId={PartyId} MapId={MapId}", hashKey, packet.PartyId, packet.MapId);
|
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)
|
private void OnIntoBossRaid(NetPeer peer, int hashKey, byte[] payload)
|
||||||
|
{
|
||||||
|
_ = OnIntoBossRaidAsync(peer, hashKey, payload).ContinueWith(t =>
|
||||||
|
{
|
||||||
|
if (t.IsFaulted)
|
||||||
|
Log.Error(t.Exception, "[GameServer] OnIntoBossRaid 예외 HashKey={Key}", hashKey);
|
||||||
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnIntoBossRaidAsync(NetPeer peer, int hashKey, byte[] payload)
|
||||||
{
|
{
|
||||||
IntoBossRaidPacket packet = Serializer.Deserialize<IntoBossRaidPacket>(new ReadOnlyMemory<byte>(payload));
|
IntoBossRaidPacket packet = Serializer.Deserialize<IntoBossRaidPacket>(new ReadOnlyMemory<byte>(payload));
|
||||||
|
|
||||||
@@ -1128,11 +1165,20 @@ public class GameServer : ServerBase
|
|||||||
List<string> userNames = new List<string>();
|
List<string> userNames = new List<string>();
|
||||||
foreach (int memberId in party.PartyMemberIds)
|
foreach (int memberId in party.PartyMemberIds)
|
||||||
{
|
{
|
||||||
userNames.Add(channel.GetPlayer(memberId).Nickname);
|
Player? memberPlayer = channel.GetPlayer(memberId);
|
||||||
|
if (memberPlayer == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BossRaidResult? result = await RestApi.Instance.BossRaidAccesssAsync(userNames, 1);
|
userNames.Add(memberPlayer.Nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
BossRaidResult? result = await RestApi.Instance.BossRaidAccessAsync(userNames, packet.RaidId);
|
||||||
|
|
||||||
|
// await 이후 — 공유 자원 접근 보호
|
||||||
|
lock (sessionLock)
|
||||||
|
{
|
||||||
// 입장 실패
|
// 입장 실패
|
||||||
if (result == null || result.BossId <= 0)
|
if (result == null || result.BossId <= 0)
|
||||||
{
|
{
|
||||||
@@ -1145,6 +1191,20 @@ public class GameServer : ServerBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// await 이후 상태 재검증
|
||||||
|
channelId = cm.HasUser(hashKey);
|
||||||
|
if (channelId < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
channel = cm.GetChannel(channelId);
|
||||||
|
party = channel.GetPartyManager().GetPartyByPlayer(hashKey);
|
||||||
|
if (party == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 레이드 맵 할당 (미사용 맵 탐색 → 없으면 동적 생성)
|
// 레이드 맵 할당 (미사용 맵 탐색 → 없으면 동적 생성)
|
||||||
int assignedRaidMapId = channel.GetOrCreateAvailableRaidMap();
|
int assignedRaidMapId = channel.GetOrCreateAvailableRaidMap();
|
||||||
|
|
||||||
@@ -1198,16 +1258,17 @@ public class GameServer : ServerBase
|
|||||||
|
|
||||||
SendTo(memberPeer, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, response));
|
SendTo(memberPeer, PacketSerializer.Serialize((ushort)PacketCode.CHANGE_MAP, response));
|
||||||
|
|
||||||
// 모두에게 레이드로 이동 (할당된 실제 레이드 맵 ID 전달)
|
// 각 파티원에게 레이드 입장 결과 전달 (Session, Token 포함)
|
||||||
SendTo(peer,
|
SendTo(memberPeer,
|
||||||
PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
||||||
new IntoBossRaidPacket
|
new IntoBossRaidPacket
|
||||||
{ RaidId = assignedRaidMapId, IsSuccess = true, Session = result.SessionName, Token = result.Tokens }));
|
{ RaidId = assignedRaidMapId, IsSuccess = true, Session = result.SessionName, Token = result.Tokens != null && result.Tokens.TryGetValue(memberPlayer.Nickname, out string? memberToken) ? memberToken : null }));
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("[GameServer] INTO_BOSS_RAID HashKey={Key} PartyId={PartyId} AssignedRaidMapId={RaidId}", hashKey, party.PartyId,
|
Log.Debug("[GameServer] INTO_BOSS_RAID HashKey={Key} PartyId={PartyId} AssignedRaidMapId={RaidId}", hashKey, party.PartyId,
|
||||||
assignedRaidMapId);
|
assignedRaidMapId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 채널 퇴장/연결 해제 시 파티 자동 탈퇴 처리
|
// 채널 퇴장/연결 해제 시 파티 자동 탈퇴 처리
|
||||||
private void HandlePartyLeaveOnExit(int channelId, int hashKey)
|
private void HandlePartyLeaveOnExit(int channelId, int hashKey)
|
||||||
@@ -1222,8 +1283,8 @@ public class GameServer : ServerBase
|
|||||||
|
|
||||||
pm.LeaveParty(hashKey, out PartyInfo? remaining);
|
pm.LeaveParty(hashKey, out PartyInfo? remaining);
|
||||||
|
|
||||||
// 0명 → DELETE, 남은 멤버 있음 → LEAVE
|
// 남은 멤버 있음 → LEAVE, 0명(파티 해산됨) → DELETE
|
||||||
UpdatePartyPacket notify = remaining != null
|
UpdatePartyPacket notify = remaining != null && remaining.PartyMemberIds.Count > 0
|
||||||
? new UpdatePartyPacket
|
? new UpdatePartyPacket
|
||||||
{
|
{
|
||||||
PartyId = partyId.Value,
|
PartyId = partyId.Value,
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ public class LoadGamePacket
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoMember(3)]
|
[ProtoMember(3)]
|
||||||
public int MaplId
|
public int MapId
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
|||||||
@@ -2,73 +2,73 @@ namespace MMOserver.Packet;
|
|||||||
|
|
||||||
public enum PacketCode : ushort
|
public enum PacketCode : ushort
|
||||||
{
|
{
|
||||||
|
// 초기 클라이언트 시작시 jwt토큰 받아옴
|
||||||
|
ACC_TOKEN = 1,
|
||||||
|
|
||||||
|
// 내 정보 로드 (서버 -> 클라)
|
||||||
|
LOAD_GAME = 2,
|
||||||
|
|
||||||
|
// 모든 채널 로드 - jwt토큰 검증후 게임에 들어갈지 말지 (내 데이터도 전송)
|
||||||
|
// (서버 -> 클라)
|
||||||
|
LOAD_CHANNEL = 3,
|
||||||
|
|
||||||
|
// 나 채널 접속 (클라 -> 서버)
|
||||||
|
INTO_CHANNEL = 4,
|
||||||
|
|
||||||
|
// 파티 채널 접속 (클라 -> 서버)
|
||||||
|
INTO_CHANNEL_PARTY = 5,
|
||||||
|
|
||||||
|
// 새로운 유저 채널 접속 (서버 -> 클라) / 유저 채널 나감 (서버 -> 클라)
|
||||||
|
UPDATE_CHANNEL_USER = 6,
|
||||||
|
|
||||||
|
// 채널 나가기 (클라 -> 서버)
|
||||||
|
EXIT_CHANNEL = 7,
|
||||||
|
|
||||||
|
// 맵 이동
|
||||||
|
CHANGE_MAP = 8,
|
||||||
|
|
||||||
|
// 단체로 맵 이동
|
||||||
|
PARTY_CHANGE_MAP = 9,
|
||||||
|
|
||||||
|
// 파티장이 보스 레이드(인스턴스 던전) 입장 신청 (클라 -> 서버)
|
||||||
|
INTO_BOSS_RAID = 10,
|
||||||
|
|
||||||
|
// 플레이어 위치, 방향 (서버 -> 클라 \ 클라 -> 서버)
|
||||||
|
TRANSFORM_PLAYER = 11,
|
||||||
|
|
||||||
|
// 플레이어 행동 업데이트 (서버 -> 클라 \ 클라 -> 서버)
|
||||||
|
ACTION_PLAYER = 12,
|
||||||
|
|
||||||
|
// 플레이어 스테이트 업데이트 (서버 -> 클라 \ 클라 -> 서버)
|
||||||
|
STATE_PLAYER = 13,
|
||||||
|
|
||||||
|
// NPC 위치, 방향 (서버 -> 클라)
|
||||||
|
TRANSFORM_NPC = 14,
|
||||||
|
|
||||||
|
// NPC 행동 업데이트 (서버 -> 클라)
|
||||||
|
ACTION_NPC = 15,
|
||||||
|
|
||||||
|
// NPC 스테이트 업데이트 (서버 -> 클라)
|
||||||
|
STATE_NPC = 16,
|
||||||
|
|
||||||
|
// 데미지 UI 전달 (서버 -> 클라)
|
||||||
|
DAMAGE = 17,
|
||||||
|
|
||||||
|
// 파티 생성/삭제, 파티원 추가/제거 (서버 -> 클라)
|
||||||
|
UPDATE_PARTY = 18,
|
||||||
|
|
||||||
|
// 파티 참가/탈퇴/생성/해산 요청 (클라 -> 서버)
|
||||||
|
REQUEST_PARTY = 19,
|
||||||
|
|
||||||
|
// 채팅 (클라 -> 서버 & 서버 -> 클라) - GLOBAL / PARTY / WHISPER
|
||||||
|
CHAT = 20,
|
||||||
|
|
||||||
// ECHO
|
// ECHO
|
||||||
ECHO = 1000,
|
ECHO = 1000,
|
||||||
|
|
||||||
// DUMMY 클라는 이걸로 jwt토큰 안받음
|
// DUMMY 클라는 이걸로 jwt토큰 안받음
|
||||||
DUMMY_ACC_TOKEN = 1001,
|
DUMMY_ACC_TOKEN = 1001,
|
||||||
|
|
||||||
// 초기 클라이언트 시작시 jwt토큰 받아옴
|
|
||||||
ACC_TOKEN = 1,
|
|
||||||
|
|
||||||
// 내 정보 로드 (서버 -> 클라)
|
|
||||||
LOAD_GAME,
|
|
||||||
|
|
||||||
// 모든 채널 로드 - jwt토큰 검증후 게임에 들어갈지 말지 (내 데이터도 전송)
|
|
||||||
// (서버 -> 클라)
|
|
||||||
LOAD_CHANNEL,
|
|
||||||
|
|
||||||
// 나 채널 접속 (클라 -> 서버)
|
|
||||||
INTO_CHANNEL,
|
|
||||||
|
|
||||||
// 파티 채널 접속 (클라 -> 서버)
|
|
||||||
INTO_CHANNEL_PARTY,
|
|
||||||
|
|
||||||
// 새로운 유저 채널 접속 (서버 -> 클라) / 유저 채널 나감 (서버 -> 클라)
|
|
||||||
UPDATE_CHANNEL_USER,
|
|
||||||
|
|
||||||
// 채널 나가기 (클라 -> 서버)
|
|
||||||
EXIT_CHANNEL,
|
|
||||||
|
|
||||||
// 맵 이동
|
|
||||||
CHANGE_MAP,
|
|
||||||
|
|
||||||
// 단체로 맵 이동
|
|
||||||
PARTY_CHANGE_MAP,
|
|
||||||
|
|
||||||
// 파티장이 보스 레이드(인스턴스 던전) 입장 신청 (클라 -> 서버)
|
|
||||||
INTO_BOSS_RAID,
|
|
||||||
|
|
||||||
// 플레이어 위치, 방향 (서버 -> 클라 \ 클라 -> 서버)
|
|
||||||
TRANSFORM_PLAYER,
|
|
||||||
|
|
||||||
// 플레이어 행동 업데이트 (서버 -> 클라 \ 클라 -> 서버)
|
|
||||||
ACTION_PLAYER,
|
|
||||||
|
|
||||||
// 플레이어 스테이트 업데이트 (서버 -> 클라 \ 클라 -> 서버)
|
|
||||||
STATE_PLAYER,
|
|
||||||
|
|
||||||
// NPC 위치, 방향 (서버 -> 클라)
|
|
||||||
TRANSFORM_NPC,
|
|
||||||
|
|
||||||
// NPC 행동 업데이트 (서버 -> 클라)
|
|
||||||
ACTION_NPC,
|
|
||||||
|
|
||||||
// NPC 스테이트 업데이트 (서버 -> 클라)
|
|
||||||
STATE_NPC,
|
|
||||||
|
|
||||||
// 데미지 UI 전달 (서버 -> 클라)
|
|
||||||
DAMAGE,
|
|
||||||
|
|
||||||
// 파티 생성/삭제, 파티원 추가/제거 (서버 -> 클라)
|
|
||||||
UPDATE_PARTY,
|
|
||||||
|
|
||||||
// 파티 참가/탈퇴/생성/해산 요청 (클라 -> 서버)
|
|
||||||
REQUEST_PARTY,
|
|
||||||
|
|
||||||
// 채팅 (클라 -> 서버 & 서버 -> 클라) - GLOBAL / PARTY / WHISPER
|
|
||||||
CHAT,
|
|
||||||
|
|
||||||
// 요청 실패 응답 (서버 -> 클라)
|
// 요청 실패 응답 (서버 -> 클라)
|
||||||
ERROR = 9999
|
ERROR = 9999
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ public abstract class ServerBase : INetEventListener
|
|||||||
// 재사용 NetDataWriter (단일 스레드 폴링이므로 안전)
|
// 재사용 NetDataWriter (단일 스레드 폴링이므로 안전)
|
||||||
private readonly NetDataWriter cachedWriter = new();
|
private readonly NetDataWriter cachedWriter = new();
|
||||||
|
|
||||||
|
// async 메서드(HandleAuth 등)의 await 이후 공유 자원 접근 보호용
|
||||||
|
protected readonly object sessionLock = new();
|
||||||
|
|
||||||
// 핑 로그 출력 여부
|
// 핑 로그 출력 여부
|
||||||
public bool PingLogRtt
|
public bool PingLogRtt
|
||||||
{
|
{
|
||||||
@@ -117,6 +120,8 @@ public abstract class ServerBase : INetEventListener
|
|||||||
|
|
||||||
// 클라이언트가 연결 해제됐을 때 (타임아웃, 명시적 끊기 등)
|
// 클라이언트가 연결 해제됐을 때 (타임아웃, 명시적 끊기 등)
|
||||||
public void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo)
|
public void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo)
|
||||||
|
{
|
||||||
|
lock (sessionLock)
|
||||||
{
|
{
|
||||||
pendingPeers.Remove(peer.Id);
|
pendingPeers.Remove(peer.Id);
|
||||||
|
|
||||||
@@ -140,6 +145,7 @@ public abstract class ServerBase : INetEventListener
|
|||||||
peer.Tag = null;
|
peer.Tag = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 연결된 피어로부터 데이터 수신 시 핵심 콜백
|
// 연결된 피어로부터 데이터 수신 시 핵심 콜백
|
||||||
public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, byte channelNumber, DeliveryMethod deliveryMethod)
|
public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, byte channelNumber, DeliveryMethod deliveryMethod)
|
||||||
@@ -167,7 +173,11 @@ public abstract class ServerBase : INetEventListener
|
|||||||
// Auth 패킷은 베이스에서 처리 (raw 8-byte long, protobuf 불필요)
|
// Auth 패킷은 베이스에서 처리 (raw 8-byte long, protobuf 불필요)
|
||||||
if (type == (ushort)PacketType.ACC_TOKEN)
|
if (type == (ushort)PacketType.ACC_TOKEN)
|
||||||
{
|
{
|
||||||
HandleAuth(peer, payload);
|
_ = HandleAuth(peer, payload).ContinueWith(t =>
|
||||||
|
{
|
||||||
|
if (t.IsFaulted)
|
||||||
|
Log.Error(t.Exception, "[Server] HandleAuth 예외 PeerId={Id}", peer.Id);
|
||||||
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (type == (ushort)PacketType.DUMMY_ACC_TOKEN)
|
else if (type == (ushort)PacketType.DUMMY_ACC_TOKEN)
|
||||||
@@ -240,7 +250,7 @@ public abstract class ServerBase : INetEventListener
|
|||||||
|
|
||||||
// ─── Auth 처리 ────────────────────────────────────────────────
|
// ─── Auth 처리 ────────────────────────────────────────────────
|
||||||
|
|
||||||
protected abstract void HandleAuth(NetPeer peer, byte[] payload);
|
protected abstract Task HandleAuth(NetPeer peer, byte[] payload);
|
||||||
|
|
||||||
// ─── 전송 헬퍼 ───────────────────────────────────────────────────────
|
// ─── 전송 헬퍼 ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user