mirror of
https://github.com/mt-mods/playerfactions.git
synced 2024-12-22 05:42:33 +01:00
remove local f == factions
This commit is contained in:
parent
4caea5e17e
commit
7131896a0b
164
mtt.lua
164
mtt.lua
@ -2,14 +2,14 @@
|
||||
-- https://github.com/OgelGames/fakelib.git
|
||||
|
||||
local pd
|
||||
if table.packer then
|
||||
if table.pack then
|
||||
pd = function(...) print(dump(table.pack(...))) end
|
||||
else
|
||||
pd = function(...) for _, v in ipairs({ ... }) do print(dump(v)) end end
|
||||
end
|
||||
local f, fcc, S = factions, factions.handle_command, factions.S
|
||||
f.mode_unique_faction = false
|
||||
f.max_members_list = 11
|
||||
local fcc, S = factions.handle_command, factions.S
|
||||
factions.mode_unique_faction = false
|
||||
factions.max_members_list = 11
|
||||
|
||||
-- factions chat command checker
|
||||
-- b1: expected return bool
|
||||
@ -22,20 +22,20 @@ local function fccc(b1, s1, n, c)
|
||||
end
|
||||
|
||||
local function resetDB()
|
||||
for k in pairs(f.get_facts()) do
|
||||
f.disband_faction(k)
|
||||
for k in pairs(factions.get_facts()) do
|
||||
factions.disband_faction(k)
|
||||
end
|
||||
end
|
||||
|
||||
local function makeFactions()
|
||||
return f.register_faction('Endorian', 'Endor', 'eEe')
|
||||
and f.register_faction('Alberian', 'Albert', 'a')
|
||||
and f.register_faction('Gandalfian', 'Gandalf', 'GgG♥💩☺')
|
||||
return factions.register_faction('Endorian', 'Endor', 'eEe')
|
||||
and factions.register_faction('Alberian', 'Albert', 'a')
|
||||
and factions.register_faction('Gandalfian', 'Gandalf', 'GgG♥💩☺')
|
||||
end
|
||||
|
||||
local function dbChecks(callback)
|
||||
-- basic db integrity tests
|
||||
local facts = f.get_facts()
|
||||
local facts = factions.get_facts()
|
||||
assert('table' == type(facts))
|
||||
assert('table' == type(facts.Alberian))
|
||||
assert('Albert' == facts.Alberian.owner)
|
||||
@ -70,13 +70,13 @@ mtt.register('join & setup players', function(callback)
|
||||
|
||||
-- make Albert a faction-admin
|
||||
local player_privs = minetest.get_player_privs('Albert')
|
||||
player_privs[f.priv] = true
|
||||
player_privs[factions.priv] = true
|
||||
minetest.set_player_privs('Albert', player_privs)
|
||||
|
||||
-- make sure the others aren't
|
||||
for _, name in ipairs({ 'Endor', 'Gandalf', 'HanSolo' }) do
|
||||
player_privs = minetest.get_player_privs(name)
|
||||
player_privs[f.priv] = nil
|
||||
player_privs[factions.priv] = nil
|
||||
minetest.set_player_privs(name, player_privs)
|
||||
end
|
||||
|
||||
@ -100,15 +100,15 @@ end)
|
||||
mtt.register('basic db checks', dbChecks)
|
||||
|
||||
mtt.register('backend functions: player_is_in_faction', function(callback)
|
||||
assert(false == f.player_is_in_faction(
|
||||
assert(false == factions.player_is_in_faction(
|
||||
'notExistingFaction', 'notExistingPlayer'))
|
||||
assert(false == f.player_is_in_faction(
|
||||
assert(false == factions.player_is_in_faction(
|
||||
'notExistingFaction', 'Gandalf'))
|
||||
assert(false == f.player_is_in_faction(
|
||||
assert(false == factions.player_is_in_faction(
|
||||
'Gandalfian', 'notExistingPlayer'))
|
||||
assert(nil == f.player_is_in_faction(
|
||||
assert(nil == factions.player_is_in_faction(
|
||||
'Gandalfian', 'Albert'))
|
||||
assert(true == f.player_is_in_faction(
|
||||
assert(true == factions.player_is_in_faction(
|
||||
'Gandalfian', 'Gandalf'))
|
||||
|
||||
callback()
|
||||
@ -116,84 +116,84 @@ end)
|
||||
|
||||
mtt.register('backend functions: get_player_faction', function(callback)
|
||||
-- (depricated) --> check log output for messages
|
||||
assert(false == f.get_player_faction('notExistingPlayer'))
|
||||
assert(nil == f.get_player_faction('HanSolo'))
|
||||
assert('Alberian' == f.get_player_faction('Albert'))
|
||||
assert(false == factions.get_player_faction('notExistingPlayer'))
|
||||
assert(nil == factions.get_player_faction('HanSolo'))
|
||||
assert('Alberian' == factions.get_player_faction('Albert'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: get_player_factions', function(callback)
|
||||
if pcall(f.get_player_factions, nil) then
|
||||
if pcall(factions.get_player_factions, nil) then
|
||||
callback('did not fail with nil as player argument -> bad')
|
||||
end
|
||||
if pcall(f.get_player_factions, 42) then
|
||||
if pcall(factions.get_player_factions, 42) then
|
||||
callback('did not fail with number as player argument -> bad')
|
||||
end
|
||||
assert(false == f.get_player_factions('notExistingPlayer'))
|
||||
assert(false == f.get_player_factions('HanSolo'))
|
||||
assert('Alberian' == f.get_player_factions('Albert')[1])
|
||||
assert(false == factions.get_player_factions('notExistingPlayer'))
|
||||
assert(false == factions.get_player_factions('HanSolo'))
|
||||
assert('Alberian' == factions.get_player_factions('Albert')[1])
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: get_owned_factions', function(callback)
|
||||
assert(false == f.get_owned_factions(nil))
|
||||
assert(false == f.get_owned_factions(42))
|
||||
assert(false == f.get_owned_factions('notExistingPlayer'))
|
||||
assert(false == f.get_owned_factions('HanSolo'))
|
||||
local t = f.get_owned_factions('Albert')
|
||||
assert(false == factions.get_owned_factions(nil))
|
||||
assert(false == factions.get_owned_factions(42))
|
||||
assert(false == factions.get_owned_factions('notExistingPlayer'))
|
||||
assert(false == factions.get_owned_factions('HanSolo'))
|
||||
local t = factions.get_owned_factions('Albert')
|
||||
assert(1 == #t and 'Alberian' == t[1])
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: get_administered_factions', function(callback)
|
||||
if pcall(f.get_administered_factions) then
|
||||
if pcall(factions.get_administered_factions) then
|
||||
callback('calling get_administered_factions with nil did not raise error')
|
||||
end
|
||||
-- a bit strange that number as player name 'works'
|
||||
assert(false == f.get_administered_factions(42))
|
||||
assert(false == f.get_administered_factions('notExistingPlayer'))
|
||||
assert(false == f.get_administered_factions('HanSolo'))
|
||||
local t = f.get_administered_factions('Gandalf')
|
||||
assert(false == factions.get_administered_factions(42))
|
||||
assert(false == factions.get_administered_factions('notExistingPlayer'))
|
||||
assert(false == factions.get_administered_factions('HanSolo'))
|
||||
local t = factions.get_administered_factions('Gandalf')
|
||||
assert(1 == #t and 'Gandalfian' == t[1])
|
||||
assert(3 == #f.get_administered_factions('Albert'))
|
||||
assert(3 == #factions.get_administered_factions('Albert'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: get_owner', function(callback)
|
||||
assert(false == f.get_owner('notExistingFaction'))
|
||||
assert('Gandalf' == f.get_owner('Gandalfian'))
|
||||
assert(false == factions.get_owner('notExistingFaction'))
|
||||
assert('Gandalf' == factions.get_owner('Gandalfian'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: chown', function(callback)
|
||||
assert(false == f.chown('notExistingFaction', 'Gandalf'))
|
||||
assert(true == f.chown('Endorian', 'Gandalf'))
|
||||
assert(false == factions.chown('notExistingFaction', 'Gandalf'))
|
||||
assert(true == factions.chown('Endorian', 'Gandalf'))
|
||||
-- revert the 'illegal' use
|
||||
f.chown('Endorian', 'Endor')
|
||||
factions.chown('Endorian', 'Endor')
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: register_faction', function(callback)
|
||||
-- (partly tested in setup)
|
||||
assert(false == f.register_faction('Endorian', 'Endor', 'rodnE'))
|
||||
assert(false == f.register_faction())
|
||||
assert(false == factions.register_faction('Endorian', 'Endor', 'rodnE'))
|
||||
assert(false == factions.register_faction())
|
||||
-- empty password
|
||||
assert(f.register_faction('foo', 'bar', ''))
|
||||
assert(factions.register_faction('foo', 'bar', ''))
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: disband_faction', function(callback)
|
||||
-- (partly tested in setup)
|
||||
assert(f.disband_faction('foo'))
|
||||
assert(false == f.disband_faction())
|
||||
assert(false == f.disband_faction('notExistingFaction'))
|
||||
assert(factions.disband_faction('foo'))
|
||||
assert(false == factions.disband_faction())
|
||||
assert(false == factions.disband_faction('notExistingFaction'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
@ -205,46 +205,46 @@ mtt.register('backend functions: hash_password', function(callback)
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: valid_password', function(callback)
|
||||
assert(false == f.valid_password())
|
||||
assert(false == f.valid_password('Endorian'))
|
||||
assert(false == f.valid_password('Endorian', 'foobar'))
|
||||
assert(true == f.valid_password('Endorian', 'eEe'))
|
||||
assert(false == factions.valid_password())
|
||||
assert(false == factions.valid_password('Endorian'))
|
||||
assert(false == factions.valid_password('Endorian', 'foobar'))
|
||||
assert(true == factions.valid_password('Endorian', 'eEe'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: get_password (depricated)', function(callback)
|
||||
assert(nil == f.get_password())
|
||||
assert(nil == f.get_password('Endorian'))
|
||||
assert(nil == factions.get_password())
|
||||
assert(nil == factions.get_password('Endorian'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: set_password', function(callback)
|
||||
assert(false == f.set_password('notExistingFaction', 'foobar'))
|
||||
assert(false == f.set_password('Endorian'))
|
||||
assert(true == f.set_password('Endorian', 'EeE'))
|
||||
assert(f.valid_password('Endorian', 'EeE'))
|
||||
assert(false == factions.set_password('notExistingFaction', 'foobar'))
|
||||
assert(false == factions.set_password('Endorian'))
|
||||
assert(true == factions.set_password('Endorian', 'EeE'))
|
||||
assert(factions.valid_password('Endorian', 'EeE'))
|
||||
-- revert that again
|
||||
f.set_password('Endorian', 'eEe')
|
||||
factions.set_password('Endorian', 'eEe')
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: join_faction', function(callback)
|
||||
assert(false == f.join_faction())
|
||||
assert(false == f.join_faction('Endorian'))
|
||||
assert(false == f.join_faction('Endorian', 'notExistingPlayer'))
|
||||
assert(true == f.join_faction('Endorian', 'Gandalf'))
|
||||
assert(false == factions.join_faction())
|
||||
assert(false == factions.join_faction('Endorian'))
|
||||
assert(false == factions.join_faction('Endorian', 'notExistingPlayer'))
|
||||
assert(true == factions.join_faction('Endorian', 'Gandalf'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
||||
mtt.register('backend functions: leave_faction', function(callback)
|
||||
assert(false == f.leave_faction())
|
||||
assert(false == f.leave_faction('Endorian'))
|
||||
assert(false == f.leave_faction('Endorian', 'notExistingPlayer'))
|
||||
assert(true == f.leave_faction('Endorian', 'Gandalf'))
|
||||
assert(false == factions.leave_faction())
|
||||
assert(false == factions.leave_faction('Endorian'))
|
||||
assert(false == factions.leave_faction('Endorian', 'notExistingPlayer'))
|
||||
assert(true == factions.leave_faction('Endorian', 'Gandalf'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
@ -263,10 +263,10 @@ mtt.register('frontend functions: create', function(callback)
|
||||
assert(fccc(false, S("Missing password."), 'Gandalf', 'create foobar'))
|
||||
assert(fccc(false, S("Faction @1 already exists.", 'Gandalfian'),
|
||||
'Gandalf', 'create Gandalfian foobar'))
|
||||
f.mode_unique_faction = true
|
||||
factions.mode_unique_faction = true
|
||||
assert(fccc(false, S("You are already in a faction."),
|
||||
'Gandalf', 'create Gandalfian2 foobar'))
|
||||
f.mode_unique_faction = false
|
||||
factions.mode_unique_faction = false
|
||||
-- correct creation (also with capitals in sub-command)
|
||||
assert(fccc(true, S("Registered @1.", 'Gandalfian2'),
|
||||
'Gandalf', 'cREate Gandalfian2 foobar'))
|
||||
@ -317,7 +317,7 @@ mtt.register('frontend functions: info', function(callback)
|
||||
makeFactions()
|
||||
assert(fccc(false, S("Faction @1 doesn't exist.", 'foobar'),
|
||||
'Endor', 'info foobar'))
|
||||
f.join_faction('Endorian', 'Gandalf')
|
||||
factions.join_faction('Endorian', 'Gandalf')
|
||||
assert(fccc(false, S("You are in multiple factions, you have to choose one of them: @1.",
|
||||
'Endorian, Gandalfian'), 'Gandalf', 'info')
|
||||
or fccc(false, S("You are in multiple factions, you have to choose one of them: @1.",
|
||||
@ -326,11 +326,11 @@ mtt.register('frontend functions: info', function(callback)
|
||||
-- so just dumping result for optical check.
|
||||
pd('Endor executes: /factions info', fcc('Endor', 'info'))
|
||||
assert(fcc('Endor', 'info'))
|
||||
f.max_members_list = 1
|
||||
factions.max_members_list = 1
|
||||
pd('max_members_list == 1 and Endor executes: /factions info',
|
||||
fcc('Endor', 'info'))
|
||||
assert(fcc('Endor', 'info'))
|
||||
f.max_members_list = 11
|
||||
factions.max_members_list = 11
|
||||
pd('Endor executes: /factions info Gandalfian', fcc('Endor', 'info Gandalfian'))
|
||||
assert(fcc('Endor', 'info Gandalfian'))
|
||||
|
||||
@ -359,10 +359,10 @@ mtt.register('frontend functions: player_info', function(callback)
|
||||
end)
|
||||
|
||||
mtt.register('frontend functions: join', function(callback)
|
||||
f.mode_unique_faction = true
|
||||
factions.mode_unique_faction = true
|
||||
assert(fccc(false, S("You are already in a faction."),
|
||||
'Endor', 'join'))
|
||||
f.mode_unique_faction = false
|
||||
factions.mode_unique_faction = false
|
||||
assert(fccc(false, S("Missing faction name."),
|
||||
'Endor', 'join'))
|
||||
assert(fccc(false, S("Faction @1 doesn't exist.", 'notExistingFaction'),
|
||||
@ -437,15 +437,15 @@ mtt.register('frontend functions: passwd', function(callback)
|
||||
'Endor', 'passwd foobar Gandalfian'))
|
||||
assert(fccc(true, S("Password has been updated."),
|
||||
'Endor', 'passwd foobar'))
|
||||
assert(f.get_facts().Endorian.password256 ==
|
||||
assert(factions.get_facts().Endorian.password256 ==
|
||||
'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')
|
||||
assert(fccc(true, S("Password has been updated."),
|
||||
'Gandalf', 'passwd foobar Gandalfian'))
|
||||
assert(f.get_facts().Gandalfian.password256 ==
|
||||
assert(factions.get_facts().Gandalfian.password256 ==
|
||||
'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')
|
||||
assert(fccc(true, S("Password has been updated."),
|
||||
'Albert', 'passwd barf Gandalfian'))
|
||||
assert(f.get_facts().Gandalfian.password256 ==
|
||||
assert(factions.get_facts().Gandalfian.password256 ==
|
||||
'8a6e40cfcd99060eb1efdfeb689fe26606e221b4fd487bb224ab79a82648ccd9')
|
||||
|
||||
callback()
|
||||
@ -467,15 +467,15 @@ mtt.register('frontend functions: chown', function(callback)
|
||||
'Gandalf', 'chown notExistingPlayer foobar'))
|
||||
assert(fccc(false, S("@1 isn't in faction @2.", 'Endor', 'Gandalfian'),
|
||||
'Gandalf', 'chown Endor foobar'))
|
||||
f.join_faction('Gandalfian', 'Endor')
|
||||
factions.join_faction('Gandalfian', 'Endor')
|
||||
assert(fccc(false, S("Permission denied: Wrong password."),
|
||||
'Gandalf', 'chown Endor foobar'))
|
||||
assert(fccc(true, S("Ownership has been transferred to @1.", 'Endor'),
|
||||
'Gandalf', 'chown Endor barf'))
|
||||
assert('Endor' == f.get_owner('Gandalfian'))
|
||||
assert('Endor' == factions.get_owner('Gandalfian'))
|
||||
assert(fccc(true, S("Ownership has been transferred to @1.", 'Gandalf'),
|
||||
'Albert', 'chown Gandalf foobar Gandalfian'))
|
||||
assert('Gandalf' == f.get_owner('Gandalfian'))
|
||||
assert('Gandalf' == factions.get_owner('Gandalfian'))
|
||||
|
||||
callback()
|
||||
end)
|
||||
@ -493,10 +493,10 @@ mtt.register('frontend functions: invite', function(callback)
|
||||
'Albert', 'invite notExistingPlayer Gandalfian'))
|
||||
assert(fccc(false, S("Player @1 is already in faction @2.", 'Endor', 'Gandalfian'),
|
||||
'Albert', 'invite Endor Gandalfian'))
|
||||
f.mode_unique_faction = true
|
||||
factions.mode_unique_faction = true
|
||||
assert(fccc(false, S("Player @1 is already in faction @2.", 'Gandalf', 'Gandalfian'),
|
||||
'Albert', 'invite Gandalf Endorian'))
|
||||
f.mode_unique_faction = false
|
||||
factions.mode_unique_faction = false
|
||||
assert(fccc(true, S("@1 is now a member of faction @2.", 'Gandalf', 'Endorian'),
|
||||
'Albert', 'invite Gandalf Endorian'))
|
||||
|
||||
@ -504,7 +504,7 @@ mtt.register('frontend functions: invite', function(callback)
|
||||
end)
|
||||
|
||||
mtt.register('final db checks', function(callback)
|
||||
pd(f.get_facts())
|
||||
pd(factions.get_facts())
|
||||
|
||||
callback()
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user