main
hecht 13 years ago
parent 28d657cf82
commit 8b54c64374

@ -62,7 +62,6 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH
if(isClanLocked($user['clan']) || isClanLocked($clanid)) {
// okay we cannot accept the challenge so make it inactive!
mysql_query('UPDATE clan_challenge_requests SET active = FALSE WHERE clan_challenge_id = ' .$clan_challenge_id);
return 'Einer der Clans erfüllt die Anforderungen an Clanfights nichtmehr (wahrscheinlich zu wenig Members)!';
}
@ -79,8 +78,8 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH
// okay we have both semaphores :)
$clan_challenges_my_clan = getOpenChallengeRequestCount($user['clan']);
$clan_challenges_oth_clan = getOpenChallengeRequestCount($clanid);
$clan_challenges_my_clan = getOpenChallengeRequestCount($user['clan']) + count(getOpenChallengeIDs($user['clan']));
$clan_challenges_oth_clan = getOpenChallengeRequestCount($clanid) + count(getOpenChallengeIDs($clanid));
if($clan_challenges_my_clan >= MAX_OPEN_REQUESTS) {
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
@ -243,10 +242,12 @@ function cancelChallengeRequest($challenged_clan, array $user) {
return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können Herausforderungen anderer Clans ablehnen!!';
}
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$challenged_clan . ' AND clan_requester = ' .$user['clan'] . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())'));
$sql = 'SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$challenged_clan . ' AND clan_requester = ' .$user['clan'] . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())';
// echo $sql .'<br>';
$clan_challenge = mysql_fetch_assoc(mysql_query($sql));
if(!$clan_challenge) {
return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!';
if(!$clan_challenge) {
return 'Konnte die Herausforderung nicht zur&uuml;ckziehen, da diese Herausforderung nicht exisitiert!';
}
// TODO: Check if this conditions are redundant
@ -277,10 +278,12 @@ function denyChallengeRequest($challenge_requester, array $user) {
return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können Herausforderungen anderer Clans ablehnen!!';
}
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenge_requester . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())'));
$sql = 'SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenge_requester . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())';
// echo $sql . '<br>';
$clan_challenge = mysql_fetch_assoc(mysql_query($sql));
if(!$clan_challenge) {
return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!';
return 'Konnte die Herausforderung nicht ablehnen, da diese Herausforderung nicht exisitiert!';
}
// TODO: Check if this conditions are redundant
@ -291,7 +294,7 @@ function denyChallengeRequest($challenge_requester, array $user) {
}
// okay seems to be okay
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan. ' AND active = TRUE');
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenge_requester. ' AND active = TRUE');
return NULL;
}
@ -352,6 +355,38 @@ function getOpenChallengeIDs($clanid) {
return $array;
}
function getActiveChallengeIDs($clanid) {
// before doing anything check if we are locked
$array = array();
if(isClanLocked($clanid)) {
return $array;
}
$sql = 'SELECT cc.clan_challenge_id FROM clan_challenges AS cc inner join clan_challenge_clans AS ccp ON cc.clan_challenge_id = ccp.clan_challenge_id WHERE clan_id = ' . $clanid . ' AND calculated = TRUE AND enddate > now() ORDER BY cc.date DESC ' . $addition;
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$array[] = $row[0];
}
// return the ids
return $array;
}
// returns the last challenge ids (beginning with the latest to the first)
function getHistoricalChallengeIDs($clanid, $limit = NULL) {
$addition = '';
if($limit !== null && is_numeric($limit)) {
$addition = ' LIMIT ' .$limit;
}
$sql = 'SELECT cc.clan_challenge_id FROM clan_challenges AS cc inner join clan_challenge_clans AS ccp ON cc.clan_challenge_id = ccp.clan_challenge_id WHERE clan_id = ' . $clanid . ' AND calculated = TRUE AND enddate < now() ORDER BY cc.date DESC ' . $addition;
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$array[] = $row[0];
}
// return the ids
return $array;
}
function getParticipatingClanIDs($clan_challenge_id) {
$array = array();
$sql = 'SELECT clan_id FROM clan_challenge_clans AS ccp WHERE clan_challenge_id = ' . $clan_challenge_id;
@ -380,21 +415,6 @@ function getParticipatingCharIDs($clan_challenge_id, $clan_id) {
return $array;
}
// returns the last challenge ids (beginning with the latest to the first)
function getHistoricalChallengeIDs($clanid, $limit = NULL) {
$addition = '';
if($limit !== null && is_numeric($limit)) {
$addition = ' LIMIT ' .$limit;
}
$sql = 'SELECT cc.clan_challenge_id FROM clan_challenges AS cc inner join clan_challenge_clans AS ccp ON cc.clan_challenge_id = ccp.clan_challenge_id WHERE clan_id = ' . $clanid . ' AND calculated = TRUE ORDER BY cc.date DESC ' . $addition;
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$array[] = $row[0];
}
// return the ids
return $array;
}
function getClanLockedTime($clan_id) {
$sql = 'SELECT TIMESTAMPDIFF(SECOND, NOW(), locked_until) FROM clan_locked WHERE clanid = ' . $clan_id;
$row = mysql_fetch_row(mysql_query($sql));
@ -432,6 +452,9 @@ function isClanLocked($clanid) {
$sql = 'INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP))';
// echo $sql.'<br>';
mysql_query($sql);
// FIXME: We were not locked but now we are! -> deactivate all outstanding clan_challenge_requests
mysql_query('UPDATE clan_challenge_requests SET active = FALSE WHERE (clan_challenged = '.$clanid.' OR clan_requester = '.$clanid);
mysql_query('DELETE FROM clan_challenges WHERE calculated = FALSE AND clan_challenge_id IN (SELECT clan_challenge_id from clan_challenge_clans WHERE clan_id = '.$clanid.')');
} else if($lock['members'] < MIN_MEMBERS){ // we have to update the actual row
// UPDATE
$sql = 'UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid;
@ -439,7 +462,6 @@ function isClanLocked($clanid) {
mysql_query($sql);
}
}
return true;
}
@ -496,7 +518,6 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
foreach ($clan_ids as $clan_id) {
if(isClanLocked($clan_id)) {
mysql_query('DELETE FROM clan_challenges WHERE clan_challenge_id = '.$clan_challenge_id);
semaphoreDown($ressource);
return 'Einer der Clans erfüllt die Anforderungen an Clanfights nichtmehr (wahrscheinlich zu wenig Members)!';
}

Loading…
Cancel
Save