Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
06a5eceb
Commit
06a5eceb
authored
11 years ago
by
ShadowNinja
Browse files
Options
Downloads
Patches
Plain Diff
Add basic protection support to builtin
parent
2636c920
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
builtin/item.lua
+18
-0
18 additions, 0 deletions
builtin/item.lua
builtin/misc.lua
+11
-0
11 additions, 0 deletions
builtin/misc.lua
builtin/misc_register.lua
+1
-0
1 addition, 0 deletions
builtin/misc_register.lua
doc/lua_api.txt
+23
-0
23 additions, 0 deletions
doc/lua_api.txt
with
53 additions
and
0 deletions
builtin/item.lua
+
18
−
0
View file @
06a5eceb
...
...
@@ -218,6 +218,15 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2)
place_to
=
{
x
=
under
.
x
,
y
=
under
.
y
,
z
=
under
.
z
}
end
if
minetest
.
is_protected
(
place_to
,
placer
:
get_player_name
())
then
minetest
.
log
(
"action"
,
placer
:
get_player_name
()
..
" tried to place "
..
def
.
name
..
" at protected position "
..
minetest
.
pos_to_string
(
place_to
))
minetest
.
record_protection_violation
(
place_to
,
placer
:
get_player_name
())
return
itemstack
end
minetest
.
log
(
"action"
,
placer
:
get_player_name
()
..
" places node "
..
def
.
name
..
" at "
..
minetest
.
pos_to_string
(
place_to
))
...
...
@@ -377,6 +386,15 @@ function minetest.node_dig(pos, node, digger)
return
end
if
minetest
.
is_protected
(
pos
,
digger
:
get_player_name
())
then
minetest
.
log
(
"action"
,
digger
:
get_player_name
()
..
" tried to dig "
..
node
.
name
..
" at protected position "
..
minetest
.
pos_to_string
(
pos
))
minetest
.
record_protection_violation
(
pos
,
digger
:
get_player_name
())
return
end
minetest
.
log
(
'action'
,
digger
:
get_player_name
()
..
" digs "
..
node
.
name
..
" at "
..
minetest
.
pos_to_string
(
pos
))
...
...
This diff is collapsed.
Click to expand it.
builtin/misc.lua
+
11
−
0
View file @
06a5eceb
...
...
@@ -106,3 +106,14 @@ function minetest.setting_get_pos(name)
return
minetest
.
string_to_pos
(
value
)
end
-- To be overriden by protection mods
function
minetest
.
is_protected
(
pos
,
name
)
return
false
end
function
minetest
.
record_protection_violation
(
pos
,
name
)
for
_
,
func
in
pairs
(
minetest
.
registered_on_protection_violation
)
do
func
(
pos
,
name
)
end
end
This diff is collapsed.
Click to expand it.
builtin/misc_register.lua
+
1
−
0
View file @
06a5eceb
...
...
@@ -344,4 +344,5 @@ minetest.registered_on_player_receive_fields, minetest.register_on_player_receiv
minetest.registered_on_cheats, minetest.register_on_cheat = make_registration()
minetest.registered_on_crafts, minetest.register_on_craft = make_registration()
minetest.registered_craft_predicts, minetest.register_craft_predict = make_registration()
minetest.registered_on_protection_violation, minetest.register_on_protection_violation = make_registration()
This diff is collapsed.
Click to expand it.
doc/lua_api.txt
+
23
−
0
View file @
06a5eceb
...
...
@@ -1154,6 +1154,13 @@ minetest.register_on_craft(func(itemstack, player, old_craft_grid, craft_inv))
minetest.register_craft_predict(func(itemstack, player, old_craft_grid, craft_inv))
^ The same as before, except that it is called before the player crafts, to make
^ craft prediction, and it should not change anything.
minetest.register_on_protection_violation(func(pos, name))
^ Called by builtin and mods when a player violates protection at a position
(eg, digs a node or punches a protected entity).
^ The registered functions can be called using minetest.record_protection_violation
^ The provided function should check that the position is protected by the mod
calling this function before it prints a message, if it does, to allow for
multiple protection mods.
Other registration functions:
minetest.register_chatcommand(cmd, chatcommand definition)
...
...
@@ -1483,6 +1490,22 @@ minetest.deserialize(string) -> table
^ Example: deserialize('return { ["foo"] = "bar" }') -> {foo='bar'}
^ Example: deserialize('print("foo")') -> nil (function call fails)
^ error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)
minetest.is_protected(pos, name) -> bool
^ This function should be overriden by protection mods and should be used to
check if a player can interact at a position.
^ This function should call the old version of itself if the position is not
protected by the mod.
^ Example:
local old_is_protected = minetest.is_protected
function minetest.is_protected(pos, name)
if mymod:position_protected_from(pos, name) then
return true
end
return old_is_protected(pos, name)
end
minetest.record_protection_violation(pos, name)
^ This function calls functions registered with
minetest.register_on_protection_violation.
Global objects:
minetest.env - EnvRef of the server environment and world.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment