From 04cac8c623fabd7f1971de3ef10415c5008c62e8 Mon Sep 17 00:00:00 2001 From: hecht Date: Sat, 11 Feb 2012 16:51:18 +0000 Subject: [PATCH] okay, finally!!! the leader now can force another users char to participate in the clanfight, even if they have the "Kampf" or "Schatzsuche Status" depending if they can be fetched ("abgeholen") --- ag/include/clan_fights.inc.php | 54 +++++++++++++++++++++------------- ag/include/semaphore.inc.php | 10 +++---- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php index a74d46b..09885aa 100644 --- a/ag/include/clan_fights.inc.php +++ b/ag/include/clan_fights.inc.php @@ -263,7 +263,7 @@ function cancelChallengeRequest($challenged_clan, array $user) { } $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 .'
'; + // echo $sql .'
'; $clan_challenge = mysql_fetch_assoc(mysql_query($sql)); if(!$clan_challenge) { @@ -308,7 +308,7 @@ function denyChallengeRequest($challenge_requester, array $user) { } $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 . '
'; + // echo $sql . '
'; $clan_challenge = mysql_fetch_assoc(mysql_query($sql)); if(!$clan_challenge) { @@ -428,7 +428,7 @@ 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()'; -// echo $sql . '
'; + // echo $sql . '
'; $qry = mysql_query($sql); while($row = mysql_fetch_row($qry)) { $array[] = $row[0]; @@ -504,7 +504,7 @@ 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)); if($row) - return $row[0]; + return $row[0]; return 0; } @@ -538,7 +538,7 @@ function isClanLocked($clanid) { // echo $sql.'
'; $res = mysql_query($sql); if(!$res) - echo $sql . '
'; + echo $sql . '
'; 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 @@ -546,15 +546,15 @@ function isClanLocked($clanid) { $sql = 'UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid; // echo $sql.'
'; $res = mysql_query($sql); - if(!$res) - echo $sql . '
'; + if(!$res) + echo $sql . '
'; } } else if($lock['members'] < MIN_MEMBERS) { $sql = 'UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid; // echo $sql.'
'; $res = mysql_query($sql); if(!$res) - echo $sql . '
'; + echo $sql . '
'; } return true; } @@ -593,13 +593,25 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) { } if($char['status'] != 'Frei') { - // char is not free but is he already participating? - $participant = getParticipatingChar($clan_challenge_id, $clan['id'], $charid); - if(!$participant || !$participant['forced']) { - return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er nicht frei ist!'; + 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? + $participant = getParticipatingChar($clan_challenge_id, $clan['id'], $charid); + if(!$participant || !$participant['forced']) { + return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er nicht frei ist!'; + } + db_query('UPDATE clan_challenge_participants SET forced = FALSE WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = '.$clan['id'].' AND char_id = ' . $charid); + return NULL; } - db_query('UPDATE clan_challenge_participants SET forced = FALSE WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = '.$clan['id'].' AND char_id = ' . $charid); - return NULL; } $clan_challenge = getChallenge($clan_challenge_id); @@ -780,10 +792,10 @@ function cancelChallenge($clan_challenge_id, array $user) { // kay, finish him !!! $sql = 'DELETE FROM clan_challenges WHERE clan_challenge_id = ' .$clan_challenge_id . ' AND calculated = FALSE'; -// echo $sql . '
'; + // echo $sql . '
'; $res = mysql_query($sql); if(!$res) - return 'Beim zurückziehen des Clan-Fights ist ein technischer Fehler aufgetreten!'; + return 'Beim zurückziehen des Clan-Fights ist ein technischer Fehler aufgetreten!'; foreach ($user_to_notify as $userid) { sendMessage($user['nickname'], $userid, 'Clan-Fight', 'Der Clan '.$clan['clanname'].' hat den Clan-Fight zurückgezogen!'); @@ -829,12 +841,12 @@ function calculateChallenge($clan_challenge_id) { case DAVY_BACK_FIGHT: $result = calculateDavyBackClanFight($clan_challenge_id, $event_id, $clan_ids, $clan_chars, $start_time); if(!is_numeric($result)) - return $result; + return $result; break; case SURVIVAL: $result = calculateSurvivalClanFight($clan_challenge_id, $event_id, $clan_ids, $clan_chars, $start_time); if(!is_numeric($result)) - return $result; + return $result; break; default: // cannot create anything -.- @@ -992,12 +1004,12 @@ function updateAuthorizedClanfightCoordinators($clan_id, array $user_ids) { $remove = array_diff($ids, $user_ids); $sql = 'DELETE FROM `clan_challenge_whitelist` WHERE `user_id` IN (' . implode(',', $remove) .') AND `clan_id` = ' . $clan_id; -// echo $sql . '
'; + // echo $sql . '
'; mysql_query($sql); foreach($add as $user_id) { $sql = 'INSERT INTO `clan_challenge_whitelist`(`user_id`, `clan_id`) values('.$user_id.', '.$clan_id.')'; -// echo $sql . '
'; + // echo $sql . '
'; mysql_query($sql); } } @@ -1023,7 +1035,7 @@ function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = N // do we require this information for a specific clan_fight??? 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 . '
'; + // echo $sql . '
'; $row = mysql_fetch_row(mysql_query($sql)); if($row[0] <= 0) { // okay, maybe its a leader ;) diff --git a/ag/include/semaphore.inc.php b/ag/include/semaphore.inc.php index b645513..d8e59da 100644 --- a/ag/include/semaphore.inc.php +++ b/ag/include/semaphore.inc.php @@ -35,15 +35,15 @@ $GLOBALS['semaphorecount'] = 0; * @param string $resource the name of the resource */ function semaphoreUP($resource){ -// echo 'semaphoreUp('.$ressource.')
' . PHP_EOL ; + // echo 'semaphoreUp('.$resource.')
' . PHP_EOL ; if($GLOBALS['semaphorecount'] == 0){ ignore_user_abort(true); // Verarbeitung darf NICHT abgebrochen werden!! // echo 'DEBUG: kritischer Bereich betreten
'; } // Loesche alte Ressourcen - mysql_query('DELETE FROM semaphore WHERE TIMESTAMPDIFF(MINUTE, zeit, now()) > 5 and ressource = \''.$ressource.'\''); + mysql_query('DELETE FROM semaphore WHERE TIMESTAMPDIFF(MINUTE, zeit, now()) > 5 and ressource = \''.$resource.'\''); - $sql = 'INSERT INTO semaphore(ressource) values(\''.$ressource.'\')'; + $sql = 'INSERT INTO semaphore(ressource) values(\''.$resource.'\')'; mysql_query($sql); if(mysql_affected_rows() > 0){ // echo 'DEBUG: Semaphore fuer '.$ressource.' belegt!('.mysql_affected_rows().')
'; @@ -59,8 +59,8 @@ function semaphoreUP($resource){ } // @Returns TRUE if ok, FALSE on Semaphore error, NULL on MYQL Error -function semaphoreDown($ressource){ - $sql = 'DELETE FROM semaphore where ressource = \''.$ressource.'\''; +function semaphoreDown($resource){ + $sql = 'DELETE FROM semaphore where ressource = \''.$resource.'\''; mysql_query($sql); if(mysql_affected_rows() == 0){ // echo 'DEBUG: Semaphore '.$ressource.' war schon freigegeben
';