예제 #1
0
파일: chat.c 프로젝트: Nihadm89/server
/*==========================================
 * leave a chatroom
 *------------------------------------------*/
int chat_leavechat(struct map_session_data* sd, bool kicked)
{
	struct chat_data* cd;
	int i;
	int leavechar;

	nullpo_retr(1, sd);

	cd = (struct chat_data*)map_id2bl(sd->chatID);
	if( cd == NULL )
	{
		pc_setchatid(sd, 0);
		return 1;
	}

	ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd );
	if ( i == cd->users )
	{	// Not found in the chatroom?
		pc_setchatid(sd, 0);
		return -1;
	}

	clif_leavechat(cd, sd, kicked);
	pc_setchatid(sd, 0);
	cd->users--;

	leavechar = i;

	for( i = leavechar; i < cd->users; i++ )
		cd->usersd[i] = cd->usersd[i+1];


	if( cd->users == 0 && cd->owner->type == BL_PC )
	{	// Delete empty chatroom
		clif_clearchat(cd, 0);
		map_deliddb(&cd->bl);
		map_delblock(&cd->bl);
		map_freeblock(&cd->bl);
		return 1;
	}

	if( leavechar == 0 && cd->owner->type == BL_PC )
	{	// Set and announce new owner
		cd->owner = (struct block_list*) cd->usersd[0];
		clif_changechatowner(cd, cd->usersd[0]);
		clif_clearchat(cd, 0);

		//Adjust Chat location after owner has been changed.
		map_delblock( &cd->bl );
		cd->bl.x=cd->usersd[0]->bl.x;
		cd->bl.y=cd->usersd[0]->bl.y;
		map_addblock( &cd->bl );

		clif_dispchat(cd,0);
	}
	else
		clif_dispchat(cd,0); // refresh chatroom

	return 0;
}
예제 #2
0
/*==========================================
 * 一時objectの解放
 * block_listからの削除、id_dbからの削除
 * object dataのfree、object[]へのNULL代入
 *
 * addとの対称性が無いのが気になる
 *------------------------------------------
 */
int map_delobject(int id)
{
	struct block_list *obj=object[id];

	if(obj==NULL)
		return 0;

	map_delobjectnofree(id);	
	map_freeblock(obj);

	return 0;
}
예제 #3
0
파일: chat.c 프로젝트: Nihadm89/server
/// Removes the chatroom from the npc.
int chat_deletenpcchat(struct npc_data* nd)
{
	struct chat_data *cd;
	nullpo_ret(nd);

	cd = (struct chat_data*)map_id2bl(nd->chat_id);
	if( cd == NULL )
		return 0;
	
	chat_npckickall(cd);
	clif_clearchat(cd, 0);
	map_deliddb(&cd->bl);
	map_delblock(&cd->bl);
	map_freeblock(&cd->bl);
	nd->chat_id = 0;
	
	return 0;
}
예제 #4
0
/*==========================================
 * leave a chatroom
 *------------------------------------------*/
int chat_leavechat(struct map_session_data *sd, bool kicked)
{
	struct chat_data *cd;
	int i;
	int leavechar;

	nullpo_retr(1, sd);

	cd = (struct chat_data *)map_id2bl(sd->chatID);
	if(cd == NULL) {
		pc_setchatid(sd, 0);
		return 1;
	}

	ARR_FIND(0, cd->users, i, cd->usersd[i] == sd);
	if(i == cd->users) {
		// Not found in the chatroom?
		pc_setchatid(sd, 0);
		return -1;
	}

	clif_leavechat(cd, sd, kicked);
	pc_setchatid(sd, 0);
	cd->users--;

	leavechar = i;

	for(i = leavechar; i < cd->users; i++)
		cd->usersd[i] = cd->usersd[i+1];


	if(cd->users == 0 && cd->owner->type == BL_PC) {   // Delete empty chatroom
		struct skill_unit *unit;
		struct skill_unit_group *group;

		clif_clearchat(cd, 0);
		db_destroy(cd->kick_list);
		map_deliddb(&cd->bl);
		map_delblock(&cd->bl);
		map_freeblock(&cd->bl);

		unit = map_find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0);
		group = (unit != NULL) ? unit->group : NULL;
		if(group != NULL)
			ext_skill_unit_onplace(unit, &sd->bl, group->tick);

		return 1;
	}

	if(leavechar == 0 && cd->owner->type == BL_PC) {
		// Set and announce new owner
		cd->owner = (struct block_list *) cd->usersd[0];
		clif_changechatowner(cd, cd->usersd[0]);
		clif_clearchat(cd, 0);

		//Adjust Chat location after owner has been changed.
		map_delblock(&cd->bl);
		cd->bl.x=cd->usersd[0]->bl.x;
		cd->bl.y=cd->usersd[0]->bl.y;
		map_addblock(&cd->bl);

		clif_dispchat(cd,0);
	} else
		clif_dispchat(cd,0); // refresh chatroom

	return 0;
}