Browse Source

Converted CZ_JOIN_BABY to struct (#8822)

Lemongrass3110 6 months ago
parent
commit
db12c5b2ce
3 changed files with 38 additions and 18 deletions
  1. 29 17
      src/map/clif.cpp
  2. 1 1
      src/map/clif_packetdb.hpp
  3. 8 0
      src/map/packets.hpp

+ 29 - 17
src/map/clif.cpp

@@ -17419,32 +17419,44 @@ void clif_parse_Adopt_request(int32 fd, map_session_data *sd)
 }
 
 
-/// Answer to adopt confirmation (CZ_JOIN_BABY).
-/// 01f7 <account id>.L <char id>.L <answer>.L
+/// Answer to adopt confirmation.
+/// 01f7 <account id>.L <char id>.L <answer>.L (CZ_JOIN_BABY)
 /// answer:
 ///     0 = rejected
 ///     1 = accepted
 void clif_parse_Adopt_reply(int32 fd, map_session_data *sd){
-	struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
-	int32 p1_id = RFIFOL(fd,info->pos[0]);
-	int32 p2_id = RFIFOL(fd,info->pos[1]);
-	int32 result = RFIFOL(fd,info->pos[2]);
-	map_session_data* p1_sd = map_id2sd(p1_id);
-	map_session_data* p2_sd = map_id2sd(p2_id);
+	const PACKET_CZ_JOIN_BABY* p = reinterpret_cast<PACKET_CZ_JOIN_BABY*>( RFIFOP( fd, 0 ) );
 
-	int32 pid = sd->adopt_invite;
-	sd->adopt_invite = 0;
+	// Check if the adoption was accepted
+	if( p->accepted == 0 ){
+		sd->adopt_invite = 0;
+		return;
+	}
+
+	map_session_data* father_sd = map_id2sd( p->father_AID );
+
+	// The father has to be online
+	if( father_sd == nullptr ){
+		sd->adopt_invite = 0;
+		return;
+	}
 
-	if( p1_sd == nullptr || p2_sd == nullptr )
-		return; // Both players need to be online
+	map_session_data* mother_sd = map_id2sd( p->mother_AID );
 
-	if( pid != p1_sd->status.account_id )
-		return; // Incorrect values
+	// The mother has to be online
+	if( mother_sd == nullptr ){
+		sd->adopt_invite = 0;
+		return;
+	}
 
-	if( result == 0 )
-		return; // Rejected
+	if( sd->adopt_invite != father_sd->status.account_id ){
+		sd->adopt_invite = 0;
+		return;
+	}
+
+	sd->adopt_invite = 0;
 
-	pc_adoption(p1_sd, p2_sd, sd);
+	pc_adoption( father_sd, mother_sd, sd );
 }
 
 

+ 1 - 1
src/map/clif_packetdb.hpp

@@ -282,7 +282,7 @@
 	packet(0x01f2,20);
 	packet(0x01f3,10);
 	packet(0x01f6,34);
-	parseable_packet(0x01f7,14,clif_parse_Adopt_reply,2,6,10);
+	parseable_packet( HEADER_CZ_JOIN_BABY, sizeof( PACKET_CZ_JOIN_BABY ), clif_parse_Adopt_reply, 0 );
 	packet(0x01f8,2);
 	parseable_packet(0x01f9,6,clif_parse_Adopt_request,2);
 	packet(0x01fa,48);

+ 8 - 0
src/map/packets.hpp

@@ -1584,6 +1584,14 @@ struct PACKET_CZ_ACTIVE_QUEST{
 } __attribute__((packed));
 DEFINE_PACKET_HEADER(CZ_ACTIVE_QUEST, 0x2b6);
 
+struct PACKET_CZ_JOIN_BABY{
+	int16 packetType;
+	uint32 father_AID;
+	uint32 mother_AID;
+	uint32 accepted;
+} __attribute__((packed));
+DEFINE_PACKET_HEADER(CZ_JOIN_BABY, 0x1f7);
+
 // 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 )