Browse Source

Reconnection partially works

nordsoft 3 years ago
parent
commit
16a5414247

+ 24 - 7
client/CServerHandler.cpp

@@ -562,6 +562,13 @@ void CServerHandler::startGameplay(CGameState * gameState)
 		saveSession->Bool() = true;
 		saveSession->Bool() = true;
 		Settings saveUuid = settings.write["server"]["uuid"];
 		Settings saveUuid = settings.write["server"]["uuid"];
 		saveUuid->String() = 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()
 void CServerHandler::restoreLastSession()
 {
 {
-	std::vector<std::string> 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)
 void CServerHandler::debugStartTest(std::string filename, bool save)

+ 5 - 4
client/NetPacksClient.cpp

@@ -356,13 +356,14 @@ void PlayerReinitInterface::applyCl(CClient * cl)
 		if(cl->gameState()->currentPlayer == player)
 		if(cl->gameState()->currentPlayer == player)
 			callOnlyThatInterface(cl, player, &CGameInterface::yourTurn);
 			callOnlyThatInterface(cl, player, &CGameInterface::yourTurn);
 	}
 	}
-	else
+	else if(playerConnectionId == CSH->c->connectionID)
 	{
 	{
 		plSettings.connectedPlayerIDs.insert(playerConnectionId);
 		plSettings.connectedPlayerIDs.insert(playerConnectionId);
+		cl->playerint.clear();
 		cl->initPlayerInterfaces();
 		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);
 	}
 	}
 }
 }
 
 

+ 10 - 1
config/schemas/settings.json

@@ -253,7 +253,7 @@
 			"type" : "object",
 			"type" : "object",
 			"additionalProperties" : false,
 			"additionalProperties" : false,
 			"default": {},
 			"default": {},
-			"required" : [ "server", "port", "localInformation", "playerAI", "friendlyAI","neutralAI", "enemyAI", "reconnect", "uuid" ],
+			"required" : [ "server", "port", "localInformation", "playerAI", "friendlyAI","neutralAI", "enemyAI", "reconnect", "uuid", "names" ],
 			"properties" : {
 			"properties" : {
 				"server" : {
 				"server" : {
 					"type":"string",
 					"type":"string",
@@ -290,6 +290,15 @@
 				"uuid" : {
 				"uuid" : {
 					"type" : "string",
 					"type" : "string",
 					"default" : ""
 					"default" : ""
+				},
+				"names" : {
+					"type" : "array",
+					"default" : {},
+					"items":
+					{
+						"type" : "string",
+						"default" : ""
+					}
 				}
 				}
 			}
 			}
 		},
 		},

+ 0 - 3
lib/NetPacksLib.cpp

@@ -369,9 +369,6 @@ DLL_LINKAGE void PlayerReinitInterface::applyGs(CGameState *gs)
 {
 {
 	if(!gs || !gs->scenarioOps)
 	if(!gs || !gs->scenarioOps)
 		return;
 		return;
-	
-	gs->currentPlayer = player;
-	
 	//auto & playerState = gs->players[player];
 	//auto & playerState = gs->players[player];
 	//playerState.daysWithoutCastle = daysWithoutCastle;
 	//playerState.daysWithoutCastle = daysWithoutCastle;
 	
 	

+ 4 - 1
server/CVCMIServer.cpp

@@ -466,7 +466,8 @@ bool CVCMIServer::passHost(int toConnectionId)
 
 
 void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & names, std::string uuid, StartInfo::EMode mode)
 void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & names, std::string uuid, StartInfo::EMode mode)
 {
 {
-	c->connectionID = currentClientId++;
+	if(state == EServerState::LOBBY)
+		c->connectionID = currentClientId++;
 
 
 	if(!hostClient)
 	if(!hostClient)
 	{
 	{
@@ -476,6 +477,8 @@ void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<st
 	}
 	}
 
 
 	logNetwork->info("Connection with client %d established. UUID: %s", c->connectionID, c->uuid);
 	logNetwork->info("Connection with client %d established. UUID: %s", c->connectionID, c->uuid);
+	
+	if(state == EServerState::LOBBY)
 	for(auto & name : names)
 	for(auto & name : names)
 	{
 	{
 		logNetwork->info("Client %d player: %s", c->connectionID, name);
 		logNetwork->info("Client %d player: %s", c->connectionID, name);