fix : 서버 설정파일 빼기 작업

This commit is contained in:
qornwh1
2026-03-16 11:14:38 +09:00
parent f6067047d9
commit f2bc3d7924
6 changed files with 100 additions and 23 deletions

View File

@@ -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

View File

@@ -0,0 +1,62 @@
using Microsoft.Extensions.Configuration;
namespace MMOserver.Config;
public static class AppConfig
{
public static ServerConfig Server
{
get;
private set;
} = null!;
public static RestApiConfig RestApi
{
get;
private set;
} = null!;
public static void Initialize(IConfiguration config)
{
Server = new ServerConfig(config.GetSection("Server"));
RestApi = new RestApiConfig(config.GetSection("RestApi"));
}
}
public sealed class ServerConfig
{
public int Port
{
get;
}
public ServerConfig(IConfigurationSection section)
{
Port = int.Parse(section["Port"] ?? throw new InvalidOperationException("Server:Port is required in config.json"));
}
}
public sealed class RestApiConfig
{
public string BaseUrl
{
get;
}
public string VerifyToken
{
get;
}
public string ApiKey
{
get;
}
public RestApiConfig(IConfigurationSection section)
{
BaseUrl = section["BaseUrl"] ?? throw new InvalidOperationException("RestApi:BaseUrl is required in config.json");
VerifyToken = section["VerifyToken"] ?? throw new InvalidOperationException("RestApi:BaseUrl is required in config.json");
ApiKey = section["ApiKey"] ?? throw new InvalidOperationException("RestApi:ApiKey is required in config.json");
}
}

View File

@@ -457,7 +457,7 @@ public class GameServer : ServerBase
newParty.DeepCopySemi(preParty);
// 최대 인원 체크
if (newChannel.UserCount + newParty.PartyMemberIds.Count >= newChannel.UserCountMax)
if (newChannel.UserCount + preParty.PartyMemberIds.Count >= newChannel.UserCountMax)
{
Log.Warning("[GameServer] INTO_CHANNEL_PARTY 채널 인원 초과 HashKey={Key} ChannelId={ChannelId} UserCount={Count}/{Max}",
hashKey, packet.ChannelId, newChannel.UserCount, newChannel.UserCountMax);
@@ -497,8 +497,9 @@ public class GameServer : ServerBase
Type = PartyUpdateType.DELETE,
LeaderId = preParty.LeaderId,
};
BroadcastToChannel(preChannelId,
PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify)); // 채널 전체 파티 목록 갱신
// 채널 전체 파티 목록 갱신
BroadcastToChannel(preChannelId, PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, notify));
// 새로운 채널에 파티원 넣기
foreach (int memberId in newParty.PartyMemberIds)
@@ -525,17 +526,22 @@ public class GameServer : ServerBase
}
// 새로운 채널에 파티를 추가한다.
newChannel.GetPartyManager().CreateParty(newParty.LeaderId, newParty.PartyName, out newParty, newParty.PartyMemberIds);
// 새 채널 기존 유저들에게 파티 생성 알림
UpdatePartyPacket createNotify = new UpdatePartyPacket
if (newChannel.GetPartyManager().CreateParty(newParty.LeaderId, newParty.PartyName, out PartyInfo? createdParty, newParty.PartyMemberIds) && createdParty != null)
{
PartyId = newParty.PartyId,
Type = PartyUpdateType.CREATE,
LeaderId = newParty.LeaderId,
PartyName = newParty.PartyName,
};
BroadcastToChannel(packet.ChannelId, PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, createNotify));
// 새 채널 기존 유저들에게 파티 생성 알림
UpdatePartyPacket createNotify = new UpdatePartyPacket
{
PartyId = createdParty.PartyId,
Type = PartyUpdateType.CREATE,
LeaderId = createdParty.LeaderId,
PartyName = createdParty.PartyName,
};
BroadcastToChannel(packet.ChannelId, PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, createNotify));
}
else
{
Log.Warning("[GameServer] 파티생성 실패 !!!");
}
}
private void OnExitChannel(NetPeer peer, int hashKey, byte[] payload)
@@ -688,7 +694,7 @@ public class GameServer : ServerBase
}
case PartyUpdateType.LEAVE:
{
if (!pm.LeaveParty(hashKey, out PartyInfo? party))
if (!pm.LeaveParty(hashKey, out PartyInfo? party) || party == null)
{
SendError(peer, ErrorCode.PARTY_NOT_IN_PARTY);
return;
@@ -696,7 +702,7 @@ public class GameServer : ServerBase
UpdatePartyPacket notify = new UpdatePartyPacket
{
PartyId = party.PartyId, Type = PartyUpdateType.DELETE, LeaderId = party?.LeaderId ?? 0, PlayerId = hashKey,
PartyId = party.PartyId, Type = PartyUpdateType.DELETE, LeaderId = party.LeaderId, PlayerId = hashKey,
};
// 파티가 남아있으면 살린다.

View File

@@ -15,10 +15,9 @@ public class PartyManager
// 파티 생성
public bool CreateParty(int leaderId, string partyName, out PartyInfo? party, List<int>? memeberIds = null)
{
party = null;
if (playerPartyMap.ContainsKey(leaderId))
{
party = null;
return false; // 이미 파티에 속해있음
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration;
using MMOserver.Config;
using MMOserver.Game;
using MMOserver.RDB;
using Serilog;
@@ -21,6 +22,8 @@ class Program
.AddEnvironmentVariables() // 도커 배포용
.Build();
AppConfig.Initialize(config);
// DB 연결
// DbConnectionFactory dbFactory = new DbConnectionFactory(config);
@@ -34,7 +37,7 @@ class Program
Log.Information("Write Log Started");
int port = 9500;
int port = AppConfig.Server.Port;
string connectionString = "test";
GameServer gameServer = new GameServer(port, connectionString);

View File

@@ -1,4 +1,12 @@
{
{
"Server": {
"Port": 9500
},
"RestApi": {
"BaseUrl": "https://a301.api.tolelom.xyz",
"VerifyToken": "/api/internal/auth/verify",
"ApiKey": "017f15b28143fc67d2e5bed283c37d2da858b9f294990a5334238e055e3f5425"
},
"Database": {
"Host": "localhost",
"Port": "0000",