From c678fd55e2cf92cc5976cd03522f8184a91036e5 Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Mon, 8 Aug 2016 13:46:42 +0200 Subject: [PATCH] Fixed tons of bugs --- chatcommands.lua | 28 +++++++++++++--------------- factions.lua | 17 +---------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 8597912..10182e0 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -29,14 +29,16 @@ factions.register_command = function(cmd_name, cmd) infaction = true, description = "This command has no description.", run = function(self, player, argv) - --[[ check global privileges if self.global_privileges then - local bool, missing_privs = minetest.check_player_privs(player, self.global_privileges) - if not bool then - send_error(player, "Missing global privileges: "..table.concat(missing_privs, ", ")) - return false + local tmp = {} + for i in ipairs(self.global_privileges) do + tmp[self.global_privileges[i]] = true end - end]] + local bool, missing_privs = minetest.check_player_privs(player, tmp) + if not bool then + send_error(player, "Unauthorized.") + end + end -- checks argument formats local args = { factions = {}, @@ -62,7 +64,7 @@ factions.register_command = function(cmd_name, cmd) elseif argtype == "player" then local pl = minetest.get_player_by_name(arg) if not pl then - send_error(player, "Player is not invited.") + send_error(player, "Player is not online.") --TODO: track existing players for offsync invites and the like return false else @@ -87,7 +89,7 @@ factions.register_command = function(cmd_name, cmd) return false end player_faction = factions.factions[player_faction] - if faction_permissions then + if self.faction_permissions then for i in ipairs(self.faction_permissions) do if not player_faction:has_permission(player, self.faction_permissions[i]) then send_error(player, "You don't have permissions to do that.") @@ -240,7 +242,7 @@ factions.register_command("leave", { }) factions.register_command("kick", { - faction_permissions = {"playerlist"}, + faction_permissions = {"playerslist"}, format = {"player"}, description = "Kick a player from your faction.", on_success = function(player, faction, pos, chunkpos, args) @@ -251,7 +253,7 @@ factions.register_command("kick", { --TODO: message? return true else - --TODO: error (player is leader or in faction) + send_error(player, "Cannot kick player "..victim.name) return false end end @@ -332,7 +334,7 @@ factions.register_command("description", { faction_permissions = {"description"}, description = "Set your faction's description", on_success = function(player, faction, pos, chunkpos, args) - faction:set_description(args.other.concat(" ")) + faction:set_description(table.concat(args.other," ")) --TODO: message return true end @@ -375,10 +377,6 @@ factions.register_command("delete", { factions.register_command("ranks", { description = "List ranks within your faction", on_success = function(player, faction, pos, chunkpos, args) - if not faction then - --TODO: error message - return false - end for rank, permissions in pairs(faction.ranks) do minetest.chat_send_player(player, rank..": "..table.concat(permissions, " ")) end diff --git a/factions.lua b/factions.lua index 518591c..27d1b7c 100644 --- a/factions.lua +++ b/factions.lua @@ -48,21 +48,6 @@ end factions.Faction = { - power = 0., - players = {}, - ranks = {["leader"] = {"disband", "claim", "playerlist", "build", "edit", "ranks"}, - ["member"] = {"build"} - }, - leader = nil, - default_rank = "member", - default_leader_rank = "leader", - description = "Default faction description.", - invited_players = {}, - land = {}, - allies = {}, - enemies = {}, - join_free = false, - spawn = nil, } factions.Faction.__index = factions.Faction @@ -71,7 +56,7 @@ function factions.Faction:new(faction) faction = { power = 0., players = {}, - ranks = {["leader"] = {"disband", "claim", "playerlist", "build", "edit", "ranks"}, + ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "edit", "ranks"}, ["member"] = {"build"} }, leader = nil,