File: NetPacksLobbyClient.cpp

package info (click to toggle)
vcmi 0.99%2Bdfsg%2Bgit20190113.f06c8a87-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye
  • size: 11,136 kB
  • sloc: cpp: 142,615; sh: 315; objc: 248; makefile: 32; ansic: 28; python: 13
file content (139 lines) | stat: -rw-r--r-- 3,487 bytes parent folder | download | duplicates (2)
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
/*
 * 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)
{
	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(!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 LobbyStartGame::applyOnLobbyHandler(CServerHandler * handler)
{
	if(handler->state == EClientState::GAMEPLAY)
	{
		handler->endGameplay(false, true);
	}
	handler->state = EClientState::STARTING;
	if(handler->si->mode != StartInfo::LOAD_GAME)
	{
		handler->si = initializedStartInfo;
	}
	if(settings["session"]["headless"].Bool())
		handler->startGameplay();
	return true;
}

void LobbyStartGame::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
{
	GH.pushIntT<CLoadingScreen>(std::bind(&CServerHandler::startGameplay, handler));
}

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->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());
}