1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-01 23:12:49 +02:00

rework netpacks to avoid double typeinfo

This commit is contained in:
Andrii Danylchenko
2023-02-12 09:23:39 +02:00
parent 8855829527
commit 9f55666931
23 changed files with 3046 additions and 1581 deletions

View File

@@ -9,6 +9,7 @@
*/
#include "StdInc.h"
#include "LobbyClientNetPackVisitors.h"
#include "lobby/CSelectionBase.h"
#include "lobby/CLobbyScreen.h"
@@ -28,123 +29,120 @@
#include "../lib/NetPacksLobby.h"
#include "../lib/serializer/Connection.h"
bool LobbyClientConnected::applyOnLobbyHandler(CServerHandler * handler)
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientConnected & pack)
{
result = false;
// Check if it's LobbyClientConnected for our client
if(uuid == handler->c->uuid)
if(pack.uuid == handler.c->uuid)
{
handler->c->connectionID = clientId;
handler.c->connectionID = pack.clientId;
if(!settings["session"]["headless"].Bool())
GH.pushIntT<CLobbyScreen>(static_cast<ESelectionScreen>(handler->screenType));
handler->state = EClientState::LOBBY;
return true;
GH.pushIntT<CLobbyScreen>(static_cast<ESelectionScreen>(handler.screenType));
handler.state = EClientState::LOBBY;
}
return false;
}
void LobbyClientConnected::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
{
if(pack.clientId != pack.c->connectionID)
{
result = false;
return;
}
handler.stopServerConnection();
}
bool LobbyClientDisconnected::applyOnLobbyHandler(CServerHandler * handler)
{
if(clientId != c->connectionID)
return false;
handler->stopServerConnection();
return true;
}
void LobbyClientDisconnected::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
{
if(GH.listInt.size())
GH.popInts(1);
}
void LobbyChatMessage::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyChatMessage(LobbyChatMessage & pack)
{
if(lobby && lobby->card)
{
lobby->card->chat->addNewMessage(playerName + ": " + message);
lobby->card->chat->addNewMessage(pack.playerName + ": " + pack.message);
lobby->card->setChat(true);
if(lobby->buttonChat)
lobby->buttonChat->addTextOverlay(CGI->generaltexth->allTexts[531], FONT_SMALL);
}
}
void LobbyGuiAction::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyGuiAction(LobbyGuiAction & pack)
{
if(!lobby || !handler->isGuest())
if(!lobby || !handler.isGuest())
return;
switch(action)
switch(pack.action)
{
case NO_TAB:
case LobbyGuiAction::NO_TAB:
lobby->toggleTab(lobby->curTab);
break;
case OPEN_OPTIONS:
case LobbyGuiAction::OPEN_OPTIONS:
lobby->toggleTab(lobby->tabOpt);
break;
case OPEN_SCENARIO_LIST:
case LobbyGuiAction::OPEN_SCENARIO_LIST:
lobby->toggleTab(lobby->tabSel);
break;
case OPEN_RANDOM_MAP_OPTIONS:
case LobbyGuiAction::OPEN_RANDOM_MAP_OPTIONS:
lobby->toggleTab(lobby->tabRand);
break;
}
}
bool LobbyEndGame::applyOnLobbyHandler(CServerHandler * handler)
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyEndGame(LobbyEndGame & pack)
{
if(handler->state == EClientState::GAMEPLAY)
if(handler.state == EClientState::GAMEPLAY)
{
handler->endGameplay(closeConnection, restart);
handler.endGameplay(pack.closeConnection, pack.restart);
}
if(restart)
handler->sendStartGame();
return true;
if(pack.restart)
handler.sendStartGame();
}
bool LobbyStartGame::applyOnLobbyHandler(CServerHandler * handler)
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
{
if(clientId != -1 && clientId != handler->c->connectionID)
return false;
handler->state = EClientState::STARTING;
if(handler->si->mode != StartInfo::LOAD_GAME || clientId == handler->c->connectionID)
if(pack.clientId != -1 && pack.clientId != handler.c->connectionID)
{
auto modeBackup = handler->si->mode;
handler->si = initializedStartInfo;
handler->si->mode = modeBackup;
result = false;
return;
}
handler.state = EClientState::STARTING;
if(handler.si->mode != StartInfo::LOAD_GAME || pack.clientId == handler.c->connectionID)
{
auto modeBackup = handler.si->mode;
handler.si = pack.initializedStartInfo;
handler.si->mode = modeBackup;
}
if(settings["session"]["headless"].Bool())
handler->startGameplay(initializedGameState);
return true;
handler.startGameplay(pack.initializedGameState);
}
void LobbyStartGame::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
{
if(clientId != -1 && clientId != handler->c->connectionID)
if(pack.clientId != -1 && pack.clientId != handler.c->connectionID)
return;
GH.pushIntT<CLoadingScreen>(std::bind(&CServerHandler::startGameplay, handler, initializedGameState));
GH.pushIntT<CLoadingScreen>(std::bind(&CServerHandler::startGameplay, &handler, pack.initializedGameState));
}
bool LobbyUpdateState::applyOnLobbyHandler(CServerHandler * handler)
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & pack)
{
hostChanged = state.hostClientId != handler->hostClientId;
static_cast<LobbyState &>(*handler) = state;
return true;
pack.hostChanged = pack.state.hostClientId != handler.hostClientId;
static_cast<LobbyState &>(handler) = pack.state;
}
void LobbyUpdateState::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & pack)
{
if(!lobby) //stub: ignore message for game mode
return;
if(!lobby->bonusSel && handler->si->campState && handler->state == EClientState::LOBBY_CAMPAIGN)
if(!lobby->bonusSel && handler.si->campState && handler.state == EClientState::LOBBY_CAMPAIGN)
{
lobby->bonusSel = std::make_shared<CBonusSelection>();
GH.pushInt(lobby->bonusSel);
@@ -155,15 +153,15 @@ void LobbyUpdateState::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler *
else
lobby->updateAfterStateChange();
if(hostChanged)
lobby->toggleMode(handler->isHost());
if(pack.hostChanged)
lobby->toggleMode(handler.isHost());
}
void LobbyShowMessage::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyShowMessage(LobbyShowMessage & pack)
{
if(!lobby) //stub: ignore message for game mode
return;
lobby->buttonStart->block(false);
handler->showServerError(message);
handler.showServerError(pack.message);
}