did some fixes on clanfights ... also adjusted the test.php to automatically test the fights. also fixed a display bug (thx to ray)

main
hecht 13 years ago
parent e86800f9d9
commit 231e1436a7

@ -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!!'; 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!!'; 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!!'; 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!!'; 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!!'; 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!!'; 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) { function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = NULL) {
// do we require this information for a specific clan_fight??? // 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; $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 . '<br>';
$row = mysql_fetch_row(mysql_query($sql)); $row = mysql_fetch_row(mysql_query($sql));
if($row[0] <= 0) { if($row[0] <= 0) {
// okay, maybe its a leader ;) // okay, maybe its a leader ;)
$clan = getClan($clan_id); $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! // the leader or the co_leader is always authorized!
return true; return true;
} }
@ -755,6 +756,17 @@ function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = N
// it is a more general thing ;) // it is a more general thing ;)
$sql = 'SELECT COUNT(*) FROM `clan_challenge_whitelist` WHERE `user_id` = ' .$user_id. ' AND `clan_id` = '.$clan_id; $sql = 'SELECT COUNT(*) FROM `clan_challenge_whitelist` WHERE `user_id` = ' .$user_id. ' AND `clan_id` = '.$clan_id;
$row = mysql_fetch_row(mysql_query($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) {
// the leader or the co_leader is always authorized!
//echo 'true<br>';
return true;
}
// not authorized!
return false;
}
} }
return true; return true;
} }

@ -286,7 +286,7 @@ function displaySchatzSuche($char){
// Lade nun die Fights runter // 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); $qry = mysql_query($sql);
while($fight = mysql_fetch_assoc($qry)){ while($fight = mysql_fetch_assoc($qry)){
displaySchatzSucheFight($quest, $char, $fight); displaySchatzSucheFight($quest, $char, $fight);
@ -460,4 +460,4 @@ function displayEventFightRound(array $char1_data, array $char2_data, array $cha
echo '</td></tr>'; echo '</td></tr>';
} }
?> ?>

@ -14,12 +14,54 @@ include_once(ROOT_PATH.'/include/clan_fights.inc.php');
$acceptTestCase = true; $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<br>';
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 . '<br>';
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 . '<br>';
mysql_query($sql);
}
}
mysql_query('DELETE FROM clan_challenge_requests'); mysql_query('DELETE FROM clan_challenge_requests');
mysql_query('DELETE FROM clan_challenges'); mysql_query('DELETE FROM clan_challenges');
mysql_query('DELETE FROM events'); 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']); $leaderClan1 = getUser($clan1['leader']);
$leaderClan2 = getUser($clan2['leader']); $leaderClan2 = getUser($clan2['leader']);
@ -54,7 +96,7 @@ if($acceptTestCase) {
if($result !== NULL) { if($result !== NULL) {
echo $result.'<br>'; echo $result.'<br>';
} }
/*
if(getOpenChallengeRequestCount($clan1['id']) > 0) { if(getOpenChallengeRequestCount($clan1['id']) > 0) {
echo 'Fehler in getOpenChallengeRequestCount: Es sollte kein Fight-Request offen sein!!<br>'; echo 'Fehler in getOpenChallengeRequestCount: Es sollte kein Fight-Request offen sein!!<br>';
} }
@ -103,7 +145,7 @@ if($acceptTestCase) {
$result = joinChallenge($clan_challenge_id, $leaderClan2, $chars2[0]['id'], 1); $result = joinChallenge($clan_challenge_id, $leaderClan2, $chars2[0]['id'], 1);
if($result !== NULL) { if($result !== NULL) {
echo $result .'<br>'; echo $result .'<br>';
}*/ }
@ -134,4 +176,4 @@ if($acceptTestCase) {
?> ?>

Loading…
Cancel
Save