aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r--src/script/cpp_api/s_player.cpp58
-rw-r--r--src/script/cpp_api/s_player.h9
-rw-r--r--src/script/cpp_api/s_security.cpp20
3 files changed, 74 insertions, 13 deletions
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp
index 22b24f363..2f366605b 100644
--- a/src/script/cpp_api/s_player.cpp
+++ b/src/script/cpp_api/s_player.cpp
@@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_item.h"
#include "util/string.h"
+#include "remoteplayer.h"
+
void ScriptApiPlayer::on_newplayer(ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
@@ -78,7 +80,7 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player,
}
void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player,
- ServerActiveObject *clicker)
+ ServerActiveObject *clicker)
{
SCRIPTAPI_PRECHECKHEADER
// Get core.registered_on_rightclickplayers
@@ -91,7 +93,7 @@ void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player,
}
s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,
- s32 hp_change, const PlayerHPChangeReason &reason)
+ s32 hp_change, const PlayerHPChangeReason &reason)
{
SCRIPTAPI_PRECHECKHEADER
@@ -380,3 +382,55 @@ void ScriptApiPlayer::player_inventory_OnTake(
pushPutTakeArguments("take", ma.from_inv, ma.from_list, ma.from_i, stack, player);
runCallbacks(4, RUN_CALLBACKS_MODE_FIRST);
}
+
+void ScriptApiPlayer::on_player_change_wield(ServerActiveObject *player, u16 item)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_leaveplayers
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_player_change_wield");
+ // Call callbacks
+ objectrefGetOrCreate(L, player);
+ lua_pushnumber(L, item);
+ runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
+}
+
+void ScriptApiPlayer::on_player_change_keys(ServerActiveObject *player, PlayerControl &control)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_player_change_keys");
+ objectrefGetOrCreate(L, player);
+
+ lua_newtable(L);
+
+ lua_pushboolean(L, control.direction_keys & (1 << 0));
+ lua_setfield(L, -2, "up");
+ lua_pushboolean(L, control.direction_keys & (1 << 1));
+ lua_setfield(L, -2, "down");
+ lua_pushboolean(L, control.direction_keys & (1 << 2));
+ lua_setfield(L, -2, "left");
+ lua_pushboolean(L, control.direction_keys & (1 << 3));
+ lua_setfield(L, -2, "right");
+ lua_pushboolean(L, control.jump);
+ lua_setfield(L, -2, "jump");
+ lua_pushboolean(L, control.aux1);
+ lua_setfield(L, -2, "aux1");
+ lua_pushboolean(L, control.sneak);
+ lua_setfield(L, -2, "sneak");
+ lua_pushboolean(L, control.dig);
+ lua_setfield(L, -2, "dig");
+ lua_pushboolean(L, control.place);
+ lua_setfield(L, -2, "place");
+ // Legacy fields to ensure mod compatibility
+ lua_pushboolean(L, control.dig);
+ lua_setfield(L, -2, "LMB");
+ lua_pushboolean(L, control.place);
+ lua_setfield(L, -2, "RMB");
+ lua_pushboolean(L, control.zoom);
+ lua_setfield(L, -2, "zoom");
+
+ runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
+}
diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h
index e866aee46..8f3834c59 100644
--- a/src/script/cpp_api/s_player.h
+++ b/src/script/cpp_api/s_player.h
@@ -23,6 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irr_v3d.h"
#include "util/string.h"
+#include "remoteplayer.h"
+
struct MoveAction;
struct InventoryLocation;
struct ItemStack;
@@ -79,7 +81,12 @@ public:
void player_inventory_OnTake(
const MoveAction &ma, const ItemStack &stack,
ServerActiveObject *player);
-private:
+
+ void on_player_change_wield(ServerActiveObject *player, u16 item);
+
+ void on_player_change_keys(ServerActiveObject *player, PlayerControl &control);
+
+//private:
void pushPutTakeArguments(
const char *method, const InventoryLocation &loc,
const std::string &listname, int index, const ItemStack &stack,
diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp
index 316b19926..2222dec3f 100644
--- a/src/script/cpp_api/s_security.cpp
+++ b/src/script/cpp_api/s_security.cpp
@@ -30,7 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <algorithm>
#include <iostream>
-
#define SECURE_API(lib, name) \
lua_pushcfunction(L, sl_##lib##_##name); \
lua_setfield(L, -2, #name);
@@ -572,16 +571,18 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
// Allow paths in mod path
// Don't bother if write access isn't important, since it will be handled later
- if (write_required || write_allowed != NULL) {
- const ModSpec *mod = gamedef->getModSpec(mod_name);
- if (mod) {
- str = fs::AbsolutePath(mod->path);
- if (!str.empty() && fs::PathStartsWith(abs_path, str)) {
- if (write_allowed) *write_allowed = true;
- return true;
- }
+// if (write_required || write_allowed != NULL) {
+
+ // Do bother, rather than compare a few hundred strings when the mod is just trying to access its own stuff
+ const ModSpec *mod = gamedef->getModSpec(mod_name);
+ if (mod) {
+ str = fs::AbsolutePath(mod->path);
+ if (!str.empty() && fs::PathStartsWith(abs_path, str)) {
+ if (write_allowed) *write_allowed = true;
+ return true;
}
}
+// }
}
lua_pop(L, 1); // Pop mod name
@@ -820,7 +821,6 @@ int ScriptApiSecurity::sl_io_input(lua_State *L)
return 1;
}
-
int ScriptApiSecurity::sl_io_output(lua_State *L)
{
if (lua_isstring(L, 1)) {