PlayerMessageProcessor.cpp 20 KB

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