From e64668eb149bf37fe630df4433c102c8d5fb504b Mon Sep 17 00:00:00 2001 From: Lorenzo Buitizon Date: Mon, 20 Apr 2026 21:43:46 +0800 Subject: [PATCH 1/6] battleground: fix requeue delay never enforcing due to storing time(NULL) instead of time(NULL)+requeue_delay as the expiry timestamp --- conf/battlegrounds.conf | 5 +++++ src/map/battleground.c | 11 ++++++++++- src/map/battleground.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/conf/battlegrounds.conf b/conf/battlegrounds.conf index fd079c59dfe..2ed0b7e4434 100644 --- a/conf/battlegrounds.conf +++ b/conf/battlegrounds.conf @@ -44,6 +44,7 @@ battlegrounds: ( maxPlayers: 60 /* maximum amount of players */ minTeamPlayers: 6 /* minimum amount of team members required for a team (party or guild) to join */ delay_var: "Tierra_BG_Tick" /* char variable name that will store the delay for this match */ + requeue_delay: 300 /* seconds a player must wait before re-queuing after a match */ maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */ fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */ pGameDuration: 20 /* time to wait for players to confirm their attendance after queueing process has finished */ @@ -62,6 +63,7 @@ battlegrounds: ( maxPlayers: 60 /* maximum amount of players */ minTeamPlayers: 6 /* minimum amount of team members required for a team (party or guild) to join */ delay_var: "Flavius_BG_Tick" /* char variable name that will store the delay for this match */ + requeue_delay: 300 /* seconds a player must wait before re-queuing after a match */ maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */ fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */ pGameDuration: 20 /* time to wait for players to confirm their attendance after queueing process has finished */ @@ -80,6 +82,7 @@ battlegrounds: ( maxPlayers: 60 /* maximum amount of players */ minTeamPlayers: 5 /* minimum amount of team members required for a team (party or guild) to join */ delay_var: "KVM_BG_Tick" /* char variable name that will store the delay for this match */ + requeue_delay: 300 /* seconds a player must wait before re-queuing after a match */ maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */ fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */ pGameDuration: 20 /* time to wait for players to confirm their attendance after queueing process has finished */ @@ -98,6 +101,7 @@ battlegrounds: ( maxPlayers: 60 /* maximum amount of players */ minTeamPlayers: 5 /* minimum amount of team members required for a team (party or guild) to join */ delay_var: "KVM_BG_Tick" /* char variable name that will store the delay for this match */ + requeue_delay: 300 /* seconds a player must wait before re-queuing after a match */ maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */ fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */ pGameDuration: 20 /* time to wait for players to confirm their attendance after queueing process has finished */ @@ -116,6 +120,7 @@ battlegrounds: ( maxPlayers: 60 /* maximum amount of players */ minTeamPlayers: 5 /* minimum amount of team members required for a team (party or guild) to join */ delay_var: "KVM_BG_Tick" /* char variable name that will store the delay for this match */ + requeue_delay: 300 /* seconds a player must wait before re-queuing after a match */ maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */ fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */ pGameDuration: 20 /* time to wait for players to confirm their attendance after queueing process has finished */ diff --git a/src/map/battleground.c b/src/map/battleground.c index a7ace3d0cc2..8dc49156629 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -391,6 +391,7 @@ static void bg_config_read(void) int prizeWin, prizeLoss, prizeDraw; int minPlayers, maxPlayers, minTeamPlayers; int maxDuration; + int requeue_delay = 300; int fillup_duration = 0, pregame_duration = 0; enum bg_queue_types allowedTypes; @@ -474,6 +475,13 @@ static void bg_config_read(void) maxDuration = 30; } + libconfig->setting_lookup_int(arena, "requeue_delay", &requeue_delay); + + if( requeue_delay < 0 ) { + ShowWarning("bg_config_read: invalid %d value for arena '%s' requeue_delay, defaulting to 300.\n",requeue_delay,aName); + requeue_delay = 300; + } + libconfig->setting_lookup_int(arena, "fillDuration", &fillup_duration); libconfig->setting_lookup_int(arena, "pGameDuration", &pregame_duration); @@ -503,6 +511,7 @@ static void bg_config_read(void) bg->arena[i]->max_players = maxPlayers; bg->arena[i]->min_team_players = minTeamPlayers; safestrncpy(bg->arena[i]->delay_var, aDelayVar, NAME_LENGTH); + bg->arena[i]->requeue_delay = requeue_delay; bg->arena[i]->maxDuration = maxDuration; bg->arena[i]->queue_id = script->queue_create(); bg->arena[i]->begin_timer = INVALID_TIMER; @@ -623,7 +632,7 @@ static void bg_match_over(struct bg_arena *arena, bool canceled) if (canceled) clif->messagecolor_self(sd->fd, COLOR_RED, msg_sd(sd, MSGTBL_BG_MATCH_CANCELED_NO_PLAYERS)); // "BG Match Canceled: not enough players." else - pc_setglobalreg(sd, script->add_variable(arena->delay_var), (unsigned int)time(NULL)); + pc_setglobalreg(sd, script->add_variable(arena->delay_var), (unsigned int)time(NULL) + arena->requeue_delay); } arena->begin_timer = INVALID_TIMER; diff --git a/src/map/battleground.h b/src/map/battleground.h index 26f9895053f..fd228c58df7 100644 --- a/src/map/battleground.h +++ b/src/map/battleground.h @@ -82,6 +82,7 @@ struct bg_arena { short max_players; short min_team_players; char delay_var[NAME_LENGTH]; + int requeue_delay; unsigned short maxDuration; int queue_id; int begin_timer; From 8b480de8d34b33d453ecca83e94cd84a7908d0e9 Mon Sep 17 00:00:00 2001 From: Lorenzo Buitizon Date: Mon, 20 Apr 2026 21:49:32 +0800 Subject: [PATCH 2/6] battleground: allow queueing for next match while current match is ongoing by snapshotting the active queue into match_queue_id and creating a fresh queue immediately on match start --- src/map/battleground.c | 20 +++++++++++++------- src/map/battleground.h | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/map/battleground.c b/src/map/battleground.c index 8dc49156629..d2a1aaf6d5c 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -514,6 +514,7 @@ static void bg_config_read(void) bg->arena[i]->requeue_delay = requeue_delay; bg->arena[i]->maxDuration = maxDuration; bg->arena[i]->queue_id = script->queue_create(); + bg->arena[i]->match_queue_id = 0; bg->arena[i]->begin_timer = INVALID_TIMER; bg->arena[i]->fillup_timer = INVALID_TIMER; bg->arena[i]->pregame_duration = pregame_duration; @@ -611,7 +612,8 @@ static void bg_queue_player_cleanup(struct map_session_data *sd) static void bg_match_over(struct bg_arena *arena, bool canceled) { - struct script_queue *queue = script->queue(arena->queue_id); + int active_queue_id = arena->match_queue_id ? arena->match_queue_id : arena->queue_id; + struct script_queue *queue = script->queue(active_queue_id); int i; nullpo_retv(arena); @@ -635,10 +637,12 @@ static void bg_match_over(struct bg_arena *arena, bool canceled) pc_setglobalreg(sd, script->add_variable(arena->delay_var), (unsigned int)time(NULL) + arena->requeue_delay); } - arena->begin_timer = INVALID_TIMER; - arena->fillup_timer = INVALID_TIMER; - /* reset queue */ - script->queue_clear(arena->queue_id); + if( arena->match_queue_id == 0 ) { + arena->begin_timer = INVALID_TIMER; + arena->fillup_timer = INVALID_TIMER; + } + script->queue_clear(active_queue_id); + arena->match_queue_id = 0; } static void bg_begin(struct bg_arena *arena) @@ -665,13 +669,15 @@ static void bg_begin(struct bg_arena *arena) if( count < arena->min_players ) { bg->match_over(arena,true); } else { + arena->match_queue_id = arena->queue_id; + arena->queue_id = script->queue_create(); arena->ongoing = true; if( bg->afk_timer_id == INVALID_TIMER && bg->mafksec > 0 ) bg->afk_timer_id = timer->add(timer->gettick()+10000,bg->afk_timer,0,0); /* TODO: make this a arena-independent var? or just .@? */ - mapreg->setreg(script->add_variable("$@bg_queue_id"),arena->queue_id); + mapreg->setreg(script->add_variable("$@bg_queue_id"),arena->match_queue_id); mapreg->setregstr(script->add_variable("$@bg_delay_var$"),bg->gdelay_var); count = 0; @@ -781,7 +787,7 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en nullpo_retv(sd); nullpo_retv(arena); - if( arena->begin_timer != INVALID_TIMER || arena->ongoing ) { + if( arena->begin_timer != INVALID_TIMER ) { clif->bgqueue_ack(sd,BGQA_FAIL_QUEUING_FINISHED,arena->id); return; } diff --git a/src/map/battleground.h b/src/map/battleground.h index fd228c58df7..8b67d325bf1 100644 --- a/src/map/battleground.h +++ b/src/map/battleground.h @@ -85,6 +85,7 @@ struct bg_arena { int requeue_delay; unsigned short maxDuration; int queue_id; + int match_queue_id; int begin_timer; int fillup_timer; int game_timer; From e1b7aa43b989d08151915dfef162ae8c73ff2065 Mon Sep 17 00:00:00 2001 From: Lorenzo Buitizon Date: Mon, 20 Apr 2026 21:51:09 +0800 Subject: [PATCH 3/6] battleground: fix maximum_afk_seconds having no effect due to comparing millisecond idle ticks against a seconds value --- src/map/battleground.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/battleground.c b/src/map/battleground.c index d2a1aaf6d5c..dd1c041711b 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -723,7 +723,7 @@ static int bg_afk_timer(int tid, int64 tick, int id, intptr_t data) for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( !sd->bg_queue.arena || !sd->bg_id ) continue; - if( DIFF_TICK(sockt->last_tick, sd->idletime) > bg->mafksec ) + if( DIFF_TICK(sockt->last_tick, sd->idletime) > (bg->mafksec * 1000) ) bg->team_leave(sd,BGTL_AFK); count++; } From e701cec11ca8ca9876894477d4f6f409846b517a Mon Sep 17 00:00:00 2001 From: Lorenzo Buitizon Date: Mon, 20 Apr 2026 21:53:31 +0800 Subject: [PATCH 4/6] battleground: enforce level and class requirements on all party/guild members when queuing, not just the leader --- src/map/battleground.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/map/battleground.c b/src/map/battleground.c index dd1c041711b..ea0d7fc44a5 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -802,6 +802,7 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en struct party_data *p = party->search(sd->status.party_id); for( i = 0; i < MAX_PARTY; i++ ) { if( !p->data[i].sd || p->data[i].sd->bg_queue.arena != NULL ) continue; + if( !bg_member_meets_requirements(p->data[i].sd, arena) ) continue; count++; } } @@ -810,6 +811,8 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en for ( i=0; iguild->max_member; i++ ) { if ( !sd->guild->member[i].sd || sd->guild->member[i].sd->bg_queue.arena != NULL ) continue; + if ( !bg_member_meets_requirements(sd->guild->member[i].sd, arena) ) + continue; count++; } break; @@ -838,6 +841,7 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en struct party_data *p = party->search(sd->status.party_id); for( i = 0; i < MAX_PARTY; i++ ) { if( !p->data[i].sd || p->data[i].sd->bg_queue.arena != NULL ) continue; + if( !bg_member_meets_requirements(p->data[i].sd, arena) ) continue; p->data[i].sd->bg_queue.type = type; p->data[i].sd->bg_queue.arena = arena; p->data[i].sd->bg_queue.ready = 0; @@ -851,6 +855,8 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en for ( i=0; iguild->max_member; i++ ) { if ( !sd->guild->member[i].sd || sd->guild->member[i].sd->bg_queue.arena != NULL ) continue; + if ( !bg_member_meets_requirements(sd->guild->member[i].sd, arena) ) + continue; sd->guild->member[i].sd->bg_queue.type = type; sd->guild->member[i].sd->bg_queue.arena = arena; sd->guild->member[i].sd->bg_queue.ready = 0; @@ -866,6 +872,15 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en bg->queue_check(arena); } +static bool bg_member_meets_requirements(struct map_session_data *msd, struct bg_arena *arena) +{ + if (msd->status.base_level < arena->min_level || msd->status.base_level > arena->max_level) + return false; + if ((msd->job & JOBL_2) == 0) + return false; + return true; +} + static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type) { int tick; @@ -914,7 +929,10 @@ static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, str else { int i, count = 0; for ( i=0; iguild->max_member; i++ ) { - if ( !sd->guild->member[i].sd || sd->guild->member[i].sd->bg_queue.arena != NULL ) + struct map_session_data *msd = sd->guild->member[i].sd; + if ( !msd || msd->bg_queue.arena != NULL ) + continue; + if ( !bg_member_meets_requirements(msd, arena) ) continue; count++; } @@ -939,11 +957,12 @@ static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, str bool is_leader = false; for(i = 0; i < MAX_PARTY; i++) { - if( !p->data[i].sd ) + struct map_session_data *msd = p->data[i].sd; + if( !msd ) continue; - if( p->party.member[i].leader && sd == p->data[i].sd ) + if( p->party.member[i].leader && sd == msd ) is_leader = true; - if( p->data[i].sd->bg_queue.arena == NULL ) + if( msd->bg_queue.arena == NULL && bg_member_meets_requirements(msd, arena) ) count++; } From 1523c935cab49ef0ed606eb8bb5c8b22fd7011ad Mon Sep 17 00:00:00 2001 From: Lorenzo Buitizon Date: Mon, 20 Apr 2026 21:58:52 +0800 Subject: [PATCH 5/6] battleground: fix players in queue-based BG not being removed from their team on disconnect due to incorrect bg_queue.arena guard --- src/map/map.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/map/map.c b/src/map/map.c index e92926a5454..eee58dd1fa0 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2048,8 +2048,10 @@ static int map_quit(struct map_session_data *sd) if (sd->npc_id) npc->event_dequeue(sd); - if( sd->bg_id && !sd->bg_queue.arena ) /* TODO: dump this chunk after bg_queue is fully enabled */ + if( sd->bg_id ) bg->team_leave(sd,BGTL_QUIT); + else if( sd->bg_queue.arena ) + bg->queue_pc_cleanup(sd); if (sd->status.clan_id) clan->member_offline(sd); From b797d87c8fedf3c9b3bfa86f1bd62f02f4f29d64 Mon Sep 17 00:00:00 2001 From: Lorenzo Buitizon Date: Mon, 20 Apr 2026 22:02:00 +0800 Subject: [PATCH 6/6] battleground: fix bg_member_meets_requirements defined after its callers and queue_pc_cleanup removing from wrong queue during a match --- src/map/battleground.c | 71 ++++++++++++++++++++++++------------------ src/map/map.c | 4 +-- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/map/battleground.c b/src/map/battleground.c index ea0d7fc44a5..5beace6953a 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -477,7 +477,7 @@ static void bg_config_read(void) libconfig->setting_lookup_int(arena, "requeue_delay", &requeue_delay); - if( requeue_delay < 0 ) { + if (requeue_delay < 0) { ShowWarning("bg_config_read: invalid %d value for arena '%s' requeue_delay, defaulting to 300.\n",requeue_delay,aName); requeue_delay = 300; } @@ -602,8 +602,14 @@ static void bg_queue_player_cleanup(struct map_session_data *sd) else clif->bgqueue_notice_delete(sd,BGQND_FAIL_NOT_QUEUING,bg->arena[0]->name); } - if( sd->bg_queue.arena ) - script->queue_remove(sd->bg_queue.arena->queue_id,sd->status.account_id); + if (sd->bg_queue.arena) { + int qid; + if (sd->bg_queue.arena->match_queue_id) + qid = sd->bg_queue.arena->match_queue_id; + else + qid = sd->bg_queue.arena->queue_id; + script->queue_remove(qid, sd->status.account_id); + } sd->bg_queue.arena = NULL; sd->bg_queue.ready = 0; sd->bg_queue.client_has_bg_data = 0; @@ -637,7 +643,7 @@ static void bg_match_over(struct bg_arena *arena, bool canceled) pc_setglobalreg(sd, script->add_variable(arena->delay_var), (unsigned int)time(NULL) + arena->requeue_delay); } - if( arena->match_queue_id == 0 ) { + if (arena->match_queue_id == 0) { arena->begin_timer = INVALID_TIMER; arena->fillup_timer = INVALID_TIMER; } @@ -723,7 +729,7 @@ static int bg_afk_timer(int tid, int64 tick, int id, intptr_t data) for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( !sd->bg_queue.arena || !sd->bg_id ) continue; - if( DIFF_TICK(sockt->last_tick, sd->idletime) > (bg->mafksec * 1000) ) + if (DIFF_TICK(sockt->last_tick, sd->idletime) > (bg->mafksec * 1000)) bg->team_leave(sd,BGTL_AFK); count++; } @@ -779,6 +785,15 @@ static void bg_queue_check(struct bg_arena *arena) } } +static bool bg_member_meets_requirements(struct map_session_data *sd, struct bg_arena *arena) +{ + if (sd->status.base_level < arena->min_level || sd->status.base_level > arena->max_level) + return false; + if ((sd->job & JOBL_2) == 0) + return false; + return true; +} + static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type) { enum BATTLEGROUNDS_QUEUE_ACK result = bg->can_queue(sd,arena,type); @@ -787,7 +802,7 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en nullpo_retv(sd); nullpo_retv(arena); - if( arena->begin_timer != INVALID_TIMER ) { + if (arena->begin_timer != INVALID_TIMER) { clif->bgqueue_ack(sd,BGQA_FAIL_QUEUING_FINISHED,arena->id); return; } @@ -801,8 +816,10 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en case BGQT_PARTY: { struct party_data *p = party->search(sd->status.party_id); for( i = 0; i < MAX_PARTY; i++ ) { - if( !p->data[i].sd || p->data[i].sd->bg_queue.arena != NULL ) continue; - if( !bg_member_meets_requirements(p->data[i].sd, arena) ) continue; + if (!p->data[i].sd || p->data[i].sd->bg_queue.arena != NULL) + continue; + if (!bg_member_meets_requirements(p->data[i].sd, arena)) + continue; count++; } } @@ -811,7 +828,7 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en for ( i=0; iguild->max_member; i++ ) { if ( !sd->guild->member[i].sd || sd->guild->member[i].sd->bg_queue.arena != NULL ) continue; - if ( !bg_member_meets_requirements(sd->guild->member[i].sd, arena) ) + if (!bg_member_meets_requirements(sd->guild->member[i].sd, arena)) continue; count++; } @@ -840,8 +857,10 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en case BGQT_PARTY: { struct party_data *p = party->search(sd->status.party_id); for( i = 0; i < MAX_PARTY; i++ ) { - if( !p->data[i].sd || p->data[i].sd->bg_queue.arena != NULL ) continue; - if( !bg_member_meets_requirements(p->data[i].sd, arena) ) continue; + if (!p->data[i].sd || p->data[i].sd->bg_queue.arena != NULL) + continue; + if (!bg_member_meets_requirements(p->data[i].sd, arena)) + continue; p->data[i].sd->bg_queue.type = type; p->data[i].sd->bg_queue.arena = arena; p->data[i].sd->bg_queue.ready = 0; @@ -855,7 +874,7 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en for ( i=0; iguild->max_member; i++ ) { if ( !sd->guild->member[i].sd || sd->guild->member[i].sd->bg_queue.arena != NULL ) continue; - if ( !bg_member_meets_requirements(sd->guild->member[i].sd, arena) ) + if (!bg_member_meets_requirements(sd->guild->member[i].sd, arena)) continue; sd->guild->member[i].sd->bg_queue.type = type; sd->guild->member[i].sd->bg_queue.arena = arena; @@ -872,15 +891,6 @@ static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, en bg->queue_check(arena); } -static bool bg_member_meets_requirements(struct map_session_data *msd, struct bg_arena *arena) -{ - if (msd->status.base_level < arena->min_level || msd->status.base_level > arena->max_level) - return false; - if ((msd->job & JOBL_2) == 0) - return false; - return true; -} - static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type) { int tick; @@ -928,11 +938,12 @@ static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, str return BGQA_NOT_PARTY_GUILD_LEADER; else { int i, count = 0; - for ( i=0; iguild->max_member; i++ ) { - struct map_session_data *msd = sd->guild->member[i].sd; - if ( !msd || msd->bg_queue.arena != NULL ) + struct guild *guild = sd->guild; + for (i = 0; i < guild->max_member; i++) { + struct map_session_data *sd = guild->member[i].sd; + if (!sd || sd->bg_queue.arena != NULL) continue; - if ( !bg_member_meets_requirements(msd, arena) ) + if (!bg_member_meets_requirements(sd, arena)) continue; count++; } @@ -957,12 +968,12 @@ static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, str bool is_leader = false; for(i = 0; i < MAX_PARTY; i++) { - struct map_session_data *msd = p->data[i].sd; - if( !msd ) - continue; - if( p->party.member[i].leader && sd == msd ) + if (p->party.member[i].leader && p->data[i].sd == sd) is_leader = true; - if( msd->bg_queue.arena == NULL && bg_member_meets_requirements(msd, arena) ) + struct map_session_data *sd = p->data[i].sd; + if (!sd) + continue; + if (sd->bg_queue.arena == NULL && bg_member_meets_requirements(sd, arena)) count++; } diff --git a/src/map/map.c b/src/map/map.c index eee58dd1fa0..25a0f106355 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2048,9 +2048,9 @@ static int map_quit(struct map_session_data *sd) if (sd->npc_id) npc->event_dequeue(sd); - if( sd->bg_id ) + if (sd->bg_id) bg->team_leave(sd,BGTL_QUIT); - else if( sd->bg_queue.arena ) + else if (sd->bg_queue.arena) bg->queue_pc_cleanup(sd); if (sd->status.clan_id)