Okay, the problem is I have another file where the game is created and when i press escape I want it to send a packets that say i have quit and want to delete the socket from the server file.
Here is a pice of code from where my game is created(the update method)
void main_multiplayergame::Update(sf::RenderWindow *window)
{
if (this->speech->speaking)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::R) && !this->enterKey)
{
this->speech->speaking = false;
}
}
else
{
if (!this->manager->Update(window))
{
return;
}
}
this->Healthbar->update(window);
this->Manabar->update(window);
this->Expbar->update(window);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
{
connected = 0;
saveSystem.x = this->manager->Get("main_guy")->getPosition().x + Entity::scroll.x;
saveSystem.y = this->manager->Get("main_guy")->getPosition().y + Entity::scroll.y;
saveSystem.Save();
coreState.SetState(new main_menu());
//////////// Here is it where i call the client function leave///////////
client->Leave();
}
}
So when i press esc I got to the main menu of the game. The leave funcktion is called from the client cpp
void Client::Leave()
{
sf::Packet leave;
leave << socket->Disconnected;
socket->send(leave);
if (socket->send(leave) != sf::Socket::Done)
{
std::cout << "error" << std::endl;
}
}
But the problem is that this pice of code never send because in the console it appers the "Error".
Because I want so the server file remove the client when i have press esc. Currently I need to close the whole appliction to leave the server.