2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* NetPacksLobbyClient.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
#include "LobbyClientNetPackVisitors.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "lobby/CSelectionBase.h"
|
|
|
|
#include "lobby/CLobbyScreen.h"
|
|
|
|
|
|
|
|
#include "lobby/OptionsTab.h"
|
|
|
|
#include "lobby/RandomMapTab.h"
|
|
|
|
#include "lobby/SelectionTab.h"
|
|
|
|
#include "lobby/CBonusSelection.h"
|
|
|
|
|
|
|
|
#include "CServerHandler.h"
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "gui/CGuiHandler.h"
|
|
|
|
#include "widgets/Buttons.h"
|
|
|
|
#include "widgets/TextControls.h"
|
|
|
|
|
|
|
|
#include "../lib/CConfigHandler.h"
|
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../lib/NetPacksLobby.h"
|
|
|
|
#include "../lib/serializer/Connection.h"
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientConnected & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = false;
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
// Check if it's LobbyClientConnected for our client
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.uuid == handler.c->uuid)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
handler.c->connectionID = pack.clientId;
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!settings["session"]["headless"].Bool())
|
2023-02-12 09:23:39 +02:00
|
|
|
GH.pushIntT<CLobbyScreen>(static_cast<ESelectionScreen>(handler.screenType));
|
|
|
|
handler.state = EClientState::LOBBY;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.clientId != pack.c->connectionID)
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
return;
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
handler.stopServerConnection();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2022-10-02 23:48:03 +02:00
|
|
|
if(GH.listInt.size())
|
|
|
|
GH.popInts(1);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyChatMessage(LobbyChatMessage & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-01-03 21:55:47 +02:00
|
|
|
if(lobby && lobby->card)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
lobby->card->chat->addNewMessage(pack.playerName + ": " + pack.message);
|
2018-01-05 19:21:07 +02:00
|
|
|
lobby->card->setChat(true);
|
|
|
|
if(lobby->buttonChat)
|
|
|
|
lobby->buttonChat->addTextOverlay(CGI->generaltexth->allTexts[531], FONT_SMALL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyGuiAction(LobbyGuiAction & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(!lobby || !handler.isGuest())
|
2018-01-05 19:21:07 +02:00
|
|
|
return;
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
switch(pack.action)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
case LobbyGuiAction::NO_TAB:
|
2018-01-05 19:21:07 +02:00
|
|
|
lobby->toggleTab(lobby->curTab);
|
|
|
|
break;
|
2023-02-12 09:23:39 +02:00
|
|
|
case LobbyGuiAction::OPEN_OPTIONS:
|
2018-01-05 19:21:07 +02:00
|
|
|
lobby->toggleTab(lobby->tabOpt);
|
|
|
|
break;
|
2023-02-12 09:23:39 +02:00
|
|
|
case LobbyGuiAction::OPEN_SCENARIO_LIST:
|
2018-01-05 19:21:07 +02:00
|
|
|
lobby->toggleTab(lobby->tabSel);
|
|
|
|
break;
|
2023-02-12 09:23:39 +02:00
|
|
|
case LobbyGuiAction::OPEN_RANDOM_MAP_OPTIONS:
|
2018-01-05 19:21:07 +02:00
|
|
|
lobby->toggleTab(lobby->tabRand);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyEndGame(LobbyEndGame & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(handler.state == EClientState::GAMEPLAY)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
handler.endGameplay(pack.closeConnection, pack.restart);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2022-09-29 19:08:05 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.restart)
|
|
|
|
handler.sendStartGame();
|
2022-09-29 19:08:05 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
|
2022-09-29 19:08:05 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.clientId != -1 && pack.clientId != handler.c->connectionID)
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
return;
|
|
|
|
}
|
2022-10-01 16:28:45 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
handler.state = EClientState::STARTING;
|
|
|
|
if(handler.si->mode != StartInfo::LOAD_GAME || pack.clientId == handler.c->connectionID)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
auto modeBackup = handler.si->mode;
|
|
|
|
handler.si = pack.initializedStartInfo;
|
|
|
|
handler.si->mode = modeBackup;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
if(settings["session"]["headless"].Bool())
|
2023-02-12 09:23:39 +02:00
|
|
|
handler.startGameplay(pack.initializedGameState);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.clientId != -1 && pack.clientId != handler.c->connectionID)
|
2022-10-01 16:28:45 +02:00
|
|
|
return;
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
GH.pushIntT<CLoadingScreen>(std::bind(&CServerHandler::startGameplay, &handler, pack.initializedGameState));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
pack.hostChanged = pack.state.hostClientId != handler.hostClientId;
|
|
|
|
static_cast<LobbyState &>(handler) = pack.state;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2022-09-30 17:32:48 +02:00
|
|
|
if(!lobby) //stub: ignore message for game mode
|
|
|
|
return;
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
if(!lobby->bonusSel && handler.si->campState && handler.state == EClientState::LOBBY_CAMPAIGN)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
lobby->bonusSel = std::make_shared<CBonusSelection>();
|
2018-01-05 19:21:07 +02:00
|
|
|
GH.pushInt(lobby->bonusSel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lobby->bonusSel)
|
|
|
|
lobby->bonusSel->updateAfterStateChange();
|
|
|
|
else
|
|
|
|
lobby->updateAfterStateChange();
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.hostChanged)
|
|
|
|
lobby->toggleMode(handler.isHost());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2022-09-23 13:02:19 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyShowMessage(LobbyShowMessage & pack)
|
2022-09-23 13:02:19 +02:00
|
|
|
{
|
2022-09-30 17:32:48 +02:00
|
|
|
if(!lobby) //stub: ignore message for game mode
|
|
|
|
return;
|
|
|
|
|
2022-09-23 13:02:19 +02:00
|
|
|
lobby->buttonStart->block(false);
|
2023-02-12 09:23:39 +02:00
|
|
|
handler.showServerError(pack.message);
|
2022-09-23 13:02:19 +02:00
|
|
|
}
|