mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-29 21:56:54 +02:00
multiplayer load changes
This commit is contained in:
parent
cfa6f46d62
commit
99a63c4bbd
@ -247,6 +247,8 @@ void CClient::loadGame(const std::string & fname, const bool server, const std::
|
||||
serv = sh.justConnectToServer(ipaddr,port=="" ? "3030" : port);
|
||||
|
||||
CStopWatch tmh;
|
||||
if(server)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(fname, EResType::CLIENT_SAVEGAME));
|
||||
@ -288,9 +290,24 @@ void CClient::loadGame(const std::string & fname, const bool server, const std::
|
||||
logGlobal->errorStream() << "Cannot load game " << fname << ". Error: " << e.what();
|
||||
throw; //obviously we cannot continue here
|
||||
}
|
||||
}
|
||||
|
||||
if(server)
|
||||
{
|
||||
serv = sh.connectToServer();
|
||||
(*serv) << *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*serv) >> *this;
|
||||
|
||||
const_cast<CGameInfo*>(CGI)->mh = new CMapHandler();
|
||||
CGI->mh->map = gs->map;
|
||||
logNetwork->infoStream() <<"Creating mapHandler: "<<tmh.getDiff();
|
||||
CGI->mh->init();
|
||||
pathInfo = make_unique<CPathsInfo>(getMapSize());
|
||||
logNetwork->infoStream() <<"Initializing mapHandler (together): "<<tmh.getDiff();
|
||||
}
|
||||
|
||||
if(player_==-1)
|
||||
player_ = player->getNum();
|
||||
@ -313,13 +330,13 @@ void CClient::loadGame(const std::string & fname, const bool server, const std::
|
||||
logNetwork->infoStream() << "Server opened savegame properly.";
|
||||
}
|
||||
|
||||
std::set<PlayerColor> clientPlayers;
|
||||
if(server)
|
||||
{
|
||||
*serv << ui32(gs->scenarioOps->playerInfos.size()+2-loadNumPlayers); //number of players + neutral
|
||||
for(auto & elem : gs->scenarioOps->playerInfos)
|
||||
if(!std::count(humanplayerindices.begin(),humanplayerindices.end(),elem.first.getNum()) || elem.first==player)
|
||||
{
|
||||
*serv << ui8(elem.first.getNum()); //players
|
||||
clientPlayers.insert(elem.first);
|
||||
if(elem.first!=player)
|
||||
{
|
||||
auto AiToGive = aiNameForPlayer(elem.second, false);
|
||||
@ -331,20 +348,21 @@ void CClient::loadGame(const std::string & fname, const bool server, const std::
|
||||
installNewPlayerInterface(make_shared<CPlayerInterface>(*player),*player);
|
||||
}
|
||||
}
|
||||
*serv << ui8(PlayerColor::NEUTRAL.getNum());
|
||||
clientPlayers.insert(PlayerColor::NEUTRAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*serv << ui32(1);
|
||||
*serv << ui8(player->getNum());
|
||||
clientPlayers.insert(*player);
|
||||
installNewPlayerInterface(make_shared<CPlayerInterface>(*player),*player);
|
||||
}
|
||||
|
||||
serv->enableStackSendingByID();
|
||||
serv->disableSmartPointerSerialization();
|
||||
(*serv) << clientPlayers;
|
||||
|
||||
logNetwork->infoStream() <<"Sent info to server: "<<tmh.getDiff();
|
||||
|
||||
serv->addStdVecItems(gs);
|
||||
serv->enableStackSendingByID();
|
||||
serv->disableSmartPointerSerialization();
|
||||
|
||||
loadNeutralBattleAI();
|
||||
|
||||
|
@ -32,6 +32,12 @@
|
||||
|
||||
#include "../lib/UnlockGuard.h"
|
||||
|
||||
#include "../client/Client.h"
|
||||
|
||||
extern template void CClient::serialize<COSer<CSaveFile>>( COSer<CSaveFile> &h, const int version );
|
||||
extern template void CClient::serialize<CISer<CConnection>>( CISer<CConnection> &h, const int version );
|
||||
extern template void CClient::serialize<COSer<CConnection>>( COSer<CConnection> &h, const int version );
|
||||
|
||||
#if defined(__GNUC__) && !defined (__MINGW32__) && !defined(VCMI_ANDROID)
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
@ -491,11 +497,13 @@ void CVCMIServer::loadGame()
|
||||
c << ui8(0);
|
||||
|
||||
CConnection* cc; //tcp::socket * ss;
|
||||
CClient client_in;
|
||||
for(int i=0; i<clients; i++)
|
||||
{
|
||||
if(!i)
|
||||
{
|
||||
cc = &c;
|
||||
(*cc) >> client_in;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -508,7 +516,7 @@ void CVCMIServer::loadGame()
|
||||
continue;
|
||||
}
|
||||
cc = new CConnection(s,NAME);
|
||||
cc->addStdVecItems(gh.gs);
|
||||
(*cc) << client_in;
|
||||
}
|
||||
gh.conns.insert(cc);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user