Skip to content

Commit

Permalink
style: apply linter
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 7, 2024
1 parent f370cf7 commit bbcd3dc
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 98 deletions.
17 changes: 9 additions & 8 deletions Flakkari/Server/Game/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ void GameManager::listGames()

void GameManager::addClientToGame(std::string gameName, std::shared_ptr<Client> client)
{
if (_gamesStore.find(gameName) == _gamesStore.end()) {
if (_gamesStore.find(gameName) == _gamesStore.end())
{
FLAKKARI_LOG_ERROR("game not found");
client.reset();
return;
Expand Down Expand Up @@ -189,16 +190,15 @@ void GameManager::removeClientFromGame(std::string gameName, std::shared_ptr<Cli

auto minPlayers = _gamesStore[gameName]->at("minPlayers").get<size_t>();

for (auto &instance : _gamesInstances[gameName]) {
for (auto &instance : _gamesInstances[gameName])
{
if (!instance->removePlayer(client))
continue;

if (instance->getPlayers().empty()) {
if (instance->getPlayers().empty())
{
_gamesInstances[gameName].erase(
std::find(
_gamesInstances[gameName].begin(), _gamesInstances[gameName].end(), instance
)
);
std::find(_gamesInstances[gameName].begin(), _gamesInstances[gameName].end(), instance));
FLAKKARI_LOG_INFO("game \"" + gameName + "\" removed");
}
else if (instance->getPlayers().size() > minPlayers)
Expand Down Expand Up @@ -227,7 +227,8 @@ int GameManager::getIndexInWaitingQueue(std::string gameName, std::shared_ptr<Cl
return FLAKKARI_LOG_ERROR("game not found"), -1;

auto tmpQueue = _waitingClients[gameName];
for (int i = 0; !tmpQueue.empty(); i++) {
for (int i = 0; !tmpQueue.empty(); i++)
{
if (tmpQueue.front() == client)
return FLAKKARI_LOG_INFO("client \"" + STR_ADDRESS + "\" found in waiting queue at " + std::to_string(i)),
i;
Expand Down
173 changes: 87 additions & 86 deletions Flakkari/Server/Game/GameManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,101 +33,102 @@ namespace Flakkari {

class GameManager : public Singleton<GameManager> {
private:
std::unordered_map<std::string /*gameName*/, std::queue<std::shared_ptr<Client>> /*waitingClients*/> _waitingClients;
std::unordered_map<std::string /*gameName*/, std::vector<std::shared_ptr<Game>> /*gamesInstances*/> _gamesInstances;
std::unordered_map<std::string /*gameName*/, std::shared_ptr<nlohmann::json> /*data*/> _gamesStore;
std::string _game_dir;
std::unordered_map<std::string /*gameName*/, std::queue<std::shared_ptr<Client>> /*waitingClients*/>
_waitingClients;
std::unordered_map<std::string /*gameName*/, std::vector<std::shared_ptr<Game>> /*gamesInstances*/> _gamesInstances;
std::unordered_map<std::string /*gameName*/, std::shared_ptr<nlohmann::json> /*data*/> _gamesStore;
std::string _game_dir;

public:
/**
* @brief Construct a new GameManager object and load all games
* already present in the Games folder
*
*/
explicit GameManager();
/**
* @brief Construct a new GameManager object and load all games
* already present in the Games folder
*
*/
explicit GameManager();

/**
* @brief Destroy the GameManager object
*
*/
~GameManager() = default;

/**
* @brief Add a game to the GameManager and load it from the Games folder
*
* @param gameName Game to add
* @return 0 Game added
* @return 1 Game not added (already exists)
* @return 2 Game not added (certificate not valid) (not implemented)
* @return 3 Game not added (corrupted game) (not implemented)
*/
int addGame(std::string gameName);

/**
* @brief Get the Game object
*
* @param gameName Game to get
* @return std::shared_ptr<Game> Game
*
* @deprecated Use getGameInstance instead
*/
std::shared_ptr<Game> getGame(std::string gameName);

/**
* @brief Get the Games Instances object (all games loaded)
*
* @return std::vector<std::shared_ptr<Game>> Games Instances
*/
std::vector<std::shared_ptr<Game>> getGamesInstances();

/**
* @brief Update a game from the GameManager
*
* @param gameName Game to update
* @return 0 Game updated
* @return 1 Game not updated (not found)
*/
int updateGame(std::string gameName);

/**
* @brief Remove a game from the GameManager
*
* @param gameName Game to remove
* @return 0 Game removed
* @return 1 Game not removed (not found)
*/
int removeGame(std::string gameName);

/**
* @brief List all games present in the GameManager
*
*/
void listGames();

/**
* @brief Add a client to a game
*
* @param gameName Game to add the client to
* @param client Client to add to the game
*/
void addClientToGame(std::string gameName, std::shared_ptr<Client> client);

/**
* @brief Remove a client from a game
*
* @param gameName Game to remove the client from
* @param client Client to remove from the game
*/
void removeClientFromGame(std::string gameName, std::shared_ptr<Client> client);

/**
* @brief Get the index of a client in the waiting queue
*
* @param gameName Game to get the index from
* @param client Client to get the index of
* @return int Index of the client in the waiting queue
*/
int getIndexInWaitingQueue(std::string gameName, std::shared_ptr<Client> client);
/**
* @brief Add a game to the GameManager and load it from the Games folder
*
* @param gameName Game to add
* @return 0 Game added
* @return 1 Game not added (already exists)
* @return 2 Game not added (certificate not valid) (not implemented)
* @return 3 Game not added (corrupted game) (not implemented)
*/
int addGame(std::string gameName);

/**
* @brief Get the Game object
*
* @param gameName Game to get
* @return std::shared_ptr<Game> Game
*
* @deprecated Use getGameInstance instead
*/
std::shared_ptr<Game> getGame(std::string gameName);

/**
* @brief Get the Games Instances object (all games loaded)
*
* @return std::vector<std::shared_ptr<Game>> Games Instances
*/
std::vector<std::shared_ptr<Game>> getGamesInstances();

/**
* @brief Update a game from the GameManager
*
* @param gameName Game to update
* @return 0 Game updated
* @return 1 Game not updated (not found)
*/
int updateGame(std::string gameName);

/**
* @brief Remove a game from the GameManager
*
* @param gameName Game to remove
* @return 0 Game removed
* @return 1 Game not removed (not found)
*/
int removeGame(std::string gameName);

/**
* @brief List all games present in the GameManager
*
*/
void listGames();

/**
* @brief Add a client to a game
*
* @param gameName Game to add the client to
* @param client Client to add to the game
*/
void addClientToGame(std::string gameName, std::shared_ptr<Client> client);

/**
* @brief Remove a client from a game
*
* @param gameName Game to remove the client from
* @param client Client to remove from the game
*/
void removeClientFromGame(std::string gameName, std::shared_ptr<Client> client);

/**
* @brief Get the index of a client in the waiting queue
*
* @param gameName Game to get the index from
* @param client Client to get the index of
* @return int Index of the client in the waiting queue
*/
int getIndexInWaitingQueue(std::string gameName, std::shared_ptr<Client> client);
};

} /* namespace Flakkari */
Expand Down
12 changes: 8 additions & 4 deletions Flakkari/Server/Internals/CommandManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,29 @@ bool CommandManager::handleAdminCommand(const std::string &input)
return true;
}

if (std::regex_match(input, ADD_GAME_REGEX)) {
if (std::regex_match(input, ADD_GAME_REGEX))
{
GameManager::GetInstance().addGame(input.substr(8));
GameManager::UnlockInstance();
return true;
}

if (std::regex_match(input, UPDATE_GAME_REGEX)) {
if (std::regex_match(input, UPDATE_GAME_REGEX))
{
GameManager::GetInstance().updateGame(input.substr(11));
GameManager::UnlockInstance();
return true;
}

if (std::regex_match(input, REMOVE_GAME_REGEX)) {
if (std::regex_match(input, REMOVE_GAME_REGEX))
{
GameManager::GetInstance().removeGame(input.substr(11));
GameManager::UnlockInstance();
return true;
}

if (input == "listGames") {
if (input == "listGames")
{
GameManager::GetInstance().listGames();
GameManager::UnlockInstance();
return true;
Expand Down

0 comments on commit bbcd3dc

Please sign in to comment.