Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/App/gameServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ void GameServer::start() {
}

void GameServer::stop() {
if (m_gameThread.joinable()) {
m_game.pushEvent(ShutdownEvent{});
}

m_server.stop();
m_game.unsubscribeState(this);

if (m_gameThread.joinable()) {
m_game.pushEvent(ShutdownEvent{});
m_gameThread.join();
}
m_players.clear();
}

void GameServer::onClientConnected(gameNet::SessionId sessionId, gameNet::Seat seat) {
Expand Down
1 change: 1 addition & 0 deletions src/App/include/app/sessionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SessionManager : public gameNet::IClientHandler {
void connect(const std::string& hostIp);
void host(unsigned boardSize);
void disconnect();
void shutdown();

// Setters
void tryPlace(unsigned x, unsigned y);
Expand Down
16 changes: 16 additions & 0 deletions src/App/sessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ void SessionManager::disconnect() {
m_eventHub.signal(AS_StateChange);
}

void SessionManager::shutdown() {
if (m_localServer) {
m_localServer->stop();
m_localServer.reset();
}
m_network.disconnect();

{
std::lock_guard<std::mutex> lock(m_stateMutex);
m_position.reset(9u);
m_expectedMessageId = 1u;
m_chatHistory.clear();
m_pendingChat.clear();
}
}


void SessionManager::tryPlace(unsigned x, unsigned y) {
m_network.send(gameNet::ClientPutStone{.c = {x, y}});
Expand Down
2 changes: 2 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
// Setup Window
setWindowTitle("Go Game");
setWindowFlags(windowFlags() | Qt::Tool | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_QuitOnClose, true);
buildLayout();
}

Expand Down Expand Up @@ -49,6 +50,7 @@ void MainWindow::openHostDialog() {
}

void MainWindow::closeEvent(QCloseEvent* event) {
m_game.shutdown();
QMainWindow::closeEvent(event);
}

Expand Down