PlayerMessageProcessor.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 cheatLevelup(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words);
  42. void cheatExperience(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words);
  43. void cheatMovement(PlayerColor player, const CGHeroInstance * hero, std::vector<std::string> words);
  44. void cheatResources(PlayerColor player, std::vector<std::string> words);
  45. void cheatVictory(PlayerColor player);
  46. void cheatDefeat(PlayerColor player);
  47. void cheatMapReveal(PlayerColor player, bool reveal);
  48. void cheatPuzzleReveal(PlayerColor player);
  49. void cheatMaxLuck(PlayerColor player, const CGHeroInstance * hero);
  50. void cheatMaxMorale(PlayerColor player, const CGHeroInstance * hero);
  51. void cheatFly(PlayerColor player, const CGHeroInstance * hero);
  52. void commandExit(PlayerColor player, const std::vector<std::string> & words);
  53. void commandKick(PlayerColor player, const std::vector<std::string> & words);
  54. void commandSave(PlayerColor player, const std::vector<std::string> & words);
  55. void commandCheaters(PlayerColor player, const std::vector<std::string> & words);
  56. void commandHelp(PlayerColor player, const std::vector<std::string> & words);
  57. void commandVote(PlayerColor player, const std::vector<std::string> & words);
  58. void finishVoting();
  59. void abortVoting();
  60. void startVoting(PlayerColor initiator, ECurrentChatVote what, int parameter);
  61. public:
  62. PlayerMessageProcessor(CGameHandler * gameHandler);
  63. /// incoming NetPack handling
  64. void playerMessage(PlayerColor player, const std::string & message, ObjectInstanceID currObj);
  65. /// Send message to specific client with "System" as sender
  66. void sendSystemMessage(std::shared_ptr<CConnection> connection, const MetaString & message);
  67. void sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message);
  68. /// Send message to all players with "System" as sender
  69. void broadcastSystemMessage(MetaString message);
  70. void broadcastSystemMessage(const std::string & message);
  71. /// Send message from specific player to all other players
  72. void broadcastMessage(PlayerColor playerSender, const std::string & message);
  73. template <typename Handler> void serialize(Handler &h)
  74. {
  75. }
  76. };