From 2e081818e2564a7e5bc677a5cb421bb4f5295771 Mon Sep 17 00:00:00 2001 From: hecht Date: Tue, 29 Nov 2011 22:13:40 +0000 Subject: [PATCH] Fixed #56 - it is not now possible anymore to challange a clan if there is a open challenge available! --- ag/include/clan_fights.inc.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php index f578ed5..cc63ec1 100644 --- a/ag/include/clan_fights.inc.php +++ b/ag/include/clan_fights.inc.php @@ -65,8 +65,6 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH return 'Einer der Clans erfüllt die Anforderungen an Clanfights nichtmehr (wahrscheinlich zu wenig Members)!'; } - - if(!semaphoreUP($ressource_clan1)) { return 'Fehler beim Verarbeiten der Anfrage für \'' . $clan['clanname'] . '\' versuche es bitte nochmal! '; } @@ -78,7 +76,9 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH // okay we have both semaphores :) - $clan_challenges_my_clan = getOpenChallengeRequestCount($user['clan']) + count(getOpenChallengeIDs($user['clan'])); + $myOpenChallengeIDs = getOpenChallengeIDs($user['clan']); + + $clan_challenges_my_clan = getOpenChallengeRequestCount($user['clan']) + count($myOpenChallengeIDs); $clan_challenges_oth_clan = getOpenChallengeRequestCount($clanid) + count(getOpenChallengeIDs($clanid)); if($clan_challenges_my_clan >= MAX_OPEN_REQUESTS) { @@ -93,6 +93,17 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH return 'Der Clan "'.$oclan['clanname'].'" hat schon die maximale Anzahl von Herausforderungen offen!'; } + // check if we have a open challenge with this clan ... + foreach ($myOpenChallengeIDs as $clan_challenge_id) { + $challenge_clans = getParticipatingClanIDs($clan_challenge_id); + if(in_array($user['clan'],$challenge_clans) && in_array($clanid,$challenge_clans)) { + semaphoreDown($ressource_clan1); // free the previously reserved semaphore! + semaphoreDown($ressource_clan2); // free the previously reserved semaphore! + return 'Der Clan kann derzeit nicht herausgefordert werden, da noch ein offener Clan-Fight mit diesem Clan besteht!'; + } + } + + // check if both clans have already been challengeing each other since 24h? $sql = 'SELECT count(*) as anzahl FROM clan_challenge_requests WHERE clan_requester IN ('.$user['clan'].', '.$clanid.') AND clan_challenged IN ('.$user['clan'].', '.$clanid.') AND challenged_time > TIMESTAMPADD(day, -1, now())'; $qry = mysql_query($sql);