remoteplayer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #ifndef REMOTEPLAYER_HEADER
  18. #define REMOTEPLAYER_HEADER
  19. #include "player.h"
  20. class PlayerSAO;
  21. enum RemotePlayerChatResult {
  22. RPLAYER_CHATRESULT_OK,
  23. RPLAYER_CHATRESULT_FLOODING,
  24. RPLAYER_CHATRESULT_KICK,
  25. };
  26. /*
  27. Player on the server
  28. */
  29. class RemotePlayer : public Player
  30. {
  31. public:
  32. RemotePlayer(const char *name, IItemDefManager *idef);
  33. virtual ~RemotePlayer() {}
  34. void save(std::string savedir, IGameDef *gamedef);
  35. void deSerialize(std::istream &is, const std::string &playername, PlayerSAO *sao);
  36. PlayerSAO *getPlayerSAO() { return m_sao; }
  37. void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
  38. const RemotePlayerChatResult canSendChatMessage();
  39. void setHotbarItemcount(s32 hotbar_itemcount)
  40. {
  41. hud_hotbar_itemcount = hotbar_itemcount;
  42. }
  43. s32 getHotbarItemcount() const { return hud_hotbar_itemcount; }
  44. void overrideDayNightRatio(bool do_override, float ratio)
  45. {
  46. m_day_night_ratio_do_override = do_override;
  47. m_day_night_ratio = ratio;
  48. }
  49. void getDayNightRatio(bool *do_override, float *ratio)
  50. {
  51. *do_override = m_day_night_ratio_do_override;
  52. *ratio = m_day_night_ratio;
  53. }
  54. void setHotbarImage(const std::string &name)
  55. {
  56. hud_hotbar_image = name;
  57. }
  58. std::string getHotbarImage() const
  59. {
  60. return hud_hotbar_image;
  61. }
  62. void setHotbarSelectedImage(const std::string &name)
  63. {
  64. hud_hotbar_selected_image = name;
  65. }
  66. const std::string &getHotbarSelectedImage() const
  67. {
  68. return hud_hotbar_selected_image;
  69. }
  70. void setSky(const video::SColor &bgcolor, const std::string &type,
  71. const std::vector<std::string> &params)
  72. {
  73. m_sky_bgcolor = bgcolor;
  74. m_sky_type = type;
  75. m_sky_params = params;
  76. }
  77. void getSky(video::SColor *bgcolor, std::string *type,
  78. std::vector<std::string> *params)
  79. {
  80. *bgcolor = m_sky_bgcolor;
  81. *type = m_sky_type;
  82. *params = m_sky_params;
  83. }
  84. bool checkModified() const { return m_dirty || inventory.checkModified(); }
  85. void setModified(const bool x)
  86. {
  87. m_dirty = x;
  88. if (!x)
  89. inventory.setModified(x);
  90. }
  91. void setLocalAnimations(v2s32 frames[4], float frame_speed)
  92. {
  93. for (int i = 0; i < 4; i++)
  94. local_animations[i] = frames[i];
  95. local_animation_speed = frame_speed;
  96. }
  97. void getLocalAnimations(v2s32 *frames, float *frame_speed)
  98. {
  99. for (int i = 0; i < 4; i++)
  100. frames[i] = local_animations[i];
  101. *frame_speed = local_animation_speed;
  102. }
  103. void setDirty(bool dirty) { m_dirty = true; }
  104. u16 protocol_version;
  105. private:
  106. /*
  107. serialize() writes a bunch of text that can contain
  108. any characters except a '\0', and such an ending that
  109. deSerialize stops reading exactly at the right point.
  110. */
  111. void serialize(std::ostream &os);
  112. PlayerSAO *m_sao;
  113. bool m_dirty;
  114. static bool m_setting_cache_loaded;
  115. static float m_setting_chat_message_limit_per_10sec;
  116. static u16 m_setting_chat_message_limit_trigger_kick;
  117. u32 m_last_chat_message_sent;
  118. float m_chat_message_allowance;
  119. u16 m_message_rate_overhead;
  120. bool m_day_night_ratio_do_override;
  121. float m_day_night_ratio;
  122. std::string hud_hotbar_image;
  123. std::string hud_hotbar_selected_image;
  124. std::string m_sky_type;
  125. video::SColor m_sky_bgcolor;
  126. std::vector<std::string> m_sky_params;
  127. };
  128. #endif