From 06b8ea5e261d9f902b48a2bb0a5dd8453046884c Mon Sep 17 00:00:00 2001 From: Sokomine Date: Mon, 30 Jul 2018 16:58:46 +0200 Subject: [PATCH] updated version and comments and removed surplus blanks --- init.lua | 64 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/init.lua b/init.lua index 64a7cfc..e0bd30e 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,3 @@ - - - --[[ Shared locked objects (Mod for MineTest) Allows to restrict usage of blocks to a certain player or a group of @@ -21,9 +18,12 @@ along with this program. If not, see . --]] --- Version 1.20 +-- Version 2.00 --- Changelog: +-- Changelog: +-- 30.07.2018 * Fixed bug with pipeworks. +-- * Repaired password. +-- * Converted back to unix file format. -- 08.05.2014 * Changed animation of shared locked furnace (removed pipeworks overlay on front, changed to new animation type) -- 10.01.2013 * Added command to toggle for pipeworks output -- * Added pipeworks support for chests and furnace. @@ -89,7 +89,7 @@ function locks:get_lockdata( pos ) if( pos == nil ) then return; end - + local meta = minetest.env:get_meta(pos); if( meta == nil) then return; @@ -110,12 +110,12 @@ function locks:set_lockdata( pos, data ) if( pos == nil ) then return; end - + local meta = minetest.env:get_meta(pos); if( meta == nil) then return; end - + meta:set_string("infotext", (data.infotext or "")); meta:set_string("owner", (data.owner or "")); meta:set_string("allowed_users",(data.allowed_users or "")); @@ -138,7 +138,7 @@ function locks:lock_set_owner( pos, player_or_name, description ) print( "Error: [locks] Missing/wrong parameters to lock_set_owner"); return false; end - + local meta = minetest.env:get_meta(pos); if( meta == nil ) then print( "Error: [locks] lock_set_owner: unable to get meta data"); @@ -156,7 +156,7 @@ function locks:lock_set_owner( pos, player_or_name, description ) end - + -- The locked object can only be digged by the owner OR by people with the diglocks priv -- Call this in can_dig in register_node. Example: -- can_dig = function(pos,player) @@ -181,7 +181,7 @@ function locks:lock_allow_dig( pos, player ) if( player:get_player_name() == meta:get_string("owner")) then return true; end - + -- players with diglocks priv can dig up locked objects as well if( minetest.check_player_privs(player:get_player_name(), {diglocks=true})) then return true; @@ -189,7 +189,7 @@ function locks:lock_allow_dig( pos, player ) return false; -- fallback end - + -- The locked object can only be used (i.e. opened, stuff taken out, changed, ... - depends on object) if this -- function returns true. Call it wherever appropriate (usually in on_punch in register_node). Example: @@ -221,7 +221,7 @@ function locks:lock_allow_use( pos, player ) end -- the player has to have a key or a keychain to open his own shared locked objects - if( name == meta:get_string("owner")) then + if( name == meta:get_string("owner")) then if( not( player:get_inventory():contains_item("main","locks:keychain 1")) and not( player:get_inventory():contains_item("main","locks:key 1"))) then @@ -230,14 +230,14 @@ function locks:lock_allow_use( pos, player ) end -- the player has to have a keychain to open shared locked objects of other players - else + else if( not( player:get_inventory():contains_item("main","locks:keychain 1"))) then minetest.chat_send_player(name, "You do not have a keychain. Without that you can't open shared locked objects of other players!"); return false; end end - + -- if the user would even be allowed to dig this node up, using the node is allowed as well if( locks:lock_allow_dig( pos, player )) then return true; @@ -249,7 +249,7 @@ function locks:lock_allow_use( pos, player ) return false; end - -- players with openlocks priv can open locked objects + -- players with openlocks priv can open locked objects if( minetest.check_player_privs(name, {openlocks=true})) then return true; end @@ -257,7 +257,7 @@ function locks:lock_allow_use( pos, player ) -- the player might be specificly allowed to use this object through allowed_users local liste = meta:get_string("allowed_users"):split( "," ); for i in ipairs( liste ) do - + if( liste[i] == name ) then return true; end @@ -349,18 +349,18 @@ function locks:lock_handle_input( pos, formname, fields, player ) minetest.chat_send_player(name, "Input contains unsupported characters. Allowed: a-z, A-Z, 0-9, _, -, :."); return; end - + if( #fields.locks_sent_lock_command > 60) then minetest.chat_send_player(name, "Input too long. Only up to 80 characters supported."); return; end - + local password = meta:get_string("password"); -- other players can only try to input the correct password if( name ~= meta:get_string( "owner" ) or (password and password ~= "" and password==fields.locks_sent_lock_command) - or (name==meta:get_string("pw_user"))) then + or (name==meta:get_string("pw_user"))) then -- no need to bother with trying other PWs if none is set... if( meta:get_string("password")=="" ) then @@ -386,7 +386,7 @@ function locks:lock_handle_input( pos, formname, fields, player ) minetest.chat_send_player(name, "Password confirmed. Access granted."); return; end - + local txt = ""; @@ -437,11 +437,11 @@ function locks:lock_handle_input( pos, formname, fields, player ) -- -- all other commands take exactly one parameter local help = fields.locks_sent_lock_command:split( " " ); - + print( tostring( help[1] )); print( tostring( help[2] )); - + -- set/change a password if( help[1]=="/set" ) then @@ -454,7 +454,7 @@ function locks:lock_handle_input( pos, formname, fields, player ) "\"\n Changed to new password: \""..tostring( help[2]).."\"."); - meta:set_string( "password", help[2]); + meta:set_string( "password", help[2]); -- reset the list of users who typed the right password meta:set_string("pw_users",""); @@ -476,7 +476,7 @@ function locks:lock_handle_input( pos, formname, fields, player ) local liste = meta:get_string("allowed_users"):split( "," ); for i in ipairs( liste ) do - anz = anz + 1; -- count players + anz = anz + 1; -- count players if( tostring( liste[i] ) == help[2] ) then found = true; end @@ -487,7 +487,7 @@ function locks:lock_handle_input( pos, formname, fields, player ) minetest.chat_send_player(name, "Player \""..tostring( help[2] ).."\" is already allowed to use this locked object. Nothing to do."); return; end - + if( help[1]=="/del" and found==false) then minetest.chat_send_player(name, "Player \""..tostring( help[2] ).."\" is not amongst the players allowed to use this locked object. Nothing to do."); return; @@ -505,10 +505,10 @@ function locks:lock_handle_input( pos, formname, fields, player ) minetest.chat_send_player(name, "You are already owner of this object."); return; end - + -- the player might try to add a playergroup if( help[2]:sub(1,1) == ":" ) then - + if( not( playergroups )) then minetest.chat_send_player(name, "Sorry, this server does not support playergroups."); return; @@ -523,9 +523,9 @@ function locks:lock_handle_input( pos, formname, fields, player ) minetest.chat_send_player(name, "You do not have a playergroup named \""..tostring( help[2]:sub(2)).."\"."); return; end - + else - + -- check if the player exists local privs = minetest.get_player_privs( help[2] ); if( not( privs ) or not( privs.interact )) then @@ -533,7 +533,7 @@ function locks:lock_handle_input( pos, formname, fields, player ) return; end end - + meta:set_string( "allowed_users", meta:get_string("allowed_users")..","..help[2] ); if( help[2]:sub(1,1) == ":" ) then @@ -549,7 +549,7 @@ function locks:lock_handle_input( pos, formname, fields, player ) userlist = meta:get_string("allowed_users"):split( ","..help[2] ); meta:set_string( "allowed_users", ( userlist[1] or "" )..(userlist[2] or "" )); - + minetest.chat_send_player(name, "Access for player \""..tostring(help[2]).."\" has been revoked."); return; end