From decc7c12013299edba5f81d545e2bbcbf6d2c288 Mon Sep 17 00:00:00 2001 From: Ralf Weinert Date: Thu, 11 Apr 2019 23:19:43 +0200 Subject: [PATCH 1/6] start to implement RAZ --- areas.lua | 197 ++++++---- config.lua | 14 +- depends.txt | 3 +- functions.lua | 87 +++++ init.lua | 163 ++------- raz.lua | 978 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1239 insertions(+), 203 deletions(-) create mode 100644 functions.lua create mode 100644 raz.lua diff --git a/areas.lua b/areas.lua index f804f7f..30a2f1c 100644 --- a/areas.lua +++ b/areas.lua @@ -1,6 +1,135 @@ -- TODO: offer teleport button? + +-- returns the first area found +markers.get_area_by_pos1_pos2 = function(pos1, pos2) + for id, area in pairs(areas.areas) do + + if( ((area.pos1.x == pos1.x and area.pos1.z == pos1.z ) + or (area.pos1.x == pos1.x and area.pos1.z == pos2.z ) + or (area.pos1.x == pos2.x and area.pos1.z == pos1.z ) + or (area.pos1.x == pos2.x and area.pos1.z == pos2.z )) + + and((area.pos2.x == pos1.x and area.pos2.z == pos1.z ) + or (area.pos2.x == pos1.x and area.pos2.z == pos2.z ) + or (area.pos2.x == pos2.x and area.pos2.z == pos1.z ) + or (area.pos2.x == pos2.x and area.pos2.z == pos2.z ))) then + + -- at least pos1 needs to have a hight value that fits in + if( (area.pos1.y <= pos1.y and area.pos2.y >= pos1.y) + or (area.pos1.y >= pos1.y and area.pos2.y <= pos1.y)) then + + local found = area; + found[ 'id' ] = id; + return found; + + end + end + end + return nil; +end + + +-- protect/buy an area +markers.marker_on_receive_fields = function(pos, formname, fields, sender) + + if( not( pos )) then + minetest.chat_send_player( name, 'Sorry, could not find the marker you where using to access this formspec.' ); + return; + end + + + local meta = minetest.get_meta( pos ); + + local name = sender:get_player_name(); + + local coords_string = meta:get_string( 'coords' ); + if( not( coords_string ) or coords_string == '' ) then + minetest.chat_send_player( name, 'Could not find marked area. Please dig and place your markers again!'); + return; + end + local coords = minetest.deserialize( coords_string ); + + + -- do not protect areas twice + local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); + if( area ) then + + minetest.chat_send_player( name, 'This area is already protected.'); + return; + end + + + -- check input + local add_height = tonumber( fields['add_height'] ); + local add_depth = tonumber( fields['add_depth'] ); + + local error_msg = ''; + if( not( add_height ) or add_height < 0 or add_height > markers.MAX_HEIGHT ) then + minetest.chat_send_player( name, 'Please enter a number between 0 and '..tostring( markers.MAX_HEIGHT ).. + ' in the field where the height of your area is requested. Your area will stretch that many blocks '.. + 'up into the sky from the position of this marker onward.'); + error_msg = 'The height value\nhas to be larger than 0\nand smaller than '..tostring( markers.MAX_HEIGHT ); + + elseif( not( add_depth ) or add_depth < 0 or add_depth > markers.MAX_HEIGHT ) then + minetest.chat_send_player( name, 'Please enter a number between 0 and '..tostring( markers.MAX_HEIGHT ).. + ' in the field where the depth of your area is requested. Your area will stretch that many blocks '.. + 'into the ground from the position of this marker onward.'); + error_msg = 'The depth value\nhas to be larger than 0\nand smaller than '..tostring( markers.MAX_HEIGHT ); + + elseif( add_height + add_depth > markers.MAX_HEIGHT ) then + minetest.chat_send_player( name, 'Sorry, your area exceeds the height limit. Height and depth added have to '.. + 'be smaller than '..tostring( markers.MAX_HEIGHT )..'.'); + error_msg = 'height + depth has to\nbe smaller than '..tostring( markers.MAX_HEIGHT )..'.' + + elseif( not( fields[ 'set_area_name' ] ) or fields['set_area_name'] == 'please enter a name' ) then + minetest.chat_send_player( name, 'Please provide a name for your area, i.e. \"'.. + tostring( name )..'s first house\" The name ought to describe what you intend to build here.'); + error_msg = 'Please provide a\nname for your area!'; + + else + error_msg = nil; + end + + + if( error_msg ~= nil ) then + minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, error_msg)); + return; + end + + + -- those coords lack the height component + local pos1 = coords[1]; + local pos2 = coords[2]; + -- apply height values from the formspeck + pos1.y = pos1.y - add_depth; + pos2.y = pos2.y + add_height; + + pos1, pos2 = areas:sortPos( pos1, pos2 ); + + --minetest.chat_send_player('singleplayer','INPUT: '..minetest.serialize( pos1 )..' pos2: '..minetest.serialize( pos2 )); + minetest.log("action", "[markers] /protect invoked, owner="..name.. + " areaname="..fields['set_area_name'].. + " startpos="..minetest.pos_to_string(pos1).. + " endpos=" ..minetest.pos_to_string(pos2)); + + local canAdd, errMsg = areas:canPlayerAddArea(pos1, pos2, name) + if not canAdd then + minetest.chat_send_player(name, "You can't protect that area: "..errMsg) + minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, errMsg)); + return + end + + local id = areas:add(name, fields['set_area_name'], pos1, pos2, nil) + areas:save() + + minetest.chat_send_player(name, "Area protected. ID: "..id) + + minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, nil)); +end + + -- Temporary compatibility function - see minetest PR#1180 if not vector.interpolate then vector.interpolate = function(pos1, pos2, factor) @@ -404,74 +533,6 @@ end --- shows where the area (defined by pos1/pos2) is located relative to the given position pos --- row_offset/col_offset are offsets for the formspec -markers.show_compass_marker = function( col_offset, row_offset, with_text, pos, pos1, pos2 ) - - local formspec = ''; --- TODO: show up/down information somehow --- TODO: what if checked with a land claim register? - - -- if possible, show how far the area streches into each direction relative to pos - if( pos.x >= pos1.x and pos.x <= pos2.x - and pos.y >= pos1.y and pos.y <= pos2.y - and pos.z >= pos1.z and pos.z <= pos2.z ) then - - if( with_text ) then - formspec = formspec.. - 'label[0.5,5.5;Dimensions of the area in relation to..]'.. --- TODO: check if there is a marker; else write 'position you clicked on' - 'label[4.7,5.5;the marker at '..minetest.pos_to_string( pos )..':]'.. - 'button_exit[8.0,5.5;2,0.5;list_areas_at;Local areas]'; - end - formspec = formspec.. - 'image['..col_offset..','..row_offset..';1,1;markers_stone.png]'.. - 'label['..(col_offset-0.8)..','..(row_offset+0.05)..';'..tostring( pos.x - pos1.x )..' m W]'.. - 'label['..(col_offset+1.0)..','..(row_offset+0.05)..';'..tostring( pos2.x - pos.x )..' m E]'.. - 'label['..(col_offset+0.1)..','..(row_offset+0.80)..';'..tostring( pos.z - pos1.z )..' m S]'.. - 'label['..(col_offset+0.1)..','..(row_offset-0.80)..';'..tostring( pos2.z - pos.z )..' m N]'; - - -- else show how far the area is away - else - - local starts_north = ''; - local starts_south = ''; - local starts_east = ''; - local starts_west = ''; - if( pos.z > pos2.z ) then - starts_north = ''; - starts_south = tostring( pos.z - pos2.z )..' m S'; - else - starts_north = tostring( pos1.z - pos.z )..' m N'; - starts_south = ''; - end - if( pos.x > pos2.x ) then - starts_east = ''; - starts_west = tostring( pos.x - pos2.x )..' m W'; - else - starts_east = tostring( pos1.x - pos.x )..' m E'; - starts_west = ''; - end - - - if( with_text ) then - formspec = formspec.. - 'label[0.5,5.5;Position of the area in relation to..]'.. --- TODO: check if there is a marker; else write 'position you clicked on' - 'label[4.7,5.5;the marker at '..minetest.pos_to_string( pos )..':]'.. - 'button_exit[8.0,5.5;2,0.5;list_areas_at;Local areas]'; - end - formspec = formspec.. - 'image['..col_offset..','..row_offset..';1,1;compass_side_top.png]'.. - 'label['..(col_offset-0.8)..','..(row_offset+0.05)..';'..starts_west..']'.. - 'label['..(col_offset+1.0)..','..(row_offset+0.05)..';'..starts_east..']'.. - 'label['..(col_offset+0.1)..','..(row_offset-0.80)..';'..starts_north..']'.. - 'label['..(col_offset+0.1)..','..(row_offset+0.80)..';'..starts_south..']'; - end - - return formspec; -end - -- formspec input needs to be handled diffrently diff --git a/config.lua b/config.lua index 99f655d..a9da00b 100644 --- a/config.lua +++ b/config.lua @@ -19,12 +19,14 @@ markers.MAX_SIZE = 4096; -- 64m * 64m= 4096 m^2 -- set to something >60000 in order to view all areas; set to a smaller -- value (i.e. 500) on multiplayer servers with many protected areas -if( #areas.areas > 1000 ) then - markers.AREA_RANGE = 100; -elseif( #areas.areas > 100 ) then - markers.AREA_RANGE = 1000; -else - markers.AREA_RANGE = 100000; +if markers.mod_areas_present then + if( #areas.areas > 1000 ) then + markers.AREA_RANGE = 100; + elseif( #areas.areas > 100 ) then + markers.AREA_RANGE = 1000; + else + markers.AREA_RANGE = 100000; + end end -- for most cases, the default values ought to work diff --git a/depends.txt b/depends.txt index a18cd91..91f9eaa 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,2 @@ -areas +areas? +raz? diff --git a/functions.lua b/functions.lua new file mode 100644 index 0000000..7fd9c44 --- /dev/null +++ b/functions.lua @@ -0,0 +1,87 @@ + + +-- shows where the area (defined by pos1/pos2) is located relative to the given position pos +-- row_offset/col_offset are offsets for the formspec +markers.show_compass_marker = function( col_offset, row_offset, with_text, pos, pos1, pos2 ) + + local formspec = ''; +-- TODO: show up/down information somehow +-- TODO: what if checked with a land claim register? + + -- if possible, show how far the area streches into each direction relative to pos + if( pos.x >= pos1.x and pos.x <= pos2.x + and pos.y >= pos1.y and pos.y <= pos2.y + and pos.z >= pos1.z and pos.z <= pos2.z ) then + + if( with_text ) then + formspec = formspec.. + 'label[0.5,5.5;Dimensions of the area in relation to..]'.. +-- TODO: check if there is a marker; else write 'position you clicked on' + 'label[4.7,5.5;the marker at '..minetest.pos_to_string( pos )..':]'.. + 'button_exit[8.0,5.5;2,0.5;list_areas_at;Local areas]'; + end + formspec = formspec.. + 'image['..col_offset..','..row_offset..';1,1;markers_stone.png]'.. + 'label['..(col_offset-0.8)..','..(row_offset+0.05)..';'..tostring( pos.x - pos1.x )..' m W]'.. + 'label['..(col_offset+1.0)..','..(row_offset+0.05)..';'..tostring( pos2.x - pos.x )..' m E]'.. + 'label['..(col_offset+0.1)..','..(row_offset+0.80)..';'..tostring( pos.z - pos1.z )..' m S]'.. + 'label['..(col_offset+0.1)..','..(row_offset-0.80)..';'..tostring( pos2.z - pos.z )..' m N]'; + + -- else show how far the area is away + else + + local starts_north = ''; + local starts_south = ''; + local starts_east = ''; + local starts_west = ''; + if( pos.z > pos2.z ) then + starts_north = ''; + starts_south = tostring( pos.z - pos2.z )..' m S'; + else + starts_north = tostring( pos1.z - pos.z )..' m N'; + starts_south = ''; + end + if( pos.x > pos2.x ) then + starts_east = ''; + starts_west = tostring( pos.x - pos2.x )..' m W'; + else + starts_east = tostring( pos1.x - pos.x )..' m E'; + starts_west = ''; + end + + + if( with_text ) then + formspec = formspec.. + 'label[0.5,5.5;Position of the area in relation to..]'.. +-- TODO: check if there is a marker; else write 'position you clicked on' + 'label[4.7,5.5;the marker at '..minetest.pos_to_string( pos )..':]'.. + 'button_exit[8.0,5.5;2,0.5;list_areas_at;Local areas]'; + end + formspec = formspec.. + 'image['..col_offset..','..row_offset..';1,1;compass_side_top.png]'.. + 'label['..(col_offset-0.8)..','..(row_offset+0.05)..';'..starts_west..']'.. + 'label['..(col_offset+1.0)..','..(row_offset+0.05)..';'..starts_east..']'.. + 'label['..(col_offset+0.1)..','..(row_offset-0.80)..';'..starts_north..']'.. + 'label['..(col_offset+0.1)..','..(row_offset+0.80)..';'..starts_south..']'; + end + + return formspec; +end + + +-- from areas modified with namespace +-- Modifies positions `pos1` and `pos2` so that each component of `pos1` +-- is less than or equal to its corresponding component of `pos2`, +-- returning the two positions. +function markers:sortPos(pos1, pos2) + if pos1.x > pos2.x then + pos2.x, pos1.x = pos1.x, pos2.x + end + if pos1.y > pos2.y then + pos2.y, pos1.y = pos1.y, pos2.y + end + if pos1.z > pos2.z then + pos2.z, pos1.z = pos1.z, pos2.z + end + return pos1, pos2 +end diff --git a/init.lua b/init.lua index 2e72af0..79a6458 100644 --- a/init.lua +++ b/init.lua @@ -1,50 +1,54 @@ --- markers are useful for measuring distances and for marking areas +-- markers are useful for measuring distances and for marking areas, regions or zones +-- it should work with areas and raz -- markers are protected from digging by other players for one day -- (the protection for the *marker* auto-expires then, and it can be digged) -markers = {} - -dofile(minetest.get_modpath("markers").."/config.lua"); -dofile(minetest.get_modpath("markers").."/areas.lua"); -dofile(minetest.get_modpath("markers").."/marker_stone.lua"); -dofile(minetest.get_modpath("markers").."/land_title_register.lua"); +markers = { --- returns the first area found -markers.get_area_by_pos1_pos2 = function(pos1, pos2) - for id, area in pairs(areas.areas) do +-- Paths and infos to the mod + worlddir = minetest.get_worldpath(), + modname = minetest.get_current_modname(), + modpath = minetest.get_modpath(minetest.get_current_modname()), + mod_areas_present = nil, + mod_raz_present = nil, +} - if( ((area.pos1.x == pos1.x and area.pos1.z == pos1.z ) - or (area.pos1.x == pos1.x and area.pos1.z == pos2.z ) - or (area.pos1.x == pos2.x and area.pos1.z == pos1.z ) - or (area.pos1.x == pos2.x and area.pos1.z == pos2.z )) - and((area.pos2.x == pos1.x and area.pos2.z == pos1.z ) - or (area.pos2.x == pos1.x and area.pos2.z == pos2.z ) - or (area.pos2.x == pos2.x and area.pos2.z == pos1.z ) - or (area.pos2.x == pos2.x and area.pos2.z == pos2.z ))) then +-- load the .luas +dofile(markers.modpath.."/config.lua") +dofile(markers.modpath.."/functions.lua") - -- at least pos1 needs to have a hight value that fits in - if( (area.pos1.y <= pos1.y and area.pos2.y >= pos1.y) - or (area.pos1.y >= pos1.y and area.pos2.y <= pos1.y)) then +-- check if areas or raz is installed +markers.mod_areas_present = minetest.get_modpath("areas") +markers.mod_raz_present = minetest.get_modpath("raz") - local found = area; - found[ 'id' ] = id; - return found; - - end - end - end - return nil; +if markers.mod_areas_present and markers.mod_raz_present then + minetest.log("error", "[" .. markers.modname .. "] areas and raz is installed - what shall be used!!!!!!") +elseif markers.mod_areas_present and not markers.mod_raz_present then + dofile(modpath.."/areas.lua") + minetest.log("action", "[" .. markers.modname .. "] areas is installed - load areas.lua") +elseif markers.mod_raz_present and not markers.mod_areas_present then + dofile(markers.modpath.."/raz.lua") + minetest.log("action", "[" .. markers.modname .. "] raz is installed - load raz.lua") +else + minetest.log("error", "[" .. markers.modname .. "] I fond no installed version of areas or raz - what shall be used!!!!!!") end +dofile(markers.modpath.."/marker_stone.lua") +dofile(markers.modpath.."/land_title_register.lua") --- this function is supposed to return a text string describing the price of the land between po1 and pos2 + + + + + +-- this function is supposed to return a text string describing the price of the land between pos1 and pos2 -- You can return somethiing like "for free" or "the promise to build anything good" as well as any -- real prices in credits or materials - it's really just a text here. -- Make sure you do not charge the player more than what you ask here. @@ -278,8 +282,7 @@ markers.get_marker_formspec = function(player, pos, error_msg) -- has the area already been defined? local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); - - + local size = (math.abs( coords[1].x - coords[2].x )+1) * (math.abs( coords[1].z - coords[2].z )+1); @@ -339,103 +342,7 @@ end --- protect/buy an area -markers.marker_on_receive_fields = function(pos, formname, fields, sender) - if( not( pos )) then - minetest.chat_send_player( name, 'Sorry, could not find the marker you where using to access this formspec.' ); - return; - end - - - local meta = minetest.get_meta( pos ); - - local name = sender:get_player_name(); - - local coords_string = meta:get_string( 'coords' ); - if( not( coords_string ) or coords_string == '' ) then - minetest.chat_send_player( name, 'Could not find marked area. Please dig and place your markers again!'); - return; - end - local coords = minetest.deserialize( coords_string ); - - - -- do not protect areas twice - local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); - if( area ) then - - minetest.chat_send_player( name, 'This area is already protected.'); - return; - end - - - -- check input - local add_height = tonumber( fields['add_height'] ); - local add_depth = tonumber( fields['add_depth'] ); - - local error_msg = ''; - if( not( add_height ) or add_height < 0 or add_height > markers.MAX_HEIGHT ) then - minetest.chat_send_player( name, 'Please enter a number between 0 and '..tostring( markers.MAX_HEIGHT ).. - ' in the field where the height of your area is requested. Your area will stretch that many blocks '.. - 'up into the sky from the position of this marker onward.'); - error_msg = 'The height value\nhas to be larger than 0\nand smaller than '..tostring( markers.MAX_HEIGHT ); - - elseif( not( add_depth ) or add_depth < 0 or add_depth > markers.MAX_HEIGHT ) then - minetest.chat_send_player( name, 'Please enter a number between 0 and '..tostring( markers.MAX_HEIGHT ).. - ' in the field where the depth of your area is requested. Your area will stretch that many blocks '.. - 'into the ground from the position of this marker onward.'); - error_msg = 'The depth value\nhas to be larger than 0\nand smaller than '..tostring( markers.MAX_HEIGHT ); - - elseif( add_height + add_depth > markers.MAX_HEIGHT ) then - minetest.chat_send_player( name, 'Sorry, your area exceeds the height limit. Height and depth added have to '.. - 'be smaller than '..tostring( markers.MAX_HEIGHT )..'.'); - error_msg = 'height + depth has to\nbe smaller than '..tostring( markers.MAX_HEIGHT )..'.' - - elseif( not( fields[ 'set_area_name' ] ) or fields['set_area_name'] == 'please enter a name' ) then - minetest.chat_send_player( name, 'Please provide a name for your area, i.e. \"'.. - tostring( name )..'s first house\" The name ought to describe what you intend to build here.'); - error_msg = 'Please provide a\nname for your area!'; - - else - error_msg = nil; - end - - - if( error_msg ~= nil ) then - minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, error_msg)); - return; - end - - - -- those coords lack the height component - local pos1 = coords[1]; - local pos2 = coords[2]; - -- apply height values from the formspeck - pos1.y = pos1.y - add_depth; - pos2.y = pos2.y + add_height; - - pos1, pos2 = areas:sortPos( pos1, pos2 ); - - --minetest.chat_send_player('singleplayer','INPUT: '..minetest.serialize( pos1 )..' pos2: '..minetest.serialize( pos2 )); - minetest.log("action", "[markers] /protect invoked, owner="..name.. - " areaname="..fields['set_area_name'].. - " startpos="..minetest.pos_to_string(pos1).. - " endpos=" ..minetest.pos_to_string(pos2)); - - local canAdd, errMsg = areas:canPlayerAddArea(pos1, pos2, name) - if not canAdd then - minetest.chat_send_player(name, "You can't protect that area: "..errMsg) - minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, errMsg)); - return - end - - local id = areas:add(name, fields['set_area_name'], pos1, pos2, nil) - areas:save() - - minetest.chat_send_player(name, "Area protected. ID: "..id) - - minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, nil)); -end diff --git a/raz.lua b/raz.lua new file mode 100644 index 0000000..dc0a0ea --- /dev/null +++ b/raz.lua @@ -0,0 +1,978 @@ + +function markers:convert_to_areas(id) + local this_area = {} + local pos1,pos2,data = raz:get_region_data_by_id(id) + this_area[ 'id' ] = id + this_area[ 'owner' ] = data.owner + this_area[ 'name' ] = data.region_name + this_area[ 'pos1' ] = pos1 + this_area[ 'pos2' ] = pos2 + this_area[ 'guests' ] = raz:convert_string_to_table(data.guests, ",") + return this_area +end + +--+++++++++++++++++++++++++++++++++++++++ +-- +-- get area by pos1 uand pos2 +-- +--+++++++++++++++++++++++++++++++++++++++ +-- input: pos1, pos2 as vector (table) +-- returns the first area found +-- msg/error handling: no +-- return nil if the is no area +-- return id of the first found area +markers.get_area_by_pos1_pos2 = function(pos1, pos2) + -- get nil or id of th efirst area + local found_id = raz:get_area_by_pos1_pos2(pos1, pos2) + --minetest.log("action", "[" .. raz.modname .. "] raz:get_area_by_pos1_pos2(pos1, pos2):"..tostring(minetest.serialize(found)) ) + if found_id ~= nil then + --local data = raz:get_region_datatable(found_id) + local return_table = markers:convert_to_areas(found_id) + --return_table[ 'id' ] = found_id + --return_table[ 'owner' ] = data.owner + --return_table[ 'name' ] = data.region_name + + return return_table + else + return nil + end +end + + + + +-- protect/buy an area +markers.marker_on_receive_fields = function(pos, formname, fields, sender) + + + if( not( pos )) then + minetest.log("action", "[" .. markers.modname .. "] markers.marker_on_receive_fields nor )pos) sender = "..tostring(sender) ) + minetest.chat_send_player( name, 'Sorry, could not find the marker you where using to access this formspec.' ); + return; + end + + + local meta = minetest.get_meta( pos ); + + local name = sender:get_player_name(); + + local coords_string = meta:get_string( 'coords' ); + if( not( coords_string ) or coords_string == '' ) then + minetest.chat_send_player( name, 'Could not find marked area. Please dig and place your markers again!'); + return; + end + local coords = minetest.deserialize( coords_string ); + + + -- do not protect areas twice + local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); + if( area ) then + minetest.log("action", "[" .. markers.modname .. "] markers.marker_on_receive_fields area = :"..tostring(area) ) + minetest.chat_send_player( name, 'This area is already protected.'); + return; + end + + + -- check input + local add_height = tonumber( fields['add_height'] ); + local add_depth = tonumber( fields['add_depth'] ); + + local error_msg = ''; + if( not( add_height ) or add_height < 0 or add_height > markers.MAX_HEIGHT ) then + minetest.chat_send_player( name, 'Please enter a number between 0 and '..tostring( markers.MAX_HEIGHT ).. + ' in the field where the height of your area is requested. Your area will stretch that many blocks '.. + 'up into the sky from the position of this marker onward.'); + error_msg = 'The height value\nhas to be larger than 0\nand smaller than '..tostring( markers.MAX_HEIGHT ); + + elseif( not( add_depth ) or add_depth < 0 or add_depth > markers.MAX_HEIGHT ) then + minetest.chat_send_player( name, 'Please enter a number between 0 and '..tostring( markers.MAX_HEIGHT ).. + ' in the field where the depth of your area is requested. Your area will stretch that many blocks '.. + 'into the ground from the position of this marker onward.'); + error_msg = 'The depth value\nhas to be larger than 0\nand smaller than '..tostring( markers.MAX_HEIGHT ); + + elseif( add_height + add_depth > markers.MAX_HEIGHT ) then + minetest.chat_send_player( name, 'Sorry, your area exceeds the height limit. Height and depth added have to '.. + 'be smaller than '..tostring( markers.MAX_HEIGHT )..'.'); + error_msg = 'height + depth has to\nbe smaller than '..tostring( markers.MAX_HEIGHT )..'.' + + elseif( not( fields[ 'set_area_name' ] ) or fields['set_area_name'] == 'please enter a name' ) then + minetest.chat_send_player( name, 'Please provide a name for your area, i.e. \"'.. + tostring( name )..'s first house\" The name ought to describe what you intend to build here.'); + error_msg = 'Please provide a\nname for your area!'; + + else + error_msg = nil; + end + + + if( error_msg ~= nil ) then + minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, error_msg)); + return; + end + + + -- those coords lack the height component + local pos1 = coords[1]; + local pos2 = coords[2]; + -- apply height values from the formspeck + pos1.y = pos1.y - add_depth; + pos2.y = pos2.y + add_height; + + -- warum? wird das gemacht? + pos1, pos2 = markers:sortPos( pos1, pos2 ); + + --minetest.chat_send_player('singleplayer','INPUT: '..minetest.serialize( pos1 )..' pos2: '..minetest.serialize( pos2 )); + minetest.log("action", "[markers] /protect invoked, owner="..name.. + " areaname="..fields['set_area_name'].. + " startpos="..minetest.pos_to_string(pos1).. + " endpos=" ..minetest.pos_to_string(pos2)); + + local canAdd, errMsg = raz:player_can_add_region(pos1, pos2, name) + minetest.chat_send_player(name, "CanAdd = "..tostring(canAdd).." err = "..tostring(errMsg)) + if canAdd == false then + minetest.chat_send_player(name, "You can't protect that area: "..tostring(errMsg)) + minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, errMsg)); + return + end + + local data = raz:create_data(name,fields['set_area_name'],true) + local id = raz:set_region(pos1,pos2,data) + minetest.chat_send_player(name, "Area protected. ID: "..tostring(id)) + + minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, nil)); + +end + + +-- Temporary compatibility function - see minetest PR#1180 +if not vector.interpolate then + vector.interpolate = function(pos1, pos2, factor) + return {x = pos1.x + (pos2.x - pos1.x) * factor, + y = pos1.y + (pos2.y - pos1.y) * factor, + z = pos1.z + (pos2.z - pos1.z) * factor} + end +end + +-- taken from mobf +local COLOR_RED = "#FF0000"; +local COLOR_GREEN = "#00FF00"; +local COLOR_WHITE = "#FFFFFF"; + + +-- we need to store which list we present to which player +markers.menu_data_by_player = {} + + +markers.get_area_by_pos = function(pos) + + local found_areas = raz.raz_store:get_areas_for_pos(pos) --{}; +-- for id, area in pairs(raz.raz_store:get_areas_for_pos(pos)) do + -- table.insert(found_areas, area ); + -- end + -- end + return found_areas; +end + + + +-- ppos: current player (or marker stone) position - used for sorting the list +-- mode: can be pos, player, all, subarea, main_areas +-- mode_data: content depends on mode +-- selected: display information about the area the player single-clicked on +markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, selected ) + + + local id_list = {}; + local title = '???'; + local tlabel = ''; + + -- expects a position in mode_data + if( mode=='pos' ) then + -- title would be too long for a label + title = 'All areas which contain position..'; + tlabel = '<'..minetest.pos_to_string( mode_data )..'>:'; + id_list = raz.raz_store:get_areas_for_pos(pos) +-- for id, area in pairs(areas.areas) do +-- + -- if( mode_data.x >= area.pos1.x and mode_data.x <= area.pos2.x and + -- mode_data.y >= area.pos1.y and mode_data.y <= area.pos2.y and + -- mode_data.z >= area.pos1.z and mode_data.z <= area.pos2.z )then-- +-- + -- table.insert( id_list, id ); + -- end + -- end + + -- expects a playername in mode_data + elseif( mode=='player' ) then + + title = 'All areas owned by player..'; + tlabel = '<'..tostring( mode_data )..'>:'; + local counter = 0 + local data = {} + while raz.raz_store:get_area(counter) do + data = raz:get_region_datatable(counter) + -- for id, area in pairs(areas.areas) do + + if( data.owner == mode_data ) then + table.insert( id_list, counter ); + end + counter = counter + 1 + end + + -- expects an area_id in mode_data + elseif( mode=='subareas' ) then + + title = 'All subareas of area..'; + tlabel = '<'..tostring( areas.areas[ mode_data ].name )..'> ['..tostring( mode_data )..']:'; + + -- for id, area in pairs(areas.areas) do +-- + -- if( area.parent and area.parent == mode_data ) then + -- table.insert( id_list, id ); + -- end + -- end + id_list = {1,2,4} + + -- show only areas that do not have parents + elseif( mode=='main_areas' ) then + title = 'All main areas withhin '..tostring( markers.AREA_RANGE )..' m:'; + tlabel = '*all main areas*'; + local counter = 0 + local data = {} + while raz.raz_store:get_area(counter) do + data = raz:get_region_datatable(counter) + -- for id, area in pairs(areas.areas) do + + if( data.parent == true ) then + table.insert( id_list, counter ); + end + counter = counter + 1 + end + + + elseif( mode=='all' ) then + title = 'All areas withhin '..tostring( markers.AREA_RANGE )..' m:'; + tlabel = '*all areas*'; + + local counter = 0 + local data = {} + while raz.raz_store:get_area(counter) do + table.insert( id_list, counter ); + counter = counter + 1 + end + end + + -- Sort the list of areas so the nearest comes first + local nearsorter = function(a, b) + -- maybe in AreaStore() min and max is user for pos1 , pos2 + return vector.distance(vector.interpolate(raz.raz_store:get_area(a).pos1, raz.raz_store:get_area(a).pos2, 0.5), ppos) < + vector.distance(vector.interpolate(raz.raz_store:get_area(b).pos1, raz.raz_store:get_area(b).pos2, 0.5), ppos) + end + table.sort(id_list, nearsorter) + + local formspec = 'size[10,9]'; + + title = minetest.formspec_escape( title ); + tlabel = minetest.formspec_escape( tlabel ); + + formspec = formspec.. + "label[0.5,0;"..title.."]".. + "label[4.7,0;"..tlabel.."]".. + "label[0.5,8.5;Doubleclick to select area.]".. + "label[4.7,8.5;Areas found: "..tostring( #id_list )..".]".. + "textlist[0.5,0.5;7,8;markers_area_list_selection;"; + + local liste = ''; + for i,v in ipairs( id_list ) do + if( liste ~= '' ) then + liste = liste..','; + end + liste = liste..minetest.formspec_escape( raz:get_region_status(pos) ); + + end + + -- highlight selected entry + if( selected ) then + formspec = formspec..liste..';'..selected..';false]'; + else + formspec = formspec..liste..';]'; + end + + local pname = player:get_player_name(); + if( not( markers.menu_data_by_player[ pname ] )) then + markers.menu_data_by_player[ pname ] = {}; + end + + -- display information about the location of the area the player clicked on + if( selected + and id_list[ selected ] + and raz.raz_store:get_area( id_list[ selected ]) ) then + + local this_area = raz.raz_store:get_area( id_list[ selected ]); + + local subareas = {}; +-- for i,v in pairs( areas.areas ) do +-- if( v.parent and v.parent == id_list[ selected ]) then +-- table.insert( subareas, i ); + -- end + -- end + + formspec = formspec.. + markers.show_compass_marker( 8.5, 3.0, false, pos, this_area.pos1, this_area.pos2 ); + + +-- if( this_area.parent) then +-- formspec = formspec.. +-- 'button[8.0,0.5;2,0.5;show_parent;'.. +-- minetest.formspec_escape( areas.areas[ this_area.parent ].name )..']'; + -- end + +-- if( #subareas > 0 ) then + -- formspec = formspec.. + -- 'button[8.0,1.0;2,0.5;list_subareas;'.. +-- minetest.formspec_escape( 'List subareas ('..tostring( #subareas )..')')..']'; +-- end + + + if( mode=='player' ) then + formspec = formspec.. + 'label[8.0,1.5;'.. + minetest.formspec_escape( this_area.owner..'\'s areas')..']'; + else + formspec = formspec.. + 'button[8.0,1.5;2,0.5;list_player_areas;'.. + minetest.formspec_escape( this_area.owner..'\'s areas')..']'; + end + + end + + formspec = formspec.. + 'button[8.0,8.5;2,0.5;list_main_areas;List all main areas]'; + + -- we need to remember especially the id_list - else it would be impossible to know what the + -- player selected + markers.menu_data_by_player[ pname ] = { + typ = 'area_list', + mode = mode, + pos = pos, + mode_data = mode_data, + list = id_list, + + selected = id_list[ selected ], + }; + + + return formspec; +end + + + + +-- shows a formspec with information about a particular area +-- pos is the position of the marker stone or place where the player clicked +-- with the land title register; it is used for relative display of coordinates +markers.get_area_desc_formspec = function( id, player, pos ) + + if( not id or not raz.raz_store:get_area( id )) then + return 'field[info;Error:;Area not found.]'; + end + -- build the this_area table + local this_area = markers:convert_to_areas(id) --{} --raz.raz_store:get_area( id ); + --local pos1,pos2,data = raz:get_region_data_by_id(id) + --this_area[ 'id' ] = id + --this_area[ 'owner' ] = data.owner + --this_area[ 'name' ] = data.region_name + --this_area[ 'pos1' ] = pos1 + --this_area[ 'pos2' ] = pos2 + --this_area[ 'guests' ] = raz:convert_string_to_table(data.guests, ",") + + local pname = player:get_player_name(); + + -- show some buttons only if area is owned by the player + local is_owner = false; + + if( this_area.owner == pname or minetest.check_player_privs(pname, { region_admin = true }) ) then + is_owner = true; + end + + local formspec = 'size[10,9]'.. + 'label[2.5,0.0;Area information and management]'.. + 'button_exit[4.7,7.0;1,0.5;abort;OK]'; + + -- general information about the area + formspec = formspec.. + 'label[0.5,1.0;This is area number ]'.. + 'label[4.7,1.0;'..tostring( id )..']'.. + + 'label[0.5,1.5;The area is called ]'.. + 'label[4.7,1.5;'..minetest.formspec_escape( this_area.name or '-not set-')..']'.. + + 'label[0.5,2.0;It is owned by ]'.. + 'label[4.7,2.0;'..minetest.formspec_escape( this_area.owner)..']'; + + + -- these functions are only available to the owner of the area + if( is_owner ) then + formspec = formspec.. + 'button_exit[8.0,0.0;2.2,0.7;change_owner;Change owner]'.. + 'button_exit[8.0,1.0;2.2,0.7;delete;Delete]'.. + 'button_exit[8.0,1.7;2.2,0.7;rename;Rename]'; --.. +-- 'button_exit[8.0,2.0;2,0.5;list_player_areas;My areas]'; +-- else +-- formspec = formspec.. +-- 'button_exit[8.0,2.0;2,0.5;list_player_areas;Player\'s areas]'; + end + + + + + -- show subowners and areas with the same coordinates + formspec = formspec.. + 'label[0.5,2.5;invited Guests of the area:]'; + local further_owners = this_area.guests--{}; + + if( #further_owners > 0 ) then + + formspec = formspec.. + 'label[4.7,2.5;'..minetest.formspec_escape( table.concat( further_owners, ', '))..'.]'; + + -- deleting subowners is done by deleting their areas + if( is_owner ) then + formspec = formspec.. + 'button_exit[8.0,2.5;2.2,0.5;add_guest;Add Guest]'.. + 'button_exit[8.0,3.0;2.2,0.5;ban_guest;remove Guest]'; + end + else + formspec = formspec.. + 'label[4.7,2.5;-none-]'; + + if( is_owner ) then + formspec = formspec.. + 'button_exit[8.0,2.5;2.2,0.5;add_guest;Add Guest]'.. + 'button_exit[8.0,3.0;2.2,0.5;ban_guest;remove Guest]'; + end + end + + + + -- does the area have subareas, i.e. is it a parent area for others? + local sub_areas = {}; + if( #sub_areas > 0 ) then + + formspec = formspec.. + 'label[0.5,4.0;Number of defined subareas:]'.. + 'label[4.7,4.0;'..tostring( #sub_areas )..']'.. + 'button_exit[8.0,4.0;2,0.5;list_subareas;List subareas]'; + -- else + -- formspec = formspec.. +-- 'label[0.5,4.0;There are no subareas defined.]'; + end + + + -- give information about the size of the area + local length_x = (math.abs( this_area.pos2.x - this_area.pos1.x )+1); + local length_y = (math.abs( this_area.pos2.y - this_area.pos1.y )+1); + local length_z = (math.abs( this_area.pos2.z - this_area.pos1.z )+1); + + formspec = formspec.. + 'label[0.5,4.5;The area extends from]'.. + 'label[4.7,4.5;'..minetest.pos_to_string( this_area.pos1 )..' to '..minetest.pos_to_string( this_area.pos2 )..'.]'.. + 'label[4.7,4.75;It spans '..tostring( length_x ).. + ' x '..tostring( length_z ).. + ' = '..tostring( length_x * length_z ).. + ' m^2. Height: '..tostring( length_y )..' m.]'; + + + formspec = formspec.. + markers.show_compass_marker( 2.0, 7.0, true, pos, this_area.pos1, this_area.pos2 ); + +-- TODO: buy / sell button + + local pname = player:get_player_name(); + if( not( markers.menu_data_by_player[ pname ] )) then + markers.menu_data_by_player[ pname ] = {}; + end + + -- we need to remember especially the id_list - else it would be impossible to know what the + -- player selected + markers.menu_data_by_player[ pname ] = + { typ = 'show_area', + mode = nil, + pos = pos, + mode_data = nil, + list = nil, + + selected = id, + }; + + return formspec; +end + + + + + +-- formspec input needs to be handled diffrently +markers.form_input_handler_areas = function( player, formname, fields) + + -- player name + local pname = player:get_player_name(); + local ppos = player:getpos() + + if( formname ~= "markers:info" + or not( player ) + or not( markers.menu_data_by_player[ pname ] )) then + + return false; + end + + local menu_data = markers.menu_data_by_player[ pname ]; + local formspec = ''; + + -- rename an area + if( fields.rename + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) -- there is an region for this ID + and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + if( not( area.name )) then + area.name = '-enter area name-'; + end + formspec = 'field[rename_new_name;Enter new name for area:;'..minetest.formspec_escape( area.name )..']'; + + elseif( fields.rename_new_name + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) -- there is an region for this ID + and ((raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) -- the owner of the ID/region is pname OR region_admin + or minetest.check_player_privs(pname, { region_admin = true }))) then + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + + -- actually rename the area + raz:region_set_attribute(pname, menu_data.selected, "region_name", fields.rename_new_name) + + minetest.chat_send_player( pname, 'Region successfully renamed.'); + -- shwo the renamed area + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + + + -- change owner the area + elseif( fields.change_owner + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected)) -- there is an region for this ID + then + + -- there are no checks here - those happen when the area is transferred + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + formspec = 'field[change_owner_name;Give area \"'..minetest.formspec_escape( area.name )..'\" to player:;-enter name of NEW OWNER-]'; + + elseif( fields.change_owner_name + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected)) -- there is an region for this + then + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + + -- only own areas can be transfered to another player (or region_admin) + if( area.owner ~= pname + and not( minetest.check_player_privs(pname, { region_admin = true }))) then + + minetest.chat_send_player( pname, 'Permission denied. You do not own the region.'); + + -- did pname has the correct privileg? + elseif( not( minetest.check_player_privs(pname, { region_set = true }))) then + + minetest.chat_send_player( pname, 'Permission denied. You do not have the correct privileg.'); + + -- the new Player do not exist + elseif( not( minetest.player_exists( fields.change_owner_name ))) then + + minetest.chat_send_player( pname, 'That player does not exist.'); + + else + -- actually change the owner + raz:region_set_attribute(pname, menu_data.selected, "owner", fields.change_owner_name) + + minetest.chat_send_player( pname, 'Your region '..tostring( area.name )..' has been transfered to '..tostring( fields.change_owner_name )..'.'); + + minetest.chat_send_player( fields.change_owner_name, pname..' has given you control over an region.') + end + + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + + -- add a guest - check id / region with ID + elseif( fields.add_guest + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID +-- and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname + + + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + + formspec = 'field[add_guest_name;Grant access to area \"'..minetest.formspec_escape( area.name )..'\" to player:;-enter player name-]'; + + elseif( fields.add_guest_name + -- the player has to own the area already; we need a diffrent name here + -- and fields.add_guest_name ~= pname + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID + -- and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + + + -- does the player exist? + if( not( minetest.player_exists( fields.add_guest_name ))) then + minetest.chat_send_player( pname, 'That player does not exist.'); + -- show the formspec + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + -- check privileg + elseif( not( minetest.check_player_privs(pname, { region_set = true }) -- privileg + and not (raz:get_region_attribute(menu_data.selected, "owner" ) == pname )) -- and owner + or not ( minetest.check_player_privs(pname, { region_admin = true })) ) then -- or admin + + minetest.chat_send_player( pname, 'Permission denied. You do not have the correct privileg.'); + + else + -- log the creation of the new area + minetest.log("action", pname.." add_guest through the markers-mod. guest = "..fields.add_guest_name.. + " AreaName = "..area.name.." ParentID = "..menu_data.selected.. + " StartPos = "..area.pos1.x..","..area.pos1.y..","..area.pos1.z.. + " EndPos = " ..area.pos2.x..","..area.pos2.y..","..area.pos2.z) + + -- actually addthe guest + raz:region_set_attribute(pname, menu_data.selected, "guest", fields.add_guest_name, true) + + + minetest.chat_send_player( fields.add_guest_name, + "You have been invitedinto the region #".. + menu_data.selected..". Type /region list to show your region.") + + minetest.chat_send_player( pname, 'The player may now build and dig in your area.'); + -- shwo the new area + --markers.menu_data_by_player[ pname ].selected = new_id; + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + end + + -- ban a guest + elseif( fields.ban_guest + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID +-- and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname + + + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + + formspec = 'field[ban_guest_name;Grant access to area \"'..minetest.formspec_escape( area.name )..'\" to player:;-enter player name-]'; + + elseif( fields.ban_guest_name + -- the player has to own the area already; we need a diffrent name here + -- and fields.ban_guest_name ~= pname + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID + -- and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + + + -- does the player exist? + if( not( minetest.player_exists( fields.ban_guest_name ))) then + minetest.chat_send_player( pname, 'That player does not exist.'); + -- show the formspec + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + -- check privileg + elseif( not( minetest.check_player_privs(pname, { region_set = true }) -- privileg + and not (raz:get_region_attribute(menu_data.selected, "owner" ) == pname )) -- and owner + or not ( minetest.check_player_privs(pname, { region_admin = true })) ) then -- or admin + + minetest.chat_send_player( pname, 'Permission denied. You do not have the correct privileg.'); + + else + -- log the creation of the new area + minetest.log("action", pname.." add_guest through the markers-mod. guest = "..fields.ban_guest_name.. + " AreaName = "..area.name.." ParentID = "..menu_data.selected.. + " StartPos = "..area.pos1.x..","..area.pos1.y..","..area.pos1.z.. + " EndPos = " ..area.pos2.x..","..area.pos2.y..","..area.pos2.z) + + -- actually addthe guest + raz:region_set_attribute(pname, menu_data.selected, "guest", fields.ban_guest_name, false) + + + minetest.chat_send_player( fields.ban_guest_name, + "You have been invitedinto the region #".. + menu_data.selected..". Type /region list to show your region.") + + minetest.chat_send_player( pname, 'The player may now build and dig in your area.'); + -- shwo the new area + --markers.menu_data_by_player[ pname ].selected = new_id; + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + end + +--[[ + + -- delete area + elseif( fields.delete + and menu_data.selected + and areas.areas[ menu_data.selected ] ) then + + local area = areas.areas[ menu_data.selected ]; + + -- a player can only delete own areas or subareas of own areas + if( area.owner ~= pname + and not( area.parent + and areas.areas[ area.parent ] + and areas.areas[ area.parent ].owner + and areas.areas[ area.parent ].owner == pname ) + and not( minetest.check_player_privs(pname, {areas=true}))) then + + minetest.chat_send_player( pname, 'Permission denied. You own neither the area itshelf nor its parent area.'); + -- shwo the area where the renaming failed + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + else + + formspec = 'field[rename_new_name;Enter new name for area:;'..minetest.formspec_escape( area.name )..']'; + formspec = 'field[delete_confirm;'..minetest.formspec_escape( 'Really delete area \"'..area.name.. + '\" (owned by '..area.owner..')? Confirm with YES:')..';-type yes in capitals to confirm-]'; + + end + + elseif( fields.delete_confirm + and menu_data.selected + and areas.areas[ menu_data.selected ] ) then + + local area = areas.areas[ menu_data.selected ]; + local old_owner = area.owner; + + local subareas = {}; + for i,v in pairs( areas.areas ) do + if( v.parent and v.parent == menu_data.selected ) then + table.insert( subareas, i ); + end + end + + -- a player can only delete own areas or subareas of own areas + if( area.owner ~= pname + and not( area.parent + and areas.areas[ area.parent ] + and areas.areas[ area.parent ].owner + and areas.areas[ area.parent ].owner == pname ) + and not( minetest.check_player_privs(pname, {areas=true}))) then + + minetest.chat_send_player( pname, 'Permission denied. You own neither the area itshelf nor its parent area.'); + -- shwo the renamed area + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + -- avoid accidents + elseif( fields.delete_confirm ~= 'YES' ) then + minetest.chat_send_player( pname, 'Delition of area \"'..tostring( area.name )..'\" (owned by '..old_owner..') aborted.'); + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + -- only areas without subareas can be deleted + elseif( #subareas > 0 ) then + minetest.chat_send_player( pname, 'The area has '..tostring( #subareas )..' subarea(s). Please delete those first!'); + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + else + + minetest.chat_send_player( pname, 'Area \"'..tostring( area.name )..'\" (owned by '..old_owner..') deleted.'); + -- really delete + areas:remove( menu_data.selected, false ); -- no recursive delete + areas:save(); + -- show the list of areas owned by the previous owner + formspec = markers.get_area_list_formspec(ppos, player, 'player', menu_data.pos, old_owner, nil ); + end + + + + elseif( fields.show_parent + and menu_data.selected + and areas.areas[ menu_data.selected ] + and areas.areas[ menu_data.selected ].parent ) then + + formspec = markers.get_area_desc_formspec( areas.areas[ menu_data.selected ].parent, player, menu_data.pos ); + + + elseif( fields.list_player_areas + and menu_data.selected + and areas.areas[ menu_data.selected ] ) then + + formspec = markers.get_area_list_formspec(ppos, player, 'player', menu_data.pos, areas.areas[ menu_data.selected ].owner, nil ); + + + elseif( fields.list_subareas + and menu_data.selected + and areas.areas[ menu_data.selected ] ) then + + formspec = markers.get_area_list_formspec(ppos, player, 'subareas', menu_data.pos, menu_data.selected, nil ); + + + elseif( fields.list_main_areas ) then + + formspec = markers.get_area_list_formspec(ppos, player, 'main_areas', menu_data.pos, nil, nil ); + + elseif( fields.list_areas_at + and menu_data.pos ) then + + formspec = markers.get_area_list_formspec(ppos, player, 'pos', menu_data.pos, menu_data.pos, nil ); + + + elseif( fields.markers_area_list_selection + and menu_data.typ + and menu_data.typ == 'area_list' + and menu_data.list + and #menu_data.list > 0 ) then + + + local field_data = fields.markers_area_list_selection:split( ':' ); + if( not( field_data ) or #field_data < 2 ) then + field_data = { '', '' }; + end + + local selected = tonumber( field_data[ 2 ] ); + if( field_data[1]=='DCL' ) then + + -- on doubleclick, show detailed area information + formspec = markers.get_area_desc_formspec( tonumber( menu_data.list[ selected ] ), player, menu_data.pos ); + else + + -- on single click, just show the position of that particular area + formspec = markers.get_area_list_formspec(ppos, player, menu_data.mode, menu_data.pos, menu_data.mode_data, selected ); + end +]]-- + else + return false; + end + + + minetest.show_formspec( pname, "markers:info", formspec ) + return true; +end + + + +-- search the area at the given position pos that might be of most intrest to the player +markers.show_marker_stone_formspec = function( player, pos ) + + local pname = player:get_player_name(); + local ppos = pos + + -- this table stores the list the player may have selected from; at the beginning, there is no list + if( not( markers.menu_data_by_player[ pname ] )) then + markers.menu_data_by_player[ pname ] = { + typ = 'area_list', + mode = 'main_areas', + pos = pos, + mode_data = pos, + list = {}, + + selected = nil, + }; + end + + + local formspec = ''; + + local found_areas = {}; + local min_area_size = 100000000000; + + for id, area in pairs(raz.raz_store:get_areas_for_pos(pos)) do + --for id, area in pairs(areas.areas) do + -- if( pos.x >= area.pos1.x and pos.x <= area.pos2.x and + -- pos.y >= area.pos1.y and pos.y <= area.pos2.y and + -- pos.z >= area.pos1.z and pos.z <= area.pos2.z )then + + -- ignore y (height) value because some areas may go from bottom to top + local area_size = math.abs( area.max.x - area.min.x ) + * math.abs( area.max.z - area.min.z ); + + -- collect subareas that have the same size + if( area_size == min_area_size ) then + table.insert(found_areas, id ); + -- we have found a smaller area - that is more intresting here + elseif( area_size <= min_area_size ) then + found_areas = {}; + min_area_size = area_size; + table.insert(found_areas, id ); + end + -- end + end + + + -- no areas found; display error message and selection menu + if( #found_areas < 1 ) then + + formspec = 'size[4,3]'.. + 'label[0.5,0.5;This position is not protected.]'.. + 'button[1.0,1.5;2,0.5;list_main_areas;List all main areas]'.. + 'button_exit[3.0,1.5;1,0.5;abort;OK]'; + + -- found exactly one areaa - display it + elseif( #found_areas == 1 ) then + + formspec = markers.get_area_desc_formspec( found_areas[ 1 ], player, pos ); + + -- found more than one area; we have saved only those with the smallest size + else + + local own_area = 0; + local parent_area = 0; + local upper_area = 0; +--[[ + for i,v in ipairs( found_areas ) do + + local area = areas.areas[ v ]; + + -- owned by player? + if( area.owner == pname ) then + own_area = v; + + -- parentless area? + elseif( not( area.parent )) then + parent_area = v; + + -- the parent has diffrent coordinates? + elseif( areas.areas[ area.parent ].pos1.x ~= area.pos1.x + or areas.areas[ area.parent ].pos1.y ~= area.pos1.y + or areas.areas[ area.parent ].pos1.z ~= area.pos1.z + or areas.areas[ area.parent ].pos2.x ~= area.pos2.x + or areas.areas[ area.parent ].pos2.y ~= area.pos2.y + or areas.areas[ area.parent ].pos2.z ~= area.pos2.z ) then + upper_area = v; + end + end +]]-- + -- the area owned by the player is most intresting + if( own_area > 0 ) then + + formspec = markers.get_area_desc_formspec( own_area, player, pos ); + + -- if the player owns none of these areas, show the topmost (parentless) area + elseif( parent_area > 0 ) then + + formspec = markers.get_area_desc_formspec( parent_area, player, pos ); + + -- an area which has a parent with diffrent coordinates from its child may (or may not) be the + -- parent of all these subareas we've found here; there is no guarantee, but it's a best guess. + -- If it is not good enough, then the player can still search for himshelf. + elseif( upper_area > 0 ) then + + formspec = markers.get_area_desc_formspec( upper_area, player, pos ); + + -- our superficial analysis of the structure of the areas failed; it is up to the player to + -- find out which of the candidates he is intrested in; we list them all + else + + formspec = markers.get_area_list_formspec(ppos, player, 'pos', pos, pos, nil ); + end + end + + minetest.show_formspec( player:get_player_name(), "markers:info", formspec ); +end From 53b2e386bde17a0530eccfab1aa6b0a474c5c631 Mon Sep 17 00:00:00 2001 From: Ralf Weinert Date: Sat, 13 Apr 2019 22:15:11 +0200 Subject: [PATCH 2/6] added raz support! --- raz.lua | 660 +++++++++++++++++++++++++++----------------------------- 1 file changed, 314 insertions(+), 346 deletions(-) diff --git a/raz.lua b/raz.lua index dc0a0ea..a7c30ca 100644 --- a/raz.lua +++ b/raz.lua @@ -1,4 +1,13 @@ - +--+++++++++++++++++++++++++++++++++++++++ +-- +-- convert_to_areas +-- get region datatable from id and +-- makes an area table +-- +--+++++++++++++++++++++++++++++++++++++++ +-- input: region ID +-- msg/error handling: no +-- returns this_area as table in the area-format function markers:convert_to_areas(id) local this_area = {} local pos1,pos2,data = raz:get_region_data_by_id(id) @@ -11,26 +20,58 @@ function markers:convert_to_areas(id) return this_area end +--+++++++++++++++++++++++++++++++++++++++ +-- +-- check_region_mark +-- checks if pname is owner of an region and has the correct privileg +-- or is region_admin +-- +--+++++++++++++++++++++++++++++++++++++++ +-- input: region ID +-- msg/error handling: no +-- returns true - is owner with privileg or region_admin +function markers:check_region_mark(pname, owner) + if( owner == pname and minetest.check_player_privs(pname, { region_mark = true }) ) + or minetest.check_player_privs(pname, { region_admin = true }) then + return true; + end + return false +end + +--+++++++++++++++++++++++++++++++++++++++ +-- +-- check_region_mark +-- checks if pname is owner of an region and has the correct privileg +-- or is region_admin +-- +--+++++++++++++++++++++++++++++++++++++++ +-- input: region ID +-- msg/error handling: no +-- returns true - is owner with privileg or region_admin +function markers:check_region_set(pname, owner) + if( owner == pname and minetest.check_player_privs(pname, { region_set = true }) ) + or minetest.check_player_privs(pname, { region_admin = true }) then + return true; + end + return false +end + --+++++++++++++++++++++++++++++++++++++++ -- -- get area by pos1 uand pos2 +-- looks for the region in the pos1-pos2 zone -- --+++++++++++++++++++++++++++++++++++++++ -- input: pos1, pos2 as vector (table) -- returns the first area found -- msg/error handling: no -- return nil if the is no area --- return id of the first found area +-- return area-table with id of the first found area markers.get_area_by_pos1_pos2 = function(pos1, pos2) - -- get nil or id of th efirst area local found_id = raz:get_area_by_pos1_pos2(pos1, pos2) - --minetest.log("action", "[" .. raz.modname .. "] raz:get_area_by_pos1_pos2(pos1, pos2):"..tostring(minetest.serialize(found)) ) if found_id ~= nil then - --local data = raz:get_region_datatable(found_id) + local return_table = markers:convert_to_areas(found_id) - --return_table[ 'id' ] = found_id - --return_table[ 'owner' ] = data.owner - --return_table[ 'name' ] = data.region_name return return_table else @@ -38,20 +79,38 @@ markers.get_area_by_pos1_pos2 = function(pos1, pos2) end end +----------------------------------------- +-- +-- player can add region +-- +----------------------------------------- +-- check ich name has the privileg +-- pos1 and pos2 are not in an other region +-- the player/name has less when MAX-Regions set +-- msg/error handling: +-- return false, err-text +-- return true, nil +function markers:player_can_add_region(pos1, pos2, name) + if not minetest.check_player_privs(name, { region_mark = true }) then + return false, "You dont have the privileg 'region_mark' " + end + if raz:get_area_by_pos1_pos2(pos1, pos2) ~= nil then + return false, "The pos1,pos2 are in an other region! - You can not mark the region." + end + + return true, nil +end - --- protect/buy an area +-- protect an region markers.marker_on_receive_fields = function(pos, formname, fields, sender) - if( not( pos )) then minetest.log("action", "[" .. markers.modname .. "] markers.marker_on_receive_fields nor )pos) sender = "..tostring(sender) ) minetest.chat_send_player( name, 'Sorry, could not find the marker you where using to access this formspec.' ); return; end - local meta = minetest.get_meta( pos ); local name = sender:get_player_name(); @@ -118,17 +177,15 @@ markers.marker_on_receive_fields = function(pos, formname, fields, sender) pos1.y = pos1.y - add_depth; pos2.y = pos2.y + add_height; - -- warum? wird das gemacht? + -- sort pos1 and pos2 pos1, pos2 = markers:sortPos( pos1, pos2 ); - --minetest.chat_send_player('singleplayer','INPUT: '..minetest.serialize( pos1 )..' pos2: '..minetest.serialize( pos2 )); minetest.log("action", "[markers] /protect invoked, owner="..name.. " areaname="..fields['set_area_name'].. " startpos="..minetest.pos_to_string(pos1).. " endpos=" ..minetest.pos_to_string(pos2)); - local canAdd, errMsg = raz:player_can_add_region(pos1, pos2, name) - minetest.chat_send_player(name, "CanAdd = "..tostring(canAdd).." err = "..tostring(errMsg)) + local canAdd, errMsg = markers:player_can_add_region(pos1, pos2, name) if canAdd == false then minetest.chat_send_player(name, "You can't protect that area: "..tostring(errMsg)) minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, errMsg)); @@ -137,7 +194,7 @@ markers.marker_on_receive_fields = function(pos, formname, fields, sender) local data = raz:create_data(name,fields['set_area_name'],true) local id = raz:set_region(pos1,pos2,data) - minetest.chat_send_player(name, "Area protected. ID: "..tostring(id)) + minetest.chat_send_player(name, "Area protected. ID: "..tostring(id)) minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, nil)); @@ -154,9 +211,9 @@ if not vector.interpolate then end -- taken from mobf -local COLOR_RED = "#FF0000"; -local COLOR_GREEN = "#00FF00"; -local COLOR_WHITE = "#FFFFFF"; +--local COLOR_RED = "#FF0000"; +--local COLOR_GREEN = "#00FF00"; +--local COLOR_WHITE = "#FFFFFF"; -- we need to store which list we present to which player @@ -166,10 +223,7 @@ markers.menu_data_by_player = {} markers.get_area_by_pos = function(pos) local found_areas = raz.raz_store:get_areas_for_pos(pos) --{}; --- for id, area in pairs(raz.raz_store:get_areas_for_pos(pos)) do - -- table.insert(found_areas, area ); - -- end - -- end + return found_areas; end @@ -186,21 +240,14 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se local title = '???'; local tlabel = ''; + -- expects a position in mode_data if( mode=='pos' ) then -- title would be too long for a label title = 'All areas which contain position..'; tlabel = '<'..minetest.pos_to_string( mode_data )..'>:'; id_list = raz.raz_store:get_areas_for_pos(pos) --- for id, area in pairs(areas.areas) do --- - -- if( mode_data.x >= area.pos1.x and mode_data.x <= area.pos2.x and - -- mode_data.y >= area.pos1.y and mode_data.y <= area.pos2.y and - -- mode_data.z >= area.pos1.z and mode_data.z <= area.pos2.z )then-- --- - -- table.insert( id_list, id ); - -- end - -- end + -- expects a playername in mode_data elseif( mode=='player' ) then @@ -211,7 +258,6 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se local data = {} while raz.raz_store:get_area(counter) do data = raz:get_region_datatable(counter) - -- for id, area in pairs(areas.areas) do if( data.owner == mode_data ) then table.insert( id_list, counter ); @@ -219,29 +265,21 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se counter = counter + 1 end + -- expects an area_id in mode_data elseif( mode=='subareas' ) then - title = 'All subareas of area..'; - tlabel = '<'..tostring( areas.areas[ mode_data ].name )..'> ['..tostring( mode_data )..']:'; + minetest.log("error", "[" .. markers.modname .. "] {markers.get_area_list_formspec} there are no subareas in raz-mod.") - -- for id, area in pairs(areas.areas) do --- - -- if( area.parent and area.parent == mode_data ) then - -- table.insert( id_list, id ); - -- end - -- end - id_list = {1,2,4} - -- show only areas that do not have parents + -- show only regions that do have parent attribute = true elseif( mode=='main_areas' ) then - title = 'All main areas withhin '..tostring( markers.AREA_RANGE )..' m:'; - tlabel = '*all main areas*'; + title = 'All parent region withhin '..tostring( markers.AREA_RANGE )..' m:'; + tlabel = '*all parent regions *'; local counter = 0 local data = {} while raz.raz_store:get_area(counter) do data = raz:get_region_datatable(counter) - -- for id, area in pairs(areas.areas) do if( data.parent == true ) then table.insert( id_list, counter ); @@ -249,10 +287,10 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se counter = counter + 1 end - + -- show all regions elseif( mode=='all' ) then - title = 'All areas withhin '..tostring( markers.AREA_RANGE )..' m:'; - tlabel = '*all areas*'; + title = 'All regions withhin '..tostring( markers.AREA_RANGE )..' m:'; + tlabel = '*all regions*'; local counter = 0 local data = {} @@ -262,11 +300,10 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se end end - -- Sort the list of areas so the nearest comes first + -- Sort the list of regions so the nearest comes first local nearsorter = function(a, b) - -- maybe in AreaStore() min and max is user for pos1 , pos2 - return vector.distance(vector.interpolate(raz.raz_store:get_area(a).pos1, raz.raz_store:get_area(a).pos2, 0.5), ppos) < - vector.distance(vector.interpolate(raz.raz_store:get_area(b).pos1, raz.raz_store:get_area(b).pos2, 0.5), ppos) + return vector.distance(vector.interpolate(raz.raz_store:get_area(a).min, raz.raz_store:get_area(a).max, 0.5), ppos) < + vector.distance(vector.interpolate(raz.raz_store:get_area(b).min, raz.raz_store:get_area(b).max, 0.5), ppos) end table.sort(id_list, nearsorter) @@ -283,11 +320,13 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se "textlist[0.5,0.5;7,8;markers_area_list_selection;"; local liste = ''; + local liste_string = "" for i,v in ipairs( id_list ) do if( liste ~= '' ) then liste = liste..','; end - liste = liste..minetest.formspec_escape( raz:get_region_status(pos) ); + list_string = "ID = "..v.." - "..raz:get_region_attribute(v, "region_name") + liste = liste..minetest.formspec_escape( list_string ) end @@ -308,32 +347,11 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se and id_list[ selected ] and raz.raz_store:get_area( id_list[ selected ]) ) then - local this_area = raz.raz_store:get_area( id_list[ selected ]); - - local subareas = {}; --- for i,v in pairs( areas.areas ) do --- if( v.parent and v.parent == id_list[ selected ]) then --- table.insert( subareas, i ); - -- end - -- end + local this_area = markers:convert_to_areas( id_list[ selected ]); formspec = formspec.. markers.show_compass_marker( 8.5, 3.0, false, pos, this_area.pos1, this_area.pos2 ); - --- if( this_area.parent) then --- formspec = formspec.. --- 'button[8.0,0.5;2,0.5;show_parent;'.. --- minetest.formspec_escape( areas.areas[ this_area.parent ].name )..']'; - -- end - --- if( #subareas > 0 ) then - -- formspec = formspec.. - -- 'button[8.0,1.0;2,0.5;list_subareas;'.. --- minetest.formspec_escape( 'List subareas ('..tostring( #subareas )..')')..']'; --- end - - if( mode=='player' ) then formspec = formspec.. 'label[8.0,1.5;'.. @@ -376,30 +394,22 @@ markers.get_area_desc_formspec = function( id, player, pos ) if( not id or not raz.raz_store:get_area( id )) then return 'field[info;Error:;Area not found.]'; end - -- build the this_area table - local this_area = markers:convert_to_areas(id) --{} --raz.raz_store:get_area( id ); - --local pos1,pos2,data = raz:get_region_data_by_id(id) - --this_area[ 'id' ] = id - --this_area[ 'owner' ] = data.owner - --this_area[ 'name' ] = data.region_name - --this_area[ 'pos1' ] = pos1 - --this_area[ 'pos2' ] = pos2 - --this_area[ 'guests' ] = raz:convert_string_to_table(data.guests, ",") + + -- build the this_area table from raz_store data + local this_area = markers:convert_to_areas(id) local pname = player:get_player_name(); -- show some buttons only if area is owned by the player - local is_owner = false; - - if( this_area.owner == pname or minetest.check_player_privs(pname, { region_admin = true }) ) then - is_owner = true; - end + local has_region_mark = markers:check_region_mark(pname, this_area.owner) + local has_region_set = markers:check_region_set(pname, this_area.owner) + local formspec = 'size[10,9]'.. 'label[2.5,0.0;Area information and management]'.. 'button_exit[4.7,7.0;1,0.5;abort;OK]'; - -- general information about the area + -- general information about the region formspec = formspec.. 'label[0.5,1.0;This is area number ]'.. 'label[4.7,1.0;'..tostring( id )..']'.. @@ -411,64 +421,46 @@ markers.get_area_desc_formspec = function( id, player, pos ) 'label[4.7,2.0;'..minetest.formspec_escape( this_area.owner)..']'; - -- these functions are only available to the owner of the area - if( is_owner ) then + -- these functions are only available to the owner of the region with privileg region_set + if has_region_set then formspec = formspec.. - 'button_exit[8.0,0.0;2.2,0.7;change_owner;Change owner]'.. - 'button_exit[8.0,1.0;2.2,0.7;delete;Delete]'.. - 'button_exit[8.0,1.7;2.2,0.7;rename;Rename]'; --.. --- 'button_exit[8.0,2.0;2,0.5;list_player_areas;My areas]'; --- else --- formspec = formspec.. --- 'button_exit[8.0,2.0;2,0.5;list_player_areas;Player\'s areas]'; + 'button_exit[8.0,0.0;2.2,0.7;change_owner;Change owner]'; end - - + -- these functions are only available to the owner of the region with privileg region_mark + if has_region_mark then + formspec = formspec.. + 'button_exit[8.0,1.0;2.2,0.7;delete;Delete]'.. + 'button_exit[8.0,1.7;2.2,0.7;rename;Rename]' + end -- show subowners and areas with the same coordinates formspec = formspec.. 'label[0.5,2.5;invited Guests of the area:]'; - local further_owners = this_area.guests--{}; + local guests = this_area.guests--{}; - if( #further_owners > 0 ) then + if( #guests > 0 ) then formspec = formspec.. - 'label[4.7,2.5;'..minetest.formspec_escape( table.concat( further_owners, ', '))..'.]'; + 'label[4.7,2.5;'..minetest.formspec_escape( table.concat( guests, ', '))..'.]'; - -- deleting subowners is done by deleting their areas - if( is_owner ) then + if( has_region_set ) then formspec = formspec.. - 'button_exit[8.0,2.5;2.2,0.5;add_guest;Add Guest]'.. - 'button_exit[8.0,3.0;2.2,0.5;ban_guest;remove Guest]'; + 'button_exit[8.0,2.5;2.2,0.7;add_guest;Add Guest]'.. + 'button_exit[8.0,3.2;2.2,0.7;ban_guest;remove Guest]'; end else formspec = formspec.. 'label[4.7,2.5;-none-]'; - if( is_owner ) then + if( has_region_set ) then formspec = formspec.. - 'button_exit[8.0,2.5;2.2,0.5;add_guest;Add Guest]'.. - 'button_exit[8.0,3.0;2.2,0.5;ban_guest;remove Guest]'; + 'button_exit[8.0,2.5;2.2,0.7;add_guest;Add Guest]'.. + 'button_exit[8.0,3.2;2.2,0.7;ban_guest;remove Guest]'; end end - - -- does the area have subareas, i.e. is it a parent area for others? - local sub_areas = {}; - if( #sub_areas > 0 ) then - - formspec = formspec.. - 'label[0.5,4.0;Number of defined subareas:]'.. - 'label[4.7,4.0;'..tostring( #sub_areas )..']'.. - 'button_exit[8.0,4.0;2,0.5;list_subareas;List subareas]'; - -- else - -- formspec = formspec.. --- 'label[0.5,4.0;There are no subareas defined.]'; - end - - -- give information about the size of the area local length_x = (math.abs( this_area.pos2.x - this_area.pos1.x )+1); local length_y = (math.abs( this_area.pos2.y - this_area.pos1.y )+1); @@ -486,9 +478,7 @@ markers.get_area_desc_formspec = function( id, player, pos ) formspec = formspec.. markers.show_compass_marker( 2.0, 7.0, true, pos, this_area.pos1, this_area.pos2 ); --- TODO: buy / sell button - - local pname = player:get_player_name(); + --local pname = player:get_player_name(); if( not( markers.menu_data_by_player[ pname ] )) then markers.menu_data_by_player[ pname ] = {}; end @@ -529,98 +519,108 @@ markers.form_input_handler_areas = function( player, formname, fields) local menu_data = markers.menu_data_by_player[ pname ]; local formspec = ''; - -- rename an area - if( fields.rename - and menu_data.selected -- raz_store-ID is set - and raz.raz_store:get_area(menu_data.selected) -- there is an region for this ID - and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname + ----------------------------------------------------------------------- + -- rename an region + -- only region_admin or owner with region_mark can rename region + if( fields.rename -- rename + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID - local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + -- there are no checks here - those happen when the region will renamed + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + if( not( area.name )) then area.name = '-enter area name-'; end formspec = 'field[rename_new_name;Enter new name for area:;'..minetest.formspec_escape( area.name )..']'; - elseif( fields.rename_new_name - and menu_data.selected -- raz_store-ID is set - and raz.raz_store:get_area(menu_data.selected) -- there is an region for this ID - and ((raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) -- the owner of the ID/region is pname OR region_admin - or minetest.check_player_privs(pname, { region_admin = true }))) then - - local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + elseif( fields.rename_new_name -- rename_new_name + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID - -- actually rename the area - raz:region_set_attribute(pname, menu_data.selected, "region_name", fields.rename_new_name) - minetest.chat_send_player( pname, 'Region successfully renamed.'); - -- shwo the renamed area - formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); - + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table - + -- check owner with privileg or region admin + if markers:check_region_mark(pname, area.owner) then -- owner with privileg or admin + + -- actually rename the area + local err = raz:region_set_attribute(pname, menu_data.selected, "region_name", fields.rename_new_name) + if err then + minetest.chat_send_player( pname, 'Region successfully renamed.'); + + -- shwo the renamed area + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + else + raz:msg_handling(err, pname) + end + else + if area.owner ~= pname then + minetest.chat_send_player( pname, 'Permission denied. You are not owner of this region!'); + else + minetest.chat_send_player( pname, "Permission denied. Missing privileg \'region_mark\'!"); + end + end + + ----------------------------------------------------------------------- -- change owner the area - elseif( fields.change_owner - and menu_data.selected -- raz_store-ID is set - and raz.raz_store:get_area(menu_data.selected)) -- there is an region for this ID - then + -- only region_admin or owner with region_set can change owner + elseif( fields.change_owner -- change_owner + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected)) then -- there is an region for this ID -- there are no checks here - those happen when the area is transferred local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table formspec = 'field[change_owner_name;Give area \"'..minetest.formspec_escape( area.name )..'\" to player:;-enter name of NEW OWNER-]'; - elseif( fields.change_owner_name - and menu_data.selected -- raz_store-ID is set - and raz.raz_store:get_area(menu_data.selected)) -- there is an region for this - then + elseif( fields.change_owner_name -- change_owner_name + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected)) then -- there is an region for this - local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table - -- only own areas can be transfered to another player (or region_admin) - if( area.owner ~= pname - and not( minetest.check_player_privs(pname, { region_admin = true }))) then - - minetest.chat_send_player( pname, 'Permission denied. You do not own the region.'); - - -- did pname has the correct privileg? - elseif( not( minetest.check_player_privs(pname, { region_set = true }))) then - - minetest.chat_send_player( pname, 'Permission denied. You do not have the correct privileg.'); - - -- the new Player do not exist - elseif( not( minetest.player_exists( fields.change_owner_name ))) then + -- check new owner is player + if( not( minetest.player_exists( fields.change_owner_name ))) then minetest.chat_send_player( pname, 'That player does not exist.'); + -- check owner with privileg or region admin + elseif markers:check_region_set(pname, area.owner) then -- owner with privileg or admin + + -- actually change the owner + local err = raz:region_set_attribute(pname, menu_data.selected, "owner", fields.change_owner_name) + if err then + + minetest.chat_send_player( pname, 'Your region '..tostring( area.name )..' has been transfered to '..tostring( fields.change_owner_name )..'.'); + + minetest.chat_send_player( fields.change_owner_name, pname..' has given you control over an region.') + else + raz:msg_handling(err, pname) + end + + elseif area.owner ~= pname then + minetest.chat_send_player( pname, 'Permission denied. You are not owner of this region!'); else - -- actually change the owner - raz:region_set_attribute(pname, menu_data.selected, "owner", fields.change_owner_name) - - minetest.chat_send_player( pname, 'Your region '..tostring( area.name )..' has been transfered to '..tostring( fields.change_owner_name )..'.'); - - minetest.chat_send_player( fields.change_owner_name, pname..' has given you control over an region.') + minetest.chat_send_player( pname, "Permission denied. Missing privileg \'region_set\'!"); end formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + ----------------------------------------------------------------------- -- add a guest - check id / region with ID elseif( fields.add_guest and menu_data.selected -- raz_store-ID is set and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID --- and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname - - local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table - formspec = 'field[add_guest_name;Grant access to area \"'..minetest.formspec_escape( area.name )..'\" to player:;-enter player name-]'; + formspec = 'field[add_guest_name;Invite a player to your region: \"'..minetest.formspec_escape( area.name )..'\";-enter player name-]'; elseif( fields.add_guest_name - -- the player has to own the area already; we need a diffrent name here - -- and fields.add_guest_name ~= pname and menu_data.selected -- raz_store-ID is set and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID - -- and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table @@ -631,52 +631,52 @@ markers.form_input_handler_areas = function( player, formname, fields) -- show the formspec formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); - -- check privileg - elseif( not( minetest.check_player_privs(pname, { region_set = true }) -- privileg - and not (raz:get_region_attribute(menu_data.selected, "owner" ) == pname )) -- and owner - or not ( minetest.check_player_privs(pname, { region_admin = true })) ) then -- or admin - - minetest.chat_send_player( pname, 'Permission denied. You do not have the correct privileg.'); + -- check owner with privileg or region admin + elseif markers:check_region_set(pname, area.owner) then -- owner with privileg or admin - else - -- log the creation of the new area + -- log add guest minetest.log("action", pname.." add_guest through the markers-mod. guest = "..fields.add_guest_name.. " AreaName = "..area.name.." ParentID = "..menu_data.selected.. " StartPos = "..area.pos1.x..","..area.pos1.y..","..area.pos1.z.. " EndPos = " ..area.pos2.x..","..area.pos2.y..","..area.pos2.z) - -- actually addthe guest - raz:region_set_attribute(pname, menu_data.selected, "guest", fields.add_guest_name, true) + -- actually add the guest + if raz:region_set_attribute(pname, menu_data.selected, "guest", fields.add_guest_name, true) then - minetest.chat_send_player( fields.add_guest_name, - "You have been invitedinto the region #".. - menu_data.selected..". Type /region list to show your region.") + minetest.chat_send_player( fields.add_guest_name, + "You have been invitedinto the region #".. + menu_data.selected..". Type /region list to show your region.") - minetest.chat_send_player( pname, 'The player may now build and dig in your area.'); - -- shwo the new area - --markers.menu_data_by_player[ pname ].selected = new_id; - formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + minetest.chat_send_player( pname, 'The player may now build and dig in your area.'); + + -- shwo the new area + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + + else + minetest.chat_send_player( pname, "ther is a player with this name {".. fields.ban_guest_name.."} in your guestlist!"); + end + + elseif area.owner ~= pname then + minetest.chat_send_player( pname, 'Permission denied. You are not owner of this region!'); + else + minetest.chat_send_player( pname, "Permission denied. Missing privileg \'region_setz\'!"); end + + ----------------------------------------------------------------------- -- ban a guest elseif( fields.ban_guest and menu_data.selected -- raz_store-ID is set - and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID --- and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname - - + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table formspec = 'field[ban_guest_name;Grant access to area \"'..minetest.formspec_escape( area.name )..'\" to player:;-enter player name-]'; elseif( fields.ban_guest_name - -- the player has to own the area already; we need a diffrent name here - -- and fields.ban_guest_name ~= pname and menu_data.selected -- raz_store-ID is set and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID - -- and raz:get_region_attribute(menu_data.selected, "owner" ) == pname ) then -- the owner of the ID/region is pname local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table @@ -687,153 +687,124 @@ markers.form_input_handler_areas = function( player, formname, fields) -- show the formspec formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); - -- check privileg - elseif( not( minetest.check_player_privs(pname, { region_set = true }) -- privileg - and not (raz:get_region_attribute(menu_data.selected, "owner" ) == pname )) -- and owner - or not ( minetest.check_player_privs(pname, { region_admin = true })) ) then -- or admin - - minetest.chat_send_player( pname, 'Permission denied. You do not have the correct privileg.'); + -- check owner with privileg or region admin + elseif markers:check_region_set(pname, area.owner) then -- owner with privileg or admin - else - -- log the creation of the new area - minetest.log("action", pname.." add_guest through the markers-mod. guest = "..fields.ban_guest_name.. + -- log ban guest + minetest.log("action", pname.." ban_guest through the markers-mod. guest = "..fields.ban_guest_name.. " AreaName = "..area.name.." ParentID = "..menu_data.selected.. " StartPos = "..area.pos1.x..","..area.pos1.y..","..area.pos1.z.. " EndPos = " ..area.pos2.x..","..area.pos2.y..","..area.pos2.z) - -- actually addthe guest - raz:region_set_attribute(pname, menu_data.selected, "guest", fields.ban_guest_name, false) + -- actually add the guest + if raz:region_set_attribute(pname, menu_data.selected, "guest", fields.ban_guest_name, false) then - minetest.chat_send_player( fields.ban_guest_name, - "You have been invitedinto the region #".. - menu_data.selected..". Type /region list to show your region.") + minetest.chat_send_player( fields.ban_guest_name, + "You have been banned from the region #".. + menu_data.selected..". Type /region list to show your region.") - minetest.chat_send_player( pname, 'The player may now build and dig in your area.'); - -- shwo the new area - --markers.menu_data_by_player[ pname ].selected = new_id; - formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); - end + minetest.chat_send_player( pname, "You have banned player ".. fields.ban_guest_name.." from your region {"..area.name.."}"); ---[[ - - -- delete area - elseif( fields.delete - and menu_data.selected - and areas.areas[ menu_data.selected ] ) then - - local area = areas.areas[ menu_data.selected ]; - - -- a player can only delete own areas or subareas of own areas - if( area.owner ~= pname - and not( area.parent - and areas.areas[ area.parent ] - and areas.areas[ area.parent ].owner - and areas.areas[ area.parent ].owner == pname ) - and not( minetest.check_player_privs(pname, {areas=true}))) then - - minetest.chat_send_player( pname, 'Permission denied. You own neither the area itshelf nor its parent area.'); - -- shwo the area where the renaming failed - formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + -- shwo the new area + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + else + minetest.chat_send_player( pname, "No player {".. fields.ban_guest_name.."} in your guestlist of region {"..area.name.."}"); + end else - formspec = 'field[rename_new_name;Enter new name for area:;'..minetest.formspec_escape( area.name )..']'; - formspec = 'field[delete_confirm;'..minetest.formspec_escape( 'Really delete area \"'..area.name.. - '\" (owned by '..area.owner..')? Confirm with YES:')..';-type yes in capitals to confirm-]'; + minetest.chat_send_player( pname, 'Permission denied. You do not have the correct privileg.'); end + ----------------------------------------------------------------------- + -- delete area + elseif( fields.delete + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID + + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table + + -- a player can only delete own regions with privileg - region_mark or as admin + -- check owner with privileg or region admin + if markers:check_region_mark(pname, area.owner) then -- owner with privileg or admin + + -- get name of region + formspec = 'field[rename_new_name;Enter new name for area:;'..minetest.formspec_escape( area.name )..']'; + -- confirm + formspec = 'field[delete_confirm;'..minetest.formspec_escape( 'Really delete area \"'..area.name.. + '\" (owned by '..area.owner..')? Confirm with YES:')..';-type yes in capitals to confirm-]'; + + elseif raz:get_region_attribute(menu_data.selected, "owner" ) ~= pname then + minetest.chat_send_player( pname, 'Permission denied. You are not owner of this region!'); + else + minetest.chat_send_player( pname, "Permission denied. missing privileg \'region_mark\'!"); + + -- show the area where the renaming failed + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + end + elseif( fields.delete_confirm - and menu_data.selected - and areas.areas[ menu_data.selected ] ) then - - local area = areas.areas[ menu_data.selected ]; - local old_owner = area.owner; + and menu_data.selected -- raz_store-ID is set + and raz.raz_store:get_area(menu_data.selected) ) then -- there is an region for this ID - local subareas = {}; - for i,v in pairs( areas.areas ) do - if( v.parent and v.parent == menu_data.selected ) then - table.insert( subareas, i ); - end - end + -- there are no checks here - those happened before + local area = markers:convert_to_areas(menu_data.selected) -- get raz_store converted to an areas-table - -- a player can only delete own areas or subareas of own areas - if( area.owner ~= pname - and not( area.parent - and areas.areas[ area.parent ] - and areas.areas[ area.parent ].owner - and areas.areas[ area.parent ].owner == pname ) - and not( minetest.check_player_privs(pname, {areas=true}))) then + -- a player can only delete own areas + -- check owner with privileg or region admin + if markers:check_region_mark(pname, area.owner) then -- owner with privileg or admin - minetest.chat_send_player( pname, 'Permission denied. You own neither the area itshelf nor its parent area.'); - -- shwo the renamed area - formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); - - -- avoid accidents - elseif( fields.delete_confirm ~= 'YES' ) then - minetest.chat_send_player( pname, 'Delition of area \"'..tostring( area.name )..'\" (owned by '..old_owner..') aborted.'); - formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); - - -- only areas without subareas can be deleted - elseif( #subareas > 0 ) then - minetest.chat_send_player( pname, 'The area has '..tostring( #subareas )..' subarea(s). Please delete those first!'); - formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); - + -- avoid accidents + if( fields.delete_confirm ~= 'YES' ) then + minetest.chat_send_player( pname, 'Delition of area \"'..tostring( area.name )..'\" (owned by '..area.owner..') aborted.'); + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + else + + minetest.chat_send_player( pname, 'Area \"'..tostring( area.name )..'\" (owned by '..area.owner..') deleted.'); + -- really delete + raz:delete_region(menu_data.selected) + -- show the list of areas owned by the previous owner + formspec = markers.get_area_list_formspec(ppos, player, 'player', menu_data.pos, area.owner, nil ); + end else - minetest.chat_send_player( pname, 'Area \"'..tostring( area.name )..'\" (owned by '..old_owner..') deleted.'); - -- really delete - areas:remove( menu_data.selected, false ); -- no recursive delete - areas:save(); - -- show the list of areas owned by the previous owner - formspec = markers.get_area_list_formspec(ppos, player, 'player', menu_data.pos, old_owner, nil ); + minetest.chat_send_player( pname, 'Permission denied. You are not owner of this region!'); + -- shwo the area where the renaming failed + formspec = markers.get_area_desc_formspec( menu_data.selected, player, menu_data.pos ); + end - - - elseif( fields.show_parent - and menu_data.selected - and areas.areas[ menu_data.selected ] - and areas.areas[ menu_data.selected ].parent ) then - - formspec = markers.get_area_desc_formspec( areas.areas[ menu_data.selected ].parent, player, menu_data.pos ); - - - elseif( fields.list_player_areas - and menu_data.selected - and areas.areas[ menu_data.selected ] ) then - - formspec = markers.get_area_list_formspec(ppos, player, 'player', menu_data.pos, areas.areas[ menu_data.selected ].owner, nil ); - - - elseif( fields.list_subareas - and menu_data.selected - and areas.areas[ menu_data.selected ] ) then - - formspec = markers.get_area_list_formspec(ppos, player, 'subareas', menu_data.pos, menu_data.selected, nil ); - + ----------------------------------------------------------------------- + -- list_main_areas elseif( fields.list_main_areas ) then - formspec = markers.get_area_list_formspec(ppos, player, 'main_areas', menu_data.pos, nil, nil ); - + formspec = markers.get_area_list_formspec(ppos, player, 'main_areas', menu_data.pos, nil, nil ); + + + ----------------------------------------------------------------------- + -- list_areas_at elseif( fields.list_areas_at - and menu_data.pos ) then + and menu_data.pos ) then - formspec = markers.get_area_list_formspec(ppos, player, 'pos', menu_data.pos, menu_data.pos, nil ); +-- formspec = markers.get_area_list_formspec(ppos, player, 'pos', menu_data.pos, menu_data.pos, nil ); + formspec = markers.get_area_list_formspec(ppos, player, 'all', menu_data.pos, menu_data.pos, nil ); + ----------------------------------------------------------------------- + -- markers_area_list_selection elseif( fields.markers_area_list_selection - and menu_data.typ - and menu_data.typ == 'area_list' - and menu_data.list - and #menu_data.list > 0 ) then + and menu_data.typ + and menu_data.typ == 'area_list' + and menu_data.list + and #menu_data.list > 0 ) then local field_data = fields.markers_area_list_selection:split( ':' ); if( not( field_data ) or #field_data < 2 ) then - field_data = { '', '' }; + field_data = { '', '' }; end local selected = tonumber( field_data[ 2 ] ); @@ -843,10 +814,11 @@ markers.form_input_handler_areas = function( player, formname, fields) formspec = markers.get_area_desc_formspec( tonumber( menu_data.list[ selected ] ), player, menu_data.pos ); else - -- on single click, just show the position of that particular area - formspec = markers.get_area_list_formspec(ppos, player, menu_data.mode, menu_data.pos, menu_data.mode_data, selected ); + -- on single click, just show the position of that particular area + formspec = markers.get_area_list_formspec(ppos, player, menu_data.mode, menu_data.pos, menu_data.mode_data, selected ); end -]]-- + + else return false; end @@ -884,25 +856,20 @@ markers.show_marker_stone_formspec = function( player, pos ) local min_area_size = 100000000000; for id, area in pairs(raz.raz_store:get_areas_for_pos(pos)) do - --for id, area in pairs(areas.areas) do - -- if( pos.x >= area.pos1.x and pos.x <= area.pos2.x and - -- pos.y >= area.pos1.y and pos.y <= area.pos2.y and - -- pos.z >= area.pos1.z and pos.z <= area.pos2.z )then - -- ignore y (height) value because some areas may go from bottom to top - local area_size = math.abs( area.max.x - area.min.x ) - * math.abs( area.max.z - area.min.z ); + -- ignore y (height) value because some areas may go from bottom to top + local area_size = math.abs( area.max.x - area.min.x ) + * math.abs( area.max.z - area.min.z ); - -- collect subareas that have the same size - if( area_size == min_area_size ) then - table.insert(found_areas, id ); - -- we have found a smaller area - that is more intresting here - elseif( area_size <= min_area_size ) then - found_areas = {}; - min_area_size = area_size; - table.insert(found_areas, id ); - end - -- end + -- collect subareas that have the same size + if( area_size == min_area_size ) then + table.insert(found_areas, id ); + -- we have found a smaller area - that is more intresting here + elseif( area_size <= min_area_size ) then + found_areas = {}; + min_area_size = area_size; + table.insert(found_areas, id ); + end end @@ -910,9 +877,9 @@ markers.show_marker_stone_formspec = function( player, pos ) if( #found_areas < 1 ) then formspec = 'size[4,3]'.. - 'label[0.5,0.5;This position is not protected.]'.. - 'button[1.0,1.5;2,0.5;list_main_areas;List all main areas]'.. - 'button_exit[3.0,1.5;1,0.5;abort;OK]'; + 'label[0.5,0.5;This position is not protected.]'.. + 'button[1.0,1.5;2,0.5;list_main_areas;List all main areas]'.. + 'button_exit[3.0,1.5;1,0.5;abort;OK]'; -- found exactly one areaa - display it elseif( #found_areas == 1 ) then @@ -953,7 +920,7 @@ markers.show_marker_stone_formspec = function( player, pos ) if( own_area > 0 ) then formspec = markers.get_area_desc_formspec( own_area, player, pos ); - +--[[ -- if the player owns none of these areas, show the topmost (parentless) area elseif( parent_area > 0 ) then @@ -968,6 +935,7 @@ markers.show_marker_stone_formspec = function( player, pos ) -- our superficial analysis of the structure of the areas failed; it is up to the player to -- find out which of the candidates he is intrested in; we list them all +]]-- else formspec = markers.get_area_list_formspec(ppos, player, 'pos', pos, pos, nil ); From ff9b288db81a11efb50f148ca3e3c5e2c60f6a5a Mon Sep 17 00:00:00 2001 From: Ralf Weinert Date: Wed, 17 Apr 2019 22:11:56 +0200 Subject: [PATCH 3/6] some minor changes (readme.md) --- README.md | 5 +++++ raz.lua | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ffa3179..2cafeac 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ This is work in progress. + +April 2019 by downad +added support for raz (Regions, Areas and Zones for Minetest) +https://github.com/downad/raz + diff --git a/raz.lua b/raz.lua index a7c30ca..266059d 100644 --- a/raz.lua +++ b/raz.lua @@ -94,7 +94,11 @@ function markers:player_can_add_region(pos1, pos2, name) if not minetest.check_player_privs(name, { region_mark = true }) then return false, "You dont have the privileg 'region_mark' " end - if raz:get_area_by_pos1_pos2(pos1, pos2) ~= nil then + local err = raz:player_can_mark_region(pos1, pos2, name) + minetest.log("action", "[" .. markers.modname .. "] markers:player_can_add_region(pos1, pos2, name) err = "..tostring(err) ) + if err ~= true then +-- if raz:get_area_by_pos1_pos2(pos1, pos2) ~= nil then + raz:msg_handling(err, name) -- message and error handling return false, "The pos1,pos2 are in an other region! - You can not mark the region." end From c4bc9c7fc78a28f911b4ca4a9d49d489aeff0a74 Mon Sep 17 00:00:00 2001 From: Ralf Weinert Date: Wed, 17 Apr 2019 22:29:56 +0200 Subject: [PATCH 4/6] some minor changes (init.lua) --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 79a6458..d77f9b8 100644 --- a/init.lua +++ b/init.lua @@ -27,7 +27,7 @@ markers.mod_raz_present = minetest.get_modpath("raz") if markers.mod_areas_present and markers.mod_raz_present then minetest.log("error", "[" .. markers.modname .. "] areas and raz is installed - what shall be used!!!!!!") elseif markers.mod_areas_present and not markers.mod_raz_present then - dofile(modpath.."/areas.lua") + dofile(markers.modpath.."/areas.lua") minetest.log("action", "[" .. markers.modname .. "] areas is installed - load areas.lua") elseif markers.mod_raz_present and not markers.mod_areas_present then dofile(markers.modpath.."/raz.lua") From 94053015db5ac6886d7043684a7ad891d68d058b Mon Sep 17 00:00:00 2001 From: Ralf Weinert Date: Mon, 22 Apr 2019 17:30:08 +0200 Subject: [PATCH 5/6] makres work on raz: city & plot --- areas.lua | 100 ++++++++++++++++++++++++++++++++++++++ init.lua | 96 ------------------------------------- raz.lua | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 230 insertions(+), 106 deletions(-) diff --git a/areas.lua b/areas.lua index 30a2f1c..f306fc5 100644 --- a/areas.lua +++ b/areas.lua @@ -924,3 +924,103 @@ markers.show_marker_stone_formspec = function( player, pos ) minetest.show_formspec( player:get_player_name(), "markers:info", formspec ); end + + + +markers.get_marker_formspec = function(player, pos, error_msg) + local formspec = ""; + + local meta = minetest.get_meta( pos ); + local owner = meta:get_string( 'owner' ); + + local name = player:get_player_name(); + + local formspec_info = "size[6,4]".. + "button_exit[2,2.5;1,0.5;abort;OK]".. + "textarea[1,1;4,2;info;Information;"; + if( owner ~= nil and owner ~= '' and owner ~= name ) then + return formspec_info.."This marker\ncan only be used by\n"..tostring( owner )..", who\nplaced the markers.]"; + end + + if( not( markers.positions[ name ]) or #markers.positions[name]<1) then + return formspec_info.."Information about the positions\nof your other markers\ngot lost.\nPlease dig and place\nyour markers again!]"; + end + + local n = #markers.positions[ name ]; + + if ( n < 2 ) then + return formspec_info.."Please place 2 or more markers\n - at least one in each corner\n of your area first]"; + end + + + local coords={} + coords[1],coords[2] = markers.get_box_from_markers(name) + + -- save data + meta:set_string( 'coords', minetest.serialize( coords ) ); + + if( not( coords ) or #coords < 2 or not( coords[1] ) or not( coords[2] )) then + return formspec_info.."Error in markers.]"; + end + + -- the coordinates are set; we may present an input form now + + -- has the area already been defined? + local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); + + local size = (math.abs( coords[1].x - coords[2].x )+1) + * (math.abs( coords[1].z - coords[2].z )+1); + + -- check if area is too large + if( markers.MAX_SIZE < size ) then + return formspec_info.."Error: You can only protect\nareas of up to "..tostring( markers.MAX_SIZE ).."m^2.\n".. + "Your marked area is "..tostring( size ).." m^2 large.]"; + end + + local formspec = 'size[10,7]'.. + 'label[0.5,1;The area you marked extends from]'.. + 'label[4.7,1;'..minetest.pos_to_string( coords[ 1 ] )..' to '..minetest.pos_to_string( coords[ 2 ] )..'.]'.. + 'label[4.7,1.5;It spans '..tostring( math.abs( coords[1].x - coords[2].x )+1 ).. + ' x '..tostring( math.abs( coords[1].z - coords[2].z )+1 ).. + ' = '..tostring( size )..' m^2.]'; + + -- display the error message (if there is any) + if( error_msg ~= nil ) then + formspec = formspec.. + 'label[0.5,0.0;Error: ]'.. + 'textarea[5.0,0;4,1.5;info;;'..error_msg..']'; + end + + if( area and area['id'] ) then + formspec = formspec.. + 'label[0.5,2.0;This is area number ]'.. + 'label[4.7,2.0;'..tostring( area['id'] )..'.]'.. + 'label[0.5,2.5;It is owned by ]'.. + 'label[4.7,2.5;'..tostring( area['owner'] )..'.]'.. + 'label[0.5,3.0;The area is called ]'.. + 'label[4.7,3.0;'..tostring( area['name'] )..'.]'.. + "button_exit[2,6.0;2,0.5;abort;OK]"; + else + formspec = formspec.. +-- 'label[0.5,2.0;Buying this area will cost you ]'.. +-- 'label[4.7,2.0;'..markers.calculate_area_price_text( coords[1], coords[2], name )..'.]'.. + + 'label[0.5,3.0;Your area ought to go..]'.. + 'label[0.5,3.5;this many blocks up:]'.. + 'field[5.0,4.0;1,0.5;add_height;;40]'.. + 'label[6.0,3.5;(above '..coords[2].y..' )]'.. + + 'label[0.5,4.0;and this many blocks down:]'.. + 'field[5.0,4.5;1,0.5;add_depth;;10]'.. + 'label[6.0,4.0;(below '..coords[1].y..' )]'.. + + 'label[0.5,4.5;The area shall be named]'.. + 'field[5.0,5.0;6,0.5;set_area_name;;please enter a name]'.. + + "button_exit[2,6.0;2,0.5;abort;Abort]".. + -- code the position in the "Buy area" field + "button_exit[6,6.0;2,0.5;"..minetest.pos_to_string(pos)..";Protect area]"; + end + + return formspec; +end diff --git a/init.lua b/init.lua index d77f9b8..886bed3 100644 --- a/init.lua +++ b/init.lua @@ -242,103 +242,7 @@ end --get_box_from_markers -markers.get_marker_formspec = function(player, pos, error_msg) - local formspec = ""; - local meta = minetest.get_meta( pos ); - local owner = meta:get_string( 'owner' ); - - local name = player:get_player_name(); - - local formspec_info = "size[6,4]".. - "button_exit[2,2.5;1,0.5;abort;OK]".. - "textarea[1,1;4,2;info;Information;"; - if( owner ~= nil and owner ~= '' and owner ~= name ) then - return formspec_info.."This marker\ncan only be used by\n"..tostring( owner )..", who\nplaced the markers.]"; - end - - if( not( markers.positions[ name ]) or #markers.positions[name]<1) then - return formspec_info.."Information about the positions\nof your other markers\ngot lost.\nPlease dig and place\nyour markers again!]"; - end - - local n = #markers.positions[ name ]; - - if ( n < 2 ) then - return formspec_info.."Please place 2 or more markers\n - at least one in each corner\n of your area first]"; - end - - - local coords={} - coords[1],coords[2] = markers.get_box_from_markers(name) - - -- save data - meta:set_string( 'coords', minetest.serialize( coords ) ); - - if( not( coords ) or #coords < 2 or not( coords[1] ) or not( coords[2] )) then - return formspec_info.."Error in markers.]"; - end - - -- the coordinates are set; we may present an input form now - - -- has the area already been defined? - local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); - - local size = (math.abs( coords[1].x - coords[2].x )+1) - * (math.abs( coords[1].z - coords[2].z )+1); - - -- check if area is too large - if( markers.MAX_SIZE < size ) then - return formspec_info.."Error: You can only protect\nareas of up to "..tostring( markers.MAX_SIZE ).."m^2.\n".. - "Your marked area is "..tostring( size ).." m^2 large.]"; - end - - local formspec = 'size[10,7]'.. - 'label[0.5,1;The area you marked extends from]'.. - 'label[4.7,1;'..minetest.pos_to_string( coords[ 1 ] )..' to '..minetest.pos_to_string( coords[ 2 ] )..'.]'.. - 'label[4.7,1.5;It spans '..tostring( math.abs( coords[1].x - coords[2].x )+1 ).. - ' x '..tostring( math.abs( coords[1].z - coords[2].z )+1 ).. - ' = '..tostring( size )..' m^2.]'; - - -- display the error message (if there is any) - if( error_msg ~= nil ) then - formspec = formspec.. - 'label[0.5,0.0;Error: ]'.. - 'textarea[5.0,0;4,1.5;info;;'..error_msg..']'; - end - - if( area and area['id'] ) then - formspec = formspec.. - 'label[0.5,2.0;This is area number ]'.. - 'label[4.7,2.0;'..tostring( area['id'] )..'.]'.. - 'label[0.5,2.5;It is owned by ]'.. - 'label[4.7,2.5;'..tostring( area['owner'] )..'.]'.. - 'label[0.5,3.0;The area is called ]'.. - 'label[4.7,3.0;'..tostring( area['name'] )..'.]'.. - "button_exit[2,6.0;2,0.5;abort;OK]"; - else - formspec = formspec.. --- 'label[0.5,2.0;Buying this area will cost you ]'.. --- 'label[4.7,2.0;'..markers.calculate_area_price_text( coords[1], coords[2], name )..'.]'.. - - 'label[0.5,3.0;Your area ought to go..]'.. - 'label[0.5,3.5;this many blocks up:]'.. - 'field[5.0,4.0;1,0.5;add_height;;40]'.. - 'label[6.0,3.5;(above '..coords[2].y..' )]'.. - - 'label[0.5,4.0;and this many blocks down:]'.. - 'field[5.0,4.5;1,0.5;add_depth;;10]'.. - 'label[6.0,4.0;(below '..coords[1].y..' )]'.. - - 'label[0.5,4.5;The area shall be named]'.. - 'field[5.0,5.0;6,0.5;set_area_name;;please enter a name]'.. - - "button_exit[2,6.0;2,0.5;abort;Abort]".. - -- code the position in the "Buy area" field - "button_exit[6,6.0;2,0.5;"..minetest.pos_to_string(pos)..";Protect area]"; - end - - return formspec; -end diff --git a/raz.lua b/raz.lua index 266059d..af34a1b 100644 --- a/raz.lua +++ b/raz.lua @@ -1,3 +1,17 @@ + +-- this is here becaue of the teleport mod +areas = {} + +function areas:canInteract(target_coords, player) + return raz:can_interact(pos, name) +end + +function areas:getNodeOwners(target_coords) + local can_interact, owner = raz:can_interact(pos, name) + return owner +end + + --+++++++++++++++++++++++++++++++++++++++ -- -- convert_to_areas @@ -95,9 +109,8 @@ function markers:player_can_add_region(pos1, pos2, name) return false, "You dont have the privileg 'region_mark' " end local err = raz:player_can_mark_region(pos1, pos2, name) - minetest.log("action", "[" .. markers.modname .. "] markers:player_can_add_region(pos1, pos2, name) err = "..tostring(err) ) + --minetest.log("action", "[" .. markers.modname .. "] markers:player_can_add_region(pos1, pos2, name) err = "..tostring(err) ) if err ~= true then --- if raz:get_area_by_pos1_pos2(pos1, pos2) ~= nil then raz:msg_handling(err, name) -- message and error handling return false, "The pos1,pos2 are in an other region! - You can not mark the region." end @@ -129,7 +142,9 @@ markers.marker_on_receive_fields = function(pos, formname, fields, sender) -- do not protect areas twice local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); - if( area ) then + -- check if this region has marked as building plot, then it can be set + + if raz:region_is_plot( coords[1], coords[2] ) == false then minetest.log("action", "[" .. markers.modname .. "] markers.marker_on_receive_fields area = :"..tostring(area) ) minetest.chat_send_player( name, 'This area is already protected.'); return; @@ -190,6 +205,7 @@ markers.marker_on_receive_fields = function(pos, formname, fields, sender) " endpos=" ..minetest.pos_to_string(pos2)); local canAdd, errMsg = markers:player_can_add_region(pos1, pos2, name) + check_region_plot = raz:region_is_plot( coords[1], coords[2] ) if canAdd == false then minetest.chat_send_player(name, "You can't protect that area: "..tostring(errMsg)) minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, errMsg)); @@ -199,7 +215,7 @@ markers.marker_on_receive_fields = function(pos, formname, fields, sender) local data = raz:create_data(name,fields['set_area_name'],true) local id = raz:set_region(pos1,pos2,data) minetest.chat_send_player(name, "Area protected. ID: "..tostring(id)) - + minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, nil)); end @@ -214,11 +230,6 @@ if not vector.interpolate then end end --- taken from mobf ---local COLOR_RED = "#FF0000"; ---local COLOR_GREEN = "#00FF00"; ---local COLOR_WHITE = "#FFFFFF"; - -- we need to store which list we present to which player markers.menu_data_by_player = {} @@ -392,7 +403,7 @@ end -- shows a formspec with information about a particular area -- pos is the position of the marker stone or place where the player clicked --- with the land title register; it is used for relative display of coordinates +-- with the land title register; can used for relative display of coordinates markers.get_area_desc_formspec = function( id, player, pos ) if( not id or not raz.raz_store:get_area( id )) then @@ -948,3 +959,112 @@ markers.show_marker_stone_formspec = function( player, pos ) minetest.show_formspec( player:get_player_name(), "markers:info", formspec ); end + + +markers.get_marker_formspec = function(player, pos, error_msg) + local formspec = ""; + + local meta = minetest.get_meta( pos ); + local owner = meta:get_string( 'owner' ); + + local name = player:get_player_name(); + + local formspec_info = "size[6,4]".. + "button_exit[2,2.5;1,0.5;abort;OK]".. + "textarea[1,1;4,2;info;Information;"; + if( owner ~= nil and owner ~= '' and owner ~= name ) then + return formspec_info.."This marker\ncan only be used by\n"..tostring( owner )..", who\nplaced the markers.]"; + end + + if( not( markers.positions[ name ]) or #markers.positions[name]<1) then + return formspec_info.."Information about the positions\nof your other markers\ngot lost.\nPlease dig and place\nyour markers again!]"; + end + + local n = #markers.positions[ name ]; + + if ( n < 2 ) then + return formspec_info.."Please place 2 or more markers\n - at least one in each corner\n of your area first]"; + end + + + local coords={} + coords[1],coords[2] = markers.get_box_from_markers(name) + + -- save data + meta:set_string( 'coords', minetest.serialize( coords ) ); + + if( not( coords ) or #coords < 2 or not( coords[1] ) or not( coords[2] )) then + return formspec_info.."Error in markers.]"; + end + + -- the coordinates are set; we may present an input form now + + -- has the area already been defined? + local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); + + local size = (math.abs( coords[1].x - coords[2].x )+1) + * (math.abs( coords[1].z - coords[2].z )+1); + + -- check if area is too large + if( markers.MAX_SIZE < size ) then + return formspec_info.."Error: You can only protect\nareas of up to "..tostring( markers.MAX_SIZE ).."m^2.\n".. + "Your marked area is "..tostring( size ).." m^2 large.]"; + end + + local formspec = 'size[10,7]'.. + 'label[0.5,1;The area you marked extends from]'.. + 'label[4.7,1;'..minetest.pos_to_string( coords[ 1 ] )..' to '..minetest.pos_to_string( coords[ 2 ] )..'.]'.. + 'label[4.7,1.5;It spans '..tostring( math.abs( coords[1].x - coords[2].x )+1 ).. + ' x '..tostring( math.abs( coords[1].z - coords[2].z )+1 ).. + ' = '..tostring( size )..' m^2.]'; + + -- display the error message (if there is any) + if( error_msg ~= nil ) then + formspec = formspec.. + 'label[0.5,0.0;Error: ]'.. + 'textarea[5.0,0;4,1.5;info;;'..error_msg..']'; + end + + + -- if this area exists + -- case 1 the region has the attribut "plot" == true then setting a new area is possible + -- case 2 the region has the attribut "plot" == false + local can_set_region = false + if( area and area['id'] ) then + if not raz:region_is_plot( coords[1], coords[2] ) == false then + can_set_region = true + end + end + if can_set_region == false then + formspec = formspec.. + 'label[0.5,2.0;This is area number ]'.. + 'label[4.7,2.0;'..tostring( area['id'] )..'.]'.. + 'label[0.5,2.5;It is owned by ]'.. + 'label[4.7,2.5;'..tostring( area['owner'] )..'.]'.. + 'label[0.5,3.0;The area is called ]'.. + 'label[4.7,3.0;'..tostring( area['name'] )..'.]'.. + "button_exit[2,6.0;2,0.5;abort;OK]"; + else + formspec = formspec.. +-- 'label[0.5,2.0;Buying this area will cost you ]'.. +-- 'label[4.7,2.0;'..markers.calculate_area_price_text( coords[1], coords[2], name )..'.]'.. + + 'label[0.5,3.0;Your area ought to go..]'.. + 'label[0.5,3.5;this many blocks up:]'.. + 'field[5.0,4.0;1,0.5;add_height;;40]'.. + 'label[6.0,3.5;(above '..coords[2].y..' )]'.. + + 'label[0.5,4.0;and this many blocks down:]'.. + 'field[5.0,4.5;1,0.5;add_depth;;10]'.. + 'label[6.0,4.0;(below '..coords[1].y..' )]'.. + + 'label[0.5,4.5;The area shall be named]'.. + 'field[5.0,5.0;6,0.5;set_area_name;;please enter a name]'.. + + "button_exit[2,6.0;2,0.5;abort;Abort]".. + -- code the position in the "Buy area" field + "button_exit[6,6.0;2,0.5;"..minetest.pos_to_string(pos)..";Protect area]"; + end + + return formspec; +end From 0012eb67616e1a7c224e43574e4090cda9009521 Mon Sep 17 00:00:00 2001 From: Ralf Weinert Date: Sat, 4 May 2019 11:35:29 +0200 Subject: [PATCH 6/6] some bugs --- raz.lua | 58 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/raz.lua b/raz.lua index af34a1b..f6e36b1 100644 --- a/raz.lua +++ b/raz.lua @@ -2,13 +2,24 @@ -- this is here becaue of the teleport mod areas = {} -function areas:canInteract(target_coords, player) - return raz:can_interact(pos, name) +function areas:canInteract(pos, name) + local can_interact = raz:can_interact(pos, name) + --minetest.log("action", "[" .. raz.modname .. "] areas:canInteract(pos, name) pos "..minetest.serialize(pos) ) + --minetest.log("action", "[" .. raz.modname .. "] areas:canInteract(pos, name) name "..tostring(name) ) + --minetest.log("action", "[" .. raz.modname .. "] areas:canInteract(pos, name) can_interact "..tostring(can_interact) ) + + return can_interact end -function areas:getNodeOwners(target_coords) - local can_interact, owner = raz:can_interact(pos, name) - return owner +function areas:getNodeOwners(pos) + + local owner = raz:get_owner_for_pos(pos) + -- owners must be a table + if owner ~= nil then + local owners = raz:convert_string_to_table(owner, ",") + return owners + end + return {} end @@ -261,11 +272,14 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se -- title would be too long for a label title = 'All areas which contain position..'; tlabel = '<'..minetest.pos_to_string( mode_data )..'>:'; - id_list = raz.raz_store:get_areas_for_pos(pos) - - + local temp_id_list = ( raz.raz_store:get_areas_for_pos(pos) ) + for k,v in next,temp_id_list,nil do + --minetest.log("error", "[" .. markers.modname .. "] {markers.get_area_list_formspec} mode= pos: k,v = "..tostring(k).." ,"..tostring(v) ) + table.insert( id_list, k ); + end -- expects a playername in mode_data elseif( mode=='player' ) then + --minetest.log("error", "[" .. markers.modname .. "] {markers.get_area_list_formspec} playername in mode_data = "..tostring(mode_data) ) title = 'All areas owned by player..'; tlabel = '<'..tostring( mode_data )..'>:'; @@ -287,16 +301,16 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se minetest.log("error", "[" .. markers.modname .. "] {markers.get_area_list_formspec} there are no subareas in raz-mod.") - -- show only regions that do have parent attribute = true + -- show only regions that do have plot attribute = true elseif( mode=='main_areas' ) then - title = 'All parent region withhin '..tostring( markers.AREA_RANGE )..' m:'; - tlabel = '*all parent regions *'; + title = 'All building plots withhin '..tostring( markers.AREA_RANGE )..' m:'; + tlabel = '*all plots regions *'; local counter = 0 local data = {} while raz.raz_store:get_area(counter) do data = raz:get_region_datatable(counter) - if( data.parent == true ) then + if( data.plot == true ) then table.insert( id_list, counter ); end counter = counter + 1 @@ -321,6 +335,7 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se vector.distance(vector.interpolate(raz.raz_store:get_area(b).min, raz.raz_store:get_area(b).max, 0.5), ppos) end table.sort(id_list, nearsorter) + --minetest.log("error", "[" .. markers.modname .. "] {markers.get_area_list_formspec} sort id_list: id_list = "..minetest.serialize(id_list) ) local formspec = 'size[10,9]'; @@ -380,7 +395,7 @@ markers.get_area_list_formspec = function(ppos, player, mode, pos, mode_data, se end formspec = formspec.. - 'button[8.0,8.5;2,0.5;list_main_areas;List all main areas]'; + 'button[8.0,8.5;2,0.5;list_main_areas;Own regions]'; -- we need to remember especially the id_list - else it would be impossible to know what the -- player selected @@ -796,7 +811,8 @@ markers.form_input_handler_areas = function( player, formname, fields) -- list_main_areas elseif( fields.list_main_areas ) then - formspec = markers.get_area_list_formspec(ppos, player, 'main_areas', menu_data.pos, nil, nil ); + --formspec = markers.get_area_list_formspec(ppos, player, 'main_areas', menu_data.pos, nil, nil ); + formspec = markers.get_area_list_formspec(ppos, player, 'player', menu_data.pos, player:get_player_name(), nil ); ----------------------------------------------------------------------- @@ -893,7 +909,7 @@ markers.show_marker_stone_formspec = function( player, pos ) formspec = 'size[4,3]'.. 'label[0.5,0.5;This position is not protected.]'.. - 'button[1.0,1.5;2,0.5;list_main_areas;List all main areas]'.. + 'button[1.0,1.5;2,0.5;list_main_areas;Own regions]'.. 'button_exit[3.0,1.5;1,0.5;abort;OK]'; -- found exactly one areaa - display it @@ -1000,7 +1016,8 @@ markers.get_marker_formspec = function(player, pos, error_msg) -- the coordinates are set; we may present an input form now -- has the area already been defined? - local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ); + local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] ) + local size = (math.abs( coords[1].x - coords[2].x )+1) * (math.abs( coords[1].z - coords[2].z )+1); @@ -1035,6 +1052,15 @@ markers.get_marker_formspec = function(player, pos, error_msg) can_set_region = true end end + + minetest.log("action", "[" .. raz.modname .. "] markers.get_marker_formspec - can_set_region = "..tostring(can_set_region) ) + minetest.log("action", "[" .. raz.modname .. "] markers.get_marker_formspec - area = "..tostring(area) ) + minetest.log("action", "[" .. raz.modname .. "] markers.get_marker_formspec - coords[1] = "..minetest.serialize(coords[1]) ) + minetest.log("action", "[" .. raz.modname .. "] markers.get_marker_formspec - coords[2] = "..minetest.serialize(coords[1]) ) + -- if there is no region then it can be placed + if area == nil then + can_set_region = true + end if can_set_region == false then formspec = formspec.. 'label[0.5,2.0;This is area number ]'..