Forráskód Böngészése

Converted CZ_LOCALBROADCAST to struct (#8995)

Lemongrass3110 3 hónapja
szülő
commit
fee336d8ea
3 módosított fájl, 21 hozzáadás és 9 törlés
  1. 13 8
      src/map/clif.cpp
  2. 1 1
      src/map/clif_packetdb.hpp
  3. 7 0
      src/map/packets.hpp

+ 13 - 8
src/map/clif.cpp

@@ -13531,18 +13531,23 @@ void clif_parse_ResetChar(int32 fd, map_session_data *sd) {
 }
 
 
-/// /lb /nlb (CZ_LOCALBROADCAST).
+/// /lb /nlb.
 /// Request to broadcast a message on current map.
-/// 019c <packet len>.W <text>.?B
+/// 019c <packet len>.W <text>.?B (CZ_LOCALBROADCAST)
 void clif_parse_LocalBroadcast(int32 fd, map_session_data* sd)
 {
-	struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
-	char command[CHAT_SIZE_MAX+16];
-	uint32 len = RFIFOW(fd,info->pos[0])-4;
-	char* msg = RFIFOCP(fd,info->pos[1]);
+	if( sd == nullptr ){
+		return;
+	}
 
-	// as the length varies depending on the command used, just block unreasonably long strings
-	mes_len_check(msg, len, CHAT_SIZE_MAX);
+	const PACKET_CZ_LOCALBROADCAST* p = reinterpret_cast<PACKET_CZ_LOCALBROADCAST*>( RFIFOP( fd, 0 ) );
+	size_t len = p->packetSize - sizeof( *p );
+
+	char msg[CHAT_SIZE_MAX];
+
+	safestrncpy( msg, p->message, std::min<size_t>( len, sizeof( msg ) ) );
+
+	char command[CHAT_SIZE_MAX];
 
 	safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
 	is_atcommand(fd, sd, command, 1);

+ 1 - 1
src/map/clif_packetdb.hpp

@@ -196,7 +196,7 @@
 	parseable_packet(0x0198,8,clif_parse_GMChangeMapType,2,4,6);
 	packet(0x0199,4);
 	packet(0x019a,14);
-	parseable_packet(0x019c,-1,clif_parse_LocalBroadcast,2,4);
+	parseable_packet( HEADER_CZ_LOCALBROADCAST, -1, clif_parse_LocalBroadcast, 0 );
 	parseable_packet(0x019d,6,clif_parse_GMHide,2);
 	parseable_packet(0x019f,6,clif_parse_CatchPet,2);
 	parseable_packet(0x01a1,3,clif_parse_PetMenu,2);

+ 7 - 0
src/map/packets.hpp

@@ -1828,6 +1828,13 @@ struct PACKET_CZ_REQ_ITEMCOMPOSITION{
 } __attribute__((packed));
 DEFINE_PACKET_HEADER(CZ_REQ_ITEMCOMPOSITION, 0x17c);
 
+struct PACKET_CZ_LOCALBROADCAST{
+	int16 packetType;
+	uint16 packetSize;
+	char message[];
+} __attribute__((packed));
+DEFINE_PACKET_HEADER(CZ_LOCALBROADCAST, 0x19c);
+
 // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
 #if !defined( sun ) && ( !defined( __NETBSD__ ) || __NetBSD_Version__ >= 600000000 )
 	#pragma pack( pop )