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