From 0612afb3388f6430324d37306253895a5bfa9360 Mon Sep 17 00:00:00 2001 From: Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com> Date: Tue, 13 Oct 2020 00:57:52 +0200 Subject: [PATCH] Add checks on command args to avoid server crashes --- init.lua | 12 +++++++++++- locale/playerfactions.fr.tr | 2 ++ locale/template.txt | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 5a21f77..e8e1e29 100644 --- a/init.lua +++ b/init.lua @@ -287,6 +287,10 @@ local function handle_command(name, param) end elseif action == "player_info" then local player_name = params[2] + if not player_name then + minetest.chat_send_player(name, S("The player name is nil or empty.")) + return false + end local player_factions = factions.get_player_factions(player_name) if not player_factions then minetest.chat_send_player(name, S("This player doesn't exists or is in no faction")) @@ -324,6 +328,8 @@ local function handle_command(name, param) local password = params[3] if factions.get_player_faction(name) ~= nil and factions.mode_unique_faction then minetest.chat_send_player(name, S("You are already in a faction.")) + elseif not faction_name then + minetest.chat_send_player(name, S("Missing faction name.")) elseif facts[faction_name] == nil then minetest.chat_send_player(name, S("The faction @1 doesn't exist.", faction_name)) elseif factions.get_password(faction_name) ~= password then @@ -487,7 +493,11 @@ local function handle_command(name, param) else local target = params[2] local faction_name = params[3] - if facts[faction_name] == nil then + if not target then + minetest.chat_send_player(name, S("Missing target.")) + elseif not faction_name then + minetest.chat_send_player(name, S("Missing faction name.")) + elseif facts[faction_name] == nil then minetest.chat_send_player(name, S("The faction @1 doesn't exist.", faction_name)) elseif not minetest.player_exists(target) then minetest.chat_send_player(name, S("The player doesn't exist.")) diff --git a/locale/playerfactions.fr.tr b/locale/playerfactions.fr.tr index 4ae0433..80c6de7 100644 --- a/locale/playerfactions.fr.tr +++ b/locale/playerfactions.fr.tr @@ -33,6 +33,7 @@ List available factions=Liste les factions disponibles Missing faction name.=Nom de faction manquant. Missing password.=Mot de passe manquant. Missing player name.=Nom de joueur manquant. +Missing target.=Nom du joueur cible manquant. Name: @1@nOwner: @2@nMembers: @3=Nom : @1@nPropriétaire : @2@nMembres : @3 Ownership has been transferred to @1.=La propriété a été transférée à @2. Password has been updated.=Le mot de passe a été mis à jour. @@ -56,6 +57,7 @@ The player doesn't exist.=Le joueur n’existe pas. The player is already in the faction "@1".=Le joueur est déjà dans la faction "@1". There are no factions yet.=Il n’y a pas encore de factions. This faction doesn't exists.=Cette faction n’existe pas. +The player name is nil or empty.=Le nom du joueur est nul ou vide. This player doesn't exists or is in no faction=Ce joueur n’existe pas ou n’est dans aucune faction. This player is not in the specified faction.=Le joueur n’est pas dans la faction spécifiée. This player is the owner of no faction.=Ce joueur n’est propriétaire d’aucune faction. diff --git a/locale/template.txt b/locale/template.txt index 1e855c7..c309bf4 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -33,6 +33,7 @@ List available factions= Missing faction name.= Missing password.= Missing player name.= +Missing target.= Name: @1@nOwner: @2@nMembers: @3= Ownership has been transferred to @1.= Password has been updated.= @@ -56,6 +57,7 @@ The player doesn't exist.= The player is already in the faction "@1".= There are no factions yet.= This faction doesn't exists.= +The player name is nil or empty.= This player doesn't exists or is in no faction= This player is not in the specified faction.= This player is the owner of no faction.=