2023-07-12 20:13:17 +02:00
|
|
|
/*
|
|
|
|
* CGameHandler.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 "PlayerMessageProcessor.h"
|
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
#include "TurnOrderProcessor.h"
|
|
|
|
|
2023-07-23 23:20:35 +02:00
|
|
|
#include "../CGameHandler.h"
|
|
|
|
#include "../CVCMIServer.h"
|
2024-05-19 19:12:29 +02:00
|
|
|
#include "../TurnTimerHandler.h"
|
2023-07-12 20:13:17 +02:00
|
|
|
|
2023-07-23 23:20:35 +02:00
|
|
|
#include "../../lib/CHeroHandler.h"
|
|
|
|
#include "../../lib/CPlayerState.h"
|
|
|
|
#include "../../lib/StartInfo.h"
|
|
|
|
#include "../../lib/gameState/CGameState.h"
|
|
|
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
2023-11-18 16:34:18 +02:00
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
2023-10-05 20:18:11 +02:00
|
|
|
#include "../../lib/modding/IdentifierStorage.h"
|
|
|
|
#include "../../lib/modding/ModScope.h"
|
2023-12-08 18:30:23 +02:00
|
|
|
#include "../../lib/mapping/CMap.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../../lib/networkPacks/PacksForClient.h"
|
|
|
|
#include "../../lib/networkPacks/StackLocation.h"
|
2023-11-18 16:34:18 +02:00
|
|
|
#include "../../lib/serializer/Connection.h"
|
2023-07-12 20:13:17 +02:00
|
|
|
|
|
|
|
PlayerMessageProcessor::PlayerMessageProcessor(CGameHandler * gameHandler)
|
|
|
|
:gameHandler(gameHandler)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
void PlayerMessageProcessor::playerMessage(PlayerColor player, const std::string & message, ObjectInstanceID currObj)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
2024-05-19 19:12:29 +02:00
|
|
|
if(!message.empty() && message[0] == '!')
|
|
|
|
{
|
|
|
|
broadcastMessage(player, message);
|
|
|
|
handleCommand(player, message);
|
2023-07-12 20:13:17 +02:00
|
|
|
return;
|
2024-05-19 19:12:29 +02:00
|
|
|
}
|
2023-07-12 20:13:17 +02:00
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
if(handleCheatCode(message, player, currObj))
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
if(!gameHandler->getPlayerSettings(player)->isControlledByAI())
|
2024-05-02 21:03:23 +02:00
|
|
|
{
|
|
|
|
MetaString txt;
|
|
|
|
txt.appendLocalString(EMetaText::GENERAL_TXT, 260);
|
|
|
|
broadcastSystemMessage(txt);
|
2024-05-19 19:12:29 +02:00
|
|
|
}
|
2023-07-12 20:13:17 +02:00
|
|
|
|
|
|
|
if(!player.isSpectator())
|
2024-05-19 19:12:29 +02:00
|
|
|
gameHandler->checkVictoryLossConditionsForPlayer(player); //Player enter win code or got required art\creature
|
2023-07-12 20:13:17 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
broadcastMessage(player, message);
|
|
|
|
}
|
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
void PlayerMessageProcessor::commandExit(PlayerColor player, const std::vector<std::string> & words)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
2023-11-18 16:34:18 +02:00
|
|
|
bool isHost = gameHandler->gameLobby()->isPlayerHost(player);
|
2024-05-19 19:12:29 +02:00
|
|
|
if(!isHost)
|
|
|
|
return;
|
2023-07-12 20:13:17 +02:00
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
broadcastSystemMessage("game was terminated");
|
|
|
|
gameHandler->gameLobby()->setState(EServerState::SHUTDOWN);
|
|
|
|
}
|
2023-07-12 20:13:17 +02:00
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
void PlayerMessageProcessor::commandKick(PlayerColor player, const std::vector<std::string> & words)
|
|
|
|
{
|
|
|
|
bool isHost = gameHandler->gameLobby()->isPlayerHost(player);
|
|
|
|
if(!isHost)
|
|
|
|
return;
|
2023-07-12 20:13:17 +02:00
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
if(words.size() == 2)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
2024-05-19 19:12:29 +02:00
|
|
|
auto playername = words[1];
|
2023-07-12 20:13:17 +02:00
|
|
|
PlayerColor playerToKick(PlayerColor::CANNOT_DETERMINE);
|
|
|
|
if(std::all_of(playername.begin(), playername.end(), ::isdigit))
|
|
|
|
playerToKick = PlayerColor(std::stoi(playername));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(auto & c : gameHandler->connections)
|
|
|
|
{
|
2023-09-04 21:21:02 +02:00
|
|
|
if(c.first.toString() == playername)
|
2023-07-12 20:13:17 +02:00
|
|
|
playerToKick = c.first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(playerToKick != PlayerColor::CANNOT_DETERMINE)
|
|
|
|
{
|
|
|
|
PlayerCheated pc;
|
|
|
|
pc.player = playerToKick;
|
|
|
|
pc.losingCheatCode = true;
|
|
|
|
gameHandler->sendAndApply(&pc);
|
|
|
|
gameHandler->checkVictoryLossConditionsForPlayer(playerToKick);
|
|
|
|
}
|
|
|
|
}
|
2024-05-19 19:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::commandSave(PlayerColor player, const std::vector<std::string> & words)
|
|
|
|
{
|
|
|
|
bool isHost = gameHandler->gameLobby()->isPlayerHost(player);
|
|
|
|
if(!isHost)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(words.size() == 2)
|
|
|
|
{
|
|
|
|
gameHandler->save("Saves/" + words[1]);
|
|
|
|
broadcastSystemMessage("game saved as " + words[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::commandCheaters(PlayerColor player, const std::vector<std::string> & words)
|
|
|
|
{
|
|
|
|
int playersCheated = 0;
|
|
|
|
for(const auto & player : gameHandler->gameState()->players)
|
2023-07-12 20:59:42 +02:00
|
|
|
{
|
2024-05-19 19:12:29 +02:00
|
|
|
if(player.second.cheated)
|
2023-09-25 18:06:40 +02:00
|
|
|
{
|
2024-05-19 19:12:29 +02:00
|
|
|
broadcastSystemMessage("Player " + player.first.toString() + " is cheater!");
|
|
|
|
playersCheated++;
|
2023-09-25 18:06:40 +02:00
|
|
|
}
|
2024-05-19 19:12:29 +02:00
|
|
|
}
|
2023-07-12 20:59:42 +02:00
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
if(!playersCheated)
|
|
|
|
broadcastSystemMessage("No cheaters registered!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::commandHelp(PlayerColor player, const std::vector<std::string> & words)
|
|
|
|
{
|
|
|
|
broadcastSystemMessage("Available commands to host:");
|
|
|
|
broadcastSystemMessage("'!exit' - immediately ends current game");
|
|
|
|
broadcastSystemMessage("'!kick <player>' - kick specified player from the game");
|
|
|
|
broadcastSystemMessage("'!save <filename>' - save game under specified filename");
|
|
|
|
broadcastSystemMessage("Available commands to all players:");
|
|
|
|
broadcastSystemMessage("'!help' - display this help");
|
|
|
|
broadcastSystemMessage("'!cheaters' - list players that entered cheat command during game");
|
|
|
|
broadcastSystemMessage("'!vote' - allows to change some game settings if all players vote for it");
|
|
|
|
}
|
2023-07-12 20:59:42 +02:00
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
void PlayerMessageProcessor::commandVote(PlayerColor player, const std::vector<std::string> & words)
|
|
|
|
{
|
|
|
|
if(words.size() < 2)
|
|
|
|
{
|
|
|
|
broadcastSystemMessage("'!vote simturns allow X' - allow simultaneous turns for specified number of days, or until contact");
|
|
|
|
broadcastSystemMessage("'!vote simturns force X' - force simultaneous turns for specified number of days, blocking player contacts");
|
|
|
|
broadcastSystemMessage("'!vote simturns abort' - abort simultaneous turns once this turn ends");
|
|
|
|
broadcastSystemMessage("'!vote timer prolong X' - prolong base timer for all players by specified number of seconds");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(words[1] == "yes" || words[1] == "no")
|
|
|
|
{
|
|
|
|
if(currentVote == ECurrentChatVote::NONE)
|
|
|
|
{
|
|
|
|
broadcastSystemMessage("No active voting!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(words[1] == "yes")
|
|
|
|
{
|
|
|
|
awaitingPlayers.erase(player);
|
|
|
|
if(awaitingPlayers.empty())
|
|
|
|
finishVoting();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(words[1] == "no")
|
|
|
|
{
|
|
|
|
abortVoting();
|
|
|
|
return;
|
|
|
|
}
|
2023-07-12 20:59:42 +02:00
|
|
|
}
|
2023-07-12 20:13:17 +02:00
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
const auto & parseNumber = [](const std::string & input) -> std::optional<int>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return std::stol(input);
|
|
|
|
}
|
|
|
|
catch(std::logic_error &)
|
|
|
|
{
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(words[1] == "simturns" && words.size() > 2)
|
|
|
|
{
|
|
|
|
if(words[2] == "allow" && words.size() > 3)
|
|
|
|
{
|
|
|
|
auto daysCount = parseNumber(words[3]);
|
|
|
|
if(daysCount && daysCount.value() > 0)
|
|
|
|
startVoting(player, ECurrentChatVote::SIMTURNS_ALLOW, daysCount.value());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(words[2] == "force" && words.size() > 3)
|
|
|
|
{
|
|
|
|
auto daysCount = parseNumber(words[3]);
|
|
|
|
if(daysCount && daysCount.value() > 0)
|
|
|
|
startVoting(player, ECurrentChatVote::SIMTURNS_FORCE, daysCount.value());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(words[2] == "abort")
|
|
|
|
{
|
|
|
|
startVoting(player, ECurrentChatVote::SIMTURNS_ABORT, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(words[1] == "timer" && words.size() > 2)
|
|
|
|
{
|
|
|
|
if(words[2] == "prolong" && words.size() > 3)
|
|
|
|
{
|
|
|
|
auto secondsCount = parseNumber(words[3]);
|
|
|
|
if(secondsCount && secondsCount.value() > 0)
|
|
|
|
startVoting(player, ECurrentChatVote::TIMER_PROLONG, secondsCount.value());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
broadcastSystemMessage("Voting command not recognized!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::finishVoting()
|
|
|
|
{
|
|
|
|
switch(currentVote)
|
|
|
|
{
|
|
|
|
case ECurrentChatVote::SIMTURNS_ALLOW:
|
|
|
|
broadcastSystemMessage("Voting successful. Simultaneous turns will run for " + std::to_string(currentVoteParameter) + " more days, or until contact");
|
|
|
|
gameHandler->turnOrder->setMaxSimturnsDuration(currentVoteParameter);
|
|
|
|
break;
|
|
|
|
case ECurrentChatVote::SIMTURNS_FORCE:
|
|
|
|
broadcastSystemMessage("Voting successful. Simultaneous turns will run for " + std::to_string(currentVoteParameter) + " more days. Contacts are blocked");
|
|
|
|
gameHandler->turnOrder->setMinSimturnsDuration(currentVoteParameter);
|
|
|
|
break;
|
|
|
|
case ECurrentChatVote::SIMTURNS_ABORT:
|
|
|
|
broadcastSystemMessage("Voting successful. Simultaneous turns will end on next day");
|
|
|
|
gameHandler->turnOrder->setMinSimturnsDuration(0);
|
|
|
|
gameHandler->turnOrder->setMaxSimturnsDuration(0);
|
|
|
|
break;
|
|
|
|
case ECurrentChatVote::TIMER_PROLONG:
|
|
|
|
broadcastSystemMessage("Voting successful. Timer for all players has been prolonger for " + std::to_string(currentVoteParameter) + " seconds");
|
|
|
|
gameHandler->turnTimerHandler->prolongTimers(currentVoteParameter * 1000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentVote = ECurrentChatVote::NONE;
|
|
|
|
currentVoteParameter = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::abortVoting()
|
|
|
|
{
|
|
|
|
broadcastSystemMessage("Player voted against change. Voting aborted");
|
|
|
|
currentVote = ECurrentChatVote::NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::startVoting(PlayerColor initiator, ECurrentChatVote what, int parameter)
|
|
|
|
{
|
|
|
|
currentVote = what;
|
|
|
|
currentVoteParameter = parameter;
|
|
|
|
|
|
|
|
switch(currentVote)
|
|
|
|
{
|
|
|
|
case ECurrentChatVote::SIMTURNS_ALLOW:
|
|
|
|
broadcastSystemMessage("Started voting to allow simultaneous turns for " + std::to_string(parameter) + " more days");
|
|
|
|
break;
|
|
|
|
case ECurrentChatVote::SIMTURNS_FORCE:
|
|
|
|
broadcastSystemMessage("Started voting to force simultaneous turns for " + std::to_string(parameter) + " more days");
|
|
|
|
break;
|
|
|
|
case ECurrentChatVote::SIMTURNS_ABORT:
|
|
|
|
broadcastSystemMessage("Started voting to end simultaneous turns starting from next day");
|
|
|
|
break;
|
|
|
|
case ECurrentChatVote::TIMER_PROLONG:
|
|
|
|
broadcastSystemMessage("Started voting to prolong timer for all players by " + std::to_string(parameter) + " seconds");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
broadcastSystemMessage("Type '!vote yes' to agree to this change or '!vote no' to vote against it");
|
|
|
|
awaitingPlayers.clear();
|
|
|
|
|
|
|
|
for(PlayerColor player(0); player < PlayerColor::PLAYER_LIMIT; ++player)
|
|
|
|
{
|
|
|
|
auto state = gameHandler->getPlayerState(player, false);
|
|
|
|
if(state && state->isHuman() && initiator != player)
|
|
|
|
awaitingPlayers.insert(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(awaitingPlayers.empty())
|
|
|
|
finishVoting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::handleCommand(PlayerColor player, const std::string & message)
|
|
|
|
{
|
|
|
|
if(message.empty() || message[0] != '!')
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<std::string> words;
|
|
|
|
boost::split(words, message, boost::is_any_of(" "));
|
|
|
|
|
|
|
|
if(words[0] == "!exit" || words[0] == "!quit")
|
|
|
|
commandExit(player, words);
|
|
|
|
if(words[0] == "!help")
|
|
|
|
commandHelp(player, words);
|
|
|
|
if(words[0] == "!vote")
|
|
|
|
commandVote(player, words);
|
|
|
|
if(words[0] == "!kick")
|
|
|
|
commandKick(player, words);
|
|
|
|
if(words[0] == "!save")
|
|
|
|
commandSave(player, words);
|
|
|
|
if(words[0] == "!cheaters")
|
|
|
|
commandCheaters(player, words);
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatGiveSpells(PlayerColor player, const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
///Give hero spellbook
|
|
|
|
if (!hero->hasSpellbook())
|
2023-12-31 23:43:35 +02:00
|
|
|
gameHandler->giveHeroNewArtifact(hero, ArtifactID(ArtifactID::SPELLBOOK).toArtifact(), ArtifactPosition::SPELLBOOK);
|
2023-07-12 20:13:17 +02:00
|
|
|
|
|
|
|
///Give all spells with bonus (to allow banned spells)
|
2023-11-06 18:27:16 +02:00
|
|
|
GiveBonus giveBonus(GiveBonus::ETarget::OBJECT);
|
|
|
|
giveBonus.id = hero->id;
|
2023-10-21 13:50:42 +02:00
|
|
|
giveBonus.bonus = Bonus(BonusDuration::PERMANENT, BonusType::SPELLS_OF_LEVEL, BonusSource::OTHER, 0, BonusSourceID());
|
2023-07-12 20:13:17 +02:00
|
|
|
//start with level 0 to skip abilities
|
|
|
|
for (int level = 1; level <= GameConstants::SPELL_LEVELS; level++)
|
|
|
|
{
|
2023-10-21 13:50:42 +02:00
|
|
|
giveBonus.bonus.subtype = BonusCustomSubtype::spellLevel(level);
|
2023-07-12 20:13:17 +02:00
|
|
|
gameHandler->sendAndApply(&giveBonus);
|
|
|
|
}
|
|
|
|
|
|
|
|
///Give mana
|
|
|
|
SetMana sm;
|
|
|
|
sm.hid = hero->id;
|
|
|
|
sm.val = 999;
|
|
|
|
sm.absolute = true;
|
|
|
|
gameHandler->sendAndApply(&sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatBuildTown(PlayerColor player, const CGTownInstance * town)
|
|
|
|
{
|
|
|
|
if (!town)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (auto & build : town->town->buildings)
|
|
|
|
{
|
|
|
|
if (!town->hasBuilt(build.first)
|
|
|
|
&& !build.second->getNameTranslated().empty()
|
|
|
|
&& build.first != BuildingID::SHIP)
|
|
|
|
{
|
|
|
|
gameHandler->buildStructure(town->id, build.first, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatGiveArmy(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
|
|
|
|
{
|
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string creatureIdentifier = words.empty() ? "archangel" : words[0];
|
|
|
|
std::optional<int> amountPerSlot;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
amountPerSlot = std::stol(words.at(1));
|
|
|
|
}
|
2023-07-24 17:24:23 +02:00
|
|
|
catch(std::logic_error&)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
std::optional<int32_t> creatureId = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), "creature", creatureIdentifier, false);
|
2023-07-12 20:13:17 +02:00
|
|
|
|
|
|
|
if(creatureId.has_value())
|
|
|
|
{
|
|
|
|
const auto * creature = CreatureID(creatureId.value()).toCreature();
|
|
|
|
|
|
|
|
for (int i = 0; i < GameConstants::ARMY_SIZE; i++)
|
|
|
|
{
|
|
|
|
if (!hero->hasStackAtSlot(SlotID(i)))
|
|
|
|
{
|
|
|
|
if (amountPerSlot.has_value())
|
|
|
|
gameHandler->insertNewStack(StackLocation(hero, SlotID(i)), creature, *amountPerSlot);
|
|
|
|
else
|
|
|
|
gameHandler->insertNewStack(StackLocation(hero, SlotID(i)), creature, 5 * std::pow(10, i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatGiveMachines(PlayerColor player, const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!hero->getArt(ArtifactPosition::MACH1))
|
2023-12-31 23:43:35 +02:00
|
|
|
gameHandler->giveHeroNewArtifact(hero, ArtifactID(ArtifactID::BALLISTA).toArtifact(), ArtifactPosition::MACH1);
|
2023-07-12 20:13:17 +02:00
|
|
|
if (!hero->getArt(ArtifactPosition::MACH2))
|
2023-12-31 23:43:35 +02:00
|
|
|
gameHandler->giveHeroNewArtifact(hero, ArtifactID(ArtifactID::AMMO_CART).toArtifact(), ArtifactPosition::MACH2);
|
2023-07-12 20:13:17 +02:00
|
|
|
if (!hero->getArt(ArtifactPosition::MACH3))
|
2023-12-31 23:43:35 +02:00
|
|
|
gameHandler->giveHeroNewArtifact(hero, ArtifactID(ArtifactID::FIRST_AID_TENT).toArtifact(), ArtifactPosition::MACH3);
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 19:20:12 +02:00
|
|
|
void PlayerMessageProcessor::cheatGiveArtifacts(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
2023-08-17 19:20:12 +02:00
|
|
|
if (!words.empty())
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
2023-08-17 19:20:12 +02:00
|
|
|
for (auto const & word : words)
|
|
|
|
{
|
|
|
|
auto artID = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), "artifact", word, false);
|
|
|
|
if(artID && VLC->arth->objects[*artID])
|
2023-12-31 23:43:35 +02:00
|
|
|
gameHandler->giveHeroNewArtifact(hero, ArtifactID(*artID).toArtifact(), ArtifactPosition::FIRST_AVAILABLE);
|
2023-08-17 19:20:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int g = 7; g < VLC->arth->objects.size(); ++g) //including artifacts from mods
|
|
|
|
{
|
|
|
|
if(VLC->arth->objects[g]->canBePutAt(hero))
|
2023-12-31 23:43:35 +02:00
|
|
|
gameHandler->giveHeroNewArtifact(hero, ArtifactID(g).toArtifact(), ArtifactPosition::FIRST_AVAILABLE);
|
2023-08-17 19:20:12 +02:00
|
|
|
}
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatLevelup(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
|
|
|
|
{
|
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int levelsToGain;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
levelsToGain = std::stol(words.at(0));
|
|
|
|
}
|
2023-07-24 17:24:23 +02:00
|
|
|
catch(std::logic_error&)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
levelsToGain = 1;
|
|
|
|
}
|
|
|
|
|
2024-01-04 23:57:36 +02:00
|
|
|
gameHandler->giveExperience(hero, VLC->heroh->reqExp(hero->level + levelsToGain) - VLC->heroh->reqExp(hero->level));
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatExperience(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
|
|
|
|
{
|
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int expAmountProcessed;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
expAmountProcessed = std::stol(words.at(0));
|
|
|
|
}
|
2023-07-24 17:24:23 +02:00
|
|
|
catch(std::logic_error&)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
expAmountProcessed = 10000;
|
|
|
|
}
|
|
|
|
|
2024-01-04 23:57:36 +02:00
|
|
|
gameHandler->giveExperience(hero, expAmountProcessed);
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatMovement(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
|
|
|
|
{
|
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetMovePoints smp;
|
|
|
|
smp.hid = hero->id;
|
2023-12-09 02:37:11 +02:00
|
|
|
bool unlimited = false;
|
2023-07-12 20:13:17 +02:00
|
|
|
try
|
|
|
|
{
|
2024-01-16 21:02:39 +02:00
|
|
|
smp.val = std::stol(words.at(0));
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
2023-07-24 17:24:23 +02:00
|
|
|
catch(std::logic_error&)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
smp.val = 1000000;
|
2023-12-09 02:37:11 +02:00
|
|
|
unlimited = true;
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gameHandler->sendAndApply(&smp);
|
|
|
|
|
2023-11-06 18:27:16 +02:00
|
|
|
GiveBonus gb(GiveBonus::ETarget::OBJECT);
|
2023-07-12 20:13:17 +02:00
|
|
|
gb.bonus.type = BonusType::FREE_SHIP_BOARDING;
|
2023-12-09 02:37:11 +02:00
|
|
|
gb.bonus.duration = unlimited ? BonusDuration::PERMANENT : BonusDuration::ONE_DAY;
|
2023-07-12 20:13:17 +02:00
|
|
|
gb.bonus.source = BonusSource::OTHER;
|
2023-11-06 18:27:16 +02:00
|
|
|
gb.id = hero->id;
|
2023-07-12 20:13:17 +02:00
|
|
|
gameHandler->giveHeroBonus(&gb);
|
2023-12-09 02:37:11 +02:00
|
|
|
|
|
|
|
if(unlimited)
|
|
|
|
{
|
|
|
|
GiveBonus gb(GiveBonus::ETarget::OBJECT);
|
|
|
|
gb.bonus.type = BonusType::UNLIMITED_MOVEMENT;
|
|
|
|
gb.bonus.duration = BonusDuration::PERMANENT;
|
|
|
|
gb.bonus.source = BonusSource::OTHER;
|
|
|
|
gb.id = hero->id;
|
|
|
|
gameHandler->giveHeroBonus(&gb);
|
|
|
|
}
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatResources(PlayerColor player, std::vector<std::string> words)
|
|
|
|
{
|
|
|
|
int baseResourceAmount;
|
|
|
|
try
|
|
|
|
{
|
2024-01-16 21:02:39 +02:00
|
|
|
baseResourceAmount = std::stol(words.at(0));
|
2023-07-12 20:13:17 +02:00
|
|
|
}
|
2023-07-24 17:24:23 +02:00
|
|
|
catch(std::logic_error&)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
baseResourceAmount = 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
TResources resources;
|
2023-07-17 15:15:49 +02:00
|
|
|
resources[EGameResID::GOLD] = baseResourceAmount * 1000;
|
2023-07-12 20:13:17 +02:00
|
|
|
for (GameResID i = EGameResID::WOOD; i < EGameResID::GOLD; ++i)
|
|
|
|
resources[i] = baseResourceAmount;
|
|
|
|
|
|
|
|
gameHandler->giveResources(player, resources);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatVictory(PlayerColor player)
|
|
|
|
{
|
|
|
|
PlayerCheated pc;
|
|
|
|
pc.player = player;
|
|
|
|
pc.winningCheatCode = true;
|
|
|
|
gameHandler->sendAndApply(&pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatDefeat(PlayerColor player)
|
|
|
|
{
|
|
|
|
PlayerCheated pc;
|
|
|
|
pc.player = player;
|
|
|
|
pc.losingCheatCode = true;
|
|
|
|
gameHandler->sendAndApply(&pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::cheatMapReveal(PlayerColor player, bool reveal)
|
|
|
|
{
|
|
|
|
FoWChange fc;
|
2023-10-04 14:31:42 +02:00
|
|
|
fc.mode = reveal ? ETileVisibility::REVEALED : ETileVisibility::HIDDEN;
|
2023-07-12 20:13:17 +02:00
|
|
|
fc.player = player;
|
|
|
|
const auto & fowMap = gameHandler->gameState()->getPlayerTeam(player)->fogOfWarMap;
|
|
|
|
const auto & mapSize = gameHandler->gameState()->getMapSize();
|
|
|
|
auto hlp_tab = new int3[mapSize.x * mapSize.y * mapSize.z];
|
|
|
|
int lastUnc = 0;
|
|
|
|
|
|
|
|
for(int z = 0; z < mapSize.z; z++)
|
|
|
|
for(int x = 0; x < mapSize.x; x++)
|
|
|
|
for(int y = 0; y < mapSize.y; y++)
|
2023-10-04 14:31:42 +02:00
|
|
|
if(!(*fowMap)[z][x][y] || fc.mode == ETileVisibility::HIDDEN)
|
2023-07-12 20:13:17 +02:00
|
|
|
hlp_tab[lastUnc++] = int3(x, y, z);
|
|
|
|
|
|
|
|
fc.tiles.insert(hlp_tab, hlp_tab + lastUnc);
|
|
|
|
delete [] hlp_tab;
|
|
|
|
gameHandler->sendAndApply(&fc);
|
|
|
|
}
|
|
|
|
|
2023-12-08 18:30:23 +02:00
|
|
|
void PlayerMessageProcessor::cheatPuzzleReveal(PlayerColor player)
|
|
|
|
{
|
|
|
|
TeamState *t = gameHandler->gameState()->getPlayerTeam(player);
|
|
|
|
|
|
|
|
for(auto & obj : gameHandler->gameState()->map->objects)
|
|
|
|
{
|
2024-01-13 17:05:12 +02:00
|
|
|
if(obj && obj->ID == Obj::OBELISK && !obj->wasVisited(player))
|
2023-12-08 18:30:23 +02:00
|
|
|
{
|
|
|
|
gameHandler->setObjPropertyID(obj->id, ObjProperty::OBELISK_VISITED, t->id);
|
|
|
|
for(const auto & color : t->players)
|
|
|
|
{
|
|
|
|
gameHandler->setObjPropertyID(obj->id, ObjProperty::VISITED, color);
|
2023-12-08 21:13:32 +02:00
|
|
|
|
|
|
|
PlayerCheated pc;
|
|
|
|
pc.player = color;
|
|
|
|
gameHandler->sendAndApply(&pc);
|
2023-12-08 18:30:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 20:20:53 +02:00
|
|
|
void PlayerMessageProcessor::cheatMaxLuck(PlayerColor player, const CGHeroInstance * hero)
|
|
|
|
{
|
2023-12-08 20:37:34 +02:00
|
|
|
if (!hero)
|
|
|
|
return;
|
2023-12-09 01:44:53 +02:00
|
|
|
|
2023-12-08 20:20:53 +02:00
|
|
|
GiveBonus gb;
|
|
|
|
gb.bonus = Bonus(BonusDuration::PERMANENT, BonusType::MAX_LUCK, BonusSource::OTHER, 0, BonusSourceID(Obj(Obj::NO_OBJ)));
|
|
|
|
gb.id = hero->id;
|
|
|
|
|
|
|
|
gameHandler->giveHeroBonus(&gb);
|
|
|
|
}
|
|
|
|
|
2023-12-09 01:44:53 +02:00
|
|
|
void PlayerMessageProcessor::cheatFly(PlayerColor player, const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GiveBonus gb;
|
|
|
|
gb.bonus = Bonus(BonusDuration::PERMANENT, BonusType::FLYING_MOVEMENT, BonusSource::OTHER, 0, BonusSourceID(Obj(Obj::NO_OBJ)));
|
|
|
|
gb.id = hero->id;
|
|
|
|
|
|
|
|
gameHandler->giveHeroBonus(&gb);
|
|
|
|
}
|
|
|
|
|
2023-12-08 20:20:53 +02:00
|
|
|
void PlayerMessageProcessor::cheatMaxMorale(PlayerColor player, const CGHeroInstance * hero)
|
|
|
|
{
|
2023-12-08 20:37:34 +02:00
|
|
|
if (!hero)
|
|
|
|
return;
|
|
|
|
|
2023-12-08 20:20:53 +02:00
|
|
|
GiveBonus gb;
|
|
|
|
gb.bonus = Bonus(BonusDuration::PERMANENT, BonusType::MAX_MORALE, BonusSource::OTHER, 0, BonusSourceID(Obj(Obj::NO_OBJ)));
|
|
|
|
gb.id = hero->id;
|
|
|
|
|
|
|
|
gameHandler->giveHeroBonus(&gb);
|
|
|
|
}
|
|
|
|
|
2023-07-12 20:13:17 +02:00
|
|
|
bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerColor player, ObjectInstanceID currObj)
|
|
|
|
{
|
|
|
|
std::vector<std::string> words;
|
2024-04-09 16:08:24 +02:00
|
|
|
boost::split(words, boost::trim_copy(cheat), boost::is_any_of("\t\r\n "));
|
2023-07-12 20:13:17 +02:00
|
|
|
|
2023-12-28 21:48:19 +02:00
|
|
|
if (words.empty() || !gameHandler->getStartInfo()->extraOptionsInfo.cheatsAllowed)
|
2023-07-12 20:13:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
//Make cheat name case-insensitive, but keep words/parameters (e.g. creature name) as it
|
|
|
|
std::string cheatName = boost::to_lower_copy(words[0]);
|
|
|
|
words.erase(words.begin());
|
|
|
|
|
|
|
|
std::vector<std::string> townTargetedCheats = { "vcmiarmenelos", "vcmibuild", "nwczion" };
|
|
|
|
std::vector<std::string> playerTargetedCheats = {
|
|
|
|
"vcmiformenos", "vcmiresources", "nwctheconstruct",
|
|
|
|
"vcmimelkor", "vcmilose", "nwcbluepill",
|
|
|
|
"vcmisilmaril", "vcmiwin", "nwcredpill",
|
|
|
|
"vcmieagles", "vcmimap", "nwcwhatisthematrix",
|
2023-12-08 18:30:23 +02:00
|
|
|
"vcmiungoliant", "vcmihidemap", "nwcignoranceisbliss",
|
2023-12-09 16:07:27 +02:00
|
|
|
"vcmiobelisk", "nwcoracle"
|
2023-07-12 20:13:17 +02:00
|
|
|
};
|
|
|
|
std::vector<std::string> heroTargetedCheats = {
|
2023-12-09 16:07:27 +02:00
|
|
|
"vcmiainur", "vcmiarchangel", "nwctrinity",
|
|
|
|
"vcmiangband", "vcmiblackknight", "nwcagents",
|
|
|
|
"vcmiglaurung", "vcmicrystal", "vcmiazure",
|
|
|
|
"vcmifaerie", "vcmiarmy", "vcminissi",
|
|
|
|
"vcmiistari", "vcmispells", "nwcthereisnospoon",
|
|
|
|
"vcminoldor", "vcmimachines", "nwclotsofguns",
|
|
|
|
"vcmiglorfindel", "vcmilevel", "nwcneo",
|
|
|
|
"vcminahar", "vcmimove", "nwcnebuchadnezzar",
|
|
|
|
"vcmiforgeofnoldorking", "vcmiartifacts",
|
|
|
|
"vcmiolorin", "vcmiexp",
|
|
|
|
"vcmiluck", "nwcfollowthewhiterabbit",
|
|
|
|
"vcmimorale", "nwcmorpheus",
|
|
|
|
"vcmigod", "nwctheone"
|
2023-07-12 20:13:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!vstd::contains(townTargetedCheats, cheatName) && !vstd::contains(playerTargetedCheats, cheatName) && !vstd::contains(heroTargetedCheats, cheatName))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool playerTargetedCheat = false;
|
|
|
|
|
|
|
|
for (const auto & i : gameHandler->gameState()->players)
|
|
|
|
{
|
2023-07-12 21:17:46 +02:00
|
|
|
if (words.empty())
|
|
|
|
break;
|
|
|
|
|
2023-07-12 20:13:17 +02:00
|
|
|
if (i.first == PlayerColor::NEUTRAL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (words.front() == "ai" && i.second.human)
|
|
|
|
continue;
|
|
|
|
|
2023-09-04 21:21:02 +02:00
|
|
|
if (words.front() != "all" && words.front() != i.first.toString())
|
2023-07-12 20:13:17 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
std::vector<std::string> parameters = words;
|
|
|
|
|
2023-09-25 18:06:40 +02:00
|
|
|
PlayerCheated pc;
|
|
|
|
pc.player = i.first;
|
|
|
|
gameHandler->sendAndApply(&pc);
|
|
|
|
|
2023-07-12 20:13:17 +02:00
|
|
|
playerTargetedCheat = true;
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
|
|
|
|
if (vstd::contains(playerTargetedCheats, cheatName))
|
|
|
|
executeCheatCode(cheatName, i.first, ObjectInstanceID::NONE, parameters);
|
|
|
|
|
|
|
|
if (vstd::contains(townTargetedCheats, cheatName))
|
|
|
|
for (const auto & t : i.second.towns)
|
|
|
|
executeCheatCode(cheatName, i.first, t->id, parameters);
|
|
|
|
|
|
|
|
if (vstd::contains(heroTargetedCheats, cheatName))
|
|
|
|
for (const auto & h : i.second.heroes)
|
|
|
|
executeCheatCode(cheatName, i.first, h->id, parameters);
|
|
|
|
}
|
|
|
|
|
2023-09-25 18:06:40 +02:00
|
|
|
PlayerCheated pc;
|
|
|
|
pc.player = player;
|
|
|
|
gameHandler->sendAndApply(&pc);
|
|
|
|
|
2023-09-26 12:01:16 +02:00
|
|
|
if (!playerTargetedCheat)
|
|
|
|
executeCheatCode(cheatName, player, currObj, words);
|
|
|
|
|
2023-07-12 20:13:17 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & words)
|
|
|
|
{
|
|
|
|
const CGHeroInstance * hero = gameHandler->getHero(currObj);
|
|
|
|
const CGTownInstance * town = gameHandler->getTown(currObj);
|
|
|
|
if (!town && hero)
|
|
|
|
town = hero->visitedTown;
|
|
|
|
|
|
|
|
const auto & doCheatGiveSpells = [&]() { cheatGiveSpells(player, hero); };
|
|
|
|
const auto & doCheatBuildTown = [&]() { cheatBuildTown(player, town); };
|
|
|
|
const auto & doCheatGiveArmyCustom = [&]() { cheatGiveArmy(player, hero, words); };
|
|
|
|
const auto & doCheatGiveArmyFixed = [&](std::vector<std::string> customWords) { cheatGiveArmy(player, hero, customWords); };
|
|
|
|
const auto & doCheatGiveMachines = [&]() { cheatGiveMachines(player, hero); };
|
2023-08-17 19:20:12 +02:00
|
|
|
const auto & doCheatGiveArtifacts = [&]() { cheatGiveArtifacts(player, hero, words); };
|
2023-07-12 20:13:17 +02:00
|
|
|
const auto & doCheatLevelup = [&]() { cheatLevelup(player, hero, words); };
|
|
|
|
const auto & doCheatExperience = [&]() { cheatExperience(player, hero, words); };
|
|
|
|
const auto & doCheatMovement = [&]() { cheatMovement(player, hero, words); };
|
|
|
|
const auto & doCheatResources = [&]() { cheatResources(player, words); };
|
|
|
|
const auto & doCheatVictory = [&]() { cheatVictory(player); };
|
|
|
|
const auto & doCheatDefeat = [&]() { cheatDefeat(player); };
|
|
|
|
const auto & doCheatMapReveal = [&]() { cheatMapReveal(player, true); };
|
|
|
|
const auto & doCheatMapHide = [&]() { cheatMapReveal(player, false); };
|
2023-12-08 18:30:23 +02:00
|
|
|
const auto & doCheatRevealPuzzle = [&]() { cheatPuzzleReveal(player); };
|
2023-12-08 20:20:53 +02:00
|
|
|
const auto & doCheatMaxLuck = [&]() { cheatMaxLuck(player, hero); };
|
|
|
|
const auto & doCheatMaxMorale = [&]() { cheatMaxMorale(player, hero); };
|
2023-12-09 01:44:53 +02:00
|
|
|
const auto & doCheatTheOne = [&]()
|
|
|
|
{
|
|
|
|
if(!hero)
|
|
|
|
return;
|
|
|
|
cheatMapReveal(player, true);
|
|
|
|
cheatGiveArmy(player, hero, { "archangel", "5" });
|
|
|
|
cheatMovement(player, hero, { });
|
|
|
|
cheatFly(player, hero);
|
|
|
|
};
|
2023-07-12 20:13:17 +02:00
|
|
|
|
|
|
|
// Unimplemented H3 cheats:
|
|
|
|
// nwcphisherprice - Changes and brightens the game colors.
|
|
|
|
|
|
|
|
std::map<std::string, std::function<void()>> callbacks = {
|
2023-12-08 20:20:53 +02:00
|
|
|
{"vcmiainur", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
|
|
|
|
{"nwctrinity", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
|
|
|
|
{"vcmiangband", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
|
|
|
|
{"vcmiglaurung", [&] () {doCheatGiveArmyFixed({ "crystalDragon", "5000" });} },
|
|
|
|
{"vcmiarchangel", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
|
|
|
|
{"nwcagents", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
|
|
|
|
{"vcmiblackknight", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
|
|
|
|
{"vcmicrystal", [&] () {doCheatGiveArmyFixed({ "crystalDragon", "5000" });} },
|
|
|
|
{"vcmiazure", [&] () {doCheatGiveArmyFixed({ "azureDragon", "5000" });} },
|
|
|
|
{"vcmifaerie", [&] () {doCheatGiveArmyFixed({ "fairieDragon", "5000" });} },
|
|
|
|
{"vcmiarmy", doCheatGiveArmyCustom },
|
|
|
|
{"vcminissi", doCheatGiveArmyCustom },
|
|
|
|
{"vcmiistari", doCheatGiveSpells },
|
|
|
|
{"vcmispells", doCheatGiveSpells },
|
|
|
|
{"nwcthereisnospoon", doCheatGiveSpells },
|
|
|
|
{"vcmiarmenelos", doCheatBuildTown },
|
|
|
|
{"vcmibuild", doCheatBuildTown },
|
|
|
|
{"nwczion", doCheatBuildTown },
|
|
|
|
{"vcminoldor", doCheatGiveMachines },
|
|
|
|
{"vcmimachines", doCheatGiveMachines },
|
|
|
|
{"nwclotsofguns", doCheatGiveMachines },
|
|
|
|
{"vcmiforgeofnoldorking", doCheatGiveArtifacts },
|
|
|
|
{"vcmiartifacts", doCheatGiveArtifacts },
|
|
|
|
{"vcmiglorfindel", doCheatLevelup },
|
|
|
|
{"vcmilevel", doCheatLevelup },
|
|
|
|
{"nwcneo", doCheatLevelup },
|
|
|
|
{"vcmiolorin", doCheatExperience },
|
|
|
|
{"vcmiexp", doCheatExperience },
|
|
|
|
{"vcminahar", doCheatMovement },
|
|
|
|
{"vcmimove", doCheatMovement },
|
|
|
|
{"nwcnebuchadnezzar", doCheatMovement },
|
|
|
|
{"vcmiformenos", doCheatResources },
|
|
|
|
{"vcmiresources", doCheatResources },
|
|
|
|
{"nwctheconstruct", doCheatResources },
|
|
|
|
{"nwcbluepill", doCheatDefeat },
|
|
|
|
{"vcmimelkor", doCheatDefeat },
|
|
|
|
{"vcmilose", doCheatDefeat },
|
|
|
|
{"nwcredpill", doCheatVictory },
|
|
|
|
{"vcmisilmaril", doCheatVictory },
|
|
|
|
{"vcmiwin", doCheatVictory },
|
|
|
|
{"nwcwhatisthematrix", doCheatMapReveal },
|
|
|
|
{"vcmieagles", doCheatMapReveal },
|
|
|
|
{"vcmimap", doCheatMapReveal },
|
|
|
|
{"vcmiungoliant", doCheatMapHide },
|
|
|
|
{"vcmihidemap", doCheatMapHide },
|
|
|
|
{"nwcignoranceisbliss", doCheatMapHide },
|
2023-12-09 16:07:27 +02:00
|
|
|
{"vcmiobelisk", doCheatRevealPuzzle },
|
2023-12-08 20:20:53 +02:00
|
|
|
{"nwcoracle", doCheatRevealPuzzle },
|
2023-12-09 16:07:27 +02:00
|
|
|
{"vcmiluck", doCheatMaxLuck },
|
2023-12-08 20:20:53 +02:00
|
|
|
{"nwcfollowthewhiterabbit", doCheatMaxLuck },
|
2023-12-09 16:07:27 +02:00
|
|
|
{"vcmimorale", doCheatMaxMorale },
|
2023-12-08 20:20:53 +02:00
|
|
|
{"nwcmorpheus", doCheatMaxMorale },
|
2023-12-09 16:07:27 +02:00
|
|
|
{"vcmigod", doCheatTheOne },
|
2023-12-09 01:44:53 +02:00
|
|
|
{"nwctheone", doCheatTheOne },
|
2023-07-12 20:13:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
assert(callbacks.count(cheatName));
|
|
|
|
if (callbacks.count(cheatName))
|
|
|
|
callbacks.at(cheatName)();
|
|
|
|
}
|
|
|
|
|
2024-05-02 21:03:23 +02:00
|
|
|
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, MetaString message)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
SystemMessage sm;
|
|
|
|
sm.text = message;
|
|
|
|
connection->sendPack(&sm);
|
|
|
|
}
|
|
|
|
|
2024-05-02 21:03:23 +02:00
|
|
|
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message)
|
|
|
|
{
|
|
|
|
MetaString str;
|
|
|
|
str.appendRawString(message);
|
|
|
|
sendSystemMessage(connection, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerMessageProcessor::broadcastSystemMessage(MetaString message)
|
2023-07-12 20:13:17 +02:00
|
|
|
{
|
|
|
|
SystemMessage sm;
|
|
|
|
sm.text = message;
|
|
|
|
gameHandler->sendToAllClients(&sm);
|
|
|
|
}
|
|
|
|
|
2024-05-02 21:03:23 +02:00
|
|
|
void PlayerMessageProcessor::broadcastSystemMessage(const std::string & message)
|
|
|
|
{
|
|
|
|
MetaString str;
|
|
|
|
str.appendRawString(message);
|
|
|
|
broadcastSystemMessage(str);
|
|
|
|
}
|
|
|
|
|
2023-07-12 20:13:17 +02:00
|
|
|
void PlayerMessageProcessor::broadcastMessage(PlayerColor playerSender, const std::string & message)
|
|
|
|
{
|
|
|
|
PlayerMessageClient temp_message(playerSender, message);
|
|
|
|
gameHandler->sendAndApply(&temp_message);
|
|
|
|
}
|