PlayerMessageProcessor.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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. try
  250. {
  251. smp.val = std::stol(words.at(0));;
  252. }
  253. catch(std::logic_error&)
  254. {
  255. smp.val = 1000000;
  256. }
  257. gameHandler->sendAndApply(&smp);
  258. GiveBonus gb(GiveBonus::ETarget::OBJECT);
  259. gb.bonus.type = BonusType::FREE_SHIP_BOARDING;
  260. gb.bonus.duration = BonusDuration::ONE_DAY;
  261. gb.bonus.source = BonusSource::OTHER;
  262. gb.id = hero->id;
  263. gameHandler->giveHeroBonus(&gb);
  264. }
  265. void PlayerMessageProcessor::cheatResources(PlayerColor player, std::vector<std::string> words)
  266. {
  267. int baseResourceAmount;
  268. try
  269. {
  270. baseResourceAmount = std::stol(words.at(0));;
  271. }
  272. catch(std::logic_error&)
  273. {
  274. baseResourceAmount = 100;
  275. }
  276. TResources resources;
  277. resources[EGameResID::GOLD] = baseResourceAmount * 1000;
  278. for (GameResID i = EGameResID::WOOD; i < EGameResID::GOLD; ++i)
  279. resources[i] = baseResourceAmount;
  280. gameHandler->giveResources(player, resources);
  281. }
  282. void PlayerMessageProcessor::cheatVictory(PlayerColor player)
  283. {
  284. PlayerCheated pc;
  285. pc.player = player;
  286. pc.winningCheatCode = true;
  287. gameHandler->sendAndApply(&pc);
  288. }
  289. void PlayerMessageProcessor::cheatDefeat(PlayerColor player)
  290. {
  291. PlayerCheated pc;
  292. pc.player = player;
  293. pc.losingCheatCode = true;
  294. gameHandler->sendAndApply(&pc);
  295. }
  296. void PlayerMessageProcessor::cheatMapReveal(PlayerColor player, bool reveal)
  297. {
  298. FoWChange fc;
  299. fc.mode = reveal ? ETileVisibility::REVEALED : ETileVisibility::HIDDEN;
  300. fc.player = player;
  301. const auto & fowMap = gameHandler->gameState()->getPlayerTeam(player)->fogOfWarMap;
  302. const auto & mapSize = gameHandler->gameState()->getMapSize();
  303. auto hlp_tab = new int3[mapSize.x * mapSize.y * mapSize.z];
  304. int lastUnc = 0;
  305. for(int z = 0; z < mapSize.z; z++)
  306. for(int x = 0; x < mapSize.x; x++)
  307. for(int y = 0; y < mapSize.y; y++)
  308. if(!(*fowMap)[z][x][y] || fc.mode == ETileVisibility::HIDDEN)
  309. hlp_tab[lastUnc++] = int3(x, y, z);
  310. fc.tiles.insert(hlp_tab, hlp_tab + lastUnc);
  311. delete [] hlp_tab;
  312. gameHandler->sendAndApply(&fc);
  313. }
  314. void PlayerMessageProcessor::cheatPuzzleReveal(PlayerColor player)
  315. {
  316. TeamState *t = gameHandler->gameState()->getPlayerTeam(player);
  317. for(auto & obj : gameHandler->gameState()->map->objects)
  318. {
  319. if(obj->ID == Obj::OBELISK)
  320. {
  321. gameHandler->setObjPropertyID(obj->id, ObjProperty::OBELISK_VISITED, t->id);
  322. for(const auto & color : t->players)
  323. {
  324. gameHandler->setObjPropertyID(obj->id, ObjProperty::VISITED, color);
  325. }
  326. }
  327. }
  328. }
  329. void PlayerMessageProcessor::cheatMaxLuck(PlayerColor player, const CGHeroInstance * hero)
  330. {
  331. GiveBonus gb;
  332. gb.bonus = Bonus(BonusDuration::PERMANENT, BonusType::MAX_LUCK, BonusSource::OTHER, 0, BonusSourceID(Obj(Obj::NO_OBJ)));
  333. gb.id = hero->id;
  334. gameHandler->giveHeroBonus(&gb);
  335. }
  336. void PlayerMessageProcessor::cheatMaxMorale(PlayerColor player, const CGHeroInstance * hero)
  337. {
  338. GiveBonus gb;
  339. gb.bonus = Bonus(BonusDuration::PERMANENT, BonusType::MAX_MORALE, BonusSource::OTHER, 0, BonusSourceID(Obj(Obj::NO_OBJ)));
  340. gb.id = hero->id;
  341. gameHandler->giveHeroBonus(&gb);
  342. }
  343. bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerColor player, ObjectInstanceID currObj)
  344. {
  345. std::vector<std::string> words;
  346. boost::split(words, cheat, boost::is_any_of("\t\r\n "));
  347. if (words.empty())
  348. return false;
  349. //Make cheat name case-insensitive, but keep words/parameters (e.g. creature name) as it
  350. std::string cheatName = boost::to_lower_copy(words[0]);
  351. words.erase(words.begin());
  352. std::vector<std::string> townTargetedCheats = { "vcmiarmenelos", "vcmibuild", "nwczion" };
  353. std::vector<std::string> playerTargetedCheats = {
  354. "vcmiformenos", "vcmiresources", "nwctheconstruct",
  355. "vcmimelkor", "vcmilose", "nwcbluepill",
  356. "vcmisilmaril", "vcmiwin", "nwcredpill",
  357. "vcmieagles", "vcmimap", "nwcwhatisthematrix",
  358. "vcmiungoliant", "vcmihidemap", "nwcignoranceisbliss",
  359. "nwcoracle"
  360. };
  361. std::vector<std::string> heroTargetedCheats = {
  362. "vcmiainur", "vcmiarchangel", "nwctrinity",
  363. "vcmiangband", "vcmiblackknight", "nwcagents",
  364. "vcmiglaurung", "vcmicrystal", "vcmiazure",
  365. "vcmifaerie", "vcmiarmy", "vcminissi",
  366. "vcmiistari", "vcmispells", "nwcthereisnospoon",
  367. "vcminoldor", "vcmimachines", "nwclotsofguns",
  368. "vcmiglorfindel", "vcmilevel", "nwcneo",
  369. "vcminahar", "vcmimove", "nwcnebuchadnezzar",
  370. "vcmiforgeofnoldorking", "vcmiartifacts",
  371. "vcmiolorin", "vcmiexp",
  372. "nwcfollowthewhiterabbit",
  373. "nwcmorpheus"
  374. };
  375. if (!vstd::contains(townTargetedCheats, cheatName) && !vstd::contains(playerTargetedCheats, cheatName) && !vstd::contains(heroTargetedCheats, cheatName))
  376. return false;
  377. bool playerTargetedCheat = false;
  378. for (const auto & i : gameHandler->gameState()->players)
  379. {
  380. if (words.empty())
  381. break;
  382. if (i.first == PlayerColor::NEUTRAL)
  383. continue;
  384. if (words.front() == "ai" && i.second.human)
  385. continue;
  386. if (words.front() != "all" && words.front() != i.first.toString())
  387. continue;
  388. std::vector<std::string> parameters = words;
  389. PlayerCheated pc;
  390. pc.player = i.first;
  391. gameHandler->sendAndApply(&pc);
  392. playerTargetedCheat = true;
  393. parameters.erase(parameters.begin());
  394. if (vstd::contains(playerTargetedCheats, cheatName))
  395. executeCheatCode(cheatName, i.first, ObjectInstanceID::NONE, parameters);
  396. if (vstd::contains(townTargetedCheats, cheatName))
  397. for (const auto & t : i.second.towns)
  398. executeCheatCode(cheatName, i.first, t->id, parameters);
  399. if (vstd::contains(heroTargetedCheats, cheatName))
  400. for (const auto & h : i.second.heroes)
  401. executeCheatCode(cheatName, i.first, h->id, parameters);
  402. }
  403. PlayerCheated pc;
  404. pc.player = player;
  405. gameHandler->sendAndApply(&pc);
  406. if (!playerTargetedCheat)
  407. executeCheatCode(cheatName, player, currObj, words);
  408. return true;
  409. }
  410. void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & words)
  411. {
  412. const CGHeroInstance * hero = gameHandler->getHero(currObj);
  413. const CGTownInstance * town = gameHandler->getTown(currObj);
  414. if (!town && hero)
  415. town = hero->visitedTown;
  416. const auto & doCheatGiveSpells = [&]() { cheatGiveSpells(player, hero); };
  417. const auto & doCheatBuildTown = [&]() { cheatBuildTown(player, town); };
  418. const auto & doCheatGiveArmyCustom = [&]() { cheatGiveArmy(player, hero, words); };
  419. const auto & doCheatGiveArmyFixed = [&](std::vector<std::string> customWords) { cheatGiveArmy(player, hero, customWords); };
  420. const auto & doCheatGiveMachines = [&]() { cheatGiveMachines(player, hero); };
  421. const auto & doCheatGiveArtifacts = [&]() { cheatGiveArtifacts(player, hero, words); };
  422. const auto & doCheatLevelup = [&]() { cheatLevelup(player, hero, words); };
  423. const auto & doCheatExperience = [&]() { cheatExperience(player, hero, words); };
  424. const auto & doCheatMovement = [&]() { cheatMovement(player, hero, words); };
  425. const auto & doCheatResources = [&]() { cheatResources(player, words); };
  426. const auto & doCheatVictory = [&]() { cheatVictory(player); };
  427. const auto & doCheatDefeat = [&]() { cheatDefeat(player); };
  428. const auto & doCheatMapReveal = [&]() { cheatMapReveal(player, true); };
  429. const auto & doCheatMapHide = [&]() { cheatMapReveal(player, false); };
  430. const auto & doCheatRevealPuzzle = [&]() { cheatPuzzleReveal(player); };
  431. const auto & doCheatMaxLuck = [&]() { cheatMaxLuck(player, hero); };
  432. const auto & doCheatMaxMorale = [&]() { cheatMaxMorale(player, hero); };
  433. // Unimplemented H3 cheats:
  434. // nwcphisherprice - Changes and brightens the game colors.
  435. std::map<std::string, std::function<void()>> callbacks = {
  436. {"vcmiainur", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  437. {"nwctrinity", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  438. {"vcmiangband", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  439. {"vcmiglaurung", [&] () {doCheatGiveArmyFixed({ "crystalDragon", "5000" });} },
  440. {"vcmiarchangel", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  441. {"nwcagents", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  442. {"vcmiblackknight", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  443. {"vcmicrystal", [&] () {doCheatGiveArmyFixed({ "crystalDragon", "5000" });} },
  444. {"vcmiazure", [&] () {doCheatGiveArmyFixed({ "azureDragon", "5000" });} },
  445. {"vcmifaerie", [&] () {doCheatGiveArmyFixed({ "fairieDragon", "5000" });} },
  446. {"vcmiarmy", doCheatGiveArmyCustom },
  447. {"vcminissi", doCheatGiveArmyCustom },
  448. {"vcmiistari", doCheatGiveSpells },
  449. {"vcmispells", doCheatGiveSpells },
  450. {"nwcthereisnospoon", doCheatGiveSpells },
  451. {"vcmiarmenelos", doCheatBuildTown },
  452. {"vcmibuild", doCheatBuildTown },
  453. {"nwczion", doCheatBuildTown },
  454. {"vcminoldor", doCheatGiveMachines },
  455. {"vcmimachines", doCheatGiveMachines },
  456. {"nwclotsofguns", doCheatGiveMachines },
  457. {"vcmiforgeofnoldorking", doCheatGiveArtifacts },
  458. {"vcmiartifacts", doCheatGiveArtifacts },
  459. {"vcmiglorfindel", doCheatLevelup },
  460. {"vcmilevel", doCheatLevelup },
  461. {"nwcneo", doCheatLevelup },
  462. {"vcmiolorin", doCheatExperience },
  463. {"vcmiexp", doCheatExperience },
  464. {"vcminahar", doCheatMovement },
  465. {"vcmimove", doCheatMovement },
  466. {"nwcnebuchadnezzar", doCheatMovement },
  467. {"vcmiformenos", doCheatResources },
  468. {"vcmiresources", doCheatResources },
  469. {"nwctheconstruct", doCheatResources },
  470. {"nwcbluepill", doCheatDefeat },
  471. {"vcmimelkor", doCheatDefeat },
  472. {"vcmilose", doCheatDefeat },
  473. {"nwcredpill", doCheatVictory },
  474. {"vcmisilmaril", doCheatVictory },
  475. {"vcmiwin", doCheatVictory },
  476. {"nwcwhatisthematrix", doCheatMapReveal },
  477. {"vcmieagles", doCheatMapReveal },
  478. {"vcmimap", doCheatMapReveal },
  479. {"vcmiungoliant", doCheatMapHide },
  480. {"vcmihidemap", doCheatMapHide },
  481. {"nwcignoranceisbliss", doCheatMapHide },
  482. {"nwcoracle", doCheatRevealPuzzle },
  483. {"nwcfollowthewhiterabbit", doCheatMaxLuck },
  484. {"nwcmorpheus", doCheatMaxMorale },
  485. };
  486. assert(callbacks.count(cheatName));
  487. if (callbacks.count(cheatName))
  488. callbacks.at(cheatName)();
  489. }
  490. void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message)
  491. {
  492. SystemMessage sm;
  493. sm.text = message;
  494. connection->sendPack(&sm);
  495. }
  496. void PlayerMessageProcessor::broadcastSystemMessage(const std::string & message)
  497. {
  498. SystemMessage sm;
  499. sm.text = message;
  500. gameHandler->sendToAllClients(&sm);
  501. }
  502. void PlayerMessageProcessor::broadcastMessage(PlayerColor playerSender, const std::string & message)
  503. {
  504. PlayerMessageClient temp_message(playerSender, message);
  505. gameHandler->sendAndApply(&temp_message);
  506. }