feat: 중복 로그인 방지 코드 추가
This commit is contained in:
parent
1d103d7f16
commit
17013f70f5
6 changed files with 102 additions and 7 deletions
|
|
@ -21,6 +21,26 @@ void SessionManager::Leave(std::shared_ptr<Session> session) {
|
|||
}
|
||||
}
|
||||
|
||||
bool SessionManager::TryJoin(std::shared_ptr<Session> session,
|
||||
const std::string &nickname) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
// 중복 체크
|
||||
for (const auto &existing : sessions_) {
|
||||
if (existing->GetNickname() == nickname) {
|
||||
Logger::Log("이미 접속 중인 유저 로그인 시도: ", nickname);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 중복이 없으면 닉네임 설정 후 추가
|
||||
session->SetNickname(nickname);
|
||||
sessions_.insert(session);
|
||||
Logger::Log("클라이언트[", nickname,
|
||||
"]가 입장했습니다. 총 세션 수: ", sessions_.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
void SessionManager::Broadcast(PacketHeader header,
|
||||
std::span<const uint8_t> body) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue