Go to file
Luke aka SwissalpS d6e7c62b84
Updated 5.9.0 (#12)
* Store hashes of passwords

cleartext password storage is bad practice.

* Depricate factions.get_password()

returns nil after first run

* loaded message

* Properly use the configurable admin priv in output

* Don't show password, since we can't anymore

* remove code that is never reached

* chown: reorder to first check if player has any factions at all

There is no point in checking other params if this part fails.

* chown: fix command signature

password is required

* proper admin priv listing in help for invite

* wrap fixup code in do-block

variable save_needed is not used for anything else

* locale: many -> multiple

* locale: remove unused entry

* locale: ownership rephrasing

* locale: tweak and add "No factions found."

* locale: exists -> exist

* locale: this -> that or better

also fixed a french mistake: player doesn't own these -> player owns
these

* locale: reuse string for missing name

besides, "nil" is a valid name. This way there is no confusion.

* locale: reuse "missing player name"

* locale: reuse "faction x doesn't exist"

* locale: faction x already exists

* locale: the player -> player x

* locale: some more de-Frenching

* add local is_admin

stash commit...

* disband: allow admin

- permit admin to disband a faction without having any factions himself
- permit admin to skip password check (he can supply any placeholder)
- permit admin to disband his own single faction
- don't call get_owner or valid_password if is admin
- streamline duplicate code

* list: check for true first instead of using negation

- check for no factions first -> simpler code
- whitespace: linebreak for easier reading

* info: cleanup

- whitespace linebreaks for easier reading and consistancy
- update helptext signiture (also for disband) to reflect actual
requirements and standard
- loop members into table for consistant and easier to read code

* player_info: cleanup

- move depricated log entry to start of get_player_faction(), no point
in skipping warning.
- simplify get_player_factions()
- whitespace linebreaks for easier reading and consistancy
- loop members into table for consistant and easier to read code
- simplify get_owned_factions()
- make player_name param optional, default to caller (still need to
check as caller name can be missing)
- loop factions into table for consistant and easier to read code (also
presumpted faster)

* join: cleanup

- don't call get_player_factions() unless needed
- use get_player_factions() instead of depricated get_player_faction()
- truth check of password in valid_password() for easier understanding
of code
- remove explicit nil check where not needed

* leave: cleanup

- update help text to standard syntax
- remove unnecessary param count checks
- simplify leave_faction() argument checking

* kick: cleanup

- simplify and reduce calls of core.get_player_privs()
- update help text to standard syntax
- streamline duplicate code
- remove unnecessary param count checks
- remove explicit nil check where not needed
- don't call get_owner if is admin (until needed)

* passwd: cleanup

- update help text to standard syntax
- streamline duplicate code
- remove unnecessary param count checks
- remove explicit nil check where not needed
- don't call get_owner if is admin

* chown: cleanup and tweak

- update help text to standard syntax
- streamline duplicate code
- remove unnecessary param count checks
- remove explicit nil check where not needed
- updated locale to be neutral to admin or owner
- don't call get_owner or valid_password if is admin
- remove core.player_exists() call since target was checked when joined
faction
- abort early if no target or password provided

* invite: cleanup and tweaks

- reduced needed indents
- remove explicit nil check where not needed
- use get_player_factions() instead of depricated get_player_faction()
and reduce calls of it
- tweaked join_faction()
- adds check if player already is in that faction

* more tweaks

- join: check if already member
- leave: checks if user is in given faction at all
- kick: early abort if no player provided
- create: early abort if no faction or password are provided
- create: use get_player_factions() instead of get_player_faction()
- create: reduce explicit nil checks
- disband: early abort if missing password
- disband: reduce param-count-checks and use table.getn()
- info: reduce explicit nil checks and use table.getn()
- passwd: early abort if no password provided
- in general remove explicit nil-checks where not needed

* is_admin -> not_admin

for slightly easier reading and shorter lines

* fix translator missing argument

* some facepalm fixes

and tweaks of table.getn() for consistency, here # would work just as
well.

* set minimum server version to 5.9.0

* another facepalm moment

* add mtt support

* refactor handle_command for mtt

It could've been done by only exposing handle_command, but this is
cleaner for future maintenance as tasks are well separated.

* bundle mtt related lines

* needs fakelib, not areas

areas will need this mod for testing

* remove unused arguments

* add owner to members on cleanup

* rename chat to cc

also no need to expose cc directly to mtt

* register the actually set priv when it is missing

* label data correctly

* move settings higher up where they are expected to be

* consistancy with variable names

use faction_name, player_name, target_name, password etc.
instead of a jumble of pw, fname, name, player_name etc.

* reduce needles table-copy

* fail to register same named factions

* no-op depricated and useless get_password

* some more checks in some API methods

* whitespace and comments

* pass translator to mtt

* bugfix cc.disband inverted password check

* standardize var name and reduce looping

* add get_members() api-method and use it

* player_info: count empty string as no player

* player_info: switch if-else to avoid negation

* unreachable comments

* simpler check

* add mtt-checks for front and backend commands

* update french locale

- informal tone
- adds missing entries

* add Spanish locale

* add German locale

* whitespace cleanup

* add fakelib comment

* provide alternative to table.pack()

* add disband hook support

* remove local f == factions
2024-12-31 19:45:10 +01:00
.github/workflows general overhaul for 5.0.0 (#11) 2024-10-13 22:24:58 -04:00
locale Updated 5.9.0 (#12) 2024-12-31 19:45:10 +01:00
.gitignore Add missing french translations I forgot in my last PR 2020-08-23 14:32:56 +02:00
.luacheckrc general overhaul for 5.0.0 (#11) 2024-10-13 22:24:58 -04:00
init.lua Updated 5.9.0 (#12) 2024-12-31 19:45:10 +01:00
LICENSE.md Added GPLv3 license 2019-09-09 16:06:33 -04:00
mod.conf Updated 5.9.0 (#12) 2024-12-31 19:45:10 +01:00
mtt.lua Updated 5.9.0 (#12) 2024-12-31 19:45:10 +01:00
README.md Fix grammar and add README 2020-08-22 23:58:18 +00:00
settingtypes.txt allow custom factions_admin priv (#7) 2023-04-14 18:35:31 +02:00

playerfactions

A simple mod which allows player created factions. Not very useful on its own, it becomes very powerful when combined with other mods.

Usage

We can choose a mode : single or multi factions. By default players can only be in one faction at a time. If you want to allow players to join multiple factions at once, add player_factions.mode_unique_faction = false to minetest.conf

Parameters marked with square brackets ([]) are optional; most of these are only used if mode_unique_faction is false.

There is an admin privs to enable every functions for every faction : playerfactions_admin

These commands can be used by anyone:

  • /factions create <faction> <password>: Create a new faction
  • /factions list: List available factions
  • /factions info <faction>: See information on a faction. For faction with lot of member we can choose the length of the member's list that's going to be shown by adding player_factions.max_members_list = int to minetest.conf, default is 50.
  • /factions player_info <player> See information on a player : joined, owned and administered factions.
  • /factions join <faction> <password>: Join an existing faction
  • /factions leave [faction]: Leave your faction

These commands can only be used by faction owners and players with the playerfactions_admin privilege:

  • /factions kick <player> [faction]: Kick someone from your faction
  • /factions disband <password> [faction]: Disband your faction
  • /factions passwd <password> [faction]: Change your faction's password
  • /factions chown <player> <password> [faction]: Transfer ownership of your faction

This command can only be used by players with the playerfactions_admin privilege:

  • /factions invite <player> <faction>: Add player to a faction

Translations

If you know English and another language, please submit a translation! It would be greatly appreciated, and your name will be added to the acknowledgements at the bottom of this page. Thanks!

Mod integration

The following mods have optional support for playerfactions:

  • areas: Protect faction territory using areas. link
  • protector: Allow faction to be added as a member to protection blocks. link

Using playerfactions in your own mod

I strongly recommend reading through the init.lua file; the functions at the top give you a pretty good idea of how to use it, but just in case you're short on time I'll list the most important functions below.

  • factions.version is a variable made to check the version of the playerfactions mod to assert compatibility:
  • factions.version == nil for firsts version of playerfactions mod
  • factions.version == 2 is the first time this variable is added, with adding multi-faction mode
  • player_is_in_faction(fname, player_name): true if the player is in the faction, nil in other cases (faction or player doesn't exists or player is not a member of the faction)
  • get_facts(): Get a copied table with all data. The structure is :
{["name_of_faction1"]={
      ["owner"]=name_of_the_owner,
      ["members"]={["name_of_a_member1"]=true, ["name_of_a_member2"]=true}
  }}
  • get_player_faction(player): Get a string with the faction a player belongs to, nil if they haven't joined a faction. In multi-faction mode, it will return the oldest created faction which player is into. (it's not necessarily the one they joined first. It checks the facts variable from the top)
  • get_player_factions(player): Get a table with the faction(s) a player belongs to, nil if they haven't joined a faction. The structure is: {name_of_faction1, name_of_faction2}
  • get_owned_factions(player): Get a table with the faction(s) owned by a player, nil if they have the ownership of no faction. The structure is: {name_of_faction1, name_of_faction2}
  • get_owner(faction): Get the owner of a faction
  • chown(fname, owner): Change the owner of a faction
  • register_faction(faction, player, password): Create a new faction
  • disband_faction(faction): Disband a faction
  • get_password(faction): Gets a faction's password
  • set_password(faction, password): Sets a faction's password
  • join_faction(faction, player): Sets the given player as belonging to this faction
  • leave_faction(faction, player): Remove the given player from the specified faction

Note that all of these functions have sanity checks : if faction or player does not exists, it return false. If operation succeed, it return true or the needed value.

Acknowledgements

Multi-faction mode and various other improvements added by Kalio_42.

This mod is loosely based off of the (unmaintained) factions mod made by Jonjeg.