From 6a1932ea549326c2c712fd32411689757b855a2b Mon Sep 17 00:00:00 2001 From: hecht Date: Wed, 18 Jan 2012 23:32:57 +0000 Subject: [PATCH] it is now possible to assign a char from an offline user into a clanfight. Additionally the clan fight coordinators may kick chars from a clan challenge. Both actions will result into a notify pm. As there is a limit of the maximum amount of chars that can be assigned from offline users (also they have to be in free state) it is possible for the owner to give its okay when coming online. --- ag/clan/kampf_info.php | 125 ++++++++++++++++++++++++++++++--- ag/include/clan_fights.inc.php | 50 ++++++++++--- ag/include/semaphore.inc.php | 9 +-- ag/include/sqlwrapper.inc.php | 2 +- ag/include/user.inc.php | 7 +- 5 files changed, 169 insertions(+), 24 deletions(-) diff --git a/ag/clan/kampf_info.php b/ag/clan/kampf_info.php index 1b2f6b5..77d6d81 100644 --- a/ag/clan/kampf_info.php +++ b/ag/clan/kampf_info.php @@ -33,10 +33,17 @@ $type = validateUnsignedInteger($_GET['type'], null); if($action == null) { $action = $_POST['action']; } -if($char_id == null) { - $char_id = validateUnsignedInteger($_POST['char'], null); + +if(isset($_POST['other_submit'])) { + $slot = validateUnsignedInteger($_POST['oslot'], null); + $char_id = validateUnsignedInteger($_POST['o_char'], null); +} else { + if($char_id == null) { + $char_id = validateUnsignedInteger($_POST['char'], null); + } + $slot = validateUnsignedInteger($_POST['slot'], null); } -$slot = validateUnsignedInteger($_POST['slot'], null); + if($clan_challange_id == null) { $clan_challange_id = validateUnsignedInteger($_POST['challenge'], null); } @@ -132,6 +139,9 @@ function displayShowChallenge($clan_challenge_id, $user) { $user_clan_chars = getParticipatingCharIDs($clan_challenge_id, $user_clan['id']); $other_clan_chars = getParticipatingCharIDs($clan_challenge_id, $other_clan['id']); $user_chars = getCharsOfUser($user['id']); + $authorized = isAuthorizedClanfightCoordinator($user['clan'], $user['id'], $clan_challenge_id); + + $slots = array(); ?> @@ -156,6 +166,9 @@ function displayShowChallenge($clan_challenge_id, $user) { echo ''; } ?> + +
+ @@ -165,10 +178,13 @@ function displayShowChallenge($clan_challenge_id, $user) { echo 'Slot '.$i.''; if($user_clan_chars[$i] != null) { $char = getChar($user_clan_chars[$i]); + $participant = getParticipatingChar($clan_challenge_id, $user_clan['id'], $user_clan_chars[$i]); $char_owner = getOwnerOfChar($char['id']); echo ''.generateCharLinkByID($char['id']); echo '('.generateUserLinkByID($char_owner['id'], FALSE).')'; - if(isUserOwnerOf($user['id'], $char['id'])) { + if(isUserOwnerOf($user['id'], $char['id']) && $participant['forced'] == TRUE) { + echo 'ok | abmelden'; + } else if(isUserOwnerOf($user['id'], $char['id']) || $authorized) { echo 'abmelden'; } } else { @@ -178,12 +194,14 @@ function displayShowChallenge($clan_challenge_id, $user) { echo ''; } ?> + +
+ Teilnahme - - Charakter: + Charakter: - + $row['user_name']); + } + $users[$row['user_id']]['chars'][] = array('char_name' => $row['char_name'], 'char_id' => $row['char_id']); + } + +// print_r($users); + + ?> + +
+ + + Chars zuweisen von Offline Usern: + + + User: + + + + + + + + Charakter: + + + + + + Slot: + + + + + + + zurück';?> diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php index 61f4469..a74d46b 100644 --- a/ag/include/clan_fights.inc.php +++ b/ag/include/clan_fights.inc.php @@ -490,6 +490,13 @@ function getParticipatingCharIDs($clan_challenge_id, $clan_id) { return $array; } +function getParticipatingChar($clan_challenge_id, $clan_id, $char_id) { + $qry = db_query('SELECT * FROM clan_challenge_participants WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = ' .$clan_id . ' AND char_id = ' . $char_id); + $row = mysql_fetch_assoc($qry); + return $row; +} + + function getClanLockedTime($clan_id) { if(!isClanLocked($clan_id)) { return 0; @@ -572,16 +579,27 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) { if($char['besitzer'] != $user['id']) { // the current user is NOT the owner of the char --> check if it is a coordinator - if(isAuthorizedClanfightCoordinator($clan_id, $user['id'], $clan_challenge_id)) { + if(isAuthorizedClanfightCoordinator($clan['id'], $user['id'], $clan_challenge_id)) { + if(isUserOnline($char['besitzer'])) { + return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da der Besitzer online ist!'; + } // okay we may assign an additional char ;) // check if we have reached the limit is later!! $forced = true; + $requestor = $user; + $user = getUser($char['besitzer']); } else { return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er dir nicht gehört!'; } } if($char['status'] != 'Frei') { - return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er nicht frei ist!'; + // 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; } $clan_challenge = getChallenge($clan_challenge_id); @@ -598,7 +616,7 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) { } // block the user actions so we can ensure he won't register multiple of its chars here! - $resource = 'User:'.$user['id']; + $ressource = 'User:'.$user['id']; if(!semaphoreUP($ressource)) { 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!'; } @@ -623,18 +641,18 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) { } - - $resource2 = 'Clan:'.$clan_id; + $ressource2 = 'Clan:'.$clan['id']; if($forced && !semaphoreUP($ressource2)) { + semaphoreDown($ressource); return 'Du kannst den Char nicht zuweisen, da exakt im gleichen Moment jemand aus deinem Clan auch einen Char zuweist!'; } // okay and now check if we reached the maximum amount of leader assigned chars!! - if($forced && getCountLeaderAssignedChars($clan_id, $clan_challenge_id) >= MAX_LEADER_ASSIGNED_CHARS) { + if($forced && getCountLeaderAssignedChars($clan['id'], $clan_challenge_id) >= MAX_LEADER_ASSIGNED_CHARS) { // shit!! semaphoreDown($ressource); semaphoreDown($ressource2); - return 'Du kannst den Char nicht zuweisen, da die maximale Anzahl der Zuweisungen schon erreicht ist!'; + return 'Du kannst den Char nicht zuweisen, da die maximale Anzahl der erlaubten Zuweisungen ('.MAX_LEADER_ASSIGNED_CHARS.') schon erreicht ist!'; } $sql = 'INSERT INTO clan_challenge_participants(clan_challenge_id, clan_id, char_id, slot, forced) values('.$clan_challenge_id.', '.$user['clan'].', '.$charid.', '.$slot.', ' .($forced?'TRUE':'FALSE') .')'; $res = mysql_query($sql); @@ -677,6 +695,11 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) { // okay we now have a complete competition and the challenge is closed :) return calculateChallenge($clan_challenge_id); } + + if($forced) { + 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!'); + } + return NULL; } @@ -695,8 +718,11 @@ function leaveChallenge($clan_challenge_id, array $user, $charid) { return 'Du bist in keinem Clan!!'; } + $forced = false; + if($char['besitzer'] != $user['id']) { if(!isAuthorizedClanfightCoordinator($clan['id'], $user['id'], $clan_challenge_id)) { + $forced = true; // authorized coordinators may remove a char!! But this one is not authorized return 'Du kannst den Char nicht vom Kampf zurückziehen, da er dir nicht gehört!'; } @@ -711,6 +737,10 @@ function leaveChallenge($clan_challenge_id, array $user, $charid) { return 'Der Char kann nicht aus dem Kampf zurückgezogen werden.'; } + if($forced) { + sendMessage($user['nickname'], $char['besitzer'], 'Kick aus Clanfight', 'Dein Char ' . $char['name'] . ' wurde aus einem Clanfight gekickt!'); + } + return NULL; } @@ -993,7 +1023,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 ;) @@ -1050,8 +1080,8 @@ function calculateClanExperience(array $clan1, array $clan2, $winner) { * @param int $clan_fight_id */ function getCountLeaderAssignedChars($clan_id, $clan_fight_id) { - $sql = 'SELECT COUNT(*) FROM `clan_challenge_participants` WHERE `clan_challenge_id` = ' .$clan_fight_id . ' AND `clan_id` = '.$clan_id .' AND `forced` = TRUE'; - $row = mysql_fetch_row(mysql_query($sql)); + $qry = db_query('SELECT COUNT(*) FROM `clan_challenge_participants` WHERE `clan_challenge_id` = ' .$clan_fight_id . ' AND `clan_id` = '.$clan_id .' AND `forced` = TRUE'); + $row = mysql_fetch_row($qry); return $row[0]; } diff --git a/ag/include/semaphore.inc.php b/ag/include/semaphore.inc.php index ca0c6c4..4201e92 100644 --- a/ag/include/semaphore.inc.php +++ b/ag/include/semaphore.inc.php @@ -25,19 +25,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// Eine spezielle Semaphore, die sich von gewoehnlichen Semaphoren unterscheidet +// Eine spezielle Semaphore, die sich von gewoehnlichen Semaphoren unterscheidet // @Returns TRUE if ok, FALSE if not, NULL on error $GLOBALS['semaphorecount'] = 0; function semaphoreUP($ressource){ +// echo 'semaphoreUp('.$ressource.')
' . 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.'\''); - + $sql = 'INSERT INTO semaphore(ressource) values(\''.$ressource.'\')'; mysql_query($sql); if(mysql_affected_rows() > 0){ @@ -48,7 +49,7 @@ function semaphoreUP($ressource){ // echo 'DEBUG:Semaphore fuer '.$ressource.' NICHT belegt!
'; if($GLOBALS['semaphorecount'] == 0){ // echo 'DEBUG: Verlassen des kritischen Bereichs
'; - ignore_user_abort(false); // Verarbeitung darf wieder abgebrochen werden!! + ignore_user_abort(false); // Verarbeitung darf wieder abgebrochen werden!! } return false; } @@ -65,7 +66,7 @@ function semaphoreDown($ressource){ $GLOBALS['semaphorecount']--; if($GLOBALS['semaphorecount'] == 0){ // echo 'DEBUG: kritischer Bereich verlassen
'; - ignore_user_abort(false); // Verarbeitung darf nun wieder abgebrochen werden!! + ignore_user_abort(false); // Verarbeitung darf nun wieder abgebrochen werden!! } return true; } diff --git a/ag/include/sqlwrapper.inc.php b/ag/include/sqlwrapper.inc.php index 12a6649..8151e8a 100755 --- a/ag/include/sqlwrapper.inc.php +++ b/ag/include/sqlwrapper.inc.php @@ -5,7 +5,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence * @author hecht */ - + function db_query($sql) { $qry = mysql_query($sql); if(!$qry) { diff --git a/ag/include/user.inc.php b/ag/include/user.inc.php index c0ade6b..6d4b579 100644 --- a/ag/include/user.inc.php +++ b/ag/include/user.inc.php @@ -19,12 +19,17 @@ function getUser($userid, $buffer_enabled = true) { } // Wenn Char nicht im Puffer ist, oder nicht gepuffert werden soll if ($GLOBALS['user_buffered_instances'][$userid] == null || !$buffer_enabled) { - $user = mysql_fetch_assoc(mysql_query('SELECT * FROM user WHERE id = '.$userid)); + $user = mysql_fetch_assoc(db_query('SELECT *, online_zeit between TIMESTAMPADD(Minute, -15, now()) and now() as online FROM user WHERE id = '.$userid)); $GLOBALS['user_buffered_instances'][$userid] = $user; } return $GLOBALS['user_buffered_instances'][$userid]; } +function isUserOnline($userid) { + $user = getUser($userid); + return $user['online']; +} + /** * * Returns the user of the Character. (attributes of the user-table should be added here if needed)