remoteplayer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2016 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. Copyright (C) 2014-2016 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2.1 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #pragma once
  18. #include "player.h"
  19. #include "cloudparams.h"
  20. class PlayerSAO;
  21. enum RemotePlayerChatResult
  22. {
  23. RPLAYER_CHATRESULT_OK,
  24. RPLAYER_CHATRESULT_FLOODING,
  25. RPLAYER_CHATRESULT_KICK,
  26. };
  27. /*
  28. Player on the server
  29. */
  30. class RemotePlayer : public Player
  31. {
  32. friend class PlayerDatabaseFiles;
  33. public:
  34. RemotePlayer(const char *name, IItemDefManager *idef);
  35. virtual ~RemotePlayer() = default;
  36. void deSerialize(std::istream &is, const std::string &playername, PlayerSAO *sao);
  37. PlayerSAO *getPlayerSAO() { return m_sao; }
  38. void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
  39. const RemotePlayerChatResult canSendChatMessage();
  40. void setHotbarItemcount(s32 hotbar_itemcount)
  41. {
  42. hud_hotbar_itemcount = hotbar_itemcount;
  43. }
  44. s32 getHotbarItemcount() const { return hud_hotbar_itemcount; }
  45. void overrideDayNightRatio(bool do_override, float ratio)
  46. {
  47. m_day_night_ratio_do_override = do_override;
  48. m_day_night_ratio = ratio;
  49. }
  50. void getDayNightRatio(bool *do_override, float *ratio)
  51. {
  52. *do_override = m_day_night_ratio_do_override;
  53. *ratio = m_day_night_ratio;
  54. }
  55. void setHotbarImage(const std::string &name) { hud_hotbar_image = name; }
  56. const std::string &getHotbarImage() const { return hud_hotbar_image; }
  57. void setHotbarSelectedImage(const std::string &name)
  58. {
  59. hud_hotbar_selected_image = name;
  60. }
  61. const std::string &getHotbarSelectedImage() const
  62. {
  63. return hud_hotbar_selected_image;
  64. }
  65. void setSky(const video::SColor &bgcolor, const std::string &type,
  66. const std::vector<std::string> &params, bool &clouds)
  67. {
  68. m_sky_bgcolor = bgcolor;
  69. m_sky_type = type;
  70. m_sky_params = params;
  71. m_sky_clouds = clouds;
  72. }
  73. void getSky(video::SColor *bgcolor, std::string *type,
  74. std::vector<std::string> *params, bool *clouds)
  75. {
  76. *bgcolor = m_sky_bgcolor;
  77. *type = m_sky_type;
  78. *params = m_sky_params;
  79. *clouds = m_sky_clouds;
  80. }
  81. void setCloudParams(const CloudParams &cloud_params)
  82. {
  83. m_cloud_params = cloud_params;
  84. }
  85. const CloudParams &getCloudParams() const { return m_cloud_params; }
  86. bool checkModified() const { return m_dirty || inventory.checkModified(); }
  87. void setModified(const bool x)
  88. {
  89. m_dirty = x;
  90. if (!x)
  91. inventory.setModified(x);
  92. }
  93. void setLocalAnimations(v2s32 frames[4], float frame_speed)
  94. {
  95. for (int i = 0; i < 4; i++)
  96. local_animations[i] = frames[i];
  97. local_animation_speed = frame_speed;
  98. }
  99. void getLocalAnimations(v2s32 *frames, float *frame_speed)
  100. {
  101. for (int i = 0; i < 4; i++)
  102. frames[i] = local_animations[i];
  103. *frame_speed = local_animation_speed;
  104. }
  105. void setDirty(bool dirty) { m_dirty = true; }
  106. u16 protocol_version = 0;
  107. session_t getPeerId() const { return m_peer_id; }
  108. void setPeerId(session_t peer_id) { m_peer_id = peer_id; }
  109. private:
  110. /*
  111. serialize() writes a bunch of text that can contain
  112. any characters except a '\0', and such an ending that
  113. deSerialize stops reading exactly at the right point.
  114. */
  115. void serialize(std::ostream &os);
  116. void serializeExtraAttributes(std::string &output);
  117. PlayerSAO *m_sao = nullptr;
  118. bool m_dirty = false;
  119. static bool m_setting_cache_loaded;
  120. static float m_setting_chat_message_limit_per_10sec;
  121. static u16 m_setting_chat_message_limit_trigger_kick;
  122. u32 m_last_chat_message_sent = std::time(0);
  123. float m_chat_message_allowance = 5.0f;
  124. u16 m_message_rate_overhead = 0;
  125. bool m_day_night_ratio_do_override = false;
  126. float m_day_night_ratio;
  127. std::string hud_hotbar_image = "";
  128. std::string hud_hotbar_selected_image = "";
  129. std::string m_sky_type;
  130. video::SColor m_sky_bgcolor;
  131. std::vector<std::string> m_sky_params;
  132. bool m_sky_clouds;
  133. CloudParams m_cloud_params;
  134. session_t m_peer_id = PEER_ID_INEXISTENT;
  135. };