return 'Der Clan "'.$oclan['clanname'].'" hat schon die maximale Anzahl von Herausforderungen offen!';
}
// select count(*) from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE
// 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);
$row = mysql_fetch_assoc($qry);
if($row['anzahl'] > 0) {
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
semaphoreDown($ressource_clan2); // free the previously reserved semaphore!
return 'Konnte den anderen Clan nicht herausfordern, da dieser Clan schoneinmal in den letzten 24 Stunden herausgefordert wurde!';
* With this function the actual user accepts the challenge request from another clan!
* @param int $clan_challenge_id
* @param int $challenged_clan the clan that has challenged us!
* @param array $user
*/
function acceptChallengeRequest($clan_challenge_id, array $user) {
function acceptChallengeRequest($challenged_clan, array $user) {
$clan = getClan($user['clan']);
if(!$clan) {
@ -121,7 +135,12 @@ function acceptChallengeRequest($clan_challenge_id, array $user) {
return 'Nur der Leader, bzw. der Co-Leader kann herausforderungen anderer Clans annehmen!!';
}
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM WHERE clan_challenge_id = ' .$clan_challenge_id));
$sql = 'SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())';
mysql_query('UPDATE clan_challenge_requests SET accepted = TRUE WHERE clan_challenge_id = ' .$clan_challenge_id);
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())');
if(mysql_affected_rows() > 0) {
// okay and for failsaveness just deactivate old requests
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan. ' AND active = TRUE');
if(is_numeric($oclan['leader'])) {
sendMessage($user['nickname'], $oclan['leader'], 'Clan-Fight', 'Der Clan '.$oclan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!');
}
@ -151,8 +173,8 @@ function acceptChallengeRequest($clan_challenge_id, array $user) {
$id = -1;
// get id
while(!$finished) {
$row = mysql_fetch_row(mysql_query('select IFNULL(max(clan_challenge_id),0) + 1 from clan_challenge'));
mysql_query('INSERT INTO clan_challenge(clan_challenge_id) values('.$row[0].')');
$row = mysql_fetch_row(mysql_query('select IFNULL(max(clan_challenge_id),0) + 1 from clan_challenges'));
mysql_query('INSERT INTO clan_challenges(clan_challenge_id, type, anzahl_chars) values('.$row[0].', '.$clan_challenge['type'].', '.$clan_challenge['anzahl_chars'].')');
$finished = mysql_affected_rows() > 0;
$id = $row[0];
}
@ -172,10 +194,10 @@ function acceptChallengeRequest($clan_challenge_id, array $user) {
/**
* With this function the actual user from the challenged clan denies the challenge request!
* @param int $clan_challenge_id
* @param int $challenged_clan
* @param array $user
*/
function denyChallengeRequest($clan_challenge_id, array $user) {
function denyChallengeRequest($challenged_clan, array $user) {
$clan = getClan($user['clan']);
if(!$clan) {
@ -186,7 +208,11 @@ function denyChallengeRequest($clan_challenge_id, array $user) {
return 'Nur der Leader, bzw. der Co-Leader kann Herausforderungen anderer Clans ablehnen!!';
}
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM WHERE clan_challenge_id = ' .$clan_challenge_id));
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())'));
if(!$clan_challenge) {
return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!';
return 'Du kannst die Herausforderung nicht ablehnen, da du nicht im herausgeforderten Clan bist!';
@ -195,7 +221,7 @@ function denyChallengeRequest($clan_challenge_id, array $user) {
}
// okay seems to be okay
mysql_query('UPDATE clan_challenge_requests SET active = FALSE WHERE clan_challenge_id = ' .$clan_challenge_id);
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan. ' AND active = TRUE');
return NULL;
}
@ -208,7 +234,11 @@ function getChallenge($challenge_id, $buffer = TRUE) {
return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :)
}
function getOpenChallengeRequests($clanid) {
$array = array();
@ -216,7 +246,8 @@ function getOpenChallengeRequests($clanid) {
return $array;
}
$sql = 'SELECT * from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND clan_requester = '.$clanid.' OR clan_challenged = '.$clanid;
$sql = 'SELECT * from clan_challenge_requests WHERE challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND (clan_requester = '.$clanid.' OR clan_challenged = '.$clanid.')';
// echo $sql . '<br>';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$array[] = $row;
@ -228,7 +259,8 @@ function getOpenChallengeRequestCount($clanid) {
if(isClanLocked($clanid)) {
return 0;
}
$sql = 'SELECT count(*) from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND clan_requester = '.$clanid.' OR clan_challenged = '.$clanid;
$sql = 'SELECT count(*) from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND (clan_requester = '.$clanid.' OR clan_challenged = '.$clanid.')';
// echo $sql . '<br>';
$row = mysql_fetch_row(mysql_query($sql));
return $row[0];
}
@ -272,7 +304,7 @@ function getParticipatingCharIDs($clan_challenge_id, $clan_id) {
$sql = 'SELECT char_id, slot FROM clan_challenge_participants WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = ' .$clan_id;
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$array['slot'] = $row['char_id'];
$array[$row['slot']] = $row['char_id'];
}
// return the ids
return $array;
@ -296,23 +328,30 @@ function getHistoricalChallengeIDs($clanid, $limit = NULL) {
// Checks if the clan is locked, will lock it if required!
function isClanLocked($clanid) {
// we really want to know if we are locked at the moment. So readout everything at once ;), right join so we always have a row :D
// okay does this user already has a char in the fight??
$qry = mysql_query('SELECT count(*) as anzahl FROM clan_challenge_participants ccp inner join chars c on ccp.char_id = c.id WHERE besitzer = ' .$user['id']);
$row = mysql_fetch_assoc($qry);
if($row['anzahl'] != 0) {
semaphoreDown($ressource);
return 'Konnte den Char nicht hinzufügen. Da du schon einen Char angemeldet hast!';
}
mysql_query('INSERT INTO clan_challenge_participants(clan_challenge_id, clan_id, char_id, slot) values('.$clan_challenge_id.', '.$user['clan'].', '.$charid.', '.$slot.')');
if(mysql_affected_rows() == 0) {
semaphoreDown($ressource);
return 'Konnte den Char nicht hinzufügen. Slot mittlerweile schon belegt?';
}
// okay, now try to update the challenge to close the challenge and to start the calculating (as long we can do it ;))
$sql = 'update clan_challenges AS cc SET calculated = TRUE WHERE '.
'(SELECT count(*) FROM clan_challenge_participants AS ccp ' .
@ -465,7 +523,7 @@ function calculateDavyBackClanFight($event_id, array $clan_ids, array $clan_char