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 #include "skyparams.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() = default;
46 
getPlayerSAO()47 	PlayerSAO *getPlayerSAO() { return m_sao; }
setPlayerSAO(PlayerSAO * sao)48 	void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
49 
50 	const RemotePlayerChatResult canSendChatMessage();
51 
setHotbarItemcount(s32 hotbar_itemcount)52 	void setHotbarItemcount(s32 hotbar_itemcount)
53 	{
54 		hud_hotbar_itemcount = hotbar_itemcount;
55 	}
56 
getHotbarItemcount()57 	s32 getHotbarItemcount() const { return hud_hotbar_itemcount; }
58 
overrideDayNightRatio(bool do_override,float ratio)59 	void overrideDayNightRatio(bool do_override, float ratio)
60 	{
61 		m_day_night_ratio_do_override = do_override;
62 		m_day_night_ratio = ratio;
63 	}
64 
getDayNightRatio(bool * do_override,float * ratio)65 	void getDayNightRatio(bool *do_override, float *ratio)
66 	{
67 		*do_override = m_day_night_ratio_do_override;
68 		*ratio = m_day_night_ratio;
69 	}
70 
setHotbarImage(const std::string & name)71 	void setHotbarImage(const std::string &name) { hud_hotbar_image = name; }
72 
getHotbarImage()73 	const std::string &getHotbarImage() const { return hud_hotbar_image; }
74 
setHotbarSelectedImage(const std::string & name)75 	void setHotbarSelectedImage(const std::string &name)
76 	{
77 		hud_hotbar_selected_image = name;
78 	}
79 
getHotbarSelectedImage()80 	const std::string &getHotbarSelectedImage() const
81 	{
82 		return hud_hotbar_selected_image;
83 	}
84 
setSky(const SkyboxParams & skybox_params)85 	void setSky(const SkyboxParams &skybox_params)
86 	{
87 		m_skybox_params = skybox_params;
88 	}
89 
getSkyParams()90 	const SkyboxParams &getSkyParams() const { return m_skybox_params; }
91 
setSun(const SunParams & sun_params)92 	void setSun(const SunParams &sun_params) { m_sun_params = sun_params; }
93 
getSunParams()94 	const SunParams &getSunParams() const { return m_sun_params; }
95 
setMoon(const MoonParams & moon_params)96 	void setMoon(const MoonParams &moon_params) { m_moon_params = moon_params; }
97 
getMoonParams()98 	const MoonParams &getMoonParams() const { return m_moon_params; }
99 
setStars(const StarParams & star_params)100 	void setStars(const StarParams &star_params) { m_star_params = star_params; }
101 
getStarParams()102 	const StarParams &getStarParams() const { return m_star_params; }
103 
setCloudParams(const CloudParams & cloud_params)104 	void setCloudParams(const CloudParams &cloud_params)
105 	{
106 		m_cloud_params = cloud_params;
107 	}
108 
getCloudParams()109 	const CloudParams &getCloudParams() const { return m_cloud_params; }
110 
checkModified()111 	bool checkModified() const { return m_dirty || inventory.checkModified(); }
112 
setModified(const bool x)113 	inline void setModified(const bool x) { m_dirty = x; }
114 
setLocalAnimations(v2s32 frames[4],float frame_speed)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 
getLocalAnimations(v2s32 * frames,float * frame_speed)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 
setDirty(bool dirty)129 	void setDirty(bool dirty) { m_dirty = true; }
130 
131 	u16 protocol_version = 0;
132 
133 	// v1 for clients older than 5.1.0-dev
134 	u16 formspec_version = 1;
135 
getPeerId()136 	session_t getPeerId() const { return m_peer_id; }
137 
setPeerId(session_t peer_id)138 	void setPeerId(session_t peer_id) { m_peer_id = peer_id; }
139 
140 	void onSuccessfulSave();
141 
142 private:
143 	PlayerSAO *m_sao = nullptr;
144 	bool m_dirty = false;
145 
146 	static bool m_setting_cache_loaded;
147 	static float m_setting_chat_message_limit_per_10sec;
148 	static u16 m_setting_chat_message_limit_trigger_kick;
149 
150 	u32 m_last_chat_message_sent = std::time(0);
151 	float m_chat_message_allowance = 5.0f;
152 	u16 m_message_rate_overhead = 0;
153 
154 	bool m_day_night_ratio_do_override = false;
155 	float m_day_night_ratio;
156 	std::string hud_hotbar_image = "";
157 	std::string hud_hotbar_selected_image = "";
158 
159 	CloudParams m_cloud_params;
160 
161 	SkyboxParams m_skybox_params;
162 	SunParams m_sun_params;
163 	MoonParams m_moon_params;
164 	StarParams m_star_params;
165 
166 	session_t m_peer_id = PEER_ID_INEXISTENT;
167 };
168