$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(hour, -'.CLANFIGHTS_RECHALLENGE_DELAY.', now())';
return 'Konnte den anderen Clan nicht herausfordern, da dieser Clan schoneinmal in den letzten '.CLANFIGHTS_RECHALLENGE_DELAY.' Stunden herausgefordert wurde!';
// it should not be possible to challenge a clan that already has an open match that is not yet calculated! ( not completely possible in sql)
$sql = 'select count(k.anzahl) as anzahl from (SELECT count(*) as anzahl FROM clan_challenges c inner join clan_challenge_clans ccc on c.clan_challenge_id = ccc.clan_challenge_id where (calculated = 1 or enddate > now()) and clan_id IN ('.$user['clan'].', '.$clanid.') group by c.clan_challenge_id) k where k.anzahl = 0';
//echo $sql .'<br>';
$row = mysql_fetch_assoc(mysql_query($sql));
if($row['anzahl'] > 0) {
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
semaphoreDown($ressource_clan2); // free the previously reserved semaphore!
return 'Du kannst einen Clan nicht herausfordern, wenn derzeit gerade ein Clanfight zwischen euch läuft oder offen ist!';
}
// now calculate how many open fights we currently had or have!
$sql = 'select count(*) as anzahl from (SELECT count(*) as anz FROM clan_challenges c inner join clan_challenge_clans ccc on c.clan_challenge_id = ccc.clan_challenge_id where calculated = 0 or TIMESTAMPADD(day, -1, now()) <enddateandclan_idIN('.$user['clan'].','.$clanid.')groupbyclan_id)kwherek.anz>= ' . CLANFIGHTS_MAX_FIGHTS_PER_24H;
//echo $sql .'<br>';
$row = mysql_fetch_assoc(mysql_query($sql));
if($row['anzahl'] > 0) {
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
semaphoreDown($ressource_clan2); // free the previously reserved semaphore!
return 'Einer der beiden Clans hat das Limit von ' . CLANFIGHTS_MAX_FIGHTS_PER_24H . ' offenen und abgeschlossenen Clanfights innerhalb von 24 erreicht. Daher kann die Herausforderung nicht versandt werden!';
sendMessage($user['nickname'], $oclan['leader'], 'Clan-Fight Herausforderung', 'Der Clan '.$clan['clanname'].' hat euch zu einem Clan-Fight herausgefordert! Über "Mein Clan" könnt ihr die Herausforderung annehmen!');
sendMessage($user['nickname'], $oclan['co_leader'], 'Clan-Fight Herausforderung', 'Der Clan '.$clan['clanname'].' hat euch zu einem Clan-Fight herausgefordert! Über "Mein Clan" könnt ihr die Herausforderung annehmen!');
$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())';
// now calculate how many open fights we currently had or have! // FIXME: Good idea to pach this in a semaphore?
$sql = 'select count(*) as anzahl from (SELECT count(*) as anz FROM clan_challenges c inner join clan_challenge_clans ccc on c.clan_challenge_id = ccc.clan_challenge_id where calculated = 0 or TIMESTAMPADD(day, -1, now()) <enddateandclan_idIN('.$clan_challenge['clan_challenged'].','.$clan_challenge['clan_requester'].')groupbyclan_id)kwherek.anz>= ' . CLANFIGHTS_MAX_FIGHTS_PER_24H;
return 'Einer der beiden Clans hat das Limit von ' . CLANFIGHTS_MAX_FIGHTS_PER_24H . ' offenen und abgeschlossenen Clanfights innerhalb von 24 erreicht. Daher kann die Herausforderung nicht angenommen werden!';
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())');
// 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');
sendMessage($user['nickname'], $oclan['leader'], 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!');
sendMessage($user['nickname'], $oclan['co_leader'], 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!');
sendMessage($user['nickname'], $clan_challenge['clan_challenge_creator'], 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!');
$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())';
return 'Du kannst die Herausforderung nicht ablehnen, da du nicht im herausfordernden Clan bist!';
} else if ($clan_challenge['active'] != 1) {
return 'Du kannst die Herausforderung nicht ablehnen, da diese schon angenommen wurde!';
}
// okay seems to be okay
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$challenged_clan . ' AND clan_requester = ' .$user['clan'] . ' AND active = TRUE');
sendMessage($user['nickname'], $oclan['leader'], 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat die Herausforderungen zu einem Clan-Fight zurückgezogen! Über "Mein Clan" kann eine neue Herausforderungen erstellt werden!');
sendMessage($user['nickname'], $oclan['co_leader'], 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat die Herausforderungen zu einem Clan-Fight zurückgezogen! Über "Mein Clan" kann eine neue Herausforderungen erstellt werden!');
$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())';
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenge_requester. ' AND active = TRUE');
sendMessage($user['nickname'], $oclan['leader'], 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight abgelehnt! Über "Mein Clan" könnt neue Herausforderungen erstellen!');
sendMessage($user['nickname'], $oclan['co_leader'], 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight abgelehnt! Über "Mein Clan" könnt neue Herausforderungen erstellen!');
sendMessage($user['nickname'], $clan_challenge['clan_challenge_creator'], 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight abgelehnt! Über "Mein Clan" könnt neue Herausforderungen erstellen!');
$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 count(*) from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND (clan_requester = '.$clanid.' OR clan_challenged = '.$clanid.')';
// this method returns the challenge ids for open fights
function getOpenChallengeIDs($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 = FALSE';
$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;
* Returns the ChallengeIDs that are finished but not yet processed by the cronjob!!
* @param int $clanid
* @return array an array containing the ids of the clan_challenges
*/
function getAwatingChallengeIDs() {
// before doing anything check if we are locked
$array = array();
$sql = 'SELECT distinct(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 elo_change is null AND calculated = TRUE AND enddate <now()';
// 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()ORDERBYcc.dateDESC'.$addition;
$sql = 'SELECT count(*) as anzahl FROM clan_challenge_participants ccp INNER JOIN clan_challenges cc on ccp.clan_challenge_id = cc.clan_challenge_id WHERE cc.calculated = FALSE AND char_id = ' .$char_id;
$sql = 'SELECT *, locked_until > now() as `lock`, (Select count(id) from user where clan = c2.id) as members FROM clan_locked right join clan c2 on c2.id = clan_locked.clanid where c2.id = ' . $clanid;
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.')');
if($forced && ($char['status'] == 'Kampf' || $char['status'] == 'Schatz Suche')) { // foreign assignment may also possible if the status is in "fetching" state
// okay now check if the fetch-time is reached!!
if($char['status'] == 'Schatz Suche') {
$row = mysql_fetch_row(db_query('SELECT Timestampdiff(Second,now(),dauer) as dauer from quests where charid = '.$charid));
} else {
$row = mysql_fetch_row(db_query('SELECT dauer - ' . time() . ' FROM kampf WHERE db_satz='.$charid ));
}
if($row[0] > 0) {
return 'Du kannst den Char \''.$char['name'].'\' nicht an dem Kampf teilnehmen lassen, da er im Moment noch für ' . $row[0] . ' Sekunden mit ' . $char['status']. ' beschäftigt ist!';
}
} else {
// char is not free but is he already participating?
return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da du scheinbar gerade auch mit was anderem beschäftigt bist, versuche es bitte nochmal!';
}
foreach ($clan_ids as $clan_id) {
if(isClanLocked($clan_id)) {
semaphoreDown($ressource);
return 'Einer der Clans erfüllt die Anforderungen an Clanfights nichtmehr (wahrscheinlich zu wenig Members)!';
$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'] . ' AND clan_challenge_id = ' . $clan_challenge_id);
sendMessage($requestor['nickname'], $char['besitzer'], 'Clanfightteilnahme', 'Dein Char ' . $char['name'] . ' wurde zu einem Clanfight hinzugezogen, du kannst ihn im Clanfight Menü abmelden oder dein OK geben, damit evtl. weitere Chars von offline Usern hinzugefügt werden können!');
// Okay, the rest we can check with the delete statement much easier!
// basically the check consists of a) is the challenge not yet calculated b) is char active in the challenge?
$sql = 'DELETE FROM clan_challenge_participants WHERE (SELECT calculated FROM clan_challenges AS cc WHERE cc.clan_challenge_id = clan_challenge_participants.clan_challenge_id) = FALSE AND char_id = ' . $charid;
mysql_query($sql);
if(mysql_affected_rows() == 0) {
return 'Der Char kann nicht aus dem Kampf zurückgezogen werden.';