OpenRCT2/src/openrct2/network/NetworkUser.h

62 lines
1.6 KiB
C
Raw Normal View History

/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include "../common.h"
#include "../core/Nullable.hpp"
#include <jansson.h>
#include <map>
#include <string>
class NetworkUser final
{
public:
2018-06-22 23:02:47 +02:00
std::string Hash;
std::string Name;
Nullable<uint8_t> GroupId;
bool Remove;
2018-06-22 23:02:47 +02:00
static NetworkUser* FromJson(json_t* json);
2018-06-22 23:02:47 +02:00
json_t* ToJson() const;
json_t* ToJson(json_t* json) const;
};
class NetworkUserManager final
{
public:
~NetworkUserManager();
void Load();
/**
* @brief NetworkUserManager::Save
* Reads mappings from JSON, updates them in-place and saves JSON.
*
* Useful for retaining custom entries in JSON file.
*/
void Save();
void UnsetUsersOfGroup(uint8_t groupId);
2018-06-22 23:02:47 +02:00
void RemoveUser(const std::string& hash);
2018-06-22 23:02:47 +02:00
NetworkUser* GetUserByHash(const std::string& hash);
const NetworkUser* GetUserByHash(const std::string& hash) const;
const NetworkUser* GetUserByName(const std::string& name) const;
NetworkUser* GetOrAddUser(const std::string& hash);
private:
std::map<std::string, NetworkUser*> _usersByHash;
void DisposeUsers();
2018-06-22 23:02:47 +02:00
static void GetStorePath(utf8* buffer, size_t bufferSize);
};