Skip to content

Commit

Permalink
CLIENT-MENU: Now users can know if they already create a server
Browse files Browse the repository at this point in the history
MINOR
  • Loading branch information
KitetsuK committed Nov 5, 2023
1 parent bccdb28 commit 06044ef
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
12 changes: 11 additions & 1 deletion assets/Json/createServer.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@
"y": 500
}
}
]
],
"errorMessage": {
"type": "text",
"color": "red",
"size": 2,
"text": "SERVER ALREADY CREATED",
"position" : {
"x": 3200,
"y": 8500
}
}
}

17 changes: 16 additions & 1 deletion src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Parallax.hpp"
#include "ResourcesManager.hpp"
#include "SelectLobbySystems.hpp"
#include "Menu.hpp"
#include "init.hpp"

namespace Menu {
Expand Down Expand Up @@ -187,7 +188,21 @@ namespace Menu {
{
auto arrInputBox = Registry::getInstance().getComponents<Types::InputBox>();
auto ids = Registry::getInstance().getEntitiesByComponents({typeid(Types::InputBox)});

static bool isExist = false;

if (Nitwork::NitworkClient::getInstance().serverAlreadyCreated() && !isExist) {
try {
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>(
ResourcesManager::getPathByJsonType(JsonType::CREATE_SERVER),
"errorMessage");
::Menu::MenuBuilder::getInstance().initMenuEntity(
jsonData);
} catch (std::runtime_error &err) {
Logger::warn(err.what());
}
isExist = true;
return;
}
for (auto id : ids) {
if (arrInputBox[id].name == "port") {
Nitwork::NitworkClient::getInstance().createForkedServer(arrInputBox[id].text);
Expand Down
8 changes: 8 additions & 0 deletions src/Nitwork/NitworkClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ namespace Nitwork {
addPacketToSend(packet);
}

bool NitworkClient::serverAlreadyCreated()
{
if (_serverPids.size() > 0) {
return true;
}
return (false);
}

void NitworkClient::createForkedServer(const std::string &port)
{
if (_serverPids.size() > 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/Nitwork/NitworkClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ namespace Nitwork {
void
addCreateLobbyMsg(const std::string &name, enum gameType_e gameType, unsigned int maxNbPlayer);

/**
* @brief Check if the server is created by the client
*/
bool serverAlreadyCreated();

/**
* @brief Create a server
* @param port port of the server
Expand Down

0 comments on commit 06044ef

Please sign in to comment.