PlayerMessageProcessor.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * CGameHandler.h, 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. #pragma once
  11. #include "../../lib/GameConstants.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class CGHeroInstance;
  14. class CGTownInstance;
  15. class CConnection;
  16. class MetaString;
  17. VCMI_LIB_NAMESPACE_END
  18. class CGameHandler;
  19. enum class ECurrentChatVote : int8_t
  20. {
  21. NONE = -1,
  22. SIMTURNS_ALLOW,
  23. SIMTURNS_FORCE,
  24. SIMTURNS_ABORT,
  25. TIMER_PROLONG,
  26. };
  27. class PlayerMessageProcessor
  28. {
  29. CGameHandler * gameHandler;
  30. ECurrentChatVote currentVote = ECurrentChatVote::NONE;
  31. int currentVoteParameter = 0;
  32. std::set<PlayerColor> awaitingPlayers;
  33. void executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & arguments );
  34. bool handleCheatCode(const std::string & cheatFullCommand, PlayerColor player, ObjectInstanceID currObj);
  35. void handleCommand(PlayerColor player, const std::string & message);
  36. void cheatGiveSpells(PlayerColor player, const CGHeroInstance * hero);
  37. void cheatBuildTown(PlayerColor player, const CGTownInstance * town);
  38. void cheatGiveArmy(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words);
  39. void cheatGiveMachines(PlayerColor player, const CGHeroInstance * hero);
  40. void cheatGiveArtifacts(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words);
  41. void cheatGiveScrolls(PlayerColor player, const CGHeroInstance * hero);
  42. void cheatLevelup(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words);
  43. void cheatExperience(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words);
  44. void cheatMovement(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words);
  45. void cheatResources(PlayerColor player, std::vector<std::string> words);
  46. void cheatVictory(PlayerColor player);
  47. void cheatDefeat(PlayerColor player);
  48. void cheatMapReveal(PlayerColor player, bool reveal);
  49. void cheatPuzzleReveal(PlayerColor player);
  50. void cheatMaxLuck(PlayerColor player, const CGHeroInstance * hero);
  51. void cheatMaxMorale(PlayerColor player, const CGHeroInstance * hero);
  52. void cheatFly(PlayerColor player, const CGHeroInstance * hero);
  53. void commandExit(PlayerColor player, const std::vector<std::string> & words);
  54. void commandKick(PlayerColor player, const std::vector<std::string> & words);
  55. void commandSave(PlayerColor player, const std::vector<std::string> & words);
  56. void commandCheaters(PlayerColor player, const std::vector<std::string> & words);
  57. void commandStatistic(PlayerColor player, const std::vector<std::string> & words);
  58. void commandHelp(PlayerColor player, const std::vector<std::string> & words);
  59. void commandVote(PlayerColor player, const std::vector<std::string> & words);
  60. void finishVoting();
  61. void abortVoting();
  62. void startVoting(PlayerColor initiator, ECurrentChatVote what, int parameter);
  63. public:
  64. PlayerMessageProcessor(CGameHandler * gameHandler);
  65. /// incoming NetPack handling
  66. void playerMessage(PlayerColor player, const std::string & message, ObjectInstanceID currObj);
  67. /// Send message to specific client with "System" as sender
  68. void sendSystemMessage(std::shared_ptr<CConnection> connection, const MetaString & message);
  69. void sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message);
  70. /// Send message to all players with "System" as sender
  71. void broadcastSystemMessage(MetaString message);
  72. void broadcastSystemMessage(const std::string & message);
  73. /// Send message from specific player to all other players
  74. void broadcastMessage(PlayerColor playerSender, const std::string & message);
  75. template <typename Handler> void serialize(Handler &h)
  76. {
  77. }
  78. };