Fix how address is logged when a wrong password is supplied
[oweals/minetest.git] / src / content_sao.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef CONTENT_SAO_HEADER
21 #define CONTENT_SAO_HEADER
22
23 #include "serverobject.h"
24 #include "itemgroup.h"
25 #include "player.h"
26 #include "object_properties.h"
27
28 /*
29         LuaEntitySAO needs some internals exposed.
30 */
31
32 class LuaEntitySAO : public ServerActiveObject
33 {
34 public:
35         LuaEntitySAO(ServerEnvironment *env, v3f pos,
36                      const std::string &name, const std::string &state);
37         ~LuaEntitySAO();
38         ActiveObjectType getType() const
39         { return ACTIVEOBJECT_TYPE_LUAENTITY; }
40         ActiveObjectType getSendType() const
41         { return ACTIVEOBJECT_TYPE_GENERIC; }
42         virtual void addedToEnvironment(u32 dtime_s);
43         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
44                         const std::string &data);
45         bool isAttached();
46         void step(float dtime, bool send_recommended);
47         std::string getClientInitializationData(u16 protocol_version);
48         std::string getStaticData();
49         int punch(v3f dir,
50                         const ToolCapabilities *toolcap=NULL,
51                         ServerActiveObject *puncher=NULL,
52                         float time_from_last_punch=1000000);
53         void rightClick(ServerActiveObject *clicker);
54         void setPos(v3f pos);
55         void moveTo(v3f pos, bool continuous);
56         float getMinimumSavedMovement();
57         std::string getDescription();
58         void setHP(s16 hp);
59         s16 getHP() const;
60         void setArmorGroups(const ItemGroupList &armor_groups);
61         ItemGroupList getArmorGroups();
62         void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
63         void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
64         void setBonePosition(const std::string &bone, v3f position, v3f rotation);
65         void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
66         void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
67         void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
68         void addAttachmentChild(int child_id);
69         void removeAttachmentChild(int child_id);
70         std::set<int> getAttachmentChildIds();
71         ObjectProperties* accessObjectProperties();
72         void notifyObjectPropertiesModified();
73         /* LuaEntitySAO-specific */
74         void setVelocity(v3f velocity);
75         v3f getVelocity();
76         void setAcceleration(v3f acceleration);
77         v3f getAcceleration();
78         void setYaw(float yaw);
79         float getYaw();
80         void setTextureMod(const std::string &mod);
81         void setSprite(v2s16 p, int num_frames, float framelength,
82                         bool select_horiz_by_yawpitch);
83         std::string getName();
84         bool getCollisionBox(aabb3f *toset);
85         bool collideWithObjects();
86 private:
87         std::string getPropertyPacket();
88         void sendPosition(bool do_interpolate, bool is_movement_end);
89
90         std::string m_init_name;
91         std::string m_init_state;
92         bool m_registered;
93         struct ObjectProperties m_prop;
94         
95         s16 m_hp;
96         v3f m_velocity;
97         v3f m_acceleration;
98         float m_yaw;
99         ItemGroupList m_armor_groups;
100         
101         bool m_properties_sent;
102         float m_last_sent_yaw;
103         v3f m_last_sent_position;
104         v3f m_last_sent_velocity;
105         float m_last_sent_position_timer;
106         float m_last_sent_move_precision;
107         bool m_armor_groups_sent;
108
109         v2f m_animation_range;
110         float m_animation_speed;
111         float m_animation_blend;
112         bool m_animation_loop;
113         bool m_animation_sent;
114
115         std::map<std::string, core::vector2d<v3f> > m_bone_position;
116         bool m_bone_position_sent;
117
118         int m_attachment_parent_id;
119         std::set<int> m_attachment_child_ids;
120         std::string m_attachment_bone;
121         v3f m_attachment_position;
122         v3f m_attachment_rotation;
123         bool m_attachment_sent;
124 };
125
126 /*
127         PlayerSAO needs some internals exposed.
128 */
129
130 class LagPool
131 {
132         float m_pool;
133         float m_max;
134 public:
135         LagPool(): m_pool(15), m_max(15)
136         {}
137         void setMax(float new_max)
138         {
139                 m_max = new_max;
140                 if(m_pool > new_max)
141                         m_pool = new_max;
142         }
143         void add(float dtime)
144         {
145                 m_pool -= dtime;
146                 if(m_pool < 0)
147                         m_pool = 0;
148         }
149         bool grab(float dtime)
150         {
151                 if(dtime <= 0)
152                         return true;
153                 if(m_pool + dtime > m_max)
154                         return false;
155                 m_pool += dtime;
156                 return true;
157         }
158 };
159
160 class PlayerSAO : public ServerActiveObject
161 {
162 public:
163         PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
164                         const std::set<std::string> &privs, bool is_singleplayer);
165         ~PlayerSAO();
166         ActiveObjectType getType() const
167         { return ACTIVEOBJECT_TYPE_PLAYER; }
168         ActiveObjectType getSendType() const
169         { return ACTIVEOBJECT_TYPE_GENERIC; }
170         std::string getDescription();
171
172         /*
173                 Active object <-> environment interface
174         */
175
176         void addedToEnvironment(u32 dtime_s);
177         void removingFromEnvironment();
178         bool isStaticAllowed() const;
179         std::string getClientInitializationData(u16 protocol_version);
180         std::string getStaticData();
181         bool isAttached();
182         void step(float dtime, bool send_recommended);
183         void setBasePosition(const v3f &position);
184         void setPos(v3f pos);
185         void moveTo(v3f pos, bool continuous);
186         void setYaw(float);
187         void setPitch(float);
188
189         /*
190                 Interaction interface
191         */
192
193         int punch(v3f dir,
194                 const ToolCapabilities *toolcap,
195                 ServerActiveObject *puncher,
196                 float time_from_last_punch);
197         void rightClick(ServerActiveObject *clicker);
198         s16 getHP() const;
199         void setHP(s16 hp);
200         s16 readDamage();
201         u16 getBreath() const;
202         void setBreath(u16 breath);
203         void setArmorGroups(const ItemGroupList &armor_groups);
204         ItemGroupList getArmorGroups();
205         void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
206         void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
207         void setBonePosition(const std::string &bone, v3f position, v3f rotation);
208         void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
209         void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
210         void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
211         void addAttachmentChild(int child_id);
212         void removeAttachmentChild(int child_id);
213         std::set<int> getAttachmentChildIds();
214         ObjectProperties* accessObjectProperties();
215         void notifyObjectPropertiesModified();
216         void setNametagColor(video::SColor color);
217         video::SColor getNametagColor();
218
219         /*
220                 Inventory interface
221         */
222
223         Inventory* getInventory();
224         const Inventory* getInventory() const;
225         InventoryLocation getInventoryLocation() const;
226         std::string getWieldList() const;
227         int getWieldIndex() const;
228         void setWieldIndex(int i);
229
230         /*
231                 PlayerSAO-specific
232         */
233
234         void disconnected();
235
236         Player* getPlayer()
237         {
238                 return m_player;
239         }
240         u16 getPeerID() const
241         {
242                 return m_peer_id;
243         }
244
245         // Cheat prevention
246
247         v3f getLastGoodPosition() const
248         {
249                 return m_last_good_position;
250         }
251         float resetTimeFromLastPunch()
252         {
253                 float r = m_time_from_last_punch;
254                 m_time_from_last_punch = 0.0;
255                 return r;
256         }
257         void noCheatDigStart(v3s16 p)
258         {
259                 m_nocheat_dig_pos = p;
260                 m_nocheat_dig_time = 0;
261         }
262         v3s16 getNoCheatDigPos()
263         {
264                 return m_nocheat_dig_pos;
265         }
266         float getNoCheatDigTime()
267         {
268                 return m_nocheat_dig_time;
269         }
270         void noCheatDigEnd()
271         {
272                 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
273         }
274         LagPool& getDigPool()
275         {
276                 return m_dig_pool;
277         }
278         // Returns true if cheated
279         bool checkMovementCheat();
280
281         // Other
282
283         void updatePrivileges(const std::set<std::string> &privs,
284                         bool is_singleplayer)
285         {
286                 m_privs = privs;
287                 m_is_singleplayer = is_singleplayer;
288         }
289
290         bool getCollisionBox(aabb3f *toset);
291         bool collideWithObjects();
292
293 private:
294         std::string getPropertyPacket();
295         
296         Player *m_player;
297         u16 m_peer_id;
298         Inventory *m_inventory;
299         s16 m_damage;
300
301         // Cheat prevention
302         LagPool m_dig_pool;
303         LagPool m_move_pool;
304         v3f m_last_good_position;
305         float m_time_from_last_punch;
306         v3s16 m_nocheat_dig_pos;
307         float m_nocheat_dig_time;
308
309         int m_wield_index;
310         bool m_position_not_sent;
311         ItemGroupList m_armor_groups;
312         bool m_armor_groups_sent;
313
314         bool m_properties_sent;
315         struct ObjectProperties m_prop;
316         // Cached privileges for enforcement
317         std::set<std::string> m_privs;
318         bool m_is_singleplayer;
319
320         v2f m_animation_range;
321         float m_animation_speed;
322         float m_animation_blend;
323         bool m_animation_loop;
324         bool m_animation_sent;
325
326         std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
327         bool m_bone_position_sent;
328
329         int m_attachment_parent_id;
330         std::set<int> m_attachment_child_ids;
331         std::string m_attachment_bone;
332         v3f m_attachment_position;
333         v3f m_attachment_rotation;
334         bool m_attachment_sent;
335
336         video::SColor m_nametag_color;
337         bool m_nametag_sent;
338
339 public:
340         float m_physics_override_speed;
341         float m_physics_override_jump;
342         float m_physics_override_gravity;
343         bool m_physics_override_sneak;
344         bool m_physics_override_sneak_glitch;
345         bool m_physics_override_sent;
346 };
347
348 #endif
349