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