Files
a301_mmo_game_server/MMOTestServer/ServerLib/Service/Session.cs
tolelom 46dd92b27d feat: 보스레이드 연동 — 입장 요청, 토큰 검증, 결과 보고 API 추가
- RestApi에 보스레이드 입장/검증/시작/완료/실패 엔드포인트 추가
- GameServer에 보스레이드 흐름 처리 로직
- Player 모델에 보스레이드 상태 필드 추가
- 보스레이드 관련 패킷 정의

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 17:51:33 +09:00

83 lines
1.7 KiB
C#

using LiteNetLib;
namespace ServerLib.Service;
public class Session
{
public string? Token
{
get;
set;
}
public string? Username
{
get;
set;
}
public int HashKey
{
get;
init;
}
public NetPeer Peer
{
get;
set;
}
// ─── 패킷 레이트 리미팅 ───────────────────────────
private int packetCount;
private long windowStartTicks;
/// <summary>초당 허용 패킷 수</summary>
public int MaxPacketsPerSecond { get; set; }
/// <summary>연속 초과 횟수</summary>
public int RateLimitViolations { get; private set; }
/// <summary>
/// 패킷 수신 시 호출. 초당 제한 초과 시 true 반환.
/// </summary>
public bool CheckRateLimit()
{
long now = Environment.TickCount64;
// 1초(1000ms) 윈도우 초과 시 리셋
if (now - windowStartTicks >= 1000)
{
windowStartTicks = now;
packetCount = 0;
}
packetCount++;
if (packetCount > MaxPacketsPerSecond)
{
RateLimitViolations++;
return true; // 제한 초과
}
return false;
}
/// <summary>위반 카운트 초기화</summary>
public void ResetViolations()
{
RateLimitViolations = 0;
}
public Session(int hashKey, NetPeer peer, int maxPacketsPerSecond = 60)
{
HashKey = hashKey;
Peer = peer;
Token = null;
MaxPacketsPerSecond = maxPacketsPerSecond;
packetCount = 0;
windowStartTicks = Environment.TickCount64;
RateLimitViolations = 0;
}
}