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

PlayerCheated: new netpack to apply losing / winning cheat code

This commit is contained in:
Arseniy Shestakov 2017-06-02 03:34:50 +03:00
parent 4b0f702e7e
commit bc6f65af04
4 changed files with 34 additions and 3 deletions

View File

@ -152,6 +152,21 @@ struct PlayerBlocked : public CPackForClient
}
};
struct PlayerCheated : public CPackForClient
{
PlayerCheated() : losingCheatCode(false), winningCheatCode(false) {}
DLL_LINKAGE void applyGs(CGameState *gs);
PlayerColor player;
bool losingCheatCode;
bool winningCheatCode;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & player & losingCheatCode & winningCheatCode;
}
};
struct YourTurn : public CPackForClient
{
YourTurn(){}

View File

@ -1840,6 +1840,12 @@ DLL_LINKAGE void BattleSetStackProperty::applyGs(CGameState *gs)
}
}
DLL_LINKAGE void PlayerCheated::applyGs(CGameState *gs)
{
gs->getPlayer(player)->enteredLosingCheatCode = losingCheatCode;
gs->getPlayer(player)->enteredWinningCheatCode = winningCheatCode;
}
DLL_LINKAGE void YourTurn::applyGs(CGameState *gs)
{
gs->currentPlayer = player;

View File

@ -210,6 +210,7 @@ void registerTypesClientPacks1(Serializer &s)
s.template registerType<CPackForClient, PackageApplied>();
s.template registerType<CPackForClient, SystemMessage>();
s.template registerType<CPackForClient, PlayerBlocked>();
s.template registerType<CPackForClient, PlayerCheated>();
s.template registerType<CPackForClient, YourTurn>();
s.template registerType<CPackForClient, SetResources>();
s.template registerType<CPackForClient, SetPrimSkill>();

View File

@ -1040,7 +1040,10 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
{
if(playerConn.second == &c)
{
gs->getPlayer(playerConn.first)->enteredLosingCheatCode = 1;
PlayerCheated pc;
pc.player = playerConn.first;
pc.losingCheatCode = true;
sendAndApply(&pc);
checkVictoryLossConditionsForPlayer(playerConn.first);
}
}
@ -6210,12 +6213,18 @@ void CGameHandler::handleCheatCode(std::string & cheat, PlayerColor player, cons
else if (cheat == "vcmisilmaril")
{
///Player wins
gs->getPlayer(player)->enteredWinningCheatCode = 1;
PlayerCheated pc;
pc.player = player;
pc.winningCheatCode = true;
sendAndApply(&pc);
}
else if (cheat == "vcmimelkor")
{
///Player looses
gs->getPlayer(player)->enteredLosingCheatCode = 1;
PlayerCheated pc;
pc.player = player;
pc.losingCheatCode = true;
sendAndApply(&pc);
}
else if (cheat == "vcmieagles" || cheat == "vcmiungoliant")
{