2
0
Ivan Savenko 6 сар өмнө
parent
commit
508c54c23a

+ 0 - 1
client/CServerHandler.cpp

@@ -633,7 +633,6 @@ void CServerHandler::startGameplay(std::shared_ptr<CGameState> gameState)
 		throw std::runtime_error("Invalid mode");
 	}
 	// After everything initialized we can accept CPackToClient netpacks
-	logicConnection->setCallback(&client->gameState());
 	setState(EClientState::GAMEPLAY);
 }
 

+ 0 - 1
client/NetPacksLobbyClient.cpp

@@ -148,7 +148,6 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyPrepareStartGame(LobbyPrepareS
 {
 	handler.client = std::make_unique<CClient>();
 	handler.logicConnection->enterLobbyConnectionMode();
-	handler.logicConnection->setCallback(&handler.client->gameInfo());
 }
 
 void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)

+ 7 - 0
lib/serializer/BinaryDeserializer.h

@@ -135,6 +135,13 @@ private:
 		////that const cast is evil because it allows to implicitly overwrite const objects when deserializing
 		typedef typename std::remove_const_t<T> nonConstT;
 		auto & hlp = const_cast<nonConstT &>(data);
+
+		if constexpr(std::is_base_of_v<IGameInfoCallback, std::remove_pointer_t<nonConstT>>)
+		{
+			assert(cb == nullptr);
+			cb = &data;
+		}
+
 		hlp.serialize(*this);
 	}
 	template<typename T, typename std::enable_if_t<std::is_array_v<T>, int> = 0>

+ 2 - 2
lib/serializer/Connection.cpp

@@ -124,9 +124,9 @@ void CConnection::enterLobbyConnectionMode()
 	serializer->clear();
 }
 
-void CConnection::setCallback(IGameInfoCallback * cb)
+void CConnection::setCallback(IGameInfoCallback & cb)
 {
-	deserializer->cb = cb;
+	deserializer->cb = &cb;
 }
 
 void CConnection::setSerializationVersion(ESerializationVersion version)

+ 1 - 1
lib/serializer/Connection.h

@@ -50,7 +50,7 @@ public:
 	std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
 
 	void enterLobbyConnectionMode();
-	void setCallback(IGameInfoCallback * cb);
+	void setCallback(IGameInfoCallback & cb);
 	void setSerializationVersion(ESerializationVersion version);
 };
 

+ 1 - 0
lib/serializer/SerializerReflection.h

@@ -35,6 +35,7 @@ struct ClassObjectCreator<T, typename std::enable_if_t<std::is_base_of_v<GameCal
 	static T *invoke(IGameInfoCallback *cb)
 	{
 		static_assert(!std::is_abstract_v<T>, "Cannot call new upon abstract classes!");
+		assert(cb != nullptr);
 		return new T(cb);
 	}
 };

+ 3 - 4
server/CGameHandler.cpp

@@ -541,14 +541,13 @@ void CGameHandler::reinitScripting()
 
 void CGameHandler::init(StartInfo *si, Load::ProgressAccumulator & progressTracking)
 {
+	CMapService mapService;
+	gs = std::make_shared<CGameState>();
 	int requestedSeed = settings["server"]["seed"].Integer();
+	randomizer = std::make_unique<GameRandomizer>(*gs);
 	if (requestedSeed != 0)
 		randomizer->setSeed(requestedSeed);
 	logGlobal->info("Using random seed: %d", randomizer->getDefault().nextInt());
-
-	CMapService mapService;
-	gs = std::make_shared<CGameState>();
-	randomizer = std::make_unique<GameRandomizer>(*gs);
 	gs->preInit(LIBRARY);
 	logGlobal->info("Gamestate created!");
 	gs->init(&mapService, si, *randomizer, progressTracking);

+ 1 - 1
server/CVCMIServer.cpp

@@ -294,7 +294,7 @@ bool CVCMIServer::prepareToStartGame()
 void CVCMIServer::startGameImmediately()
 {
 	for(auto activeConnection : activeConnections)
-		activeConnection->setCallback(&gh->gameInfo());
+		activeConnection->setCallback(gh->gameInfo());
 
 	gh->start(si->mode == EStartMode::LOAD_GAME);
 	setState(EServerState::GAMEPLAY);

+ 1 - 1
server/NetPacksLobbyServer.cpp

@@ -241,7 +241,7 @@ void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyStartGame(LobbyStartGam
 		{
 			if(connection->connectionID == pack.clientId)
 			{
-				connection->setCallback(&srv.gh->gameInfo());
+				connection->setCallback(srv.gh->gameInfo());
 				srv.reconnectPlayer(pack.clientId);
 			}
 		}