Skip to content

Commit

Permalink
Added player permission script commands (rathena#8450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daegaladh authored Jun 21, 2024
1 parent d344caa commit 5123704
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 33 deletions.
68 changes: 37 additions & 31 deletions doc/permissions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -46,86 +52,86 @@ 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,
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).

Expand All @@ -136,96 +142,96 @@ 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,
@mapmove, @go, @jump, etc.).

---------------------------------------

*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).

Expand Down
44 changes: 42 additions & 2 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>.

Expand All @@ -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.|
==================================
Expand Down
54 changes: 54 additions & 0 deletions src/map/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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},
Expand Down
Loading

0 comments on commit 5123704

Please sign in to comment.