diff options
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r-- | src/map/atcommand.c | 675 |
1 files changed, 351 insertions, 324 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index bc539837d..19a7e360b 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -132,7 +132,6 @@ 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,21 +169,6 @@ 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; } @@ -223,8 +207,8 @@ ACMD(send) // read message type as hex number (without the 0x) if (!*message - || !((sscanf(message, "len %x", &type)==1 && (len=1, true)) - || sscanf(message, "%x", &type)==1) + || !((sscanf(message, "len %x", (unsigned int*)&type)==1 && (len=1, true)) + || sscanf(message, "%x", (unsigned int*)&type)==1) ) { clif->message(fd, msg_fd(fd,900)); // Usage: clif->message(fd, msg_fd(fd,901)); // @send len <packet hex number> @@ -252,7 +236,7 @@ ACMD(send) } while(0) //define SKIP_VALUE #define GET_VALUE(p,num) do { \ - if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\ + if(sscanf((p), "x%lx", (long unsigned int*)&(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\ PARSE_ERROR("Invalid number in:",(p));\ return false;\ }\ @@ -266,22 +250,22 @@ 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 clif->message(fd, atcmd_output); return true; } - + len = clif->packet(type)->len; - + if (len == -1) { // dynamic packet len = SHRT_MAX-4; // maximum length off = 4; } - + WFIFOHEAD(sd->fd, len); WFIFOW(sd->fd,0)=TOW(type); @@ -482,11 +466,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) { @@ -547,7 +531,7 @@ ACMD(jumpto) { return false; } - if((pl_sd=map->nick2sd((char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -655,7 +639,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 +748,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); @@ -870,7 +854,7 @@ ACMD(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,7 +869,7 @@ 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; } @@ -893,12 +877,12 @@ ACMD(guildstorage) 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; } @@ -953,7 +937,7 @@ ACMD(hide) { if (sd->disguise != -1 ) status->set_viewdata(&sd->bl, sd->disguise); else - status->set_viewdata(&sd->bl, sd->status.class_); + 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 @@ -967,7 +951,7 @@ ACMD(hide) { 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; + sd->vd.class = INVISIBLE_CLASS; clif->message(fd, msg_fd(fd,11)); // Invisible: On // decrement the number of pvp players on the map @@ -1091,9 +1075,9 @@ 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 - intif->broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(info->command + 4) == 'b' || *(info->command + 4) == 'B') ? BC_BLUE : BC_YELLOW); + intif->broadcast(atcmd_output, (int)strlen(atcmd_output) + 1, (*(info->command + 4) == 'b' || *(info->command + 4) == 'B') ? BC_BLUE : BC_YELLOW); } 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 +1088,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); + intif->broadcast2(atcmd_output, (int)strlen(atcmd_output) + 1, color, 0x190, 12, 0, 0); } return true; } @@ -1384,13 +1368,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 +1385,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 +1395,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); @@ -1423,6 +1408,10 @@ ACMD(baselevelup) pc->baselevelchanged(sd); 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 +1431,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 +1443,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 +1453,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,6 +1462,9 @@ 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; } @@ -1511,7 +1504,7 @@ ACMD(help) { clif->message(fd, atcmd_output); { // Display aliases - DBIterator* iter; + struct DBIterator *iter; AtCommandInfo *command_info; AliasInfo *alias_info = NULL; StringBuf buf; @@ -1721,7 +1714,21 @@ ACMD(bodystyle) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!*message || sscanf(message, "%d", &body_style) < 1) { + if ((sd->job & MAPID_THIRDMASK) != MAPID_GUILLOTINE_CROSS + && (sd->job & MAPID_THIRDMASK) != MAPID_GENETIC + && (sd->job & MAPID_THIRDMASK) != MAPID_MECHANIC + && (sd->job & MAPID_THIRDMASK) != MAPID_ROYAL_GUARD + && (sd->job & MAPID_THIRDMASK) != MAPID_ARCH_BISHOP + && (sd->job & MAPID_THIRDMASK) != MAPID_RANGER + && (sd->job & MAPID_THIRDMASK) != MAPID_WARLOCK + && (sd->job & MAPID_THIRDMASK) != MAPID_SHADOW_CHASER + && (sd->job & MAPID_THIRDMASK) != MAPID_MINSTRELWANDERER + ) { + 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 +1736,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; } @@ -2272,11 +2279,11 @@ ACMD(gat) { for (y = 2; y >= -2; y--) { safesnprintf(atcmd_output, sizeof(atcmd_output), "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", map->list[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y, - map->getcell(sd->bl.m, &sd->bl, sd->bl.x - 2, sd->bl.y + y, CELL_GETTYPE), - map->getcell(sd->bl.m, &sd->bl, sd->bl.x - 1, sd->bl.y + y, CELL_GETTYPE), - map->getcell(sd->bl.m, &sd->bl, sd->bl.x, sd->bl.y + y, CELL_GETTYPE), - map->getcell(sd->bl.m, &sd->bl, sd->bl.x + 1, sd->bl.y + y, CELL_GETTYPE), - map->getcell(sd->bl.m, &sd->bl, sd->bl.x + 2, sd->bl.y + y, CELL_GETTYPE)); + (unsigned int)map->getcell(sd->bl.m, &sd->bl, sd->bl.x - 2, sd->bl.y + y, CELL_GETTYPE), + (unsigned int)map->getcell(sd->bl.m, &sd->bl, sd->bl.x - 1, sd->bl.y + y, CELL_GETTYPE), + (unsigned int)map->getcell(sd->bl.m, &sd->bl, sd->bl.x, sd->bl.y + y, CELL_GETTYPE), + (unsigned int)map->getcell(sd->bl.m, &sd->bl, sd->bl.x + 1, sd->bl.y + y, CELL_GETTYPE), + (unsigned int)map->getcell(sd->bl.m, &sd->bl, sd->bl.x + 2, sd->bl.y + y, CELL_GETTYPE)); clif->message(fd, atcmd_output); } @@ -2312,30 +2319,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 +2355,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; } @@ -2747,7 +2730,7 @@ ACMD(recall) { return false; } - if((pl_sd=map->nick2sd((char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -3072,7 +3055,7 @@ ACMD(kick) return false; } - if((pl_sd=map->nick2sd((char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -3613,16 +3596,16 @@ ACMD(reloadskilldb) * @reloadatcommand - reloads conf/atcommand.conf conf/groups.conf *------------------------------------------*/ ACMD(reloadatcommand) { - config_t run_test; + struct config_t run_test; - if (libconfig->read_file(&run_test, "conf/groups.conf")) { + if (!libconfig->load_file(&run_test, "conf/groups.conf")) { clif->message(fd, msg_fd(fd,1036)); // Error reading groups.conf, reload failed. return false; } libconfig->destroy(&run_test); - if (libconfig->read_file(&run_test, map->ATCOMMAND_CONF_FILENAME)) { + if (!libconfig->load_file(&run_test, map->ATCOMMAND_CONF_FILENAME)) { clif->message(fd, msg_fd(fd,1037)); // Error reading atcommand.conf, reload failed. return false; } @@ -3642,7 +3625,9 @@ 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; if( prev_config.item_rate_mvp != battle_config.item_rate_mvp || prev_config.item_rate_common != battle_config.item_rate_common @@ -3746,7 +3731,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) { @@ -3791,7 +3776,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++; } } @@ -3970,7 +3955,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); @@ -4004,7 +3989,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); @@ -4019,7 +4004,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); @@ -4034,7 +4019,7 @@ ACMD(mount_peco) } return true; } - if ((sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC) { + if ((sd->job & MAPID_THIRDMASK) == MAPID_MECHANIC) { if (!pc_ismadogear(sd)) { clif->message(sd->fd,msg_fd(fd,1123)); // You have mounted your Mado Gear. pc->setmadogear(sd, true); @@ -4044,7 +4029,7 @@ ACMD(mount_peco) } 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! @@ -4151,8 +4136,9 @@ ACMD(repairall) 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; + 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++; } @@ -4909,7 +4895,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); + intif->broadcast(atcmd_output, (int)strlen(atcmd_output) + 1, BC_DEFAULT); return true; } @@ -4928,7 +4914,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; } @@ -5123,8 +5109,7 @@ ACMD(follow) { return true; } - if ((pl_sd = map->nick2sd((char *)message)) == NULL) - { + if ((pl_sd = map->nick2sd(message)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5174,6 +5159,11 @@ ACMD(storeall) } } + if (sd->storage.received == false) { + clif->message(fd, msg_fd(fd, 27)); // "Storage has not been loaded yet" + return false; + } + for (i = 0; i < MAX_INVENTORY; i++) { if (sd->status.inventory[i].amount) { if(sd->status.inventory[i].equip != 0) @@ -5189,17 +5179,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. @@ -5262,7 +5260,7 @@ ACMD(clearcart) for( i = 0; i < MAX_CART; i++ ) if(sd->status.cart[i].nameid > 0) - pc->cart_delitem(sd, i, sd->status.cart[i].amount, 1, LOG_TYPE_OTHER); + pc->cart_delitem(sd, i, sd->status.cart[i].amount, 1, LOG_TYPE_COMMAND); clif->clearcart(fd); clif->updatestatus(sd,SP_CARTINFO); @@ -5277,12 +5275,13 @@ ACMD(clearcart) *------------------------------------------*/ #define MAX_SKILLID_PARTIAL_RESULTS 5 #define MAX_SKILLID_PARTIAL_RESULTS_LEN 74 /* "skill " (6) + "%d:" (up to 5) + "%s" (up to 30) + " (%s)" (up to 33) */ -ACMD(skillid) { +ACMD(skillid) +{ int i, found = 0; size_t skillen; - DBIterator* iter; - DBKey key; - DBData *data; + struct DBIterator *iter; + union DBKey key; + struct DBData *data; char partials[MAX_SKILLID_PARTIAL_RESULTS][MAX_SKILLID_PARTIAL_RESULTS_LEN]; if (!*message) { @@ -5601,7 +5600,7 @@ ACMD(changegm) { return false; } - if ((pl_sd=map->nick2sd((char *) message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) { + if ((pl_sd=map->nick2sd(message)) == 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; } @@ -5621,7 +5620,7 @@ ACMD(changeleader) { return false; } - if (party->changeleader(sd, map->nick2sd((char *) message))) + if (party->changeleader(sd, map->nick2sd(message))) return true; return false; } @@ -6380,7 +6379,7 @@ ACMD(trade) { return false; } - if ( (pl_sd = map->nick2sd((char *)message)) == NULL ) { + if ((pl_sd = map->nick2sd(message)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -6423,8 +6422,7 @@ ACMD(unmute) { return false; } - if ((pl_sd = map->nick2sd((char *)message)) == NULL) - { + if ((pl_sd = map->nick2sd(message)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -6639,9 +6637,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 @@ -6778,7 +6776,7 @@ ACMD(showmobs) 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 ) @@ -7665,9 +7663,10 @@ ACMD(showdelay) * @reject - reject invitation * @leave - leave duel *------------------------------------------*/ -ACMD(invite) { +ACMD(invite) +{ unsigned int did = sd->duel_group; - struct map_session_data *target_sd = map->nick2sd((char *)message); + struct map_session_data *target_sd = map->nick2sd(message); if (did == 0) { @@ -7739,8 +7738,7 @@ ACMD(duel) { } duel->create(sd, maxpl); } else { - struct map_session_data *target_sd; - target_sd = map->nick2sd((char *)message); + struct map_session_data *target_sd = map->nick2sd(message); if (target_sd != NULL) { unsigned int newduel; if ((newduel = duel->create(sd, 2)) != -1) { @@ -7835,7 +7833,7 @@ ACMD(cash) // 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)); + clif_disp_onlyself(sd, output); clif->message(fd, output); } } else @@ -7843,7 +7841,7 @@ ACMD(cash) } 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)); + clif_disp_onlyself(sd, output); clif->message(fd, output); } else clif->message(fd, msg_fd(fd,41)); // Unable to decrease the number/value. @@ -7854,7 +7852,7 @@ ACMD(cash) // 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)); + clif_disp_onlyself(sd, output); clif->message(fd, output); } } else @@ -7862,7 +7860,7 @@ ACMD(cash) } 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)); + clif_disp_onlyself(sd, output); clif->message(fd, output); } else clif->message(fd, msg_fd(fd,41)); // Unable to decrease the number/value. @@ -7882,7 +7880,7 @@ ACMD(clone) { return false; } - if ((pl_sd=map->nick2sd((char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -7919,7 +7917,7 @@ ACMD(clone) { y = sd->bl.y; } - if ((x = mob->clone_spawn(pl_sd, sd->bl.m, x, y, "", master, 0, flag?1:0, 0)) > 0) { + if ((x = mob->clone_spawn(pl_sd, sd->bl.m, x, y, "", master, MD_NONE, flag?1:0, 0)) > 0) { clif->message(fd, msg_fd(fd,128+flag*2)); // Evil Clone spawned. Clone spawned. Slave clone spawned. return true; } @@ -7957,7 +7955,7 @@ 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)); + clif_disp_onlyself(sd, atcmd_output); clif->message(sd->fd,msg_fd(fd,279)); // @request sent. return true; } @@ -8056,8 +8054,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; @@ -8078,7 +8076,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; @@ -8239,7 +8237,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); @@ -8352,7 +8350,7 @@ void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommand char line_buff[CHATBOX_SIZE]; char* cur = line_buff; AtCommandInfo* cmd; - DBIterator *iter = db_iterator(atcommand->db); + struct DBIterator *iter = db_iterator(atcommand->db); int count = 0; memset(line_buff,' ',CHATBOX_SIZE); @@ -8395,6 +8393,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); @@ -8419,22 +8449,24 @@ 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,-1); + 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; } @@ -8498,30 +8530,34 @@ ACMD(set) CREATE(data, struct script_data,1); - if( is_str ) {// string variable - switch( reg[0] ) { + if (is_str) { + // string variable + const char *str = NULL; + switch (reg[0]) { case '@': - data->u.str = pc->readregstr(sd, script->add_str(reg)); + str = pc->readregstr(sd, script->add_str(reg)); break; case '$': - data->u.str = mapreg->readregstr(script->add_str(reg)); + str = mapreg->readregstr(script->add_str(reg)); break; case '#': - if( reg[1] == '#' ) - data->u.str = pc_readaccountreg2str(sd, script->add_str(reg));// global + if (reg[1] == '#') + str = pc_readaccountreg2str(sd, script->add_str(reg));// global else - data->u.str = pc_readaccountregstr(sd, script->add_str(reg));// local + str = pc_readaccountregstr(sd, script->add_str(reg));// local break; default: - data->u.str = pc_readglobalreg_str(sd, script->add_str(reg)); + str = pc_readglobalreg_str(sd, script->add_str(reg)); break; } - if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string + if (str == NULL || str[0] == '\0') { + // empty string data->type = C_CONSTSTR; data->u.str = ""; - } else {// duplicate string + } else { + // duplicate string data->type = C_STR; - data->u.str = aStrdup(data->u.str); + data->u.mutstr = aStrdup(str); } } else {// integer variable data->type = C_INT; @@ -8549,7 +8585,7 @@ ACMD(set) safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,1373),reg,data->u.num); // %s value is now :%d break; case C_STR: - safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,1374),reg,data->u.str); // %s value is now :%s + safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,1374),reg,data->u.mutstr); // %s value is now :%s break; case C_CONSTSTR: safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,1375),reg); // %s is empty @@ -8822,7 +8858,7 @@ ACMD(channel) { clif->messagecolor_self(fd, channel->config->colors[k], atcmd_output); } } else { - DBIterator *iter = db_iterator(channel->db); + struct DBIterator *iter = db_iterator(channel->db); bool show_all = pc_has_permission(sd, PC_PERM_HCHSYS_ADMIN) ? true : false; clif->message(fd, msg_fd(fd,1410)); // -- Public Channels if (channel->config->local) { @@ -9052,9 +9088,9 @@ ACMD(channel) { clif->message(fd, atcmd_output); } else if (strcmpi(subcmd,"banlist") == 0) { // sub1 = channel name; sub2 = unused; sub3 = unused - DBIterator *iter = NULL; - DBKey key; - DBData *data; + struct DBIterator *iter = NULL; + union DBKey key; + struct DBData *data; bool isA = pc_has_permission(sd, PC_PERM_HCHSYS_ADMIN)?true:false; if (sub1[0] != '#') { clif->message(fd, msg_fd(fd,1405));// Channel name must start with a '#' @@ -9243,7 +9279,12 @@ ACMD(searchstore){ searchstore->open(sd, 99, val); return true; } -ACMD(costume){ + +/*========================================== +* @costume +*------------------------------------------*/ +ACMD(costume) +{ const char* names[] = { "Wedding", "Xmas", @@ -9252,6 +9293,9 @@ ACMD(costume){ #if PACKETVER >= 20131218 "Oktoberfest", #endif +#if PACKETVER >= 20141022 + "Summer2", +#endif }; const int name2id[] = { SC_WEDDING, @@ -9261,52 +9305,60 @@ ACMD(costume){ #if PACKETVER >= 20131218 SC_OKTOBERFEST, #endif +#if PACKETVER >= 20141022 + SC_DRESS_UP, +#endif }; unsigned short k = 0, len = ARRAYLENGTH(names); 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); + + 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); + 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; } - sc_start(NULL,&sd->bl, name2id[k], 100, 0, -1); + sc_start(NULL, &sd->bl, name2id[k], 100, 0, INFINITE_DURATION); 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); @@ -9729,8 +9781,7 @@ 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) { - DBIterator* atcommand_iter; - DBIterator* alias_iter; + struct DBIterator *atcommand_iter, *alias_iter; AtCommandInfo* command_info = NULL; AliasInfo* alias_info = NULL; AtCommandType type = is_atcmd_cmd ? COMMAND_ATCOMMAND : COMMAND_CHARCOMMAND; @@ -9800,143 +9851,126 @@ void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bo } /** - * Executes an at-command + * Executes an at-command. + * * @param fd fd associated to the invoking character * @param sd sd associated to the invoking character * @param message atcommand arguments * @param player_invoked true if the command was invoked by a player, false if invoked by the server (bypassing any restrictions) + * + * @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) { - char charname[NAME_LENGTH], params[100]; - char charname2[NAME_LENGTH]; - char command[100]; +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]; - //Reconstructed message + // Reconstructed message char atcmd_msg[CHAT_SIZE_MAX]; struct map_session_data *ssd = NULL; //sd for target - AtCommandInfo * info; + AtCommandInfo *info; + + bool is_atcommand = true; // false if it's a charcommand nullpo_retr(false, sd); - //Shouldn't happen - if ( !message || !*message ) + // Shouldn't happen + if (message == NULL || *message == '\0') return false; - //Block NOCHAT but do not display it as a normal message + // Block NOCHAT but do not display it as a normal message if (pc_ismuted(&sd->sc, MANNER_NOCOMMAND)) return true; // skip 10/11-langtype's codepage indicator, if detected - if ( message[0] == '|' && strlen(message) >= 4 && (message[3] == atcommand->at_symbol || message[3] == atcommand->char_symbol) ) + if (message[0] == '|' && strlen(message) >= 4 && (message[3] == atcommand->at_symbol || message[3] == atcommand->char_symbol)) message += 3; - //Should display as a normal message - if ( *message != atcommand->at_symbol && *message != atcommand->char_symbol ) + // Should display as a normal message + if (*message != atcommand->at_symbol && *message != atcommand->char_symbol) return false; if (player_invoked) { - //Commands are disabled on maps flagged as 'nocommand' - if ( map->list[sd->bl.m].nocommand && pc_get_group_level(sd) < map->list[sd->bl.m].nocommand ) { + // Commands are disabled on maps flagged as 'nocommand' + if (map->list[sd->bl.m].nocommand && pc_get_group_level(sd) < map->list[sd->bl.m].nocommand) { clif->message(fd, msg_fd(fd,143)); return false; } } - if (*message == atcommand->char_symbol) { - do { - char params2[100]; - int x, y, z; - - //Checks to see if #command has a name or a name + parameters. - x = sscanf(message, "%99s \"%23[^\"]\" %99[^\n]", command, charname, params); - y = sscanf(message, "%99s %23s %99[^\n]", command, charname2, params2); + if (*message == atcommand->char_symbol) + is_atcommand = false; - //z always has the value of the scan that was successful - z = ( x > 1 ) ? x : y; - - //#command + name means the sufficient target was used and anything else after - //can be looked at by the actual command function since most scan to see if the - //right parameters are used. - if ( x > 2 ) { - sprintf(atcmd_msg, "%s %s", command, params); - break; - } - else if ( y > 2 ) { - sprintf(atcmd_msg, "%s %s", command, params2); - break; - } - //Regardless of what style the #command is used, if it's correct, it will always have - //this value if there is no parameter. Send it as just the #command - else if ( z == 2 ) { - sprintf(atcmd_msg, "%s", command); - break; - } + if (is_atcommand) { // #command + sprintf(atcmd_msg, "%s", message); + ssd = sd; + } else { // @command + char charname[NAME_LENGTH]; + int n; + + // Checks to see if #command has a name or a name + parameters. + if ((n = sscanf(message, "%99s \"%23[^\"]\" %99[^\n]", command, charname, params)) < 2 + && (n = sscanf(message, "%99s %23s %99[^\n]", command, charname, params)) < 2 + ) { + if (pc_get_group_level(sd) == 0) { + if (n < 1) + return false; // no command found. Display as normal message - if( !pc_get_group_level(sd) ) { - if( x >= 1 || y >= 1 ) { /* we have command */ - info = atcommand->get_info_byname(atcommand->check_alias(command + 1)); - if( !info || info->char_groups[pcg->get_idx(sd->group)] == 0 ) /* if we can't use or doesn't exist: don't even display the command failed message */ - return false; - } else - return false;/* display as normal message */ + info = atcommand->get_info_byname(atcommand->check_alias(command + 1)); + if (info == NULL || info->char_groups[pcg->get_idx(sd->group)] == 0) { + /* if we can't use or doesn't exist: don't even display the command failed message */ + return false; + } } sprintf(output, msg_fd(fd,1388), atcommand->char_symbol); // Charcommand failed (usage: %c<command> <char name> <parameters>). clif->message(fd, output); return true; - } while(0); - } - else /*if (*message == atcommand->at_symbol)*/ { - //atcmd_msg is constructed above differently for charcommands - //it's copied from message if not a charcommand so it can - //pass through the rest of the code compatible with both symbols - sprintf(atcmd_msg, "%s", message); + } + + ssd = map->nick2sd(charname); + if (ssd == NULL) { + sprintf(output, msg_fd(fd,1389), command); // %s failed. Player not found. + clif->message(fd, output); + return true; + } + + if (n > 2) + sprintf(atcmd_msg, "%s %s", command, params); + else + sprintf(atcmd_msg, "%s", command); } pc->update_idle_time(sd, BCIDLE_ATCOMMAND); //Clearing these to be used once more. - memset(command, '\0', sizeof(command)); - memset(params, '\0', sizeof(params)); + memset(command, '\0', sizeof command); + memset(params, '\0', sizeof params); //check to see if any params exist within this command - if( sscanf(atcmd_msg, "%99s %99[^\n]", command, params) < 2 ) + if (sscanf(atcmd_msg, "%99s %99[^\n]", command, params) < 2) params[0] = '\0'; // @commands (script based) - if(player_invoked && atcommand->binding_count > 0) { - struct atcmd_binding_data * binding; - + if (player_invoked && atcommand->binding_count > 0) { // Get atcommand binding - binding = atcommand->get_bind_byname(command); + struct atcmd_binding_data *binding = atcommand->get_bind_byname(command); // Check if the binding isn't NULL and there is a NPC event, level of usage met, et cetera - if( binding != NULL - && binding->npc_event[0] + if (binding != NULL && binding->npc_event[0] != '\0' && ( - (*atcmd_msg == atcommand->at_symbol && pc_get_group_level(sd) >= binding->group_lv) - || (*atcmd_msg == atcommand->char_symbol && pc_get_group_level(sd) >= binding->group_lv_char) + (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) ) ) { - // Check if self or character invoking; if self == character invoked, then self invoke. - bool invokeFlag = ((*atcmd_msg == atcommand->at_symbol) ? 1 : 0); - - // Check if the command initiated is a character command - if (*message == atcommand->char_symbol - && (ssd = map->nick2sd(charname)) == NULL - && (ssd = map->nick2sd(charname2)) == NULL - ) { - sprintf(output, msg_fd(fd,1389), command); // %s failed. Player not found. - clif->message(fd, output); - return true; - } - - if( binding->log ) /* log only if this command should be logged [Ind/Hercules] */ + if (binding->log) /* log only if this command should be logged [Ind/Hercules] */ logs->atcommand(sd, atcmd_msg); - npc->do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event); + npc->do_atcmd_event(ssd, command, params, binding->npc_event); return true; } } @@ -9944,51 +9978,40 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa //Grab the command information and check for the proper GM level required to use it or if the command exists info = atcommand->get_info_byname(atcommand->check_alias(command + 1)); if (info == NULL) { - if( pc_get_group_level(sd) ) { // TODO: remove or replace with proper permission - sprintf(output, msg_fd(fd,153), command); // "%s is Unknown Command." - clif->message(fd, output); - atcommand->get_suggestions(sd, command + 1, *message == atcommand->at_symbol); - return true; - } else + if (pc_get_group_level(sd) == 0) // TODO: remove or replace with proper permission return false; + + sprintf(output, msg_fd(fd,153), command); // "%s is Unknown Command." + clif->message(fd, output); + atcommand->get_suggestions(sd, command + 1, is_atcommand); + return true; } if (player_invoked) { int i; - 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) ) { + if ((is_atcommand && info->at_groups[pcg->get_idx(sd->group)] == 0) + || (!is_atcommand && info->char_groups[pcg->get_idx(sd->group)] == 0)) return false; - } - if( pc_isdead(sd) && pc_has_permission(sd,PC_PERM_DISABLE_CMD_DEAD) ) { + + if (pc_isdead(sd) && pc_has_permission(sd,PC_PERM_DISABLE_CMD_DEAD)) { clif->message(fd, msg_fd(fd,1393)); // You can't use commands while dead return true; } - for(i = 0; i < map->list[sd->bl.m].zone->disabled_commands_count; i++) { - if( info->func == map->list[sd->bl.m].zone->disabled_commands[i]->cmd ) { + for (i = 0; i < map->list[sd->bl.m].zone->disabled_commands_count; i++) { + if (info->func == map->list[sd->bl.m].zone->disabled_commands[i]->cmd) { if (pc_get_group_level(sd) < map->list[sd->bl.m].zone->disabled_commands[i]->group_lv) { clif->messagecolor_self(sd->fd, COLOR_RED, "This command is disabled in this area"); return true; - } else { - break;/* already found the matching command, no need to keep checking -- just go on */ } + break; /* already found the matching command, no need to keep checking -- just go on */ } } } - // Check if target is valid only if confirmed that player can use command. - if (*message == atcommand->char_symbol - && (ssd = map->nick2sd(charname)) == NULL - && (ssd = map->nick2sd(charname2)) == NULL - ) { - sprintf(output, msg_fd(fd,1389), command); // %s failed. Player not found. - clif->message(fd, output); - return true; - } - //Attempt to use the command - if ( (info->func(fd, (*atcmd_msg == atcommand->at_symbol) ? sd : ssd, command, params,info) != true) ) { + if ((info->func(fd, ssd, command, params,info) != true)) { #ifdef AUTOTRADE_PERSISTENCY - if( info->func == atcommand_autotrade ) /** autotrade deletes caster, so we got nothing more to do here **/ + if (info->func == atcommand_autotrade) /* autotrade deletes caster, so we got nothing more to do here */ return true; #endif sprintf(output,msg_fd(fd,154), command); // %s failed. @@ -9996,8 +10019,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] */ - logs->atcommand(sd, *atcmd_msg == atcommand->at_symbol ? atcmd_msg : message); + if (info->log) /* log only if this command should be logged [Ind/Hercules] */ + logs->atcommand(sd, is_atcommand ? atcmd_msg : message); return true; } @@ -10006,13 +10029,13 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa * *------------------------------------------*/ void atcommand_config_read(const char* config_filename) { - config_t atcommand_config; - config_setting_t *aliases = NULL, *help = NULL, *nolog = NULL; + struct config_t atcommand_config; + struct config_setting_t *aliases = NULL, *help = NULL, *nolog = NULL; const char *symbol = NULL; int num_aliases = 0; nullpo_retv(config_filename); - if (libconfig->read_file(&atcommand_config, config_filename)) + if (!libconfig->load_file(&atcommand_config, config_filename)) return; // Command symbols @@ -10041,7 +10064,7 @@ void atcommand_config_read(const char* config_filename) { int count = libconfig->setting_length(aliases); for (i = 0; i < count; ++i) { - config_setting_t *command; + struct config_setting_t *command; const char *commandname = NULL; int j = 0, alias_count = 0; AtCommandInfo *commandinfo = NULL; @@ -10079,7 +10102,7 @@ void atcommand_config_read(const char* config_filename) { int count = libconfig->setting_length(nolog); for (i = 0; i < count; ++i) { - config_setting_t *command; + struct config_setting_t *command; const char *commandname = NULL; AtCommandInfo *commandinfo = NULL; @@ -10101,7 +10124,7 @@ void atcommand_config_read(const char* config_filename) { int i; for (i = 0; i < count; ++i) { - config_setting_t *command; + struct config_setting_t *command; const char *commandname; AtCommandInfo *commandinfo = NULL; @@ -10144,9 +10167,9 @@ static inline int atcommand_command_type2idx(AtCommandType type) * Loads permissions for groups to use commands. * */ -void atcommand_db_load_groups(GroupSettings **groups, config_setting_t **commands_, size_t sz) +void atcommand_db_load_groups(GroupSettings **groups, struct config_setting_t **commands_, size_t sz) { - DBIterator *iter = db_iterator(atcommand->db); + struct DBIterator *iter = db_iterator(atcommand->db); AtCommandInfo *atcmd; nullpo_retv(groups); @@ -10157,7 +10180,7 @@ void atcommand_db_load_groups(GroupSettings **groups, config_setting_t **command CREATE(atcmd->char_groups, char, sz); for (i = 0; i < sz; i++) { GroupSettings *group = groups[i]; - config_setting_t *commands = commands_[i]; + struct config_setting_t *commands = commands_[i]; int result = 0; int idx = -1; @@ -10178,7 +10201,7 @@ void atcommand_db_load_groups(GroupSettings **groups, config_setting_t **command } if (commands != NULL) { - config_setting_t *cmd = NULL; + struct config_setting_t *cmd = NULL; // <commandname> : <bool> (only atcommand) if (config_setting_lookup_bool(commands, atcmd->command, &result) && result) { @@ -10205,31 +10228,34 @@ void atcommand_db_load_groups(GroupSettings **groups, config_setting_t **command } bool atcommand_can_use(struct map_session_data *sd, const char *command) { - AtCommandInfo *info = atcommand->get_info_byname(atcommand->check_alias(command + 1)); + 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)); + 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; @@ -10248,7 +10274,8 @@ bool atcommand_hp_add(char *name, AtCommandFunc func) { /** * @see DBApply */ -int atcommand_db_clear_sub(DBKey key, DBData *data, va_list args) { +int atcommand_db_clear_sub(union DBKey key, struct DBData *data, va_list args) +{ AtCommandInfo *cmd = DB->data2ptr(data); aFree(cmd->at_groups); aFree(cmd->char_groups); |