1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/*
* 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"
#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"
bool LobbyClientConnected::applyOnLobbyHandler(CServerHandler * handler)
{
// Check if it's LobbyClientConnected for our client
if(uuid == handler->c->uuid)
{
handler->c->connectionID = clientId;
if(!settings["session"]["headless"].Bool())
GH.pushIntT<CLobbyScreen>(static_cast<ESelectionScreen>(handler->screenType));
handler->state = EClientState::LOBBY;
return true;
}
return false;
}
void LobbyClientConnected::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
{
}
bool LobbyClientDisconnected::applyOnLobbyHandler(CServerHandler * handler)
{
if(clientId != c->connectionID)
return false;
handler->stopServerConnection();
return true;
}
void LobbyClientDisconnected::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
{
if(GH.listInt.size())
GH.popInts(1);
}
void LobbyChatMessage::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
{
if(lobby)
{
lobby->card->chat->addNewMessage(playerName + ": " + message);
lobby->card->setChat(true);
if(lobby->buttonChat)
lobby->buttonChat->addTextOverlay(CGI->generaltexth->allTexts[531], FONT_SMALL);
}
}
void LobbyGuiAction::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
{
if(!lobby || !handler->isGuest())
return;
switch(action)
{
case NO_TAB:
lobby->toggleTab(lobby->curTab);
break;
case OPEN_OPTIONS:
lobby->toggleTab(lobby->tabOpt);
break;
case OPEN_SCENARIO_LIST:
lobby->toggleTab(lobby->tabSel);
break;
case OPEN_RANDOM_MAP_OPTIONS:
lobby->toggleTab(lobby->tabRand);
break;
}
}
bool LobbyEndGame::applyOnLobbyHandler(CServerHandler * handler)
{
if(handler->state == EClientState::GAMEPLAY)
{
handler->endGameplay(closeConnection, restart);
}
if(restart)
handler->sendStartGame();
return true;
}
bool LobbyStartGame::applyOnLobbyHandler(CServerHandler * handler)
{
if(clientId != -1 && clientId != handler->c->connectionID)
return false;
handler->state = EClientState::STARTING;
if(handler->si->mode != StartInfo::LOAD_GAME || clientId == handler->c->connectionID)
{
auto modeBackup = handler->si->mode;
handler->si = initializedStartInfo;
handler->si->mode = modeBackup;
}
if(settings["session"]["headless"].Bool())
handler->startGameplay(initializedGameState);
return true;
}
void LobbyStartGame::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
{
if(clientId != -1 && clientId != handler->c->connectionID)
return;
GH.pushIntT<CLoadingScreen>(std::bind(&CServerHandler::startGameplay, handler, initializedGameState));
}
bool LobbyUpdateState::applyOnLobbyHandler(CServerHandler * handler)
{
hostChanged = state.hostClientId != handler->hostClientId;
static_cast<LobbyState &>(*handler) = state;
return true;
}
void LobbyUpdateState::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
{
if(!lobby) //stub: ignore message for game mode
return;
if(!lobby->bonusSel && handler->si->campState && handler->state == EClientState::LOBBY_CAMPAIGN)
{
lobby->bonusSel = std::make_shared<CBonusSelection>();
GH.pushInt(lobby->bonusSel);
}
if(lobby->bonusSel)
lobby->bonusSel->updateAfterStateChange();
else
lobby->updateAfterStateChange();
if(hostChanged)
lobby->toggleMode(handler->isHost());
}
void LobbyShowMessage::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
{
if(!lobby) //stub: ignore message for game mode
return;
lobby->buttonStart->block(false);
handler->showServerError(message);
}
|