PlayerMessageProcessor.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*
  2. * CGameHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "PlayerMessageProcessor.h"
  12. #include "../CGameHandler.h"
  13. #include "../CVCMIServer.h"
  14. #include "../../lib/CGeneralTextHandler.h"
  15. #include "../../lib/CHeroHandler.h"
  16. #include "../../lib/modding/IdentifierStorage.h"
  17. #include "../../lib/CPlayerState.h"
  18. #include "../../lib/GameConstants.h"
  19. #include "../../lib/StartInfo.h"
  20. #include "../../lib/gameState/CGameState.h"
  21. #include "../../lib/mapObjects/CGTownInstance.h"
  22. #include "../../lib/mapObjects/CGHeroInstance.h"
  23. #include "../../lib/modding/IdentifierStorage.h"
  24. #include "../../lib/modding/ModScope.h"
  25. #include "../../lib/mapping/CMap.h"
  26. #include "../../lib/networkPacks/PacksForClient.h"
  27. #include "../../lib/networkPacks/StackLocation.h"
  28. #include "../../lib/serializer/Connection.h"
  29. PlayerMessageProcessor::PlayerMessageProcessor(CGameHandler * gameHandler)
  30. :gameHandler(gameHandler)
  31. {
  32. }
  33. void PlayerMessageProcessor::playerMessage(PlayerColor player, const std::string &message, ObjectInstanceID currObj)
  34. {
  35. if (handleHostCommand(player, message))
  36. return;
  37. if (handleCheatCode(message, player, currObj))
  38. {
  39. if(!gameHandler->getPlayerSettings(player)->isControlledByAI())
  40. broadcastSystemMessage(VLC->generaltexth->allTexts[260]);
  41. if(!player.isSpectator())
  42. gameHandler->checkVictoryLossConditionsForPlayer(player);//Player enter win code or got required art\creature
  43. return;
  44. }
  45. broadcastMessage(player, message);
  46. }
  47. bool PlayerMessageProcessor::handleHostCommand(PlayerColor player, const std::string &message)
  48. {
  49. std::vector<std::string> words;
  50. boost::split(words, message, boost::is_any_of(" "));
  51. bool isHost = gameHandler->gameLobby()->isPlayerHost(player);
  52. if(!isHost || words.size() < 2 || words[0] != "game")
  53. return false;
  54. if(words[1] == "exit" || words[1] == "quit" || words[1] == "end")
  55. {
  56. broadcastSystemMessage("game was terminated");
  57. gameHandler->gameLobby()->setState(EServerState::SHUTDOWN);
  58. return true;
  59. }
  60. if(words.size() == 3 && words[1] == "save")
  61. {
  62. gameHandler->save("Saves/" + words[2]);
  63. broadcastSystemMessage("game saved as " + words[2]);
  64. return true;
  65. }
  66. if(words.size() == 3 && words[1] == "kick")
  67. {
  68. auto playername = words[2];
  69. PlayerColor playerToKick(PlayerColor::CANNOT_DETERMINE);
  70. if(std::all_of(playername.begin(), playername.end(), ::isdigit))
  71. playerToKick = PlayerColor(std::stoi(playername));
  72. else
  73. {
  74. for(auto & c : gameHandler->connections)
  75. {
  76. if(c.first.toString() == playername)
  77. playerToKick = c.first;
  78. }
  79. }
  80. if(playerToKick != PlayerColor::CANNOT_DETERMINE)
  81. {
  82. PlayerCheated pc;
  83. pc.player = playerToKick;
  84. pc.losingCheatCode = true;
  85. gameHandler->sendAndApply(&pc);
  86. gameHandler->checkVictoryLossConditionsForPlayer(playerToKick);
  87. }
  88. return true;
  89. }
  90. if(words.size() == 2 && words[1] == "cheaters")
  91. {
  92. int playersCheated = 0;
  93. for (const auto & player : gameHandler->gameState()->players)
  94. {
  95. if(player.second.cheated)
  96. {
  97. broadcastSystemMessage("Player " + player.first.toString() + " is cheater!");
  98. playersCheated++;
  99. }
  100. }
  101. if (!playersCheated)
  102. broadcastSystemMessage("No cheaters registered!");
  103. return true;
  104. }
  105. return false;
  106. }
  107. void PlayerMessageProcessor::cheatGiveSpells(PlayerColor player, const CGHeroInstance * hero)
  108. {
  109. if (!hero)
  110. return;
  111. ///Give hero spellbook
  112. if (!hero->hasSpellbook())
  113. gameHandler->giveHeroNewArtifact(hero, ArtifactID(ArtifactID::SPELLBOOK).toArtifact(), ArtifactPosition::SPELLBOOK);
  114. ///Give all spells with bonus (to allow banned spells)
  115. GiveBonus giveBonus(GiveBonus::ETarget::OBJECT);
  116. giveBonus.id = hero->id;
  117. giveBonus.bonus = Bonus(BonusDuration::PERMANENT, BonusType::SPELLS_OF_LEVEL, BonusSource::OTHER, 0, BonusSourceID());
  118. //start with level 0 to skip abilities
  119. for (int level = 1; level <= GameConstants::SPELL_LEVELS; level++)
  120. {
  121. giveBonus.bonus.subtype = BonusCustomSubtype::spellLevel(level);
  122. gameHandler->sendAndApply(&giveBonus);
  123. }
  124. ///Give mana
  125. SetMana sm;
  126. sm.hid = hero->id;
  127. sm.val = 999;
  128. sm.absolute = true;
  129. gameHandler->sendAndApply(&sm);
  130. }
  131. void PlayerMessageProcessor::cheatBuildTown(PlayerColor player, const CGTownInstance * town)
  132. {
  133. if (!town)
  134. return;
  135. for (auto & build : town->town->buildings)
  136. {
  137. if (!town->hasBuilt(build.first)
  138. && !build.second->getNameTranslated().empty()
  139. && build.first != BuildingID::SHIP)
  140. {
  141. gameHandler->buildStructure(town->id, build.first, true);
  142. }
  143. }
  144. }
  145. void PlayerMessageProcessor::cheatGiveArmy(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
  146. {
  147. if (!hero)
  148. return;
  149. std::string creatureIdentifier = words.empty() ? "archangel" : words[0];
  150. std::optional<int> amountPerSlot;
  151. try
  152. {
  153. amountPerSlot = std::stol(words.at(1));
  154. }
  155. catch(std::logic_error&)
  156. {
  157. }
  158. std::optional<int32_t> creatureId = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), "creature", creatureIdentifier, false);
  159. if(creatureId.has_value())
  160. {
  161. const auto * creature = CreatureID(creatureId.value()).toCreature();
  162. for (int i = 0; i < GameConstants::ARMY_SIZE; i++)
  163. {
  164. if (!hero->hasStackAtSlot(SlotID(i)))
  165. {
  166. if (amountPerSlot.has_value())
  167. gameHandler->insertNewStack(StackLocation(hero, SlotID(i)), creature, *amountPerSlot);
  168. else
  169. gameHandler->insertNewStack(StackLocation(hero, SlotID(i)), creature, 5 * std::pow(10, i));
  170. }
  171. }
  172. }
  173. }
  174. void PlayerMessageProcessor::cheatGiveMachines(PlayerColor player, const CGHeroInstance * hero)
  175. {
  176. if (!hero)
  177. return;
  178. if (!hero->getArt(ArtifactPosition::MACH1))
  179. gameHandler->giveHeroNewArtifact(hero, ArtifactID(ArtifactID::BALLISTA).toArtifact(), ArtifactPosition::MACH1);
  180. if (!hero->getArt(ArtifactPosition::MACH2))
  181. gameHandler->giveHeroNewArtifact(hero, ArtifactID(ArtifactID::AMMO_CART).toArtifact(), ArtifactPosition::MACH2);
  182. if (!hero->getArt(ArtifactPosition::MACH3))
  183. gameHandler->giveHeroNewArtifact(hero, ArtifactID(ArtifactID::FIRST_AID_TENT).toArtifact(), ArtifactPosition::MACH3);
  184. }
  185. void PlayerMessageProcessor::cheatGiveArtifacts(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
  186. {
  187. if (!hero)
  188. return;
  189. if (!words.empty())
  190. {
  191. for (auto const & word : words)
  192. {
  193. auto artID = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), "artifact", word, false);
  194. if(artID && VLC->arth->objects[*artID])
  195. gameHandler->giveHeroNewArtifact(hero, ArtifactID(*artID).toArtifact(), ArtifactPosition::FIRST_AVAILABLE);
  196. }
  197. }
  198. else
  199. {
  200. for(int g = 7; g < VLC->arth->objects.size(); ++g) //including artifacts from mods
  201. {
  202. if(VLC->arth->objects[g]->canBePutAt(hero))
  203. gameHandler->giveHeroNewArtifact(hero, ArtifactID(g).toArtifact(), ArtifactPosition::FIRST_AVAILABLE);
  204. }
  205. }
  206. }
  207. void PlayerMessageProcessor::cheatLevelup(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
  208. {
  209. if (!hero)
  210. return;
  211. int levelsToGain;
  212. try
  213. {
  214. levelsToGain = std::stol(words.at(0));
  215. }
  216. catch(std::logic_error&)
  217. {
  218. levelsToGain = 1;
  219. }
  220. gameHandler->giveExperience(hero, VLC->heroh->reqExp(hero->level + levelsToGain) - VLC->heroh->reqExp(hero->level));
  221. }
  222. void PlayerMessageProcessor::cheatExperience(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
  223. {
  224. if (!hero)
  225. return;
  226. int expAmountProcessed;
  227. try
  228. {
  229. expAmountProcessed = std::stol(words.at(0));
  230. }
  231. catch(std::logic_error&)
  232. {
  233. expAmountProcessed = 10000;
  234. }
  235. gameHandler->giveExperience(hero, expAmountProcessed);
  236. }
  237. void PlayerMessageProcessor::cheatMovement(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words)
  238. {
  239. if (!hero)
  240. return;
  241. SetMovePoints smp;
  242. smp.hid = hero->id;
  243. bool unlimited = false;
  244. try
  245. {
  246. smp.val = std::stol(words.at(0));
  247. }
  248. catch(std::logic_error&)
  249. {
  250. smp.val = 1000000;
  251. unlimited = true;
  252. }
  253. gameHandler->sendAndApply(&smp);
  254. GiveBonus gb(GiveBonus::ETarget::OBJECT);
  255. gb.bonus.type = BonusType::FREE_SHIP_BOARDING;
  256. gb.bonus.duration = unlimited ? BonusDuration::PERMANENT : BonusDuration::ONE_DAY;
  257. gb.bonus.source = BonusSource::OTHER;
  258. gb.id = hero->id;
  259. gameHandler->giveHeroBonus(&gb);
  260. if(unlimited)
  261. {
  262. GiveBonus gb(GiveBonus::ETarget::OBJECT);
  263. gb.bonus.type = BonusType::UNLIMITED_MOVEMENT;
  264. gb.bonus.duration = BonusDuration::PERMANENT;
  265. gb.bonus.source = BonusSource::OTHER;
  266. gb.id = hero->id;
  267. gameHandler->giveHeroBonus(&gb);
  268. }
  269. }
  270. void PlayerMessageProcessor::cheatResources(PlayerColor player, std::vector<std::string> words)
  271. {
  272. int baseResourceAmount;
  273. try
  274. {
  275. baseResourceAmount = std::stol(words.at(0));
  276. }
  277. catch(std::logic_error&)
  278. {
  279. baseResourceAmount = 100;
  280. }
  281. TResources resources;
  282. resources[EGameResID::GOLD] = baseResourceAmount * 1000;
  283. for (GameResID i = EGameResID::WOOD; i < EGameResID::GOLD; ++i)
  284. resources[i] = baseResourceAmount;
  285. gameHandler->giveResources(player, resources);
  286. }
  287. void PlayerMessageProcessor::cheatVictory(PlayerColor player)
  288. {
  289. PlayerCheated pc;
  290. pc.player = player;
  291. pc.winningCheatCode = true;
  292. gameHandler->sendAndApply(&pc);
  293. }
  294. void PlayerMessageProcessor::cheatDefeat(PlayerColor player)
  295. {
  296. PlayerCheated pc;
  297. pc.player = player;
  298. pc.losingCheatCode = true;
  299. gameHandler->sendAndApply(&pc);
  300. }
  301. void PlayerMessageProcessor::cheatMapReveal(PlayerColor player, bool reveal)
  302. {
  303. FoWChange fc;
  304. fc.mode = reveal ? ETileVisibility::REVEALED : ETileVisibility::HIDDEN;
  305. fc.player = player;
  306. const auto & fowMap = gameHandler->gameState()->getPlayerTeam(player)->fogOfWarMap;
  307. const auto & mapSize = gameHandler->gameState()->getMapSize();
  308. auto hlp_tab = new int3[mapSize.x * mapSize.y * mapSize.z];
  309. int lastUnc = 0;
  310. for(int z = 0; z < mapSize.z; z++)
  311. for(int x = 0; x < mapSize.x; x++)
  312. for(int y = 0; y < mapSize.y; y++)
  313. if(!(*fowMap)[z][x][y] || fc.mode == ETileVisibility::HIDDEN)
  314. hlp_tab[lastUnc++] = int3(x, y, z);
  315. fc.tiles.insert(hlp_tab, hlp_tab + lastUnc);
  316. delete [] hlp_tab;
  317. gameHandler->sendAndApply(&fc);
  318. }
  319. void PlayerMessageProcessor::cheatPuzzleReveal(PlayerColor player)
  320. {
  321. TeamState *t = gameHandler->gameState()->getPlayerTeam(player);
  322. for(auto & obj : gameHandler->gameState()->map->objects)
  323. {
  324. if(obj && obj->ID == Obj::OBELISK && !obj->wasVisited(player))
  325. {
  326. gameHandler->setObjPropertyID(obj->id, ObjProperty::OBELISK_VISITED, t->id);
  327. for(const auto & color : t->players)
  328. {
  329. gameHandler->setObjPropertyID(obj->id, ObjProperty::VISITED, color);
  330. PlayerCheated pc;
  331. pc.player = color;
  332. gameHandler->sendAndApply(&pc);
  333. }
  334. }
  335. }
  336. }
  337. void PlayerMessageProcessor::cheatMaxLuck(PlayerColor player, const CGHeroInstance * hero)
  338. {
  339. if (!hero)
  340. return;
  341. GiveBonus gb;
  342. gb.bonus = Bonus(BonusDuration::PERMANENT, BonusType::MAX_LUCK, BonusSource::OTHER, 0, BonusSourceID(Obj(Obj::NO_OBJ)));
  343. gb.id = hero->id;
  344. gameHandler->giveHeroBonus(&gb);
  345. }
  346. void PlayerMessageProcessor::cheatFly(PlayerColor player, const CGHeroInstance * hero)
  347. {
  348. if (!hero)
  349. return;
  350. GiveBonus gb;
  351. gb.bonus = Bonus(BonusDuration::PERMANENT, BonusType::FLYING_MOVEMENT, BonusSource::OTHER, 0, BonusSourceID(Obj(Obj::NO_OBJ)));
  352. gb.id = hero->id;
  353. gameHandler->giveHeroBonus(&gb);
  354. }
  355. void PlayerMessageProcessor::cheatMaxMorale(PlayerColor player, const CGHeroInstance * hero)
  356. {
  357. if (!hero)
  358. return;
  359. GiveBonus gb;
  360. gb.bonus = Bonus(BonusDuration::PERMANENT, BonusType::MAX_MORALE, BonusSource::OTHER, 0, BonusSourceID(Obj(Obj::NO_OBJ)));
  361. gb.id = hero->id;
  362. gameHandler->giveHeroBonus(&gb);
  363. }
  364. bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerColor player, ObjectInstanceID currObj)
  365. {
  366. std::vector<std::string> words;
  367. boost::split(words, boost::trim_copy(cheat), boost::is_any_of("\t\r\n "));
  368. if (words.empty() || !gameHandler->getStartInfo()->extraOptionsInfo.cheatsAllowed)
  369. return false;
  370. //Make cheat name case-insensitive, but keep words/parameters (e.g. creature name) as it
  371. std::string cheatName = boost::to_lower_copy(words[0]);
  372. words.erase(words.begin());
  373. std::vector<std::string> townTargetedCheats = { "vcmiarmenelos", "vcmibuild", "nwczion" };
  374. std::vector<std::string> playerTargetedCheats = {
  375. "vcmiformenos", "vcmiresources", "nwctheconstruct",
  376. "vcmimelkor", "vcmilose", "nwcbluepill",
  377. "vcmisilmaril", "vcmiwin", "nwcredpill",
  378. "vcmieagles", "vcmimap", "nwcwhatisthematrix",
  379. "vcmiungoliant", "vcmihidemap", "nwcignoranceisbliss",
  380. "vcmiobelisk", "nwcoracle"
  381. };
  382. std::vector<std::string> heroTargetedCheats = {
  383. "vcmiainur", "vcmiarchangel", "nwctrinity",
  384. "vcmiangband", "vcmiblackknight", "nwcagents",
  385. "vcmiglaurung", "vcmicrystal", "vcmiazure",
  386. "vcmifaerie", "vcmiarmy", "vcminissi",
  387. "vcmiistari", "vcmispells", "nwcthereisnospoon",
  388. "vcminoldor", "vcmimachines", "nwclotsofguns",
  389. "vcmiglorfindel", "vcmilevel", "nwcneo",
  390. "vcminahar", "vcmimove", "nwcnebuchadnezzar",
  391. "vcmiforgeofnoldorking", "vcmiartifacts",
  392. "vcmiolorin", "vcmiexp",
  393. "vcmiluck", "nwcfollowthewhiterabbit",
  394. "vcmimorale", "nwcmorpheus",
  395. "vcmigod", "nwctheone"
  396. };
  397. if (!vstd::contains(townTargetedCheats, cheatName) && !vstd::contains(playerTargetedCheats, cheatName) && !vstd::contains(heroTargetedCheats, cheatName))
  398. return false;
  399. bool playerTargetedCheat = false;
  400. for (const auto & i : gameHandler->gameState()->players)
  401. {
  402. if (words.empty())
  403. break;
  404. if (i.first == PlayerColor::NEUTRAL)
  405. continue;
  406. if (words.front() == "ai" && i.second.human)
  407. continue;
  408. if (words.front() != "all" && words.front() != i.first.toString())
  409. continue;
  410. std::vector<std::string> parameters = words;
  411. PlayerCheated pc;
  412. pc.player = i.first;
  413. gameHandler->sendAndApply(&pc);
  414. playerTargetedCheat = true;
  415. parameters.erase(parameters.begin());
  416. if (vstd::contains(playerTargetedCheats, cheatName))
  417. executeCheatCode(cheatName, i.first, ObjectInstanceID::NONE, parameters);
  418. if (vstd::contains(townTargetedCheats, cheatName))
  419. for (const auto & t : i.second.towns)
  420. executeCheatCode(cheatName, i.first, t->id, parameters);
  421. if (vstd::contains(heroTargetedCheats, cheatName))
  422. for (const auto & h : i.second.heroes)
  423. executeCheatCode(cheatName, i.first, h->id, parameters);
  424. }
  425. PlayerCheated pc;
  426. pc.player = player;
  427. gameHandler->sendAndApply(&pc);
  428. if (!playerTargetedCheat)
  429. executeCheatCode(cheatName, player, currObj, words);
  430. return true;
  431. }
  432. void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & words)
  433. {
  434. const CGHeroInstance * hero = gameHandler->getHero(currObj);
  435. const CGTownInstance * town = gameHandler->getTown(currObj);
  436. if (!town && hero)
  437. town = hero->visitedTown;
  438. const auto & doCheatGiveSpells = [&]() { cheatGiveSpells(player, hero); };
  439. const auto & doCheatBuildTown = [&]() { cheatBuildTown(player, town); };
  440. const auto & doCheatGiveArmyCustom = [&]() { cheatGiveArmy(player, hero, words); };
  441. const auto & doCheatGiveArmyFixed = [&](std::vector<std::string> customWords) { cheatGiveArmy(player, hero, customWords); };
  442. const auto & doCheatGiveMachines = [&]() { cheatGiveMachines(player, hero); };
  443. const auto & doCheatGiveArtifacts = [&]() { cheatGiveArtifacts(player, hero, words); };
  444. const auto & doCheatLevelup = [&]() { cheatLevelup(player, hero, words); };
  445. const auto & doCheatExperience = [&]() { cheatExperience(player, hero, words); };
  446. const auto & doCheatMovement = [&]() { cheatMovement(player, hero, words); };
  447. const auto & doCheatResources = [&]() { cheatResources(player, words); };
  448. const auto & doCheatVictory = [&]() { cheatVictory(player); };
  449. const auto & doCheatDefeat = [&]() { cheatDefeat(player); };
  450. const auto & doCheatMapReveal = [&]() { cheatMapReveal(player, true); };
  451. const auto & doCheatMapHide = [&]() { cheatMapReveal(player, false); };
  452. const auto & doCheatRevealPuzzle = [&]() { cheatPuzzleReveal(player); };
  453. const auto & doCheatMaxLuck = [&]() { cheatMaxLuck(player, hero); };
  454. const auto & doCheatMaxMorale = [&]() { cheatMaxMorale(player, hero); };
  455. const auto & doCheatTheOne = [&]()
  456. {
  457. if(!hero)
  458. return;
  459. cheatMapReveal(player, true);
  460. cheatGiveArmy(player, hero, { "archangel", "5" });
  461. cheatMovement(player, hero, { });
  462. cheatFly(player, hero);
  463. };
  464. // Unimplemented H3 cheats:
  465. // nwcphisherprice - Changes and brightens the game colors.
  466. std::map<std::string, std::function<void()>> callbacks = {
  467. {"vcmiainur", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  468. {"nwctrinity", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  469. {"vcmiangband", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  470. {"vcmiglaurung", [&] () {doCheatGiveArmyFixed({ "crystalDragon", "5000" });} },
  471. {"vcmiarchangel", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  472. {"nwcagents", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  473. {"vcmiblackknight", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  474. {"vcmicrystal", [&] () {doCheatGiveArmyFixed({ "crystalDragon", "5000" });} },
  475. {"vcmiazure", [&] () {doCheatGiveArmyFixed({ "azureDragon", "5000" });} },
  476. {"vcmifaerie", [&] () {doCheatGiveArmyFixed({ "fairieDragon", "5000" });} },
  477. {"vcmiarmy", doCheatGiveArmyCustom },
  478. {"vcminissi", doCheatGiveArmyCustom },
  479. {"vcmiistari", doCheatGiveSpells },
  480. {"vcmispells", doCheatGiveSpells },
  481. {"nwcthereisnospoon", doCheatGiveSpells },
  482. {"vcmiarmenelos", doCheatBuildTown },
  483. {"vcmibuild", doCheatBuildTown },
  484. {"nwczion", doCheatBuildTown },
  485. {"vcminoldor", doCheatGiveMachines },
  486. {"vcmimachines", doCheatGiveMachines },
  487. {"nwclotsofguns", doCheatGiveMachines },
  488. {"vcmiforgeofnoldorking", doCheatGiveArtifacts },
  489. {"vcmiartifacts", doCheatGiveArtifacts },
  490. {"vcmiglorfindel", doCheatLevelup },
  491. {"vcmilevel", doCheatLevelup },
  492. {"nwcneo", doCheatLevelup },
  493. {"vcmiolorin", doCheatExperience },
  494. {"vcmiexp", doCheatExperience },
  495. {"vcminahar", doCheatMovement },
  496. {"vcmimove", doCheatMovement },
  497. {"nwcnebuchadnezzar", doCheatMovement },
  498. {"vcmiformenos", doCheatResources },
  499. {"vcmiresources", doCheatResources },
  500. {"nwctheconstruct", doCheatResources },
  501. {"nwcbluepill", doCheatDefeat },
  502. {"vcmimelkor", doCheatDefeat },
  503. {"vcmilose", doCheatDefeat },
  504. {"nwcredpill", doCheatVictory },
  505. {"vcmisilmaril", doCheatVictory },
  506. {"vcmiwin", doCheatVictory },
  507. {"nwcwhatisthematrix", doCheatMapReveal },
  508. {"vcmieagles", doCheatMapReveal },
  509. {"vcmimap", doCheatMapReveal },
  510. {"vcmiungoliant", doCheatMapHide },
  511. {"vcmihidemap", doCheatMapHide },
  512. {"nwcignoranceisbliss", doCheatMapHide },
  513. {"vcmiobelisk", doCheatRevealPuzzle },
  514. {"nwcoracle", doCheatRevealPuzzle },
  515. {"vcmiluck", doCheatMaxLuck },
  516. {"nwcfollowthewhiterabbit", doCheatMaxLuck },
  517. {"vcmimorale", doCheatMaxMorale },
  518. {"nwcmorpheus", doCheatMaxMorale },
  519. {"vcmigod", doCheatTheOne },
  520. {"nwctheone", doCheatTheOne },
  521. };
  522. assert(callbacks.count(cheatName));
  523. if (callbacks.count(cheatName))
  524. callbacks.at(cheatName)();
  525. }
  526. void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message)
  527. {
  528. SystemMessage sm;
  529. sm.text = message;
  530. connection->sendPack(&sm);
  531. }
  532. void PlayerMessageProcessor::broadcastSystemMessage(const std::string & message)
  533. {
  534. SystemMessage sm;
  535. sm.text = message;
  536. gameHandler->sendToAllClients(&sm);
  537. }
  538. void PlayerMessageProcessor::broadcastMessage(PlayerColor playerSender, const std::string & message)
  539. {
  540. PlayerMessageClient temp_message(playerSender, message);
  541. gameHandler->sendAndApply(&temp_message);
  542. }