Move RemotePlayer code to its own cpp/header
[oweals/minetest.git] / src / remoteplayer.h
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
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #ifndef REMOTEPLAYER_HEADER
22 #define REMOTEPLAYER_HEADER
23
24 #include "player.h"
25
26 class PlayerSAO;
27
28 enum RemotePlayerChatResult {
29         RPLAYER_CHATRESULT_OK,
30         RPLAYER_CHATRESULT_FLOODING,
31         RPLAYER_CHATRESULT_KICK,
32 };
33 /*
34         Player on the server
35 */
36 class RemotePlayer : public Player
37 {
38 public:
39         RemotePlayer(const char *name, IItemDefManager *idef);
40         virtual ~RemotePlayer() {}
41
42         void save(std::string savedir, IGameDef *gamedef);
43         void deSerialize(std::istream &is, const std::string &playername);
44
45         PlayerSAO *getPlayerSAO() { return m_sao; }
46         void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
47         void setPosition(const v3f &position);
48
49         const RemotePlayerChatResult canSendChatMessage();
50
51         void setHotbarItemcount(s32 hotbar_itemcount)
52         {
53                 hud_hotbar_itemcount = hotbar_itemcount;
54         }
55
56         s32 getHotbarItemcount() const { return hud_hotbar_itemcount; }
57
58         void overrideDayNightRatio(bool do_override, float ratio)
59         {
60                 m_day_night_ratio_do_override = do_override;
61                 m_day_night_ratio = ratio;
62         }
63
64         void getDayNightRatio(bool *do_override, float *ratio)
65         {
66                 *do_override = m_day_night_ratio_do_override;
67                 *ratio = m_day_night_ratio;
68         }
69
70         // Use a function, if isDead can be defined by other conditions
71         bool isDead() const { return hp == 0; }
72
73         void setHotbarImage(const std::string &name)
74         {
75                 hud_hotbar_image = name;
76         }
77
78         std::string getHotbarImage() const
79         {
80                 return hud_hotbar_image;
81         }
82
83         void setHotbarSelectedImage(const std::string &name)
84         {
85                 hud_hotbar_selected_image = name;
86         }
87
88         const std::string &getHotbarSelectedImage() const
89         {
90                 return hud_hotbar_selected_image;
91         }
92
93         // Deprecated
94         f32 getRadPitchDep() const { return -1.0 * m_pitch * core::DEGTORAD; }
95
96         // Deprecated
97         f32 getRadYawDep() const { return (m_yaw + 90.) * core::DEGTORAD; }
98
99         void setSky(const video::SColor &bgcolor, const std::string &type,
100                                 const std::vector<std::string> &params)
101         {
102                 m_sky_bgcolor = bgcolor;
103                 m_sky_type = type;
104                 m_sky_params = params;
105         }
106
107         void getSky(video::SColor *bgcolor, std::string *type,
108                                 std::vector<std::string> *params)
109         {
110                 *bgcolor = m_sky_bgcolor;
111                 *type = m_sky_type;
112                 *params = m_sky_params;
113         }
114
115         bool checkModified() const { return m_dirty || inventory.checkModified(); }
116
117         void setModified(const bool x)
118         {
119                 m_dirty = x;
120                 if (!x)
121                         inventory.setModified(x);
122         }
123
124         virtual void setBreath(u16 breath)
125         {
126                 if (breath != m_breath)
127                         m_dirty = true;
128                 Player::setBreath(breath);
129         }
130
131         virtual void setPitch(f32 pitch)
132         {
133                 if (pitch != m_pitch)
134                         m_dirty = true;
135                 Player::setPitch(pitch);
136         }
137
138         virtual void setYaw(f32 yaw)
139         {
140                 if (yaw != m_yaw)
141                         m_dirty = true;
142                 Player::setYaw(yaw);
143         }
144
145         u16 protocol_version;
146 private:
147         /*
148                 serialize() writes a bunch of text that can contain
149                 any characters except a '\0', and such an ending that
150                 deSerialize stops reading exactly at the right point.
151         */
152         void serialize(std::ostream &os);
153
154         PlayerSAO *m_sao;
155         bool m_dirty;
156
157         static bool m_setting_cache_loaded;
158         static float m_setting_chat_message_limit_per_10sec;
159         static u16 m_setting_chat_message_limit_trigger_kick;
160
161         u32 m_last_chat_message_sent;
162         float m_chat_message_allowance;
163         u16 m_message_rate_overhead;
164
165         bool m_day_night_ratio_do_override;
166         float m_day_night_ratio;
167         std::string hud_hotbar_image;
168         std::string hud_hotbar_selected_image;
169
170         std::string m_sky_type;
171         video::SColor m_sky_bgcolor;
172         std::vector<std::string> m_sky_params;
173 };
174
175 #endif