feat : 보스레이드 신청 메시지 응답 패킷 구현
This commit is contained in:
13
MMOTestServer/MMOserver/Api/BossRaidResult.cs
Normal file
13
MMOTestServer/MMOserver/Api/BossRaidResult.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace MMOserver.Api;
|
||||||
|
|
||||||
|
// RestApi.BossRaidAccesssAsync 반환용 도메인 모델
|
||||||
|
// API 응답(BossRaidAccessResponse)을 직접 노출하지 않고 이걸로 매핑해서 반환
|
||||||
|
public sealed class BossRaidResult
|
||||||
|
{
|
||||||
|
public int RoomId { get; init; }
|
||||||
|
public string SessionName { get; init; } = string.Empty;
|
||||||
|
public int BossId { get; init; }
|
||||||
|
public List<string> Players { get; init; } = new();
|
||||||
|
public string Status { get; init; } = string.Empty;
|
||||||
|
public string? Tokens { get; init; }
|
||||||
|
}
|
||||||
@@ -70,8 +70,8 @@ public class RestApi : Singleton<RestApi>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 레이드 채널 접속 여부 체크
|
// 레이드 채널 접속 여부 체크
|
||||||
// 성공 시 sessionName 반환, 실패/거절 시 null 반환
|
// 성공 시 BossRaidResult 반환, 실패/거절 시 null 반환
|
||||||
public async Task<bool?> BossRaidAccesssAsync(List<string> userNames, int bossId)
|
public async Task<BossRaidResult?> BossRaidAccesssAsync(List<string> userNames, int bossId)
|
||||||
{
|
{
|
||||||
string url = AppConfig.RestApi.BaseUrl + "/api/internal/bossraid/entry";
|
string url = AppConfig.RestApi.BaseUrl + "/api/internal/bossraid/entry";
|
||||||
|
|
||||||
@@ -85,20 +85,31 @@ public class RestApi : Singleton<RestApi>
|
|||||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
{
|
{
|
||||||
Log.Warning("[RestApi] 보스 레이드 접속 인증 실패 (401)");
|
Log.Warning("[RestApi] 보스 레이드 접속 인증 실패 (401)");
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 400: 입장 조건 미충족 (레벨 부족, 이미 진행중 등)
|
// 400: 입장 조건 미충족 (레벨 부족, 이미 진행중 등)
|
||||||
if (response.StatusCode == HttpStatusCode.BadRequest)
|
if (response.StatusCode == HttpStatusCode.BadRequest)
|
||||||
{
|
{
|
||||||
Log.Warning("[RestApi] 보스 레이드 입장 거절 (400) BossId={BossId}", bossId);
|
Log.Warning("[RestApi] 보스 레이드 입장 거절 (400) BossId={BossId}", bossId);
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
BossRaidAccessResponse? result = await response.Content.ReadFromJsonAsync<BossRaidAccessResponse>();
|
BossRaidAccessResponse? raw = await response.Content.ReadFromJsonAsync<BossRaidAccessResponse>();
|
||||||
return result?.BossId > 0 ? true : false;
|
if (raw == null) return null;
|
||||||
|
|
||||||
|
// API 응답 → 도메인 모델 매핑
|
||||||
|
return new BossRaidResult
|
||||||
|
{
|
||||||
|
RoomId = raw.RoomId,
|
||||||
|
SessionName = raw.SessionName ?? string.Empty,
|
||||||
|
BossId = raw.BossId,
|
||||||
|
Players = raw.Players,
|
||||||
|
Status = raw.Status ?? string.Empty,
|
||||||
|
Tokens = raw.Tokens
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (attempt < MAX_RETRY)
|
catch (Exception ex) when (attempt < MAX_RETRY)
|
||||||
{
|
{
|
||||||
@@ -111,7 +122,7 @@ public class RestApi : Singleton<RestApi>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class BossRaidAccessResponse
|
private sealed class BossRaidAccessResponse
|
||||||
@@ -152,10 +163,10 @@ public class RestApi : Singleton<RestApi>
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonPropertyName("tokens")]
|
[JsonPropertyName("tokens")]
|
||||||
public Dictionary<string, string> Tokens
|
public string? Tokens
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1076,10 +1076,10 @@ public class GameServer : ServerBase
|
|||||||
userNames.Add(channel.GetPlayer(memberId).Nickname);
|
userNames.Add(channel.GetPlayer(memberId).Nickname);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool? result = await RestApi.Instance.BossRaidAccesssAsync(userNames, 1);
|
BossRaidResult? result = await RestApi.Instance.BossRaidAccesssAsync(userNames, 1);
|
||||||
|
|
||||||
// 입장 실패
|
// 입장 실패
|
||||||
if (result.Value == false)
|
if (result != null)
|
||||||
{
|
{
|
||||||
SendTo(peer,
|
SendTo(peer,
|
||||||
PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
||||||
@@ -1087,6 +1087,7 @@ public class GameServer : ServerBase
|
|||||||
|
|
||||||
Log.Debug("[GameServer] INTO_BOSS_RAID HashKey={Key} PartyId={PartyId} AssignedRaidMapId={RaidId} Failed", hashKey,
|
Log.Debug("[GameServer] INTO_BOSS_RAID HashKey={Key} PartyId={PartyId} AssignedRaidMapId={RaidId} Failed", hashKey,
|
||||||
party.PartyId, -1);
|
party.PartyId, -1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 레이드 맵 할당 (미사용 맵 탐색 → 없으면 동적 생성)
|
// 레이드 맵 할당 (미사용 맵 탐색 → 없으면 동적 생성)
|
||||||
@@ -1146,7 +1147,8 @@ public class GameServer : ServerBase
|
|||||||
// 파티장에게 입장 성공 응답 (할당된 실제 레이드 맵 ID 전달)
|
// 파티장에게 입장 성공 응답 (할당된 실제 레이드 맵 ID 전달)
|
||||||
SendTo(peer,
|
SendTo(peer,
|
||||||
PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
PacketSerializer.Serialize((ushort)PacketCode.INTO_BOSS_RAID,
|
||||||
new IntoBossRaidPacket { RaidId = assignedRaidMapId, IsSuccess = true }));
|
new IntoBossRaidPacket
|
||||||
|
{ RaidId = assignedRaidMapId, IsSuccess = true, Session = result.SessionName, Token = result.Tokens }));
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -769,6 +769,20 @@ public class IntoBossRaidPacket
|
|||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ProtoMember(3)]
|
||||||
|
public string Token
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ProtoMember(4)]
|
||||||
|
public string Session
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PARTY_CHANGE_MAP (클라 -> 서버 전용)
|
// PARTY_CHANGE_MAP (클라 -> 서버 전용)
|
||||||
|
|||||||
Reference in New Issue
Block a user