/*========================================== * 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; }
/*========================================== * チャットルームから抜ける *------------------------------------------ */ int chat_leavechat(struct map_session_data *sd, unsigned char flag) { struct chat_data *cd; int i,leavechar; nullpo_retr(1, sd); if((cd = map_id2cd(sd->chatID)) == NULL) return 1; leavechar = -1; for(i = 0; i < cd->users; i++) { if(cd->usersd[i] == sd) { leavechar = i; break; } } if(leavechar < 0) // そのchatに所属していないらしい (バグ時のみ) return -1; if(leavechar == 0 && cd->users > 1 && (*cd->owner)->type == BL_PC) { // 所有者だった&他に人が居る&PCのチャット clif_changechatowner(cd,cd->usersd[1]); clif_clearchat(cd,-1); } // 抜けるPCにも送るのでusersを減らす前に実行 clif_leavechat(cd,sd,flag); cd->users--; sd->chatID = 0; sd->state.joinchat = 0; if(cd->users == 0 && (*cd->owner)->type == BL_PC) { // 全員居なくなった&PCのチャットなので消す clif_clearchat(cd,-1); linkdb_final(&cd->ban_list); map_delobject(cd->bl.id); // freeまでしてくれる } else { for(i = leavechar; i < cd->users; i++) { cd->usersd[i] = cd->usersd[i+1]; } if(leavechar == 0 && (*cd->owner)->type == BL_PC) { // PCのチャットで所有者が抜けたので位置変更 cd->bl.x = cd->usersd[0]->bl.x; cd->bl.y = cd->usersd[0]->bl.y; } clif_dispchat(cd,-1); } return 0; }
/*========================================== * チャットルームから抜ける *------------------------------------------ */ int chat_leavechat(struct map_session_data *sd) { struct chat_data *cd; int i,leavechar; nullpo_retr(1, sd); cd=(struct chat_data*)map_id2bl(sd->chatID); if(cd==NULL) return 1; for(i = 0,leavechar=-1;i < cd->users;i++){ if(cd->usersd[i] == sd){ leavechar=i; break; } } if(leavechar<0) // そのchatに所属していないらしい (バグ時のみ) return -1; if(leavechar==0 && cd->users>1 && (*cd->owner)->type==BL_PC){ // 所有者だった&他に人が居る&PCのチャット clif_changechatowner(cd,cd->usersd[1]); clif_clearchat(cd,0); } // 抜けるPCにも送るのでusersを減らす前に実行 clif_leavechat(cd,sd); cd->users--; pc_setchatid(sd,0); if(cd->users == 0 && (*cd->owner)->type==BL_PC){ // 全員居なくなった&PCのチャットなので消す clif_clearchat(cd,0); map_delobject(cd->bl.id); // freeまでしてくれる } else { for(i=leavechar;i < cd->users;i++) cd->usersd[i] = cd->usersd[i+1]; if(leavechar==0 && (*cd->owner)->type==BL_PC){ // PCのチャットなので所有者が抜けたので位置変更 cd->bl.x=cd->usersd[0]->bl.x; cd->bl.y=cd->usersd[0]->bl.y; } clif_dispchat(cd,0); } return 0; }
/** * Change a chat room's owner. * @param sd : player requesting * @param nextownername : string of new owner (name should be in chatroom) * @return 0:success, 1:failure */ int chat_changechatowner(struct map_session_data* sd, const char* nextownername) { struct chat_data* cd; struct map_session_data* tmpsd; int i; nullpo_retr(1, sd); cd = (struct chat_data*)map_id2bl(sd->chatID); if( cd == NULL || (struct block_list*) sd != cd->owner ) return 1; ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 ); if( i == cd->users ) return -1; // name not found // erase temporarily clif_clearchat(cd,0); // set new owner cd->owner = (struct block_list*) cd->usersd[i]; clif_changechatowner(cd,cd->usersd[i]); // swap the old and new owners' positions tmpsd = cd->usersd[i]; cd->usersd[i] = cd->usersd[0]; cd->usersd[0] = tmpsd; // set the new chatroom position map_delblock( &cd->bl ); cd->bl.x = cd->owner->x; cd->bl.y = cd->owner->y; if(map_addblock( &cd->bl )) return 1; // and display again clif_dispchat(cd,0); return 0; }
/*========================================== * チャットルームの持ち主を譲る *------------------------------------------ */ void chat_changechatowner(struct map_session_data *sd, const char *nextownername) { struct chat_data *cd; struct map_session_data *tmp_sd; int i,nextowner; nullpo_retv(sd); cd = map_id2cd(sd->chatID); if(cd == NULL || &sd->bl != (*cd->owner)) return; nextowner = -1; for(i = 1; i < cd->users; i++) { if(strncmp(cd->usersd[i]->status.name, nextownername, 24) == 0) { nextowner = i; break; } } if(nextowner < 0) // そんな人は居ない return; clif_changechatowner(cd,cd->usersd[nextowner]); // 一旦消す clif_clearchat(cd,-1); // userlistの順番変更 (0が所有者なので) if( (tmp_sd = cd->usersd[0]) == NULL ) return; //ありえるのかな? cd->usersd[0] = cd->usersd[nextowner]; cd->usersd[nextowner] = tmp_sd; // 新しい所有者の位置へ変更 cd->bl.x = cd->usersd[0]->bl.x; cd->bl.y = cd->usersd[0]->bl.y; // 再度表示 clif_dispchat(cd,-1); return; }
/*========================================== * チャットルームの持ち主を譲る *------------------------------------------ */ int chat_changechatowner(struct map_session_data *sd,char *nextownername) { struct chat_data *cd; struct map_session_data *tmp_sd; int i, nextowner; nullpo_retr(1, sd); cd = (struct chat_data*)map_id2bl(sd->chatID); if (cd == NULL || (struct block_list *)sd != (*cd->owner)) return 1; for(i = 1,nextowner=-1;i < cd->users;i++){ if(strcmp(cd->usersd[i]->status.name,nextownername)==0){ nextowner=i; break; } } if(nextowner<0) // そんな人は居ない return -1; clif_changechatowner(cd,cd->usersd[nextowner]); // 一旦消す clif_clearchat(cd,0); // userlistの順番変更 (0が所有者なので) if( (tmp_sd = cd->usersd[0]) == NULL ) return 1; //ありえるのかな? cd->usersd[0] = cd->usersd[nextowner]; cd->usersd[nextowner] = tmp_sd; // 新しい所有者の位置へ変更 cd->bl.x=cd->usersd[0]->bl.x; cd->bl.y=cd->usersd[0]->bl.y; // 再度表示 clif_dispchat(cd,0); return 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; }