PlayerMessageProcessor.cpp 20 KB

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