diff --git a/server/src/game/Game.cpp b/server/src/game/Game.cpp index 9ec8d5b..71ea342 100644 --- a/server/src/game/Game.cpp +++ b/server/src/game/Game.cpp @@ -1,9 +1,9 @@ +#include "Game.hpp" #include #include -#include "Game.hpp" +#include "Catan.hpp" #include "INetwork.hpp" #include "Logger.hpp" -#include "Catan.hpp" Game::Game() { @@ -218,7 +218,8 @@ bool Game::startGame(const Player &player) if (_selectedGame.length() == 0) { return false; } - if (std::find(_availableGameName.begin(), _availableGameName.end(), _selectedGame) == _availableGameName.end()) { + if (std::find(_availableGameName.begin(), _availableGameName.end(), _selectedGame) + == _availableGameName.end()) { return false; } if (player._peer->getId() != _keyOwner) { diff --git a/server/src/game/Game.hpp b/server/src/game/Game.hpp index 1d402a3..f53c2ff 100644 --- a/server/src/game/Game.hpp +++ b/server/src/game/Game.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include "INetwork.hpp" #include "IGame.hpp" +#include "INetwork.hpp" #include "Player.hpp" class Game { diff --git a/server/src/game/games/ConfigUI.cpp b/server/src/game/games/ConfigUI.cpp index 9b52af5..b066e45 100644 --- a/server/src/game/games/ConfigUI.cpp +++ b/server/src/game/games/ConfigUI.cpp @@ -1,14 +1,14 @@ +#include "ConfigUI.hpp" #include #include #include -#include "ConfigUI.hpp" #include "INetwork.hpp" #include "Logger.hpp" #include "PathResolver.hpp" -ConfigUI::ConfigUI(const std::string &identifier): - _identifier(identifier), - _filePath(PathResolver::resolve("assets/uiconf/" + identifier)) +ConfigUI::ConfigUI(const std::string &identifier) + : _identifier(identifier), + _filePath(PathResolver::resolve("assets/uiconf/" + identifier)) { std::ifstream file(_filePath); std::string all; @@ -24,12 +24,12 @@ ConfigUI::ConfigUI(const std::string &identifier): _fileChunk.push_back(bufferS); all = all + bufferS; } - _fileHash = std::hash{}(all); + _fileHash = std::hash {}(all); } void ConfigUI::addPeer(std::shared_ptr peer) { - _peers[peer->getId()] = peer; + _peers[peer->getId()] = peer; _peersState[peer->getId()] = ConfigState(); } @@ -47,34 +47,40 @@ void ConfigUI::update() } const auto messageType = message.at("type").template get(); if (messageType == "uiConfigHash") { - if (!message.contains("name") || !message.contains("hash") || !message.at("name").is_string() || !message.at("hash").is_string()) { + if (!message.contains("name") || !message.contains("hash") + || !message.at("name").is_string() || !message.at("hash").is_string()) { continue; } const auto name = message.at("name").template get(); const auto hash = message.at("hash").template get(); if (name != _identifier) { - network.send(pEer, { - {"type", "uiConfigHash"}, - {"name", _identifier}, + network.send( + pEer, + { + {"type", "uiConfigHash"}, + {"name", _identifier }, }); continue; } if (hash != _fileHash) { - pState._ok = false; - pState._nbChunk = _fileChunk.size(); + pState._ok = false; + pState._nbChunk = _fileChunk.size(); pState._currentChunk = -1; - pState._hashClient = ""; + pState._hashClient = ""; } else { pState._ok = true; Logger::debug("CONFIGUI: one client ok"); } } else if (messageType == "uiConfig") { - if (!message.contains("name") || !message.contains("nbChunk") || !message.at("name").is_string() || !message.at("nbChunk").is_number()) { + if (!message.contains("name") || !message.contains("nbChunk") + || !message.at("name").is_string() || !message.at("nbChunk").is_number()) { continue; } - network.send(pEer, { - {"type", "uiConfigHash"}, - {"name", _identifier}, + network.send( + pEer, + { + {"type", "uiConfigHash"}, + {"name", _identifier }, }); } } @@ -82,9 +88,11 @@ void ConfigUI::update() continue; } if (!pState._askedHash) { - network.send(_peers[key], { - {"type", "uiConfigHash"}, - {"name", _identifier}, + network.send( + _peers[key], + { + {"type", "uiConfigHash"}, + {"name", _identifier }, }); pState._askedHash = true; continue; @@ -99,12 +107,14 @@ void ConfigUI::update() if (pState._currentChunk == pState._nbChunk) { continue; } - network.send(pEer, { - {"type", "uiConfig"}, - {"name", _identifier}, - {"nbChunk", pState._nbChunk}, - {"chunkIndex", pState._currentChunk}, - {"data", _fileChunk[pState._currentChunk]}, + network.send( + pEer, + { + {"type", "uiConfig" }, + {"name", _identifier }, + {"nbChunk", pState._nbChunk }, + {"chunkIndex", pState._currentChunk }, + {"data", _fileChunk[pState._currentChunk]}, }); } return; diff --git a/server/src/game/games/ConfigUI.hpp b/server/src/game/games/ConfigUI.hpp index e9aca0f..6e988c9 100644 --- a/server/src/game/games/ConfigUI.hpp +++ b/server/src/game/games/ConfigUI.hpp @@ -13,12 +13,11 @@ class ConfigUI { void update(); private: - class ConfigState { public: - bool _askedHash = false; - bool _ok = false; - int _nbChunk = -1; + bool _askedHash = false; + bool _ok = false; + int _nbChunk = -1; int _currentChunk = -1; std::string _hashClient; }; diff --git a/server/src/game/games/IGame.hpp b/server/src/game/games/IGame.hpp index 2792afa..750d67e 100644 --- a/server/src/game/games/IGame.hpp +++ b/server/src/game/games/IGame.hpp @@ -1,13 +1,13 @@ #pragma once -#include #include +#include #include "Player.hpp" class IGame { public: - virtual ~IGame() = default; + virtual ~IGame() = default; virtual void init(std::unordered_map &players) = 0; - virtual void update() = 0; - virtual bool isFinished() = 0; + virtual void update() = 0; + virtual bool isFinished() = 0; }; diff --git a/server/src/game/games/catan/Catan.cpp b/server/src/game/games/catan/Catan.cpp index 1173489..ac5c373 100644 --- a/server/src/game/games/catan/Catan.cpp +++ b/server/src/game/games/catan/Catan.cpp @@ -2,14 +2,14 @@ #include #include "Logger.hpp" -Catan::Catan(): _players(_tmpPlayers) +Catan::Catan() : _players(_tmpPlayers) { Logger::debug("Catan game created"); } void Catan::init(std::unordered_map &players) { - _players = players; + _players = players; _configUi = std::make_unique("catan.json"); for (const auto &[key, pLayer] : _players) { _playersState[key] = PlayerState(); diff --git a/server/src/game/games/catan/Catan.hpp b/server/src/game/games/catan/Catan.hpp index 17e0867..e407ce9 100644 --- a/server/src/game/games/catan/Catan.hpp +++ b/server/src/game/games/catan/Catan.hpp @@ -1,7 +1,7 @@ #pragma once -#include "IGame.hpp" #include "ConfigUI.hpp" +#include "IGame.hpp" class Catan : public IGame { public: @@ -20,7 +20,7 @@ class Catan : public IGame { std::unordered_map _playersState; - bool _isFinished = false; + bool _isFinished = false; bool _allConfigOk = false; std::unique_ptr _configUi;