feat : 코드 단락 정리
This commit is contained in:
@@ -9,10 +9,9 @@ namespace MMOserver.Api;
|
||||
|
||||
public class RestApi : Singleton<RestApi>
|
||||
{
|
||||
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<RestApi>
|
||||
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<BossRaidResult?> BossRaidAccessAsync(List<string> userNames, int bossId)
|
||||
@@ -153,7 +100,7 @@ public class RestApi : Singleton<RestApi>
|
||||
{
|
||||
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<RestApi>
|
||||
{
|
||||
string url = AppConfig.RestApi.BaseUrl + "/api/internal/player/save?username=" + Uri.EscapeDataString(username);
|
||||
|
||||
var body = new Dictionary<string, object?>();
|
||||
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<string, object?> 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<RestApi>
|
||||
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")]
|
||||
|
||||
Reference in New Issue
Block a user