s_player.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 ScriptApiPlayer : virtual public ScriptApiBase
  26. {
  27. public:
  28. virtual ~ScriptApiPlayer() = default;
  29. void on_newplayer(ServerActiveObject *player);
  30. void on_dieplayer(ServerActiveObject *player, const PlayerHPChangeReason &reason);
  31. bool on_respawnplayer(ServerActiveObject *player);
  32. bool on_prejoinplayer(const std::string &name, const std::string &ip,
  33. std::string *reason);
  34. bool can_bypass_userlimit(const std::string &name, const std::string &ip);
  35. void on_joinplayer(ServerActiveObject *player);
  36. void on_leaveplayer(ServerActiveObject *player, bool timeout);
  37. void on_cheat(ServerActiveObject *player, const std::string &cheat_type);
  38. bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter,
  39. float time_from_last_punch, const ToolCapabilities *toolcap,
  40. v3f dir, s16 damage);
  41. s16 on_player_hpchange(ServerActiveObject *player, s16 hp_change,
  42. const PlayerHPChangeReason &reason);
  43. void on_playerReceiveFields(ServerActiveObject *player,
  44. const std::string &formname, const StringMap &fields);
  45. void on_auth_failure(const std::string &name, const std::string &ip);
  46. // Player inventory callbacks
  47. // Return number of accepted items to be moved
  48. int player_inventory_AllowMove(
  49. const MoveAction &ma, int count,
  50. ServerActiveObject *player);
  51. // Return number of accepted items to be put
  52. int player_inventory_AllowPut(
  53. const MoveAction &ma, const ItemStack &stack,
  54. ServerActiveObject *player);
  55. // Return number of accepted items to be taken
  56. int player_inventory_AllowTake(
  57. const MoveAction &ma, const ItemStack &stack,
  58. ServerActiveObject *player);
  59. // Report moved items
  60. void player_inventory_OnMove(
  61. const MoveAction &ma, int count,
  62. ServerActiveObject *player);
  63. // Report put items
  64. void player_inventory_OnPut(
  65. const MoveAction &ma, const ItemStack &stack,
  66. ServerActiveObject *player);
  67. // Report taken items
  68. void player_inventory_OnTake(
  69. const MoveAction &ma, const ItemStack &stack,
  70. ServerActiveObject *player);
  71. private:
  72. void pushPutTakeArguments(
  73. const char *method, const InventoryLocation &loc,
  74. const std::string &listname, int index, const ItemStack &stack,
  75. ServerActiveObject *player);
  76. void pushMoveArguments(const MoveAction &ma,
  77. int count, ServerActiveObject *player);
  78. };