summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_client.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-07-18 21:39:55 +0200
committerGitHub <noreply@github.com>2017-07-18 21:39:55 +0200
commit79f19b8369a0120fbf0bd0ee3739989fbbbca50e (patch)
tree0051cde3efe56d35d03aa50a5095d9b8ba04d15b /src/script/lua_api/l_client.cpp
parent7e3cdf7088b1fb6744d0bd9cc903823b6e3bbfe3 (diff)
downloadminetest-79f19b8369a0120fbf0bd0ee3739989fbbbca50e.tar.gz
minetest-79f19b8369a0120fbf0bd0ee3739989fbbbca50e.tar.bz2
minetest-79f19b8369a0120fbf0bd0ee3739989fbbbca50e.zip
[CSM] Add flavour limits controlled by server (#5930)
* [CSM] Add flavour limits controlled by server Server send flavour limits to client permitting to disable or limit some Lua calls * Add limits for reading nodedefs and itemdefs * flavour: Add lookup node limits * Merge get_node_or_nil into get_node. Sending fake node doesn't make sense in CSM, just return nil if node is not available for any reason * Add node range customization when noderange flavour is enabled (default 8 nodes) * Limit nodes range & disable chat message sending by default * Bump protocol version
Diffstat (limited to 'src/script/lua_api/l_client.cpp')
-rw-r--r--src/script/lua_api/l_client.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index e7d75cce7..6f9240466 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -91,6 +91,11 @@ int ModApiClient::l_send_chat_message(lua_State *L)
{
if (!lua_isstring(L, 1))
return 0;
+
+ // If server disabled this API, discard
+ if (getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_CHAT_MESSAGES))
+ return 0;
+
std::string message = luaL_checkstring(L, 1);
getClient(L)->sendChatMessage(utf8_to_wide(message));
return 0;
@@ -166,24 +171,11 @@ int ModApiClient::l_gettext(lua_State *L)
// get_node(pos)
// pos = {x=num, y=num, z=num}
-int ModApiClient::l_get_node(lua_State *L)
-{
- // pos
- v3s16 pos = read_v3s16(L, 1);
- // Do it
- bool pos_ok;
- MapNode n = getClient(L)->getNode(pos, &pos_ok);
- // Return node
- pushnode(L, n, getClient(L)->ndef());
- return 1;
-}
-
-// get_node_or_nil(pos)
-// pos = {x=num, y=num, z=num}
int ModApiClient::l_get_node_or_nil(lua_State *L)
{
// pos
v3s16 pos = read_v3s16(L, 1);
+
// Do it
bool pos_ok;
MapNode n = getClient(L)->getNode(pos, &pos_ok);
@@ -290,6 +282,9 @@ int ModApiClient::l_get_item_def(lua_State *L)
IItemDefManager *idef = gdef->idef();
assert(idef);
+ if (getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_READ_ITEMDEFS))
+ return 0;
+
if (!lua_isstring(L, 1))
return 0;
@@ -315,6 +310,9 @@ int ModApiClient::l_get_node_def(lua_State *L)
if (!lua_isstring(L, 1))
return 0;
+ if (getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_READ_NODEDEFS))
+ return 0;
+
const std::string &name = lua_tostring(L, 1);
const ContentFeatures &cf = ndef->get(ndef->getId(name));
if (cf.name != name) // Unknown node. | name = <whatever>, cf.name = ignore
@@ -363,7 +361,6 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(show_formspec);
API_FCT(send_respawn);
API_FCT(gettext);
- API_FCT(get_node);
API_FCT(get_node_or_nil);
API_FCT(get_wielded_item);
API_FCT(disconnect);