PlayerSAO/LocalPlayer refactor: (#4612)
[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, PlayerSAO *sao);
44
45         PlayerSAO *getPlayerSAO() { return m_sao; }
46         void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
47
48         const RemotePlayerChatResult canSendChatMessage();
49
50         void setHotbarItemcount(s32 hotbar_itemcount)
51         {
52                 hud_hotbar_itemcount = hotbar_itemcount;
53         }
54
55         s32 getHotbarItemcount() const { return hud_hotbar_itemcount; }
56
57         void overrideDayNightRatio(bool do_override, float ratio)
58         {
59                 m_day_night_ratio_do_override = do_override;
60                 m_day_night_ratio = ratio;
61         }
62
63         void getDayNightRatio(bool *do_override, float *ratio)
64         {
65                 *do_override = m_day_night_ratio_do_override;
66                 *ratio = m_day_night_ratio;
67         }
68
69         void setHotbarImage(const std::string &name)
70         {
71                 hud_hotbar_image = name;
72         }
73
74         std::string getHotbarImage() const
75         {
76                 return hud_hotbar_image;
77         }
78
79         void setHotbarSelectedImage(const std::string &name)
80         {
81                 hud_hotbar_selected_image = name;
82         }
83
84         const std::string &getHotbarSelectedImage() const
85         {
86                 return hud_hotbar_selected_image;
87         }
88
89         void setSky(const video::SColor &bgcolor, const std::string &type,
90                                 const std::vector<std::string> &params)
91         {
92                 m_sky_bgcolor = bgcolor;
93                 m_sky_type = type;
94                 m_sky_params = params;
95         }
96
97         void getSky(video::SColor *bgcolor, std::string *type,
98                                 std::vector<std::string> *params)
99         {
100                 *bgcolor = m_sky_bgcolor;
101                 *type = m_sky_type;
102                 *params = m_sky_params;
103         }
104
105         bool checkModified() const { return m_dirty || inventory.checkModified(); }
106
107         void setModified(const bool x)
108         {
109                 m_dirty = x;
110                 if (!x)
111                         inventory.setModified(x);
112         }
113
114         void setLocalAnimations(v2s32 frames[4], float frame_speed)
115         {
116                 for (int i = 0; i < 4; i++)
117                         local_animations[i] = frames[i];
118                 local_animation_speed = frame_speed;
119         }
120
121         void getLocalAnimations(v2s32 *frames, float *frame_speed)
122         {
123                 for (int i = 0; i < 4; i++)
124                         frames[i] = local_animations[i];
125                 *frame_speed = local_animation_speed;
126         }
127
128         void setDirty(bool dirty) { m_dirty = true; }
129
130         u16 protocol_version;
131 private:
132         /*
133                 serialize() writes a bunch of text that can contain
134                 any characters except a '\0', and such an ending that
135                 deSerialize stops reading exactly at the right point.
136         */
137         void serialize(std::ostream &os);
138
139         PlayerSAO *m_sao;
140         bool m_dirty;
141
142         static bool m_setting_cache_loaded;
143         static float m_setting_chat_message_limit_per_10sec;
144         static u16 m_setting_chat_message_limit_trigger_kick;
145
146         u32 m_last_chat_message_sent;
147         float m_chat_message_allowance;
148         u16 m_message_rate_overhead;
149
150         bool m_day_night_ratio_do_override;
151         float m_day_night_ratio;
152         std::string hud_hotbar_image;
153         std::string hud_hotbar_selected_image;
154
155         std::string m_sky_type;
156         video::SColor m_sky_bgcolor;
157         std::vector<std::string> m_sky_params;
158 };
159
160 #endif