mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-20 20:23:03 +02:00
Replaced unique_ptr with simple references to packs
This commit is contained in:
parent
2399a5a765
commit
cc6d6b0d63
@ -49,7 +49,7 @@ public:
|
||||
|
||||
void visitForLobby(CPackForLobby & packForLobby) override
|
||||
{
|
||||
handler.handleReceivedPack(std::unique_ptr<CPackForLobby>(&packForLobby));
|
||||
handler.handleReceivedPack(packForLobby);
|
||||
}
|
||||
|
||||
void visitForServer(CPackForServer & serverPack) override
|
||||
@ -231,9 +231,9 @@ bool CVCMIServer::prepareToStartGame()
|
||||
{
|
||||
//FIXME: UNGUARDED MULTITHREADED ACCESS!!!
|
||||
currentProgress = progressTracking.get();
|
||||
std::unique_ptr<LobbyLoadProgress> loadProgress(new LobbyLoadProgress);
|
||||
loadProgress->progress = currentProgress;
|
||||
announcePack(std::move(loadProgress));
|
||||
LobbyLoadProgress loadProgress;
|
||||
loadProgress.progress = currentProgress;
|
||||
announcePack(loadProgress);
|
||||
}
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
}
|
||||
@ -305,29 +305,29 @@ void CVCMIServer::onDisconnected(const std::shared_ptr<INetworkConnection> & con
|
||||
|
||||
if(gh && getState() == EServerState::GAMEPLAY)
|
||||
{
|
||||
auto lcd = std::make_unique<LobbyClientDisconnected>();
|
||||
lcd->c = c;
|
||||
lcd->clientId = c->connectionID;
|
||||
handleReceivedPack(std::move(lcd));
|
||||
LobbyClientDisconnected lcd;
|
||||
lcd.c = c;
|
||||
lcd.clientId = c->connectionID;
|
||||
handleReceivedPack(lcd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CVCMIServer::handleReceivedPack(std::unique_ptr<CPackForLobby> pack)
|
||||
void CVCMIServer::handleReceivedPack(CPackForLobby & pack)
|
||||
{
|
||||
ClientPermissionsCheckerNetPackVisitor checker(*this);
|
||||
pack->visit(checker);
|
||||
pack.visit(checker);
|
||||
|
||||
if(checker.getResult())
|
||||
{
|
||||
ApplyOnServerNetPackVisitor applier(*this);
|
||||
pack->visit(applier);
|
||||
pack.visit(applier);
|
||||
if (applier.getResult())
|
||||
announcePack(std::move(pack));
|
||||
announcePack(pack);
|
||||
}
|
||||
}
|
||||
|
||||
void CVCMIServer::announcePack(std::unique_ptr<CPackForLobby> pack)
|
||||
void CVCMIServer::announcePack(CPackForLobby & pack)
|
||||
{
|
||||
for(auto activeConnection : activeConnections)
|
||||
{
|
||||
@ -335,19 +335,19 @@ void CVCMIServer::announcePack(std::unique_ptr<CPackForLobby> pack)
|
||||
// Until UUID set we only pass LobbyClientConnected to this client
|
||||
//if(c->uuid == uuid && !dynamic_cast<LobbyClientConnected *>(pack.get()))
|
||||
// continue;
|
||||
activeConnection->sendPack(pack.get());
|
||||
activeConnection->sendPack(pack);
|
||||
}
|
||||
|
||||
ApplyOnServerAfterAnnounceNetPackVisitor applier(*this);
|
||||
pack->visit(applier);
|
||||
pack.visit(applier);
|
||||
}
|
||||
|
||||
void CVCMIServer::announceMessage(const MetaString & txt)
|
||||
{
|
||||
logNetwork->info("Show message: %s", txt.toString());
|
||||
auto cm = std::make_unique<LobbyShowMessage>();
|
||||
cm->message = txt;
|
||||
announcePack(std::move(cm));
|
||||
LobbyShowMessage cm;
|
||||
cm.message = txt;
|
||||
announcePack(cm);
|
||||
}
|
||||
|
||||
void CVCMIServer::announceMessage(const std::string & txt)
|
||||
@ -360,10 +360,10 @@ void CVCMIServer::announceMessage(const std::string & txt)
|
||||
void CVCMIServer::announceTxt(const MetaString & txt, const std::string & playerName)
|
||||
{
|
||||
logNetwork->info("%s says: %s", playerName, txt.toString());
|
||||
auto cm = std::make_unique<LobbyChatMessage>();
|
||||
cm->playerName = playerName;
|
||||
cm->message = txt;
|
||||
announcePack(std::move(cm));
|
||||
LobbyChatMessage cm;
|
||||
cm.playerName = playerName;
|
||||
cm.message = txt;
|
||||
announcePack(cm);
|
||||
}
|
||||
|
||||
void CVCMIServer::announceTxt(const std::string & txt, const std::string & playerName)
|
||||
@ -633,9 +633,9 @@ void CVCMIServer::updateAndPropagateLobbyState()
|
||||
}
|
||||
}
|
||||
|
||||
auto lus = std::make_unique<LobbyUpdateState>();
|
||||
lus->state = *this;
|
||||
announcePack(std::move(lus));
|
||||
LobbyUpdateState lus;
|
||||
lus.state = *this;
|
||||
announcePack(lus);
|
||||
}
|
||||
|
||||
void CVCMIServer::setPlayer(PlayerColor clickedColor)
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
|
||||
void threadHandleClient(std::shared_ptr<CConnection> c);
|
||||
|
||||
void announcePack(std::unique_ptr<CPackForLobby> pack);
|
||||
void announcePack(CPackForLobby & pack);
|
||||
bool passHost(int toConnectionId);
|
||||
|
||||
void announceTxt(const MetaString & txt, const std::string & playerName = "system");
|
||||
@ -102,7 +102,7 @@ public:
|
||||
void announceMessage(const MetaString & txt);
|
||||
void announceMessage(const std::string & txt);
|
||||
|
||||
void handleReceivedPack(std::unique_ptr<CPackForLobby> pack);
|
||||
void handleReceivedPack(CPackForLobby & pack);
|
||||
|
||||
void updateAndPropagateLobbyState();
|
||||
|
||||
|
@ -128,10 +128,10 @@ void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyClientDisconnected(Lobb
|
||||
}
|
||||
else if(pack.c->connectionID == srv.hostClientId)
|
||||
{
|
||||
auto ph = std::make_unique<LobbyChangeHost>();
|
||||
LobbyChangeHost ph;
|
||||
auto newHost = srv.activeConnections.front();
|
||||
ph->newHostConnectionId = newHost->connectionID;
|
||||
srv.announcePack(std::move(ph));
|
||||
ph.newHostConnectionId = newHost->connectionID;
|
||||
srv.announcePack(ph);
|
||||
}
|
||||
srv.updateAndPropagateLobbyState();
|
||||
|
||||
|
@ -847,7 +847,7 @@ void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> conn
|
||||
{
|
||||
SystemMessage sm;
|
||||
sm.text = message;
|
||||
connection->sendPack(&sm);
|
||||
connection->sendPack(sm);
|
||||
}
|
||||
|
||||
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message)
|
||||
|
Loading…
Reference in New Issue
Block a user