Kaynağa Gözat

Preparatory cleanup of clans (#8416)

Lemongrass3110 11 ay önce
ebeveyn
işleme
aaa9890470

+ 55 - 52
src/map/clan.cpp

@@ -73,13 +73,12 @@ struct clan* clan_searchname( const char* name ){
 	return c;
 }
 
-map_session_data* clan_getavailablesd( struct clan* clan ){
+map_session_data* clan_getavailablesd( struct clan& clan ){
 	int i;
 
-	nullpo_retr(nullptr, clan);
+	ARR_FIND( 0, clan.max_member, i, clan.members[i] != nullptr );
 
-	ARR_FIND( 0, clan->max_member, i, clan->members[i] != nullptr );
-	return ( i < clan->max_member ) ? clan->members[i] : nullptr;
+	return ( i < clan.max_member ) ? clan.members[i] : nullptr;
 }
 
 int clan_getMemberIndex( struct clan* clan, uint32 account_id ){
@@ -110,111 +109,115 @@ int clan_getNextFreeMemberIndex( struct clan* clan ){
 	}
 }
 
-void clan_member_joined( map_session_data* sd ){
-	nullpo_retv(sd);
-
-	if( sd->clan != nullptr ){
+void clan_member_joined( map_session_data& sd ){
+	if( sd.clan != nullptr ){
 		clif_clan_basicinfo( sd );
-		clif_clan_onlinecount( sd->clan );
+		clif_clan_onlinecount( *sd.clan );
 		return;
 	}
 
-	struct clan* clan = clan_search(sd->status.clan_id);
-	int index;
+	struct clan* clan = clan_search( sd.status.clan_id );
+
+	if( clan == nullptr ){
+		return;
+	}
 
-	nullpo_retv(clan);
+	int index = clan_getNextFreeMemberIndex( clan );
 
-	if( ( index = clan_getNextFreeMemberIndex(clan) ) >= 0 ){
-		sd->clan = clan;
-		clan->members[index] = sd;
+	if( index >= 0 ){
+		sd.clan = clan;
+		clan->members[index] = &sd;
 		clan->connect_member++;
 
 		clif_clan_basicinfo(sd);
 
 		intif_clan_member_joined(clan->id);
-		clif_clan_onlinecount(clan);
+		clif_clan_onlinecount( *clan );
 	}
 }
 
-void clan_member_left( map_session_data* sd ){
-	int index;
-	struct clan* clan;
+void clan_member_left( map_session_data& sd ){
+	struct clan* clan = sd.clan;
 
-	nullpo_retv(sd);
-	nullpo_retv(clan = sd->clan);
+	if( clan == nullptr ){
+		return;
+	}
 
-	if( ( index = clan_getMemberIndex(clan,sd->status.account_id) ) >= 0 ){
+	int index = clan_getMemberIndex( clan, sd.status.account_id );
+
+	if( index >= 0 ){
 		clan->members[index] = nullptr;
 		clan->connect_member--;
 
 		intif_clan_member_left(clan->id);
-		clif_clan_onlinecount(clan);
+		clif_clan_onlinecount( *clan );
 	}
 }
 
-bool clan_member_join( map_session_data *sd, int clan_id, uint32 account_id, uint32 char_id ){
-	struct clan *clan;
-
-	nullpo_ret(sd);
+bool clan_member_join( map_session_data& sd, int clan_id, uint32 account_id, uint32 char_id ){
+	struct clan *clan = clan_search( clan_id );
 
-	if( ( clan = clan_search( clan_id ) ) == nullptr ){
+	if( clan == nullptr ){
 		return false;
 	}
 
-	if( sd->status.account_id != account_id || sd->status.char_id != char_id || sd->status.clan_id != 0 ){
+	if( sd.status.account_id != account_id || sd.status.char_id != char_id || sd.status.clan_id != 0 ){
 		return false;
 	}
 
-	sd->status.clan_id = clan->id;
+	sd.status.clan_id = clan->id;
 
 	clan_member_joined(sd);
 
 	return true;
 }
 
-bool clan_member_leave( map_session_data* sd, int clan_id, uint32 account_id, uint32 char_id ){
-	struct clan *clan;
+bool clan_member_leave( map_session_data& sd, int clan_id, uint32 account_id, uint32 char_id ){
+	if( sd.status.account_id != account_id || sd.status.char_id != char_id || sd.status.clan_id != clan_id ){
+		return false;
+	}
 
-	nullpo_ret(sd);
+	struct clan* clan = sd.clan;
 
-	if( sd->status.account_id != account_id || sd->status.char_id != char_id || sd->status.clan_id != clan_id || ( clan = sd->clan ) == nullptr ){
+	if( clan == nullptr ){
 		return false;
 	}
 
 	clan_member_left(sd);
 
-	sd->clan = nullptr;
-	sd->status.clan_id = 0;
+	sd.clan = nullptr;
+	sd.status.clan_id = 0;
 
 	clif_clan_leave(sd);
 
 	return true;
 }
 
-void clan_recv_message(int clan_id,uint32 account_id,const char *mes,int len) {
-	struct clan *clan;
+void clan_recv_message( int clan_id, uint32 account_id, const char *mes, size_t len ){
+	struct clan *clan = clan_search( clan_id );
 
-	nullpo_retv( clan = clan_search(clan_id) );
+	if( clan == nullptr ){
+		return;
+	}
 
-	clif_clan_message(clan,mes,len);
+	clif_clan_message( *clan, mes, len );
 }
 
-void clan_send_message( map_session_data *sd, const char *mes, int len ){
-	nullpo_retv(sd);
-	nullpo_retv(sd->clan);
+void clan_send_message( map_session_data& sd, const char *mes, size_t len ){
+	if( sd.clan == nullptr ){
+		return;
+	}
 
-	intif_clan_message(sd->status.clan_id,sd->status.account_id,mes,len);
-	clan_recv_message(sd->status.clan_id,sd->status.account_id,mes,len);
-	log_chat( LOG_CHAT_CLAN, sd->status.clan_id, sd->status.char_id, sd->status.account_id, mapindex_id2name( sd->mapindex ), sd->bl.x, sd->bl.y, nullptr, mes );
+	intif_clan_message( sd.status.clan_id, sd.status.account_id, mes, len );
+	clan_recv_message( sd.status.clan_id, sd.status.account_id, mes, len );
+	log_chat( LOG_CHAT_CLAN, sd.status.clan_id, sd.status.char_id, sd.status.account_id, mapindex_id2name( sd.mapindex ), sd.bl.x, sd.bl.y, nullptr, mes );
 }
 
-int clan_get_alliance_count( struct clan *clan, int flag ){
-	int i, count;
-
-	nullpo_ret(clan);
+int clan_get_alliance_count( struct clan& clan, int flag ){
+	int count = 0;
 
-	for( i = 0, count = 0; i < MAX_CLANALLIANCE; i++ ){
-		if(	clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
+	for( int i = 0; i < MAX_CLANALLIANCE; i++ ){
+		if(	clan.alliance[i].clan_id > 0 && clan.alliance[i].opposition == flag ){
 			count++;
 		}
 	}

+ 8 - 8
src/map/clan.hpp

@@ -14,13 +14,13 @@ 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( map_session_data* sd );
-void clan_member_left( map_session_data* sd );
-bool clan_member_join( map_session_data *sd, int clan_id, uint32 account_id, uint32 char_id );
-bool clan_member_leave( map_session_data* sd, int clan_id, uint32 account_id, uint32 char_id );
-void clan_send_message( map_session_data *sd, const char *mes, int len );
-void clan_recv_message(int clan_id,uint32 account_id,const char *mes,int len);
-map_session_data* clan_getavailablesd( struct clan* clan );
-int clan_get_alliance_count( struct clan *clan, int flag );
+void clan_member_joined( map_session_data& sd );
+void clan_member_left( map_session_data& sd );
+bool clan_member_join( map_session_data& sd, int clan_id, uint32 account_id, uint32 char_id );
+bool clan_member_leave( map_session_data& sd, int clan_id, uint32 account_id, uint32 char_id );
+void clan_send_message( map_session_data& sd, const char *mes, size_t len );
+void clan_recv_message( int clan_id, uint32 account_id, const char *mes, size_t len );
+map_session_data* clan_getavailablesd( struct clan& clan );
+int clan_get_alliance_count( struct clan& clan, int flag );
 
 #endif /* CLAN_HPP */

+ 64 - 70
src/map/clif.cpp

@@ -20169,27 +20169,35 @@ void clif_party_leaderchanged(map_session_data *sd, int prev_leader_aid, int new
 * Sends a clan message to a player
 * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
 **/
-void clif_clan_message(struct clan *clan,const char *mes,int len){
+void clif_clan_message( struct clan& clan, const char *mes, size_t len ){
 #if PACKETVER >= 20131223
-	map_session_data *sd;
-	uint8 buf[256];
+	map_session_data* sd = clan_getavailablesd( clan );
 
 	if( len == 0 ){
 		return;
-	}else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
-		ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
-		len = sizeof(buf)-5-NAME_LENGTH;
 	}
 
-	WBUFW(buf, 0) = 0x98e;
-	WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
+	PACKET_ZC_NOTIFY_CLAN_CHAT* p = reinterpret_cast<PACKET_ZC_NOTIFY_CLAN_CHAT*>( packet_buffer );
+
+	// Maximum message length = size of our packet buffer minus fixed size of the packet and 1 byte zero termination
+	static size_t len_max = sizeof( packet_buffer ) - sizeof( *p ) - 1;
+
+	// Is the length bigger than the maximum message length
+	if( len > len_max ){
+		ShowWarning( "clif_clan_message: Truncated message '%s' (len=%" PRIuPTR ", max=%" PRIuPTR ", clan_id=%d).\n", mes, len, len_max, clan.id );
+		len = len_max;
+	}
+
+	p->PacketType = HEADER_ZC_NOTIFY_CLAN_CHAT;
+	p->PacketLength = sizeof( *p );
 	
 	// Offially the sender name should also be filled here, but it is not required by the client and since it's in the message too we do not fill it
-	//safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
-	safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
+	safestrncpy( p->MemberName, "", sizeof( p->MemberName ) );
+
+	safestrncpy( p->Message, mes, len + 1 );
+	p->PacketLength += static_cast<decltype(p->PacketLength)>( len + 1 );
 
-	if((sd = clan_getavailablesd(clan)) != nullptr)
-		clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
+	clif_send( p, p->PacketLength, &sd->bl, CLAN );
 #endif
 }
 
@@ -20199,13 +20207,17 @@ void clif_clan_message(struct clan *clan,const char *mes,int len){
 **/
 void clif_parse_clan_chat( int fd, map_session_data* sd ){
 #if PACKETVER >= 20131223
+	if( sd == nullptr ){
+		return;
+	}
+
 	char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
 
 	// validate packet and retrieve name and message
 	if( !clif_process_message(sd, false, name, message, output ) )
 		return;
 
-	clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
+	clan_send_message( *sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
 #endif
 }
 
@@ -20214,52 +20226,38 @@ void clif_parse_clan_chat( int fd, map_session_data* sd ){
 * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
 *      <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
 **/
-void clif_clan_basicinfo( map_session_data *sd ){
-#if PACKETVER >= 20131223
-	int fd, offset, length, i, flag;
-	struct clan* clan;
-	char mapname[MAP_NAME_LENGTH_EXT];
-	
-	nullpo_retv( sd );
-	nullpo_retv( clan = sd->clan );
-	
-	// Check if the player has a valid session and is not autotrading
-	if( !clif_session_isValid( sd ) ){
+void clif_clan_basicinfo( map_session_data& sd ){
+#if PACKETVER_MAIN_NUM >= 20130626 || PACKETVER_RE_NUM >= 20130605 || defined(PACKETVER_ZERO)
+	struct clan* clan = sd.clan;
+
+	if( clan == nullptr ){
 		return;
 	}
 
-	length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
-	fd = sd->fd;
-
-	WFIFOHEAD(fd,length);
-
-	memset( WFIFOP(fd, 0), 0, length );
+	PACKET_ZC_CLANINFO* p = reinterpret_cast<PACKET_ZC_CLANINFO*>( packet_buffer );
 
-	WFIFOW( fd, 0 ) = 0x98a;
-	WFIFOL( fd, 4 ) = clan->id;
-	offset = 8;
-	safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
-	offset += NAME_LENGTH;
-	safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
-	offset += NAME_LENGTH;
-	mapindex_getmapname_ext( clan->map, mapname );
-	safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
-	offset += MAP_NAME_LENGTH_EXT;
+	p->PacketType = HEADER_ZC_CLANINFO;
+	p->PacketLength = sizeof( *p );
+	p->ClanID = clan->id;
+	safestrncpy( p->ClanName, clan->name, sizeof( p->ClanName ) );
+	safestrncpy( p->MasterName, clan->master, sizeof( p->MasterName ) );
+	mapindex_getmapname_ext( clan->map, p->Map );
+	p->AllyCount = clan_get_alliance_count( *clan, 0 );
+	p->AntagonistCount = clan_get_alliance_count( *clan, 1 );
+
+	for( int flag = 0; flag < 2; flag++ ){
+		for( int i = 0; i < MAX_CLANALLIANCE; i++ ){
+			if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
+				char* name = reinterpret_cast<char*>( WBUFP( p, p->PacketLength ) );
 
-	WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
-	WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
+				safestrncpy( name, clan->alliance[i].name, NAME_LENGTH );
 
-	for( flag = 0; flag < 2; flag++ ){
-		for( i = 0; i < MAX_CLANALLIANCE; i++ ){
-			if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
-				safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
-				offset += NAME_LENGTH;
+				p->PacketLength += static_cast<decltype(p->PacketLength)>( NAME_LENGTH );
 			}
 		}
 	}
 
-	WFIFOW( fd, 2 ) = offset;
-	WFIFOSET(fd,offset);
+	clif_send( p, p->PacketLength, &sd.bl, SELF );
 #endif
 }
 
@@ -20267,17 +20265,21 @@ void clif_clan_basicinfo( map_session_data *sd ){
 * Updates the online and maximum player count of a clan.
 * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
 **/
-void clif_clan_onlinecount( struct clan* clan ){
+void clif_clan_onlinecount( struct clan& clan ){
 #if PACKETVER >= 20131223
-	uint8 buf[6];
-	map_session_data *sd;
+	map_session_data* sd = clan_getavailablesd( clan );
+
+	if( sd == nullptr){
+		return;
+	}
+
+	PACKET_ZC_NOTIFY_CLAN_CONNECTINFO p = {};
 
-	WBUFW(buf,0) = 0x988;
-	WBUFW(buf,2) = clan->connect_member;
-	WBUFW(buf,4) = clan->max_member;
+	p.PacketType = HEADER_ZC_NOTIFY_CLAN_CONNECTINFO;
+	p.NumConnect = clan.connect_member;
+	p.NumTotal = clan.max_member;
 
-	if((sd = clan_getavailablesd(clan)) != nullptr)
-		clif_send(buf, 6, &sd->bl, CLAN);
+	clif_send( &p, sizeof( p ), &sd->bl, CLAN );
 #endif
 }
 
@@ -20285,21 +20287,13 @@ void clif_clan_onlinecount( struct clan* clan ){
 * Notifies the client that the player has left his clan.
 * 0989 (ZC_ACK_CLAN_LEAVE)
 **/
-void clif_clan_leave( map_session_data* sd ){
+void clif_clan_leave( map_session_data& sd ){
 #if PACKETVER >= 20131223
-	int fd;
-	
-	nullpo_retv( sd );
-	
-	if( !clif_session_isValid( sd ) ){
-		return;
-	}
-	
-	fd = sd->fd;
+	PACKET_ZC_ACK_CLAN_LEAVE p = {};
 
-	WFIFOHEAD(fd,2);
-	WFIFOW(fd,0) = 0x989;
-	WFIFOSET(fd,2);
+	p.PacketType = HEADER_ZC_ACK_CLAN_LEAVE;
+
+	clif_send( &p, sizeof( p ), &sd.bl, SELF );
 #endif
 }
 

+ 4 - 4
src/map/clif.hpp

@@ -1287,10 +1287,10 @@ void clif_snap( struct block_list *bl, short x, short y );
 void clif_monster_hp_bar( struct mob_data* md, int fd );
 
 // Clan System
-void clif_clan_basicinfo( map_session_data *sd );
-void clif_clan_message(struct clan *clan,const char *mes,int len);
-void clif_clan_onlinecount( struct clan* clan );
-void clif_clan_leave( map_session_data* sd );
+void clif_clan_basicinfo( map_session_data& sd );
+void clif_clan_message( struct clan &clan, const char *mes, size_t len );
+void clif_clan_onlinecount( struct clan& clan );
+void clif_clan_leave( map_session_data& sd );
 
 // Bargain Tool
 void clif_sale_start(struct sale_item_data* sale_item, struct block_list* bl, enum send_target target);

+ 0 - 4
src/map/clif_packetdb.hpp

@@ -1990,11 +1990,7 @@
 	packet(0x09D7,-1);
 	parseable_packet(0x09D8,2,clif_parse_NPCMarketClosed,0);
 	// Clan System
-	packet(0x0988,6);
-	packet(0x0989,2);
-	packet(0x098A,-1);
 	parseable_packet(0x098D,-1,clif_parse_clan_chat,2,4);
-	packet(0x098E,-1);
 	// Sale
 	parseable_packet( HEADER_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO, -1, clif_parse_sale_search, 0 );
 	packet( HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO, sizeof( PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO ) );

+ 1 - 1
src/map/instance.cpp

@@ -317,7 +317,7 @@ void instance_getsd(int instance_id, map_session_data *&sd, enum send_target *ta
 			(*target) = SELF;
 			break;
 		case IM_CLAN:
-			sd = clan_getavailablesd(clan_search(idata->owner_id));
+			sd = clan_getavailablesd( *clan_search( idata->owner_id ) );
 			(*target) = CLAN;
 	}
 	return;

+ 3 - 3
src/map/intif.cpp

@@ -3686,7 +3686,7 @@ void intif_parse_clans( int fd ){
 	clan_load_clandata( ( RFIFOW(fd, 2) - 4 ) / sizeof( struct clan ), (struct clan*)RFIFOP(fd,4) );
 }
 
-int intif_clan_message(int clan_id,uint32 account_id,const char *mes,int len){
+int intif_clan_message( int clan_id, uint32 account_id, const char *mes, size_t len ){
 	if (CheckForCharServer())
 		return 0;
 
@@ -3695,7 +3695,7 @@ int intif_clan_message(int clan_id,uint32 account_id,const char *mes,int len){
 
 	WFIFOHEAD(inter_fd, len + 12);
 	WFIFOW(inter_fd,0)=0x30A1;
-	WFIFOW(inter_fd,2)=len+12;
+	WFIFOW( inter_fd, 2 ) = static_cast<uint16>( len + 12 );
 	WFIFOL(inter_fd,4)=clan_id;
 	WFIFOL(inter_fd,8)=account_id;
 	safestrncpy(WFIFOCP(inter_fd,12),mes,len);
@@ -3749,7 +3749,7 @@ int intif_parse_clan_onlinecount( int fd ){
 
 	clan->connect_member = RFIFOW(fd,6);
 
-	clif_clan_onlinecount(clan);
+	clif_clan_onlinecount( *clan );
 
 	return 1;
 }

+ 1 - 1
src/map/intif.hpp

@@ -116,7 +116,7 @@ int intif_elemental_delete(int ele_id);
 int intif_elemental_save(struct s_elemental *ele);
 // CLAN SYSTEM
 int intif_clan_requestclans();
-int intif_clan_message(int clan_id,uint32 account_id,const char *mes,int len);
+int intif_clan_message( int clan_id, uint32 account_id, const char *mes, size_t len );
 int intif_clan_member_joined( int clan_id );
 int intif_clan_member_left( int clan_id );
 // ACHIEVEMENT SYSTEM

+ 1 - 1
src/map/map.cpp

@@ -2134,7 +2134,7 @@ int map_quit(map_session_data *sd) {
 		bg_queue_leave(sd, false);
 
 	if( sd->status.clan_id )
-		clan_member_left(sd);
+		clan_member_left( *sd );
 
 	pc_itemcd_do(sd,false);
 

+ 3 - 0
src/map/packets.hpp

@@ -1065,6 +1065,9 @@ DEFINE_PACKET_HEADER(CZ_SKILL_SELECT_RESPONSE, 0x443)
 DEFINE_PACKET_HEADER(ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER, 0x824)
 DEFINE_PACKET_HEADER(CZ_SSILIST_ITEM_CLICK, 0x83c)
 DEFINE_PACKET_HEADER(ZC_ACK_SCHEDULER_CASHITEM, 0x8ca)
+DEFINE_PACKET_HEADER(ZC_NOTIFY_CLAN_CONNECTINFO, 0x988)
+DEFINE_PACKET_HEADER(ZC_ACK_CLAN_LEAVE, 0x989)
+DEFINE_PACKET_HEADER(ZC_NOTIFY_CLAN_CHAT, 0x98e)
 DEFINE_PACKET_HEADER(CZ_REQ_BANKING_DEPOSIT, 0x9a7)
 DEFINE_PACKET_HEADER(CZ_REQ_BANKING_WITHDRAW, 0x9a9)
 DEFINE_PACKET_HEADER(CZ_REQ_BANKING_CHECK, 0x9ab)

+ 1 - 1
src/map/pc.cpp

@@ -2388,7 +2388,7 @@ void pc_reg_received(map_session_data *sd)
 	if (sd->status.guild_id > 0)
 		guild_member_joined(sd);
 	if (sd->status.clan_id > 0)
-		clan_member_joined(sd);
+		clan_member_joined( *sd );
 #if !( PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410 )
 	// Before those clients you could send out the instance info even when the client was still loading the map, afterwards you need to send it later
 	clif_instance_info( *sd );

+ 3 - 3
src/map/script.cpp

@@ -23916,7 +23916,7 @@ BUILDIN_FUNC(clan_join){
 		return SCRIPT_CMD_FAILURE;
 	}
 
-	if( clan_member_join( sd, clan_id, sd->status.account_id, sd->status.char_id ) )
+	if( clan_member_join( *sd, clan_id, sd->status.account_id, sd->status.char_id ) )
 		script_pushint(st, true);
 	else
 		script_pushint(st, false);
@@ -23925,14 +23925,14 @@ BUILDIN_FUNC(clan_join){
 }
 
 BUILDIN_FUNC(clan_leave){
-	map_session_data *sd;
+	map_session_data* sd;
 
 	if( !script_charid2sd( 2, sd ) ){
 		script_pushint(st, false);
 		return SCRIPT_CMD_FAILURE;
 	}
 
-	if( clan_member_leave( sd, sd->status.clan_id, sd->status.account_id, sd->status.char_id ) )
+	if( clan_member_leave( *sd, sd->status.clan_id, sd->status.account_id, sd->status.char_id ) )
 		script_pushint(st, true);
 	else
 		script_pushint(st, false);