From 0617e6a194dfd41126f76df6f7afb08a496aac88 Mon Sep 17 00:00:00 2001 From: qornwh1 Date: Mon, 30 Mar 2026 12:29:20 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=BD=94=EB=93=9C=20=EB=8B=A8?= =?UTF-8?q?=EB=9D=BD=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MMOTestServer/MMOserver/Api/RestApi.cs | 193 +++++++++++++++++-------- 1 file changed, 132 insertions(+), 61 deletions(-) diff --git a/MMOTestServer/MMOserver/Api/RestApi.cs b/MMOTestServer/MMOserver/Api/RestApi.cs index 22470b7..debc12e 100644 --- a/MMOTestServer/MMOserver/Api/RestApi.cs +++ b/MMOTestServer/MMOserver/Api/RestApi.cs @@ -9,10 +9,9 @@ namespace MMOserver.Api; public class RestApi : Singleton { - private readonly HttpClient httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5) }; - private const int MAX_RETRY = 3; private static readonly TimeSpan RETRY_DELAY = TimeSpan.FromSeconds(1); + private readonly HttpClient httpClient = new() { Timeout = TimeSpan.FromSeconds(5) }; public RestApi() { @@ -91,58 +90,6 @@ public class RestApi : Singleton return null; } - private sealed class AuthVerifyResponse - { - [JsonPropertyName("username")] - public string? Username - { - get; - set; - } - } - - public sealed class PlayerProfileResponse - { - [JsonPropertyName("nickname")] - public string Nickname { get; set; } = string.Empty; - - [JsonPropertyName("level")] - public int Level { get; set; } - - [JsonPropertyName("experience")] - public int Experience { get; set; } - - [JsonPropertyName("nextExp")] - public int NextExp { get; set; } - - [JsonPropertyName("maxHp")] - public double MaxHp { get; set; } - - [JsonPropertyName("maxMp")] - public double MaxMp { get; set; } - - [JsonPropertyName("attackPower")] - public double AttackPower { get; set; } - - [JsonPropertyName("attackRange")] - public double AttackRange { get; set; } - - [JsonPropertyName("sprintMultiplier")] - public double SprintMultiplier { get; set; } - - [JsonPropertyName("lastPosX")] - public double LastPosX { get; set; } - - [JsonPropertyName("lastPosY")] - public double LastPosY { get; set; } - - [JsonPropertyName("lastPosZ")] - public double LastPosZ { get; set; } - - [JsonPropertyName("lastRotY")] - public double LastRotY { get; set; } - } - // 레이드 채널 접속 여부 체크 // 성공 시 BossRaidResult 반환, 실패/거절 시 null 반환 public async Task BossRaidAccessAsync(List userNames, int bossId) @@ -153,7 +100,7 @@ public class RestApi : Singleton { try { - HttpResponseMessage response = await httpClient.PostAsJsonAsync(url, new { usernames = userNames, bossId = bossId }); + HttpResponseMessage response = await httpClient.PostAsJsonAsync(url, new { usernames = userNames, bossId }); // 401: API 키 인증 실패 if (response.StatusCode == HttpStatusCode.Unauthorized) @@ -210,12 +157,31 @@ public class RestApi : Singleton { string url = AppConfig.RestApi.BaseUrl + "/api/internal/player/save?username=" + Uri.EscapeDataString(username); - var body = new Dictionary(); - if (posX.HasValue) body["lastPosX"] = posX.Value; - if (posY.HasValue) body["lastPosY"] = posY.Value; - if (posZ.HasValue) body["lastPosZ"] = posZ.Value; - if (rotY.HasValue) body["lastRotY"] = rotY.Value; - if (playTimeDelta.HasValue) body["playTimeDelta"] = playTimeDelta.Value; + Dictionary body = new(); + if (posX.HasValue) + { + body["lastPosX"] = posX.Value; + } + + if (posY.HasValue) + { + body["lastPosY"] = posY.Value; + } + + if (posZ.HasValue) + { + body["lastPosZ"] = posZ.Value; + } + + if (rotY.HasValue) + { + body["lastRotY"] = rotY.Value; + } + + if (playTimeDelta.HasValue) + { + body["playTimeDelta"] = playTimeDelta.Value; + } for (int attempt = 1; attempt <= MAX_RETRY; attempt++) { @@ -235,9 +201,114 @@ public class RestApi : Singleton Log.Error("[RestApi] 게임 데이터 저장 최종 실패 ({Max}회 시도): {Message}", MAX_RETRY, ex.Message); } } + return false; } + private sealed class AuthVerifyResponse + { + [JsonPropertyName("username")] + public string? Username + { + get; + set; + } + } + + public sealed class PlayerProfileResponse + { + [JsonPropertyName("nickname")] + public string Nickname + { + get; + set; + } = string.Empty; + + [JsonPropertyName("level")] + public int Level + { + get; + set; + } + + [JsonPropertyName("experience")] + public int Experience + { + get; + set; + } + + [JsonPropertyName("nextExp")] + public int NextExp + { + get; + set; + } + + [JsonPropertyName("maxHp")] + public double MaxHp + { + get; + set; + } + + [JsonPropertyName("maxMp")] + public double MaxMp + { + get; + set; + } + + [JsonPropertyName("attackPower")] + public double AttackPower + { + get; + set; + } + + [JsonPropertyName("attackRange")] + public double AttackRange + { + get; + set; + } + + [JsonPropertyName("sprintMultiplier")] + public double SprintMultiplier + { + get; + set; + } + + [JsonPropertyName("lastPosX")] + public double LastPosX + { + get; + set; + } + + [JsonPropertyName("lastPosY")] + public double LastPosY + { + get; + set; + } + + [JsonPropertyName("lastPosZ")] + public double LastPosZ + { + get; + set; + } + + [JsonPropertyName("lastRotY")] + public double LastRotY + { + get; + set; + } + } + private sealed class BossRaidAccessResponse { [JsonPropertyName("roomId")]