Esempio n. 1
0
/// Updates the party info related to the target character.
/// Returns true on success.
bool inter_party_update(struct mmo_charstatus* cd)
{
	struct party_data* p;
	struct party_member* member;
	int i;

	if( cd == NULL || cd->party_id == 0 )
		return false; // character not in a party
	p = inter_party_fromsql(cd->party_id);
	if( p == NULL )
		return false; // invalid party
	for( i = 0; i <= p->party.count; ++i )
	{
		member = &p->party.member[i];
		if( member->account_id != cd->account_id || member->char_id != cd->char_id )
			continue;
		safestrncpy(member->name, cd->name, NAME_LENGTH);
		member->class_ = cd->class_;
		member->map = cd->last_point.map;
		member->lv = cd->base_level;
		mapif_party_info(-1, &p->party, cd->char_id); // send to all map servers
		return true; // found and updated
	}
	return false; // not found
}
Esempio n. 2
0
//-----------------------
// A member change of map
//-----------------------
void mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, char *map, unsigned char online, int lv) { // online: 0: offline, 1:online
	int i;

	inter_party_fromsql(party_id); // fill party_tmp with informations of the party (or set all values to 0)

	if (party_tmp.party_id <= 0) // party doesn't exist
		return;

	for(i = 0; i < MAX_PARTY; i++) {
		if (party_tmp.member[i].account_id == account_id) { // same account can have more than character in same party. we must check name here too!
			memset(party_tmp.member[i].map, 0, sizeof(party_tmp.member[i].map));
			strncpy(party_tmp.member[i].map, map, 16); // 17 - NULL
			party_tmp.member[i].online = online; // online: 0: offline, 1:online
			party_tmp.member[i].lv = lv;
			mapif_party_membermoved(&party_tmp, i);

			if (party_tmp.exp > 0 && !party_check_exp_share(&party_tmp)) {
				party_tmp.exp = 0;
				mapif_party_optionchanged(fd, &party_tmp, 0, 0);
			}
			break;
		}
	}
	inter_party_tosql(party_id, &party_tmp);

	return;
}
Esempio n. 3
0
// パーティー設定変更要求
int mapif_parse_PartyChangeOption(int fd,int party_id,int account_id,int exp,int item)
{
	struct party *p;
	int flag=0;

	p = party_pt;
	if(p==NULL){
		ShowFatalError("int_party: out of memory !\n");
		return 0;
	}

	inter_party_fromsql(party_id, p);

	if(p->party_id <= 0){
		return 0;
	}

	p->exp=exp;
	if( exp>0 && !party_check_exp_share(p) ){
		flag|=0x01;
		p->exp=0;
	}

	p->item=item;

	mapif_party_optionchanged(fd,p,account_id,flag);
	inter_party_tosql(party_id, p);
	return 0;
}
Esempio n. 4
0
int inter_party_charname_changed(int party_id, uint32 char_id, char *name)
{
	struct party_data* p = NULL;
	int i;

	p = inter_party_fromsql(party_id);
	if( p == NULL || p->party.party_id == 0 )
	{
		ShowError("inter_party_charname_changed: Can't find party %d.\n", party_id);
		return 0;
	}

	ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == char_id);
	if( i == MAX_PARTY )
	{
		ShowError("inter_party_charname_changed: Can't find character %d in party %d.\n", char_id, party_id);
		return 0;
	}

	safestrncpy(p->party.member[i].name, name, NAME_LENGTH);

	mapif_party_info(-1, &p->party, char_id);
	
	return 0;
}
Esempio n. 5
0
int inter_party_CharOnline (int char_id, int party_id)
{
	struct party_data *p;
	int i;

	if (party_id == -1)
	{
		// Get party_id from the database
		char *data;

		if (SQL_ERROR == Sql_Query (sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id))
		{
			Sql_ShowDebug (sql_handle);
			return 0;
		}

		if (SQL_SUCCESS != Sql_NextRow (sql_handle))
			return 0; //Eh? No party?

		Sql_GetData (sql_handle, 0, &data, NULL);
		party_id = atoi (data);
		Sql_FreeResult (sql_handle);
	}

	if (party_id == 0)
		return 0; //No party...

	p = inter_party_fromsql (party_id);

	if (!p)
	{
		ShowError ("Character %d's party %d not found!\n", char_id, party_id);
		return 0;
	}

	//Set member online
	for (i = 0; i < MAX_PARTY; i++)
	{
		if (p->party.member[i].char_id == char_id)
		{
			if (!p->party.member[i].online)
			{
				p->party.member[i].online = 1;
				p->party.count++;

				if (p->party.member[i].lv < p->min_lv ||
						p->party.member[i].lv > p->max_lv)
					int_party_check_lv (p);
			}

			break;
		}
	}

	return 1;
}
Esempio n. 6
0
// パーティ情報要求
static void mapif_parse_PartyInfo(int fd, int party_id, int char_id)
{
	struct party_data *p;
	p = inter_party_fromsql(party_id);

	if (p)
		mapif_party_info(fd, &p->party, char_id);
	else
		mapif_party_noinfo(fd, party_id, char_id);
}
Esempio n. 7
0
//----------------------------------
// Request to have party information
//----------------------------------
void mapif_parse_PartyInfo(int fd, int party_id) { // 0x3021 <party_id>.L - ask for party
	inter_party_fromsql(party_id); // fill party_tmp with informations of the party (or set all values to 0)

	if (party_tmp.party_id >= 0)
		mapif_party_info(fd, &party_tmp);
	else
		mapif_party_noinfo(fd, party_id); // party doesn't exist

	return;
}
Esempio n. 8
0
// When member goes to other map or levels up.
int mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, int char_id, unsigned short map, int online, unsigned int lv)
{
	struct party_data *p;
	int i;

	p = inter_party_fromsql(party_id);
	if (p == NULL)
		return 0;

	for(i = 0; i < MAX_PARTY && 
		(p->party.member[i].account_id != account_id ||
		p->party.member[i].char_id != char_id); i++);

	if (i == MAX_PARTY) return 0;

	if (p->party.member[i].online != online)
	{
		p->party.member[i].online = online;
		if (online)
			p->party.count++;
		else
			p->party.count--;
		// Even share check situations: Family state (always breaks)
		// character logging on/off is max/min level (update level range) 
		// or character logging on/off has a different level (update level range using new level)
		if (p->family ||
			(p->party.member[i].lv <= p->min_lv || p->party.member[i].lv >= p->max_lv) ||
			(p->party.member[i].lv != lv && (lv <= p->min_lv || lv >= p->max_lv))
			)
		{
			p->party.member[i].lv = lv;
			int_party_check_lv(p);
		}
		//Send online/offline update.
		mapif_party_membermoved(&p->party, i);
	}

	if (p->party.member[i].lv != lv) {
		if(p->party.member[i].lv == p->min_lv ||
			p->party.member[i].lv == p->max_lv)
		{
			p->party.member[i].lv = lv;
			int_party_check_lv(p);
		} else
			p->party.member[i].lv = lv;
		//There is no need to send level update to map servers
		//since they do nothing with it.
	}

	if (p->party.member[i].map != map) {
		p->party.member[i].map = map;
		mapif_party_membermoved(&p->party, i);
	}
	return 0;
}
Esempio n. 9
0
// パーティ情報要求
int mapif_parse_PartyInfo(int fd,int party_id)
{
	struct party_data *p;
	p = inter_party_fromsql(party_id);

	if (p)
		mapif_party_info(fd,&p->party);
	else
		mapif_party_noinfo(fd,party_id);
	return 0;
}
Esempio n. 10
0
//-----------------
// Break of a party
//-----------------
void mapif_parse_BreakParty(int fd, int party_id) {
	inter_party_fromsql(party_id); // fill party_tmp with informations of the party (or set all values to 0)

	if (party_tmp.party_id <= 0) // party doesn't exist
		return;

	inter_party_tosql(party_id, &party_tmp);

	mapif_party_broken(party_id);

	return;
}
Esempio n. 11
0
// パーティ解散要求
int mapif_parse_BreakParty(int fd,int party_id)
{
	struct party_data *p;

	p = inter_party_fromsql(party_id);

	if(!p)
		return 0;
	inter_party_tosql(&p->party,PS_BREAK,0);
	mapif_party_broken(fd,party_id);
	return 0;
}
Esempio n. 12
0
int inter_party_CharOffline (int char_id, int party_id)
{
	struct party_data *p = NULL;
	int i;

	if (party_id == -1)
	{
		// Get guild_id from the database
		char *data;

		if (SQL_ERROR == Sql_Query (sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id))
		{
			Sql_ShowDebug (sql_handle);
			return 0;
		}

		if (SQL_SUCCESS != Sql_NextRow (sql_handle))
			return 0; //Eh? No party?

		Sql_GetData (sql_handle, 0, &data, NULL);
		party_id = atoi (data);
		Sql_FreeResult (sql_handle);
	}

	if (party_id == 0)
		return 0; //No party...

	//Character has a party, set character offline and check if they were the only member online
	if ( (p = inter_party_fromsql (party_id)) == NULL)
		return 0;

	//Set member offline
	for (i = 0; i < MAX_PARTY; i++)
	{
		if (p->party.member[i].char_id == char_id)
		{
			p->party.member[i].online = 0;
			p->party.count--;

			if (p->party.member[i].lv == p->min_lv ||
					p->party.member[i].lv == p->max_lv)
				int_party_check_lv (p);

			break;
		}
	}

	if (!p->party.count)
		//Parties don't have any data that needs be saved at this point... so just remove it from memory.
		idb_remove (party_db_, party_id);

	return 1;
}
Esempio n. 13
0
//Request leave party
int mapif_parse_PartyLeave(int fd, int party_id, uint32 account_id, uint32 char_id, char *name, enum e_party_member_withdraw type)
{
	struct party_data *p;
	int i,j=-1;

	p = inter_party_fromsql(party_id);
	if( p == NULL )
	{// Party does not exists?
		if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", schema_config.char_db, party_id) )
			Sql_ShowDebug(sql_handle);
		return 0;
	}

	for (i = 0; i < MAX_PARTY; i++) {
		if(p->party.member[i].account_id == account_id &&
			p->party.member[i].char_id == char_id) {
			break;
		}
	}
	if (i >= MAX_PARTY)
		return 0; //Member not found?

	mapif_party_withdraw(party_id, account_id, char_id, name, type);

	if (p->party.member[i].leader){
		// TODO: Official allow 'leaderless' party
		p->party.member[i].account_id = 0;
		for (j = 0; j < MAX_PARTY; j++) {
			if (!p->party.member[j].account_id)
				continue;
			mapif_party_withdraw(party_id, p->party.member[j].account_id, p->party.member[j].char_id, p->party.member[j].name, type);
			p->party.member[j].account_id = 0;
		}
		//Party gets deleted on the check_empty call below.
	} else {
		inter_party_tosql(&p->party,PS_DELMEMBER,i);
		j = p->party.member[i].lv;
		if(p->party.member[i].online) p->party.count--;
		memset(&p->party.member[i], 0, sizeof(struct party_member));
		p->size--;
		if (j == p->min_lv || j == p->max_lv || p->family)
		{
			if(p->family) p->family = 0; //Family state broken.
			int_party_check_lv(p);
		}
	}

	if (party_check_empty(p) == 0)
		mapif_party_info(-1, &p->party, 0);
	return 0;
}
Esempio n. 14
0
// パーティ情報要求
int mapif_parse_PartyInfo(int fd,int party_id)
{
	struct party *p = party_pt;
	if(p==NULL){
		ShowFatalError("int_party: out of memory !\n");
		return 0;
	}
	inter_party_fromsql(party_id, p);

	if(p->party_id >= 0)
		mapif_party_info(fd,p);
	else
		mapif_party_noinfo(fd,party_id);
	return 0;
}
Esempio n. 15
0
// Search for the party according to its name
struct party_data *search_partyname(char *str) {
	char esc_name[NAME_LENGTH*2+1];
	char *data;
	struct party_data *p = NULL;

	Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH));
	if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", party_db, esc_name))
		Sql_ShowDebug(sql_handle);
	else if(SQL_SUCCESS == Sql_NextRow(sql_handle)) {
		Sql_GetData(sql_handle, 0, &data, NULL);
		p = inter_party_fromsql(atoi(data));
	}
	Sql_FreeResult(sql_handle);

	return p;
}
Esempio n. 16
0
// パーティ追加要求
int mapif_parse_PartyAddMember(int fd,int party_id,int account_id,char *nick,char *map,int lv)
{
	struct party *p;
	int i;

	p = party_pt;
	if(p==NULL){
		ShowFatalError("int_party: out of memory !\n");
		return 0;
	}
	inter_party_fromsql(party_id, p);

	if(p->party_id <= 0){
		mapif_party_memberadded(fd,party_id,account_id,1);
		return 0;
	}

	for(i=0;i<MAX_PARTY;i++){
		if(p->member[i].account_id==0){
			int flag=0;

			p->member[i].account_id=account_id;
			memcpy(p->member[i].name,nick,NAME_LENGTH-1);
			memcpy(p->member[i].map,map,MAP_NAME_LENGTH-1);
			p->member[i].leader=0;
			p->member[i].online=1;
			p->member[i].lv=lv;
			mapif_party_memberadded(fd,party_id,account_id,0);
			mapif_party_info(-1,p);

			if( p->exp>0 && !party_check_exp_share(p) ){
				p->exp=0;
				flag=0x01;
			}
			if(flag)
				mapif_party_optionchanged(fd,p,0,0);

			inter_party_tosql(party_id, p);
			return 0;
		}
	}
	mapif_party_memberadded(fd,party_id,account_id,1);
	//inter_party_tosql(party_id, p);
	return 0;
}
Esempio n. 17
0
// パーティ追加要求
int mapif_parse_PartyAddMember (int fd, int party_id, struct party_member *member)
{
	struct party_data *p;
	int i;
	p = inter_party_fromsql (party_id);

	if (p == NULL || p->size == MAX_PARTY)
	{
		mapif_party_memberadded (fd, party_id, member->account_id, member->char_id, 1);
		return 0;
	}

	ARR_FIND (0, MAX_PARTY, i, p->party.member[i].account_id == 0);

	if (i == MAX_PARTY)
	{
		// Party full
		mapif_party_memberadded (fd, party_id, member->account_id, member->char_id, 1);
		return 0;
	}

	memcpy (&p->party.member[i], member, sizeof (struct party_member));
	p->party.member[i].leader = 0;

	if (p->party.member[i].online) p->party.count++;

	p->size++;

	if (p->size == 3) //Check family state.
		int_party_calc_state (p);
	else //Check even share range.
		if (member->lv < p->min_lv || member->lv > p->max_lv || p->family)
		{
			if (p->family) p->family = 0; //Family state broken.

			int_party_check_lv (p);
		}

	mapif_party_info (-1, &p->party, 0);
	mapif_party_memberadded (fd, party_id, member->account_id, member->char_id, 0);
	inter_party_tosql (&p->party, PS_ADDMEMBER, i);
	return 0;
}
Esempio n. 18
0
// パーティー設定変更要求
int mapif_parse_PartyChangeOption(int fd,int party_id,int account_id,int exp,int item)
{
	struct party_data *p;
	int flag = 0;
	p = inter_party_fromsql(party_id);

	if(!p)
		return 0;

	p->party.exp=exp;
	if( exp && !party_check_exp_share(p) ){
		flag|=0x01;
		p->party.exp=0;
	}
	p->party.item = item&0x3; //Filter out invalid values.
	mapif_party_optionchanged(fd,&p->party,account_id,flag);
	inter_party_tosql(&p->party, PS_BASIC, 0);
	return 0;
}
Esempio n. 19
0
//Checks whether the even-share setting of a party is broken when a character logs in. [Skotlex]
int inter_party_logged(int party_id, int account_id)
{
	struct party *p = party_pt;
	if(p==NULL){
		ShowFatalError("int_party: out of memory !\n");
		return 0;
	}
	if (!party_id)
		return 0;
		
	inter_party_fromsql(party_id, p);

	if(p->party_id && p->exp == 1 && !party_check_exp_share(p))
	{
		p->exp=0;
		mapif_party_optionchanged(0,p,0,0);
		return 1;
	}
	return 0;
}
Esempio n. 20
0
// パーティ解散要求
int mapif_parse_BreakParty(int fd,int party_id)
{
	struct party *p;

	p = party_pt;
	if(p==NULL){
		ShowFatalError("int_party: out of memory !\n");
		return 0;
	}

	inter_party_fromsql(party_id, p);

	if(p->party_id <= 0){
		return 0;
	}
	inter_party_tosql(party_id,p);

	mapif_party_broken(fd,party_id);
	return 0;
}
Esempio n. 21
0
//---------------------------
// Adding a member in a party
//---------------------------
void mapif_parse_PartyAddMember(int fd, int party_id, int account_id, char *nick, char *map, int lv) {
	int i;

	inter_party_fromsql(party_id); // fill party_tmp with informations of the party (or set all values to 0)

	if (party_tmp.party_id <= 0) { // party doesn't exist
		mapif_party_memberadded(fd, party_id, account_id, 1);
		return;
	}

	for(i = 0; i < MAX_PARTY; i++) {
		if (party_tmp.member[i].account_id == 0) { // must we check if an other character of same account is in the party?
			party_tmp.member[i].account_id = account_id;
			memset(party_tmp.member[i].name, 0, sizeof(party_tmp.member[i].name));
			strncpy(party_tmp.member[i].name, nick, 24);
			memset(party_tmp.member[i].map, 0, sizeof(party_tmp.member[i].map));
			strncpy(party_tmp.member[i].map, map, 16); // 17 - NULL
			party_tmp.member[i].leader = 0;
			party_tmp.member[i].online = 1;
			party_tmp.member[i].lv = lv;
			mapif_party_memberadded(fd, party_id, account_id, 0);
			mapif_party_info(-1, &party_tmp);
			// Update character in memory
			for(i = 0; i < char_num; i++)
				if (char_dat[i].account_id == account_id && memcmp(char_dat[i].name, nick, 24) == 0) {
					char_dat[i].party_id = party_tmp.party_id;
					break;
				}

			if (party_tmp.exp > 0 && !party_check_exp_share(&party_tmp)) {
				party_tmp.exp = 0;
				mapif_party_optionchanged(fd, &party_tmp, 0, 0);
			}
			inter_party_tosql(party_id, &party_tmp);
			return;
		}
	}
	mapif_party_memberadded(fd, party_id, account_id, 1);

	return;
}
Esempio n. 22
0
int mapif_parse_PartyLeaderChange(int fd,int party_id,int account_id,int char_id)
{
	struct party_data *p;
	int i;

	p = inter_party_fromsql(party_id);

	if(!p)
		return 0;

	for(i = 0; i < MAX_PARTY; i++) {
		if(p->party.member[i].leader)
			p->party.member[i].leader = 0;
		if(p->party.member[i].account_id == account_id &&
		   p->party.member[i].char_id == char_id) {
			p->party.member[i].leader = 1;
			inter_party_tosql(&p->party,PS_LEADER, i);
		}
	}
	return 1;
}
Esempio n. 23
0
//--------------------------------------
// Request to change a option in a party
//--------------------------------------
void mapif_parse_PartyChangeOption(int fd, int party_id, int account_id, unsigned short exp, unsigned char item) {
	int flag;

	inter_party_fromsql(party_id); // fill party_tmp with informations of the party (or set all values to 0)

	if (party_tmp.party_id <= 0) // party doesn't exist
		return;

	flag = 0;
	party_tmp.exp = exp;
	if (exp > 0 && !party_check_exp_share(&party_tmp)) {
		flag = 1;
		party_tmp.exp = 0;
	}

	party_tmp.item = item;

	mapif_party_optionchanged(fd, &party_tmp, account_id, flag);
	inter_party_tosql(party_id, &party_tmp);

	return;
}
Esempio n. 24
0
// When member goes to other map
int mapif_parse_PartyChangeMap(int fd,int party_id,int account_id,char *map,int online,int lv)
{
	struct party *p;
	int i;
	
	p = party_pt;
	if(p==NULL){
		printf("int_party: out of memory !\n");
		return 0;
	}
	inter_party_fromsql(party_id, p);
	
	if(p->party_id <= 0){
		return 0;
	}
	for(i=0;i<MAX_PARTY;i++){
		if(p->member[i].account_id==account_id){
			int flag=0;
			
			memcpy(p->member[i].map,map,16);
			p->member[i].online=online;
			p->member[i].lv=lv;
			mapif_party_membermoved(p,i);

			if( p->exp>0 && !party_check_exp_share(p) ){
				p->exp=0;
				flag=1;
			}
			if(flag)
				mapif_party_optionchanged(fd,p,0,0);
			break;
		}
	}
	inter_party_tosql(party_id, p);
	return 0;
}
Esempio n. 25
0
// パーティ脱退要求
int mapif_parse_PartyLeave(int fd,int party_id,int account_id)
{
	struct party *p = party_pt;
	if(p==NULL){
		printf("int_party: out of memory !\n");
		return 0;
	}
	
	inter_party_fromsql(party_id, p);
	
	if(p->party_id >= 0){
		int i,j;
		for(i=0;i<MAX_PARTY;i++){
			
			if(p->member[i].account_id==account_id){
				//printf("p->member[i].account_id = %d , account_id = %d \n",p->member[i].account_id,account_id);
				mapif_party_leaved(party_id,account_id,p->member[i].name);
				
				
				char t_memname[256];
				jstrescapecpy(t_memname, p->member[i].name);
				// Update char information, does the name need encoding?
				sprintf(tmp_sql,"UPDATE `char` SET `party_id`='0', `online`='1' WHERE `party_id`='%d' AND BINARY `name`='%s';", 
					party_id, t_memname);	
				if(mysql_query(&mysql_handle, tmp_sql) ) {
					printf("DB server Error (update `char`)- %s\n", mysql_error(&mysql_handle) );
				}
				printf("Delete member %s from MySQL \n", p->member[i].name);	
						
				if (p->member[i].leader==1){
					for(j=0;j<MAX_PARTY;j++)
					{
						//printf("j = %d , p->member[j].account_id = %d , p->member[j].account_id = %d \n",j,p->member[j].account_id,p->member[j].account_id);
						if(p->member[j].account_id>0&&j!=i){
							mapif_party_leaved(party_id,p->member[j].account_id,p->member[j].name);
							// Update char information, does the name need encoding?
							char t_memname[256];
							jstrescapecpy(t_memname,p->member[j].name);
							sprintf(tmp_sql,"UPDATE `char` SET `party_id`='0', `online`='1' WHERE `party_id`='%d' AND BINARY `name`='%s';", 
								party_id, t_memname);	
							if(mysql_query(&mysql_handle, tmp_sql) ) {
								printf("DB server Error (update `char`)- %s\n", mysql_error(&mysql_handle) );
							}
							printf("Delete member %s from MySQL \n", p->member[j].name);	
						}
					}
					// Delete the party, if has no member.
					sprintf(tmp_sql,"DELETE FROM `party` WHERE `party_id`='%d'",party_id);
					if(mysql_query(&mysql_handle, tmp_sql) ) {
						printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
					}
					printf("Leader breaks party %d \n",party_id);
					memset(p, 0, sizeof(struct party));					
				}else memset(&p->member[i],0,sizeof(struct party_member));
				
				break;

			}
		}
		if( party_check_empty(p)==0 )
			mapif_party_info(-1,p);// まだ人がいるのでデータ送信
		/*
		else
			inter_party_tosql(party_id,p);	// Break the party if no member
		*/
	}
	return 0;
}
Esempio n. 26
0
// パーティ脱退要求
int mapif_parse_PartyLeave(int fd,int party_id,int account_id)
{
	char t_member[2*NAME_LENGTH];
	struct party *p = party_pt;
	if (p == NULL) {
		ShowFatalError("int_party: out of memory !\n");
		return 0;
	}

	inter_party_fromsql(party_id, p);
	if (p->party_id >= 0) {
		int i;
		for (i = 0; i < MAX_PARTY; i++) {
			if (p->member[i].account_id == account_id) {
				mapif_party_leaved(party_id, account_id, p->member[i].name);

				// Update char information, does the name need encoding?
				sprintf (tmp_sql, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `name`='%s'",
					char_db, party_id, jstrescapecpy(t_member,p->member[i].name));
				if (mysql_query (&mysql_handle, tmp_sql)) {
					ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
					ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
				}

				if (p->member[i].leader == 1){
					int j;
					for (j = 0; j < MAX_PARTY; j++) {
						if (p->member[j].account_id > 0 && j != i) {
							mapif_party_leaved(party_id, p->member[j].account_id, p->member[j].name);
						}
					}
					// we'll skip name-checking and just reset everyone with the same party id [celest]
					// -- if anything goes wrong just uncomment the section above ^^;
					sprintf (tmp_sql, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id);
					if (mysql_query(&mysql_handle, tmp_sql)) {
						ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
						ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
					}
					// Delete the party, if has no member.
					sprintf(tmp_sql, "DELETE FROM `%s` WHERE `party_id`='%d'", party_db, party_id);
					if (mysql_query(&mysql_handle, tmp_sql)) {
						ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
						ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
					}
					memset(p, 0, sizeof(struct party));
				} else
					memset(&p->member[i], 0, sizeof(struct party_member));
				break;
			}
		}

		if (party_check_empty(p) == 0)
			mapif_party_info(-1,p);// まだ人がいるのでデータ送信
		//else
		//	inter_party_tosql(party_id,p);	// Break the party if no member
	} else {
		sprintf(tmp_sql, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `online`='1'",
			char_db, party_id, account_id);
		if (mysql_query(&mysql_handle, tmp_sql)) {
			ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
			ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
		}
	}
	return 0;
}
Esempio n. 27
0
//------------------------
// A member leaves a party
//------------------------
int mapif_parse_PartyLeave(int fd, int party_id, int account_id) {
	char t_member[49]; // 24 * 2 + NULL
	int i, j;
	int flag;

	inter_party_fromsql(party_id); // fill party_tmp with informations of the party (or set all values to 0)

	if (party_tmp.party_id > 0) {
		for(i = 0; i < MAX_PARTY; i++) {
			if (party_tmp.member[i].account_id == account_id) {
				//printf("member leave the party #%d: account_id = %d.\n", party_id, account_id);
				mapif_party_leaved(party_id, account_id, party_tmp.member[i].name);

				// Update character information
				db_sql_escape_string(t_member, party_tmp.member[i].name, strlen(party_tmp.member[i].name));
				sql_request("UPDATE `%s` SET `party_id`='0' WHERE `account_id`='%d' AND `name`='%s'", char_db, account_id, t_member);
				// Update character in memory
				for(j = 0; j < char_num; j++)
					if (char_dat[j].account_id == account_id && strncmp(char_dat[j].name, party_tmp.member[i].name, 24) == 0) {
						char_dat[j].party_id = 0;
						break;
					}
				//printf("Delete member %s from party #%d.\n", p->member[i].name, party_id);

				// if it's leader, remove all other members
				if (party_tmp.member[i].leader == 1) {
					flag = 0;
					for(j = 0; j < MAX_PARTY; j++) {
						if (party_tmp.member[j].account_id > 0 && j != i) {
							mapif_party_leaved(party_id, party_tmp.member[j].account_id, party_tmp.member[j].name);
							flag++;
							//printf("Delete member %s from party #%d (Leader breaks party).\n", party_tmp->member[j].name, party_id);
						}
					}
					if (flag > 0) {
						// Update char information in database
						sql_request("UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id);
					}
					// Update characters in memory
					for(j = 0; j < char_num; j++)
						if (char_dat[j].party_id == party_id)
							char_dat[j].party_id = 0;
					// Delete the party.
					sql_request("DELETE FROM `%s` WHERE `party_id`='%d'", party_db, party_id);
					//printf("Leader breaks party #%d.\n", party_id);
					memset(&party_tmp, 0, sizeof(struct party));
					// remove party from memory
					for(j = 0; j < party_num; j++)
						if (partys[j].party_id == party_id) { // if found
							if (j != (party_num - 1))
								memcpy(&partys[j], &partys[party_num - 1], sizeof(struct party));
							party_num--;
							break;
						}
				} else {
					memset(&party_tmp.member[i], 0, sizeof(struct party_member));
					// Update party in memory (party_tmp is not pointer on &partys[j])
					for(j = 0; j < party_num; j++) {
						if (partys[j].party_id == party_id) { // if found
							memcpy(&partys[j], &party_tmp, sizeof(struct party));
							break;
						}
					}
 				}
				// leader is always the last member, but with deletion of char, that can be different
				if (party_check_empty(&party_tmp) == 0)
					mapif_party_info(-1, &party_tmp); // Sending party information to map-server // �܂��l������̂Ńf�[�^���M
				break;
			}
		}

	// party not found, suppress characters with this party
	} else {
		sql_request("UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id);
		// Update character in memory
		for(i = 0; i < char_num; i++)
			if (char_dat[i].party_id == party_id)
				char_dat[i].party_id = 0;
	}

	return 0;
}