remoteplayer.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 "skyparams.h"
  20. #include "lighting.h"
  21. class PlayerSAO;
  22. enum RemotePlayerChatResult
  23. {
  24. RPLAYER_CHATRESULT_OK,
  25. RPLAYER_CHATRESULT_FLOODING,
  26. RPLAYER_CHATRESULT_KICK,
  27. };
  28. /*
  29. Player on the server
  30. */
  31. class RemotePlayer : public Player
  32. {
  33. friend class PlayerDatabaseFiles;
  34. public:
  35. RemotePlayer(const char *name, IItemDefManager *idef);
  36. virtual ~RemotePlayer();
  37. PlayerSAO *getPlayerSAO() { return m_sao; }
  38. void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
  39. 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 SkyboxParams &skybox_params)
  66. {
  67. m_skybox_params = skybox_params;
  68. }
  69. const SkyboxParams &getSkyParams() const { return m_skybox_params; }
  70. void setSun(const SunParams &sun_params) { m_sun_params = sun_params; }
  71. const SunParams &getSunParams() const { return m_sun_params; }
  72. void setMoon(const MoonParams &moon_params) { m_moon_params = moon_params; }
  73. const MoonParams &getMoonParams() const { return m_moon_params; }
  74. void setStars(const StarParams &star_params) { m_star_params = star_params; }
  75. const StarParams &getStarParams() const { return m_star_params; }
  76. void setCloudParams(const CloudParams &cloud_params)
  77. {
  78. m_cloud_params = cloud_params;
  79. }
  80. const CloudParams &getCloudParams() const { return m_cloud_params; }
  81. bool checkModified() const { return m_dirty || inventory.checkModified(); }
  82. inline void setModified(const bool x) { m_dirty = x; }
  83. void setLocalAnimations(v2s32 frames[4], float frame_speed)
  84. {
  85. for (int i = 0; i < 4; i++)
  86. local_animations[i] = frames[i];
  87. local_animation_speed = frame_speed;
  88. }
  89. void getLocalAnimations(v2s32 *frames, float *frame_speed)
  90. {
  91. for (int i = 0; i < 4; i++)
  92. frames[i] = local_animations[i];
  93. *frame_speed = local_animation_speed;
  94. }
  95. void setLighting(const Lighting &lighting) { m_lighting = lighting; }
  96. const Lighting& getLighting() const { return m_lighting; }
  97. void setDirty(bool dirty) { m_dirty = true; }
  98. u16 protocol_version = 0;
  99. u16 formspec_version = 0;
  100. /// returns PEER_ID_INEXISTENT when PlayerSAO is not ready
  101. session_t getPeerId() const { return m_peer_id; }
  102. void setPeerId(session_t peer_id) { m_peer_id = peer_id; }
  103. void onSuccessfulSave();
  104. private:
  105. PlayerSAO *m_sao = nullptr;
  106. bool m_dirty = false;
  107. static bool m_setting_cache_loaded;
  108. static float m_setting_chat_message_limit_per_10sec;
  109. static u16 m_setting_chat_message_limit_trigger_kick;
  110. u32 m_last_chat_message_sent = std::time(0);
  111. float m_chat_message_allowance = 5.0f;
  112. u16 m_message_rate_overhead = 0;
  113. bool m_day_night_ratio_do_override = false;
  114. float m_day_night_ratio;
  115. std::string hud_hotbar_image = "";
  116. std::string hud_hotbar_selected_image = "";
  117. CloudParams m_cloud_params;
  118. SkyboxParams m_skybox_params;
  119. SunParams m_sun_params;
  120. MoonParams m_moon_params;
  121. StarParams m_star_params;
  122. Lighting m_lighting;
  123. session_t m_peer_id = PEER_ID_INEXISTENT;
  124. };