summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBremaWeb <brandon@bremaweb.com>2013-11-30 13:23:50 -0600
committerBremaWeb <brandon@bremaweb.com>2013-11-30 13:23:50 -0600
commit81a12e3d38c83eacfce4a3eeaec14724dcdb4c8f (patch)
tree58701772bd01e4ab332a0699cdcf0a3e0bf8e432
parent6b22f3d60f1b942485ccbb6dc5417fbe65119db9 (diff)
restructured, use Settings interface for config, use protection API
-rw-r--r--chatcommands.lua45
-rw-r--r--claims.lua46
-rw-r--r--config.lua32
-rw-r--r--functions.lua54
-rw-r--r--hud.lua40
-rw-r--r--init.lua467
-rw-r--r--landsale.lua14
-rw-r--r--protection.lua188
-rw-r--r--shared_door.lua63
-rw-r--r--sign.lua45
10 files changed, 503 insertions, 491 deletions
diff --git a/chatcommands.lua b/chatcommands.lua
index 458522b..84849f9 100644
--- a/chatcommands.lua
+++ b/chatcommands.lua
@@ -21,9 +21,9 @@ minetest.register_chatcommand("userunclaim", {
description = "Unclaims all of a players areas",
func = function(name, param)
qdone = 0
- for k,v in pairs(claims) do
- if claims[k].owner == param then
- claims[k] = nil
+ for k,v in pairs(landrush.claims) do
+ if landrush.claims[k].owner == param then
+ landrush.claims[k] = nil
qdone = qdone + 1
end
end
@@ -44,14 +44,9 @@ minetest.register_chatcommand("unclaim", {
if owner then
if owner == name or minetest.check_player_privs(name, {landrush=true}) then
chunk = landrush.get_chunk(pos)
- --if inv:room_for_item("main", claims[chunk].claimtype) then
- -- player:get_inventory():add_item("main", {name=claims[chunk].claimtype}) -- they don't get their claim item back
- claims[chunk] = nil
+ landrush.claims[chunk] = nil
landrush.save_claims()
minetest.chat_send_player(name, "You renounced your claim on this area.")
- --else
--- minetest.chat_send_player(name, "Your inventory is full.")
- -- end
else
minetest.chat_send_player(name, "This area is owned by "..owner)
end
@@ -72,7 +67,7 @@ minetest.register_chatcommand("sharearea", {
if owner then
if ( owner == name and name ~= param ) or minetest.check_player_privs(name, {landrush=true}) then
if minetest.env:get_player_by_name(param) or param=="*all" then
- claims[landrush.get_chunk(pos)].shared[param] = param
+ landrush.claims[landrush.get_chunk(pos)].shared[param] = param
landrush.save_claims()
minetest.chat_send_player(name, param.." may now edit this area.")
minetest.chat_send_player(param, name.." has just shared an area with you.")
@@ -99,7 +94,7 @@ minetest.register_chatcommand("unsharearea", {
if owner then
if owner == name or minetest.check_player_privs(name, {landrush=true}) then
if name ~= param then
- claims[landrush.get_chunk(pos)].shared[param] = nil
+ landrush.claims[landrush.get_chunk(pos)].shared[param] = nil
landrush.save_claims()
minetest.chat_send_player(name, param.." may no longer edit this area.")
minetest.chat_send_player(param, name.." has just revoked your editing privileges in an area.")
@@ -125,7 +120,7 @@ minetest.register_chatcommand("mayedit", {
local mayedit = landrush.get_owner(pos)
if mayedit then
local chunk = landrush.get_chunk(pos)
- for user, user in pairs(claims[chunk].shared) do
+ for user, user in pairs(landrush.claims[chunk].shared) do
mayedit = mayedit..", "..user
end
minetest.chat_send_player(name, mayedit)
@@ -141,20 +136,10 @@ minetest.register_chatcommand("showarea", {
privs = {interact=true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
- local pos = player:getpos()
- --local owner = landrush.get_owner(pos)
--- if owner then
- --if landrush.can_interact(name, pos) then
+ local pos = player:getpos()
local entpos = landrush.get_chunk_center(pos)
entpos.y = (pos.y-1)
- minetest.env:add_entity(entpos, "landrush:showarea")
- --else
- -- minetest.chat_send_player(name, "This area is owned by "..owner)
- --end
---[[ else
- minetest.chat_send_player(name, "This area is unowned.")
- end]]
--- (Removed at Rarkenin's request)
+ minetest.env:add_entity(entpos, "landrush:showarea")
end,
})
@@ -166,9 +151,9 @@ minetest.register_chatcommand("shareall", {
if minetest.env:get_player_by_name(param) then
local qdone = 0
- for k,v in pairs(claims) do
- if claims[k].owner == name then
- claims[k].shared[param] = param
+ for k,v in pairs(landrush.claims) do
+ if landrush.claims[k].owner == name then
+ landrush.claims[k].shared[param] = param
qdone = qdone + 1
end
end
@@ -195,9 +180,9 @@ minetest.register_chatcommand("unshareall", {
func = function(name, param)
if name ~= param then
local qdone = 0
- for k,v in pairs(claims) do
- if claims[k].owner == name then
- claims[k].shared[param] = nil
+ for k,v in pairs(landrush.claims) do
+ if landrush.claims[k].owner == name then
+ landrush.claims[k].shared[param] = nil
qdone = qdone + 1
end
end
diff --git a/claims.lua b/claims.lua
new file mode 100644
index 0000000..c9c45a3
--- /dev/null
+++ b/claims.lua
@@ -0,0 +1,46 @@
+landrush.claimFile = worldpath.."/landrush-claims"
+landrush.claims = {}
+
+function landrush.load_claims()
+ local file = io.open(landrush.claimFile, "r")
+ if file then
+ for line in file:lines() do
+ if line ~= "" then
+ local area = line:split(" ")
+ local shared = {}
+ if area[3] and area[3] ~= "*" then
+ for k,v in ipairs(area[3]:split(",")) do
+ shared[v] = v
+ end
+ end
+ local claimtype
+ if area[4] then
+ claimtype = area[4]
+ else
+ claimtype = "landrush:landclaim"
+ end
+ landrush.claims[area[1]] = {owner=area[2], shared=shared, claimtype=claimtype}
+ end
+ end
+ file:close()
+ end
+end
+
+function landrush.save_claims()
+ local file = io.open(landrush.claimFile, "w")
+ for key,value in pairs(landrush.claims) do
+ local sharedata = ""
+ for k,v in pairs(value.shared) do
+ sharedata = sharedata..v..","
+ end
+ local sharestring
+ if sharedata == "" then
+ sharestring = "*"
+ else
+ sharestring = sharedata:sub(1,-2)
+ end
+ file:write(key.." "..value.owner.." "..sharestring.." "..value.claimtype.."\n")
+ end
+ file:close()
+end
+
diff --git a/config.lua b/config.lua
new file mode 100644
index 0000000..4c34102
--- /dev/null
+++ b/config.lua
@@ -0,0 +1,32 @@
+-- copied config section from technic
+worldpath = minetest.get_worldpath()
+
+landrush.config = Settings(worldpath.."/landrush.conf")
+
+local conf_table = landrush.config:to_table()
+
+local defaults = {
+ requireClaim = "false",
+ onlineProtection = "true",
+ offenseDamage = "4",
+ autoBan = "false",
+ banLevel = "40",
+ banWarning = "25",
+ offenseReset = "1440",
+ adminUser = nil,
+ chunkSize = "16",
+ enableHud = "true"
+}
+
+for k, v in pairs(defaults) do
+ if conf_table[k] == nil then
+ landrush.config:set(k, v)
+ end
+end
+
+-- Create the config file if it doesn't exist
+landrush.config:write()
+
+-- These are items that can be dug in unclaimed areas when landrush.config:get_bool("requireClaim") is true
+landrush.global_dig_list = {["default:ladder"]=true,["default:leaves"]=true,["default:tree"]=true,["default:grass"]=true,["default:grass_1"]=true,["default:grass_2"]=true,["default:grass_3"]=true,["default:grass_4"]=true}
+
diff --git a/functions.lua b/functions.lua
new file mode 100644
index 0000000..92cad80
--- /dev/null
+++ b/functions.lua
@@ -0,0 +1,54 @@
+function landrush.get_chunk(pos)
+ local x = math.floor(pos.x/landrush.config:get("chunkSize"))
+ -- 3 levels of vertical protection
+ local y = 0
+
+ if ( pos.y < -200 ) then
+ y = - 32000
+ elseif ( pos.y < -60 ) then
+ y = -200
+ elseif ( pos.y < 140 ) then
+ y = -30
+ else
+ y = 90
+ end
+
+
+ local z = math.floor(pos.z/landrush.config:get("chunkSize"))
+ return x..","..y..","..z
+end
+
+function landrush.get_chunk_center(pos)
+ local x = math.floor(pos.x/landrush.config:get("chunkSize"))*landrush.config:get("chunkSize")+7.5
+ local y = 0
+
+ if ( pos.y < -200 ) then
+ y = - 32000
+ elseif ( pos.y < -60 ) then
+ y = -200
+ elseif ( pos.y < 120 ) then
+ y = -30
+ else
+ y = 120
+ end
+
+ local z = math.floor(pos.z/landrush.config:get("chunkSize"))*landrush.config:get("chunkSize")+7.5
+ return {x=x,y=y,z=z}
+end
+
+function landrush.get_owner(pos)
+ local chunk = landrush.get_chunk(pos)
+ if landrush.claims[chunk] then
+ return landrush.claims[chunk].owner
+ end
+end
+
+function landrush.get_distance(pos1,pos2)
+
+ if ( pos1 ~= nil and pos2 ~= nil ) then
+ return math.abs(math.floor(math.sqrt( (pos1.x - pos2.x)^2 + (pos1.z - pos2.z)^2 )))
+ else
+ return 0
+ end
+
+end
diff --git a/hud.lua b/hud.lua
new file mode 100644
index 0000000..f7b58c4
--- /dev/null
+++ b/hud.lua
@@ -0,0 +1,40 @@
+landrush.gstepCount = 0
+landrush.playerHudItems = {}
+
+minetest.register_globalstep(function(dtime)
+ landrush.gstepCount = landrush.gstepCount + dtime
+ if ( landrush.gstepCount > 2 ) then
+ landrush.gstepCount=0
+ local oplayers = minetest.get_connected_players()
+ for _,player in ipairs(oplayers) do
+ local name = player:get_player_name()
+ local sameowner = false
+ owner = landrush.get_owner(player:getpos())
+
+ if ( landrush.playerHudItems[name] ~= nil ) then
+ if ( landrush.playerHudItems[name].lastowner == owner ) then
+ -- same owner as last time don't update the hud
+ sameowner = true
+ end
+ end
+
+ if ( landrush.playerHudItems[name] ~= nil and sameowner == false ) then
+ player:hud_remove(landrush.playerHudItems[name].hud)
+ landrush.playerHudItems[name] = nil
+ end
+
+ if ( owner ~= nil and sameowner == false ) then
+ --minetest.log('action','Redraw hud for '..name)
+ landrush.playerHudItems[name] = {hud = player:hud_add({
+ hud_elem_type = "text",
+ name = "LandOwner",
+ number = 0xFFFFFF,
+ position = {x=.2, y=.98},
+ text="Land Owner: "..owner,
+ scale = {x=200,y=25},
+ alignment = {x=0, y=0},
+ }), lastowner=owner}
+ end
+ end
+ end
+end)
diff --git a/init.lua b/init.lua
index 2aed384..b78dc12 100644
--- a/init.lua
+++ b/init.lua
@@ -1,303 +1,29 @@
minetest.log('action','Loading Land Rush Land Claim')
-landrush = {}
-
-local requireClaim = false -- Change this to true if you want to require people to claim an area before building or digging
-local onlineProtection = true -- false turns protection off when the claim owner is online
-
-local offenseDamage = 4 -- how much damage is dealt to the player when they dig in protected areas
-
-local autoBan = false -- users who attempt to dig and build in claimed areas can be auto banned
-local banLevel = 40 -- the offense level they must exceed to get banned, 40 is roughly 5 nodes dug in the same area
-local banWarning = 25 -- the offense level they start getting ban warnings
-local offenseReset = 1440 -- after this number of minutes all offenses will be forgiven
-local adminUser = nil -- this user will be messaged if chat plus is installed when a player is autobanned
-
-chunkSize = 16 -- don't change this value after you start using landrush
-claims = {}
-local offense = {}
-
-gstepCount = 0
-playerHudItems = {}
-
-local path = minetest.get_modpath("landrush")
-
--- These are items that can be dug in unclaimed areas when requireClaim is true
-local global_dig_list = {["default:ladder"]=true,["default:leaves"]=true,["default:tree"]=true,["default:grass"]=true,["default:grass_1"]=true,["default:grass_2"]=true,["default:grass_3"]=true,["default:grass_4"]=true}
-
-local filename = minetest.get_worldpath().."/landrush-claims"
-
-minetest.register_privilege("landrush", "Allows player to dig and build anywhere, and use the landrush chat commands.")
-
-function landrush.load_claims()
- local file = io.open(filename, "r")
- if file then
- for line in file:lines() do
- if line ~= "" then
- local area = line:split(" ")
- local shared = {}
- if area[3] and area[3] ~= "*" then
- for k,v in ipairs(area[3]:split(",")) do
- shared[v] = v
- end
- end
- local claimtype
- if area[4] then
- claimtype = area[4]
- else
- claimtype = "landrush:landclaim"
- end
- claims[area[1]] = {owner=area[2], shared=shared, claimtype=claimtype}
- end
- end
- file:close()
- end
-end
-
-function landrush.save_claims()
- local file = io.open(filename, "w")
- for key,value in pairs(claims) do
- local sharedata = ""
- for k,v in pairs(value.shared) do
- sharedata = sharedata..v..","
- end
- local sharestring
- if sharedata == "" then
- sharestring = "*"
- else
- sharestring = sharedata:sub(1,-2)
- end
- file:write(key.." "..value.owner.." "..sharestring.." "..value.claimtype.."\n")
- end
- file:close()
-end
-
-function landrush.get_chunk(pos)
- local x = math.floor(pos.x/chunkSize)
- -- 3 levels of vertical protection
- local y = 0
-
- if ( pos.y < -200 ) then
- y = - 32000
- elseif ( pos.y < -60 ) then
- y = -200
- elseif ( pos.y < 140 ) then
- y = -30
- else
- y = 90
- end
-
-
- local z = math.floor(pos.z/chunkSize)
- return x..","..y..","..z
-end
-
-function landrush.get_chunk_center(pos)
- local x = math.floor(pos.x/chunkSize)*chunkSize+7.5
- local y = 0
-
- if ( pos.y < -200 ) then
- y = - 32000
- elseif ( pos.y < -60 ) then
- y = -200
- elseif ( pos.y < 120 ) then
- y = -30
- else
- y = 120
- end
-
- local z = math.floor(pos.z/chunkSize)*chunkSize+7.5
- return {x=x,y=y,z=z}
-end
-
-function landrush.get_owner(pos)
- local chunk = landrush.get_chunk(pos)
- if claims[chunk] then
- return claims[chunk].owner
- end
+-- Freeminer Compatibility
+if freeminer then
+ minetest = freeminer
end
-function landrush.can_interact(name, pos)
-
- if ( pos.y < -200 ) then
- return true
- end
-
- if ( minetest.check_player_privs(name, {landrush=true}) ) then
- return true
- end
-
- local chunk = landrush.get_chunk(pos)
- -- return claims[chunk] == nil or claims[chunk].owner == name or claims[chunk].shared[name]
- if ( claims[chunk] == nil ) then
- if ( requireClaim == true ) then
- return false
- else
- return true
- end
- end
-
- -- if it's the owner or it's shared
- if ( claims[chunk].shared[name] or claims[chunk].owner == name or claims[chunk].shared['*all'] ) then
- return true
- end
+landrush = {}
- -- see if the owner is offline, and area is not shared then it's off limits
- if ( minetest.env:get_player_by_name(claims[chunk].owner) == nil ) then
- if ( claims[chunk].shared[name] ) then
- return true
- else
- return nil
- end
- else
- if ( claims[chunk].owner ~= name and onlineProtection == false ) then
- minetest.chat_send_player( claims[chunk].owner, "You are being griefed by "..name.." at "..minetest.pos_to_string(pos) )
+local path = minetest.get_modpath("landrush")
- for u,u in pairs(claims[chunk].shared) do
- minetest.chat_send_player( u, name.." is griefing your shared claim at "..minetest.pos_to_string(pos) )
- end
+dofile(path.."/config.lua")
+dofile(path.."/functions.lua")
+dofile(path.."/claims.lua")
+dofile(path.."/protection.lua")
+dofile(path.."/shared_door.lua")
+dofile(path.."/chest.lua")
+dofile(path.."/sign.lua")
- minetest.chat_send_player( name, "You are griefing "..claims[chunk].owner )
- return true
- end
- end
- return claims[chunk].owner == name or claims[chunk].shared[name]
+if ( landrush.config:get_bool("enableHud") ) then
+ dofile(path.."/hud.lua")
end
-landrush.default_place = minetest.item_place
-landrush.default_dig = minetest.node_dig
-
--- Redefined Lua:
-function minetest.node_dig(pos, node, digger)
- local player = digger:get_player_name()
- if landrush.can_interact(player, pos) or player == "" then
- landrush.default_dig(pos, node, digger)
- else
- local owner = landrush.get_owner(pos)
- if ( owner ~= nil ) then
- minetest.chat_send_player(player, "Area owned by "..owner.." stop trying to dig here!")
- digger:set_hp( digger:get_hp() - offenseDamage )
- --[[ **********************************************
- START THE AUTOBAN SECTION!!
- ***********************************************]]
- if ( autoBan == true ) then
- if ( offense[player] == nil ) then
- offense[player] = {count=0,lastpos=nil,lasttime=os.time(),bancount=0}
- end
-
- local timediff = (os.time() - offense[player].lasttime)/60
- local distance = landrush.get_distance(offense[player].lastpos,pos)
-
- -- reset offenses after a given time period
- if timediff > offenseReset then
- offense[player].count=0
- end
-
- -- 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 make it fair for people who aren't
- -- intentionally griefing
- offenseAmount = ( 10 - ( timediff / 10 ) ) - ( ( distance / chunkSize ) * 0.5 )
-
- offense[player].count=offense[player].count + offenseAmount
- minetest.log("action",player.." greifing attempt")
-
- if ( offense[player].count > banLevel ) then
- offense[player].bancount = offense[player].bancount + 1
-
- local banlength = offense[player].bancount * 10
-
- if ( offense[player].bancount < 4 ) then
- minetest.chat_send_player(player, "You have been banned for "..tostring(banlength).." minutes!")
- else
- minetest.chat_send_player(player, "You have been banned!")
- end
-
- minetest.log("action",player.." has been banned for griefing attempts")
- minetest.chat_send_all(player.." has been banned for griefing attempts")
-
- if ( chatplus and adminUser ~= nil) then
- table.insert(chatplus.players[adminUser].messages,"mail from <LandRush>: "..player.." banned for "..tostring(banlength).." minutes for attempted griefing")
- end
- minetest.ban_player(player)
-
- offense[player].count = 0
- offense[player].lastpos = nil
-
- if ( offense[player].bancount < 4 ) then
- minetest.after( (banlength * 60), minetest.unban_player_or_ip,player )
- end
-
- return
- end
-
- if ( offense[player].count > banWarning ) then
- minetest.chat_send_player(player, "Stop trying to dig in claimed areas or you will be banned!")
- minetest.chat_send_player(player, "Use /showarea and /landowner to see the protected area and who owns it.")
- minetest.sound_play("landrush_ban_warning", {to_player=player,gain = 10.0})
- end
-
- offense[player].lasttime = os.time()
- offense[player].lastpos = pos
-
- end
- --[[ **********************************************
- END THE AUTOBAN SECTION!!
- ***********************************************]]
- else
- -- allow them to dig the global dig list
- if ( global_dig_list[node['name']] ~= true ) then
- minetest.chat_send_player(player,"Area unclaimed, claim this area to build")
- else
- landrush.default_dig(pos, node, digger)
- end
- end
- end
-end
-
-function minetest.item_place(itemstack, placer, pointed_thing)
- owner = landrush.get_owner(pointed_thing.above)
- player = placer:get_player_name()
- if landrush.can_interact(player, pointed_thing.above) or itemstack:get_name() == "" then
- -- add a workaround for TNT, since overwriting the registered node seems not to work
- if itemstack:get_name() == "tnt:tnt" or itemstack:get_name() == "tnt:tnt_burning" then
- local pos = pointed_thing.above
- local temp_pos = pos
- temp_pos.x = pos.x + 2
- if player ~= landrush.get_owner( temp_pos ) then
- minetest.chat_send_player( player, "Do not place TNT near claimed areas..." )
- return itemstack
- end
- temp_pos.x = pos.x - 2
- if player ~= landrush.get_owner( temp_pos ) then
- minetest.chat_send_player( player, "Do not place TNT near claimed areas..." )
- return itemstack
- end
- temp_pos.z = pos.z + 2
- if player ~= landrush.get_owner( temp_pos ) then
- minetest.chat_send_player( player, "Do not place TNT near claimed areas..." )
- return itemstack
- end
- temp_pos.z = pos.z - 2
- if player ~= landrush.get_owner( temp_pos ) then
- minetest.chat_send_player( player, "Do not place TNT near claimed areas..." )
- return itemstack
- end
- end
- -- end of the workaround
- return landrush.default_place(itemstack, placer, pointed_thing)
- else
- if ( owner ~= nil ) then
- minetest.chat_send_player(player, "Area owned by "..owner)
- return itemstack
- else
- minetest.chat_send_player(player,"Area unclaimed, claim this area to build")
- return itemstack
- end
- end
-end
+minetest.register_privilege("landrush", "Allows player to dig and build anywhere, and use the landrush chat commands.")
landrush.load_claims()
--- Load now
minetest.register_node("landrush:landclaim", {
description = "Land Rush Land Claim",
@@ -317,9 +43,9 @@ landrush.load_claims()
else
minetest.env:remove_node(pointed_thing.above)
chunk = landrush.get_chunk(pointed_thing.above)
- claims[chunk] = {owner=placer:get_player_name(),shared={},claimtype="landclaim"}
+ landrush.claims[chunk] = {owner=placer:get_player_name(),shared={},claimtype="landclaim"}
landrush.save_claims()
- minetest.chat_send_player(claims[chunk].owner, "You now own this area.")
+ minetest.chat_send_player(landrush.claims[chunk].owner, "You now own this area.")
itemstack:take_item()
return itemstack
end
@@ -337,115 +63,6 @@ minetest.register_craft({
minetest.register_alias("landclaim", "landrush:landclaim")
minetest.register_alias("landrush:landclaim_b","landrush:landclaim")
-doors:register_door("landrush:shared_door", {
- description = "Shared Door",
- inventory_image = "shared_door_inv.png",
- groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2,door=1},
- tiles_bottom = {"shared_door_b.png", "door_blue.png"},
- tiles_top = {"shared_door_a.png", "door_blue.png"},
-})
-
-minetest.register_craft({
- output = 'landrush:shared_door',
- recipe = {
- {'default:steel_ingot','default:steel_ingot',''},
- {'default:steel_ingot','landrush:landclaim',''},
- {'default:steel_ingot','default:steel_ingot',''}
- }
-})
-
-function landrush.on_rightclick(pos, dir, check_name, replace, replace_dir, params)
- pos.y = pos.y+dir
- if not minetest.get_node(pos).name == check_name then
- return
- end
- local p2 = minetest.get_node(pos).param2
- p2 = params[p2+1]
-
- local meta = minetest.get_meta(pos):to_table()
- minetest.set_node(pos, {name=replace_dir, param2=p2})
- minetest.get_meta(pos):from_table(meta)
-
- pos.y = pos.y-dir
- meta = minetest.get_meta(pos):to_table()
- minetest.set_node(pos, {name=replace, param2=p2})
- minetest.get_meta(pos):from_table(meta)
- end
-
-minetest.registered_nodes['landrush:shared_door_b_1'].on_rightclick = function(pos, node, clicker)
-if ( landrush.can_interact(clicker:get_player_name(),pos) ) then
- landrush.on_rightclick(pos, 1, "landrush:shared_door_t_1", "landrush:shared_door_b_2", "landrush:shared_door_t_2", {1,2,3,0})
-end
-end
-
-minetest.registered_nodes['landrush:shared_door_t_1'].on_rightclick = function(pos, node, clicker)
-if ( landrush.can_interact(clicker:get_player_name(),pos) ) then
- landrush.on_rightclick(pos, -1, "landrush:shared_door_b_1", "landrush:shared_door_t_2", "landrush:shared_door_b_2", {1,2,3,0})
-end
-end
-
--- Fix for duplicating Bug!
--- Bug was caused, because the reverse order of the on_rightclick was not taken into account
-
-minetest.registered_nodes['landrush:shared_door_b_2'].on_rightclick = function(pos, node, clicker)
-if ( landrush.can_interact(clicker:get_player_name(),pos) ) then
- landrush.on_rightclick(pos, 1, "landrush:shared_door_t_2", "landrush:shared_door_b_1", "landrush:shared_door_t_1", {3,0,1,2})
-end
-end
-
-minetest.registered_nodes['landrush:shared_door_t_2'].on_rightclick = function(pos, node, clicker)
-if ( landrush.can_interact(clicker:get_player_name(),pos) ) then
- landrush.on_rightclick(pos, -1, "landrush:shared_door_b_2", "landrush:shared_door_t_1", "landrush:shared_door_b_1", {3,0,1,2})
-end
-end
-
--- End of fix
-
--- create a new type of sign that is not protected by landrush mod
-minetest.register_node("landrush:unlocked_sign", {
- description = "Unprotected Sign",
- drawtype = "signlike",
- tiles = {"default_sign_wall.png"},
- inventory_image = "default_sign_wall.png",
- wield_image = "default_sign_wall.png",
- paramtype = "light",
- paramtype2 = "wallmounted",
- sunlight_propagates = true,
- walkable = false,
- selection_box = {
- type = "wallmounted",
- --wall_top = <default>
- --wall_bottom = <default>
- --wall_side = <default>
- },
- groups = {choppy=2,dig_immediate=2,attached_node=1},
- legacy_wallmounted = true,
- sounds = default.node_sound_defaults(),
- on_construct = function(pos)
- --local n = minetest.get_node(pos)
- local meta = minetest.get_meta(pos)
- meta:set_string("formspec", "field[text;;${text}]")
- meta:set_string("infotext", "\"\"")
- end,
- on_receive_fields = function(pos, formname, fields, sender)
- local meta = minetest.get_meta(pos)
- fields.text = fields.text or ""
- print((sender:get_player_name() or "").." wrote \""..fields.text..
- "\" to sign at "..minetest.pos_to_string(pos))
- meta:set_string("text", fields.text)
- meta:set_string("infotext", '"'..fields.text..'"')
- end,
-})
-
-
-minetest.register_craft({
- output = 'landrush:unlocked_sign 6',
- recipe = {
- {'default:wood','default:wood','default:wood'},
- {'default:wood','default:wood','landrush:landclaim'},
- {'','default:stick',''}
- }
-})
minetest.register_entity("landrush:showarea",{
on_activate = function(self, staticdata, dtime_s)
@@ -471,61 +88,11 @@ minetest.register_entity("landrush:showarea",{
}
})
-minetest.register_globalstep(function(dtime)
- gstepCount = gstepCount + dtime
- if ( gstepCount > 2 ) then
- gstepCount=0
- local oplayers = minetest.get_connected_players()
- for _,player in ipairs(oplayers) do
- local name = player:get_player_name()
- local sameowner = false
- owner = landrush.get_owner(player:getpos())
-
- if ( playerHudItems[name] ~= nil ) then
- if ( playerHudItems[name].lastowner == owner ) then
- -- same owner as last time don't update the hud
- sameowner = true
- end
- end
-
- if ( playerHudItems[name] ~= nil and sameowner == false ) then
- player:hud_remove(playerHudItems[name].hud)
- playerHudItems[name] = nil
- end
-
- if ( owner ~= nil and sameowner == false ) then
- --minetest.log('action','Redraw hud for '..name)
- playerHudItems[name] = {hud = player:hud_add({
- hud_elem_type = "text",
- name = "LandOwner",
- number = 0xFFFFFF,
- position = {x=.2, y=.98},
- text="Land Owner: "..owner,
- scale = {x=200,y=25},
- alignment = {x=0, y=0},
- }), lastowner=owner}
- end
- end
- end
-end)
-
-function landrush.get_distance(pos1,pos2)
-
- if ( pos1 ~= nil and pos2 ~= nil ) then
- return math.abs(math.floor(math.sqrt( (pos1.x - pos2.x)^2 + (pos1.z - pos2.z)^2 )))
- else
- return 0
- end
-
-end
-
if ( minetest.get_modpath("money2") ) then
minetest.log('action','Loading Landrush Land Sale')
dofile(path.."/landsale.lua")
end
-dofile(path.."/chest.lua")
-
minetest.after(0, function ()
dofile(path.."/default.lua")
diff --git a/landsale.lua b/landsale.lua
index f77f65d..96bc273 100644
--- a/landsale.lua
+++ b/landsale.lua
@@ -37,9 +37,9 @@ minetest.register_node("landrush:sale_block",{
local transfer = money.transfer(name,owner,price)
if ( transfer == nil ) then
chunk = landrush.get_chunk(pos)
- claims[chunk] = {owner=name,shared={},claimtype='landclaim'}
+ landrush.claims[chunk] = {owner=name,shared={},claimtype='landclaim'}
landrush.save_claims()
- minetest.chat_send_player(claims[chunk].owner, "You now own this claim.")
+ minetest.chat_send_player(landrush.claims[chunk].owner, "You now own this claim.")
minetest.remove_node(pos)
if ( chatplus ) then
@@ -54,15 +54,7 @@ minetest.register_node("landrush:sale_block",{
end
end
end,
---[[
- on_rightclick = function (pos, node, player, itemstack)
- name = player:get_player_name()
- owner = landrush.get_owner(pos)
- if ( name == owner ) then
- minetest.show_formspec(name,"landrush_sell",landrush.sell_formspec(pos,player))
- end
- end,
-]]
+
on_receive_fields = function ( pos, formname, fields, sender )
--process formspec
local name = sender:get_player_name()
diff --git a/protection.lua b/protection.lua
new file mode 100644
index 0000000..8e1f16f
--- /dev/null
+++ b/protection.lua
@@ -0,0 +1,188 @@
+landrush.offense = {}
+
+function landrush.can_interact(pos, name)
+
+ if ( pos.y < -200 ) then
+ return true
+ end
+
+ if ( minetest.check_player_privs(name, {landrush=true}) ) then
+ return true
+ end
+
+ local chunk = landrush.get_chunk(pos)
+
+ if ( landrush.claims[chunk] ~= nil ) then
+ if ( landrush.claims[chunk].shared['*all'] ) then
+ return true
+ end
+ end
+
+
+ -- return landrush.claims[chunk] == nil or landrush.claims[chunk].owner == name or landrush.claims[chunk].shared[name]
+ if ( landrush.claims[chunk] == nil ) then
+ if ( landrush.config:get_bool("requireClaim") == true ) then
+ return false
+ else
+ return true
+ end
+ end
+
+ -- see if the owner is offline, and area is not shared then it's off limits
+ if ( landrush.claims[chunk].owner ~= name and landrush.config:get_bool("onlineProtection") == false ) then
+ if ( minetest.get_player_by_name(owner) ~= nil ) then
+ minetest.chat_send_player( landrush.claims[chunk].owner, "You are being griefed by "..name.." at "..minetest.pos_to_string(pos) )
+
+ for u,u in pairs(landrush.claims[chunk].shared) do
+ minetest.chat_send_player( u, 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 )
+ return true
+ end
+ end
+ return landrush.claims[chunk].owner == name or landrush.claims[chunk].shared[name]
+end
+
+function landrush.do_autoban(pos,name)
+ -- moved this to it's own function so landrush.protection_violation is a little cleaner, and this could be overwritten as well
+ 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
+
+ -- 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 make it fair for people who aren't
+ -- intentionally griefing
+ offenseAmount = ( 10 - ( timediff / 10 ) ) - ( ( distance / landrush.config:get("chunkSize") ) * 0.5 )
+
+ landrush.offense[name].count=landrush.offense[name].count + offenseAmount
+ minetest.log("action",name.." greifing attempt")
+
+ if ( landrush.offense[name].count > tonumber(landrush.config:get("banLevel")) ) then
+ landrush.offense[name].bancount = landrush.offense[name].bancount + 1
+
+ local banlength = landrush.offense[name].bancount * 10
+
+ if ( landrush.offense[name].bancount < 4 ) then
+ minetest.chat_send_player(name, "You have been banned for "..tostring(banlength).." minutes!")
+ else
+ minetest.chat_send_player(name, "You have been banned!")
+ end
+
+ minetest.log("action",name.." has been banned for griefing attempts")
+ minetest.chat_send_all(name.." has been banned for griefing attempts")
+
+ if ( chatplus and landrush.config:get_string("adminUser") ~= nil) then
+ table.insert(chatplus.names[landrush.config:get_string("adminUser")].messages,"mail from <LandRush>: "..name.." banned for "..tostring(banlength).." minutes for attempted griefing")
+ end
+ minetest.ban_player(name)
+
+ landrush.offense[name].count = 0
+ landrush.offense[name].lastpos = nil
+
+ if ( landrush.offense[name].bancount < 4 ) then
+ minetest.after( (banlength * 60), minetest.unban_name_or_ip,name )
+ 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_name=name,gain = 10.0})
+ end
+
+ landrush.offense[name].lasttime = os.time()
+ landrush.offense[name].lastpos = pos
+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)
+ local owner = landrush.get_owner(pos)
+
+ if ( landrush.config:get_bool("requireClaim") == true ) then
+ if ( owner == nil ) then
+ minetest.chat_send_player(name,"This area is unowned, but you must claim it to build or mine")
+ return true
+ end
+ end
+
+ minetest.chat_send_player(name, "Area owned by "..tostring(owner).." stop trying to dig here!")
+ player:set_hp( player:get_hp() - landrush.config:get("offenseDamage") )
+
+ if ( landrush.config:get_bool("autoBan") == true ) then
+ landrush.do_autoban(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)
+ else
+ return true
+ end
+end
+
+minetest.register_on_protection_violation( landrush.protection_violation )
+
+
+-- I'm keeping this just for the TNT workaround
+landrush.default_place = minetest.item_place
+
+function minetest.item_place(itemstack, placer, pointed_thing)
+ owner = landrush.get_owner(pointed_thing.above)
+ name = placer:get_player_name()
+ if landrush.can_interact(pointed_thing.above,name) or itemstack:get_name() == "" then
+ -- add a workaround for TNT, since overwriting the registered node seems not to work
+ if itemstack:get_name() == "tnt:tnt" or itemstack:get_name() == "tnt:tnt_burning" then
+ local pos = pointed_thing.above
+ local temp_pos = pos
+ temp_pos.x = pos.x + 2
+ if name ~= landrush.get_owner( temp_pos ) then
+ minetest.chat_send_player( name, "Do not place TNT near claimed areas..." )
+ return itemstack
+ end
+ temp_pos.x = pos.x - 2
+ if name ~= landrush.get_owner( temp_pos ) then
+ minetest.chat_send_player( name, "Do not place TNT near claimed areas..." )
+ return itemstack
+ end
+ temp_pos.z = pos.z + 2
+ if name ~= landrush.get_owner( temp_pos ) then
+ minetest.chat_send_player( name, "Do not place TNT near claimed areas..." )
+ return itemstack
+ end
+ temp_pos.z = pos.z - 2
+ if name ~= landrush.get_owner( temp_pos ) then
+ minetest.chat_send_player( name, "Do not place TNT near claimed areas..." )
+ return itemstack
+ end
+ end
+ -- end of the workaround
+ return landrush.default_place(itemstack, placer, pointed_thing)
+ else
+ if ( owner ~= nil ) then
+ minetest.chat_send_player(name, "Area owned by "..owner)
+ return itemstack
+ else
+ minetest.chat_send_player(name,"Area unclaimed, claim this area to build")
+ return itemstack
+ end
+ end
+end
+
diff --git a/shared_door.lua b/shared_door.lua
new file mode 100644
index 0000000..a876485
--- /dev/null
+++ b/shared_door.lua
@@ -0,0 +1,63 @@
+function landrush.on_rightclick(pos, dir, check_name, replace, replace_dir, params)
+ pos.y = pos.y+dir
+ if not minetest.get_node(pos).name == check_name then
+ return
+ end
+ local p2 = minetest.get_node(pos).param2
+ p2 = params[p2+1]
+
+ local meta = minetest.get_meta(pos):to_table()
+ minetest.set_node(pos, {name=replace_dir, param2=p2})
+ minetest.get_meta(pos):from_table(meta)
+
+ pos.y = pos.y-dir
+ meta = minetest.get_meta(pos):to_table()
+ minetest.set_node(pos, {name=replace, param2=p2})
+ minetest.get_meta(pos):from_table(meta)
+ end
+
+doors:register_door("landrush:shared_door", {
+ description = "Shared Door",
+ inventory_image = "shared_door_inv.png",
+ groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2,door=1},
+ tiles_bottom = {"shared_door_b.png", "door_blue.png"},
+ tiles_top = {"shared_door_a.png", "door_blue.png"},
+})
+
+minetest.register_craft({
+ output = 'landrush:shared_door',
+ recipe = {
+ {'default:steel_ingot','default:steel_ingot',''},
+ {'default:steel_ingot','landrush:landclaim',''},
+ {'default:steel_ingot','default:steel_ingot',''}
+ }
+})
+
+
+
+minetest.registered_nodes['landrush:shared_door_b_1'].on_rightclick = function(pos, node, clicker)
+if ( landrush.can_interact(clicker:get_player_name(),pos) ) then
+ landrush.on_rightclick(pos, 1, "landrush:shared_door_t_1", "landrush:shared_door_b_2", "landrush:shared_door_t_2", {1,2,3,0})
+end
+end
+
+minetest.registered_nodes['landrush:shared_door_t_1'].on_rightclick = function(pos, node, clicker)
+if ( landrush.can_interact(clicker:get_player_name(),pos) ) then
+ landrush.on_rightclick(pos, -1, "landrush:shared_door_b_1", "landrush:shared_door_t_2", "landrush:shared_door_b_2", {1,2,3,0})
+end
+end
+
+-- Fix for duplicating Bug!
+-- Bug was caused, because the reverse order of the on_rightclick was not taken into account
+
+minetest.registered_nodes['landrush:shared_door_b_2'].on_rightclick = function(pos, node, clicker)
+if ( landrush.can_interact(clicker:get_player_name(),pos) ) then
+ landrush.on_rightclick(pos, 1, "landrush:shared_door_t_2", "landrush:shared_door_b_1", "landrush:shared_door_t_1", {3,0,1,2})
+end
+end
+
+minetest.registered_nodes['landrush:shared_door_t_2'].on_rightclick = function(pos, node, clicker)
+if ( landrush.can_interact(clicker:get_player_name(),pos) ) then
+ landrush.on_rightclick(pos, -1, "landrush:shared_door_b_2", "landrush:shared_door_t_1", "landrush:shared_door_b_1", {3,0,1,2})
+end
+end
diff --git a/sign.lua b/sign.lua
new file mode 100644
index 0000000..83b33d6
--- /dev/null
+++ b/sign.lua
@@ -0,0 +1,45 @@
+-- create a new type of sign that is not protected by landrush mod
+minetest.register_node("landrush:unlocked_sign", {
+ description = "Unprotected Sign",
+ drawtype = "signlike",
+ tiles = {"default_sign_wall.png"},
+ inventory_image = "default_sign_wall.png",
+ wield_image = "default_sign_wall.png",
+ paramtype = "light",
+ paramtype2 = "wallmounted",
+ sunlight_propagates = true,
+ walkable = false,
+ selection_box = {
+ type = "wallmounted",
+ --wall_top = <default>
+ --wall_bottom = <default>
+ --wall_side = <default>
+ },
+ groups = {choppy=2,dig_immediate=2,attached_node=1},
+ legacy_wallmounted = true,
+ sounds = default.node_sound_defaults(),
+ on_construct = function(pos)
+ --local n = minetest.get_node(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("formspec", "field[text;;${text}]")
+ meta:set_string("infotext", "\"\"")
+ end,
+ on_receive_fields = function(pos, formname, fields, sender)
+ local meta = minetest.get_meta(pos)
+ fields.text = fields.text or ""
+ print((sender:get_player_name() or "").." wrote \""..fields.text..
+ "\" to sign at "..minetest.pos_to_string(pos))
+ meta:set_string("text", fields.text)
+ meta:set_string("infotext", '"'..fields.text..'"')
+ end,
+})
+
+
+minetest.register_craft({
+ output = 'landrush:unlocked_sign 6',
+ recipe = {
+ {'default:wood','default:wood','default:wood'},
+ {'default:wood','default:wood','landrush:landclaim'},
+ {'','default:stick',''}
+ }
+})