Wireless: avoid inserting numerous times same wireless in wireless table

This commit is contained in:
upsilon 2017-04-27 17:42:59 +02:00
parent b403e6e9ab
commit 5422017493
No known key found for this signature in database
GPG Key ID: A80DAE1F266E1C3C
1 changed files with 11 additions and 5 deletions

View File

@ -23,13 +23,14 @@ local function remove_wireless(pos)
if not owner or owner == "" then
return
end
remove(wireless_meta.owners, pos.z,pos.y,pos.x)
if not wireless[owner] or not next(wireless[owner]) then
wireless[owner] = nil
return
end
local channel = get(wireless_meta.channels, pos.z,pos.y,pos.x)
if not channel or channel == "" or not wireless[owner][channel] then
if not channel or channel == "" then
return
end
@ -41,7 +42,6 @@ local function remove_wireless(pos)
end
end
remove(wireless_meta.owners, pos.z,pos.y,pos.x)
remove(wireless_meta.channels, pos.z,pos.y,pos.x)
remove(wireless_meta.ids, pos.z,pos.y,pos.x)
end
@ -94,9 +94,15 @@ function set_channel(pos, channel)
if not wireless[owner][channel] then
wireless[owner][channel] = {}
end
table.insert(wireless[owner][channel], pos)
meta:set_int("id", #wireless[owner][channel])
set(wireless_meta.ids, pos.z,pos.y,pos.x, #wireless[owner][channel])
local id = get(wireless_meta.ids, pos.z,pos.y,pos.x)
if id then
wireless[owner][channel][id] = pos
else
table.insert(wireless[owner][channel], pos)
meta:set_int("id", #wireless[owner][channel])
set(wireless_meta.ids, pos.z,pos.y,pos.x, #wireless[owner][channel])
end
meta:set_string("infotext", "Wireless owned by " .. owner .. " on channel " .. channel)
end