Bladeren bron

Added player permission script commands (#8450)

Daegaladh 11 maanden geleden
bovenliggende
commit
5123704795
4 gewijzigde bestanden met toevoegingen van 167 en 33 verwijderingen
  1. 37 31
      doc/permissions.txt
  2. 42 2
      doc/script_commands.txt
  3. 54 0
      src/map/script.cpp
  4. 34 0
      src/map/script_constants.hpp

+ 37 - 31
doc/permissions.txt

@@ -11,6 +11,12 @@
 This file describes the functions of player group permissions,
 configured in '/conf/groups.conf' under the "permissions" bracket.
 
+The permission name used in '/conf/groups.conf' goes after the asterisk "*",
+while the constant name used in scripts and src goes between the parentheses "()"
+in the following format:
+
+*permission_name (PC_PERM_CONSTANT_NAME)
+
 To search for a permission, write "*" before its name.
 The format of this file is as follows:
 	1. Basic Permissions
@@ -22,20 +28,20 @@ The format of this file is as follows:
 ========================
 ---------------------------------------
 
-*can_trade
+*can_trade (PC_PERM_TRADE)
 
 Allows player to distribute items, such as through trades, dropping,
 vending, storage, mail, etc.
 
 ---------------------------------------
 
-*can_party
+*can_party (PC_PERM_PARTY)
 
 Allows player to create and join parties.
 
 ---------------------------------------
 
-*attendance
+*attendance (PC_PERM_ATTENDANCE)
 
 Allows player to use the daily attendance system.
 
@@ -46,78 +52,78 @@ Allows player to use the daily attendance system.
 ===========================
 ---------------------------------------
 
-*all_skill
+*all_skill (PC_PERM_ALL_SKILL)
 
 Grants player all available skills in the player's skill tree.
 
 ---------------------------------------
 
-*all_equipment
+*all_equipment (PC_PERM_USE_ALL_EQUIPMENT)
 
 Allows player to equip any item, regardless of requirements (class, level,
 etc.). Note that this can cause client errors if a sprite does not exist.
 
 ---------------------------------------
 
-*skill_unconditional
+*skill_unconditional (PC_PERM_SKILL_UNCONDITIONAL)
 
 Allows player to use any skill, regardless of required conditions (SP,
 items, etc.).
 
 ---------------------------------------
 
-*join_chat
+*join_chat (PC_PERM_JOIN_ALL_CHAT)
 
 Allows player to join password-protected chatrooms.
 
 ---------------------------------------
 
-*kick_chat
+*kick_chat (PC_PERM_NO_CHAT_KICK)
 
 Prevents player from being kicked from a chatroom.
 
 ---------------------------------------
 
-*view_hpmeter
+*view_hpmeter (PC_PERM_VIEW_HPMETER)
 
 Allows player to see the HP bar of every player.
 
 ---------------------------------------
 
-*view_equipment
+*view_equipment (PC_PERM_VIEW_EQUIPMENT)
 
 Allows player to view the equipment of every player, regardless of that
 player's setting.
 
 ---------------------------------------
 
-*hack_info
+*hack_info (PC_PERM_RECEIVE_HACK_INFO)
 
 Allows player to receive all information about players who try to hack,
 spoof a name, etc.
 
 ---------------------------------------
 
-*disable_pvm
+*disable_pvm (PC_PERM_DISABLE_PVM)
 
 Prevents player from attacking monsters.
 
 ---------------------------------------
 
-*disable_pvp
+*disable_pvp (PC_PERM_DISABLE_PVP)
 
 Prevents player from attacking other players.
 
 ---------------------------------------
 
-*can_trade_bounded
+*can_trade_bounded (PC_PERM_TRADE_BOUNDED)
 
 Allows player to do normal item actions with bounded items (drop, sell,
 trade, etc.).
 
 ---------------------------------------
  
-*item_unconditional
+*item_unconditional (PC_PERM_ITEM_UNCONDITIONAL)
 
 Allows player to consume any consumable item regardless the requirements
 (bypass noitemconsumption mapflag, item's class, gender, status changes,
@@ -125,7 +131,7 @@ item delay, etc).
 
 ---------------------------------------
 
-*trade_unconditional
+*trade_unconditional (PC_PERM_TRADE_UNCONDITIONAL)
 
 Allows player to ignore the trade conditions of items (drop, trade, sell, cart, storage/gstorage, mail and auction).
 
@@ -136,32 +142,32 @@ Allows player to ignore the trade conditions of items (drop, trade, sell, cart,
 ======================
 ---------------------------------------
 
-*all_commands
+*all_commands (PC_PERM_USE_ALL_COMMANDS)
 
 Allows usage of all atcommands and charcommands.
 
 ---------------------------------------
 
-*disable_commands_when_dead
+*disable_commands_when_dead (PC_PERM_DISABLE_CMD_DEAD)
 
 Disables usage of atcommands when player is dead.
 
 ---------------------------------------
 
-*hide_session
+*hide_session (PC_PERM_HIDE_SESSION)
 
 Hides player session from being displayed by atcommands (@who, @whomap,
 etc.).
 
 ---------------------------------------
 
-*who_display_aid
+*who_display_aid (PC_PERM_WHO_DISPLAY_AID)
 
 Displays all GMs and character/account IDs in the @who command.
 
 ---------------------------------------
 
-*any_warp
+*any_warp (PC_PERM_WARP_ANYWHERE)
 
 Allows player to bypass 'nowarp', 'nowarpto', 'noteleport', and 'nomemo'
 mapflags in commands which modify a character's map or coordinates (@memo,
@@ -169,63 +175,63 @@ mapflags in commands which modify a character's map or coordinates (@memo,
 
 ---------------------------------------
 
-*receive_requests
+*receive_requests (PC_PERM_RECEIVE_REQUESTS)
 
 Allows player to receive requests through the @requests command.
 
 ---------------------------------------
 
-*show_bossmobs
+*show_bossmobs (PC_PERM_SHOW_BOSS)
 
 Displays boss mobs in the @showmobs command.
 
 ---------------------------------------
 
-*channel_admin
+*channel_admin (PC_PERM_CHANNEL_ADMIN)
 
 Allows player to modify #channel settings regardless of ownership and to
 join password-protected channels without a password.
 
 ---------------------------------------
 
-*use_check
+*use_check (PC_PERM_USE_CHECK)
 
 Allows player to use the client command /check (displays character status).
 
 ---------------------------------------
 
-*use_changemaptype
+*use_changemaptype (PC_PERM_USE_CHANGEMAPTYPE)
 
 Allows player to use the client command /changemaptype.
 
 ---------------------------------------
 
-*command_enable
+*command_enable (PC_PERM_ENABLE_COMMAND)
 
 Enable to use atcommand while talking with NPC.
 
 ---------------------------------------
 
-*bypass_stat_onclone
+*bypass_stat_onclone (PC_PERM_BYPASS_STAT_ONCLONE)
 
 Bypass max parameter limit while using @clonestat
 
 ---------------------------------------
 
-*bypass_max_stat
+*bypass_max_stat (PC_PERM_BYPASS_MAX_STAT)
 
 Allow to bypass the maximum stat parameter (at conf/player.conf) to
 maximum value 32,767.
 
 ---------------------------------------
 
-*macro_detect
+*macro_detect (PC_PERM_MACRO_DETECT)
 
 Allows player to use the client command /macro_detector.
 
 ---------------------------------------
 
-*macro_register
+*macro_register (PC_PERM_MACRO_REGISTER)
 
 Allows player to use the client commands /macro_register (used to add new captcha) and /macro_preview (used to preview captcha by ID).
 

+ 42 - 2
doc/script_commands.txt

@@ -6638,8 +6638,8 @@ Examples:
 
 ---------------------------------------
 
-macro_detector({<account ID>});
-macro_detector({"<character name>"});
+*macro_detector({<account ID>});
+*macro_detector({"<character name>"});
 
 This command will display the captcha UI challenge onto the invoking character or the given <account ID>/<character name>.
 
@@ -6660,6 +6660,46 @@ Example:
 
 ---------------------------------------
 
+*permission_check(<permission>{,<char_id>});
+
+This command will return true if the attached character has the specified permission, false otherwise.
+If <char_id> is given, it will check the permission for that character instead.
+
+A full list of the player permission constants (with the 'PC_PERM' prefix) along with the
+full permissions documentation can be found in 'doc/permissions.txt'.
+
+
+Example:
+	if (permission_check(PC_PERM_TRADE)) {
+		mes "You have permission to trade!";
+	}
+	else {
+		mes "You do not have permission to trade!";
+	}
+	end;
+
+---------------------------------------
+
+*permission_add(<permission>{,<char_id>});
+*permission_remove(<permission>{,<char_id>});
+
+These commands will temporarily add or remove the specified permission to the attached character,
+or the given <char_id> until the player logs out.
+
+A full list of the player permission constants (with the 'PC_PERM' prefix) along with the
+full permissions documentation can be found in 'doc/permissions.txt'.
+
+Examples:
+	// Adds the 'can_trade' permission to the attached character,
+	// allowing them to trade, drop, sell, store and mail items.
+	permission_add(PC_PERM_TRADE);
+
+	// Removes the 'can_party' permission from the attached character,
+	// preventing them from joining or creating parties.
+	permission_remove(PC_PERM_PARTY);
+
+---------------------------------------
+
 ==================================
 |5.- Mob / NPC -related commands.|
 ==================================

+ 54 - 0
src/map/script.cpp

@@ -27340,6 +27340,56 @@ BUILDIN_FUNC(setdialogpospercent){
 	return SCRIPT_CMD_SUCCESS;
 }
 
+/**
+ * Checks if the character has that permission.
+ * permission_check(<permission>{,<char_id>}) -> <bool>
+ */
+BUILDIN_FUNC(permission_check)
+{
+	map_session_data* sd = nullptr;
+
+	if (!script_charid2sd(3, sd))
+		return SCRIPT_CMD_FAILURE;
+
+	int permission = script_getnum(st, 2);
+
+	if (permission < PC_PERM_TRADE || permission >= PC_PERM_MAX) {
+		ShowError("buildin_permission_check: Invalid permission %d\n", permission);
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	script_pushint(st, pc_has_permission(sd, static_cast<e_pc_permission>(permission)));
+
+	return SCRIPT_CMD_SUCCESS;
+}
+
+/**
+ * Adds or removes a permission from the character
+ * permission_add(<permission>{,<char_id>})
+ * permission_remove(<permission>{,<char_id>})
+ */
+BUILDIN_FUNC(permission_add)
+{
+	map_session_data* sd = nullptr;
+
+	if (!script_charid2sd(3, sd))
+		return SCRIPT_CMD_FAILURE;
+
+	int permission = script_getnum(st, 2);
+
+	if (permission < PC_PERM_TRADE || permission >= PC_PERM_MAX) {
+		ShowError("buildin_permission_check: Invalid permission %d\n", permission);
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	if (strcmp(script_getfuncname(st), "permission_add") == 0)
+		sd->permissions.set(static_cast<e_pc_permission>(permission)); // Adds permission
+	else
+		sd->permissions.reset(static_cast<e_pc_permission>(permission)); // Removes permission
+
+	return SCRIPT_CMD_SUCCESS;
+}
+
 #include <custom/script.inc>
 
 // declarations that were supposed to be exported from npc_chat.cpp
@@ -28105,6 +28155,10 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(setdialogpos, "ii"),
 	BUILDIN_DEF(setdialogpospercent, "ii"),
 
+	BUILDIN_DEF(permission_check, "i?"),
+	BUILDIN_DEF(permission_add, "i?"),
+	BUILDIN_DEF2(permission_add, "permission_remove", "i?"),
+
 #include <custom/script_def.inc>
 
 	{nullptr,nullptr,nullptr},

+ 34 - 0
src/map/script_constants.hpp

@@ -10581,6 +10581,40 @@
 	export_constant(SKILLDMG_MAX);
 	export_constant(SKILLDMG_CASTER);
 
+	/* player permissions */
+	export_constant(PC_PERM_TRADE);
+	export_constant(PC_PERM_PARTY);
+	export_constant(PC_PERM_ALL_SKILL);
+	export_constant(PC_PERM_USE_ALL_EQUIPMENT);
+	export_constant(PC_PERM_SKILL_UNCONDITIONAL);
+	export_constant(PC_PERM_JOIN_ALL_CHAT);
+	export_constant(PC_PERM_NO_CHAT_KICK);
+	export_constant(PC_PERM_HIDE_SESSION);
+	export_constant(PC_PERM_WHO_DISPLAY_AID);
+	export_constant(PC_PERM_RECEIVE_HACK_INFO);
+	export_constant(PC_PERM_WARP_ANYWHERE);
+	export_constant(PC_PERM_VIEW_HPMETER);
+	export_constant(PC_PERM_VIEW_EQUIPMENT);
+	export_constant(PC_PERM_USE_CHECK);
+	export_constant(PC_PERM_USE_CHANGEMAPTYPE);
+	export_constant(PC_PERM_USE_ALL_COMMANDS);
+	export_constant(PC_PERM_RECEIVE_REQUESTS);
+	export_constant(PC_PERM_SHOW_BOSS);
+	export_constant(PC_PERM_DISABLE_PVM);
+	export_constant(PC_PERM_DISABLE_PVP);
+	export_constant(PC_PERM_DISABLE_CMD_DEAD);
+	export_constant(PC_PERM_CHANNEL_ADMIN);
+	export_constant(PC_PERM_TRADE_BOUNDED);
+	export_constant(PC_PERM_ITEM_UNCONDITIONAL);
+	export_constant(PC_PERM_ENABLE_COMMAND);
+	export_constant(PC_PERM_BYPASS_STAT_ONCLONE);
+	export_constant(PC_PERM_BYPASS_MAX_STAT);
+	export_constant(PC_PERM_ATTENDANCE);
+	export_constant(PC_PERM_MACRO_DETECT);
+	export_constant(PC_PERM_MACRO_REGISTER);
+	export_constant(PC_PERM_TRADE_UNCONDITIONAL);
+	export_constant(PC_PERM_MAX);
+
 	/* guild permissions */
 	export_constant(GUILD_PERM_INVITE);
 	export_constant(GUILD_PERM_EXPEL);