mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-28 01:04:50 +01:00
remove user from users.json when kicked (#11)
This commit is contained in:
committed by
Michał Janiszewski
parent
f08f2bef2c
commit
1b3331f584
@@ -42,6 +42,7 @@ NetworkUser * NetworkUser::FromJson(json_t * json)
|
||||
if (!json_is_null(jsonGroupId)) {
|
||||
user->GroupId = (uint8)json_integer_value(jsonGroupId);
|
||||
}
|
||||
user->Remove = false;
|
||||
return user;
|
||||
}
|
||||
return user;
|
||||
@@ -137,8 +138,19 @@ void NetworkUserManager::Save()
|
||||
{
|
||||
auto hashString = std::string(hash);
|
||||
const NetworkUser * networkUser = GetUserByHash(hashString);
|
||||
networkUser->ToJson(jsonUser);
|
||||
savedHashes.insert(hashString);
|
||||
if (networkUser != nullptr)
|
||||
{
|
||||
if (networkUser->Remove)
|
||||
{
|
||||
json_array_remove(jsonUsers, i);
|
||||
i--;
|
||||
}
|
||||
else
|
||||
{
|
||||
networkUser->ToJson(jsonUser);
|
||||
savedHashes.insert(hashString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +158,7 @@ void NetworkUserManager::Save()
|
||||
for (const auto &kvp : _usersByHash)
|
||||
{
|
||||
const NetworkUser * networkUser = kvp.second;
|
||||
if (savedHashes.find(networkUser->Hash) == savedHashes.end())
|
||||
if (!networkUser->Remove && savedHashes.find(networkUser->Hash) == savedHashes.end())
|
||||
{
|
||||
json_t * jsonUser = networkUser->ToJson();
|
||||
json_array_append_new(jsonUsers, jsonUser);
|
||||
@@ -170,6 +182,11 @@ void NetworkUserManager::UnsetUsersOfGroup(uint8 groupId)
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkUserManager::RemoveUser(const std::string &hash)
|
||||
{
|
||||
_usersByHash[hash]->Remove = true;
|
||||
}
|
||||
|
||||
NetworkUser * NetworkUserManager::GetUserByHash(const std::string &hash)
|
||||
{
|
||||
auto it = _usersByHash.find(hash);
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
std::string Hash;
|
||||
std::string Name;
|
||||
Nullable<uint8> GroupId;
|
||||
bool Remove;
|
||||
|
||||
static NetworkUser * FromJson(json_t * json);
|
||||
|
||||
@@ -52,6 +53,8 @@ public:
|
||||
void Save();
|
||||
|
||||
void UnsetUsersOfGroup(uint8 groupId);
|
||||
void RemoveUser(const std::string &hash);
|
||||
|
||||
NetworkUser * GetUserByHash(const std::string &hash);
|
||||
const NetworkUser * GetUserByHash(const std::string &hash) const;
|
||||
const NetworkUser * GetUserByName(const std::string &name) const;
|
||||
|
||||
@@ -2704,6 +2704,11 @@ void game_command_kick_player(int *eax, int *ebx, int *ecx, int *edx, int *esi,
|
||||
if (*ebx & GAME_COMMAND_FLAG_APPLY) {
|
||||
if (gNetwork.GetMode() == NETWORK_MODE_SERVER) {
|
||||
gNetwork.KickPlayer(playerid);
|
||||
|
||||
NetworkUserManager * networkUserManager = &gNetwork._userManager;
|
||||
networkUserManager->Load();
|
||||
networkUserManager->RemoveUser(player->keyhash);
|
||||
networkUserManager->Save();
|
||||
}
|
||||
}
|
||||
*ebx = 0;
|
||||
|
||||
Reference in New Issue
Block a user