diff options
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r-- | src/map/atcommand.c | 2109 |
1 files changed, 1423 insertions, 686 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 3da5c203f..3fe6c8581 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2016 Hercules Dev Team - * Copyright (C) Athena Dev Teams + * Copyright (C) 2012-2020 Hercules Dev Team + * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ #include "map/channel.h" #include "map/chat.h" #include "map/chrif.h" +#include "map/clan.h" #include "map/clif.h" #include "map/duel.h" #include "map/elemental.h" @@ -47,6 +48,7 @@ #include "map/pc_groups.h" // groupid2name #include "map/pet.h" #include "map/quest.h" +#include "map/refine.h" #include "map/script.h" #include "map/searchstore.h" #include "map/skill.h" @@ -54,12 +56,14 @@ #include "map/storage.h" #include "map/trade.h" #include "map/unit.h" +#include "map/achievement.h" #include "common/cbasetypes.h" #include "common/conf.h" #include "common/core.h" #include "common/memmgr.h" #include "common/mmo.h" // MAX_CARTS #include "common/nullpo.h" +#include "common/packets.h" #include "common/random.h" #include "common/showmsg.h" #include "common/socket.h" @@ -73,14 +77,15 @@ #include <stdlib.h> #include <string.h> -struct atcommand_interface atcommand_s; +static struct atcommand_interface atcommand_s; struct atcommand_interface *atcommand; static char atcmd_output[CHAT_SIZE_MAX]; static char atcmd_player_name[NAME_LENGTH]; // @commands (script-based) -struct atcmd_binding_data* get_atcommandbind_byname(const char* name) { +static struct atcmd_binding_data *get_atcommandbind_byname(const char *name) +{ int i = 0; nullpo_retr(NULL, name); @@ -92,14 +97,16 @@ struct atcmd_binding_data* get_atcommandbind_byname(const char* name) { return ( i < atcommand->binding_count ) ? atcommand->binding[i] : NULL; } -const char* atcommand_msgsd(struct map_session_data *sd, int msg_number) { +static const char *atcommand_msgsd(struct map_session_data *sd, int msg_number) +{ Assert_retr("??", msg_number >= 0 && msg_number < MAX_MSG && atcommand->msg_table[0][msg_number] != NULL); if (!sd || sd->lang_id >= atcommand->max_message_table || !atcommand->msg_table[sd->lang_id][msg_number]) return atcommand->msg_table[0][msg_number]; return atcommand->msg_table[sd->lang_id][msg_number]; } -const char* atcommand_msgfd(int fd, int msg_number) { +static const char *atcommand_msgfd(int fd, int msg_number) +{ struct map_session_data *sd = sockt->session_is_valid(fd) ? sockt->session[fd]->session_data : NULL; Assert_retr("??", msg_number >= 0 && msg_number < MAX_MSG && atcommand->msg_table[0][msg_number] != NULL); if (!sd || sd->lang_id >= atcommand->max_message_table || !atcommand->msg_table[sd->lang_id][msg_number]) @@ -110,7 +117,8 @@ const char* atcommand_msgfd(int fd, int msg_number) { //----------------------------------------------------------- // Return the message string of the specified number by [Yor] //----------------------------------------------------------- -const char* atcommand_msg(int msg_number) { +static const char *atcommand_msg(int msg_number) +{ Assert_retr("??", msg_number >= 0 && msg_number < MAX_MSG); if (atcommand->msg_table[map->default_lang_id][msg_number] != NULL && atcommand->msg_table[map->default_lang_id][msg_number][0] != '\0') return atcommand->msg_table[map->default_lang_id][msg_number]; @@ -128,11 +136,11 @@ const char* atcommand_msg(int msg_number) { * @param[in] allow_override whether to allow duplicate message IDs to override the original value. * @return success state. */ -bool msg_config_read(const char *cfg_name, bool allow_override) { +static bool msg_config_read(const char *cfg_name, bool allow_override) +{ int msg_number; char line[1024], w1[1024], w2[1024]; FILE *fp; - static int called = 1; nullpo_retr(false, cfg_name); if ((fp = fopen(cfg_name, "r")) == NULL) { @@ -170,28 +178,14 @@ bool msg_config_read(const char *cfg_name, bool allow_override) { } fclose(fp); - if( ++called == 1 ) { //Original - if( script->lang_export_fp ) { - int i; - for(i = 0; i < MAX_MSG;i++) { - if( atcommand->msg_table[0][i] != NULL ) { - fprintf(script->lang_export_fp, "msgctxt \"messages.conf\"\n" - "msgid \"%s\"\n" - "msgstr \"\"\n", - atcommand->msg_table[0][i] - ); - } - } - } - } - return true; } /*========================================== * Cleanup Message Data *------------------------------------------*/ -void do_final_msg(void) { +static void do_final_msg(void) +{ int i, j; for(i = 0; i < atcommand->max_message_table; i++) { @@ -209,7 +203,8 @@ void do_final_msg(void) { /** * retrieves the help string associated with a given command. */ -static inline const char* atcommand_help_string(AtCommandInfo *info) { +static inline const char *atcommand_help_string(AtCommandInfo *info) +{ return info->help; } @@ -266,22 +261,25 @@ ACMD(send) clif->message(fd, atcmd_output); return false; } - + if (len) { // show packet length - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,904), type, clif->packet(type)->len); // Packet 0x%x length: %d + Assert_retr(false, type <= MAX_PACKET_DB && type >= MIN_PACKET_DB); + len = packets->db[type]; + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,904), type, len); // Packet 0x%x length: %d clif->message(fd, atcmd_output); return true; } - - len = clif->packet(type)->len; - + + Assert_retr(false, type <= MAX_PACKET_DB && type >= MIN_PACKET_DB); + len = packets->db[type]; + if (len == -1) { // dynamic packet len = SHRT_MAX-4; // maximum length off = 4; } - + WFIFOHEAD(sd->fd, len); WFIFOW(sd->fd,0)=TOW(type); @@ -422,7 +420,7 @@ ACMD(send) SKIP_VALUE(message); } - if (clif->packet(type)->len == -1) { // send dynamic packet + if (packets->db[type] == -1) { // send dynamic packet WFIFOW(sd->fd,2)=TOW(off); WFIFOSET(sd->fd,off); } else {// send static packet @@ -446,7 +444,8 @@ ACMD(send) /*========================================== * @rura, @warp, @mapmove *------------------------------------------*/ -ACMD(mapmove) { +ACMD(mapmove) +{ char map_name[MAP_NAME_LENGTH_EXT]; unsigned short map_index; short x = 0, y = 0; @@ -482,11 +481,11 @@ ACMD(mapmove) { x = y = 0; //Invalid cell, use random spot. } if (map->list[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) { - clif->message(fd, msg_fd(fd,247)); + clif->message(fd, msg_fd(fd,247)); // You are not authorized to warp to this map. return false; } if (sd->bl.m >= 0 && map->list[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) { - clif->message(fd, msg_fd(fd,248)); + clif->message(fd, msg_fd(fd,248)); // You are not authorized to warp from your current map. return false; } if (pc->setpos(sd, map_index, x, y, CLR_TELEPORT) != 0) { @@ -501,7 +500,8 @@ ACMD(mapmove) { /*========================================== * Displays where a character is. Corrected version by Silent. [Skotlex] *------------------------------------------*/ -ACMD(where) { +ACMD(where) +{ struct map_session_data* pl_sd; memset(atcmd_player_name, '\0', sizeof atcmd_player_name); @@ -511,7 +511,7 @@ ACMD(where) { return false; } - pl_sd = map->nick2sd(atcmd_player_name); + pl_sd = map->nick2sd(atcmd_player_name, true); if (pl_sd == NULL || strncmp(pl_sd->status.name, atcmd_player_name, NAME_LENGTH) != 0 || (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > pc_get_group_level(sd) && !pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID)) @@ -529,7 +529,8 @@ ACMD(where) { /*========================================== * *------------------------------------------*/ -ACMD(jumpto) { +ACMD(jumpto) +{ struct map_session_data *pl_sd = NULL; if (!*message) { @@ -547,7 +548,7 @@ ACMD(jumpto) { return false; } - if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message, true)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -612,7 +613,8 @@ ACMD(jump) * Display list of online characters with * various info. *------------------------------------------*/ -ACMD(who) { +ACMD(who) +{ const struct map_session_data *pl_sd = NULL; struct s_mapiterator *iter = NULL; char player_name[NAME_LENGTH] = ""; @@ -655,7 +657,7 @@ ACMD(who) { if (pc_get_group_id(pl_sd) > 0) // Player title, if exists StrBuf->Printf(&buf, msg_fd(fd,344), pcg->get_name(pl_sd->group)); // "(%s) " StrBuf->Printf(&buf, msg_fd(fd,347), pl_sd->status.base_level, pl_sd->status.job_level, - pc->job_name(pl_sd->status.class_)); // "| Lv:%d/%d | Job: %s" + pc->job_name(pl_sd->status.class)); // "| Lv:%d/%d | Job: %s" break; } case 3: { @@ -764,7 +766,7 @@ ACMD(whogm) safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,915), // BLvl: %d | Job: %s (Lvl: %d) pl_sd->status.base_level, - pc->job_name(pl_sd->status.class_), pl_sd->status.job_level); + pc->job_name(pl_sd->status.class), pl_sd->status.job_level); clif->message(fd, atcmd_output); p = party->search(pl_sd->status.party_id); @@ -809,7 +811,8 @@ ACMD(save) /*========================================== * *------------------------------------------*/ -ACMD(load) { +ACMD(load) +{ int16 m; m = map->mapindex2mapid(sd->status.save_point.map); @@ -866,11 +869,16 @@ ACMD(speed) *------------------------------------------*/ ACMD(storage) { - if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag) + if (sd->npc_id || sd->state.vending || sd->state.prevend || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag) + return false; + + if (!pc_has_permission(sd, PC_PERM_BYPASS_NOSTORAGE) && (map->list[sd->bl.m].flag.nostorage & 1)) { // mapflag nostorage already defined? can't open :c + clif->message(fd, msg_fd(fd, 1161)); // You currently cannot open your storage. return false; + } if (storage->open(sd) == 1) { //Already open. - clif->message(fd, msg_fd(fd,250)); + clif->message(fd, msg_fd(fd,250)); // You have already opened your storage. Close it first. return false; } @@ -885,20 +893,25 @@ ACMD(storage) ACMD(guildstorage) { if (!sd->status.guild_id) { - clif->message(fd, msg_fd(fd,252)); + clif->message(fd, msg_fd(fd,252)); // You are not in a guild. return false; } - if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading) + if (sd->npc_id || sd->state.vending || sd->state.prevend || sd->state.buyingstore || sd->state.trading) return false; if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { - clif->message(fd, msg_fd(fd,250)); + clif->message(fd, msg_fd(fd,250)); // You have already opened your storage. Close it first. return false; } if (sd->state.storage_flag == STORAGE_FLAG_GUILD) { - clif->message(fd, msg_fd(fd,251)); + clif->message(fd, msg_fd(fd,251)); // You have already opened your guild storage. Close it first. + return false; + } + + if (!pc_has_permission(sd, PC_PERM_BYPASS_NOSTORAGE) && (map->list[sd->bl.m].flag.nogstorage & 1)) { // mapflag nogstorage already defined? can't open :c + clif->message(fd, msg_fd(fd, 1161)); // You currently cannot open your storage. (there is no other messages...) return false; } @@ -947,39 +960,12 @@ ACMD(option) /*========================================== * *------------------------------------------*/ -ACMD(hide) { - if (pc_isinvisible(sd)) { - sd->sc.option &= ~OPTION_INVISIBLE; - if (sd->disguise != -1 ) - status->set_viewdata(&sd->bl, sd->disguise); - else - status->set_viewdata(&sd->bl, sd->status.class_); - clif->message(fd, msg_fd(fd,10)); // Invisible: Off - - // increment the number of pvp players on the map - map->list[sd->bl.m].users_pvp++; - - if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank ) { - // register the player for ranking calculations - sd->pvp_timer = timer->add( timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0 ); - } - //bugreport:2266 - map->foreachinmovearea(clif->insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl); - } else { - sd->sc.option |= OPTION_INVISIBLE; - sd->vd.class_ = INVISIBLE_CLASS; - clif->message(fd, msg_fd(fd,11)); // Invisible: On - - // decrement the number of pvp players on the map - map->list[sd->bl.m].users_pvp--; - - if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER ) { - // unregister the player for ranking - timer->delete( sd->pvp_timer, pc->calc_pvprank_timer ); - sd->pvp_timer = INVALID_TIMER; - } - } - clif->changeoption(&sd->bl); +ACMD(hide) +{ + if (pc_isinvisible(sd)) + pc->unhide(sd, true); + else + pc->hide(sd, true); return true; } @@ -1091,9 +1077,11 @@ ACMD(kami) sscanf(message, "%199[^\n]", atcmd_output); if (stristr(info->command, "l") != NULL) - clif->broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, BC_DEFAULT, ALL_SAMEMAP); + clif->broadcast(&sd->bl, atcmd_output, (int)strlen(atcmd_output) + 1, BC_DEFAULT, ALL_SAMEMAP); + else if (info->command[4] == 'b' || info->command[4] == 'B') + clif->broadcast(NULL, atcmd_output, (int)strlen(atcmd_output) + 1, BC_BLUE, ALL_CLIENT); else - intif->broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(info->command + 4) == 'b' || *(info->command + 4) == 'B') ? BC_BLUE : BC_YELLOW); + clif->broadcast(NULL, atcmd_output, (int)strlen(atcmd_output) + 1, BC_YELLOW, ALL_CLIENT); } else { if(!*message || (sscanf(message, "%10u %199[^\n]", &color, atcmd_output) < 2)) { clif->message(fd, msg_fd(fd,981)); // Please enter color and message (usage: @kamic <color> <message>). @@ -1104,7 +1092,7 @@ ACMD(kami) clif->message(fd, msg_fd(fd,982)); // Invalid color. return false; } - intif->broadcast2(atcmd_output, strlen(atcmd_output) + 1, color, 0x190, 12, 0, 0); + clif->broadcast2(NULL, atcmd_output, (int)strlen(atcmd_output) + 1, color, 0x190, 12, 0, 0, ALL_CLIENT); } return true; } @@ -1131,7 +1119,7 @@ ACMD(heal) } if ( hp > 0 && sp >= 0 ) { - if(!status->heal(&sd->bl, hp, sp, 0)) + if (status->heal(&sd->bl, hp, sp, STATUS_HEAL_DEFAULT) == 0) clif->message(fd, msg_fd(fd,157)); // HP and SP are already with the good value. else clif->message(fd, msg_fd(fd,17)); // HP, SP recovered. @@ -1148,7 +1136,7 @@ ACMD(heal) //Opposing signs. if ( hp ) { if (hp > 0) - status->heal(&sd->bl, hp, 0, 0); + status->heal(&sd->bl, hp, 0, STATUS_HEAL_DEFAULT); else { status->damage(NULL, &sd->bl, -hp, 0, 0, 0); clif->damage(&sd->bl,&sd->bl, 0, 0, -hp, 0, BDT_ENDURE, 0); @@ -1157,7 +1145,7 @@ ACMD(heal) if ( sp ) { if (sp > 0) - status->heal(&sd->bl, 0, sp, 0); + status->heal(&sd->bl, 0, sp, STATUS_HEAL_DEFAULT); else status->damage(NULL, &sd->bl, 0, -sp, 0, 0); } @@ -1266,20 +1254,20 @@ ACMD(item2) struct item_data *item_data; char item_name[100]; int item_id, number = 0, bound = 0; - int identify = 0, refine = 0, attr = 0; + int identify = 0, refine_level = 0, attr = 0; int c1 = 0, c2 = 0, c3 = 0, c4 = 0; memset(item_name, '\0', sizeof(item_name)); if (!strcmpi(info->command,"itembound2") && (!*message || ( - sscanf(message, "\"%99[^\"]\" %12d %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 && - sscanf(message, "%99s %12d %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 ))) { + sscanf(message, "\"%99[^\"]\" %12d %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine_level, &attr, &c1, &c2, &c3, &c4, &bound) < 10 && + sscanf(message, "%99s %12d %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine_level, &attr, &c1, &c2, &c3, &c4, &bound) < 10 ))) { clif->message(fd, msg_fd(fd,296)); // Please enter all parameters (usage: @itembound2 <item name/ID> <quantity> clif->message(fd, msg_fd(fd,297)); // <identify_flag> <refine> <attribute> <card1> <card2> <card3> <card4> <bound_type>). return false; } else if (!*message - || ( sscanf(message, "\"%99[^\"]\" %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 - && sscanf(message, "%99s %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 + || ( sscanf(message, "\"%99[^\"]\" %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine_level, &attr, &c1, &c2, &c3, &c4) < 9 + && sscanf(message, "%99s %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine_level, &attr, &c1, &c2, &c3, &c4) < 9 )) { clif->message(fd, msg_fd(fd,984)); // Please enter all parameters (usage: @item2 <item name/ID> <quantity> clif->message(fd, msg_fd(fd,985)); // <identify_flag> <refine> <attribute> <card1> <card2> <card3> <card4>). @@ -1315,20 +1303,20 @@ ACMD(item2) get_count = 1; if (item_data->type == IT_PETEGG) { identify = 1; - refine = 0; + refine_level = 0; } if (item_data->type == IT_PETARMOR) - refine = 0; + refine_level = 0; } else { identify = 1; - refine = attr = 0; + refine_level = attr = 0; } - refine = cap_value(refine, 0, MAX_REFINE); + refine_level = cap_value(refine_level, 0, MAX_REFINE); for (i = 0; i < loop; i++) { memset(&item_tmp, 0, sizeof(item_tmp)); item_tmp.nameid = item_id; item_tmp.identify = identify; - item_tmp.refine = refine; + item_tmp.refine = refine_level; item_tmp.attribute = attr; item_tmp.bound = (unsigned char)bound; item_tmp.card[0] = c1; @@ -1355,9 +1343,7 @@ ACMD(item2) *------------------------------------------*/ ACMD(itemreset) { - int i; - - for (i = 0; i < MAX_INVENTORY; i++) { + for (int i = 0; i < sd->status.inventorySize; i++) { if (sd->status.inventory[i].amount && sd->status.inventory[i].equip == 0) { pc->delitem(sd, i, sd->status.inventory[i].amount, 0, DELITEM_NORMAL, LOG_TYPE_COMMAND); } @@ -1384,13 +1370,13 @@ ACMD(baselevelup) clif->message(fd, msg_fd(fd,47)); // Base level can't go any higher. return false; } // End Addition - if ((unsigned int)level > pc->maxbaselv(sd) || (unsigned int)level > pc->maxbaselv(sd) - sd->status.base_level) // fix positive overflow + if (level > pc->maxbaselv(sd) || level > pc->maxbaselv(sd) - sd->status.base_level) // fix positive overflow level = pc->maxbaselv(sd) - sd->status.base_level; for (i = 0; i < level; i++) status_point += pc->gets_status_point(sd->status.base_level + i); sd->status.status_point += status_point; - sd->status.base_level += (unsigned int)level; + sd->status.base_level += level; status_calc_pc(sd, SCO_FORCE); status_percent_heal(&sd->bl, 100, 100); clif->misceffect(&sd->bl, 0); @@ -1401,7 +1387,7 @@ ACMD(baselevelup) return false; } level*=-1; - if ((unsigned int)level >= sd->status.base_level) + if (level >= sd->status.base_level) level = sd->status.base_level-1; for (i = 0; i > -level; i--) status_point += pc->gets_status_point(sd->status.base_level + i - 1); @@ -1411,9 +1397,10 @@ ACMD(baselevelup) sd->status.status_point = 0; else sd->status.status_point -= status_point; - sd->status.base_level -= (unsigned int)level; + sd->status.base_level -= level; clif->message(fd, msg_fd(fd,22)); // Base level lowered. status_calc_pc(sd, SCO_FORCE); + level *= -1; } sd->status.base_exp = 0; clif->updatestatus(sd, SP_STATUSPOINT); @@ -1421,8 +1408,16 @@ ACMD(baselevelup) clif->updatestatus(sd, SP_BASEEXP); clif->updatestatus(sd, SP_NEXTBASEEXP); pc->baselevelchanged(sd); + + // achievements + achievement->validate_stats(sd, SP_BASELEVEL, sd->status.base_level); + if(sd->status.party_id) party->send_levelup(sd); + + if (level > 0 && battle_config.atcommand_levelup_events) + npc->script_event(sd, NPCE_BASELVUP); // Trigger OnPCBaseLvUpEvent + return true; } @@ -1442,9 +1437,9 @@ ACMD(joblevelup) clif->message(fd, msg_fd(fd,23)); // Job level can't go any higher. return false; } - if ((unsigned int)level > pc->maxjoblv(sd) || (unsigned int)level > pc->maxjoblv(sd) - sd->status.job_level) // fix positive overflow + if (level > pc->maxjoblv(sd) || level > pc->maxjoblv(sd) - sd->status.job_level) // fix positive overflow level = pc->maxjoblv(sd) - sd->status.job_level; - sd->status.job_level += (unsigned int)level; + sd->status.job_level += level; sd->status.skill_point += level; clif->misceffect(&sd->bl, 1); clif->message(fd, msg_fd(fd,24)); // Job level raised. @@ -1454,9 +1449,9 @@ ACMD(joblevelup) return false; } level *=-1; - if ((unsigned int)level >= sd->status.job_level) // fix negative overflow + if (level >= sd->status.job_level) // fix negative overflow level = sd->status.job_level-1; - sd->status.job_level -= (unsigned int)level; + sd->status.job_level -= level; if (sd->status.skill_point < level) pc->resetskill(sd, PCRESETSKILL_NONE); //Reset skills since we need to subtract more points. if (sd->status.skill_point < level) @@ -1464,6 +1459,7 @@ ACMD(joblevelup) else sd->status.skill_point -= level; clif->message(fd, msg_fd(fd,25)); // Job level lowered. + level *= -1; } sd->status.job_exp = 0; clif->updatestatus(sd, SP_JOBLEVEL); @@ -1472,13 +1468,17 @@ ACMD(joblevelup) clif->updatestatus(sd, SP_SKILLPOINT); status_calc_pc(sd, SCO_FORCE); + if (level > 0 && battle_config.atcommand_levelup_events) + npc->script_event(sd, NPCE_JOBLVUP); // Trigger OnPCJobLvUpEvent + return true; } /*========================================== * @help *------------------------------------------*/ -ACMD(help) { +ACMD(help) +{ const char *command_name = NULL; char *default_command = "help"; AtCommandInfo *tinfo = NULL; @@ -1546,7 +1546,7 @@ ACMD(help) { * Arglist parameters: * - (int) id: If 0, stop any attacks. Otherwise, the target block list id to stop attacking. */ -int atcommand_stopattack(struct block_list *bl,va_list ap) +static int atcommand_stopattack(struct block_list *bl, va_list ap) { struct unit_data *ud = NULL; int id = 0; @@ -1565,7 +1565,7 @@ int atcommand_stopattack(struct block_list *bl,va_list ap) /*========================================== * *------------------------------------------*/ -int atcommand_pvpoff_sub(struct block_list *bl,va_list ap) +static int atcommand_pvpoff_sub(struct block_list *bl, va_list ap) { struct map_session_data *sd = NULL; nullpo_ret(bl); @@ -1603,7 +1603,7 @@ ACMD(pvpoff) /*========================================== * *------------------------------------------*/ -int atcommand_pvpon_sub(struct block_list *bl,va_list ap) +static int atcommand_pvpon_sub(struct block_list *bl, va_list ap) { struct map_session_data *sd = NULL; nullpo_ret(bl); @@ -1611,7 +1611,8 @@ int atcommand_pvpon_sub(struct block_list *bl,va_list ap) sd = BL_UCAST(BL_PC, bl); if (sd->pvp_timer == INVALID_TIMER) { - sd->pvp_timer = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0); + if (!map->list[sd->bl.m].flag.pvp_nocalcrank) + sd->pvp_timer = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0); sd->pvp_rank = 0; sd->pvp_lastusers = 0; sd->pvp_point = 5; @@ -1645,7 +1646,8 @@ ACMD(pvpon) /*========================================== * *------------------------------------------*/ -ACMD(gvgoff) { +ACMD(gvgoff) +{ if (!map->list[sd->bl.m].flag.gvg) { clif->message(fd, msg_fd(fd,162)); // GvG is already Off. @@ -1684,6 +1686,45 @@ ACMD(gvgon) /*========================================== * *------------------------------------------*/ +ACMD(cvcoff) +{ + if (!map->list[sd->bl.m].flag.cvc) { + clif->message(fd, msg_fd(fd, 141)); // CvC is already Off. + return false; + } + + map->zone_change2(sd->bl.m, map->list[sd->bl.m].prev_zone); + map->list[sd->bl.m].flag.cvc = 0; + clif->map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING); + clif->maptypeproperty2(&sd->bl, ALL_SAMEMAP); + map->foreachinmap(atcommand->stopattack, sd->bl.m, BL_CHAR, 0); + clif->message(fd, msg_fd(fd, 137)); // CvC: Off. + + return true; +} + +/*========================================== + * + *------------------------------------------*/ +ACMD(cvcon) +{ + if (map->list[sd->bl.m].flag.cvc) { + clif->message(fd, msg_fd(fd, 142)); // CvC is already On. + return false; + } + + map->zone_change2(sd->bl.m, strdb_get(map->zone_db, MAP_ZONE_CVC_NAME)); + map->list[sd->bl.m].flag.cvc = 1; + clif->map_property_mapall(sd->bl.m, MAPPROPERTY_AGITZONE); + clif->maptypeproperty2(&sd->bl, ALL_SAMEMAP); + clif->message(fd, msg_fd(fd, 138)); // CvC: On. + + return true; +} + +/*========================================== + * + *------------------------------------------*/ ACMD(model) { int hair_style = 0, hair_color = 0, cloth_color = 0; @@ -1721,7 +1762,12 @@ ACMD(bodystyle) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!*message || sscanf(message, "%d", &body_style) < 1) { + if (!pc->has_second_costume(sd)) { + clif->message(fd, msg_fd(fd, 35)); // This job has no alternate body styles. + return false; + } + + if (*message == '\0' || sscanf(message, "%d", &body_style) < 1) { sprintf(atcmd_output, "Please, enter a body style (usage: @bodystyle <body ID: %d-%d>).", MIN_BODY_STYLE, MAX_BODY_STYLE); clif->message(fd, atcmd_output); return false; @@ -1729,9 +1775,9 @@ ACMD(bodystyle) if (body_style >= MIN_BODY_STYLE && body_style <= MAX_BODY_STYLE) { pc->changelook(sd, LOOK_BODY2, body_style); - clif->message(fd, msg_txt(36)); // Appearence changed. + clif->message(fd, msg_fd(fd, 36)); // Appearence changed. } else { - clif->message(fd, msg_txt(37)); // An invalid number was specified. + clif->message(fd, msg_fd(fd, 37)); // An invalid number was specified. return false; } @@ -1816,10 +1862,68 @@ ACMD(hair_color) return true; } +ACMD(setzone) +{ + char zone_name[MAP_ZONE_MAPFLAG_LENGTH]; + memset(zone_name, '\0', sizeof(zone_name)); + + char fmt_str[8] = ""; + safesnprintf(fmt_str, 8, "%%%ds", MAP_ZONE_MAPFLAG_LENGTH - 1); + + if (*message == '\0' || sscanf(message, fmt_str, zone_name) < 1) { + clif->message(fd, msg_fd(fd, 924)); // usage info + return false; + } + + struct map_zone_data *zone = strdb_get(map->zone_db, zone_name); + const char *prev_zone_name = map->list[sd->bl.m].zone->name; + + // handle special zones: + if (zone == NULL && strcmp(zone_name, MAP_ZONE_NORMAL_NAME) == 0) { + zone = &map->zone_all; + } else if (zone == NULL && strcmp(zone_name, MAP_ZONE_PK_NAME) == 0) { + zone = &map->zone_pk; + } + + if (zone != NULL) { + if (map->list[sd->bl.m].zone != zone) { + if (strcmp(prev_zone_name, MAP_ZONE_PVP_NAME) == 0) { + atcommand_pvpoff(fd, sd, command, message, info); + } else if (strcmp(prev_zone_name, MAP_ZONE_GVG_NAME) == 0) { + atcommand_gvgoff(fd, sd, command, message, info); + } else if (strcmp(prev_zone_name, MAP_ZONE_CVC_NAME) == 0) { + atcommand_cvcoff(fd, sd, command, message, info); + } + } else { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 925), zone_name); + clif->message(fd, atcmd_output); // nothing to do + return false; + } + + if (strcmp(zone_name, MAP_ZONE_PVP_NAME) == 0) { + atcommand_pvpon(fd, sd, command, message, info); + } else if (strcmp(zone_name, MAP_ZONE_GVG_NAME) == 0) { + atcommand_gvgon(fd, sd, command, message, info); + } else if (strcmp(zone_name, MAP_ZONE_CVC_NAME) == 0) { + atcommand_cvcon(fd, sd, command, message, info); + } else { + map->zone_change2(sd->bl.m, zone); + } + } else { + clif->message(fd, msg_fd(fd, 926)); // zone not found + return false; + } + + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 927), prev_zone_name, zone_name); + clif->message(fd, atcmd_output); // changed successfully + return true; +} + /*========================================== * @go [city_number or city_name] - Updated by Harbin *------------------------------------------*/ -ACMD(go) { +ACMD(go) +{ int town = INT_MAX; // Initialized to INT_MAX instead of -1 to avoid conflicts with those who map [-3:-1] to @memo locations. char map_name[MAP_NAME_LENGTH]; @@ -2006,7 +2110,7 @@ ACMD(monster) number = 1; if (!name[0]) - strcpy(name, "--ja--"); + strcpy(name, DEFAULT_MOB_JNAME); // If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive if (battle_config.atc_spawn_quantity_limit && number > battle_config.atc_spawn_quantity_limit) @@ -2049,7 +2153,7 @@ ACMD(monster) /*========================================== * *------------------------------------------*/ -int atkillmonster_sub(struct block_list *bl, va_list ap) +static int atkillmonster_sub(struct block_list *bl, va_list ap) { struct mob_data *md = NULL; int flag = va_arg(ap, int); @@ -2067,7 +2171,8 @@ int atkillmonster_sub(struct block_list *bl, va_list ap) return 1; } -ACMD(killmonster) { +ACMD(killmonster) +{ int map_id, drop_flag; char map_name[MAP_NAME_LENGTH_EXT]; @@ -2094,59 +2199,100 @@ ACMD(killmonster) { *------------------------------------------*/ ACMD(refine) { - int j, position = 0, refine = 0, current_position, final_refine; + int j, position = 0, refine_level = 0, current_position, final_refine; int count; memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!*message || sscanf(message, "%12d %12d", &position, &refine) < 2) { - clif->message(fd, msg_fd(fd,996)); // Please enter a position and an amount (usage: @refine <equip position> <+/- amount>). - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,997), EQP_HEAD_LOW); // %d: Lower Headgear + if (!*message || sscanf(message, "%12d %12d", &position, &refine_level) < 2) { + clif->message(fd, msg_fd(fd, 996)); // Please enter a position and an amount (usage: @refine <equip position> <+/- amount>). +#if PACKETVER > 20100707 + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1515), -3); // %d: Refine All Equip (Shadow) + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1514), -2); // %d: Refine All Equip (Costume) + clif->message(fd, atcmd_output); +#endif + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1513), -1); // %d: Refine All Equip (General) + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 997), EQP_HEAD_LOW); // %d: Headgear (Low) + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 998), EQP_HAND_R); // Hand (Right) + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 999), EQP_GARMENT); // %d: Garment + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1000), EQP_ACC_L); // Accessory (Left) + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1001), EQP_ARMOR); // %d: Body Armor + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1002), EQP_HAND_L); // Hand (Left) + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1003), EQP_SHOES); // %d: Shoes + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1004), EQP_ACC_R); // Accessory (Right) + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1005), EQP_HEAD_TOP); // %d: Headgear (Top) clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,998), EQP_HAND_R); // %d: Right Hand + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1006), EQP_HEAD_MID); // %d: Headgear (Mid) +#if PACKETVER > 20100707 + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1503), EQP_COSTUME_HEAD_TOP); // %d: Costume Headgear (Top) clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,999), EQP_GARMENT); // %d: Garment + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1504), EQP_COSTUME_HEAD_MID); // %d: Costume Headgear (Mid) clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1000), EQP_ACC_L); // %d: Left Accessory + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1505), EQP_COSTUME_HEAD_LOW); // %d: Costume Headgear (Low) clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1001), EQP_ARMOR); // %d: Body Armor + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1506), EQP_COSTUME_GARMENT); // %d: Costume Garment clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1002), EQP_HAND_L); // %d: Left Hand + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1507), EQP_SHADOW_ARMOR); // %d: Shadow Armor clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1003), EQP_SHOES); // %d: Shoes + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1508), EQP_SHADOW_WEAPON); // %d: Shadow Weapon clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1004), EQP_ACC_R); // %d: Right Accessory + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1509), EQP_SHADOW_SHIELD); // %d: Shadow Shield clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1005), EQP_HEAD_TOP); // %d: Top Headgear + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1510), EQP_SHADOW_SHOES); // %d: Shadow Shoes clif->message(fd, atcmd_output); - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1006), EQP_HEAD_MID); // %d: Mid Headgear + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1511), EQP_SHADOW_ACC_R); // %d: Shadow Accessory (Right) + clif->message(fd, atcmd_output); + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1512), EQP_SHADOW_ACC_L); // %d: Shadow Accessory (Left) + clif->message(fd, atcmd_output); +#endif clif->message(fd, atcmd_output); return false; } - refine = cap_value(refine, -MAX_REFINE, MAX_REFINE); + refine_level = cap_value(refine_level, -MAX_REFINE, MAX_REFINE); count = 0; for (j = 0; j < EQI_MAX; j++) { int idx = sd->equip_index[j]; if (idx < 0) continue; - if(j == EQI_AMMO) continue; /* can't equip ammo */ - if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == idx) + if (j == EQI_AMMO) + continue; /* can't equip ammo */ + if (j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == idx) + continue; + if (j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == idx) + continue; + if (j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == idx || sd->equip_index[EQI_HEAD_LOW] == idx)) continue; - if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == idx) + if (j == EQI_COSTUME_MID && sd->equip_index[EQI_COSTUME_LOW] == idx) continue; - if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == idx || sd->equip_index[EQI_HEAD_LOW] == idx)) + if (j == EQI_COSTUME_TOP && (sd->equip_index[EQI_COSTUME_MID] == idx || sd->equip_index[EQI_COSTUME_LOW] == idx)) continue; - if(position && !(sd->status.inventory[idx].equip & position)) + if (position == -3 && !itemdb_is_shadowequip(sd->status.inventory[idx].equip)) + continue; + else if (position == -2 && !itemdb_is_costumeequip(sd->status.inventory[idx].equip)) + continue; + else if (position == -1 && (itemdb_is_costumeequip(sd->status.inventory[idx].equip) || itemdb_is_shadowequip(sd->status.inventory[idx].equip))) + continue; + else if (position && !(sd->status.inventory[idx].equip & position)) continue; - final_refine = cap_value(sd->status.inventory[idx].refine + refine, 0, MAX_REFINE); + final_refine = cap_value(sd->status.inventory[idx].refine + refine_level, 0, MAX_REFINE); if (sd->status.inventory[idx].refine != final_refine) { sd->status.inventory[idx].refine = final_refine; current_position = sd->status.inventory[idx].equip; - pc->unequipitem(sd, idx, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); + pc->unequipitem(sd, idx, PCUNEQUIPITEM_RECALC | PCUNEQUIPITEM_FORCE); clif->refine(fd, 0, idx, sd->status.inventory[idx].refine); clif->delitem(sd, idx, 1, DELITEM_MATERIALCHANGE); clif->additem(sd, idx, 1, 0); @@ -2157,11 +2303,11 @@ ACMD(refine) } if (count == 0) - clif->message(fd, msg_fd(fd,166)); // No item has been refined. + clif->message(fd, msg_fd(fd, 166)); // No item has been refined. else if (count == 1) - clif->message(fd, msg_fd(fd,167)); // 1 item has been refined. + clif->message(fd, msg_fd(fd, 167)); // 1 item has been refined. else { - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,168), count); // %d items have been refined. + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 168), count); // %d items have been refined. clif->message(fd, atcmd_output); } @@ -2264,7 +2410,8 @@ ACMD(memo) /*========================================== * *------------------------------------------*/ -ACMD(gat) { +ACMD(gat) +{ int y; memset(atcmd_output, '\0', sizeof(atcmd_output)); @@ -2301,7 +2448,7 @@ ACMD(displaystatus) if( flag == 0 ) clif->sc_end(&sd->bl,sd->bl.id,AREA,type); else - clif->status_change(&sd->bl, type, flag, tick, val1, val2, val3); + clif->status_change(&sd->bl, type, BL_PC, flag, tick, val1, val2, val3); return true; } @@ -2312,30 +2459,18 @@ ACMD(displaystatus) ACMD(statuspoint) { int point; - unsigned int new_status_point; + int new_status_point; if (!*message || (point = atoi(message)) == 0) { clif->message(fd, msg_fd(fd,1010)); // Please enter a number (usage: @stpoint <number of points>). return false; } - if(point < 0) - { - if(sd->status.status_point < (unsigned int)(-point)) - { - new_status_point = 0; - } - else - { - new_status_point = sd->status.status_point + point; - } - } - else if(UINT_MAX - sd->status.status_point < (unsigned int)point) - { - new_status_point = UINT_MAX; - } - else - { + if (point < 0 && sd->status.status_point + point < 0) { + new_status_point = 0; + } else if (point > 0 && (int64)sd->status.status_point + point > INT_MAX) { + new_status_point = INT_MAX; + } else { new_status_point = sd->status.status_point + point; } @@ -2360,30 +2495,18 @@ ACMD(statuspoint) ACMD(skillpoint) { int point; - unsigned int new_skill_point; + int new_skill_point; if (!*message || (point = atoi(message)) == 0) { clif->message(fd, msg_fd(fd,1011)); // Please enter a number (usage: @skpoint <number of points>). return false; } - if(point < 0) - { - if(sd->status.skill_point < (unsigned int)(-point)) - { - new_skill_point = 0; - } - else - { - new_skill_point = sd->status.skill_point + point; - } - } - else if(UINT_MAX - sd->status.skill_point < (unsigned int)point) - { - new_skill_point = UINT_MAX; - } - else - { + if (point < 0 && sd->status.skill_point + point < 0) { + new_skill_point = 0; + } else if (point > 0 && (int64)sd->status.skill_point + point > INT_MAX) { + new_skill_point = INT_MAX; + } else { new_skill_point = sd->status.skill_point + point; } @@ -2434,7 +2557,8 @@ ACMD(zeny) /*========================================== * *------------------------------------------*/ -ACMD(param) { +ACMD(param) +{ int i, value = 0, new_value, max; const char* param[] = { "str", "agi", "vit", "int", "dex", "luk" }; short* stats[6]; @@ -2480,6 +2604,7 @@ ACMD(param) { clif->updatestatus(sd, SP_USTR + i); status_calc_pc(sd, SCO_FORCE); clif->message(fd, msg_fd(fd,42)); // Stat changed. + achievement->validate_stats(sd, SP_STR + i, new_value); // Achievements [Smokexyz/Hercules] } else { if (value < 0) clif->message(fd, msg_fd(fd,41)); // Unable to decrease the number/value. @@ -2494,7 +2619,8 @@ ACMD(param) { /*========================================== * Stat all by fritz (rewritten by [Yor]) *------------------------------------------*/ -ACMD(stat_all) { +ACMD(stat_all) +{ int index, count, value, max, new_value; short* stats[6]; //we don't use direct initialization because it isn't part of the c standard. @@ -2550,7 +2676,8 @@ ACMD(stat_all) { /*========================================== * *------------------------------------------*/ -ACMD(guildlevelup) { +ACMD(guildlevelup) +{ int level = 0; int16 added_level; struct guild *guild_info; @@ -2588,42 +2715,49 @@ ACMD(guildlevelup) { return true; } -/*========================================== +/** + * Creates a pet egg in the character's inventory. * - *------------------------------------------*/ + * @code{.herc} + * @makeegg <pet> + * @endcode + * + **/ ACMD(makeegg) { - struct item_data *item_data; - int id, pet_id; - - if (!*message) { - clif->message(fd, msg_fd(fd,1015)); // Please enter a monster/egg name/ID (usage: @makeegg <pet>). + if (*message == '\0') { + clif->message(fd, msg_fd(fd, 1015)); // Please enter a monster/egg name/ID (usage: @makeegg <pet>). return false; } - if ((item_data = itemdb->search_name(message)) != NULL) // for egg name + struct item_data *item_data = itemdb->search_name(message); + int id; + + if (item_data != NULL) { // Egg name. id = item_data->nameid; - else - if ((id = mob->db_searchname(message)) != 0) // for monster name - ; - else - id = atoi(message); + } else { + id = mob->db_searchname(message); // Monster name. + + if (id == 0) + id = atoi(message); // Egg/monster ID. + } - pet_id = pet->search_petDB_index(id, PET_CLASS); - if (pet_id < 0) + int pet_id = pet->search_petDB_index(id, PET_CLASS); + + if (pet_id == INDEX_NOT_FOUND) pet_id = pet->search_petDB_index(id, PET_EGG); - if (pet_id >= 0) { - sd->catch_target_class = pet->db[pet_id].class_; - intif->create_pet( - sd->status.account_id, sd->status.char_id, - (short)pet->db[pet_id].class_, (short)mob->db(pet->db[pet_id].class_)->lv, - (short)pet->db[pet_id].EggID, 0, (short)pet->db[pet_id].intimate, - 100, 0, 1, pet->db[pet_id].jname); - } else { - clif->message(fd, msg_fd(fd,180)); // The monster/egg name/id doesn't exist. + + if (pet_id == INDEX_NOT_FOUND) { + clif->message(fd, msg_fd(fd, 180)); // The monster/egg name/ID doesn't exist. return false; } + sd->catch_target_class = pet->db[pet_id].class_; + intif->create_pet(sd->status.account_id, sd->status.char_id, pet->db[pet_id].class_, + mob->db(pet->db[pet_id].class_)->lv, pet->db[pet_id].EggID, 0, + (short)pet->db[pet_id].intimate, PET_HUNGER_STUFFED, + 0, 1,pet->db[pet_id].jname); + return true; } @@ -2642,72 +2776,90 @@ ACMD(hatch) return true; } -/*========================================== +/** + * Sets a pet's intimacy value. * - *------------------------------------------*/ + * @code{.herc} + * @petfriendly <0-1000> + * @endcode + * + **/ ACMD(petfriendly) { - int friendly; - struct pet_data *pd; - - if (!*message || (friendly = atoi(message)) < 0) { - clif->message(fd, msg_fd(fd,1016)); // Please enter a valid value (usage: @petfriendly <0-1000>). + if (*message == '\0' || (atoi(message) == 0 && isdigit(*message) == 0)) { + clif->message(fd, msg_fd(fd, 1016)); // Please enter a valid value (usage: @petfriendly <0-1000>). return false; } - pd = sd->pd; - if (!pd) { - clif->message(fd, msg_fd(fd,184)); // Sorry, but you have no pet. + int friendly = atoi(message); + + if (friendly < PET_INTIMACY_NONE || friendly > PET_INTIMACY_MAX) { + clif->message(fd, msg_fd(fd, 1016)); // Please enter a valid value (usage: @petfriendly <0-1000>). return false; } - if (friendly < 0 || friendly > 1000) - { - clif->message(fd, msg_fd(fd,37)); // An invalid number was specified. + struct pet_data *pd = sd->pd; + + if (sd->status.pet_id == 0 || pd == NULL) { + clif->message(fd, msg_fd(fd, 184)); // Sorry, but you have no pet. return false; } - if (friendly == pd->pet.intimate) { - clif->message(fd, msg_fd(fd,183)); // Pet intimacy is already at maximum. + if (friendly == pd->pet.intimate && friendly == PET_INTIMACY_MAX) { + clif->message(fd, msg_fd(fd, 183)); // Pet intimacy is already at maximum. return false; } - pet->set_intimate(pd, friendly); - clif->send_petstatus(sd); - clif->message(fd, msg_fd(fd,182)); // Pet intimacy changed. + if (friendly != pd->pet.intimate) { // No need to update the pet's status if intimacy value won't change. + pet->set_intimate(pd, friendly); + clif->send_petstatus(sd); + } + + clif->message(fd, msg_fd(fd, 182)); // Pet intimacy changed. (Send message regardless of value has changed or not.) + return true; } -/*========================================== +/** + * Sets a pet's hunger value. * - *------------------------------------------*/ + * @code{.herc} + * @pethungry <0-100> + * @endcode + * + **/ ACMD(pethungry) { - int hungry; - struct pet_data *pd; - - if (!*message || (hungry = atoi(message)) < 0) { - clif->message(fd, msg_fd(fd,1017)); // Please enter a valid number (usage: @pethungry <0-100>). + if (*message == '\0' || (atoi(message) == 0 && isdigit(*message) == 0)) { + clif->message(fd, msg_fd(fd, 1017)); // Please enter a valid number (usage: @pethungry <0-100>). return false; } - pd = sd->pd; - if (!sd->status.pet_id || !pd) { - clif->message(fd, msg_fd(fd,184)); // Sorry, but you have no pet. + int hungry = atoi(message); + + if (hungry < PET_HUNGER_STARVING || hungry > PET_HUNGER_STUFFED) { + clif->message(fd, msg_fd(fd, 1017)); // Please enter a valid number (usage: @pethungry <0-100>). return false; } - if (hungry < 0 || hungry > 100) { - clif->message(fd, msg_fd(fd,37)); // An invalid number was specified. + + struct pet_data *pd = sd->pd; + + if (sd->status.pet_id == 0 || pd == NULL) { + clif->message(fd, msg_fd(fd, 184)); // Sorry, but you have no pet. return false; } - if (hungry == pd->pet.hungry) { - clif->message(fd, msg_fd(fd,186)); // Pet hunger is already at maximum. + + if (hungry == pd->pet.hungry && hungry == PET_HUNGER_STUFFED) { + clif->message(fd, msg_fd(fd, 186)); // Pet hunger is already at maximum. return false; } - pd->pet.hungry = hungry; - clif->send_petstatus(sd); - clif->message(fd, msg_fd(fd,185)); // Pet hunger changed. + if (hungry != pd->pet.hungry) { // No need to update the pet's status if hunger value won't change. + pd->pet.hungry = hungry; + clif->send_petstatus(sd); + } + + clif->message(fd, msg_fd(fd, 185)); // Pet hunger changed. (Send message regardless of value has changed or not.) return true; } @@ -2739,7 +2891,8 @@ ACMD(petrename) /*========================================== * *------------------------------------------*/ -ACMD(recall) { +ACMD(recall) +{ struct map_session_data *pl_sd = NULL; if (!*message) { @@ -2747,7 +2900,7 @@ ACMD(recall) { return false; } - if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message, true)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -3011,7 +3164,7 @@ ACMD(doommap) /*========================================== * *------------------------------------------*/ -void atcommand_raise_sub(struct map_session_data* sd) +static void atcommand_raise_sub(struct map_session_data *sd) { nullpo_retv(sd); status->revive(&sd->bl, 100, 100); @@ -3072,7 +3225,7 @@ ACMD(kick) return false; } - if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message, true)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -3309,7 +3462,8 @@ ACMD(breakguild) /*========================================== * *------------------------------------------*/ -ACMD(agitstart) { +ACMD(agitstart) +{ if (map->agit_flag == 1) { clif->message(fd, msg_fd(fd,73)); // War of Emperium is currently in progress. return false; @@ -3325,7 +3479,8 @@ ACMD(agitstart) { /*========================================== * *------------------------------------------*/ -ACMD(agitstart2) { +ACMD(agitstart2) +{ if (map->agit2_flag == 1) { clif->message(fd, msg_fd(fd,404)); // "War of Emperium SE is currently in progress." return false; @@ -3341,7 +3496,8 @@ ACMD(agitstart2) { /*========================================== * *------------------------------------------*/ -ACMD(agitend) { +ACMD(agitend) +{ if (map->agit_flag == 0) { clif->message(fd, msg_fd(fd,75)); // War of Emperium is currently not in progress. return false; @@ -3357,7 +3513,8 @@ ACMD(agitend) { /*========================================== * *------------------------------------------*/ -ACMD(agitend2) { +ACMD(agitend2) +{ if (map->agit2_flag == 0) { clif->message(fd, msg_fd(fd,406)); // "War of Emperium SE is currently not in progress." return false; @@ -3373,7 +3530,8 @@ ACMD(agitend2) { /*========================================== * @mapexit - shuts down the map server *------------------------------------------*/ -ACMD(mapexit) { +ACMD(mapexit) +{ map->do_shutdown(); return true; } @@ -3397,7 +3555,7 @@ ACMD(idsearch) safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,77), item_name); // Search results for '%s' (name: id): clif->message(fd, atcmd_output); - match = itemdb->search_name_array(item_array, MAX_SEARCH, item_name, 0); + match = itemdb->search_name_array(item_array, MAX_SEARCH, item_name, IT_SEARCH_NAME_PARTIAL); if (match > MAX_SEARCH) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,269), MAX_SEARCH, match); clif->message(fd, atcmd_output); @@ -3583,7 +3741,8 @@ ACMD(reloaditemdb) /*========================================== * *------------------------------------------*/ -ACMD(reloadmobdb) { +ACMD(reloadmobdb) +{ mob->reload(); pet->read_db(); homun->reload(); @@ -3612,7 +3771,8 @@ ACMD(reloadskilldb) /*========================================== * @reloadatcommand - reloads conf/atcommand.conf conf/groups.conf *------------------------------------------*/ -ACMD(reloadatcommand) { +ACMD(reloadatcommand) +{ struct config_t run_test; if (!libconfig->load_file(&run_test, "conf/groups.conf")) { @@ -3642,7 +3802,7 @@ ACMD(reloadbattleconf) struct Battle_Config prev_config; memcpy(&prev_config, &battle_config, sizeof(prev_config)); - battle->config_read(map->BATTLE_CONF_FILENAME); + battle->config_read(map->BATTLE_CONF_FILENAME, false); if (prev_config.feature_roulette == 0 && battle_config.feature_roulette == 1 && !clif->parse_roulette_db()) battle_config.feature_roulette = 0; @@ -3686,13 +3846,14 @@ ACMD(reloadbattleconf) /*========================================== * @reloadstatusdb - reloads job_db1.txt job_db2.txt job_db2-2.txt refine_db.txt size_fix.txt *------------------------------------------*/ -ACMD(reloadstatusdb) { +ACMD(reloadstatusdb) +{ status->readdb(); clif->message(fd, msg_fd(fd,256)); return true; } /*========================================== - * @reloadpcdb - reloads exp.txt skill_tree.txt attr_fix.txt statpoint.txt + * @reloadpcdb - reloads exp_group_db.conf skill_tree.txt attr_fix.txt statpoint.txt *------------------------------------------*/ ACMD(reloadpcdb) { @@ -3704,7 +3865,8 @@ ACMD(reloadpcdb) /*========================================== * @reloadscript - reloads all scripts (npcs, warps, mob spawns, ...) *------------------------------------------*/ -ACMD(reloadscript) { +ACMD(reloadscript) +{ struct s_mapiterator* iter; struct map_session_data* pl_sd; @@ -3748,7 +3910,7 @@ ACMD(reloadscript) { * 1 = Show users in that map and their location * 2 = Shows NPCs in that map * 3 = Shows the chats in that map - TODO# add the missing mapflags e.g. adjust_skill_damage to display + * TODO# add the missing mapflags e.g. adjust_skill_damage to display *------------------------------------------*/ ACMD(mapinfo) { @@ -3793,7 +3955,7 @@ ACMD(mapinfo) if( pl_sd->mapindex == m_index ) { if( pl_sd->state.vending ) vend_num++; - else if ((cd = map->id2cd(pl_sd->chatID)) != NULL && cd->usersd[0] == pl_sd) + else if ((cd = map->id2cd(pl_sd->chat_id)) != NULL && cd->usersd[0] == pl_sd) chat_num++; } } @@ -3813,6 +3975,9 @@ ACMD(mapinfo) if (map->list[m_id].flag.battleground) clif->message(fd, msg_fd(fd,1045)); // Battlegrounds ON + if (map->list[m_id].flag.cvc) + clif->message(fd, msg_fd(fd, 139)); // CvC ON + strcpy(atcmd_output,msg_fd(fd,1046)); // PvP Flags: if (map->list[m_id].flag.pvp) strcat(atcmd_output, msg_fd(fd,1047)); // Pvp ON | @@ -3923,8 +4088,14 @@ ACMD(mapinfo) strcat(atcmd_output, msg_fd(fd,1096)); // PartyLock | if (map->list[m_id].flag.guildlock) strcat(atcmd_output, msg_fd(fd,1097)); // GuildLock | + if (map->list[m_id].flag.noautoloot) + strcat(atcmd_output, msg_fd(fd, 1063)); // NoAutoloot | if (map->list[m_id].flag.noviewid != EQP_NONE) strcat(atcmd_output, msg_fd(fd,1079)); // NoViewID | + if (map->list[m_id].flag.pairship_startable) + strcat(atcmd_output, msg_fd(fd, 1292)); // PrivateAirshipStartable | + if (map->list[m_id].flag.pairship_endable) + strcat(atcmd_output, msg_fd(fd, 1293)); // PrivateAirshipEndable | clif->message(fd, atcmd_output); switch (list) { @@ -3948,16 +4119,36 @@ ACMD(mapinfo) for (i = 0; i < map->list[m_id].npc_num;) { struct npc_data *nd = map->list[m_id].npc[i]; switch(nd->dir) { - case 0: strcpy(direction, msg_fd(fd,1101)); break; // North - case 1: strcpy(direction, msg_fd(fd,1102)); break; // North West - case 2: strcpy(direction, msg_fd(fd,1103)); break; // West - case 3: strcpy(direction, msg_fd(fd,1104)); break; // South West - case 4: strcpy(direction, msg_fd(fd,1105)); break; // South - case 5: strcpy(direction, msg_fd(fd,1106)); break; // South East - case 6: strcpy(direction, msg_fd(fd,1107)); break; // East - case 7: strcpy(direction, msg_fd(fd,1108)); break; // North East - case 9: strcpy(direction, msg_fd(fd,1109)); break; // North - default: strcpy(direction, msg_fd(fd,1110)); break; // Unknown + case UNIT_DIR_NORTH: + strcpy(direction, msg_fd(fd, 1101)); // North + break; + case UNIT_DIR_NORTHWEST: + strcpy(direction, msg_fd(fd, 1102)); // North West + break; + case UNIT_DIR_WEST: + strcpy(direction, msg_fd(fd, 1103)); // West + break; + case UNIT_DIR_SOUTHWEST: + strcpy(direction, msg_fd(fd, 1104)); // South West + break; + case UNIT_DIR_SOUTH: + strcpy(direction, msg_fd(fd, 1105)); // South + break; + case UNIT_DIR_SOUTHEAST: + strcpy(direction, msg_fd(fd, 1106)); // South East + break; + case UNIT_DIR_EAST: + strcpy(direction, msg_fd(fd, 1107)); // East + break; + case UNIT_DIR_NORTHEAST: + strcpy(direction, msg_fd(fd, 1108)); // North East + break; + case 9: // is this actually used? [skyleo] + strcpy(direction, msg_fd(fd, 1109)); // North + break; + default: + strcpy(direction, msg_fd(fd, 1110)); // Unknown + break; } if(strcmp(nd->name,nd->exname) == 0) safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1111), // NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d @@ -3972,7 +4163,7 @@ ACMD(mapinfo) clif->message(fd, msg_fd(fd,1113)); // ----- Chats in Map ----- iter = mapit_getallusers(); for (pl_sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCCAST(BL_PC, mapit->next(iter))) { - if ((cd = map->id2cd(pl_sd->chatID)) != NULL && pl_sd->mapindex == m_index && cd->usersd[0] == pl_sd) { + if ((cd = map->id2cd(pl_sd->chat_id)) != NULL && pl_sd->mapindex == m_index && cd->usersd[0] == pl_sd) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1114), // Chat: %s | Player: %s | Location: %d %d cd->title, pl_sd->status.name, cd->bl.x, cd->bl.y); clif->message(fd, atcmd_output); @@ -4006,7 +4197,7 @@ ACMD(mount_peco) return false; } - if ((sd->class_&MAPID_THIRDMASK) == MAPID_RUNE_KNIGHT) { + if ((sd->job & MAPID_THIRDMASK) == MAPID_RUNE_KNIGHT) { if (!pc->checkskill(sd,RK_DRAGONTRAINING)) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,213), skill->get_desc(RK_DRAGONTRAINING)); // You need %s to mount! clif->message(fd, atcmd_output); @@ -4021,7 +4212,7 @@ ACMD(mount_peco) } return true; } - if ((sd->class_&MAPID_THIRDMASK) == MAPID_RANGER) { + if ((sd->job & MAPID_THIRDMASK) == MAPID_RANGER) { if (!pc->checkskill(sd,RA_WUGRIDER)) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,213), skill->get_desc(RA_WUGRIDER)); // You need %s to mount! clif->message(fd, atcmd_output); @@ -4036,17 +4227,24 @@ ACMD(mount_peco) } return true; } - if ((sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC) { + if ((sd->job & MAPID_THIRDMASK) == MAPID_MECHANIC) { + int mtype = MADO_ROBOT; + if (!*message) + sscanf(message, "%d", &mtype); + if (mtype < MADO_ROBOT || mtype >= MADO_MAX) { + clif->message(fd, msg_fd(fd, 173)); // Please enter a valid madogear type. + return false; + } if (!pc_ismadogear(sd)) { clif->message(sd->fd,msg_fd(fd,1123)); // You have mounted your Mado Gear. - pc->setmadogear(sd, true); + pc->setmadogear(sd, true, (enum mado_type)mtype); } else { clif->message(sd->fd,msg_fd(fd,1124)); // You have released your Mado Gear. - pc->setmadogear(sd, false); + pc->setmadogear(sd, false, (enum mado_type)mtype); } return true; } - if (sd->class_&MAPID_SWORDMAN && sd->class_&JOBL_2) { + if ((sd->job & MAPID_BASEMASK) == MAPID_SWORDMAN && (sd->job & JOBL_2) != 0) { if (!pc_isridingpeco(sd)) { // if actually no peco if (!pc->checkskill(sd, KN_RIDING)) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,213), skill->get_desc(KN_RIDING)); // You need %s to mount! @@ -4068,7 +4266,8 @@ ACMD(mount_peco) /*========================================== *Spy Commands by Syrus22 *------------------------------------------*/ -ACMD(guildspy) { +ACMD(guildspy) +{ char guild_name[NAME_LENGTH]; struct guild *g; @@ -4107,7 +4306,8 @@ ACMD(guildspy) { /*========================================== * *------------------------------------------*/ -ACMD(partyspy) { +ACMD(partyspy) +{ char party_name[NAME_LENGTH]; struct party_data *p; @@ -4149,12 +4349,13 @@ ACMD(partyspy) { *------------------------------------------*/ ACMD(repairall) { - int count, i; - - count = 0; - for (i = 0; i < MAX_INVENTORY; i++) { - if (sd->status.inventory[i].nameid && sd->status.inventory[i].attribute == 1) { - sd->status.inventory[i].attribute = 0; + int count = 0; + for (int i = 0; i < sd->status.inventorySize; i++) { + if (sd->status.inventory[i].card[0] == CARD0_PET) + continue; + if (sd->status.inventory[i].nameid && (sd->status.inventory[i].attribute & ATTR_BROKEN) != 0) { + sd->status.inventory[i].attribute |= ATTR_BROKEN; + sd->status.inventory[i].attribute ^= ATTR_BROKEN; clif->produce_effect(sd, 0, sd->status.inventory[i].nameid); count++; } @@ -4162,7 +4363,7 @@ ACMD(repairall) if (count > 0) { clif->misceffect(&sd->bl, 3); - clif->equiplist(sd); + clif->equipList(sd); clif->message(fd, msg_fd(fd,107)); // All items have been repaired. } else { clif->message(fd, msg_fd(fd,108)); // No item need to be repaired. @@ -4175,7 +4376,8 @@ ACMD(repairall) /*========================================== * @nuke [Valaris] *------------------------------------------*/ -ACMD(nuke) { +ACMD(nuke) +{ struct map_session_data *pl_sd; memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); @@ -4185,7 +4387,7 @@ ACMD(nuke) { return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) != NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) != NULL) { if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kill only lower or same GM level skill->castend_nodamage_id(&pl_sd->bl, &pl_sd->bl, NPC_SELFDESTRUCTION, 99, timer->gettick(), 0); clif->message(fd, msg_fd(fd,109)); // Player has been nuked! @@ -4204,7 +4406,8 @@ ACMD(nuke) { /*========================================== * @tonpc *------------------------------------------*/ -ACMD(tonpc) { +ACMD(tonpc) +{ char npcname[NAME_LENGTH+1]; struct npc_data *nd; @@ -4303,34 +4506,98 @@ ACMD(loadnpc) return true; } +/** + * Unloads a specific NPC. + * + * @code{.herc} + * @unloadnpc <NPC_name> {<flag>} + * @endcode + * + **/ ACMD(unloadnpc) { - struct npc_data *nd; - char NPCname[NAME_LENGTH+1]; + char npc_name[NAME_LENGTH + 1] = {'\0'}; + int flag = 1; - memset(NPCname, '\0', sizeof(NPCname)); + if (*message == '\0' || sscanf(message, "%24s %1d", npc_name, &flag) < 1) { + clif->message(fd, msg_fd(fd, 1133)); /// Please enter a NPC name (Usage: @unloadnpc <NPC_name> {<flag>}). + return false; + } + + struct npc_data *nd = npc->name2id(npc_name); + + if (nd == NULL) { + clif->message(fd, msg_fd(fd, 111)); /// This NPC doesn't exist. + return false; + } + + npc->unload_duplicates(nd, (flag != 0)); + npc->unload(nd, true, (flag != 0)); + npc->read_event_script(); + clif->message(fd, msg_fd(fd, 112)); /// Npc Disabled. + return true; +} - if (!*message || sscanf(message, "%24[^\n]", NPCname) < 1) { - clif->message(fd, msg_fd(fd,1133)); // Please enter a NPC name (usage: @npcoff <NPC_name>). +/** + * Unloads a script file and reloads it. + * Note: Be aware that some changes made by NPC are not reverted on unload. See doc/atcommands.txt for details. + * + * @code{.herc} + * @reloadnpc <path> {<flag>} + * @endcode + * + **/ +ACMD(reloadnpc) +{ + char format[20]; + + snprintf(format, sizeof(format), "%%%ds %%1d", MAX_DIR_PATH); + + char file_path[MAX_DIR_PATH + 1] = {'\0'}; + int flag = 1; + + if (*message == '\0' || (sscanf(message, format, file_path, &flag) < 1)) { + clif->message(fd, msg_fd(fd, 1516)); /// Usage: @reloadnpc <path> {<flag>} return false; } - if ((nd = npc->name2id(NPCname)) == NULL) { - clif->message(fd, msg_fd(fd,111)); // This NPC doesn't exist. + if (!exists(file_path)) { + clif->message(fd, msg_fd(fd, 1387)); /// File not found. return false; } - npc->unload_duplicates(nd); - npc->unload(nd,true); + if (!is_file(file_path)) { + clif->message(fd, msg_fd(fd, 1518)); /// Not a file. + return false; + } + + FILE *fp = fopen(file_path, "r"); + + if (fp == NULL) { + clif->message(fd, msg_fd(fd, 1519)); /// Can't open file. + return false; + } + + fclose(fp); + + if (!npc->unloadfile(file_path, (flag != 0))) { + clif->message(fd, msg_fd(fd, 1517)); /// Script could not be unloaded. + return false; + } + + clif->message(fd, msg_fd(fd, 1386)); /// File unloaded. Be aware that... + npc->addsrcfile(file_path); + npc->parsesrcfile(file_path, true); npc->read_event_script(); - clif->message(fd, msg_fd(fd,112)); // Npc Disabled. + clif->message(fd, msg_fd(fd, 262)); /// Script loaded. return true; } /*========================================== * time in txt for time command (by [Yor]) *------------------------------------------*/ -char* txt_time(int fd, unsigned int duration) { +static char *txt_time(int fd, unsigned int duration) +{ int days, hours, minutes, seconds; static char temp1[CHAT_SIZE_MAX]; int tlen = 0; @@ -4368,7 +4635,8 @@ char* txt_time(int fd, unsigned int duration) { * @time/@date/@serverdate/@servertime: Display the date/time of the server (by [Yor] * Calculation management of GM modification (@day/@night GM commands) is done *------------------------------------------*/ -ACMD(servertime) { +ACMD(servertime) +{ time_t time_server; // variable for number of seconds (used with time() function) struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ... char temp[CHAT_SIZE_MAX]; @@ -4423,7 +4691,7 @@ ACMD(servertime) { //Added by Coltaro //We're using this function here instead of using time_t so that it only counts player's jail time when he/she's online (and since the idea is to reduce the amount of minutes one by one in status->change_timer...). //Well, using time_t could still work but for some reason that looks like more coding x_x -void get_jail_time(int jailtime, int* year, int* month, int* day, int* hour, int* minute) +static void get_jail_time(int jailtime, int *year, int *month, int *day, int *hour, int *minute) { const int factor_year = 518400; //12*30*24*60 = 518400 const int factor_month = 43200; //30*24*60 = 43200 @@ -4457,7 +4725,8 @@ void get_jail_time(int jailtime, int* year, int* month, int* day, int* hour, int * @jail <char_name> by [Yor] * Special warp! No check with nowarp and nowarpto flag *------------------------------------------*/ -ACMD(jail) { +ACMD(jail) +{ struct map_session_data *pl_sd; int x, y; unsigned short m_index; @@ -4469,7 +4738,7 @@ ACMD(jail) { return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) == NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -4510,7 +4779,8 @@ ACMD(jail) { * @unjail/@discharge <char_name> by [Yor] * Special warp! No check with nowarp and nowarpto flag *------------------------------------------*/ -ACMD(unjail) { +ACMD(unjail) +{ struct map_session_data *pl_sd; memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); @@ -4520,7 +4790,7 @@ ACMD(unjail) { return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) == NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -4544,7 +4814,8 @@ ACMD(unjail) { return true; } -ACMD(jailfor) { +ACMD(jailfor) +{ struct map_session_data *pl_sd = NULL; int year, month, day, hour, minute; char * modif_p; @@ -4598,7 +4869,7 @@ ACMD(jailfor) { return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) == NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -4828,7 +5099,8 @@ ACMD(undisguise) /*========================================== * UndisguiseAll *------------------------------------------*/ -ACMD(undisguiseall) { +ACMD(undisguiseall) +{ struct map_session_data *pl_sd; struct s_mapiterator* iter; @@ -4880,21 +5152,19 @@ ACMD(undisguiseguild) *------------------------------------------*/ ACMD(exp) { - char output[CHAT_SIZE_MAX]; - double nextb, nextj; - - memset(output, '\0', sizeof(output)); + double percentb = 0.0, percentj = 0.0; + uint64 nextb, nextj; nextb = pc->nextbaseexp(sd); - if (nextb) - nextb = sd->status.base_exp*100.0/nextb; + if (nextb != 0) + percentb = sd->status.base_exp * 100.0 / nextb; nextj = pc->nextjobexp(sd); - if (nextj) - nextj = sd->status.job_exp*100.0/nextj; + if (nextj != 0) + percentj = sd->status.job_exp * 100.0 / nextj; - sprintf(output, msg_fd(fd,1148), sd->status.base_level, nextb, sd->status.job_level, nextj); // Base Level: %d (%.3f%%) | Job Level: %d (%.3f%%) - clif->message(fd, output); + sprintf(atcmd_output, msg_fd(fd,1148), sd->status.base_level, percentb, sd->status.job_level, percentj); // Base Level: %d (%.3f%%) | Job Level: %d (%.3f%%) + clif->message(fd, atcmd_output); return true; } @@ -4911,7 +5181,7 @@ ACMD(broadcast) } safesnprintf(atcmd_output, sizeof(atcmd_output), "%s: %s", sd->status.name, message); - intif->broadcast(atcmd_output, strlen(atcmd_output) + 1, BC_DEFAULT); + clif->broadcast(NULL, atcmd_output, (int)strlen(atcmd_output) + 1, BC_DEFAULT, ALL_CLIENT); return true; } @@ -4930,7 +5200,7 @@ ACMD(localbroadcast) safesnprintf(atcmd_output, sizeof(atcmd_output), "%s: %s", sd->status.name, message); - clif->broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, BC_DEFAULT, ALL_SAMEMAP); + clif->broadcast(&sd->bl, atcmd_output, (int)strlen(atcmd_output) + 1, BC_DEFAULT, ALL_SAMEMAP); return true; } @@ -5008,7 +5278,8 @@ ACMD(killer) * @killable by MouseJstr * enable other people killing you *------------------------------------------*/ -ACMD(killable) { +ACMD(killable) +{ sd->state.killable = !sd->state.killable; if (sd->state.killable) { @@ -5024,7 +5295,8 @@ ACMD(killable) { * @skillon by MouseJstr * turn skills on for the map *------------------------------------------*/ -ACMD(skillon) { +ACMD(skillon) +{ map->list[sd->bl.m].flag.noskill = 0; clif->message(fd, msg_fd(fd,244)); return true; @@ -5034,7 +5306,8 @@ ACMD(skillon) { * @skilloff by MouseJstr * Turn skills off on the map *------------------------------------------*/ -ACMD(skilloff) { +ACMD(skilloff) +{ map->list[sd->bl.m].flag.noskill = 1; clif->message(fd, msg_fd(fd,243)); return true; @@ -5044,7 +5317,8 @@ ACMD(skilloff) { * @npcmove by MouseJstr * move a npc *------------------------------------------*/ -ACMD(npcmove) { +ACMD(npcmove) +{ int x = 0, y = 0, m; struct npc_data *nd = 0; @@ -5114,7 +5388,8 @@ ACMD(addwarp) * @follow by [MouseJstr] * Follow a player .. staying no more then 5 spaces away *------------------------------------------*/ -ACMD(follow) { +ACMD(follow) +{ struct map_session_data *pl_sd = NULL; if (!*message) { @@ -5125,7 +5400,7 @@ ACMD(follow) { return true; } - if ((pl_sd = map->nick2sd(message)) == NULL) { + if ((pl_sd = map->nick2sd(message, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5142,20 +5417,49 @@ ACMD(follow) { } /*========================================== - * @dropall by [MouseJstr] - * Drop all your possession on the ground + * @dropall by [MouseJstr] and [Xantara] + * Drop all your possession on the ground based on item type *------------------------------------------*/ ACMD(dropall) { - int i; + int type = -1; - for (i = 0; i < MAX_INVENTORY; i++) { - if (sd->status.inventory[i].amount) { - if(sd->status.inventory[i].equip != 0) - pc->unequipitem(sd, i, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); - pc->dropitem(sd, i, sd->status.inventory[i].amount); + if (message[0] != '\0') { + type = atoi(message); + if (!((type >= IT_HEALING && type <= IT_DELAYCONSUME) || type == IT_CASH || type == -1)) { + clif->message(fd, msg_fd(fd, 1500)); + clif->message(fd, msg_fd(fd, 1501)); + return false; } } + + int count = 0, count_skipped = 0; + for (int i = 0; i < sd->status.inventorySize; i++) { + if (sd->status.inventory[i].amount > 0) { + struct item_data *item_data = itemdb->exists(sd->status.inventory[i].nameid); + if (item_data == NULL) { + ShowWarning("Non-existant item %d on dropall list (account_id: %d, char_id: %d)\n", sd->status.inventory[i].nameid, sd->status.account_id, sd->status.char_id); + continue; + } + + if (!pc->candrop(sd, &sd->status.inventory[i])) + continue; + + if (type == -1 || type == item_data->type) { + if (sd->status.inventory[i].equip != 0) + pc->unequipitem(sd, i, PCUNEQUIPITEM_RECALC | PCUNEQUIPITEM_FORCE); + + int amount = sd->status.inventory[i].amount; + if (pc->dropitem(sd, i, amount) != 0) + count += amount; + else + count_skipped += amount; + } + } + } + + sprintf(atcmd_output, msg_fd(fd, 1502), count, count_skipped); // %d items are dropped (%d skipped)! + clif->message(fd, atcmd_output); return true; } @@ -5165,8 +5469,6 @@ ACMD(dropall) *------------------------------------------*/ ACMD(storeall) { - int i; - if (sd->state.storage_flag != STORAGE_FLAG_NORMAL) { //Open storage. if (storage->open(sd) == 1) { @@ -5175,7 +5477,12 @@ ACMD(storeall) } } - for (i = 0; i < MAX_INVENTORY; i++) { + if (sd->storage.received == false) { + clif->message(fd, msg_fd(fd, 27)); // "Storage has not been loaded yet" + return false; + } + + for (int i = 0; i < sd->status.inventorySize; i++) { if (sd->status.inventory[i].amount) { if(sd->status.inventory[i].equip != 0) pc->unequipitem(sd, i, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); @@ -5190,17 +5497,25 @@ ACMD(storeall) ACMD(clearstorage) { - int i, j; + int i; if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { clif->message(fd, msg_fd(fd,250)); return false; } - j = sd->status.storage.storage_amount; - for (i = 0; i < j; ++i) { - storage->delitem(sd, i, sd->status.storage.items[i].amount); + if (sd->storage.received == false) { + clif->message(fd, msg_fd(fd, 27)); // "Storage has not been loaded yet" + return false; } + + for (i = 0; i < VECTOR_LENGTH(sd->storage.item); ++i) { + if (VECTOR_INDEX(sd->storage.item, i).nameid == 0) + continue; // we skip the already deleted items. + + storage->delitem(sd, i, VECTOR_INDEX(sd->storage.item, i).amount); + } + storage->close(sd); clif->message(fd, msg_fd(fd,1394)); // Your storage was cleaned. @@ -5256,7 +5571,7 @@ ACMD(clearcart) return false; } - if (sd->state.vending) { + if (sd->state.vending || sd->state.prevend) { clif->message(fd, msg_fd(fd,548)); // You can't clean a cart while vending! return false; } @@ -5297,12 +5612,13 @@ ACMD(skillid) iter = db_iterator(skill->name2id_db); for (data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key)) { - int idx = skill->get_index(DB->data2i(data)); - if (strnicmp(key.str, message, skillen) == 0 || strnicmp(skill->dbs->db[idx].desc, message, skillen) == 0) { - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1164), DB->data2i(data), skill->dbs->db[idx].desc, key.str); // skill %d: %s (%s) + int skill_id = DB->data2i(data); + const char *skill_desc = skill->get_desc(skill_id); + if (strnicmp(key.str, message, skillen) == 0 || strnicmp(skill_desc, message, skillen) == 0) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1164), skill_id, skill_desc, key.str); // skill %d: %s (%s) clif->message(fd, atcmd_output); - } else if ( found < MAX_SKILLID_PARTIAL_RESULTS && ( stristr(key.str,message) || stristr(skill->dbs->db[idx].desc,message) ) ) { - snprintf(partials[found], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_fd(fd,1164), DB->data2i(data), skill->dbs->db[idx].desc, key.str); + } else if (found < MAX_SKILLID_PARTIAL_RESULTS && (stristr(key.str, message) != NULL || stristr(skill_desc, message) != NULL)) { + snprintf(partials[found], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_fd(fd, 1164), skill_id, skill_desc, key.str); found++; } } @@ -5325,7 +5641,8 @@ ACMD(skillid) * @useskill by [MouseJstr] * A way of using skills without having to find them in the skills menu *------------------------------------------*/ -ACMD(useskill) { +ACMD(useskill) +{ struct map_session_data *pl_sd = NULL; struct block_list *bl; uint16 skill_id; @@ -5339,7 +5656,7 @@ ACMD(useskill) { if (!strcmp(target,"self")) pl_sd = sd; //quick keyword - else if ((pl_sd = map->nick2sd(target)) == NULL) { + else if ((pl_sd = map->nick2sd(target, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5350,6 +5667,8 @@ ACMD(useskill) { return false; } + pc->autocast_clear(sd); + if (skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE+MAX_HOMUNSKILL && sd->hd && homun_alive(sd->hd)) // (If used with @useskill, put the homunc as dest) bl = &sd->hd->bl; @@ -5371,7 +5690,8 @@ ACMD(useskill) { * Debug command to locate new skill IDs. It sends the * three possible skill-effect packets to the area. *------------------------------------------*/ -ACMD(displayskill) { +ACMD(displayskill) +{ struct status_data *st; int64 tick; uint16 skill_id; @@ -5406,7 +5726,7 @@ ACMD(skilltree) return false; } - if ( (pl_sd = map->nick2sd(target)) == NULL ) { + if ( (pl_sd = map->nick2sd(target, true)) == NULL ) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5429,7 +5749,7 @@ ACMD(skilltree) for (j = 0; j < VECTOR_LENGTH(entry->need); j++) { struct skill_tree_requirement *req = &VECTOR_INDEX(entry->need, j); if (pc->checkskill(sd, req->id) < req->lv) { - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1170), req->lv, skill->dbs->db[req->id].desc); // Player requires level %d of skill %s. + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1170), req->lv, skill->get_desc(req->id)); // Player requires level %d of skill %s. clif->message(fd, atcmd_output); meets = 0; } @@ -5442,7 +5762,8 @@ ACMD(skilltree) } // Hand a ring with partners name on it to this char -void atcommand_getring(struct map_session_data* sd) { +static void atcommand_getring(struct map_session_data *sd) +{ int flag, item_id; struct item item_tmp; nullpo_retv(sd); @@ -5451,13 +5772,13 @@ void atcommand_getring(struct map_session_data* sd) { memset(&item_tmp, 0, sizeof(item_tmp)); item_tmp.nameid = item_id; item_tmp.identify = 1; - item_tmp.card[0] = 255; - item_tmp.card[2] = sd->status.partner_id; - item_tmp.card[3] = sd->status.partner_id >> 16; + item_tmp.card[0] = CARD0_FORGE; + item_tmp.card[2] = GetWord(sd->status.partner_id, 0); + item_tmp.card[3] = GetWord(sd->status.partner_id, 1); if((flag = pc->additem(sd,&item_tmp,1,LOG_TYPE_COMMAND))) { clif->additem(sd,0,0,flag); - map->addflooritem(&sd->bl, &item_tmp, 1, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 0); + map->addflooritem(&sd->bl, &item_tmp, 1, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 0, false); } } @@ -5465,7 +5786,8 @@ void atcommand_getring(struct map_session_data* sd) { * @marry by [MouseJstr], fixed by Lupus * Marry two players *------------------------------------------*/ -ACMD(marry) { +ACMD(marry) +{ struct map_session_data *pl_sd = NULL; char player_name[NAME_LENGTH] = ""; @@ -5474,7 +5796,7 @@ ACMD(marry) { return false; } - if ((pl_sd = map->nick2sd(player_name)) == NULL) { + if ((pl_sd = map->nick2sd(player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); return false; } @@ -5584,7 +5906,8 @@ ACMD(autotrade) * @changegm by durf (changed by Lupus) * Changes Master of your Guild to a specified guild member *------------------------------------------*/ -ACMD(changegm) { +ACMD(changegm) +{ struct guild *g; struct map_session_data *pl_sd; @@ -5603,12 +5926,12 @@ ACMD(changegm) { return false; } - if ((pl_sd=map->nick2sd(message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) { + if ((pl_sd=map->nick2sd(message, true)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) { clif->message(fd, msg_fd(fd,1184)); // Target character must be online and be a guild member. return false; } - guild->gm_change(sd->status.guild_id, pl_sd); + guild->gm_change(sd->status.guild_id, pl_sd->status.char_id); return true; } @@ -5616,14 +5939,15 @@ ACMD(changegm) { * @changeleader by Skotlex * Changes the leader of a party. *------------------------------------------*/ -ACMD(changeleader) { +ACMD(changeleader) +{ if (!message[0]) { clif->message(fd, msg_fd(fd,1185)); // Usage: @changeleader <party_member_name> return false; } - if (party->changeleader(sd, map->nick2sd(message))) + if (party->changeleader(sd, map->nick2sd(message, true))) return true; return false; } @@ -5805,7 +6129,8 @@ ACMD(autolootitem) * Credits: * chriser,Aleos *------------------------------------------*/ -ACMD(autoloottype) { +ACMD(autoloottype) +{ uint8 action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset enum item_types type = -1; int ITEM_NONE = 0; @@ -5918,8 +6243,8 @@ ACMD(snow) /*========================================== * Cherry tree snowstorm is made to fall. (Sakura) *------------------------------------------*/ -ACMD(sakura) { - +ACMD(sakura) +{ if (map->list[sd->bl.m].flag.sakura) { map->list[sd->bl.m].flag.sakura=0; clif->weather(sd->bl.m); @@ -5935,8 +6260,8 @@ ACMD(sakura) { /*========================================== * Clouds appear. *------------------------------------------*/ -ACMD(clouds) { - +ACMD(clouds) +{ if (map->list[sd->bl.m].flag.clouds) { map->list[sd->bl.m].flag.clouds=0; clif->weather(sd->bl.m); @@ -5953,8 +6278,8 @@ ACMD(clouds) { /*========================================== * Different type of clouds using effect 516 *------------------------------------------*/ -ACMD(clouds2) { - +ACMD(clouds2) +{ if (map->list[sd->bl.m].flag.clouds2) { map->list[sd->bl.m].flag.clouds2=0; clif->weather(sd->bl.m); @@ -5971,8 +6296,8 @@ ACMD(clouds2) { /*========================================== * Fog hangs over. *------------------------------------------*/ -ACMD(fog) { - +ACMD(fog) +{ if (map->list[sd->bl.m].flag.fog) { map->list[sd->bl.m].flag.fog=0; clif->weather(sd->bl.m); @@ -5988,8 +6313,8 @@ ACMD(fog) { /*========================================== * Fallen leaves fall. *------------------------------------------*/ -ACMD(leaves) { - +ACMD(leaves) +{ if (map->list[sd->bl.m].flag.leaves) { map->list[sd->bl.m].flag.leaves=0; clif->weather(sd->bl.m); @@ -6006,8 +6331,8 @@ ACMD(leaves) { /*========================================== * Fireworks appear. *------------------------------------------*/ -ACMD(fireworks) { - +ACMD(fireworks) +{ if (map->list[sd->bl.m].flag.fireworks) { map->list[sd->bl.m].flag.fireworks=0; clif->weather(sd->bl.m); @@ -6084,9 +6409,10 @@ ACMD(mobsearch) clif->message(fd, atcmd_output); return false; } - if (mob_id == atoi(mob_name)) - strcpy(mob_name,mob->db(mob_id)->jname); // --ja-- - //strcpy(mob_name,mob_db(mob_id)->name); // --en-- + if (mob_id == atoi(mob_name)) { + strcpy(mob_name,mob->db(mob_id)->jname); // DEFAULT_MOB_JNAME + //strcpy(mob_name,mob->db(mob_id)->name); // DEFAULT_MOB_NAME + } snprintf(atcmd_output, sizeof atcmd_output, msg_fd(fd,1220), mob_name, mapindex_id2name(sd->mapindex)); // Mob Search... %s %s clif->message(fd, atcmd_output); @@ -6114,20 +6440,23 @@ ACMD(mobsearch) * @cleanmap - cleans items on the ground * @cleanarea - cleans items on the ground within an specified area *------------------------------------------*/ -int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap) { +static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap) +{ nullpo_ret(bl); map->clearflooritem(bl); return 0; } -ACMD(cleanmap) { +ACMD(cleanmap) +{ map->foreachinmap(atcommand->cleanfloor_sub, sd->bl.m, BL_ITEM); clif->message(fd, msg_fd(fd,1221)); // All dropped items have been cleaned up. return true; } -ACMD(cleanarea) { +ACMD(cleanarea) +{ int x0 = 0, y0 = 0, x1 = 0, y1 = 0, n = 0; if (!*message || (n=sscanf(message, "%d %d %d %d", &x0, &y0, &x1, &y1)) < 1) { @@ -6148,7 +6477,7 @@ ACMD(cleanarea) { *------------------------------------------*/ ACMD(npctalk) { - char name[NAME_LENGTH],mes[100],temp[100]; + char name[NAME_LENGTH], mes[100], temp[200]; struct npc_data *nd; bool ifcolor=(*(info->command + 7) != 'c' && *(info->command + 7) != 'C')?0:1; unsigned int color = 0; @@ -6178,14 +6507,14 @@ ACMD(npctalk) snprintf(temp, sizeof(temp), "%s : %s", name, mes); if(ifcolor) clif->messagecolor(&nd->bl,color,temp); - else clif->disp_overhead(&nd->bl, temp); + else clif->disp_overhead(&nd->bl, temp, AREA_CHAT_WOC, NULL); return true; } ACMD(pettalk) { - char mes[100],temp[100]; + char mes[100], temp[200]; struct pet_data *pd; if (battle_config.min_chat_delay) { @@ -6238,7 +6567,7 @@ ACMD(pettalk) } snprintf(temp, sizeof temp ,"%s : %s", pd->pet.name, mes); - clif->disp_overhead(&pd->bl, temp); + clif->disp_overhead(&pd->bl, temp, AREA_CHAT_WOC, NULL); return true; } @@ -6291,7 +6620,8 @@ ACMD(users) /*========================================== * *------------------------------------------*/ -ACMD(reset) { +ACMD(reset) +{ pc->resetstate(sd); pc->resetskill(sd, PCRESETSKILL_RESYNC); safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,208), sd->status.name); // '%s' skill and stats points reseted! @@ -6302,47 +6632,52 @@ ACMD(reset) { /*========================================== * *------------------------------------------*/ + +/** + * Spawns mobs which treats the invoking as its master. + * + * @code{.herc} + * @summon <monster name/ID> {<duration>} + * @endcode + * + **/ ACMD(summon) { - char name[NAME_LENGTH]; - int mob_id = 0; + char name[NAME_LENGTH + 1] = {'\0'}; int duration = 0; - struct mob_data *md; - int64 tick=timer->gettick(); - if (!*message || sscanf(message, "%23s %12d", name, &duration) < 1) - { - clif->message(fd, msg_fd(fd,1225)); // Please enter a monster name (usage: @summon <monster name> {duration}). + if (*message == '\0' || sscanf(message, "%24s %12d", name, &duration) < 1) { + clif->message(fd, msg_fd(fd, 1225)); /// Please enter a monster name (usage: @summon <monster name> {duration}). return false; } - if (duration < 1) - duration =1; - else if (duration > 60) - duration =60; + int mob_id = atoi(name); - if ((mob_id = atoi(name)) == 0) + if (mob_id == 0) mob_id = mob->db_searchname(name); - if(mob_id == 0 || mob->db_checkid(mob_id) == 0) - { - clif->message(fd, msg_fd(fd,40)); // Invalid monster ID or name. + + if (mob_id == 0 || mob->db_checkid(mob_id) == 0) { + clif->message(fd, msg_fd(fd, 40)); /// Invalid monster ID or name. return false; } - md = mob->once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, "--ja--", mob_id, "", SZ_SMALL, AI_NONE); + struct mob_data *md = mob->once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, DEFAULT_MOB_JNAME, mob_id, "", + SZ_SMALL, AI_NONE, 0); - if(!md) + if (md == NULL) return false; md->master_id = sd->bl.id; md->special_state.ai = AI_ATTACK; - md->deletetimer = timer->add(tick+(duration*60000),mob->timer_delete,md->bl.id,0); - clif->specialeffect(&md->bl,344,AREA); - mob->spawn(md); - sc_start4(NULL,&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000); - clif->skill_poseffect(&sd->bl,AM_CALLHOMUN,1,md->bl.x,md->bl.y,tick); - clif->message(fd, msg_fd(fd,39)); // All monster summoned! + const int64 tick = timer->gettick(); + + md->deletetimer = timer->add(tick + (int64)cap_value(duration, 1, 60) * 60000, mob->timer_delete, md->bl.id, 0); + clif->specialeffect(&md->bl, 344, AREA); + mob->spawn(md); + sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000); + clif->skill_poseffect(&sd->bl, AM_CALLHOMUN, 1, md->bl.x, md->bl.y, tick); + clif->message(fd, msg_fd(fd, 39)); /// All monster summoned! return true; } @@ -6374,7 +6709,8 @@ ACMD(adjgroup) * @trade by [MouseJstr] * Open a trade window with a remote player *------------------------------------------*/ -ACMD(trade) { +ACMD(trade) +{ struct map_session_data *pl_sd = NULL; if (!*message) { @@ -6382,7 +6718,7 @@ ACMD(trade) { return false; } - if ((pl_sd = map->nick2sd(message)) == NULL) { + if ((pl_sd = map->nick2sd(message, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -6417,7 +6753,8 @@ ACMD(setbattleflag) /*========================================== * @unmute [Valaris] *------------------------------------------*/ -ACMD(unmute) { +ACMD(unmute) +{ struct map_session_data *pl_sd = NULL; if (!*message) { @@ -6425,7 +6762,7 @@ ACMD(unmute) { return false; } - if ((pl_sd = map->nick2sd(message)) == NULL) { + if ((pl_sd = map->nick2sd(message, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -6468,7 +6805,8 @@ ACMD(uptime) * @changesex <sex> * => Changes one's sex. Argument sex can be 0 or 1, m or f, male or female. *------------------------------------------*/ -ACMD(changesex) { +ACMD(changesex) +{ int i; pc->resetskill(sd, PCRESETSKILL_CHSEX); @@ -6479,10 +6817,23 @@ ACMD(changesex) { return true; } +ACMD(changecharsex) +{ + int i; + + pc->resetskill(sd, PCRESETSKILL_CHSEX); + // to avoid any problem with equipment and invalid sex, equipment is unequipped. + for (i=0; i<EQI_MAX; i++) + if (sd->equip_index[i] >= 0) pc->unequipitem(sd, sd->equip_index[i], PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); + chrif->changesex(sd, false); + return true; +} + /*================================================ * @mute - Mutes a player for a set amount of time *------------------------------------------------*/ -ACMD(mute) { +ACMD(mute) +{ struct map_session_data *pl_sd = NULL; int manner; @@ -6491,7 +6842,7 @@ ACMD(mute) { return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) == NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -6523,6 +6874,9 @@ ACMD(mute) { *------------------------------------------*/ ACMD(refresh) { + if (sd->npc_id > 0) + return false; + clif->refresh(sd); return true; } @@ -6534,33 +6888,46 @@ ACMD(refreshall) iter = mapit_getallusers(); for (iter_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); iter_sd = BL_UCAST(BL_PC, mapit->next(iter))) - clif->refresh(iter_sd); + if (iter_sd->npc_id <= 0) + clif->refresh(iter_sd); mapit->free(iter); return true; } /*========================================== - * @identify + * @identify / @identifyall * => GM's magnifier. *------------------------------------------*/ ACMD(identify) { - int i,num; + int num = 0; + bool identifyall = (strcmpi(info->command, "identifyall") == 0); - for (i=num=0;i<MAX_INVENTORY;i++) { - if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){ - num++; + if (!identifyall) { + for (int i = 0; i < sd->status.inventorySize; i++) { + if (sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify != 1) { + num++; + } } - } - if (num > 0) { - clif->item_identify_list(sd); } else { - clif->message(fd,msg_fd(fd,1238)); // There are no items to appraise. + for (int i = 0; i < sd->status.inventorySize; i++) { + if (sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify != 1) { + skill->identify(sd, i); + num++; + } + } } + + if (num == 0) + clif->message(fd,msg_fd(fd,1238)); // There are no items to appraise. + else if (!identifyall) + clif->item_identify_list(sd); + return true; } -ACMD(misceffect) { +ACMD(misceffect) +{ int effect = 0; if (!*message) @@ -6640,9 +7007,9 @@ ACMD(mobinfo) // stats if (monster->mexp) - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1240), monster->name, monster->jname, monster->sprite, monster->vd.class_); // MVP Monster: '%s'/'%s'/'%s' (%d) + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1240), monster->name, monster->jname, monster->sprite, monster->vd.class); // MVP Monster: '%s'/'%s'/'%s' (%d) else - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1241), monster->name, monster->jname, monster->sprite, monster->vd.class_); // Monster: '%s'/'%s'/'%s' (%d) + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1241), monster->name, monster->jname, monster->sprite, monster->vd.class); // Monster: '%s'/'%s'/'%s' (%d) clif->message(fd, atcmd_output); safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1242), monster->lv, monster->status.max_hp, base_exp, job_exp, MOB_HIT(monster), MOB_FLEE(monster)); // Lv:%d HP:%d Base EXP:%u Job EXP:%u HIT:%d FLEE:%d @@ -6770,16 +7137,17 @@ ACMD(showmobs) return false; } - if(mob_id == atoi(mob_name)) - strcpy(mob_name,mob->db(mob_id)->jname); // --ja-- - //strcpy(mob_name,mob_db(mob_id)->name); // --en-- + if (mob_id == atoi(mob_name)) { + strcpy(mob_name,mob->db(mob_id)->jname); // DEFAULT_MOB_JNAME + //strcpy(mob_name,mob->db(mob_id)->name); // DEFAULT_MOB_NAME + } snprintf(atcmd_output, sizeof atcmd_output, msg_fd(fd,1252), // Mob Search... %s %s mob_name, mapindex_id2name(sd->mapindex)); clif->message(fd, atcmd_output); it = mapit_geteachmob(); - for (md = BL_UCCAST(BL_MOB, mapit->first(it)); mapit->next(it); md = BL_UCCAST(BL_MOB, mapit->next(it))) { + for (md = BL_UCCAST(BL_MOB, mapit->first(it)); mapit->exists(it); md = BL_UCCAST(BL_MOB, mapit->next(it))) { if( md->bl.m != sd->bl.m ) continue; if( mob_id != -1 && md->class_ != mob_id ) @@ -6800,7 +7168,8 @@ ACMD(showmobs) /*========================================== * homunculus level up [orn] *------------------------------------------*/ -ACMD(homlevel) { +ACMD(homlevel) +{ struct homun_data *hd; int level = 0; enum homun_type htype; @@ -6871,7 +7240,8 @@ ACMD(homevolution) return true; } -ACMD(hommutate) { +ACMD(hommutate) +{ int homun_id; enum homun_type m_class, m_id; @@ -6900,7 +7270,8 @@ ACMD(hommutate) { /*========================================== * call choosen homunculus [orn] *------------------------------------------*/ -ACMD(makehomun) { +ACMD(makehomun) +{ int homunid; if (!*message) { @@ -6990,7 +7361,7 @@ ACMD(homhungry) *------------------------------------------*/ ACMD(homtalk) { - char mes[100],temp[100]; + char mes[100], temp[200]; if (battle_config.min_chat_delay) { if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0) @@ -7012,7 +7383,7 @@ ACMD(homtalk) } snprintf(temp, sizeof temp ,"%s : %s", sd->hd->homunculus.name, mes); - clif->disp_overhead(&sd->hd->bl, temp); + clif->disp_overhead(&sd->hd->bl, temp, AREA_CHAT_WOC, NULL); return true; } @@ -7020,7 +7391,8 @@ ACMD(homtalk) /*========================================== * Show homunculus stats *------------------------------------------*/ -ACMD(hominfo) { +ACMD(hominfo) +{ struct homun_data *hd; struct status_data *st; @@ -7148,7 +7520,7 @@ ACMD(iteminfo) return false; } if ((item_array[0] = itemdb->exists(atoi(message))) == NULL) - count = itemdb->search_name_array(item_array, MAX_SEARCH, message, 0); + count = itemdb->search_name_array(item_array, MAX_SEARCH, message, IT_SEARCH_NAME_PARTIAL); if (!count) { clif->message(fd, msg_fd(fd,19)); // Invalid item ID or name. @@ -7199,7 +7571,7 @@ ACMD(whodrops) return false; } if ((item_array[0] = itemdb->exists(atoi(message))) == NULL) - count = itemdb->search_name_array(item_array, MAX_SEARCH, message, 0); + count = itemdb->search_name_array(item_array, MAX_SEARCH, message, IT_SEARCH_NAME_PARTIAL); if (!count) { clif->message(fd, msg_fd(fd,19)); // Invalid item ID or name. @@ -7280,7 +7652,8 @@ ACMD(whereis) return true; } -ACMD(version) { +ACMD(version) +{ safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1296), sysinfo->is64bit() ? 64 : 32, sysinfo->platform()); // Hercules %d-bit for %s clif->message(fd, atcmd_output); safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1295), sysinfo->vcstype(), sysinfo->vcsrevision_src(), sysinfo->vcsrevision_scripts()); // %s revision '%s' (src) / '%s' (scripts) @@ -7292,8 +7665,9 @@ ACMD(version) { /*========================================== * @mutearea by MouseJstr *------------------------------------------*/ -int atcommand_mutearea_sub(struct block_list *bl, va_list ap) -{ // As it is being used [ACMD(mutearea)] there's no need to be a bool, but if there's need to reuse it, it's better to be this way +static int atcommand_mutearea_sub(struct block_list *bl, va_list ap) +{ + // As it is being used [ACMD(mutearea)] there's no need to be a bool, but if there's need to reuse it, it's better to be this way int time, id; struct map_session_data *pl_sd = BL_CAST(BL_PC, bl); @@ -7313,7 +7687,8 @@ int atcommand_mutearea_sub(struct block_list *bl, va_list ap) return 1; } -ACMD(mutearea) { +ACMD(mutearea) +{ int time; if (!*message) { @@ -7372,7 +7747,7 @@ ACMD(me) } safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,270), sd->status.name, tempmes); // *%s %s* - clif->disp_overhead(&sd->bl, atcmd_output); + clif->disp_overhead(&sd->bl, atcmd_output, AREA_CHAT_WOC, NULL); return true; } @@ -7478,49 +7853,71 @@ ACMD(sizeguild) *------------------------------------------*/ ACMD(monsterignore) { - if (!sd->state.monster_ignore) { - sd->state.monster_ignore = 1; + if (!sd->block_action.immune) { + sd->block_action.immune = 1; clif->message(sd->fd, msg_fd(fd,1305)); // You are now immune to attacks. } else { - sd->state.monster_ignore = 0; + sd->block_action.immune = 0; clif->message(sd->fd, msg_fd(fd,1306)); // Returned to normal state. } return true; } -/*========================================== - * @fakename - * => Gives your character a fake name. [Valaris] - *------------------------------------------*/ + +/** + * Temporarily changes the character's name to the specified string. + * + * @code{.herc} + * @fakename {<options>} {<fake_name>} + * @endcode + * + **/ ACMD(fakename) { - if (!*message) - { - if (sd->fakename[0]) - { + if (*message == '\0') { + if (sd->fakename[0] != '\0') { sd->fakename[0] = '\0'; - clif->charnameack(0, &sd->bl); - if( sd->disguise ) - clif->charnameack(sd->fd, &sd->bl); - clif->message(sd->fd, msg_fd(fd,1307)); // Returned to real name. + sd->fakename_options = FAKENAME_OPTION_NONE; + clif->blname_ack(0, &sd->bl); + + if (sd->disguise != 0) // Another packet should be sent so the client updates the name for sd. + clif->blname_ack(sd->fd, &sd->bl); + + clif->message(sd->fd, msg_fd(fd, 1307)); // Returned to real name. return true; } - clif->message(sd->fd, msg_fd(fd,1308)); // You must enter a name. + clif->message(sd->fd, msg_fd(fd, 1308)); // You must enter a name. return false; } - if (strlen(message) < 2) - { - clif->message(sd->fd, msg_fd(fd,1309)); // Fake name must be at least two characters. + int options = FAKENAME_OPTION_NONE; + char buf[NAME_LENGTH] = {'\0'}; + const char *fake_name = NULL; + + if (sscanf(message, "%d %23[^\n]", &options, buf) == 2) { + fake_name = buf; + } else { + options = FAKENAME_OPTION_NONE; + fake_name = message; + } + + if (strlen(fake_name) < 2) { + clif->message(sd->fd, msg_fd(fd, 1309)); // Fake name must be at least two characters. return false; } - safestrncpy(sd->fakename, message, sizeof(sd->fakename)); - clif->charnameack(0, &sd->bl); - if (sd->disguise) // Another packet should be sent so the client updates the name for sd - clif->charnameack(sd->fd, &sd->bl); - clif->message(sd->fd, msg_fd(fd,1310)); // Fake name enabled. + if (options < FAKENAME_OPTION_NONE) + options = FAKENAME_OPTION_NONE; + + safestrncpy(sd->fakename, fake_name, sizeof(sd->fakename)); + sd->fakename_options = options; + clif->blname_ack(0, &sd->bl); + + if (sd->disguise != 0) // Another packet should be sent so the client updates the name for sd. + clif->blname_ack(sd->fd, &sd->bl); + + clif->message(sd->fd, msg_fd(fd, 1310)); // Fake name enabled. return true; } @@ -7528,7 +7925,8 @@ ACMD(fakename) /*========================================== * Ragnarok Resources *------------------------------------------*/ -ACMD(mapflag) { +ACMD(mapflag) +{ #define CHECKFLAG( cmd ) do { if (map->list[ sd->bl.m ].flag.cmd ) clif->message(sd->fd,#cmd);} while(0) #define SETFLAG( cmd ) do { \ if (strcmp( flag_name , #cmd ) == 0) { \ @@ -7551,15 +7949,16 @@ ACMD(mapflag) { CHECKFLAG(noreturn); CHECKFLAG(monster_noteleport); CHECKFLAG(nosave); CHECKFLAG(nobranch); CHECKFLAG(noexppenalty); CHECKFLAG(pvp); CHECKFLAG(pvp_noparty); CHECKFLAG(pvp_noguild); CHECKFLAG(pvp_nightmaredrop); CHECKFLAG(pvp_nocalcrank); CHECKFLAG(gvg_castle); CHECKFLAG(gvg); - CHECKFLAG(gvg_dungeon); CHECKFLAG(gvg_noparty); CHECKFLAG(battleground); CHECKFLAG(nozenypenalty); - CHECKFLAG(notrade); CHECKFLAG(noskill); CHECKFLAG(nowarp); CHECKFLAG(nowarpto); - CHECKFLAG(noicewall); CHECKFLAG(snow); CHECKFLAG(clouds); CHECKFLAG(clouds2); - CHECKFLAG(fog); CHECKFLAG(fireworks); CHECKFLAG(sakura); CHECKFLAG(leaves); - CHECKFLAG(nobaseexp); + CHECKFLAG(gvg_dungeon); CHECKFLAG(gvg_noparty); CHECKFLAG(battleground); CHECKFLAG(cvc); + CHECKFLAG(nozenypenalty); CHECKFLAG(notrade); CHECKFLAG(noskill); CHECKFLAG(nowarp); + CHECKFLAG(nowarpto); CHECKFLAG(noicewall); CHECKFLAG(snow); CHECKFLAG(clouds); + CHECKFLAG(clouds2); CHECKFLAG(fog); CHECKFLAG(fireworks); CHECKFLAG(sakura); + CHECKFLAG(leaves); CHECKFLAG(nobaseexp); CHECKFLAG(nojobexp); CHECKFLAG(nomobloot); CHECKFLAG(nomvploot); CHECKFLAG(nightenabled); CHECKFLAG(nodrop); CHECKFLAG(novending); CHECKFLAG(loadevent); CHECKFLAG(nochat); CHECKFLAG(partylock); CHECKFLAG(guildlock); CHECKFLAG(src4instance); - CHECKFLAG(notomb); CHECKFLAG(nocashshop); CHECKFLAG(noviewid); + CHECKFLAG(notomb); CHECKFLAG(nocashshop); CHECKFLAG(noviewid); CHECKFLAG(town); + CHECKFLAG(nostorage); CHECKFLAG(nogstorage); clif->message(sd->fd," "); clif->message(sd->fd,msg_fd(fd,1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On) clif->message(sd->fd,msg_fd(fd,1313)); // Type "@mapflag available" to list the available mapflags. @@ -7567,48 +7966,54 @@ ACMD(mapflag) { } for (i = 0; flag_name[i]; i++) flag_name[i] = TOLOWER(flag_name[i]); //lowercase - if (strcmp( flag_name , "gvg" ) == 0) { - if( flag && !map->list[sd->bl.m].flag.gvg ) - map->zone_change2(sd->bl.m,strdb_get(map->zone_db, MAP_ZONE_GVG_NAME)); - else if ( !flag && map->list[sd->bl.m].flag.gvg ) - map->zone_change2(sd->bl.m,map->list[sd->bl.m].prev_zone); - } else if ( strcmp( flag_name , "pvp" ) == 0 ) { - if ( flag && !map->list[sd->bl.m].flag.pvp ) - map->zone_change2(sd->bl.m,strdb_get(map->zone_db, MAP_ZONE_PVP_NAME)); - else if ( !flag && map->list[sd->bl.m].flag.pvp ) - map->zone_change2(sd->bl.m,map->list[sd->bl.m].prev_zone); - } else if ( strcmp( flag_name , "battleground" ) == 0 ) { - if ( flag && !map->list[sd->bl.m].flag.battleground ) - map->zone_change2(sd->bl.m,strdb_get(map->zone_db, MAP_ZONE_BG_NAME)); - else if ( !flag && map->list[sd->bl.m].flag.battleground ) - map->zone_change2(sd->bl.m,map->list[sd->bl.m].prev_zone); + if (strcmp(flag_name, "gvg") == 0) { + if (flag && !map->list[sd->bl.m].flag.gvg) + map->zone_change2(sd->bl.m, strdb_get(map->zone_db, MAP_ZONE_GVG_NAME)); + else if (!flag && map->list[sd->bl.m].flag.gvg) + map->zone_change2(sd->bl.m, map->list[sd->bl.m].prev_zone); + } else if (strcmp(flag_name, "pvp") == 0) { + if (flag && !map->list[sd->bl.m].flag.pvp) + map->zone_change2(sd->bl.m, strdb_get(map->zone_db, MAP_ZONE_PVP_NAME)); + else if (!flag && map->list[sd->bl.m].flag.pvp) + map->zone_change2(sd->bl.m, map->list[sd->bl.m].prev_zone); + } else if (strcmp(flag_name, "battleground") == 0) { + if (flag && !map->list[sd->bl.m].flag.battleground) + map->zone_change2(sd->bl.m, strdb_get(map->zone_db, MAP_ZONE_BG_NAME)); + else if (!flag && map->list[sd->bl.m].flag.battleground) + map->zone_change2(sd->bl.m, map->list[sd->bl.m].prev_zone); + } else if (strcmp(flag_name, "cvc") == 0) { + if (flag && !map->list[sd->bl.m].flag.cvc) + map->zone_change2(sd->bl.m, strdb_get(map->zone_db, MAP_ZONE_CVC_NAME)); + else if (!flag && map->list[sd->bl.m].flag.cvc) + map->zone_change2(sd->bl.m, map->list[sd->bl.m].prev_zone); } SETFLAG(autotrade); SETFLAG(allowks); SETFLAG(nomemo); SETFLAG(noteleport); SETFLAG(noreturn); SETFLAG(monster_noteleport); SETFLAG(nosave); SETFLAG(nobranch); SETFLAG(noexppenalty); SETFLAG(pvp); SETFLAG(pvp_noparty); SETFLAG(pvp_noguild); SETFLAG(pvp_nightmaredrop); SETFLAG(pvp_nocalcrank); SETFLAG(gvg_castle); SETFLAG(gvg); - SETFLAG(gvg_dungeon); SETFLAG(gvg_noparty); SETFLAG(battleground); SETFLAG(nozenypenalty); - SETFLAG(notrade); SETFLAG(noskill); SETFLAG(nowarp); SETFLAG(nowarpto); - SETFLAG(noicewall); SETFLAG(snow); SETFLAG(clouds); SETFLAG(clouds2); - SETFLAG(fog); SETFLAG(fireworks); SETFLAG(sakura); SETFLAG(leaves); - SETFLAG(nobaseexp); - SETFLAG(nojobexp); SETFLAG(nomobloot); SETFLAG(nomvploot); SETFLAG(nightenabled); - SETFLAG(nodrop); SETFLAG(novending); SETFLAG(loadevent); - SETFLAG(nochat); SETFLAG(partylock); SETFLAG(guildlock); SETFLAG(src4instance); - SETFLAG(notomb); SETFLAG(nocashshop); SETFLAG(noviewid); - - clif->message(sd->fd,msg_fd(fd,1314)); // Invalid flag name or flag. - clif->message(sd->fd,msg_fd(fd,1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On) - clif->message(sd->fd,msg_fd(fd,1315)); // Available Flags: - clif->message(sd->fd,"----------------------------------"); - clif->message(sd->fd,"town, autotrade, allowks, nomemo, noteleport, noreturn, monster_noteleport, nosave,"); - clif->message(sd->fd,"nobranch, noexppenalty, pvp, pvp_noparty, pvp_noguild, pvp_nightmaredrop,"); - clif->message(sd->fd,"pvp_nocalcrank, gvg_castle, gvg, gvg_dungeon, gvg_noparty, battleground,"); - clif->message(sd->fd,"nozenypenalty, notrade, noskill, nowarp, nowarpto, noicewall, snow, clouds, clouds2,"); - clif->message(sd->fd,"fog, fireworks, sakura, leaves, nobaseexp, nojobexp, nomobloot,"); - clif->message(sd->fd,"nomvploot, nightenabled, nodrop, novending, loadevent, nochat, partylock,"); - clif->message(sd->fd,"guildlock, src4instance, notomb, nocashshop, noviewid"); + SETFLAG(gvg_dungeon); SETFLAG(gvg_noparty); SETFLAG(battleground); SETFLAG(cvc); + SETFLAG(nozenypenalty); SETFLAG(notrade); SETFLAG(noskill); SETFLAG(nowarp); + SETFLAG(nowarpto); SETFLAG(noicewall); SETFLAG(snow); SETFLAG(clouds); + SETFLAG(clouds2); SETFLAG(fog); SETFLAG(fireworks); SETFLAG(sakura); + SETFLAG(leaves); SETFLAG(nobaseexp); SETFLAG(nojobexp); SETFLAG(nomobloot); + SETFLAG(nomvploot); SETFLAG(nightenabled); SETFLAG(nodrop); SETFLAG(novending); + SETFLAG(loadevent); SETFLAG(nochat); SETFLAG(partylock); SETFLAG(guildlock); + SETFLAG(src4instance); SETFLAG(notomb); SETFLAG(nocashshop); SETFLAG(noviewid); + SETFLAG(town); SETFLAG(nostorage); SETFLAG(nogstorage); + + + clif->message(sd->fd, msg_fd(fd, 1314)); // Invalid flag name or flag. + clif->message(sd->fd, msg_fd(fd, 1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On) + clif->message(sd->fd, msg_fd(fd, 1315)); // Available Flags: + clif->message(sd->fd, "----------------------------------"); + clif->message(sd->fd, "town, autotrade, allowks, nomemo, noteleport, noreturn, monster_noteleport, nosave,"); + clif->message(sd->fd, "nobranch, noexppenalty, pvp, pvp_noparty, pvp_noguild, pvp_nightmaredrop,"); + clif->message(sd->fd, "pvp_nocalcrank, gvg_castle, gvg, gvg_dungeon, gvg_noparty, battleground, cvc,"); + clif->message(sd->fd, "nozenypenalty, notrade, noskill, nowarp, nowarpto, noicewall, snow, clouds, clouds2,"); + clif->message(sd->fd, "fog, fireworks, sakura, leaves, nobaseexp, nojobexp, nomobloot,"); + clif->message(sd->fd, "nomvploot, nightenabled, nodrop, novending, loadevent, nochat, partylock,"); + clif->message(sd->fd, "guildlock, src4instance, notomb, nocashshop, noviewid, nostorage, nogstorage"); #undef CHECKFLAG #undef SETFLAG @@ -7669,7 +8074,7 @@ ACMD(showdelay) ACMD(invite) { unsigned int did = sd->duel_group; - struct map_session_data *target_sd = map->nick2sd(message); + struct map_session_data *target_sd = map->nick2sd(message, true); if (did == 0) { @@ -7711,7 +8116,8 @@ ACMD(invite) return true; } -ACMD(duel) { +ACMD(duel) +{ unsigned int maxpl = 0; if (sd->duel_group > 0) { @@ -7725,10 +8131,11 @@ ACMD(duel) { return false; } - if (!duel->checktime(sd)) { + int64 diff = duel->difftime(sd); + if (diff > 0) { char output[CHAT_SIZE_MAX]; - // "Duel: You can take part in duel only one time per %d minutes." - sprintf(output, msg_fd(fd,356), battle_config.duel_time_interval); + // "Duel: You can take part in duel again after %d secconds." + sprintf(output, msg_fd(fd,356), (int)diff); clif->message(fd, output); return false; } @@ -7741,7 +8148,7 @@ ACMD(duel) { } duel->create(sd, maxpl); } else { - struct map_session_data *target_sd = map->nick2sd(message); + struct map_session_data *target_sd = map->nick2sd(message, true); if (target_sd != NULL) { unsigned int newduel; if ((newduel = duel->create(sd, 2)) != -1) { @@ -7764,7 +8171,8 @@ ACMD(duel) { return true; } -ACMD(leave) { +ACMD(leave) +{ if (sd->duel_group <= 0) { // "Duel: @leave without @duel." clif->message(fd, msg_fd(fd,358)); @@ -7775,11 +8183,13 @@ ACMD(leave) { return true; } -ACMD(accept) { - if (!duel->checktime(sd)) { +ACMD(accept) +{ + int64 diff = duel->difftime(sd); + if (diff > 0) { char output[CHAT_SIZE_MAX]; - // "Duel: You can take part in duel only one time per %d minutes." - sprintf(output, msg_fd(fd,356), battle_config.duel_time_interval); + // "Duel: You can take part in duel again after %d seconds." + sprintf(output, msg_fd(fd,356), (int)diff); clif->message(fd, output); return false; } @@ -7803,7 +8213,8 @@ ACMD(accept) { return true; } -ACMD(reject) { +ACMD(reject) +{ if (sd->duel_invite <= 0) { // "Duel: @reject without invitation." clif->message(fd, msg_fd(fd,362)); @@ -7823,7 +8234,6 @@ ACMD(cash) { char output[128]; int value; - int ret=0; if (!*message || (value = atoi(message)) == 0) { clif->message(fd, msg_fd(fd,1322)); // Please enter an amount. @@ -7831,39 +8241,39 @@ ACMD(cash) } if (!strcmpi(info->command,"cash")) { - if( value > 0 ) { - if( (ret=pc->getcash(sd, value, 0)) >= 0){ + if (value > 0) { + if ((pc->getcash(sd, value, 0)) >= 0) { // If this option is set, the message is already sent by pc function - if( !battle_config.cashshop_show_points ){ - sprintf(output, msg_fd(fd,505), ret, sd->cashPoints); - clif_disp_onlyself(sd, output, strlen(output)); + if (!battle_config.cashshop_show_points) { + sprintf(output, msg_fd(fd,505), value, sd->cashPoints); + clif_disp_onlyself(sd, output); clif->message(fd, output); } } else clif->message(fd, msg_fd(fd,149)); // Unable to decrease the number/value. } else { - if( (ret=pc->paycash(sd, -value, 0)) >= 0){ - sprintf(output, msg_fd(fd,410), ret, sd->cashPoints); - clif_disp_onlyself(sd, output, strlen(output)); + if ((pc->paycash(sd, -value, 0)) >= 0) { + sprintf(output, msg_fd(fd,410), -value, sd->cashPoints); + clif_disp_onlyself(sd, output); clif->message(fd, output); } else clif->message(fd, msg_fd(fd,41)); // Unable to decrease the number/value. } } else { // @points - if( value > 0 ) { - if( (ret=pc->getcash(sd, 0, value)) >= 0) { + if (value > 0) { + if ((pc->getcash(sd, 0, value)) >= 0) { // If this option is set, the message is already sent by pc function - if( !battle_config.cashshop_show_points ){ - sprintf(output, msg_fd(fd,506), ret, sd->kafraPoints); - clif_disp_onlyself(sd, output, strlen(output)); + if (!battle_config.cashshop_show_points) { + sprintf(output, msg_fd(fd,506), value, sd->kafraPoints); + clif_disp_onlyself(sd, output); clif->message(fd, output); } } else clif->message(fd, msg_fd(fd,149)); // Unable to decrease the number/value. } else { - if( (ret=pc->paycash(sd, -value, -value)) >= 0){ - sprintf(output, msg_fd(fd,411), ret, sd->kafraPoints); - clif_disp_onlyself(sd, output, strlen(output)); + if ((pc->paycash(sd, -value, -value)) >= 0) { + sprintf(output, msg_fd(fd,411), -value, sd->kafraPoints); + clif_disp_onlyself(sd, output); clif->message(fd, output); } else clif->message(fd, msg_fd(fd,41)); // Unable to decrease the number/value. @@ -7874,7 +8284,8 @@ ACMD(cash) } // @clone/@slaveclone/@evilclone <playername> [Valaris] -ACMD(clone) { +ACMD(clone) +{ int x=0,y=0,flag=0,master=0,i=0; struct map_session_data *pl_sd=NULL; @@ -7883,7 +8294,7 @@ ACMD(clone) { return false; } - if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message, true)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -7957,8 +8368,8 @@ ACMD(request) } safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,278), message); // (@request): %s - intif->wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output); - clif_disp_onlyself(sd, atcmd_output, strlen(atcmd_output)); + pc->wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output); + clif_disp_onlyself(sd, atcmd_output); clif->message(sd->fd,msg_fd(fd,279)); // @request sent. return true; } @@ -7974,6 +8385,15 @@ ACMD(feelreset) return true; } +// Reset hatred targets [Wolfie] +ACMD(hatereset) +{ + pc->resethate(sd); + clif->message(fd, msg_fd(fd, 979)); // Reset 'Hatred' targets. + + return true; +} + /*========================================== * AUCTION SYSTEM *------------------------------------------*/ @@ -7992,7 +8412,8 @@ ACMD(auction) /*========================================== * Kill Steal Protection *------------------------------------------*/ -ACMD(ksprotection) { +ACMD(ksprotection) +{ if( sd->state.noks ) { sd->state.noks = KSPROTECT_NONE; clif->message(fd, msg_fd(fd,1325)); // [ K.S Protection Inactive ] @@ -8057,8 +8478,8 @@ ACMD(itemlist) if( strcmpi(info->command, "storagelist") == 0 ) { location = "storage"; - items = sd->status.storage.items; - size = MAX_STORAGE; + items = VECTOR_DATA(sd->storage.item); + size = VECTOR_LENGTH(sd->storage.item); } else if( strcmpi(info->command, "cartlist") == 0 ) { location = "cart"; items = sd->status.cart; @@ -8066,7 +8487,7 @@ ACMD(itemlist) } else if( strcmpi(info->command, "itemlist") == 0 ) { location = "inventory"; items = sd->status.inventory; - size = MAX_INVENTORY; + size = sd->status.inventorySize; } else return false; @@ -8079,7 +8500,7 @@ ACMD(itemlist) const struct item* it = &items[i]; struct item_data* itd; - if( it->nameid == 0 || (itd = itemdb->exists(it->nameid)) == NULL ) + if (it->nameid == 0 || (itd = itemdb->exists(it->nameid)) == NULL) continue; counter += it->amount; @@ -8240,7 +8661,7 @@ ACMD(stats) output_table[14].value = sd->change_level_2nd; output_table[15].value = sd->change_level_3rd; - sprintf(job_jobname, "Job - %s %s", pc->job_name(sd->status.class_), "(level %d)"); + sprintf(job_jobname, "Job - %s %s", pc->job_name(sd->status.class), "(level %d)"); sprintf(output, msg_fd(fd,53), sd->status.name); // '%s' stats: clif->message(fd, output); @@ -8252,7 +8673,8 @@ ACMD(stats) return true; } -ACMD(delitem) { +ACMD(delitem) +{ char item_name[100]; int nameid, amount = 0, total, idx; struct item_data* id; @@ -8313,7 +8735,8 @@ ACMD(delitem) { /*========================================== * Custom Fonts *------------------------------------------*/ -ACMD(font) { +ACMD(font) +{ int font_id; font_id = atoi(message); @@ -8348,7 +8771,7 @@ ACMD(font) { /*========================================== * type: 1 = commands (@), 2 = charcommands (#) *------------------------------------------*/ -void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommandType type) +static void atcommand_commands_sub(struct map_session_data *sd, const int fd, AtCommandType type) { char line_buff[CHATBOX_SIZE]; char* cur = line_buff; @@ -8396,6 +8819,38 @@ void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommand dbi_destroy(iter); clif->message(fd,line_buff); + if (atcommand->binding_count > 0) { + int i, count_bind = 0; + int gm_lvl = pc_get_group_level(sd); + + for (i = 0; i < atcommand->binding_count; i++) { + if (gm_lvl >= ((type == COMMAND_ATCOMMAND) ? atcommand->binding[i]->group_lv : atcommand->binding[i]->group_lv_char) + || (type == COMMAND_ATCOMMAND && atcommand->binding[i]->at_groups[pcg->get_idx(sd->group)] > 0) + || (type == COMMAND_CHARCOMMAND && atcommand->binding[i]->char_groups[pcg->get_idx(sd->group)] > 0)) { + size_t slen = strlen(atcommand->binding[i]->command); + if (count_bind == 0) { + cur = line_buff; + memset(line_buff, ' ', CHATBOX_SIZE); + line_buff[CHATBOX_SIZE - 1] = 0; + clif->message(fd, "------------------"); + clif->message(fd, "Custom commands:"); + } + if (slen + cur - line_buff >= CHATBOX_SIZE) { + clif->message(fd, line_buff); + cur = line_buff; + memset(line_buff, ' ', CHATBOX_SIZE); + line_buff[CHATBOX_SIZE - 1] = 0; + } + memcpy(cur, atcommand->binding[i]->command, slen); + cur += slen + (10 - slen % 10); + count_bind++; + } + } + if (count_bind > 0) + clif->message(fd, line_buff); // Last Line + count += count_bind; + } + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,274), count); // "%d commands found." clif->message(fd, atcmd_output); @@ -8420,26 +8875,29 @@ ACMD(charcommands) return true; } -/* for new mounts */ +/* For new mounts */ ACMD(cashmount) { if (pc_hasmount(sd)) { - clif->message(fd, msg_fd(fd,1476)); // You are already mounting something else + clif->message(fd, msg_fd(fd, 1476)); // You are already mounting something else return false; } - clif->message(sd->fd,msg_fd(fd,1362)); // NOTICE: If you crash with mount your LUA is outdated. + clif->message(sd->fd, msg_fd(fd, 1362)); // NOTICE: If you crash with mount your LUA is outdated. + if (!sd->sc.data[SC_ALL_RIDING]) { - clif->message(sd->fd,msg_fd(fd,1363)); // You have mounted. - sc_start(NULL, &sd->bl, SC_ALL_RIDING, 100, 25, INFINITE_DURATION); + clif->message(sd->fd, msg_fd(fd, 1363)); // You have mounted. + sc_start(NULL, &sd->bl, SC_ALL_RIDING, 100, battle_config.boarding_halter_speed, INFINITE_DURATION); } else { - clif->message(sd->fd,msg_fd(fd,1364)); // You have released your mount. + clif->message(sd->fd, msg_fd(fd, 1364)); // You have released your mount. status_change_end(&sd->bl, SC_ALL_RIDING, INVALID_TIMER); } + return true; } -ACMD(accinfo) { +ACMD(accinfo) +{ char query[NAME_LENGTH]; if (!*message || strlen(message) > NAME_LENGTH ) { @@ -8504,19 +8962,19 @@ ACMD(set) const char *str = NULL; switch (reg[0]) { case '@': - str = pc->readregstr(sd, script->add_str(reg)); + str = pc->readregstr(sd, script->add_variable(reg)); break; case '$': - str = mapreg->readregstr(script->add_str(reg)); + str = mapreg->readregstr(script->add_variable(reg)); break; case '#': if (reg[1] == '#') - str = pc_readaccountreg2str(sd, script->add_str(reg));// global + str = pc_readaccountreg2str(sd, script->add_variable(reg));// global else - str = pc_readaccountregstr(sd, script->add_str(reg));// local + str = pc_readaccountregstr(sd, script->add_variable(reg));// local break; default: - str = pc_readglobalreg_str(sd, script->add_str(reg)); + str = pc_readglobalreg_str(sd, script->add_variable(reg)); break; } if (str == NULL || str[0] == '\0') { @@ -8532,19 +8990,19 @@ ACMD(set) data->type = C_INT; switch( reg[0] ) { case '@': - data->u.num = pc->readreg(sd, script->add_str(reg)); + data->u.num = pc->readreg(sd, script->add_variable(reg)); break; case '$': - data->u.num = mapreg->readreg(script->add_str(reg)); + data->u.num = mapreg->readreg(script->add_variable(reg)); break; case '#': if( reg[1] == '#' ) - data->u.num = pc_readaccountreg2(sd, script->add_str(reg));// global + data->u.num = pc_readaccountreg2(sd, script->add_variable(reg));// global else - data->u.num = pc_readaccountreg(sd, script->add_str(reg));// local + data->u.num = pc_readaccountreg(sd, script->add_variable(reg));// local break; default: - data->u.num = pc_readglobalreg(sd, script->add_str(reg)); + data->u.num = pc_readglobalreg(sd, script->add_variable(reg)); break; } } @@ -8568,12 +9026,16 @@ ACMD(set) aFree(data); return true; } -ACMD(reloadquestdb) { + +ACMD(reloadquestdb) +{ quest->reload(); clif->message(fd, msg_fd(fd,1377)); // Quest database has been reloaded. return true; } -ACMD(addperm) { + +ACMD(addperm) +{ int perm_size = pcg->permission_count; bool add = (strcmpi(info->command, "addperm") == 0) ? true : false; int i; @@ -8629,22 +9091,60 @@ ACMD(addperm) { return true; } + +/** + * Unloads a script file. + * Note: Be aware that some changes made by NPC are not reverted on unload. See doc/atcommands.txt for details. + * + * @code{.herc} + * @unloadnpcfile <path> {<flag>} + * @endcode + * + **/ ACMD(unloadnpcfile) { - if (!*message) { - clif->message(fd, msg_fd(fd,1385)); // Usage: @unloadnpcfile <file name> + char format[20]; + + snprintf(format, sizeof(format), "%%%ds %%1d", MAX_DIR_PATH); + + char file_path[MAX_DIR_PATH + 1] = {'\0'}; + int flag = 1; + + if (*message == '\0' || (sscanf(message, format, file_path, &flag) < 1)) { + clif->message(fd, msg_fd(fd, 1385)); /// Usage: @unloadnpcfile <path> {<flag>} return false; } - if (npc->unloadfile(message)) { - clif->message(fd, msg_fd(fd,1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed. - } else { - clif->message(fd, msg_fd(fd,1387)); // File not found. + if (!exists(file_path)) { + clif->message(fd, msg_fd(fd, 1387)); /// File not found. return false; } + + if (!is_file(file_path)) { + clif->message(fd, msg_fd(fd, 1518)); /// Not a file. + return false; + } + + FILE *fp = fopen(file_path, "r"); + + if (fp == NULL) { + clif->message(fd, msg_fd(fd, 1519)); /// Can't open file. + return false; + } + + fclose(fp); + + if (!npc->unloadfile(file_path, (flag != 0))) { + clif->message(fd, msg_fd(fd, 1517)); /// Script could not be unloaded. + return false; + } + + clif->message(fd, msg_fd(fd, 1386)); /// File unloaded. Be aware that... return true; } -ACMD(cart) { + +ACMD(cart) +{ #define MC_CART_MDFY(x,idx) do { \ sd->status.skill[idx].id = (x)?MC_PUSHCART:0; \ sd->status.skill[idx].lv = (x)?1:0; \ @@ -8653,7 +9153,7 @@ ACMD(cart) { int val = atoi(message); bool need_skill = pc->checkskill(sd, MC_PUSHCART) ? false : true; - unsigned int index = skill->get_index(MC_PUSHCART); + int index = skill->get_index(MC_PUSHCART); if (!*message || val < 0 || val > MAX_CARTS) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1390),command,MAX_CARTS); // Unknown Cart (usage: %s <0-%d>). @@ -8686,6 +9186,7 @@ ACMD(cart) { return true; #undef MC_CART_MDFY } + /* [Ind/Hercules] */ ACMD(join) { @@ -8729,8 +9230,10 @@ ACMD(join) return true; } + /* [Ind/Hercules] */ -void atcommand_channel_help(int fd, const char *command, bool can_create) { +static void atcommand_channel_help(int fd, const char *command, bool can_create) +{ nullpo_retv(command); safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1404),command); // %s failed. clif->message(fd, atcmd_output); @@ -8759,9 +9262,7 @@ void atcommand_channel_help(int fd, const char *command, bool can_create) { clif->message(fd, msg_fd(fd,1428));// - binds global chat to <channel name>, making anything you type in global be sent to the channel safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1429),command);// -- %s unbind clif->message(fd, atcmd_output); - clif->message(fd, msg_fd(fd,1430));// - unbinds your global chat from its attached channel (if binded) - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1429),command);// -- %s unbind - clif->message(fd, atcmd_output); + clif->message(fd, msg_fd(fd,1430));// - unbinds your global chat from its attached channel (if bound) if( can_create ) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1456),command);// -- %s ban <channel name> <character name> clif->message(fd, atcmd_output); @@ -8780,11 +9281,12 @@ void atcommand_channel_help(int fd, const char *command, bool can_create) { clif->message(fd, msg_fd(fd,1463));// - adds or removes <option name> with <option value> to <channel name> channel } } + /* [Ind/Hercules] */ -ACMD(channel) { +ACMD(channel) +{ struct channel_data *chan; char subcmd[HCS_NAME_LENGTH], sub1[HCS_NAME_LENGTH], sub2[HCS_NAME_LENGTH], sub3[HCS_NAME_LENGTH]; - unsigned char k = 0; sub1[0] = sub2[0] = sub3[0] = '\0'; if (!*message || sscanf(message, "%19s %19s %19s %19s", subcmd, sub1, sub2, sub3) < 1) { @@ -8821,7 +9323,7 @@ ACMD(channel) { } else if (strcmpi(subcmd,"list") == 0) { // sub1 = list type; sub2 = unused; sub3 = unused if (sub1[0] != '\0' && strcmpi(sub1,"colors") == 0) { - for (k = 0; k < channel->config->colors_count; k++) { + for (int k = 0; k < channel->config->colors_count; k++) { safesnprintf(atcmd_output, sizeof(atcmd_output), "[ %s list colors ] : %s", command, channel->config->colors_name[k]); clif->messagecolor_self(fd, channel->config->colors[k], atcmd_output); @@ -8850,6 +9352,7 @@ ACMD(channel) { } } else if (strcmpi(subcmd,"setcolor") == 0) { // sub1 = channel name; sub2 = color; sub3 = unused + int k; if (sub1[0] != '#') { clif->message(fd, msg_fd(fd,1405));// Channel name must start with a '#' return false; @@ -8867,10 +9370,7 @@ ACMD(channel) { return false; } - for (k = 0; k < channel->config->colors_count; k++) { - if (strcmpi(sub2, channel->config->colors_name[k]) == 0) - break; - } + ARR_FIND(0, channel->config->colors_count, k, strcmpi(sub2, channel->config->colors_name[k]) == 0); if (k == channel->config->colors_count) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1411), sub2);// Unknown color '%s' clif->message(fd, atcmd_output); @@ -8881,51 +9381,45 @@ ACMD(channel) { clif->message(fd, atcmd_output); } else if (strcmpi(subcmd,"leave") == 0) { // sub1 = channel name; sub2 = unused; sub3 = unused + int k; if (sub1[0] != '#') { clif->message(fd, msg_fd(fd,1405));// Channel name must start with a '#' return false; } - for (k = 0; k < sd->channel_count; k++) { - if (strcmpi(sub1+1,sd->channels[k]->name) == 0) - break; - } - if (k == sd->channel_count) { + ARR_FIND(0, VECTOR_LENGTH(sd->channels), k, strcmpi(sub1 + 1, VECTOR_INDEX(sd->channels, k)->name) == 0); + if (k == VECTOR_LENGTH(sd->channels)) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1425),sub1);// You're not part of the '%s' channel clif->message(fd, atcmd_output); return false; } - if (sd->channels[k]->type == HCS_TYPE_ALLY) { - do { - for (k = 0; k < sd->channel_count; k++) { - if (sd->channels[k]->type == HCS_TYPE_ALLY) { - channel->leave(sd->channels[k],sd); - break; - } + if (VECTOR_INDEX(sd->channels, k)->type == HCS_TYPE_ALLY) { + for (k = VECTOR_LENGTH(sd->channels) - 1; k >= 0; k--) { + // Loop downward to avoid issues when channel->leave() compacts the array + if (VECTOR_INDEX(sd->channels, k)->type == HCS_TYPE_ALLY) { + channel->leave(VECTOR_INDEX(sd->channels, k), sd); } - } while (k != sd->channel_count); + } } else { - channel->leave(sd->channels[k],sd); + channel->leave(VECTOR_INDEX(sd->channels, k), sd); } safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1426),sub1); // You've left the '%s' channel clif->message(fd, atcmd_output); } else if (strcmpi(subcmd,"bindto") == 0) { // sub1 = channel name; sub2 = unused; sub3 = unused + int k; if (sub1[0] != '#') { clif->message(fd, msg_fd(fd,1405));// Channel name must start with a '#' return false; } - for (k = 0; k < sd->channel_count; k++) { - if (strcmpi(sub1+1,sd->channels[k]->name) == 0) - break; - } - if (k == sd->channel_count) { + ARR_FIND(0, VECTOR_LENGTH(sd->channels), k, strcmpi(sub1 + 1, VECTOR_INDEX(sd->channels, k)->name) == 0); + if (k == VECTOR_LENGTH(sd->channels)) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1425),sub1);// You're not part of the '%s' channel clif->message(fd, atcmd_output); return false; } - sd->gcbind = sd->channels[k]; + sd->gcbind = VECTOR_INDEX(sd->channels, k); safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1431),sub1); // Your global chat is now bound to the '%s' channel clif->message(fd, atcmd_output); } else if (strcmpi(subcmd,"unbind") == 0) { @@ -8962,7 +9456,7 @@ ACMD(channel) { return false; } - if (sub4[0] == '\0' || (pl_sd = map->nick2sd(sub4)) == NULL) { + if (sub4[0] == '\0' || (pl_sd = map->nick2sd(sub4, true)) == NULL) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1434), sub4);// Player '%s' was not found clif->message(fd, atcmd_output); return false; @@ -9009,7 +9503,7 @@ ACMD(channel) { clif->message(fd, atcmd_output); return false; } - if (sub4[0] == '\0' || (pl_sd = map->nick2sd(sub4)) == NULL) { + if (sub4[0] == '\0' || (pl_sd = map->nick2sd(sub4, true)) == NULL) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1434), sub4);// Player '%s' was not found clif->message(fd, atcmd_output); return false; @@ -9097,6 +9591,7 @@ ACMD(channel) { dbi_destroy(iter); } else if (strcmpi(subcmd,"setopt") == 0) { // sub1 = channel name; sub2 = option name; sub3 = value + int k; const char* opt_str[3] = { "None", "JoinAnnounce", @@ -9152,8 +9647,8 @@ ACMD(channel) { } else { int v = atoi(sub3); if (k == HCS_OPT_MSG_DELAY) { - if (v < 0 || v > 10) { - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1451), v, opt_str[k]);// value '%d' for option '%s' is out of range (limit is 0-10) + if (v < 0 || v > channel->config->channel_opt_msg_delay) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1451), v, opt_str[k], channel->config->channel_opt_msg_delay);// value '%d' for option '%s' is out of range (limit is 0-%d) clif->message(fd, atcmd_output); return false; } @@ -9200,8 +9695,10 @@ ACMD(channel) { } return true; } + /* debug only, delete after */ -ACMD(fontcolor) { +ACMD(fontcolor) +{ unsigned char k; if (!*message) { @@ -9233,7 +9730,9 @@ ACMD(fontcolor) { return true; } -ACMD(searchstore){ + +ACMD(searchstore) +{ int val = atoi(message); switch (val) { @@ -9248,7 +9747,12 @@ ACMD(searchstore){ searchstore->open(sd, 99, val); return true; } -ACMD(costume){ + +/*========================================== +* @costume +*------------------------------------------*/ +ACMD(costume) +{ const char* names[] = { "Wedding", "Xmas", @@ -9257,6 +9761,9 @@ ACMD(costume){ #if PACKETVER >= 20131218 "Oktoberfest", #endif +#if PACKETVER >= 20141022 + "Summer2", +#endif }; const int name2id[] = { SC_WEDDING, @@ -9266,41 +9773,54 @@ ACMD(costume){ #if PACKETVER >= 20131218 SC_OKTOBERFEST, #endif +#if PACKETVER >= 20141022 + SC_DRESS_UP, +#endif }; unsigned short k = 0, len = ARRAYLENGTH(names); + bool isChangeDress = (strcmpi(info->command, "changedress") == 0 || strcmpi(info->command, "nocosplay") == 0); + if (!*message) { - for( k = 0; k < len; k++ ) { - if( sd->sc.data[name2id[k]] ) { - safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,1473),names[k]);//Costume '%s' removed. - clif->message(sd->fd,atcmd_output); - status_change_end(&sd->bl,name2id[k],INVALID_TIMER); + for (k = 0; k < len; k++) { + if (sd->sc.data[name2id[k]]) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1473), names[k]); // Costume '%s' removed. + clif->message(sd->fd, atcmd_output); + status_change_end(&sd->bl, name2id[k], INVALID_TIMER); return true; } } - clif->message(sd->fd,msg_fd(fd,1472)); - for( k = 0; k < len; k++ ) { - safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,1471),names[k]);//-- %s - clif->message(sd->fd,atcmd_output); + + if (isChangeDress) + return true; + clif->message(sd->fd, msg_fd(fd, 1472)); // - Available Costumes + + for (k = 0; k < len; k++) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1471), names[k]); //-- %s + clif->message(sd->fd, atcmd_output); } return false; } - for( k = 0; k < len; k++ ) { - if( sd->sc.data[name2id[k]] ) { - safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,1470),names[k]);// You're already with a '%s' costume, type '@costume' to remove it. - clif->message(sd->fd,atcmd_output); + if (isChangeDress) + return true; + + for (k = 0; k < len; k++) { + if (sd->sc.data[name2id[k]]) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1470), names[k]); // You're already with a '%s' costume, type '@costume' to remove it. + clif->message(sd->fd, atcmd_output); return false; } } - for( k = 0; k < len; k++ ) { - if( strcmpi(message,names[k]) == 0 ) + for (k = 0; k < len; k++) { + if (strcmpi(message,names[k]) == 0) break; } - if( k == len ) { - safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,1469),message);// '%s' is not a known costume - clif->message(sd->fd,atcmd_output); + + if (k == len) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 1469), message); // '%s' is not a known costume + clif->message(sd->fd, atcmd_output); return false; } @@ -9308,10 +9828,12 @@ ACMD(costume){ return true; } + /* for debugging purposes (so users can easily provide us with debug info) */ /* should be trashed as soon as its no longer necessary */ -ACMD(skdebug) { - safesnprintf(atcmd_output, sizeof(atcmd_output),"second: %u; third: %u", sd->sktree.second, sd->sktree.third); +ACMD(skdebug) +{ + safesnprintf(atcmd_output, sizeof(atcmd_output),"second: %d; third: %d", sd->sktree.second, sd->sktree.third); clif->message(fd,atcmd_output); safesnprintf(atcmd_output, sizeof(atcmd_output),"pc_calc_skilltree_normalize_job: %d",pc->calc_skilltree_normalize_job(sd)); clif->message(fd,atcmd_output); @@ -9321,10 +9843,12 @@ ACMD(skdebug) { clif->message(fd,atcmd_output); return true; } + /** * cooldown-debug **/ -ACMD(cddebug) { +ACMD(cddebug) +{ int i; struct skill_cd* cd = NULL; @@ -9345,7 +9869,7 @@ ACMD(cddebug) { } if (!cd || (*message && !strcmpi(message,"reset"))) { - for(i = 0; i < MAX_SKILL; i++) { + for (i = 0; i < MAX_SKILL_DB; i++) { if( sd->blockskill[i] ) { clif->messages(fd,"Found skill '%s', unblocking...",skill->dbs->db[i].name); sd->blockskill[i] = false; @@ -9369,7 +9893,8 @@ ACMD(cddebug) { /** * **/ -ACMD(lang) { +ACMD(lang) +{ uint8 i; if (!*message) { @@ -9401,12 +9926,180 @@ ACMD(lang) { return true; } + +ACMD(claninfo) +{ + struct DBIterator *iter = db_iterator(clan->db); + struct clan *c; + int i, count; + + for (c = dbi_first(iter); dbi_exists(iter); c = dbi_next(iter)) { + safesnprintf(atcmd_output, sizeof(atcmd_output), "Clan #%d:", c->clan_id); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Name: %s", c->name); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Constant: %s", c->constant); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Master: %s", c->master); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Map: %s", c->map); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Max Member: %d", c->max_member); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Kick Time: %dh", c->kick_time / 3600); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Check Time: %dh", c->check_time / 3600000); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Connected Members: %d", c->connect_member); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Total Members: %d", c->member_count); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Allies: %d", VECTOR_LENGTH(c->allies)); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + count = 0; + for (i = 0; i < VECTOR_LENGTH(c->allies); i++) { + struct clan_relationship *ally = &VECTOR_INDEX(c->allies, i); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- - Ally #%d (Id: %d): %s", i + 1, ally->clan_id, ally->constant); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + count++; + } + + if (count == 0) { + clif->messagecolor_self(fd, COLOR_DEFAULT, "- - No Allies Found!"); + } + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- Antagonists: %d", VECTOR_LENGTH(c->antagonists)); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + + count = 0; + for (i = 0; i < VECTOR_LENGTH(c->antagonists); i++) { + struct clan_relationship *antagonist = &VECTOR_INDEX(c->antagonists, i); + + safesnprintf(atcmd_output, sizeof(atcmd_output), "- - Antagonist #%d (Id: %d): %s", i + 1, antagonist->clan_id, antagonist->constant); + clif->messagecolor_self(fd, COLOR_DEFAULT, atcmd_output); + count++; + } + + if (count == 0) { + clif->messagecolor_self(fd, COLOR_DEFAULT, "- - No Antagonists Found!"); + } + + clif->messagecolor_self(fd, COLOR_DEFAULT, "============================"); + } + dbi_destroy(iter); + return true; +} + +/** + * Clan System: Joins in the given clan + */ +ACMD(joinclan) +{ + int clan_id; + + if (*message == '\0') { + clif->message(fd, "Please enter a Clan ID (usage: @joinclan <clan ID>)."); + return false; + } + if (sd->status.clan_id != 0) { + clif->messagecolor_self(fd, COLOR_RED, "You are already in a clan."); + return false; + } else if (sd->status.guild_id != 0) { + clif->messagecolor_self(fd, COLOR_RED, "You must leave your guild before enter in a clan."); + return false; + } + + clan_id = atoi(message); + if (clan_id <= 0) { + clif->messagecolor_self(fd, COLOR_RED, "Invalid Clan ID."); + return false; + } + if (!clan->join(sd, clan_id)) { + clif->messagecolor_self(fd, COLOR_RED, "The clan couldn't be joined."); + return false; + } + return true; +} + +/** + * Clan System: Leaves current clan + */ +ACMD(leaveclan) +{ + if (sd->status.clan_id == 0) { + clif->messagecolor_self(fd, COLOR_RED, "You aren't in a clan."); + return false; + } + if (!clan->leave(sd, false)) { + clif->messagecolor_self(fd, COLOR_RED, "Failed on leaving clan."); + return false; + } + return true; +} + +/** + * Clan System: Reloads clan db + */ +ACMD(reloadclans) +{ + clan->reload(); + clif->messagecolor_self(fd, COLOR_DEFAULT, "Clan configuration and database have been reloaded."); + return true; +} + +// show camera window or change camera parameters +ACMD(camerainfo) +{ + if (*message == '\0') { + clif->camera_showWindow(sd); + return true; + } + float range = 0; + float rotation = 0; + float latitude = 0; + if (sscanf(message, "%15f %15f %15f", &range, &rotation, &latitude) < 3) { + clif->message(fd, msg_fd(fd, 452)); // usage @camerainfo range rotation latitude + return false; + } + clif->camera_change(sd, range, rotation, latitude, SELF); + return true; +} + +ACMD(refineryui) +{ +#if PACKETVER_MAIN_NUM >= 20161005 || PACKETVER_RE_NUM >= 20161005 || defined(PACKETVER_ZERO) + if (battle_config.enable_refinery_ui == 0) { + clif->message(fd, msg_fd(fd, 453)); + return false; + } + + clif->OpenRefineryUI(sd); + return true; +#else + clif->message(fd, msg_fd(fd, 453)); + return false; +#endif +} + /** * Fills the reference of available commands in atcommand DBMap **/ #define ACMD_DEF(x) { #x, atcommand_ ## x, NULL, NULL, NULL, true } #define ACMD_DEF2(x2, x) { x2, atcommand_ ## x, NULL, NULL, NULL, true } -void atcommand_basecommands(void) { +static void atcommand_basecommands(void) +{ /** * Command reference list, place the base of your commands here **/ @@ -9569,10 +10262,12 @@ void atcommand_basecommands(void) { ACMD_DEF(clearweather), ACMD_DEF(uptime), ACMD_DEF(changesex), + ACMD_DEF(changecharsex), ACMD_DEF(mute), ACMD_DEF(refresh), ACMD_DEF(refreshall), ACMD_DEF(identify), + ACMD_DEF2("identifyall", identify), ACMD_DEF(misceffect), ACMD_DEF(mobsearch), ACMD_DEF(cleanmap), @@ -9635,6 +10330,7 @@ void atcommand_basecommands(void) { ACMD_DEF(homshuffle), ACMD_DEF(showmobs), ACMD_DEF(feelreset), + ACMD_DEF(hatereset), ACMD_DEF(auction), ACMD_DEF(mail), ACMD_DEF2("noks", ksprotection), @@ -9662,6 +10358,7 @@ void atcommand_basecommands(void) { ACMD_DEF(addperm), ACMD_DEF2("rmvperm", addperm), ACMD_DEF(unloadnpcfile), + ACMD_DEF(reloadnpc), ACMD_DEF(cart), ACMD_DEF(cashmount), ACMD_DEF(join), @@ -9669,10 +10366,21 @@ void atcommand_basecommands(void) { ACMD_DEF(fontcolor), ACMD_DEF(searchstore), ACMD_DEF(costume), + ACMD_DEF2("changedress", costume), + ACMD_DEF2("nocosplay", costume), ACMD_DEF(skdebug), ACMD_DEF(cddebug), ACMD_DEF(lang), ACMD_DEF(bodystyle), + ACMD_DEF(cvcoff), + ACMD_DEF(cvcon), + ACMD_DEF(claninfo), + ACMD_DEF(joinclan), + ACMD_DEF(leaveclan), + ACMD_DEF(reloadclans), + ACMD_DEF(setzone), + ACMD_DEF(camerainfo), + ACMD_DEF(refineryui), }; int i; @@ -9691,7 +10399,8 @@ void atcommand_basecommands(void) { #undef ACMD_DEF #undef ACMD_DEF2 -bool atcommand_add(char *name, AtCommandFunc func, bool replace) { +static bool atcommand_add(char *name, AtCommandFunc func, bool replace) +{ AtCommandInfo* cmd; nullpo_retr(false, name); @@ -9714,18 +10423,21 @@ bool atcommand_add(char *name, AtCommandFunc func, bool replace) { /*========================================== * Command lookup functions *------------------------------------------*/ -AtCommandInfo* atcommand_exists(const char* name) { +static AtCommandInfo *atcommand_exists(const char *name) +{ return strdb_get(atcommand->db, name); } -AtCommandInfo* get_atcommandinfo_byname(const char *name) { +static AtCommandInfo *get_atcommandinfo_byname(const char *name) +{ AtCommandInfo *cmd; if ((cmd = strdb_get(atcommand->db, name))) return cmd; return NULL; } -const char* atcommand_checkalias(const char *aliasname) { +static const char *atcommand_checkalias(const char *aliasname) +{ AliasInfo *alias_info = NULL; if ((alias_info = (AliasInfo*)strdb_get(atcommand->alias_db, aliasname)) != NULL) return alias_info->command->command; @@ -9733,7 +10445,8 @@ const char* atcommand_checkalias(const char *aliasname) { } /// AtCommand suggestion -void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool is_atcmd_cmd) { +static void atcommand_get_suggestions(struct map_session_data *sd, const char *name, bool is_atcmd_cmd) +{ struct DBIterator *atcommand_iter, *alias_iter; AtCommandInfo* command_info = NULL; AliasInfo* alias_info = NULL; @@ -9814,10 +10527,11 @@ void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bo * @retval true if the message was recognized as atcommand. * @retval false if the message should be considered a non-command message. */ -bool atcommand_exec(const int fd, struct map_session_data *sd, const char *message, bool player_invoked) +static bool atcommand_exec(const int fd, struct map_session_data *sd, const char *message, bool player_invoked) { char params[100], command[100]; char output[CHAT_SIZE_MAX]; + bool logCommand; // Reconstructed message char atcmd_msg[CHAT_SIZE_MAX]; @@ -9851,6 +10565,8 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa clif->message(fd, msg_fd(fd,143)); return false; } + if (sd->block_action.commands) // *pcblock script command + return false; } if (*message == atcommand->char_symbol) @@ -9883,7 +10599,7 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa return true; } - ssd = map->nick2sd(charname); + ssd = map->nick2sd(charname, true); if (ssd == NULL) { sprintf(output, msg_fd(fd,1389), command); // %s failed. Player not found. clif->message(fd, output); @@ -9916,6 +10632,8 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa && ( (is_atcommand && pc_get_group_level(sd) >= binding->group_lv) || (!is_atcommand && pc_get_group_level(sd) >= binding->group_lv_char) + || (is_atcommand && binding->at_groups[pcg->get_idx(sd->group)] > 0) + || (!is_atcommand && binding->char_groups[pcg->get_idx(sd->group)] > 0) ) ) { if (binding->log) /* log only if this command should be logged [Ind/Hercules] */ @@ -9959,6 +10677,7 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa } } + logCommand = info->log; //Attempt to use the command if ((info->func(fd, ssd, command, params,info) != true)) { #ifdef AUTOTRADE_PERSISTENCY @@ -9970,7 +10689,8 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa return true; } - if (info->log) /* log only if this command should be logged [Ind/Hercules] */ + // info->log cant be used here, because info can be freed [4144] + if (logCommand) /* log only if this command should be logged [Ind/Hercules] */ logs->atcommand(sd, is_atcommand ? atcmd_msg : message); return true; @@ -9979,7 +10699,8 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa /*========================================== * *------------------------------------------*/ -void atcommand_config_read(const char* config_filename) { +static void atcommand_config_read(const char *config_filename) +{ struct config_t atcommand_config; struct config_setting_t *aliases = NULL, *help = NULL, *nolog = NULL; const char *symbol = NULL; @@ -10118,7 +10839,7 @@ static inline int atcommand_command_type2idx(AtCommandType type) * Loads permissions for groups to use commands. * */ -void atcommand_db_load_groups(GroupSettings **groups, struct config_setting_t **commands_, size_t sz) +static void atcommand_db_load_groups(GroupSettings **groups, struct config_setting_t **commands_, size_t sz) { struct DBIterator *iter = db_iterator(atcommand->db); AtCommandInfo *atcmd; @@ -10178,37 +10899,44 @@ void atcommand_db_load_groups(GroupSettings **groups, struct config_setting_t ** return; } -bool atcommand_can_use(struct map_session_data *sd, const char *command) { - AtCommandInfo *info = atcommand->get_info_byname(atcommand->check_alias(command + 1)); +static bool atcommand_can_use(struct map_session_data *sd, const char *command) +{ + AtCommandInfo *acmd_d; + struct atcmd_binding_data *bcmd_d; nullpo_retr(false, sd); - nullpo_retr(false, command); - if (info == NULL) - return false; - if ((*command == atcommand->at_symbol && info->at_groups[pcg->get_idx(sd->group)] != 0) || - (*command == atcommand->char_symbol && info->char_groups[pcg->get_idx(sd->group)] != 0) ) { - return true; + if ((acmd_d = atcommand->get_info_byname(atcommand->check_alias(command + 1))) != NULL) { + return ((*command == atcommand->at_symbol && acmd_d->at_groups[pcg->get_idx(sd->group)] > 0) || + (*command == atcommand->char_symbol && acmd_d->char_groups[pcg->get_idx(sd->group)] > 0)); + } else if ((bcmd_d = atcommand->get_bind_byname(atcommand->check_alias(command + 1))) != NULL) { + return ((*command == atcommand->at_symbol && bcmd_d->at_groups[pcg->get_idx(sd->group)] > 0) || + (*command == atcommand->char_symbol && bcmd_d->char_groups[pcg->get_idx(sd->group)] > 0)); } return false; } -bool atcommand_can_use2(struct map_session_data *sd, const char *command, AtCommandType type) { - AtCommandInfo *info = atcommand->get_info_byname(atcommand->check_alias(command)); + +static bool atcommand_can_use2(struct map_session_data *sd, const char *command, AtCommandType type) +{ + AtCommandInfo *acmd_d; + struct atcmd_binding_data *bcmd_d; nullpo_retr(false, sd); - nullpo_retr(false, command); - if (info == NULL) - return false; - if ((type == COMMAND_ATCOMMAND && info->at_groups[pcg->get_idx(sd->group)] != 0) || - (type == COMMAND_CHARCOMMAND && info->char_groups[pcg->get_idx(sd->group)] != 0) ) { - return true; + if ((acmd_d = atcommand->get_info_byname(atcommand->check_alias(command))) != NULL) { + return ((type == COMMAND_ATCOMMAND && acmd_d->at_groups[pcg->get_idx(sd->group)] > 0) || + (type == COMMAND_CHARCOMMAND && acmd_d->char_groups[pcg->get_idx(sd->group)] > 0)); + } else if ((bcmd_d = atcommand->get_bind_byname(atcommand->check_alias(command))) != NULL) { + return ((type == COMMAND_ATCOMMAND && bcmd_d->at_groups[pcg->get_idx(sd->group)] > 0) || + (type == COMMAND_CHARCOMMAND && bcmd_d->char_groups[pcg->get_idx(sd->group)] > 0)); } return false; } -bool atcommand_hp_add(char *name, AtCommandFunc func) { + +static bool atcommand_hp_add(char *name, AtCommandFunc func) +{ /* if commands are added after group permissions are thrown in, they end up with no permissions */ /* so we restrict commands to be linked in during boot */ if( core->runflag == MAPSERVER_ST_RUNNING ) { @@ -10222,7 +10950,7 @@ bool atcommand_hp_add(char *name, AtCommandFunc func) { /** * @see DBApply */ -int atcommand_db_clear_sub(union DBKey key, struct DBData *data, va_list args) +static int atcommand_db_clear_sub(union DBKey key, struct DBData *data, va_list args) { AtCommandInfo *cmd = DB->data2ptr(data); aFree(cmd->at_groups); @@ -10232,7 +10960,8 @@ int atcommand_db_clear_sub(union DBKey key, struct DBData *data, va_list args) return 0; } -void atcommand_db_clear(void) { +static void atcommand_db_clear(void) +{ if( atcommand->db != NULL ) { atcommand->db->destroy(atcommand->db, atcommand->cmd_db_clear_sub); atcommand->db = NULL; @@ -10243,7 +10972,8 @@ void atcommand_db_clear(void) { } } -void atcommand_doload(void) { +static void atcommand_doload(void) +{ if( core->runflag >= MAPSERVER_ST_RUNNING ) atcommand->cmd_db_clear(); if( atcommand->db == NULL ) @@ -10254,12 +10984,14 @@ void atcommand_doload(void) { atcommand->config_read(map->ATCOMMAND_CONF_FILENAME); } -void atcommand_expand_message_table(void) { +static void atcommand_expand_message_table(void) +{ RECREATE(atcommand->msg_table, char **, ++atcommand->max_message_table); CREATE(atcommand->msg_table[atcommand->max_message_table - 1], char *, MAX_MSG); } -void do_init_atcommand(bool minimal) { +static void do_init_atcommand(bool minimal) +{ if (minimal) return; @@ -10270,13 +11002,18 @@ void do_init_atcommand(bool minimal) { atcommand->doload(); } -void do_final_atcommand(void) { +static void do_final_atcommand(void) +{ atcommand->cmd_db_clear(); } -void atcommand_defaults(void) { +void atcommand_defaults(void) +{ atcommand = &atcommand_s; + atcommand->atcmd_output = &atcmd_output; + atcommand->atcmd_player_name = &atcmd_player_name; + atcommand->db = NULL; atcommand->alias_db = NULL; |