fix : 서버 설정파일 빼기 작업
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using MMOserver.Config;
|
||||||
using MMOserver.Utils;
|
using MMOserver.Utils;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@@ -8,8 +9,6 @@ namespace MMOserver.Api;
|
|||||||
|
|
||||||
public class RestApi : Singleton<RestApi>
|
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 readonly HttpClient httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
|
||||||
|
|
||||||
private const int MAX_RETRY = 3;
|
private const int MAX_RETRY = 3;
|
||||||
@@ -17,7 +16,7 @@ public class RestApi : Singleton<RestApi>
|
|||||||
|
|
||||||
public RestApi()
|
public RestApi()
|
||||||
{
|
{
|
||||||
httpClient.DefaultRequestHeaders.Add("X-API-Key", INTERNAL_API_KEY);
|
httpClient.DefaultRequestHeaders.Add("X-API-Key", AppConfig.RestApi.ApiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 토큰 검증 - 성공 시 username 반환
|
// 토큰 검증 - 성공 시 username 반환
|
||||||
@@ -25,7 +24,7 @@ public class RestApi : Singleton<RestApi>
|
|||||||
// 타임아웃/네트워크 오류 → 최대 MAX_RETRY회 재시도 후 null 반환
|
// 타임아웃/네트워크 오류 → 최대 MAX_RETRY회 재시도 후 null 반환
|
||||||
public async Task<string?> VerifyTokenAsync(string token)
|
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++)
|
for (int attempt = 1; attempt <= MAX_RETRY; attempt++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
62
MMOTestServer/MMOserver/Config/AppConfig.cs
Normal file
62
MMOTestServer/MMOserver/Config/AppConfig.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -457,7 +457,7 @@ public class GameServer : ServerBase
|
|||||||
newParty.DeepCopySemi(preParty);
|
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}",
|
Log.Warning("[GameServer] INTO_CHANNEL_PARTY 채널 인원 초과 HashKey={Key} ChannelId={ChannelId} UserCount={Count}/{Max}",
|
||||||
hashKey, packet.ChannelId, newChannel.UserCount, newChannel.UserCountMax);
|
hashKey, packet.ChannelId, newChannel.UserCount, newChannel.UserCountMax);
|
||||||
@@ -497,8 +497,9 @@ public class GameServer : ServerBase
|
|||||||
Type = PartyUpdateType.DELETE,
|
Type = PartyUpdateType.DELETE,
|
||||||
LeaderId = preParty.LeaderId,
|
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)
|
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);
|
if (newChannel.GetPartyManager().CreateParty(newParty.LeaderId, newParty.PartyName, out PartyInfo? createdParty, newParty.PartyMemberIds) && createdParty != null)
|
||||||
|
|
||||||
// 새 채널 기존 유저들에게 파티 생성 알림
|
|
||||||
UpdatePartyPacket createNotify = new UpdatePartyPacket
|
|
||||||
{
|
{
|
||||||
PartyId = newParty.PartyId,
|
// 새 채널 기존 유저들에게 파티 생성 알림
|
||||||
Type = PartyUpdateType.CREATE,
|
UpdatePartyPacket createNotify = new UpdatePartyPacket
|
||||||
LeaderId = newParty.LeaderId,
|
{
|
||||||
PartyName = newParty.PartyName,
|
PartyId = createdParty.PartyId,
|
||||||
};
|
Type = PartyUpdateType.CREATE,
|
||||||
BroadcastToChannel(packet.ChannelId, PacketSerializer.Serialize<UpdatePartyPacket>((ushort)PacketCode.UPDATE_PARTY, createNotify));
|
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)
|
private void OnExitChannel(NetPeer peer, int hashKey, byte[] payload)
|
||||||
@@ -688,7 +694,7 @@ public class GameServer : ServerBase
|
|||||||
}
|
}
|
||||||
case PartyUpdateType.LEAVE:
|
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);
|
SendError(peer, ErrorCode.PARTY_NOT_IN_PARTY);
|
||||||
return;
|
return;
|
||||||
@@ -696,7 +702,7 @@ public class GameServer : ServerBase
|
|||||||
|
|
||||||
UpdatePartyPacket notify = new UpdatePartyPacket
|
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,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 파티가 남아있으면 살린다.
|
// 파티가 남아있으면 살린다.
|
||||||
|
|||||||
@@ -15,10 +15,9 @@ public class PartyManager
|
|||||||
// 파티 생성
|
// 파티 생성
|
||||||
public bool CreateParty(int leaderId, string partyName, out PartyInfo? party, List<int>? memeberIds = null)
|
public bool CreateParty(int leaderId, string partyName, out PartyInfo? party, List<int>? memeberIds = null)
|
||||||
{
|
{
|
||||||
party = null;
|
|
||||||
|
|
||||||
if (playerPartyMap.ContainsKey(leaderId))
|
if (playerPartyMap.ContainsKey(leaderId))
|
||||||
{
|
{
|
||||||
|
party = null;
|
||||||
return false; // 이미 파티에 속해있음
|
return false; // 이미 파티에 속해있음
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MMOserver.Config;
|
||||||
using MMOserver.Game;
|
using MMOserver.Game;
|
||||||
using MMOserver.RDB;
|
using MMOserver.RDB;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
@@ -21,6 +22,8 @@ class Program
|
|||||||
.AddEnvironmentVariables() // 도커 배포용
|
.AddEnvironmentVariables() // 도커 배포용
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
AppConfig.Initialize(config);
|
||||||
|
|
||||||
// DB 연결
|
// DB 연결
|
||||||
// DbConnectionFactory dbFactory = new DbConnectionFactory(config);
|
// DbConnectionFactory dbFactory = new DbConnectionFactory(config);
|
||||||
|
|
||||||
@@ -34,7 +37,7 @@ class Program
|
|||||||
|
|
||||||
Log.Information("Write Log Started");
|
Log.Information("Write Log Started");
|
||||||
|
|
||||||
int port = 9500;
|
int port = AppConfig.Server.Port;
|
||||||
string connectionString = "test";
|
string connectionString = "test";
|
||||||
GameServer gameServer = new GameServer(port, connectionString);
|
GameServer gameServer = new GameServer(port, connectionString);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
{
|
{
|
||||||
|
"Server": {
|
||||||
|
"Port": 9500
|
||||||
|
},
|
||||||
|
"RestApi": {
|
||||||
|
"BaseUrl": "https://a301.api.tolelom.xyz",
|
||||||
|
"VerifyToken": "/api/internal/auth/verify",
|
||||||
|
"ApiKey": "017f15b28143fc67d2e5bed283c37d2da858b9f294990a5334238e055e3f5425"
|
||||||
|
},
|
||||||
"Database": {
|
"Database": {
|
||||||
"Host": "localhost",
|
"Host": "localhost",
|
||||||
"Port": "0000",
|
"Port": "0000",
|
||||||
|
|||||||
Reference in New Issue
Block a user