diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index a22c62bdf..fe7b54088 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -562,6 +562,13 @@ void CServerHandler::startGameplay(CGameState * gameState) saveSession->Bool() = true; Settings saveUuid = settings.write["server"]["uuid"]; saveUuid->String() = uuid; + Settings saveNames = settings.write["server"]["names"]; + for(auto & name : myNames) + { + JsonNode jsonName; + jsonName.String() = name; + saveNames->Vector().push_back(jsonName); + } } } @@ -649,13 +656,23 @@ ui8 CServerHandler::getLoadMode() void CServerHandler::restoreLastSession() { - std::vector nm{"stub"}; - resetStateForLobby(StartInfo::LOAD_GAME, &nm); - screenType = ESelectionScreen::loadGame; - justConnectToServer("127.0.0.1", 3030); - //c->disableSmartVectorMemberSerialization(); - //c->disableSmartPointerSerialization(); - //c->disableStackSendingByID(); + auto loadSession = [this]() + { + for(auto & name : settings["server"]["names"].Vector()) + myNames.push_back(name.String()); + resetStateForLobby(StartInfo::LOAD_GAME, &myNames); + screenType = ESelectionScreen::loadGame; + justConnectToServer("127.0.0.1", 3030); + }; + + auto cleanUpSession = []() + { + //reset settings + Settings saveSession = settings.write["server"]["reconnect"]; + saveSession->Bool() = false; + }; + + CInfoWindow::showYesNoDialog("Connect to the last session?", {}, loadSession, cleanUpSession); } void CServerHandler::debugStartTest(std::string filename, bool save) diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 8172cde2f..78887e477 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -356,13 +356,14 @@ void PlayerReinitInterface::applyCl(CClient * cl) if(cl->gameState()->currentPlayer == player) callOnlyThatInterface(cl, player, &CGameInterface::yourTurn); } - else + else if(playerConnectionId == CSH->c->connectionID) { plSettings.connectedPlayerIDs.insert(playerConnectionId); + cl->playerint.clear(); cl->initPlayerInterfaces(); - callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, player); - //if(cl->gameState()->currentPlayer == player) - callOnlyThatInterface(cl, player, &CGameInterface::yourTurn); + auto currentPlayer = cl->gameState()->currentPlayer; + callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, currentPlayer); + callOnlyThatInterface(cl, currentPlayer, &CGameInterface::yourTurn); } } diff --git a/config/schemas/settings.json b/config/schemas/settings.json index 86b3f7e64..f81d5bc6a 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -253,7 +253,7 @@ "type" : "object", "additionalProperties" : false, "default": {}, - "required" : [ "server", "port", "localInformation", "playerAI", "friendlyAI","neutralAI", "enemyAI", "reconnect", "uuid" ], + "required" : [ "server", "port", "localInformation", "playerAI", "friendlyAI","neutralAI", "enemyAI", "reconnect", "uuid", "names" ], "properties" : { "server" : { "type":"string", @@ -290,6 +290,15 @@ "uuid" : { "type" : "string", "default" : "" + }, + "names" : { + "type" : "array", + "default" : {}, + "items": + { + "type" : "string", + "default" : "" + } } } }, diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 9d7b2f2f1..9772f227e 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -369,9 +369,6 @@ DLL_LINKAGE void PlayerReinitInterface::applyGs(CGameState *gs) { if(!gs || !gs->scenarioOps) return; - - gs->currentPlayer = player; - //auto & playerState = gs->players[player]; //playerState.daysWithoutCastle = daysWithoutCastle; diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 949a75c6e..1feb77266 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -466,7 +466,8 @@ bool CVCMIServer::passHost(int toConnectionId) void CVCMIServer::clientConnected(std::shared_ptr c, std::vector & names, std::string uuid, StartInfo::EMode mode) { - c->connectionID = currentClientId++; + if(state == EServerState::LOBBY) + c->connectionID = currentClientId++; if(!hostClient) { @@ -476,6 +477,8 @@ void CVCMIServer::clientConnected(std::shared_ptr c, std::vectorinfo("Connection with client %d established. UUID: %s", c->connectionID, c->uuid); + + if(state == EServerState::LOBBY) for(auto & name : names) { logNetwork->info("Client %d player: %s", c->connectionID, name);