s_player.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "cpp_api/s_base.h"
  18. #include "irr_v3d.h"
  19. #include "util/string.h"
  20. struct MoveAction;
  21. struct InventoryLocation;
  22. struct ItemStack;
  23. struct ToolCapabilities;
  24. struct PlayerHPChangeReason;
  25. class ServerActiveObject;
  26. class ScriptApiPlayer : virtual public ScriptApiBase
  27. {
  28. public:
  29. virtual ~ScriptApiPlayer() = default;
  30. void on_newplayer(ServerActiveObject *player);
  31. void on_dieplayer(ServerActiveObject *player, const PlayerHPChangeReason &reason);
  32. bool on_respawnplayer(ServerActiveObject *player);
  33. bool on_prejoinplayer(const std::string &name, const std::string &ip,
  34. std::string *reason);
  35. bool can_bypass_userlimit(const std::string &name, const std::string &ip);
  36. void on_joinplayer(ServerActiveObject *player, s64 last_login);
  37. void on_leaveplayer(ServerActiveObject *player, bool timeout);
  38. void on_cheat(ServerActiveObject *player, const std::string &cheat_type);
  39. bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter,
  40. float time_from_last_punch, const ToolCapabilities *toolcap,
  41. v3f dir, s32 damage);
  42. void on_rightclickplayer(ServerActiveObject *player, ServerActiveObject *clicker);
  43. s32 on_player_hpchange(ServerActiveObject *player, s32 hp_change,
  44. const PlayerHPChangeReason &reason);
  45. void on_playerReceiveFields(ServerActiveObject *player,
  46. const std::string &formname, const StringMap &fields);
  47. void on_authplayer(const std::string &name, const std::string &ip, bool is_success);
  48. // Player inventory callbacks
  49. // Return number of accepted items to be moved
  50. int player_inventory_AllowMove(
  51. const MoveAction &ma, int count,
  52. ServerActiveObject *player);
  53. // Return number of accepted items to be put
  54. int player_inventory_AllowPut(
  55. const MoveAction &ma, const ItemStack &stack,
  56. ServerActiveObject *player);
  57. // Return number of accepted items to be taken
  58. int player_inventory_AllowTake(
  59. const MoveAction &ma, const ItemStack &stack,
  60. ServerActiveObject *player);
  61. // Report moved items
  62. void player_inventory_OnMove(
  63. const MoveAction &ma, int count,
  64. ServerActiveObject *player);
  65. // Report put items
  66. void player_inventory_OnPut(
  67. const MoveAction &ma, const ItemStack &stack,
  68. ServerActiveObject *player);
  69. // Report taken items
  70. void player_inventory_OnTake(
  71. const MoveAction &ma, const ItemStack &stack,
  72. ServerActiveObject *player);
  73. private:
  74. void pushPutTakeArguments(
  75. const char *method, const InventoryLocation &loc,
  76. const std::string &listname, int index, const ItemStack &stack,
  77. ServerActiveObject *player);
  78. void pushMoveArguments(const MoveAction &ma,
  79. int count, ServerActiveObject *player);
  80. };