diff options
author | Piotr HaĆaczkiewicz <piotr.halaczkiewicz@gmail.com> | 2013-07-24 12:41:50 +0200 |
---|---|---|
committer | Piotr HaĆaczkiewicz <piotr.halaczkiewicz@gmail.com> | 2013-07-29 21:51:08 +0200 |
commit | e7750ecfff5bf856ecc9f38ea327c6b6cc535761 (patch) | |
tree | 163859983acdced47483f0d4fb480377da5b5be2 /src/map/script.c | |
parent | 640c66779d8da4baa8af6bd0fee2583ec2b6143c (diff) | |
download | hercules-e7750ecfff5bf856ecc9f38ea327c6b6cc535761.tar.gz hercules-e7750ecfff5bf856ecc9f38ea327c6b6cc535761.tar.bz2 hercules-e7750ecfff5bf856ecc9f38ea327c6b6cc535761.tar.xz hercules-e7750ecfff5bf856ecc9f38ea327c6b6cc535761.zip |
Permission cache overhaul
* Reworked group permission caching in session data (follow-up to cd45c30ab2dcc44bfbfac283d15bb09b3d4644bc)
* Removed duplicated information from session data in favor of direct pointer to group settings.
* Added getters for all group data required to process permissions and related stuff.
* Added new functions to PC interface and updated calls everywhere.
* Extracted function to set new group for a player (used at login, group config reload, manual adjustment of group).
* Moved command permission config parsing to atcommand module.
* Improved dummy map session handling.
* Since it's required for all map sessions to have a valid group, dummy sessions are now created by a designated function.
* Updated related code that uses dummy sessions (console `gm use` and script `atcommand`, `useatcmd`).
* Various minor improvements and cleanups.
* Eliminated some global variables related to loading atcommand permissions for group by passing them directly to function.
* Moved definition of global array holding PC permission names from header file to source file.
* Streamlined destuction of atcommands database to use DBApply helper function instead of DBIterator.
* Replaced hardcoded position of console dummy session with defines from mapindex.h (thx Haruna for pointing it out).
* Removed fixed length restriction on group names.
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/map/script.c b/src/map/script.c index 2a917236a..336ab7b9f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -9287,7 +9287,7 @@ BUILDIN(getusersname) iter = mapit_getallusers(); for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { - if (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc->get_group_level(pl_sd) > group_level) + if (pc->has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc->get_group_level(pl_sd) > group_level) continue; // skip hidden sessions /* Temporary fix for bugreport:1023. @@ -12280,10 +12280,10 @@ BUILDIN(nude) *------------------------------------------*/ BUILDIN(atcommand) { - TBL_PC dummy_sd; - TBL_PC* sd; + TBL_PC *sd, *dummy_sd = NULL; int fd; const char* cmd; + bool ret = true; cmd = script_getstr(st,2); @@ -12291,26 +12291,25 @@ BUILDIN(atcommand) sd = script_rid2sd(st); fd = sd->fd; } else { //Use a dummy character. - sd = &dummy_sd; + sd = dummy_sd = pc->get_dummy_sd(); fd = 0; - memset(&dummy_sd, 0, sizeof(TBL_PC)); if (st->oid) { struct block_list* bl = iMap->id2bl(st->oid); - memcpy(&dummy_sd.bl, bl, sizeof(struct block_list)); + memcpy(&sd->bl, bl, sizeof(struct block_list)); if (bl->type == BL_NPC) - safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); + safestrncpy(sd->status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); } } if (!atcommand->parse(fd, sd, cmd, 0)) { ShowWarning("script: buildin_atcommand: failed to execute command '%s'\n", cmd); script_reportsrc(st); - return false; + ret = false; } - - return true; + if (dummy_sd) aFree(dummy_sd); + return ret; } /*========================================== @@ -16849,8 +16848,7 @@ BUILDIN(unbindatcmd) { BUILDIN(useatcmd) { - TBL_PC dummy_sd; - TBL_PC* sd; + TBL_PC *sd, *dummy_sd = NULL; int fd; const char* cmd; @@ -16863,16 +16861,15 @@ BUILDIN(useatcmd) } else { // Use a dummy character. - sd = &dummy_sd; + sd = dummy_sd = pc->get_dummy_sd(); fd = 0; - memset(&dummy_sd, 0, sizeof(TBL_PC)); if( st->oid ) { struct block_list* bl = iMap->id2bl(st->oid); - memcpy(&dummy_sd.bl, bl, sizeof(struct block_list)); + memcpy(&sd->bl, bl, sizeof(struct block_list)); if( bl->type == BL_NPC ) - safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); + safestrncpy(sd->status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); } } @@ -16884,6 +16881,7 @@ BUILDIN(useatcmd) } atcommand->parse(fd, sd, cmd, 1); + if (dummy_sd) aFree(dummy_sd); return true; } |