浏览代码

Atcommand clanspy

Lemongrass3110 8 年之前
父节点
当前提交
633d50fa72
共有 7 个文件被更改,包括 77 次插入1 次删除
  1. 6 0
      conf/msg_conf/map_msg.conf
  2. 40 0
      src/map/atcommand.c
  3. 14 0
      src/map/clan.c
  4. 1 0
      src/map/clan.h
  5. 14 0
      src/map/clif.c
  6. 1 1
      src/map/map.c
  7. 1 0
      src/map/pc.h

+ 6 - 0
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 <clan_name/ID>).
+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

+ 40 - 0
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 <clan_name/ID>).
+		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),

+ 14 - 0
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;
 

+ 1 - 0
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 );

+ 14 - 0
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;
 

+ 1 - 1
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;

+ 1 - 0
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;