forked from Bremaweb/landrush
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprotection.lua
More file actions
279 lines (221 loc) · 7.11 KB
/
Copy pathprotection.lua
File metadata and controls
279 lines (221 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
landrush.offense = {}
function landrush.grief_alert(pos, name)
local chunk = landrush.get_chunk(pos)
minetest.chat_send_player(
landrush.claims[chunk].owner,
"You are being griefed by " ..
name ..
" at " ..
minetest.pos_to_string(pos)
)
for _,shared_player_name in pairs(landrush.claims[chunk].shared) do
minetest.chat_send_player(
shared_player_name,
name ..
" is griefing your shared claim at " ..
minetest.pos_to_string(pos)
)
end
minetest.chat_send_player(
name,
"You are griefing " ..
landrush.claims[chunk].owner
)
end
function landrush.can_interact_in_radius(pos, name, r)
local corners = { {x=pos.x+r, y=pos.y+r, z=pos.z+r},
{x=pos.x+r, y=pos.y+r, z=pos.z-r},
{x=pos.x+r, y=pos.y-r, z=pos.z+r},
{x=pos.x+r, y=pos.y-r, z=pos.z-r},
{x=pos.x-r, y=pos.y+r, z=pos.z+r},
{x=pos.x-r, y=pos.y+r, z=pos.z-r},
{x=pos.x-r, y=pos.y-r, z=pos.z+r},
{x=pos.x-r, y=pos.y-r, z=pos.z-r} }
for _, corner in ipairs(corners) do
if not landrush.can_interact(corner,"") then
return false
end
end
return true
end
function landrush.can_interact(pos, name)
if not pos or not name then return false end
--if ( pos.y < -200 or name == '' or name == nil ) then
if ( pos.y < -200 ) or
( minetest.check_player_privs(name, {landrush=true}) ) or
( minetest.check_player_privs(name, {protection_bypass=true}) ) then
return true
end
local chunk = landrush.get_chunk(pos)
if ( landrush.claims[chunk] == nil ) then
if ( landrush.config:get_bool("requireClaim") == false ) then
return true
end
return false
else -- landrush.claims[chunk] ~= nil
if landrush.claims[chunk].owner == name or
landrush.claims[chunk].shared[name] or
landrush.claims[chunk].shared['*all'] then
return true
else
if landrush.config:get_bool("onlineProtection") == false then
landrush.grief_alert(chunk, name)
return true
end
return false
end
end
end
function landrush.restore_privs(name, privs, grant_privs)
for _,priv in ipairs(grant_privs) do
privs[priv] = true
end
core.set_player_privs(name, privs)
core.chat_send_player(name,
"Your privileges have been restored."
)
core.chat_send_all(
name .. "'s privileges have been restored."
)
core.log("action",
name .. "'s privileges have been restored."
)
end
function landrush.suspend_privs(name, revoke_privs, minutes)
local privs = core.get_player_privs(name)
if not privs then return end
for _,priv in ipairs(revoke_privs) do
privs[priv] = nil
end
core.set_player_privs(name, privs)
core.after( minutes*60, landrush.restore_privs, name, privs, revoke_privs )
minetest.chat_send_player(name,
"Your privileges have been reduced for " ..
tostring(minutes) .. " minutes for trying to grief."
)
minetest.chat_send_all(
name .. "'s privileges have been reduced for trying to grief."
)
minetest.log("action",
name .. "'s privileges have been reduced for trying to grief."
)
end
function landrush.moderate(pos,name)
if ( landrush.offense[name] == nil ) then
landrush.offense[name] = {count=0,lastpos=nil,lasttime=os.time(),bancount=0}
end
local timediff = (os.time() - landrush.offense[name].lasttime)/60
local distance = landrush.get_distance(landrush.offense[name].lastpos,pos)
-- reset offenses after a given time period
if timediff > tonumber(landrush.config:get("offenseReset")) then
landrush.offense[name].count=0
end
if timediff > tonumber(landrush.config:get("offenseReset"))*7 then
landrush.offense[name].bancount=0
end
local offenseAmount = 0
if timediff < 0.01 then
-- reduce the offense amount for very rapid attempts that
-- may be unnoticed by the player due to lag
offenseAmount = 1
else
-- offense amount starts at 10 and is decreased based on
-- the length of time between offenses and the distance
-- from the last offense. This weighted system tries to
-- tolerate players who aren't intentionally griefing
local N = landrush.config:get("chunkSize")
offenseAmount = math.max(0, 10 - timediff/6 - distance/N)
end
landrush.offense[name].count = landrush.offense[name].count + offenseAmount
landrush.offense[name].lastpos = pos
landrush.offense[name].lasttime = os.time()
minetest.log("action",
string.format(
name ..
" attempted to grief. Offense count raised to %.3f.",
landrush.offense[name].count
)
)
if ( landrush.offense[name].count > tonumber(landrush.config:get("banLevel")) ) then
landrush.offense[name].bancount = landrush.offense[name].bancount + 1
landrush.offense[name].count = 0
landrush.offense[name].lastpos = nil
local term = 3^landrush.offense[name].bancount -- minutes
if ( landrush.offense[name].bancount < 4 ) then
local privs = {"interact", "shout"}
landrush.suspend_privs(name, privs, term)
else
minetest.ban_player(name)
minetest.log("action",
name .. " has been banned for too many grief attempts."
)
minetest.chat_send_all(
name .. " has been banned for too many grief attempts."
)
end
if minetest.get_modpath("chatplus") then
if ( chatplus and landrush.config:get("adminUser") ~= nil) then
table.insert(
chatplus.names[landrush.config:get("adminUser")].messages,
"mail from <LandRush>: " ..
name .. " banned for " ..
tostring(term) ..
" minutes for attempted griefing"
)
end
end
return
end
if ( landrush.offense[name].count > tonumber(landrush.config:get("banWarning")) ) then
minetest.chat_send_player(name,
"Stop trying to dig in claimed areas or you will be banned!"
)
minetest.chat_send_player(name,
"Use /showarea and /landowner to see the protected area and who owns it."
)
minetest.sound_play("landrush_ban_warning", {to_player=name,gain = 10.0})
end
end
function landrush.protection_violation(pos, name)
-- this function can be overwritten to apply whatever discipline the server admin wants
-- this is the default discipline
local player = minetest.get_player_by_name(name)
if ( player == nil ) then
return
end
-- inform
local owner = landrush.get_owner(pos)
if ( owner == nil ) and
( landrush.config:get_bool("requireClaim") == true ) then
minetest.chat_send_player(name,
"This area is unowned, but you must claim it to build or mine"
)
return true
else
minetest.chat_send_player(name,
"Area owned by " ..
tostring(owner) ..
" stop trying to dig here!"
)
end
-- discipline
if ( tonumber(landrush.config:get("noDamageTime")) >
landrush.get_timeonline(name) ) then
minetest.after(0.01, function()
player:set_hp( player:get_hp() - landrush.config:get("offenseDamage") )
end)
end
if ( landrush.config:get_bool("autoBan") == true ) and
( tonumber(landrush.config:get("noBanTime")) >
landrush.get_timeonline(name) ) then
landrush.moderate(pos,name)
end
end
landrush.default_is_protected = minetest.is_protected
function minetest.is_protected (pos, name)
if ( landrush.can_interact(pos, name) ) then
return landrush.default_is_protected(pos,name)
end
return true
end
minetest.register_on_protection_violation( landrush.protection_violation )