]> git.lizzy.rs Git - minetest.git/blob - src/remoteplayer.h
Translated using Weblate (French)
[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 #pragma once
22
23 #include "player.h"
24 #include "skyparams.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         PlayerSAO *getPlayerSAO() { return m_sao; }
47         void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
48
49         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         void setHotbarImage(const std::string &name) { hud_hotbar_image = name; }
71
72         const std::string &getHotbarImage() const { return hud_hotbar_image; }
73
74         void setHotbarSelectedImage(const std::string &name)
75         {
76                 hud_hotbar_selected_image = name;
77         }
78
79         const std::string &getHotbarSelectedImage() const
80         {
81                 return hud_hotbar_selected_image;
82         }
83
84         void setSky(const SkyboxParams &skybox_params)
85         {
86                 m_skybox_params = skybox_params;
87         }
88
89         const SkyboxParams &getSkyParams() const { return m_skybox_params; }
90
91         void setSun(const SunParams &sun_params) { m_sun_params = sun_params; }
92
93         const SunParams &getSunParams() const { return m_sun_params; }
94
95         void setMoon(const MoonParams &moon_params) { m_moon_params = moon_params; }
96
97         const MoonParams &getMoonParams() const { return m_moon_params; }
98
99         void setStars(const StarParams &star_params) { m_star_params = star_params; }
100
101         const StarParams &getStarParams() const { return m_star_params; }
102
103         void setCloudParams(const CloudParams &cloud_params)
104         {
105                 m_cloud_params = cloud_params;
106         }
107
108         const CloudParams &getCloudParams() const { return m_cloud_params; }
109
110         bool checkModified() const { return m_dirty || inventory.checkModified(); }
111
112         inline void setModified(const bool x) { m_dirty = x; }
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 = 0;
131
132         // v1 for clients older than 5.1.0-dev
133         u16 formspec_version = 1;
134
135         session_t getPeerId() const { return m_peer_id; }
136
137         void setPeerId(session_t peer_id) { m_peer_id = peer_id; }
138
139         void onSuccessfulSave();
140
141 private:
142         PlayerSAO *m_sao = nullptr;
143         bool m_dirty = false;
144
145         static bool m_setting_cache_loaded;
146         static float m_setting_chat_message_limit_per_10sec;
147         static u16 m_setting_chat_message_limit_trigger_kick;
148
149         u32 m_last_chat_message_sent = std::time(0);
150         float m_chat_message_allowance = 5.0f;
151         u16 m_message_rate_overhead = 0;
152
153         bool m_day_night_ratio_do_override = false;
154         float m_day_night_ratio;
155         std::string hud_hotbar_image = "";
156         std::string hud_hotbar_selected_image = "";
157
158         CloudParams m_cloud_params;
159
160         SkyboxParams m_skybox_params;
161         SunParams m_sun_params;
162         MoonParams m_moon_params;
163         StarParams m_star_params;
164
165         session_t m_peer_id = PEER_ID_INEXISTENT;
166 };