From 231e1436a7bc05a93c4a8ab6814543688b9043a4 Mon Sep 17 00:00:00 2001 From: hecht Date: Thu, 17 Nov 2011 21:56:48 +0000 Subject: [PATCH] did some fixes on clanfights ... also adjusted the test.php to automatically test the fights. also fixed a display bug (thx to ray) --- ag/include/clan_fights.inc.php | 22 +++++++++++--- ag/include/kampf_anzeige.inc.php | 4 +-- ag/test.php | 52 +++++++++++++++++++++++++++++--- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php index ce6beaa..6078484 100644 --- a/ag/include/clan_fights.inc.php +++ b/ag/include/clan_fights.inc.php @@ -52,7 +52,7 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH return 'Entweder bist du nicht in einem Clan oder der andere Clan existiert nicht mehr!!'; } - if(isAuthorizedClanfightCoordinator($user['id'])){ + if(!isAuthorizedClanfightCoordinator($user['clan'], $user['id'])){ return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können andere Clans herausfordern!!'; } @@ -160,7 +160,7 @@ function acceptChallengeRequest($challenged_clan, array $user) { return 'Du bist in keinem Clan!!'; } - if(isAuthorizedClanfightCoordinator($user['id'])){ + if(!isAuthorizedClanfightCoordinator($user['clan'], $user['id'])){ return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können Herausforderungen anderer Clans annehmen!!'; } @@ -242,7 +242,7 @@ function denyChallengeRequest($challenged_clan, array $user) { return 'Du bist in keinem Clan!!'; } - if(isAuthorizedClanfightCoordinator($user['id'])){ + if(!isAuthorizedClanfightCoordinator($user['clan'], $user['id'])){ return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können Herausforderungen anderer Clans ablehnen!!'; } @@ -735,13 +735,14 @@ function getClanFightCapableClanIds() { */ function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = NULL) { // do we require this information for a specific clan_fight??? - if($clan_fight_id === NULL) { + if($clan_fight_id !== NULL) { $sql = 'SELECT COUNT(*) FROM `clan_challenge_clans` WHERE `clan_coordinator` = ' .$user_id. ' AND `clan_id` = '.$clan_id . ' AND `clan_challenge_id` = ' .$clan_fight_id; + //echo $sql . '
'; $row = mysql_fetch_row(mysql_query($sql)); if($row[0] <= 0) { // okay, maybe its a leader ;) $clan = getClan($clan_id); - if($clan['leader'] == $user_id || $clan['co_leader'] = $user_id) { + if($clan['leader'] == $user_id || $clan['co_leader'] == $user_id) { // the leader or the co_leader is always authorized! return true; } @@ -755,6 +756,17 @@ function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = N // it is a more general thing ;) $sql = 'SELECT COUNT(*) FROM `clan_challenge_whitelist` WHERE `user_id` = ' .$user_id. ' AND `clan_id` = '.$clan_id; $row = mysql_fetch_row(mysql_query($sql)); + if($row[0] <= 0) { + // okay, maybe its a leader ;) + $clan = getClan($clan_id); + if($clan['leader'] == $user_id || $clan['co_leader'] == $user_id) { + // the leader or the co_leader is always authorized! + //echo 'true
'; + return true; + } + // not authorized! + return false; + } } return true; } diff --git a/ag/include/kampf_anzeige.inc.php b/ag/include/kampf_anzeige.inc.php index 4eab9a8..05047e1 100644 --- a/ag/include/kampf_anzeige.inc.php +++ b/ag/include/kampf_anzeige.inc.php @@ -286,7 +286,7 @@ function displaySchatzSuche($char){ // Lade nun die Fights runter - $sql = 'Select * from quest_fights where charid = '.$char['id']; + $sql = 'Select * from quest_fights where charid = '.$char['id'].' ORDER BY fightnr ASC'; $qry = mysql_query($sql); while($fight = mysql_fetch_assoc($qry)){ displaySchatzSucheFight($quest, $char, $fight); @@ -460,4 +460,4 @@ function displayEventFightRound(array $char1_data, array $char2_data, array $cha echo ''; } -?> \ No newline at end of file +?> diff --git a/ag/test.php b/ag/test.php index 924c52c..ee8ff27 100644 --- a/ag/test.php +++ b/ag/test.php @@ -14,12 +14,54 @@ include_once(ROOT_PATH.'/include/clan_fights.inc.php'); $acceptTestCase = true; +mysql_query('UPDATE user SET clan = null'); // clean all clans + +$ids = getClanFightCapableClanIds(); +$row = mysql_fetch_row(mysql_query('SELECT COUNT(*) FROM user WHERE 0 < (SELECT COUNT(*) FROM chars WHERE besitzer = user.id)')); + +if(count($ids) < $row[0] / MIN_MEMBERS) { + //echo 'We may optimize the user('.$row[0].')/clan('.count($ids).') ratio
'; + + mysql_query('UPDATE user SET clan = null'); // clean all clans + mysql_query('UPDATE clan SET leader = null, co_leader = null'); + $sql = 'SELECT id FROM clan ORDER BY ID ASC'; + $qry = mysql_query($sql); + while( $row = mysql_fetch_assoc($qry)) { + $sql = 'UPDATE user SET clan = ' .$row['id'] . ' WHERE clan is null AND 0 < (SELECT COUNT(*) FROM chars WHERE besitzer = user.id) LIMIT 5'; + //echo $sql . '
'; + mysql_query($sql); + + if(mysql_affected_rows() == 0) { + break; + } + + } + + $qry = mysql_query('SELECT clan, min(id) as id FROM user WHERE clan is not null GROUP BY clan'); + while($row = mysql_fetch_assoc($qry)) { + $sql = 'UPDATE clan SET leader = '.$row['id'].' WHERE id = '.$row['clan']; + //echo $sql . '
'; + mysql_query($sql); + } + +} + mysql_query('DELETE FROM clan_challenge_requests'); mysql_query('DELETE FROM clan_challenges'); mysql_query('DELETE FROM events'); +mysql_query('DELETE FROM clan_locked'); + + -$clan1 = getClan(786); -$clan2 = getClan(783); + +$ids = getClanFightCapableClanIds(); +if(count($ids) < 2) { + echo "zu wenig Clans die Clanfights machen können " . count($ids); + die(); +} + +$clan1 = getClan($ids[0]); +$clan2 = getClan($ids[1]); $leaderClan1 = getUser($clan1['leader']); $leaderClan2 = getUser($clan2['leader']); @@ -54,7 +96,7 @@ if($acceptTestCase) { if($result !== NULL) { echo $result.'
'; } -/* + if(getOpenChallengeRequestCount($clan1['id']) > 0) { echo 'Fehler in getOpenChallengeRequestCount: Es sollte kein Fight-Request offen sein!!
'; } @@ -103,7 +145,7 @@ if($acceptTestCase) { $result = joinChallenge($clan_challenge_id, $leaderClan2, $chars2[0]['id'], 1); if($result !== NULL) { echo $result .'
'; - }*/ + } @@ -134,4 +176,4 @@ if($acceptTestCase) { -?> \ No newline at end of file +?>