@@ -36,28 +36,46 @@ simple_protection.can_access = function(pos, player_name)
3636 if not player_name or player_name == " " then
3737 return false
3838 end
39- -- allow pipeworks access
39+ -- Allow pipeworks access
4040 if player_name == " :pipeworks" then
4141 return true
4242 end
4343
44- -- get data of area
44+ -- Data of current area
4545 local data = simple_protection .get_data (pos )
46+
47+ -- Area is not claimed
4648 if not data then
49+ -- Allow digging when claiming is not forced
50+ if not simple_protection .claim_to_dig then
51+ return true
52+ end
53+
54+ -- Claim everywhere? Disallow everywhere.
55+ if simple_protection .underground_claim then
56+ return false
57+ end
58+ -- Is it in claimable area? Yes? Disallow.
59+ if pos .y >= simple_protection .underground_limit then
60+ return false
61+ end
4762 return true
4863 end
4964 if player_name == data .owner then
5065 return true
5166 end
67+ -- Owner shared the area with the player
5268 if table_contains (simple_protection .share [data .owner ], player_name ) then
5369 return true
5470 end
71+ -- Globally shared area
5572 if table_contains (data .shared , player_name ) then
5673 return true
5774 end
5875 if table_contains (data .shared , " *all" ) then
5976 return true
6077 end
78+ -- Admin power
6179 if minetest .check_player_privs (player_name , {simple_protection = true }) then
6280 return true
6381 end
@@ -92,21 +110,21 @@ simple_protection.get_center = function(pos1)
92110 z = pos1 .z / size
93111 }
94112 pos = vector .floor (pos )
113+ -- Get the middle of the area
95114 pos .x = pos .x * size + (size / 2 )
96- pos .z = pos .z * size + (size / 2 ) -- add half of chunk
115+ pos .z = pos .z * size + (size / 2 )
97116 return pos
98117end
99118
100119simple_protection .load_claims = function ()
101- minetest .log (" action" , " Loading simple protection claims" )
102120 local file = io.open (simple_protection .file , " r" )
103121 if not file then
104122 return
105123 end
106124 for line in file :lines () do
107125 if line ~= " " then
108126 local data = line :split (" " )
109- -- coords , owner, shared1, shared2 , ..
127+ -- Line format: pos , owner, shared_player, shared_player2 , ..
110128 local _shared = {}
111129 if # data > 2 then
112130 for index = 3 , # data do
@@ -119,18 +137,18 @@ simple_protection.load_claims = function()
119137 end
120138 end
121139 io.close (file )
140+ minetest .log (" action" , " Loaded claim data" )
122141end
123142
124143simple_protection .load_shareall = function ()
125- minetest .log (" action" , " Loading shared claims" )
126144 local file = io.open (simple_protection .sharefile , " r" )
127145 if not file then
128146 return
129147 end
130148 for line in file :lines () do
131149 if line ~= " " then
132150 local data = line :split (" " )
133- -- owner, shared1, shared2 , ..
151+ -- Line format: owner, shared_player, shared_player2 , ..
134152 local _shared = {}
135153 if # data > 1 then
136154 for index = 2 , # data do
@@ -143,6 +161,7 @@ simple_protection.load_shareall = function()
143161 end
144162 end
145163 io.close (file )
164+ minetest .log (" action" , " Loaded shared claims" )
146165end
147166
148167simple_protection .save = function ()
@@ -157,6 +176,7 @@ simple_protection.save = function()
157176 end
158177 end
159178 io.close (file )
179+ -- Save globally shared areas
160180 file = io.open (simple_protection .sharefile , " w" )
161181 for name , players in pairs (simple_protection .share ) do
162182 if # players > 0 then
@@ -171,16 +191,16 @@ simple_protection.save = function()
171191end
172192
173193simple_protection .load_config = function ()
174- -- load defaults
194+ -- Load defaults
175195 dofile (simple_protection .mod_path .. " /settings.conf" )
176196 local file = io.open (simple_protection .conf , " r" )
177197 if file then
178198 io.close (file )
179- -- load existing config
199+ -- Load existing config
180200 dofile (simple_protection .conf )
181201 return
182202 end
183- -- duplicate configuration file
203+ -- Duplicate configuration file on first time
184204 local src = io.open (simple_protection .mod_path .. " /settings.conf" , " r" )
185205 file = io.open (simple_protection .conf , " w" )
186206
0 commit comments