PlayerMessageProcessor.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerColor player, ObjectInstanceID currObj)
  330. {
  331. std::vector<std::string> words;
  332. boost::split(words, cheat, boost::is_any_of("\t\r\n "));
  333. if (words.empty())
  334. return false;
  335. //Make cheat name case-insensitive, but keep words/parameters (e.g. creature name) as it
  336. std::string cheatName = boost::to_lower_copy(words[0]);
  337. words.erase(words.begin());
  338. std::vector<std::string> townTargetedCheats = { "vcmiarmenelos", "vcmibuild", "nwczion" };
  339. std::vector<std::string> playerTargetedCheats = {
  340. "vcmiformenos", "vcmiresources", "nwctheconstruct",
  341. "vcmimelkor", "vcmilose", "nwcbluepill",
  342. "vcmisilmaril", "vcmiwin", "nwcredpill",
  343. "vcmieagles", "vcmimap", "nwcwhatisthematrix",
  344. "vcmiungoliant", "vcmihidemap", "nwcignoranceisbliss",
  345. "nwcoracle"
  346. };
  347. std::vector<std::string> heroTargetedCheats = {
  348. "vcmiainur", "vcmiarchangel", "nwctrinity",
  349. "vcmiangband", "vcmiblackknight", "nwcagents",
  350. "vcmiglaurung", "vcmicrystal", "vcmiazure",
  351. "vcmifaerie", "vcmiarmy", "vcminissi",
  352. "vcmiistari", "vcmispells", "nwcthereisnospoon",
  353. "vcminoldor", "vcmimachines", "nwclotsofguns",
  354. "vcmiglorfindel", "vcmilevel", "nwcneo",
  355. "vcminahar", "vcmimove", "nwcnebuchadnezzar",
  356. "vcmiforgeofnoldorking", "vcmiartifacts",
  357. "vcmiolorin", "vcmiexp",
  358. };
  359. if (!vstd::contains(townTargetedCheats, cheatName) && !vstd::contains(playerTargetedCheats, cheatName) && !vstd::contains(heroTargetedCheats, cheatName))
  360. return false;
  361. bool playerTargetedCheat = false;
  362. for (const auto & i : gameHandler->gameState()->players)
  363. {
  364. if (words.empty())
  365. break;
  366. if (i.first == PlayerColor::NEUTRAL)
  367. continue;
  368. if (words.front() == "ai" && i.second.human)
  369. continue;
  370. if (words.front() != "all" && words.front() != i.first.toString())
  371. continue;
  372. std::vector<std::string> parameters = words;
  373. PlayerCheated pc;
  374. pc.player = i.first;
  375. gameHandler->sendAndApply(&pc);
  376. playerTargetedCheat = true;
  377. parameters.erase(parameters.begin());
  378. if (vstd::contains(playerTargetedCheats, cheatName))
  379. executeCheatCode(cheatName, i.first, ObjectInstanceID::NONE, parameters);
  380. if (vstd::contains(townTargetedCheats, cheatName))
  381. for (const auto & t : i.second.towns)
  382. executeCheatCode(cheatName, i.first, t->id, parameters);
  383. if (vstd::contains(heroTargetedCheats, cheatName))
  384. for (const auto & h : i.second.heroes)
  385. executeCheatCode(cheatName, i.first, h->id, parameters);
  386. }
  387. PlayerCheated pc;
  388. pc.player = player;
  389. gameHandler->sendAndApply(&pc);
  390. if (!playerTargetedCheat)
  391. executeCheatCode(cheatName, player, currObj, words);
  392. return true;
  393. }
  394. void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & words)
  395. {
  396. const CGHeroInstance * hero = gameHandler->getHero(currObj);
  397. const CGTownInstance * town = gameHandler->getTown(currObj);
  398. if (!town && hero)
  399. town = hero->visitedTown;
  400. const auto & doCheatGiveSpells = [&]() { cheatGiveSpells(player, hero); };
  401. const auto & doCheatBuildTown = [&]() { cheatBuildTown(player, town); };
  402. const auto & doCheatGiveArmyCustom = [&]() { cheatGiveArmy(player, hero, words); };
  403. const auto & doCheatGiveArmyFixed = [&](std::vector<std::string> customWords) { cheatGiveArmy(player, hero, customWords); };
  404. const auto & doCheatGiveMachines = [&]() { cheatGiveMachines(player, hero); };
  405. const auto & doCheatGiveArtifacts = [&]() { cheatGiveArtifacts(player, hero, words); };
  406. const auto & doCheatLevelup = [&]() { cheatLevelup(player, hero, words); };
  407. const auto & doCheatExperience = [&]() { cheatExperience(player, hero, words); };
  408. const auto & doCheatMovement = [&]() { cheatMovement(player, hero, words); };
  409. const auto & doCheatResources = [&]() { cheatResources(player, words); };
  410. const auto & doCheatVictory = [&]() { cheatVictory(player); };
  411. const auto & doCheatDefeat = [&]() { cheatDefeat(player); };
  412. const auto & doCheatMapReveal = [&]() { cheatMapReveal(player, true); };
  413. const auto & doCheatMapHide = [&]() { cheatMapReveal(player, false); };
  414. const auto & doCheatRevealPuzzle = [&]() { cheatPuzzleReveal(player); };
  415. // Unimplemented H3 cheats:
  416. // nwcfollowthewhiterabbit - The currently selected hero permanently gains maximum luck.
  417. // nwcmorpheus - The currently selected hero permanently gains maximum morale.
  418. // nwcphisherprice - Changes and brightens the game colors.
  419. std::map<std::string, std::function<void()>> callbacks = {
  420. {"vcmiainur", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  421. {"nwctrinity", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  422. {"vcmiangband", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  423. {"vcmiglaurung", [&] () {doCheatGiveArmyFixed({ "crystalDragon", "5000" });} },
  424. {"vcmiarchangel", [&] () {doCheatGiveArmyFixed({ "archangel", "5" });} },
  425. {"nwcagents", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  426. {"vcmiblackknight", [&] () {doCheatGiveArmyFixed({ "blackKnight", "10" });} },
  427. {"vcmicrystal", [&] () {doCheatGiveArmyFixed({ "crystalDragon", "5000" });} },
  428. {"vcmiazure", [&] () {doCheatGiveArmyFixed({ "azureDragon", "5000" });} },
  429. {"vcmifaerie", [&] () {doCheatGiveArmyFixed({ "fairieDragon", "5000" });} },
  430. {"vcmiarmy", doCheatGiveArmyCustom },
  431. {"vcminissi", doCheatGiveArmyCustom },
  432. {"vcmiistari", doCheatGiveSpells },
  433. {"vcmispells", doCheatGiveSpells },
  434. {"nwcthereisnospoon", doCheatGiveSpells },
  435. {"vcmiarmenelos", doCheatBuildTown },
  436. {"vcmibuild", doCheatBuildTown },
  437. {"nwczion", doCheatBuildTown },
  438. {"vcminoldor", doCheatGiveMachines },
  439. {"vcmimachines", doCheatGiveMachines },
  440. {"nwclotsofguns", doCheatGiveMachines },
  441. {"vcmiforgeofnoldorking", doCheatGiveArtifacts },
  442. {"vcmiartifacts", doCheatGiveArtifacts },
  443. {"vcmiglorfindel", doCheatLevelup },
  444. {"vcmilevel", doCheatLevelup },
  445. {"nwcneo", doCheatLevelup },
  446. {"vcmiolorin", doCheatExperience },
  447. {"vcmiexp", doCheatExperience },
  448. {"vcminahar", doCheatMovement },
  449. {"vcmimove", doCheatMovement },
  450. {"nwcnebuchadnezzar", doCheatMovement },
  451. {"vcmiformenos", doCheatResources },
  452. {"vcmiresources", doCheatResources },
  453. {"nwctheconstruct", doCheatResources },
  454. {"nwcbluepill", doCheatDefeat },
  455. {"vcmimelkor", doCheatDefeat },
  456. {"vcmilose", doCheatDefeat },
  457. {"nwcredpill", doCheatVictory },
  458. {"vcmisilmaril", doCheatVictory },
  459. {"vcmiwin", doCheatVictory },
  460. {"nwcwhatisthematrix", doCheatMapReveal },
  461. {"vcmieagles", doCheatMapReveal },
  462. {"vcmimap", doCheatMapReveal },
  463. {"vcmiungoliant", doCheatMapHide },
  464. {"vcmihidemap", doCheatMapHide },
  465. {"nwcignoranceisbliss", doCheatMapHide },
  466. {"nwcoracle", doCheatRevealPuzzle },
  467. };
  468. assert(callbacks.count(cheatName));
  469. if (callbacks.count(cheatName))
  470. callbacks.at(cheatName)();
  471. }
  472. void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message)
  473. {
  474. SystemMessage sm;
  475. sm.text = message;
  476. connection->sendPack(&sm);
  477. }
  478. void PlayerMessageProcessor::broadcastSystemMessage(const std::string & message)
  479. {
  480. SystemMessage sm;
  481. sm.text = message;
  482. gameHandler->sendToAllClients(&sm);
  483. }
  484. void PlayerMessageProcessor::broadcastMessage(PlayerColor playerSender, const std::string & message)
  485. {
  486. PlayerMessageClient temp_message(playerSender, message);
  487. gameHandler->sendAndApply(&temp_message);
  488. }