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:
@@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using MMOserver.Config;
|
||||
using MMOserver.Utils;
|
||||
using Serilog;
|
||||
|
||||
@@ -8,8 +9,6 @@ namespace MMOserver.Api;
|
||||
|
||||
public class RestApi : Singleton<RestApi>
|
||||
{
|
||||
private const string VERIFY_URL = "https://a301.api.tolelom.xyz";
|
||||
private const string INTERNAL_API_KEY = "017f15b28143fc67d2e5bed283c37d2da858b9f294990a5334238e055e3f5425";
|
||||
private readonly HttpClient httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
|
||||
|
||||
private const int MAX_RETRY = 3;
|
||||
@@ -17,7 +16,7 @@ public class RestApi : Singleton<RestApi>
|
||||
|
||||
public RestApi()
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.Add("X-API-Key", INTERNAL_API_KEY);
|
||||
httpClient.DefaultRequestHeaders.Add("X-API-Key", AppConfig.RestApi.ApiKey);
|
||||
}
|
||||
|
||||
// 토큰 검증 - 성공 시 username 반환
|
||||
@@ -25,7 +24,7 @@ public class RestApi : Singleton<RestApi>
|
||||
// 타임아웃/네트워크 오류 → 최대 MAX_RETRY회 재시도 후 null 반환
|
||||
public async Task<string?> VerifyTokenAsync(string token)
|
||||
{
|
||||
string url = VERIFY_URL + "/api/internal/auth/verify";
|
||||
string url = AppConfig.RestApi.BaseUrl + AppConfig.RestApi.VerifyToken;
|
||||
for (int attempt = 1; attempt <= MAX_RETRY; attempt++)
|
||||
{
|
||||
try
|
||||
@@ -36,7 +35,7 @@ public class RestApi : Singleton<RestApi>
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
Log.Warning("[RestApi] 토큰 인증 실패 (401)");
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
@@ -57,7 +56,7 @@ public class RestApi : Singleton<RestApi>
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
// 플레이어 프로필 조회 - 성공 시 PlayerProfileResponse 반환
|
||||
@@ -131,4 +130,108 @@ public class RestApi : Singleton<RestApi>
|
||||
[JsonPropertyName("sprintMultiplier")]
|
||||
public double SprintMultiplier { get; set; }
|
||||
}
|
||||
|
||||
// 레이드 채널 접속 여부 체크
|
||||
// 성공 시 BossRaidResult 반환, 실패/거절 시 null 반환
|
||||
public async Task<BossRaidResult?> BossRaidAccesssAsync(List<string> userNames, int bossId)
|
||||
{
|
||||
string url = AppConfig.RestApi.BaseUrl + "/api/internal/bossraid/entry";
|
||||
|
||||
for (int attempt = 1; attempt <= MAX_RETRY; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await httpClient.PostAsJsonAsync(url, new { usernames = userNames, bossId });
|
||||
|
||||
// 401: API 키 인증 실패
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
Log.Warning("[RestApi] 보스 레이드 접속 인증 실패 (401)");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 400: 입장 조건 미충족 (레벨 부족, 이미 진행중 등)
|
||||
if (response.StatusCode == HttpStatusCode.BadRequest)
|
||||
{
|
||||
Log.Warning("[RestApi] 보스 레이드 입장 거절 (400) BossId={BossId}", bossId);
|
||||
return null;
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
BossRaidAccessResponse? raw = await response.Content.ReadFromJsonAsync<BossRaidAccessResponse>();
|
||||
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)
|
||||
{
|
||||
Log.Warning("[RestApi] 보스 레이드 통신 실패 (시도 {Attempt}/{Max}): {Message}", attempt, MAX_RETRY, ex.Message);
|
||||
await Task.Delay(RETRY_DELAY);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("[RestApi] 보스 레이드 최종 통신 실패 ({Max}회 시도): {Message}", MAX_RETRY, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private sealed class BossRaidAccessResponse
|
||||
{
|
||||
[JsonPropertyName("roomId")]
|
||||
public int RoomId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[JsonPropertyName("sessionName")]
|
||||
public string? SessionName
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[JsonPropertyName("bossId")]
|
||||
public int BossId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[JsonPropertyName("players")]
|
||||
public List<string> Players
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
|
||||
[JsonPropertyName("status")]
|
||||
public string? Status
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[JsonPropertyName("tokens")]
|
||||
public Dictionary<string, string>? Tokens
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user