Kaynağa Gözat

Converted ZC_ROOM_NEWENTRY to struct (#8718)

Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>
Alvisrynoc 5 ay önce
ebeveyn
işleme
ae9d36eff6
6 değiştirilmiş dosya ile 91 ekleme ve 79 silme
  1. 8 8
      src/map/chat.cpp
  2. 58 66
      src/map/clif.cpp
  3. 8 1
      src/map/clif.hpp
  4. 0 1
      src/map/clif_packetdb.hpp
  5. 12 0
      src/map/packets.hpp
  6. 5 3
      src/map/pc.cpp

+ 8 - 8
src/map/chat.cpp

@@ -106,7 +106,7 @@ int32 chat_createpcchat(map_session_data* sd, const char* title, const char* pas
 		pc_setchatid(sd,cd->bl.id);
 		pc_stop_attack(sd);
 		clif_createchat( *sd, CREATEROOM_SUCCESS );
-		clif_dispchat(cd,0);
+		clif_dispchat(*cd);
 
 		if (status_isdead(sd->bl))
 			achievement_update_objective(sd, AG_CHATTING_DYING, 1, 1);
@@ -172,7 +172,7 @@ int32 chat_joinchat(map_session_data* sd, int32 chatid, const char* pass)
 	clif_joinchatok(*sd, *cd);
 	// Reports to the persons, who already are in the chat
 	clif_addchat( *cd, *sd );
-	clif_dispchat(cd, 0); //Reported number of changes to the people around
+	clif_dispchat(*cd); //Reported number of changes to the people around
 
 	if (cd->owner->type == BL_PC)
 		achievement_update_objective(map_id2sd(cd->owner->id), AG_CHATTING_COUNT, 1, cd->users);
@@ -246,9 +246,9 @@ int32 chat_leavechat(map_session_data* sd, bool kicked)
 		if(map_addblock( &cd->bl ))
 			return 1;
 
-		clif_dispchat(cd,0);
+		clif_dispchat(*cd);
 	} else
-		clif_dispchat(cd,0); // refresh chatroom
+		clif_dispchat(*cd); // refresh chatroom
 
 	return 0;
 }
@@ -299,7 +299,7 @@ int32 chat_changechatowner(map_session_data* sd, const char* nextownername)
 		return 1;
 
 	// and display again
-	clif_dispchat(cd,0);
+	clif_dispchat(*cd);
 
 	return 0;
 }
@@ -330,7 +330,7 @@ int32 chat_changechatstatus(map_session_data* sd, const char* title, const char*
 	cd->pub = pub;
 
 	clif_changechatstatus(*cd);
-	clif_dispchat(cd,0);
+	clif_dispchat(*cd);
 
 	return 0;
 }
@@ -416,9 +416,9 @@ int32 chat_createnpcchat(struct npc_data* nd, const char* title, int32 limit, bo
 
 	cd = chat_createchat(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl);
 
-	if( cd ) {
+	if( cd != nullptr ){
 		nd->chat_id = cd->bl.id;
-		clif_dispchat(cd,0);
+		clif_dispchat(*cd);
 	}
 
 	return 0;

+ 58 - 66
src/map/clif.cpp

@@ -4490,62 +4490,61 @@ void clif_createchat( map_session_data& sd, e_create_chatroom flag ){
 	clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
 }
 
-
-/// Display a chat above the owner (ZC_ROOM_NEWENTRY).
-/// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
+/// Calculates the chat status
 /// type:
 ///     0 = private (password protected)
 ///     1 = public
 ///     2 = arena (npc waiting room)
 ///     3 = PK zone (non-clickable)
-void clif_dispchat(struct chat_data* cd, int32 fd)
-{
-	unsigned char buf[128];
-	uint8 type;
+static e_status_chatroom clif_chat_status( const chat_data &cd ){
+	if (cd.owner->type == BL_PC)
+		return (cd.pub) ? STATUSROOM_PUBLIC : STATUSROOM_PRIVATE;
+	else if (cd.owner->type == BL_NPC)
+		return (cd.limit) ? STATUSROOM_ARENA : STATUSROOM_PK_ZONE;
+	else
+		return STATUSROOM_PUBLIC;
+}
 
-	if( cd == nullptr || cd->owner == nullptr )
+/// Calculates the chat user count
+static uint16 clif_chat_usercount( const chat_data& cd ){
+	if( cd.owner->type == BL_NPC ){
+		return cd.users + 1;
+	}else{
+		return cd.users;
+	}
+}
+
+/// Display a chat above the owner.
+/// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B (ZC_ROOM_NEWENTRY)
+void clif_dispchat( const chat_data& cd ){
+	if( cd.owner == nullptr ){
 		return;
+	}
 
-	type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
-	     : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
-	     : 1;
+	PACKET_ZC_ROOM_NEWENTRY* p = reinterpret_cast<PACKET_ZC_ROOM_NEWENTRY*>( packet_buffer );
 
-	WBUFW(buf, 0) = 0xd7;
-	WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
-	WBUFL(buf, 4) = cd->owner->id;
-	WBUFL(buf, 8) = cd->bl.id;
-	WBUFW(buf,12) = cd->limit;
-	WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
-	WBUFB(buf,16) = type;
-	memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
+	p->packetType = HEADER_ZC_ROOM_NEWENTRY;
+	p->packetSize = sizeof( *p );
+	p->owner = cd.owner->id;
+	p->id = cd.bl.id;
+	p->limit = cd.limit;
+	p->users = clif_chat_usercount( cd );
+	p->type = clif_chat_status( cd );
 
-	if( session_isActive(fd) ) {
-		WFIFOHEAD(fd,WBUFW(buf,2));
-		memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
-		WFIFOSET(fd,WBUFW(buf,2));
-	} else {
-		clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
-	}
-}
+	// not zero-terminated
+	size_t max = safestrnlen( cd.title, CHATROOM_TITLE_SIZE );
+	strncpy( p->title, cd.title, max );
+	p->packetSize += static_cast<decltype(p->packetSize)>( max );
 
+	clif_send( p, p->packetSize, cd.owner, AREA_WOSC );
+}
 
-/// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
-/// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
-/// type:
-///     0 = private (password protected)
-///     1 = public
-///     2 = arena (npc waiting room)
-///     3 = PK zone (non-clickable)
+/// Chatroom properties adjustment.
+/// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B (ZC_CHANGE_CHATROOM)
 void clif_changechatstatus(chat_data& cd) {
-	if(cd.usersd[0] == nullptr )
+	if( cd.owner == nullptr ){
 		return;
-
-	enum e_chat_flags:uint8 {
-		CHAT_PRIVATE = 0,
-		CHAT_PUBLIC,
-		CHAT_ARENA,
-		CHAT_PK
-	};
+	}
 
 	PACKET_ZC_CHANGE_CHATROOM* p = reinterpret_cast<PACKET_ZC_CHANGE_CHATROOM*>( packet_buffer );
 
@@ -4554,27 +4553,14 @@ void clif_changechatstatus(chat_data& cd) {
 	p->ownerId = cd.owner->id;
 	p->chatId = cd.bl.id;
 	p->limit = cd.limit;
-	p->users = cd.users;
+	p->users = clif_chat_usercount( cd );
+	p->flag = clif_chat_status( cd );
 
 	// not zero-terminated
 	size_t max = safestrnlen( cd.title, CHATROOM_TITLE_SIZE );
 	strncpy( p->title, cd.title, max );
 	p->packetSize += static_cast<decltype(p->packetSize)>( max );
 
-	if(cd.owner->type == BL_NPC){
-		// NPC itself counts as additional chat user
-		p->users++;
-
-		if(cd.limit)
-			p->flag = CHAT_ARENA;
-		else
-			p->flag = CHAT_PK;
-	}else if(cd.owner->type == BL_PC && cd.pub == false){
-		p->flag = CHAT_PRIVATE;
-	}else{
-		p->flag = CHAT_PUBLIC;
-	}
-
 	clif_send(p,p->packetSize,cd.owner,CHAT);
 }
 
@@ -4619,8 +4605,6 @@ void clif_joinchatfail( map_session_data& sd, e_refuse_enter_room result ){
 ///     0 = owner (menu)
 ///     1 = normal
 void clif_joinchatok(map_session_data& sd, chat_data& cd){
-
-
 	PACKET_ZC_ENTER_ROOM* p = reinterpret_cast<PACKET_ZC_ENTER_ROOM*>( packet_buffer );
 
 	p->packetType = HEADER_ZC_ENTER_ROOM;
@@ -4653,7 +4637,6 @@ void clif_joinchatok(map_session_data& sd, chat_data& cd){
 	}
 
 	clif_send(p,p->packetSize,&sd.bl,SELF);
-
 }
 
 
@@ -4976,9 +4959,11 @@ static void clif_getareachar_pc(map_session_data* sd,map_session_data* dstsd)
 	int32 i;
 
 	if( dstsd->chatID ) {
-		struct chat_data *cd = nullptr;
-		if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
-			clif_dispchat(cd,sd->fd);
+		chat_data* cd = map_id2cd( dstsd->chatID );
+
+		if( cd != nullptr && cd->usersd[0] == dstsd ){
+			clif_dispchat(*cd);
+		}
 	} else if( dstsd->state.vending )
 		clif_showvendingboard( *dstsd, SELF, &sd->bl );
 	else if( dstsd->state.buyingstore )
@@ -5071,8 +5056,15 @@ void clif_getareachar_unit( map_session_data* sd,struct block_list *bl ){
 	case BL_NPC:
 		{
 			TBL_NPC* nd = (TBL_NPC*)bl;
-			if( nd->chat_id )
-				clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
+
+			if( nd->chat_id ){
+				chat_data* cd = map_id2cd( nd->chat_id );
+
+				if( cd != nullptr ){
+					clif_dispchat( *cd );
+				}
+			}
+
 			if( nd->size == SZ_BIG )
 				clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
 			else if( nd->size == SZ_MEDIUM )
@@ -5581,7 +5573,7 @@ int32 clif_outsight(struct block_list *bl,va_list ap)
 				struct chat_data *cd;
 				cd=(struct chat_data*)map_id2bl(sd->chatID);
 				if(cd->usersd[0]==sd)
-					clif_dispchat(cd,tsd->fd);
+					clif_dispchat(*cd);
 			}
 			if(sd->state.vending)
 				clif_closevendingboard(bl,tsd->fd);

+ 8 - 1
src/map/clif.hpp

@@ -758,6 +758,13 @@ enum e_create_chatroom : uint8 {
 	CREATEROOM_ALREADY_EXISTS = 2
 };
 
+enum e_status_chatroom : uint8 {
+	STATUSROOM_PRIVATE = 0,
+	STATUSROOM_PUBLIC,
+	STATUSROOM_ARENA,
+	STATUSROOM_PK_ZONE
+};
+
 enum e_action_failure : uint8 {
 	ARROWFAIL_NO_AMMO = 0,
 	ARROWFAIL_WEIGHT_LIMIT = 1,
@@ -883,7 +890,7 @@ void clif_changeoption2( block_list& bl );
 void clif_useitemack(map_session_data *sd,int32 index,int32 amount,bool ok);	// self
 void clif_GlobalMessage( block_list& bl, const char* message, enum send_target target );
 void clif_createchat( map_session_data& sd, e_create_chatroom flag );
-void clif_dispchat(struct chat_data* cd, int32 fd);	// area or fd
+void clif_dispchat( const chat_data& cd );
 void clif_joinchatfail( map_session_data& sd, e_refuse_enter_room result );
 void clif_joinchatok(map_session_data& sd,chat_data& cd);
 void clif_addchat( chat_data& cd, map_session_data& sd );

+ 0 - 1
src/map/clif_packetdb.hpp

@@ -85,7 +85,6 @@
 	parseable_packet(0x00d3,2,clif_parse_PMIgnoreList,0);
 	packet(0x00d4,-1);
 	parseable_packet( HEADER_CZ_CREATE_CHATROOM, -1, clif_parse_CreateChatRoom, 0 );
-	packet(0x00d7,-1);
 	parseable_packet(0x00d9,14,clif_parse_ChatAddMember,2,6);
 	parseable_packet(0x00de,-1,clif_parse_ChatRoomStatusChange,2,4,6,7,15);
 	parseable_packet(0x00e0,30,clif_parse_ChangeChatOwner,2,6);

+ 12 - 0
src/map/packets.hpp

@@ -1622,6 +1622,18 @@ struct PACKET_ZC_DRESSROOM_OPEN{
 } __attribute__((packed));
 DEFINE_PACKET_HEADER(ZC_DRESSROOM_OPEN, 0xa02);
 
+struct PACKET_ZC_ROOM_NEWENTRY {
+	int16 packetType;
+	uint16 packetSize; 
+	int32 owner;
+	int32 id;
+	uint16 limit;
+	uint16 users;
+	uint8 type;
+	char title[];
+} __attribute__((packed));
+DEFINE_PACKET_HEADER(ZC_ROOM_NEWENTRY, 0xd7);
+
 // 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 )

+ 5 - 3
src/map/pc.cpp

@@ -3018,9 +3018,11 @@ int32 pc_disguise(map_session_data *sd, int32 class_)
 			clif_updatestatus(*sd,SP_CARTINFO);
 		}
 		if (sd->chatID) {
-			struct chat_data* cd;
-			if ((cd = (struct chat_data*)map_id2bl(sd->chatID)) != nullptr)
-				clif_dispchat(cd,0);
+			chat_data* cd = map_id2cd( sd->chatID );
+
+			if( cd != nullptr ){
+				clif_dispchat( *cd );
+			}
 		}
 	}
 	return 1;