ソースを参照

Reconnection works

nordsoft 3 年 前
コミット
722acb2a1d
3 ファイル変更18 行追加3 行削除
  1. 1 0
      client/CServerHandler.cpp
  2. 3 2
      client/NetPacksClient.cpp
  3. 14 1
      server/CVCMIServer.cpp

+ 1 - 0
client/CServerHandler.cpp

@@ -563,6 +563,7 @@ void CServerHandler::startGameplay(CGameState * gameState)
 		Settings saveUuid = settings.write["server"]["uuid"];
 		saveUuid->String() = uuid;
 		Settings saveNames = settings.write["server"]["names"];
+		saveNames->Vector().clear();
 		for(auto & name : myNames)
 		{
 			JsonNode jsonName;

+ 3 - 2
client/NetPacksClient.cpp

@@ -353,8 +353,9 @@ void PlayerReinitInterface::applyCl(CClient * cl)
 		plSettings.connectedPlayerIDs.clear();
 		cl->initPlayerEnvironments();
 		cl->initPlayerInterfaces();
-		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);
 	}
 	else if(playerConnectionId == CSH->c->connectionID)
 	{

+ 14 - 1
server/CVCMIServer.cpp

@@ -327,10 +327,23 @@ void CVCMIServer::connectionAccepted(const boost::system::error_code & ec)
 			connections.insert(c);
 			c->handler = std::make_shared<boost::thread>(&CVCMIServer::threadHandleClient, this, c);
 			
-			if(!hangingConnections.empty())
+			if(!hangingConnections.empty() && gh)
 			{
+				//TODO: check client uuid
 				logNetwork->info("Reconnection player");
 				c->connectionID = (*hangingConnections.begin())->connectionID;
+				for(auto & playerConnection : gh->connections)
+				{
+					for(auto & existingConnection : playerConnection.second)
+					{
+						if(existingConnection == *hangingConnections.begin())
+						{
+							playerConnection.second.erase(existingConnection);
+							playerConnection.second.insert(c);
+							break;
+						}
+					}
+				}
 				//hangingConnections.clear();
 			}
 		}