Allow: players, claims, and ips to store more data
This commit is contained in:
parent
e63b07cb99
commit
db914eec5a
@ -10,7 +10,7 @@ function factions.can_claim_parcel(name, parcelpos)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
if fn then
|
||||
local fac = factions.factions.get(fn)
|
||||
local fac = factions.factions.get(fn.faction)
|
||||
|
||||
if fac.power < 0. and faction.power >= factions_config.power_per_parcel and not faction.allies[fn] and not faction.neutral[fn] then
|
||||
return true
|
||||
@ -27,12 +27,16 @@ end
|
||||
--! @brief claim a parcel, update power and update global parcels table
|
||||
function factions.claim_parcel(name, parcelpos)
|
||||
-- check if claiming over other faction's territory
|
||||
local otherfac = factions.parcels.get(parcelpos)
|
||||
if otherfac then
|
||||
factions.unclaim_parcel(otherfac, parcelpos)
|
||||
factions.parcelless_check(otherfac)
|
||||
end
|
||||
factions.parcels.set(parcelpos, name)
|
||||
local otherfac = factions.parcels.get(parcelpos)
|
||||
|
||||
if otherfac then
|
||||
local otherfac_name = otherfac.faction
|
||||
factions.unclaim_parcel(otherfac_name, parcelpos)
|
||||
factions.parcelless_check(otherfac_name)
|
||||
end
|
||||
local data = factions.create_claim_table()
|
||||
data.faction = name
|
||||
factions.parcels.set(parcelpos, data)
|
||||
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
@ -85,8 +89,9 @@ function factions.parcelless_check(name)
|
||||
end
|
||||
|
||||
function factions.get_parcel_faction(parcelpos)
|
||||
local facname = factions.parcels.get(parcelpos)
|
||||
if facname then
|
||||
local data = factions.parcels.get(parcelpos)
|
||||
if data then
|
||||
local facname = data.faction
|
||||
local faction = factions.factions.get(facname)
|
||||
return faction, facname
|
||||
end
|
||||
|
100
databases.lua
100
databases.lua
@ -11,3 +11,103 @@ factions.player_ips = factions.root.sub_database("ips")
|
||||
|
||||
-- Memory only storage.
|
||||
factions.onlineplayers = {}
|
||||
|
||||
-- Table hook functions.
|
||||
|
||||
-- Hook function to add or delete from the faction table.
|
||||
function factions.on_create_faction_table(table)
|
||||
return table
|
||||
end
|
||||
|
||||
-- Hook function to add or delete from the ip table.
|
||||
function factions.on_create_ip_table(table)
|
||||
return table
|
||||
end
|
||||
|
||||
-- Hook function to add or delete from the player table.
|
||||
function factions.on_create_player_table(table)
|
||||
return table
|
||||
end
|
||||
|
||||
-- Hook function to add or delete from the claim table.
|
||||
function factions.on_create_claim_table(table)
|
||||
return table
|
||||
end
|
||||
|
||||
-- Table creation.
|
||||
|
||||
-- Create a empty faction.
|
||||
function factions.create_faction_table()
|
||||
local table = {
|
||||
name = "",
|
||||
--! @brief power of a faction (needed for parcel claiming)
|
||||
power = factions_config.power,
|
||||
--! @brief maximum power of a faction
|
||||
maxpower = factions_config.maxpower,
|
||||
--! @brief power currently in use
|
||||
usedpower = 0.,
|
||||
--! @brief list of player names
|
||||
players = {},
|
||||
--! @brief table of ranks/permissions
|
||||
ranks = starting_ranks,
|
||||
--! @brief name of the leader
|
||||
leader = nil,
|
||||
--! @brief spawn of the faction
|
||||
spawn = {x = 0, y = 0, z = 0},
|
||||
--! @brief default joining rank for new members
|
||||
default_rank = "member",
|
||||
--! @brief default rank assigned to the leader
|
||||
default_leader_rank = "leader",
|
||||
--! @brief faction's description string
|
||||
description = "Default faction description.",
|
||||
--! @brief faction's message of the day.
|
||||
message_of_the_day = "",
|
||||
--! @brief list of players currently invited (can join with /f join)
|
||||
invited_players = {},
|
||||
--! @brief table of claimed parcels (keys are parcelpos strings)
|
||||
land = {},
|
||||
--! @brief table of allies
|
||||
allies = {},
|
||||
--
|
||||
request_inbox = {},
|
||||
--! @brief table of enemies
|
||||
enemies = {},
|
||||
--!
|
||||
neutral = {},
|
||||
--! @brief table of parcels/factions that are under attack
|
||||
attacked_parcels = {},
|
||||
--! @brief whether faction is closed or open (boolean)
|
||||
join_free = false,
|
||||
--! @brief gives certain privileges
|
||||
is_admin = false,
|
||||
--! @brief last time anyone logged on
|
||||
last_logon = os.time(),
|
||||
--! @brief how long this has been without parcels
|
||||
no_parcel = os.time(),
|
||||
}
|
||||
return factions.on_create_faction_table(table)
|
||||
end
|
||||
|
||||
-- Create a empty ip table.
|
||||
function factions.create_ip_table()
|
||||
local table = {
|
||||
ip = ""
|
||||
}
|
||||
return factions.on_create_ip_table(table)
|
||||
end
|
||||
|
||||
-- Create a empty player table.
|
||||
function factions.create_player_table()
|
||||
local table = {
|
||||
faction = ""
|
||||
}
|
||||
return factions.on_create_player_table(table)
|
||||
end
|
||||
|
||||
-- Create a empty claim table.
|
||||
function factions.create_claim_table()
|
||||
local table = {
|
||||
faction = ""
|
||||
}
|
||||
return factions.on_create_claim_table(table)
|
||||
end
|
||||
|
61
factions.lua
61
factions.lua
@ -70,60 +70,9 @@ if factions_config.faction_diplomacy == true then
|
||||
starting_ranks["leader"] = lt
|
||||
end
|
||||
|
||||
function factions.new()
|
||||
return {
|
||||
name = "",
|
||||
--! @brief power of a faction (needed for parcel claiming)
|
||||
power = factions_config.power,
|
||||
--! @brief maximum power of a faction
|
||||
maxpower = factions_config.maxpower,
|
||||
--! @brief power currently in use
|
||||
usedpower = 0.,
|
||||
--! @brief list of player names
|
||||
players = {},
|
||||
--! @brief table of ranks/permissions
|
||||
ranks = starting_ranks,
|
||||
--! @brief name of the leader
|
||||
leader = nil,
|
||||
--! @brief spawn of the faction
|
||||
spawn = {x=0, y=0, z=0},
|
||||
--! @brief default joining rank for new members
|
||||
default_rank = "member",
|
||||
--! @brief default rank assigned to the leader
|
||||
default_leader_rank = "leader",
|
||||
--! @brief faction's description string
|
||||
description = "Default faction description.",
|
||||
--! @brief faction's message of the day.
|
||||
message_of_the_day = "",
|
||||
--! @brief list of players currently invited (can join with /f join)
|
||||
invited_players = {},
|
||||
--! @brief table of claimed parcels (keys are parcelpos strings)
|
||||
land = {},
|
||||
--! @brief table of allies
|
||||
allies = {},
|
||||
--
|
||||
request_inbox = {},
|
||||
--! @brief table of enemies
|
||||
enemies = {},
|
||||
--!
|
||||
neutral = {},
|
||||
--! @brief table of parcels/factions that are under attack
|
||||
attacked_parcels = {},
|
||||
--! @brief whether faction is closed or open (boolean)
|
||||
join_free = false,
|
||||
--! @brief gives certain privileges
|
||||
is_admin = false,
|
||||
--! @brief last time anyone logged on
|
||||
last_logon = os.time(),
|
||||
--! @brief how long this has been without parcels
|
||||
no_parcel = os.time(),
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
--! @brief create a new empty faction
|
||||
function factions.new_faction(name)
|
||||
local faction = factions.new()
|
||||
local faction = factions.create_faction_table()
|
||||
|
||||
faction.name = name
|
||||
factions.factions.set(name, faction)
|
||||
@ -172,11 +121,13 @@ function factions.set_name(oldname, name)
|
||||
end
|
||||
|
||||
for parcel in pairs(faction.land) do
|
||||
factions.parcels.set(parcel, name)
|
||||
local data = factions.create_claim_table()
|
||||
data.faction = name
|
||||
factions.parcels.set(parcel, data)
|
||||
end
|
||||
|
||||
for playername in pairs(faction.players) do
|
||||
local data = factions.players.get(playername) or {}
|
||||
local data = factions.players.get(playername) or factions.create_player_table()
|
||||
data.faction = name
|
||||
factions.players.set(playername, data)
|
||||
end
|
||||
@ -231,7 +182,7 @@ function factions.add_player(name, player, rank)
|
||||
|
||||
faction.players[player] = rank or faction.default_rank
|
||||
|
||||
local data = factions.players.get(player) or {}
|
||||
local data = factions.players.get(player) or factions.create_player_table()
|
||||
data.faction = name
|
||||
factions.players.set(player, data)
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
local on_death = {}
|
||||
|
||||
minetest.register_on_prejoinplayer(function(name, ip)
|
||||
factions.player_ips.set(name, ip)
|
||||
local data = factions.create_ip_table()
|
||||
data.ip = ip
|
||||
factions.player_ips.set(name, data)
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
@ -49,18 +51,19 @@ minetest.register_on_leaveplayer(function(player)
|
||||
end
|
||||
|
||||
if faction then
|
||||
faction.last_logon = os.time()
|
||||
factions.factions.set(facname, faction)
|
||||
factions.onlineplayers[facname][name] = nil
|
||||
local id_name2 = name .. "factionName"
|
||||
local id_name3 = name .. "powerWatch"
|
||||
|
||||
if hud_ids[id_name2] then
|
||||
hud_ids[id_name2] = nil
|
||||
end
|
||||
if hud_ids[id_name3] then
|
||||
hud_ids[id_name3] = nil
|
||||
end
|
||||
for k, v in pairs(factions.onlineplayers[facname]) do
|
||||
return
|
||||
end
|
||||
|
||||
factions.onlineplayers[facname] = nil
|
||||
on_death[name] = nil
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user