]> git.lizzy.rs Git - dragonfireclient.git/blob - src/remoteplayer.h
260504fb4379400455a5a77ac139c34a1fb29f0b
[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 #pragma once
22
23 #include "player.h"
24 #include "cloudparams.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() = default;
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         const 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, bool &clouds)
88         {
89                 m_sky_bgcolor = bgcolor;
90                 m_sky_type = type;
91                 m_sky_params = params;
92                 m_sky_clouds = clouds;
93         }
94
95         void getSky(video::SColor *bgcolor, std::string *type,
96                         std::vector<std::string> *params, bool *clouds)
97         {
98                 *bgcolor = m_sky_bgcolor;
99                 *type = m_sky_type;
100                 *params = m_sky_params;
101                 *clouds = m_sky_clouds;
102         }
103
104         void setCloudParams(const CloudParams &cloud_params)
105         {
106                 m_cloud_params = cloud_params;
107         }
108
109         const CloudParams &getCloudParams() const { return m_cloud_params; }
110
111         bool checkModified() const { return m_dirty || inventory.checkModified(); }
112
113         inline void setModified(const bool x) { m_dirty = x; }
114
115         void setLocalAnimations(v2s32 frames[4], float frame_speed)
116         {
117                 for (int i = 0; i < 4; i++)
118                         local_animations[i] = frames[i];
119                 local_animation_speed = frame_speed;
120         }
121
122         void getLocalAnimations(v2s32 *frames, float *frame_speed)
123         {
124                 for (int i = 0; i < 4; i++)
125                         frames[i] = local_animations[i];
126                 *frame_speed = local_animation_speed;
127         }
128
129         void setDirty(bool dirty) { m_dirty = true; }
130
131         u16 protocol_version = 0;
132
133         session_t getPeerId() const { return m_peer_id; }
134
135         void setPeerId(session_t peer_id) { m_peer_id = peer_id; }
136
137         void onSuccessfulSave();
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 = nullptr;
149         bool m_dirty = false;
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 = std::time(0);
156         float m_chat_message_allowance = 5.0f;
157         u16 m_message_rate_overhead = 0;
158
159         bool m_day_night_ratio_do_override = false;
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         session_t m_peer_id = PEER_ID_INEXISTENT;
172 };