-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathUserManager.h
More file actions
79 lines (60 loc) · 1.51 KB
/
UserManager.h
File metadata and controls
79 lines (60 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include <unordered_map>
#include "ErrorCode.h"
#include "User.h"
class UserManager
{
public:
UserManager() = default;
~UserManager() = default;
void Init(const INT32 maxUserCount_)
{
mMaxUserCnt = maxUserCount_;
mUserObjPool = std::vector<User*>(mMaxUserCnt);
for (auto i = 0; i < mMaxUserCnt; i++)
{
mUserObjPool[i] = new User();
mUserObjPool[i]->Init(i);
}
}
INT32 GetCurrentUserCnt() { return mCurrentUserCnt; }
INT32 GetMaxUserCnt() { return mMaxUserCnt; }
void IncreaseUserCnt() { mCurrentUserCnt++; }
void DecreaseUserCnt()
{
if (mCurrentUserCnt > 0)
{
mCurrentUserCnt--;
}
}
ERROR_CODE AddUser(char* userID_, int clientIndex_)
{
//TODO 최흥배 유저 중복 조사하기
auto user_idx = clientIndex_;
mUserObjPool[user_idx]->SetLogin(userID_);
mUserIDDictionary.insert(std::pair< char*, int>(userID_, clientIndex_));
return ERROR_CODE::NONE;
}
INT32 FindUserIndexByID(char* userID_)
{
if (auto res = mUserIDDictionary.find(userID_); res != mUserIDDictionary.end())
{
return (*res).second;
}
return -1;
}
void DeleteUserInfo(User* user_)
{
mUserIDDictionary.erase(user_->GetUserId());
user_->Clear();
}
User* GetUserByConnIdx(INT32 clientIndex_)
{
return mUserObjPool[clientIndex_];
}
private:
INT32 mMaxUserCnt = 0;
INT32 mCurrentUserCnt = 0;
std::vector<User*> mUserObjPool; //vector로
std::unordered_map<std::string, int> mUserIDDictionary;
};