2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* NetPacksLobbyServer.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 "LobbyNetPackVisitors.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
#include "CVCMIServer.h"
|
|
|
|
#include "CGameHandler.h"
|
|
|
|
|
|
|
|
#include "../lib/serializer/Connection.h"
|
|
|
|
#include "../lib/StartInfo.h"
|
|
|
|
|
|
|
|
// Campaigns
|
2023-06-25 21:28:24 +02:00
|
|
|
#include "../lib/campaign/CampaignState.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::visitForLobby(CPackForLobby & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.isForServer())
|
|
|
|
{
|
|
|
|
result = srv.isClientHost(pack.c->connectionID);
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerAfterAnnounceNetPackVisitor::visitForLobby(CPackForLobby & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
// Propogate options after every CLobbyPackToServer
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.isForServer())
|
|
|
|
{
|
|
|
|
srv.updateAndPropagateLobbyState();
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::visitLobbyClientConnected(LobbyClientConnected & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(srv.gh)
|
2022-10-04 18:54:40 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
for(auto & connection : srv.hangingConnections)
|
2022-10-04 18:54:40 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(connection->uuid == pack.uuid)
|
2022-10-04 18:54:40 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
return;
|
|
|
|
}
|
2022-10-04 18:54:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 17:45:13 +02:00
|
|
|
if(srv.getState() == EServerState::LOBBY)
|
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
|
|
|
return;
|
2023-08-22 17:45:13 +02:00
|
|
|
}
|
2022-10-04 18:54:40 +02:00
|
|
|
|
|
|
|
//disconnect immediately and ignore this client
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.connections.erase(pack.c);
|
|
|
|
if(pack.c && pack.c->isOpen())
|
|
|
|
{
|
|
|
|
pack.c->close();
|
|
|
|
pack.c->connected = false;
|
|
|
|
}
|
2022-10-04 18:54:40 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = false;
|
|
|
|
return;
|
2022-10-04 18:54:40 +02:00
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbyClientConnected(LobbyClientConnected & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(srv.gh)
|
2022-10-04 18:54:40 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
for(auto & connection : srv.hangingConnections)
|
2022-10-04 18:54:40 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(connection->uuid == pack.uuid)
|
2022-10-04 18:54:40 +02:00
|
|
|
{
|
|
|
|
logNetwork->info("Reconnection player");
|
2023-02-12 09:23:39 +02:00
|
|
|
pack.c->connectionID = connection->connectionID;
|
|
|
|
for(auto & playerConnection : srv.gh->connections)
|
2022-10-04 18:54:40 +02:00
|
|
|
{
|
|
|
|
for(auto & existingConnection : playerConnection.second)
|
|
|
|
{
|
|
|
|
if(existingConnection == connection)
|
|
|
|
{
|
|
|
|
playerConnection.second.erase(existingConnection);
|
2023-02-12 09:23:39 +02:00
|
|
|
playerConnection.second.insert(pack.c);
|
2022-10-04 18:54:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.hangingConnections.erase(connection);
|
2022-10-04 18:54:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.clientConnected(pack.c, pack.names, pack.uuid, pack.mode);
|
2018-01-05 19:21:07 +02:00
|
|
|
// Server need to pass some data to newly connected client
|
2023-02-12 09:23:39 +02:00
|
|
|
pack.clientId = pack.c->connectionID;
|
|
|
|
pack.mode = srv.si->mode;
|
|
|
|
pack.hostClientId = srv.hostClientId;
|
|
|
|
|
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyClientConnected(LobbyClientConnected & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
// FIXME: we need to avoid senting something to client that not yet get answer for LobbyClientConnected
|
|
|
|
// Until UUID set we only pass LobbyClientConnected to this client
|
2023-02-12 09:23:39 +02:00
|
|
|
pack.c->uuid = pack.uuid;
|
|
|
|
srv.updateAndPropagateLobbyState();
|
2023-08-22 17:45:13 +02:00
|
|
|
if(srv.getState() == EServerState::GAMEPLAY)
|
2022-10-01 16:28:45 +02:00
|
|
|
{
|
|
|
|
//immediately start game
|
|
|
|
std::unique_ptr<LobbyStartGame> startGameForReconnectedPlayer(new LobbyStartGame);
|
2023-02-12 09:23:39 +02:00
|
|
|
startGameForReconnectedPlayer->initializedStartInfo = srv.si;
|
|
|
|
startGameForReconnectedPlayer->initializedGameState = srv.gh->gameState();
|
|
|
|
startGameForReconnectedPlayer->clientId = pack.c->connectionID;
|
|
|
|
srv.addToAnnounceQueue(std::move(startGameForReconnectedPlayer));
|
2022-10-01 16:28:45 +02:00
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::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
|
|
|
if(pack.shutdownServer)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(!srv.cmdLineOptions.count("run-by-client"))
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
return;
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.c->uuid != srv.cmdLineOptions["uuid"].as<std::string>())
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
return;
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.clientDisconnected(pack.c);
|
|
|
|
pack.c->close();
|
|
|
|
pack.c->connected = false;
|
|
|
|
|
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.c && pack.c->isOpen())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
boost::unique_lock<boost::mutex> lock(*pack.c->mutexWrite);
|
|
|
|
pack.c->close();
|
|
|
|
pack.c->connected = false;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.shutdownServer)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
logNetwork->info("Client requested shutdown, server will close itself...");
|
2023-08-22 17:45:13 +02:00
|
|
|
srv.setState(EServerState::SHUTDOWN);
|
2018-01-05 19:21:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-02-12 09:23:39 +02:00
|
|
|
else if(srv.connections.empty())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
logNetwork->error("Last connection lost, server will close itself...");
|
2023-08-22 17:45:13 +02:00
|
|
|
srv.setState(EServerState::SHUTDOWN);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-02-12 09:23:39 +02:00
|
|
|
else if(pack.c == srv.hostClient)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2022-12-07 23:36:20 +02:00
|
|
|
auto ph = std::make_unique<LobbyChangeHost>();
|
2023-02-12 09:23:39 +02:00
|
|
|
auto newHost = *RandomGeneratorUtil::nextItem(srv.connections, CRandomGenerator::getDefault());
|
2018-01-05 19:21:07 +02:00
|
|
|
ph->newHostConnectionId = newHost->connectionID;
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.addToAnnounceQueue(std::move(ph));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.updateAndPropagateLobbyState();
|
2023-09-29 19:49:18 +02:00
|
|
|
|
2023-12-24 22:31:02 +02:00
|
|
|
// if(srv.getState() != EServerState::SHUTDOWN && srv.remoteConnections.count(pack.c))
|
|
|
|
// {
|
|
|
|
// srv.remoteConnections -= pack.c;
|
|
|
|
// srv.connectToRemote();
|
|
|
|
// }
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::visitLobbyChatMessage(LobbyChatMessage & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetMap(LobbySetMap & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-22 17:45:13 +02:00
|
|
|
if(srv.getState() != EServerState::LOBBY)
|
2023-02-12 09:23:39 +02:00
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
srv.updateStartInfoOnMapChange(pack.mapInfo, pack.mapGenOpts);
|
2018-04-22 16:40:02 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetCampaign(LobbySetCampaign & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-06-26 00:07:55 +02:00
|
|
|
srv.si->mapname = pack.ourCampaign->getFilename();
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.si->mode = StartInfo::CAMPAIGN;
|
|
|
|
srv.si->campState = pack.ourCampaign;
|
2023-08-14 00:16:25 +02:00
|
|
|
srv.si->turnTimerInfo = TurnTimerInfo{};
|
2023-06-25 20:16:03 +02:00
|
|
|
|
2023-06-25 23:01:25 +02:00
|
|
|
bool isCurrentMapConquerable = pack.ourCampaign->currentScenario() && pack.ourCampaign->isAvailable(*pack.ourCampaign->currentScenario());
|
|
|
|
|
|
|
|
for(auto scenarioID : pack.ourCampaign->allScenarios())
|
|
|
|
{
|
|
|
|
if(pack.ourCampaign->isAvailable(scenarioID))
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-06-25 23:01:25 +02:00
|
|
|
if(!isCurrentMapConquerable || (isCurrentMapConquerable && scenarioID == *pack.ourCampaign->currentScenario()))
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-06-25 20:16:03 +02:00
|
|
|
srv.setCampaignMap(scenarioID);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-12 09:23:39 +02:00
|
|
|
|
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetCampaignMap(LobbySetCampaignMap & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.setCampaignMap(pack.mapId);
|
|
|
|
|
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetCampaignBonus(LobbySetCampaignBonus & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.setCampaignBonus(pack.bonusId);
|
|
|
|
|
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::visitLobbyGuiAction(LobbyGuiAction & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = srv.isClientHost(pack.c->connectionID);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::visitLobbyEndGame(LobbyEndGame & pack)
|
2022-09-29 19:08:05 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = srv.isClientHost(pack.c->connectionID);
|
2022-09-29 19:08:05 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbyEndGame(LobbyEndGame & pack)
|
2022-09-29 19:08:05 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.prepareToRestart();
|
|
|
|
|
|
|
|
result = true;
|
2022-09-29 19:08:05 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyEndGame(LobbyEndGame & pack)
|
2022-09-29 19:08:05 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
boost::unique_lock<boost::mutex> stateLock(srv.stateMutex);
|
|
|
|
for(auto & c : srv.connections)
|
2022-09-29 19:08:05 +02:00
|
|
|
{
|
|
|
|
c->enterLobbyConnectionMode();
|
|
|
|
c->disableStackSendingByID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = srv.isClientHost(pack.c->connectionID);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.verifyStateBeforeStart(true);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = false;
|
|
|
|
return;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-08-21 03:06:58 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
// Server will prepare gamestate and we announce StartInfo to clients
|
2023-02-12 09:23:39 +02:00
|
|
|
if(!srv.prepareToStartGame())
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
return;
|
|
|
|
}
|
2022-09-23 13:02:19 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
pack.initializedStartInfo = std::make_shared<StartInfo>(*srv.gh->getStartInfo(true));
|
|
|
|
pack.initializedGameState = srv.gh->gameState();
|
2022-09-28 21:15:05 +02:00
|
|
|
|
2023-08-22 17:45:13 +02:00
|
|
|
srv.setState(EServerState::GAMEPLAY_STARTING);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(pack.clientId == -1) //do not restart game for single client only
|
|
|
|
srv.startGameImmidiately();
|
2022-10-01 16:28:45 +02:00
|
|
|
else
|
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
for(auto & c : srv.connections)
|
2022-10-01 16:28:45 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(c->connectionID == pack.clientId)
|
2022-10-01 16:28:45 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
c->enterGameplayConnectionMode(srv.gh->gameState());
|
|
|
|
srv.reconnectPlayer(pack.clientId);
|
2022-10-01 16:28:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::visitLobbyChangeHost(LobbyChangeHost & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = srv.isClientHost(pack.c->connectionID);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbyChangeHost(LobbyChangeHost & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyChangeHost(LobbyChangeHost & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
auto result = srv.passHost(pack.newHostConnectionId);
|
|
|
|
|
|
|
|
if(!result)
|
|
|
|
{
|
|
|
|
logGlobal->error("passHost returned false. What does it mean?");
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ClientPermissionsCheckerNetPackVisitor::visitLobbyChangePlayerOption(LobbyChangePlayerOption & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(srv.isClientHost(pack.c->connectionID))
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
return;
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
if(vstd::contains(srv.getAllClientPlayers(pack.c->connectionID), pack.color))
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbyChangePlayerOption(LobbyChangePlayerOption & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
switch(pack.what)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-14 00:08:48 +02:00
|
|
|
case LobbyChangePlayerOption::TOWN_ID:
|
2023-09-28 18:43:04 +02:00
|
|
|
srv.optionSetCastle(pack.color, FactionID(pack.value));
|
2023-08-14 00:08:48 +02:00
|
|
|
break;
|
2023-02-12 09:23:39 +02:00
|
|
|
case LobbyChangePlayerOption::TOWN:
|
2023-08-14 00:08:48 +02:00
|
|
|
srv.optionNextCastle(pack.color, pack.value);
|
|
|
|
break;
|
|
|
|
case LobbyChangePlayerOption::HERO_ID:
|
2023-09-28 18:43:04 +02:00
|
|
|
srv.optionSetHero(pack.color, HeroTypeID(pack.value));
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
2023-02-12 09:23:39 +02:00
|
|
|
case LobbyChangePlayerOption::HERO:
|
2023-08-14 00:08:48 +02:00
|
|
|
srv.optionNextHero(pack.color, pack.value);
|
|
|
|
break;
|
|
|
|
case LobbyChangePlayerOption::BONUS_ID:
|
2023-09-28 18:43:04 +02:00
|
|
|
srv.optionSetBonus(pack.color, PlayerStartingBonus(pack.value));
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
2023-02-12 09:23:39 +02:00
|
|
|
case LobbyChangePlayerOption::BONUS:
|
2023-08-14 00:08:48 +02:00
|
|
|
srv.optionNextBonus(pack.color, pack.value);
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-02-12 09:23:39 +02:00
|
|
|
|
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetPlayer(LobbySetPlayer & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.setPlayer(pack.clickedColor);
|
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-10-13 23:04:35 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetPlayerName(LobbySetPlayerName & pack)
|
|
|
|
{
|
|
|
|
srv.setPlayerName(pack.color, pack.name);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
2023-09-22 18:57:43 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetSimturns(LobbySetSimturns & pack)
|
|
|
|
{
|
|
|
|
srv.si->simturnsInfo = pack.simturnsInfo;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetTurnTime(LobbySetTurnTime & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-14 00:16:25 +02:00
|
|
|
srv.si->turnTimerInfo = pack.turnTimerInfo;
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-12-28 21:48:19 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetExtraOptions(LobbySetExtraOptions & pack)
|
2023-12-27 15:39:35 +02:00
|
|
|
{
|
2023-12-28 21:48:19 +02:00
|
|
|
srv.si->extraOptionsInfo = pack.extraOptionsInfo;
|
2023-12-27 15:39:35 +02:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbySetDifficulty(LobbySetDifficulty & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-11 00:00:46 +02:00
|
|
|
srv.si->difficulty = std::clamp<uint8_t>(pack.difficulty, 0, 4);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyOnServerNetPackVisitor::visitLobbyForceSetPlayer(LobbyForceSetPlayer & pack)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
srv.si->playerInfos[pack.targetPlayerColor].connectedPlayerIDs.insert(pack.targetConnectedPlayer);
|
|
|
|
result = true;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|