From 633d50fa728ee5ede879033862f5cfaf5d25cda1 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Mon, 16 Jan 2017 23:36:52 +0100 Subject: [PATCH] Atcommand clanspy --- conf/msg_conf/map_msg.conf | 6 ++++++ src/map/atcommand.c | 40 ++++++++++++++++++++++++++++++++++++++ src/map/clan.c | 14 +++++++++++++ src/map/clan.h | 1 + src/map/clif.c | 14 +++++++++++++ src/map/map.c | 2 +- src/map/pc.h | 1 + 7 files changed, 77 insertions(+), 1 deletion(-) diff --git a/conf/msg_conf/map_msg.conf b/conf/msg_conf/map_msg.conf index f4dfc4624d..aa9c692fde 100644 --- a/conf/msg_conf/map_msg.conf +++ b/conf/msg_conf/map_msg.conf @@ -1625,5 +1625,11 @@ // @guild 1498: You cannot create a guild because you are in a clan. +// @clanspy +1499: Please enter a clan name/ID (usage: @clanspy ). +1500: No longer spying on the %s clan. +1501: Spying on the %s clan. +1502: Incorrect clan name/ID. + //Custom translations //import: conf/msg_conf/import/map_msg_eng_conf.txt diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 7190474990..0161fbaa79 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -4425,6 +4425,45 @@ ACMD_FUNC(partyspy) return 0; } +ACMD_FUNC(clanspy){ + char clan_name[NAME_LENGTH]; + struct clan* c; + nullpo_retr(-1, sd); + + memset(clan_name, '\0', sizeof(clan_name)); + memset(atcmd_output, '\0', sizeof(atcmd_output)); + + if( !enable_spy ){ + clif_displaymessage(fd, msg_txt(sd, 1125)); // The mapserver has spy command support disabled. + return -1; + } + + if( !message || !*message || sscanf( message, "%23[^\n]", clan_name ) < 1 ){ + clif_displaymessage(fd, msg_txt(sd, 1499)); // Please enter a clan name/ID (usage: @clanspy ). + return -1; + } + + if ((c = clan_searchname(clan_name)) != NULL || // name first to avoid error when name begin with a number + (c = clan_search(atoi(message))) != NULL) { + if (sd->clanspy == c->id) { + sd->clanspy = 0; + sprintf(atcmd_output, msg_txt(sd, 1500), c->name); // No longer spying on the %s clan. + clif_displaymessage(fd, atcmd_output); + } + else { + sd->clanspy = c->id; + sprintf(atcmd_output, msg_txt(sd, 1501), c->name); // Spying on the %s clan. + clif_displaymessage(fd, atcmd_output); + } + } + else { + clif_displaymessage(fd, msg_txt(sd, 1502)); // Incorrect clan name/ID. + return -1; + } + + return 0; +} + /*========================================== * @repairall [Valaris] *------------------------------------------*/ @@ -10015,6 +10054,7 @@ void atcommand_basecommands(void) { ACMD_DEF2("mount", mount_peco), ACMD_DEF(guildspy), ACMD_DEF(partyspy), + ACMD_DEF(clanspy), ACMD_DEF(repairall), ACMD_DEF(guildrecall), ACMD_DEF(partyrecall), diff --git a/src/map/clan.c b/src/map/clan.c index 8182751fcd..a6cf75c216 100644 --- a/src/map/clan.c +++ b/src/map/clan.c @@ -54,6 +54,20 @@ struct clan* clan_search( int id ){ return (struct clan*)idb_get(clan_db,id); } +struct clan* clan_searchname( const char* name ){ + struct clan* c; + + DBIterator *iter = db_iterator(clan_db); + for( c = (struct clan*)dbi_first(iter); dbi_exists(iter); c = (struct clan*)dbi_next(iter) ){ + if( strncmpi( c->name, name, NAME_LENGTH ) == 0 ){ + break; + } + } + dbi_destroy(iter); + + return c; +} + struct map_session_data* clan_getavailablesd( struct clan* clan ){ int i; diff --git a/src/map/clan.h b/src/map/clan.h index 88e56ce7b4..f3b8b74a77 100644 --- a/src/map/clan.h +++ b/src/map/clan.h @@ -10,6 +10,7 @@ void do_init_clan(); void do_final_clan(); struct clan* clan_search( int id ); + struct clan* clan_searchname( const char* name ); void clan_load_clandata( int count, struct clan* clans ); void clan_member_joined( struct map_session_data* sd ); void clan_member_left( struct map_session_data* sd ); diff --git a/src/map/clif.c b/src/map/clif.c index bcd115147f..28272a197a 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -647,6 +647,20 @@ int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target WFIFOSET(fd,len); } } + + if (!enable_spy) //Skip unnecessary parsing. [Skotlex] + break; + + iter = mapit_getallusers(); + while ((tsd = (TBL_PC*)mapit_next(iter)) != NULL){ + if (tsd->clanspy == clan->id && packet_db[tsd->packet_ver][RBUFW(buf, 0)].len) + { // packet must exist for the client version + WFIFOHEAD(tsd->fd, len); + memcpy(WFIFOP(tsd->fd, 0), buf, len); + WFIFOSET(tsd->fd, len); + } + } + mapit_free(iter); } break; diff --git a/src/map/map.c b/src/map/map.c index 524dcec141..cee1a98e9b 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -103,7 +103,7 @@ static int block_free_count = 0, block_free_lock = 0; static struct block_list *bl_list[BL_LIST_MAX]; static int bl_list_count = 0; -#define MAP_MAX_MSG 1500 +#define MAP_MAX_MSG 1550 struct map_data map[MAX_MAP_PER_SERVER]; int map_num = 0; diff --git a/src/map/pc.h b/src/map/pc.h index 1c4e4fc5d6..ed1b4f4f45 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -524,6 +524,7 @@ struct map_session_data { short guild_x,guild_y; // For guildmate position display. [Skotlex] should be short [zzo] int guildspy; // [Syrus22] int partyspy; // [Syrus22] + int clanspy; struct clan *clan;