diff --git a/ag/clan/clan_info.php b/ag/clan/clan_info.php index ec0a3fc..17b5e1b 100644 --- a/ag/clan/clan_info.php +++ b/ag/clan/clan_info.php @@ -7,6 +7,7 @@ */ include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/clan.inc.php'); +include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/clan_fights.inc.php'); include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/fehlerausgabe.inc.php'); @@ -52,7 +53,7 @@ if(isset($_GET['value1']) || isset($_GET['value2'])) { break; case 'Clanzeichen': $value1 = validateString($_GET['value1']); - $value2 = validateString($_GET['value2']); + $value2 = validateString($_GET['value2']); break; case 'Leadership': $value1 = validateUnsignedInteger($_GET['value1'], NULL); @@ -68,7 +69,7 @@ function displayClanProfileReadOnly($clan, $ownclan, $userid){ $count = mysql_num_rows($member_qry); $member = array(); while($row = mysql_fetch_assoc($member_qry)){ - $tmp = displayUserLinkByID($row['id']); + $tmp = generateUserLinkByID($row['id']); if($row['id'] == $userid){ $member[] = $tmp.' (verlassen)'; } else{ @@ -86,9 +87,25 @@ function displayClanProfileReadOnly($clan, $ownclan, $userid){ $invited = array(); while($row = mysql_fetch_assoc($inv_qry)) { - $invited[] = displayUserLinkByID($row['userid']) . ' (noch ' . $row['till'] . 'h gültig)'; + $invited[] = generateUserLinkByID($row['userid']) . ' (noch ' . $row['till'] . 'h gültig)'; + } + + if(count($invited) == 0) { + $invited[] = 'Keine'; + } + + $openChallengeRequests = getOpenChallengeRequests($clan['id']); + // okay now we split into challenges we have done and we have received + foreach($openChallengeRequests as $request) { + if($request['clan_requester'] != $clan['id']) { + $openChallengeRequestsDisplay[] = displayClanLink($request['clan_requester']) ; + } else { + $openChallengeRequestsDisplay[] = displayClanLink($request['clan_challenged']) ; + } + } + ?>
@@ -137,27 +154,38 @@ function displayClanProfileReadOnly($clan, $ownclan, $userid){ 0) { ?> - + + 0) { + ?> + + + + + - - + + + + + + - - - - - + + + - - - + + + + 0) { + ?> - + + + 0) { + ?> + + + + + - - - - - - - - + + + + + + + + - + + + '; + $content = ''; $what = 'ERROR'; - } + } $clan = getCLan($clanid); $content = ''; @@ -501,26 +566,6 @@ function displayEdit($what, $clanid, $rootlvl){ '; - mysql_query($sql); - if(mysql_affected_rows() > 0){ // Soll nur ausgeführt werden, wenn member wirklich gekickt wurde!! - $sql = 'Update chars set clan_train = NULL where besitzer = '.$member; - mysql_query($sql); - if($user['id'] != $member) { - sendMessage($user['nickname'], $member, 'Clan rauswurf!', 'Du wurdest von '.$user['nickname'].' aus deinem Clan geworfen. Du wirst dir wohl einen neuen suchen müssen!'); - } else if(getClanMembersCount($user['clan']) == 0) { - mysql_query('DELETE FROM clan WHERE id =' .$user['clan']); - } - } - } else{ - echo displayErrorMessage(NULL, 'Du kannst den Member nicht feuern!', displayHistoryBackLink()); - } -} - function deleteClan($user){ $row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user['clan'])); if($user['id'] == $row['leader']){ @@ -561,9 +606,9 @@ if($action !== NULL) { // this is done to not require to reprogramm the whole st $displayMore = false; } if($errorMsg !== NULL) { - echo displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink()); - $displayMore = false; - } + echo displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink()); + $displayMore = false; + } break; case 'fire': diff --git a/ag/include/clan.inc.php b/ag/include/clan.inc.php index c6dfd9c..2f1599a 100644 --- a/ag/include/clan.inc.php +++ b/ag/include/clan.inc.php @@ -11,7 +11,7 @@ $GLOBALS['clan_buffered_instances'] = array (); function getClan($clanid, $buffer = TRUE) { - if(!is_numeric($clanid)) { return NULL; } + if(!is_numeric($clanid) || $clanid === NULL) { return NULL; } if(buffer && isset($GLOBALS['clan_buffered_instances'][$clanid])) { return $GLOBALS['clan_buffered_instances'][$clanid]; // okay, we already buffered the clan :) } @@ -73,7 +73,7 @@ function getMaximumMembers($clanid) { // be invited :) $clan = getClan($clanid); - if($clan === NULL){ return 0; } + if($clan === NULL){ return 0; } $base = 12; $members_by_level = getClanMemberBonusByLevel($clan['level']); $malus = 0; @@ -160,149 +160,28 @@ function inviteUser(array $user, $userid, array $clan = NULL){ } } -define("DAVY_BACK_FIGHT", 1); -define("SURVIVAL", 2); - -/** - * - * Challenge an other clan (Davy Back Fight) - * @param array $user the user array - * @param int $clanid the id of the clan to challenge - * @param int $validTime the amount of hours that the challenge is valid - */ -function challengeClan(array $user, $clanid, $type = DAVY_BACK_FIGHT, $anzahl, $validTime = 24) { - $qry = mysql_query('SELECT * FROM clan WHERE id = ' . $user['clan']); - $clan = mysql_fetch_assoc($qry); - - $oclan = mysql_fetch_assoc(mysql_query('SELECT * FROM clan WHERE id = ' . $clanid)); - - if(!$clan || !$oclan) { - return 'Entweder bist du nicht in einem Clan oder der andere Clan existiert nicht mehr!!'; - } - - if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ - return 'Nur der Leader, bzw. der Co-Leader kann andere Clans herausfordern!!'; - } - - - // Fordere heraus! - mysql_query('INSERT INTO clan_challenge(clan_requester, clan_challenged, type, anzahl, valid, accepted) VALUES('.$user['clan'].', '.$clanid.','.$type.' , TIMESTAMPADD(HOUR, CURRENT_TIMESTAMP, 4), '.$anzahl.', false)'); - - if(mysql_affected_rows() > 0) { - if(is_numeric($oclan['leader'])) { - sendMessage($user['nickname'], $oclan['leader'], 'Davy Back Fight Herausforderung', 'Der Clan '.$oclan['clanname'].' hat euch zu einem Davy Back Fight herausgefordert! Über "Mein Clan" könnt ihr die Herausforderung annehmen!'); - } - if(is_numeric($oclan['co_leader']) && $oclan['leader'] != $oclan['co_leader']) { - sendMessage($user['nickname'], $oclan['co_leader'], 'Davy Back Fight Herausforderung', 'Der Clan '.$oclan['clanname'].' hat euch zu einem Davy Back Fight herausgefordert! Über "Mein Clan" könnt ihr die Herausforderung annehmen!'); - } - } else { - return 'Konnte den anderen Clan nicht herausfordern!!'; - } - - return NULL; -} - - -function acceptChallenge($challengeid, array $user) { - $qry = mysql_query('Select * from clan where id = ' . $user['clan']); - $clan = mysql_fetch_assoc($qry); - - if(!$clan) { - return 'Du bist in keinem Clan!!'; - } - - if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ - return 'Nur der Leader, bzw. der Co-Leader kann herausforderungen anderer Clans annehmen!!'; - } - - $clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge WHERE clan_challenge_id = ' .$challengeid)); - - if($user['clan'] != $clan_challenge['clan_challenged']) { - return 'Du kannst die Herausforderung nicht annehmen, da du nicht im herausgeforderten Clan bist!'; - } - - // The user must be in the challanged clan - $oclan = mysql_fetch_assoc('SELECT * FROM clan WHERE id = '.$clan_challenge['clan_requester']); - - mysql_query('UPDATE clan_challenge SET accepted = TRUE WHERE clan_challenge_id = ' .$challengeid); - - - if(mysql_affected_rows() > 0) { - if(is_numeric($oclan['leader'])) { - sendMessage($user['nickname'], $oclan['leader'], 'Davy Back Fight', 'Der Clan '.$oclan['clanname'].' hat eure Herausforderungen zu einem Davy Back Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!'); - } - if(is_numeric($oclan['co_leader']) && $oclan['leader'] != $oclan['co_leader']) { - sendMessage($user['nickname'], $oclan['co_leader'], 'Davy Back Fight', 'Der Clan '.$oclan['clanname'].' hat eure Herausforderungen zu einem Davy Back Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!'); - } - } else { - return 'Du kannst die Herausforderungen nicht annehmen. Wurde die Herausforderung schon angenommen?'; - } - - return NULL; -} - - -function getOpenChallengesByUser(array $user) { - $qry = mysql_query('SELECT * FROM clan_challenge WHERE accepted = FALSE AND clan_requester = '.$user['clan'].' OR clan_challenged = '.$user['clan']); - $array = array(); - while($row = mysql_fetch_assoc($qry)) { - $array[] = $row; - } - return $array; -} - -function getOpenChallengesByClanId($clanid) { - $qry = mysql_query('SELECT * FROM clan_challenge WHERE accepted = FALSE AND clan_requester = '.$clanid.' OR clan_challenged = '.$clanid); - $array = array(); - while($row = mysql_fetch_assoc($qry)) { - $array[] = $row; - } - return $array; -} - - -/** - * This function lets a user take part in the clan fight! The clan fight will be calculated if all chars have been registered. - * A challenge can only be joined if there is no other char of the same user joined. If the given slot is free and the challangeid is valid. - * @param int $challengeid the id of the challenge - * @param array $user the user array - * @param int $charid the id of the char that should join - */ -function joinChallenge($challengeid, array $user, $charid, $slot ) { - $qry = mysql_query('Select * from clan where id = ' . $user['clan']); - $clan = mysql_fetch_assoc($qry); - - if(!$clan) { - return 'Du bist in keinem Clan!!'; - } - - $clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge WHERE clan_challenge_id = ' .$challengeid)); - - if($user['clan'] != $clan_challenge['clan_challenged'] && $user['clan'] != $clan_challenge['clan_requester'] ) { - return 'Du kannst an der Herausforderung nicht teilnehmen, da du nicht in einem teilnehmenden Clan bist!'; - } - - $char = getChar($charid); - - if($user['id'] != $char['besitzer']) { - return 'Du kannst den Char nicht an der Herausforderung teilnehmen lassen, da er dir nicht gehört!'; - } - - // query all clan_challange_participants to see if the user already has a char in competition! - - -} - -/** - * This function does the calculation of the clan fight. - * @param int $challengeid the id of the challenge - */ -function calculateChallenge($challengeid) { - +function fireMember($user, $member){ + $row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user['clan'])); + if($member != $row['leader'] && $member != $row['co_leader'] && ($user['id'] == $row['leader'] || $user['id'] == $row['co_leader'] || $member == $user['id'])){ + $sql = 'Update user set clan = NULL where id = '.$member.' AND clan = '.$user['clan']; + // echo $sql.'
'; + mysql_query($sql); + if(mysql_affected_rows() > 0){ // Soll nur ausgeführt werden, wenn member wirklich gekickt wurde!! + $sql = 'Update chars set clan_train = NULL where besitzer = '.$member; + mysql_query($sql); + if($user['id'] != $member) { + sendMessage($user['nickname'], $member, 'Clan rauswurf!', 'Du wurdest von '.$user['nickname'].' aus deinem Clan geworfen. Du wirst dir wohl einen neuen suchen müssen!'); + } else if(getClanMembersCount($user['clan']) == 0) { + mysql_query('DELETE FROM clan WHERE id =' .$user['clan']); + } + + // delete the participation in open clan fights! Thats tricky because the user itself is not stored in the database!! + mysql_query('DELETE FROM clan_challenge_participants WHERE clan_challenge_id in (SELECT clan_challenge_id FROM clan_challenge where calculated = FALSE) and char_id IN (Select id FROM chars where besitzer = '.$user['id'].')'); + } + } else{ + echo displayErrorMessage(NULL, 'Du kannst den Member nicht feuern!', displayHistoryBackLink()); + } } - - - ?> diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php new file mode 100644 index 0000000..47eb06a --- /dev/null +++ b/ag/include/clan_fights.inc.php @@ -0,0 +1,502 @@ + MAX_OPEN_REQUESTS) { + semaphoreDown($ressource_clan1); // free the previously reserved semaphore! + semaphoreDown($ressource_clan2); // free the previously reserved semaphore! + return 'Dein Clan hat schon die maximale Anzahl von Herausforderungen offen!'; + } + + if($clan_challenges_oth_clan > MAX_OPEN_REQUESTS) { + semaphoreDown($ressource_clan1); // free the previously reserved semaphore! + semaphoreDown($ressource_clan2); // free the previously reserved semaphore! + 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 + + // Fordere heraus! + mysql_query('INSERT INTO clan_challenge(clan_requester, clan_challenged, type, anzahl, valid, accepted) VALUES('.$user['clan'].', '.$clanid.','.$type.' , TIMESTAMPADD(HOUR, CURRENT_TIMESTAMP, 4), '.$anzahl.', false)'); + + if(mysql_affected_rows() > 0) { + if(is_numeric($oclan['leader'])) { + sendMessage($user['nickname'], $oclan['leader'], 'Clan-Fight Herausforderung', 'Der Clan '.$oclan['clanname'].' hat euch zu einem Clan-Fight herausgefordert! Über "Mein Clan" könnt ihr die Herausforderung annehmen!'); + } + if(is_numeric($oclan['co_leader']) && $oclan['leader'] != $oclan['co_leader']) { + sendMessage($user['nickname'], $oclan['co_leader'], 'Clan-Fight Herausforderung', 'Der Clan '.$oclan['clanname'].' hat euch zu einem Clan-Fight herausgefordert! Über "Mein Clan" könnt ihr die Herausforderung annehmen!'); + } + } else { + semaphoreDown($ressource_clan1); // free the previously reserved semaphore! + semaphoreDown($ressource_clan2); // free the previously reserved semaphore! + return 'Konnte den anderen Clan nicht herausfordern!!'; + } + + semaphoreDown($ressource_clan1); // free the previously reserved semaphore! + semaphoreDown($ressource_clan2); // free the previously reserved semaphore! + return NULL; +} + +/** + * With this function the actual user accepts the challenge request from another clan! + * @param int $clan_challenge_id + * @param array $user + */ +function acceptChallengeRequest($clan_challenge_id, array $user) { + $clan = getClan($user['clan']); + + if(!$clan) { + return 'Du bist in keinem Clan!!'; + } + + if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ + 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)); + + if($user['clan'] != $clan_challenge['clan_challenged']) { + return 'Du kannst die Herausforderung nicht annehmen, da du nicht im herausgeforderten Clan bist!'; + } else if ($clan_challenge['active'] != 1) { + return 'Du kannst die Herausforderung nicht annehmen, da diese schon angenommen wurde!'; + } + + if(isClanLocked($clan_challenge['clan_challenged']) || isClanLocked($clan_challenge['clan_requester'])) { + // 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)!'; + } + + $oclan = getClan($clan_challenge['clan_requester']); + + mysql_query('UPDATE clan_challenge_requests SET accepted = TRUE WHERE clan_challenge_id = ' .$clan_challenge_id); + + if(mysql_affected_rows() > 0) { + 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!'); + } + if(is_numeric($oclan['co_leader']) && $oclan['leader'] != $oclan['co_leader']) { + sendMessage($user['nickname'], $oclan['co_leader'], 'Clan-Fight', 'Der Clan '.$oclan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!'); + } + + $finished = FALSE; + $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].')'); + $finished = mysql_affected_rows(); + $id = $row[0]; + } + + // insert the participants :) + mysql_query('INSERT INTO clan_challenge_clans(clan_challenge_id, clan_id, elo) values('.$id.', '.$clan['id'].', '.$clan['elo'].')'); + mysql_query('INSERT INTO clan_challenge_clans(clan_challenge_id, clan_id, elo) values('.$id.', '.$oclan['id'].', '.$clan['elo'].')'); + + // we have everything we need for this challenge to be opened :) + + } else { + return 'Du kannst die Herausforderungen nicht annehmen. Wurde die Herausforderung schon angenommen?'; + } + + return NULL; +} + +/** + * With this function the actual user from the challenged clan denies the challenge request! + * @param int $clan_challenge_id + * @param array $user + */ +function denyChallengeRequest($clan_challenge_id, array $user) { + $clan = getClan($user['clan']); + + if(!$clan) { + return 'Du bist in keinem Clan!!'; + } + + if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ + 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)); + + if($user['clan'] != $clan_challenge['clan_challenged']) { + return 'Du kannst die Herausforderung nicht ablehnen, da du nicht im herausgeforderten 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_challenge_id = ' .$clan_challenge_id); + return NULL; +} + +/** + * Reads out the given date from the table "clan_challenge" + * @param int $challenge_id + * @param bool $buffer + */ +function getChallenge($challenge_id, $buffer = TRUE) { + if(buffer && isset($GLOBALS['clan_challenge_buffered_instances'][$challenge_id])) { + return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :) + } +} + +function getOpenChallengeRequests($clanid) { + $array = array(); + if(isClanLocked($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; + $qry = mysql_query($sql); + while($row = mysql_fetch_assoc($qry)) { + $array[] = $row; + } + return $array; +} + +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; + $row = mysql_fetch_row(mysql_query($sql)); + return $row[0]; +} + +// 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'; + $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; + $qry = mysql_query($sql); + while($row = mysql_fetch_row($qry)) { + $array[] = $row[0]; + } + // return the ids + return $array; +} + +function getParticipatingCharIDs($clan_challenge_id, $clan_id) { + $array = array(); + $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']; + } + // 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 ORDER BY cc.date DESC ' . $addition; + $qry = mysql_query($sql); + while($row = mysql_fetch_row($qry)) { + $array[] = $row[0]; + } + // return the ids + return $array; +} + +// 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 + $sql = 'SELECT *, locked_until < now(), (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; + $lock = mysql_fetch_assoc(mysql_query($sql)); + if($lock['lock'] == 0) { // don't matter if it is 0 or NULL + // we do not have data in the clan locked table so we are not locked :D + // or + // we do have data but it seems we are not locked anymore ;) + + // are we still having enough members?? + if($lock['members'] >= MIN_MEMBERS) { + // key so every thing seems to be fine :) + return false; // the only case we may return false! + } else if($lock['lock'] === NULL){ // we need to insert a row + // INSERT + mysql_query('INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP)'); + } else { // we have to update the actual row + // UPDATE + mysql_query('UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid); + } + } + + return true; +} + + +/** + * This function lets a user take part in the clan fight! The clan fight will be calculated if all chars have been registered. + * A challenge can only be joined if there is no other char of the same user joined. If the given slot is free and the challangeid is valid. + * @param int $clan_challenge_id the id of the challenge + * @param array $user the user array + * @param int $charid the id of the char that should join + */ +function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) { + $clan = getClan($user['clan']); + $char = getChar($charid); + + if(!$clan) { + return 'Du bist in keinem Clan!!'; + } + + if($char['besitzer'] != $user['id']) { + return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er dir nicht gehört!'; + } + + $clan_challenge = getChallenge($clan_challenge_id); + + $clan_ids = getParticipatingClanIDs($clan_challenge['clan_challenge_id']); + + if(array_search($user['clan'], $clan_ids) === FALSE) { + // the clan does not match a participant!! + return 'Du bist in keinem Clan der an dieser Challenge teilnimmt!'; + } + + // block the user actions so we can ensure he won't register multiple of its chars here! + $resource = '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!'; + } + + 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)!'; + } + } + + // 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 ' . + 'WHERE ccp.clan_challenge_id = cc.clan_challenge_id AND clan_id = '.$clan_ids[0]. + ') = ' . $clan_challenge['anzahl_chars'] . + ' AND ' . + '(SELECT count(*) FROM clan_challenge_participants AS ccp ' . + 'WHERE ccp.clan_challenge_id = cc.clan_challenge_id AND clan_id = '.$clan_ids[1]. + ') = ' . $clan_challenge['anzahl_chars']; + + mysql_query($sql); + $rows = mysql_affected_rows(); + semaphoreDown($ressource); + + if($rows > 0) { + // okay we now have a complete competition and the challenge is closed :) + calculateChallenge($clan_challenge_id); + } + +} + +/** + * + * Lets the user to remove his char from the challenge + * @param integer $clan_challenge_id + * @param array $user + * @param integer $charid + */ +function leaveChallenge($clan_challenge_id, array $user, $charid) { + $clan = getClan($user['clan']); + $char = getChar($charid); + + if(!$clan) { + return 'Du bist in keinem Clan!!'; + } + + if($char['besitzer'] != $user['id']) { + return 'Du kannst den Char nicht vom Kampf zurückziehen, da er dir nicht gehört!'; + } + + // 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.'; + } + + return NULL; +} + +/** + * This function does the calculation of the clan fight. + * @param int $clan_challenge_id the id of the challenge + */ +function calculateChallenge($clan_challenge_id) { + $challenge = getChallenge($clan_challenge_id); + + // okay the calculated flag is already set so readout all the required data for further processing! + $clan_ids = getParticipatingClanIDs($clan_challenge_id); + $clan_chars = array(); + + foreach ($clan_ids as $clan_id) { + $clan_char_ids = getParticipatingCharIDs($clan_challenge_id, $clan_id); + foreach ($clan_char_ids as $slot => $char_id) { + $clan_chars[$clan_id][$slot] = getChar($char_id); + } + } + + // okay now determine the type of fight + switch($challenge['type']) { + case DAVY_BACK_FIGHT: + return calculateDavyBackClanFight($clan_ids, $clan_chars); + break; + case SURVIVAL: + return calculateSurvivalClanFight($clan_ids, $clan_chars); + break; + default: + // cannot create anything -.- + return 'Der Clanfight Typ "'.$challenge['type'].'" wird nicht unterstützt, bitte melde dich beim Administrator!' ; + } + + return NULL; +} + +function calculateDavyBackClanFight(array $clan_ids, array $clan_char_array) { + // okay, davy back fights are 1 vs. 1 and the winner is the one that has won the most fights. + if(count($clan_char_array) != 2) { + return 'Davy Back Fights können nur zwischen 2 Clans ausgetragen werden und nicht von ' . count($clan_char_array); + } + if(count($clan_char_array[$clan_ids[0]]) != count($clan_char_array[$clan_ids[1]])) { + return 'Davy Back Fights können nur zwischen Clans mit der selben Anzahl von Chars ausgetragen werden!'; + } + $count_chars = count($clan_char_array[$clan_ids[0]]); + // okay ... now do the calculation! + for($runde = 0; $runde<$count_chars;$runde++) { + $char_clan_1 = $clan_char_array[$clan_ids[0]][$runde]; + $char_clan_2 = $clan_char_array[$clan_ids[1]][$runde]; + + // we do not need to know right now who won the battle! This is required in the post processing (cronjob)! + battle($char_clan_1, $char_clan_2, ATTACK_SET_DAVY_BACK_FIGHT); + } +} + +function calculateSurvivalClanFight(array $clan_ids, array $clan_char_array) { + // okay, survival fights are 1 vs. 1 and the winner is the one that has the last man standing. + if(count($clan_char_array) != 2) { + return 'Survival Fights können nur zwischen 2 Clans ausgetragen werden und nicht von ' . count($clan_char_array); + } + if(count($clan_char_array[$clan_ids[0]]) != count($clan_char_array[$clan_ids[1]])) { + return 'Survival Fights können nur zwischen Clans mit der selben Anzahl von Chars ausgetragen werden!'; + } + $count_chars = count($clan_char_array[$clan_ids[0]]); + + $counter_clan_1 = 0; + $counter_clan_2 = 0; + $char_clan_1 = $clan_char_array[$clan_ids[0]][0]; + $char_clan_2 = $clan_char_array[$clan_ids[1]][0]; + + // As long as char 1 and char 2 are set + while($char_clan_1 != NULL && $char_clan_2 != NULL) { + $sieger = battle($char_clan_1, $char_clan_2, ATTACK_SET_SURVIVAL); + if($sieger['id'] != $char_clan_1['id']) { + // the loser is of clan 1 + $char_clan_1 = $clan_char_array[$clan_ids[0]][++$counter_clan_1]; + $char_clan_2 = $sieger; // the new array contains the adjusted health parameter + } else { + // the loser is of clan 2 + $char_clan_2 = $clan_char_array[$clan_ids[1]][++$counter_clan_2]; + $char_clan_1 = $sieger; // the new array contains the adjusted health parameter + } + } + +} + +/** + * This function calculates the battle between two chars. + * @param array $char1 + * @param array $char2 + * @param int $attack_set the attack set that should be used! + * @return the winners array + */ +function battle(array $char1, array $char2, $attack_set) { + // TODO: Implement the single fight ... +} + + +?> diff --git a/ag/include/clanfights.inc.php b/ag/include/clanfights.inc.php deleted file mode 100644 index 919f977..0000000 --- a/ag/include/clanfights.inc.php +++ /dev/null @@ -1,749 +0,0 @@ -'.$row['nickname'].''; - } - return $options; -} - -function getMemberCharacters($userid) { - $qry = mysql_query('SELECT * FROM chars where besitzer = '.$userid); - $options = ''; - while ($row = mysql_fetch_assoc($qry)) { - $options .= ''; - } - return $options; -} - -function getClans($clanid) { - $qry= mysql_query('SELECT clanname, id FROM clan WHERE id != '.$clanid.' ORDER BY clanname ASC'); - #$qry= mysql_query('SELECT clanname, id FROM clan ORDER BY clanname ASC'); - $options = ''; - while ($row = mysql_fetch_assoc($qry)) { - $options .= ''; - } - return $options; -} - -function displayClanFights($userid) { - $clanid = getClanOfUser($userid); - $claninfos= getClanInformation($clanid); - ?> -
',$member); ?>
EingeladenEingeladen: ', $invited); ?>
Herausforderungen:', $openChallengeRequestsDisplay); ?>
Level:
Erfahrung: Erfahrung: +
ELO-Wertung:
ELO-Wertung:
Homepage:
 
 
@@ -236,7 +266,23 @@ function displayClanProfileEditable($clan, $userid){ $invited = array(); while($row = mysql_fetch_assoc($inv_qry)) { - $invited[] = displayUserLinkByID($row['userid']) . ' (noch ' . $row['till'] . 'h gültig, zurückziehen)'; + $invited[] = generateUserLinkByID($row['userid']) . ' (noch ' . $row['till'] . 'h gültig, zurückziehen)'; + } + + if(count($invited) == 0) { + $invited[] = 'Keine'; + } + + + $openChallengeRequests = getOpenChallengeRequests($clan['id']); + // okay now we split into challenges we have done and we have received + foreach($openChallengeRequests as $request) { + if($request['clan_requester'] != $clan['id']) { + $openChallengeRequestsDisplay[] = displayClanLink($request['clan_requester']) . ' (annehmen)'; + } else { + $openChallengeRequestsDisplay[] = displayClanLink($request['clan_challenged']) . ' (zurückziehen)'; + } + } @@ -274,25 +320,42 @@ function displayClanProfileEditable($clan, $userid){
Member ():',$member); ?>
Member ():',$member); ?>
EingeladenEingeladen: ', $invited); ?>
Herausforderungen:', $openChallengeRequestsDisplay); ?>
Level:
Erfahrung:
ELO-Wertung:
Erfahrung: +
ELO-Wertung:
Homepage:(edit) @@ -316,7 +379,9 @@ function displayClanProfileEditable($clan, $userid){ href="javascript:if(confirm('Wirklich löschen?')==true) window.location.href='index.php?as=clan/clan_info&action=kill'">Clan löschen
 
 
@@ -346,7 +411,7 @@ function displayClanProfileEditable($clan, $userid){ function displayClanProfile($clanid, $user){ $clan = getClan($clanid, FALSE); - if(!$clan) { + if(!$clan) { echo displayErrorMessage(NULL, 'Es gibt den Clan mit der ID ' .$clanid.' nicht oder nicht mehr!', displayHistoryBackLink()); return; } @@ -404,10 +469,10 @@ function setProfile($what, $value1, $value2, $clanid, $rootlvl){ else if($rootlvl == 1) { $value1 = $clan['leader']; } if($value2 == 0){$value2 = 'null';} // okay, are we allowed to change?? If we have max members, it is not allowed to remove the co_leader - + $clan = getClan($clanid); - $members = getClanMembersCount($clanid); - $members_max = getMaximumMembers($clan['id']); + $members = getClanMembersCount($clanid); + $members_max = getMaximumMembers($clan['id']); if($members_max == $members && $clan['leader'] != $clan['co_leader'] && ($value1 == $value2 || $value2 == 'null')) { // Okay, actually there are the max amount of users in the clan @@ -432,9 +497,9 @@ function setProfile($what, $value1, $value2, $clanid, $rootlvl){ function displayEdit($what, $clanid, $rootlvl){ if($rootlvl < 1) { - $content = '
Du hast keine Rechte um diese Aktion auszuführen!
Du hast keine Rechte um diese Aktion auszuführen!
- - - - - - - - - - - - -
Clan Kämpfe -
- -
Dein Clan hat bereits 3 Herausforderungen. Mehr sind nicht möglich. -
Clan herausfordern -
- - - - - - - - - - - -
Kampftyp: - -
- -
- - -
- - - - - - - - - - -
Anzahl Kämpfer: - -
- -
-
- -
- '; - } elseif ($type == 'accept') { - echo ''; - echo ''; - } - ?> - - - - - - - - - - - - - - -
User - -
- -
-
-Es sind nicht genug Clanmitglieder ausgewählt worden für einen Clankampf!

'; - $errmsg .= '

Leider nur '.$anzahl_gewaehlt.' von '.count($wahluser).' Clanmitglieder ausgewählt!

'; - break; - } - } - - foreach ($count_member_array as $key => $value) { - if ($value > 1 AND $key != -1) { - $errmsg .= '

Du hast leider ein Clanmitglied mehrfach ausgewählt!

'; - break; - } - } - - - $clanid = getClanOfUser($userid); - $optionen = getCharacterOptions($clanid); - - if (empty($errmsg)) { - ?> -
- '; - echo ''; - echo ''; - } elseif ($type == 'accept') { - echo ''; - echo ''; - } - ?> - - - - - - - - - - -
User - -
- -
-
-
'; - echo $errmsg1; - echo $errmsg; - - } -} - -function displaySelectClanToFight($userid,$numberoffighter,$clanfighttyp) { - $clanid = getClanOfUser($userid); - /*for ($i=1;$i'; - echo '

Folgende Charaktere sind nicht verfügbar:

'; - echo ''; - exit; - }*/ - ?> -
- - > - - - - - - - - - - - - - - - - - - - -
Clan: - -
Datum: - -
Zeitpunkt: - -
- -
-
- Willst du den Clankamp wirklich ablehnen?

'; - echo '

Ja | Nein

'; - } else { - $clankampf_loeschen= mysql_query('DELETE FROM clan_fight_list WHERE id='.$clanfightid.' LIMIT 1'); - echo '

Clankampf erfolgreich abgelehnt!

'; - echo '

zurück zur Übersicht

'; - } -} - -function checkIfChallengeTimedOut($userid) { - $clanid= getClanOfUser($userid); - $qry = mysql_query('SELECT id, zeitpunkt, status FROM clan_fight_list WHERE clan='.$clanid.' OR gclan='.$clanid); - while($row = mysql_fetch_assoc($qry)){ - if ($row['zeitpunkt'] <= time() AND $row['status'] == 0) { - $status_updaten= mysql_query('UPDATE clan_fight_list SET status=3 WHERE id='.$row['id'].' LIMIT 1'); - } - } -} - -function termineBereitsBelegt($clanid,$gclanid,$timestamp) { - global $errmsg; - $clan_qry= mysql_num_rows(mysql_query('SELECT id FROM clan_fight_list WHERE clan = '.$clanid.' AND status != 3 AND zeitpunkt = '.$timestamp)); - $gclan_qry= mysql_num_rows(mysql_query('SELECT id FROM clan_fight_list WHERE gclan = '.$gclanid.' AND status != 3 AND zeitpunkt = '.$timestamp)); - if ($clan_qry AND $gclan_qry) { - $errmsg= 'Dein Clan und der herausgeforderte Clan haben zu diesem Zeitpunkt bereits einen Clankampf!'; - $err= 1; - } elseif ($clan_qry) { - $errmsg= 'Dein Clan hat zu diesem Zeitpunkt bereits einen Clankampf!'; - $err= 1; - } elseif ($gclan_qry) { - $errmsg= 'Der herausgeforderte Clan hat zu diesem Zeitpunkt bereits einen Clankampf!'; - $err= 1; - } else { - $err= 0; - } - return $err; -} - -function clanfightFromOwnClan($clanfightid,$userid='') { - $clanid= getClanOfUser($userid); - $clanfightcheck= mysql_fetch_assoc(mysql_query('SELECT clan from clan_fight_list WHERE id='.$clanfightid.' LIMIT 1')); - if ($clanfightcheck['clan'] == $clanid) { - return 1; - } else { - global $errmsg; - $errmsg= '

Dieser Clankampf ist nicht von deinem Clan erstellt und kann somit nicht zurückgezogen werden!

'; - return 0; - } -} - -function clanfightToOwnClan($clanfightid,$userid='') { - $clanid= getClanOfUser($userid); - $clanfightcheck= mysql_fetch_assoc(mysql_query('SELECT gclan from clan_fight_list WHERE id='.$clanfightid.' LIMIT 1')); - if ($clanfightcheck['gclan'] == $clanid) { - return 1; - } else { - global $errmsg; - $errmsg= '

Die Herausforderung von diesem Clankampf ist nicht an deinem Clan gerichtet!

'; - return 0; - } -} - -function checkClanfight($clanfightid,$type='') { - if (is_numeric($clanfightid)) { - $clanfightcheck= mysql_fetch_assoc(mysql_query('SELECT status FROM clan_fight_list WHERE id='.$clanfightid.' LIMIT 1')); - if ($clanfightcheck) { - if ($clanfightcheck['status'] == 2 AND ($type == 'look' OR $type == 'look_survival')) { - return 1; - } elseif ($clanfightcheck['status'] != 0) { - global $errmsg; - $errmsg= '

Der Clankampf wurde bereits angenommen / abgelehnt!

'; - return 0; - } else { - return 1; - } - } else { - global $errmsg; - $errmsg= '

Diesen Clankampf gibt es nicht!

'; - return 0; - } - } else { - global $errmsg; - $errmsg= '

Die ID des Clankampfes ist kein numerischer Wert!

'; - return 0; - } -} - -function getNumberOfFightersByClanfightID($clanfightid) { - $clankampf_informationen= mysql_fetch_assoc(mysql_query('SELECT numberoffighter FROM clan_fight_list WHERE id='.$clanfightid.' LIMIT 1')); - return $clankampf_informationen['numberoffighter']; -} - -function acceptClanfight($clanfightid,$chars) { - $chars= implode(",",$chars); - $status_pruefen= mysql_fetch_assoc(mysql_query('SELECT status FROM clan_fight_list WHERE id='.$clanfightid.' LIMIT 1')); - if ($status_pruefen['status'] == 0) { - $datensatz_updaten= mysql_query('UPDATE clan_fight_list SET gfighter="'.$chars.'", status=1 WHERE id='.$clanfightid) or die(mysql_error()); - echo '

Der Clankampf wurde erfolgreich angenommen!

'; - echo 'zurück zur Übersicht'; - } else { - echo '

Dieser Clankampf kann nichtmehr angenommen werden. Er wurde bereits angenommen!

'; - echo 'zurück zur Übersicht'; - } -} - -function deleteClanFight($clanfightid) { - $clankampf_loeschen= mysql_query('DELETE FROM clan_fight_list WHERE id='.$clanfightid.' LIMIT 1'); - echo '

Herausforderung erfolgreich zurückgezogen!

'; - echo 'zurück zur Übersicht'; -} - -function getClanOptions(){ - $sql = 'SELECT clanname, id FROM clan order by clanname'; - $qry = mysql_query($sql); - $options = ''; - while($row = mysql_fetch_assoc($qry)){ - $options .= ''; - } - return $options; -} - - -// Diese Funktion liefert alle Karaktaere des Clans mit der id $clanid. -// Sortiert werden die Eintraege nach Trainer und Charname -function getCharacterOptions($clanid){ - $sql = 'SELECT c.name, c.id, u.nickname FROM chars c LEFT JOIN user u ON (u.id=c.besitzer) WHERE u.clan='.$clanid.' ORDER BY u.nickname, c.name ASC'; - $qry = mysql_query($sql); - $options = ''; - while($row = mysql_fetch_assoc($qry)){ - $options .= ''; - } - return $options; -} - -function getActualClanChallengeInformation($clanid,$userid){ - $string = ''; - #$kaempfe = mysql_query('SELECT u.aktiv, u.besitzer, c.clanname, c2.clanname as clanname2, u.tick, u.id FROM clan_k_list u LEFT JOIN clan c ON(u.besitzer=c.id) LEFT JOIN clan c2 ON(u.an = c2.id )WHERE u.an='.$clanid.' OR u.besitzer='.$clanid.' ORDER BY tick ASC'); - $kaempfe_query= mysql_query('SELECT * FROM clan_fight_list WHERE (clan='.$clanid.' OR gclan='.$clanid.') AND status=0 ORDER BY zeitpunkt DESC'); - $informationen_eigener_clan= getClanInformation($clanid); - while($row = mysql_fetch_assoc($kaempfe_query)) { - if($row['clan'] == $clanid) { - $claninformationen= getClanInformation($row['gclan']); - if ($informationen_eigener_clan['leader'] == $userid OR $informationen_eigener_clan['co_leader'] == $userid) { - $string .= ''; - } else { - $string .= ''; - } - } else { - $claninformationen= getClanInformation($row['clan']); - if ($informationen_eigener_clan['leader'] == $userid OR $informationen_eigener_clan['co_leader'] == $userid) { - $string .= ''; - } else { - $string .= ''; - } - } - } - $string .= '
Herausforderung an "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).' (zurückziehen)
Herausforderung an "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).' (zurückziehen)
Herausforderung von "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'(annehmen | ablehnen)
Herausforderung von "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'(annehmen | ablehnen)
'; - return $string; -} - -function getActualClanFightInformation($clanid,$userid){ - $string = ''; - #$kaempfe = mysql_query('SELECT u.aktiv, u.besitzer, c.clanname, c2.clanname as clanname2, u.tick, u.id FROM clan_k_list u LEFT JOIN clan c ON(u.besitzer=c.id) LEFT JOIN clan c2 ON(u.an = c2.id )WHERE u.an='.$clanid.' OR u.besitzer='.$clanid.' ORDER BY tick ASC'); - $kaempfe_query= mysql_query('SELECT * FROM clan_fight_list WHERE clan='.$clanid.' OR gclan='.$clanid.' ORDER BY zeitpunkt DESC'); - $informationen_eigener_clan= getClanInformation($clanid); - while($row = mysql_fetch_assoc($kaempfe_query)) { - if($row['clan'] == $clanid) { - $claninformationen= getClanInformation($row['gclan']); - if ($row['status'] == 1) { - $string .= ''; - } elseif ($row['status'] == 2) { - $string .= ''; - } - } else { - $claninformationen= getClanInformation($row['clan']); - if ($row['status'] == 1) { - $string .= ''; - } elseif ($row['status'] == 2) { - $string .= ''; - } - } - } - $string .= '
Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'anschauen
Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'anschauen
Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'anschauen
Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'anschauen
'; - return $string; -} - -function getClanInformation($clanid){ - return mysql_fetch_array(mysql_query('SELECT clanname, leader, id, co_leader FROM clan WHERE id='.$clanid)); -} - -function getClanOfUser($userid){ - $sql = 'SELECT clan FROM user WHERE id = '.$userid; - $row = mysql_fetch_assoc(mysql_query($sql)); - return $row[clan]; -} - -function getStatusOfChar($charid) { - $sql= 'SELECT status FROM chars WHERE id='.$charid; - $row= mysql_fetch_assoc(mysql_query($sql)); - return $row[status]; -} - -function getNameOfChar($charid) { - $sql= 'SELECT status, name FROM chars WHERE id='.$charid; - $row= mysql_fetch_assoc(mysql_query($sql)); - return 'Char: '.$row[name].' - Status: '.$row[status]; -} - -function erstelleClanKampf($userid, $clanid, $time, $chars, $numberoffighter, $clanfighttyp) { - $chars= implode(",",$chars); - $own_clan = getClanOfUser($userid); - $claninfo = getClanInformation($own_clan); - $claninfo2 = getClanInformation($clanid); - - $anfrage_an_clan_bereits_vorhanden= mysql_num_rows(mysql_query('SELECT * FROM clan_fight_list WHERE clan='.$claninfo['id'].' AND gclan='.$claninfo2['id'].' AND zeitpunkt='.$time.' AND status=0')); - if ($anfrage_an_clan_bereits_vorhanden == 1) { - echo '
'; - echo '

Eine Anfrage für den '.date("d.m.Y H:i:s",$time).' an den Clan "'.$claninfo2['clanname'].'" wurde bereits gestellt!

'; - exit; - } - - $anfrage_von_clan_bereits_vorhanden= mysql_num_rows(mysql_query('SELECT * FROM clan_fight_list WHERE clan='.$claninfo2['id'].' AND gclan='.$claninfo['id'].' AND zeitpunkt='.$time.' AND status=0')); - if ($anfrage_von_clan_bereits_vorhanden == 1) { - echo '
'; - echo '

Eine Herausforderung für den '.date("d.m.Y H:i:s",$time).' vom Clan "'.$claninfo2['clanname'].'" wurde bereits an deinen Clan gestellt!

'; - exit; - } - - if($claninfo2 == null){ - return 'Der herauszufordernde Clan existiert nicht (mehr!'; - } - if($userid != $claninfo[leader] && $userid != $claninfo[co_leader]){ - return 'Nur der Leader, bzw. der Co-Leader kann Clan-kämpfe erstellen!'; - } - - $clankampfanfrage_eintragen = mysql_query("INSERT INTO clan_fight_list (id,clan,gclan,fighter,clanfighttyp,numberoffighter,zeitpunkt,status) VALUES ('','".$claninfo['id']."','".$claninfo2['id']."','".$chars."','".$clanfighttyp."','".$numberoffighter."','".$time."',0)"); - if(!$foo){ - return 'Error by sql: '.$sql.'
'; - } -} - - -function loescheKampf($userid, $kampfid){ - if(!is_numeric($userid) || !is_numeric($kampfid)){ - return 'Fehler beim Übertragen der Daten aufgetreten!'; - } - $clanid = getClanOfUser($userid); - $claninfo = getClanInformation($clanid); - if($userid != $claninfo[leader] && $userid != $claninfo[co_leader]){ - return 'Nur der Leader, bzw. der Co-Leader kann das!'; - } - $pruef = mysql_num_rows(mysql_query('SELECT id FROM clan_k_list WHERE (besitzer='.$clanid.' OR an='.$clanid.') AND id='.$kampfid)); - if($pruef == 1){ - if(mysql_query('DELETE FROM clan_k_list WHERE id = '.$kampfid)){ - return ''; - } else{ - return 'Fehler beim löschen in der Datenbank'; - } - } -} - -function nehmeKampfAn($userid, $kampfid, $chars){ - if(!is_numeric($userid) || !is_numeric($kampfid) || !is_array($chars)){ - return 'Fehler beim &Uml;bertragen der Daten augetreten!'; - } - - $clanid = getClanOfUser($userid); - $claninfo = getClanInformation($clanid); - if($userid != $claninfo[leader] && $userid != $claninfo[co_leader]){ - return 'Nur der Leader, bzw. der Co-Leader kann das!'; - } - - $error = checkCharArray($clanid, $chars); - if($error != ''){ - return $error; - } - $sql = 'Update clan_k_list SET aktiv = 1, gcharakter1 = '.$chars[1].', gcharakter2 = '.$chars[2].', gcharakter3 = '.$chars[3].', gcharakter4 = '.$chars[4].', gcharakter5 = '.$chars[5].', gcharakter6 = '.$chars[6].' WHERE aktiv = 0 and id = '.$kampfid.' and an='.$clanid; - if(mysql_query($sql)){ - return ''; - } else{ - return 'Fehler beim einfuegen in der Datenbank'; - } -} - -function checkIfClanFightsToExecute($userid) { - $clanid= getClanOfUser($userid); - $qry = mysql_query('SELECT id, zeitpunkt, status FROM clan_fight_list WHERE clan='.$clanid.' OR gclan='.$clanid); - while($row = mysql_fetch_assoc($qry)){ - if ($row['zeitpunkt'] <= time() AND $row['status'] == 1) { - $status_updaten= mysql_query('UPDATE clan_fight_list SET status=2 WHERE id='.$row['id'].' LIMIT 1'); - clanFightExecute($row['id']); - } - } -} - -function starteClanFight($chara_1, $chara_2, $clanfight_id, $runde, $kampf){ - global $sieger, $verlierer; - include 'kampf_clan.php'; -} - -function clanFightExecute($id) { - $pkt_a_satz= 0; - $pkt_b_satz= 0; - $pkt_runde_a= 0; - $pkt_runde_b= 0; - $rundenzaehler= 1; - $kampfzaehler= 1; - - $clanfight_daten= mysql_fetch_assoc(mysql_query('SELECT fighter, gfighter, numberoffighter FROM clan_fight_list WHERE id='.$id.' LIMIT 1')); - $fighter_a_array= explode(",",$clanfight_daten['fighter']); - $fighter_b_array= explode(",",$clanfight_daten['gfighter']); - - for ($x=1;;$x++) { - - /*if ($rundenzaehler == 7) { - break; - }*/ - - $fighter_a= mt_rand(0, count($fighter_a_array)-1); - $fighter_b= mt_rand(0, count($fighter_b_array)-1); - - $char_a= getChar2($fighter_a_array[$fighter_a]); - $char_b= getChar2($fighter_b_array[$fighter_b]); - - starteClanFight($char_a, $char_b, $id, $rundenzaehler, $kampfzaehler); - - $kampfzaehler++; - - if ($fighter_a_array[$fighter_a] == $sieger) { - $pkt_a_satz++; - } else { - $pkt_b_satz++; - } - - unset($fighter_a_array[$fighter_a]); - unset($fighter_b_array[$fighter_b]); - sort($fighter_a_array); - sort($fighter_b_array); - - #if ($pkt_a_satz == 3 OR $pkt_b_satz == 3) { - if ($pkt_a_satz + $pkt_b_satz == $clanfight_daten['numberoffighter']) { - if ($pkt_a_satz > $pkt_b_satz) { - $pkt_runde_a++; - } elseif ($pkt_a_satz < $pkt_b_satz) { - $pkt_runde_b++; - } - - $fighter_a_array= explode(",",$clanfight_daten['fighter']); - $fighter_b_array= explode(",",$clanfight_daten['gfighter']); - - $rundenzaehler++; - $kampfzaehler= 1; - $pkt_a_satz= 0; - $pkt_b_satz= 0; - if ($pkt_runde_a + $pkt_runde_b == 6) { - break; - } - } - } -} - -### old function ### -/*function getActualClanFightInformation($clanid,$userid){ - $string = ''; - #$kaempfe = mysql_query('SELECT u.aktiv, u.besitzer, c.clanname, c2.clanname as clanname2, u.tick, u.id FROM clan_k_list u LEFT JOIN clan c ON(u.besitzer=c.id) LEFT JOIN clan c2 ON(u.an = c2.id )WHERE u.an='.$clanid.' OR u.besitzer='.$clanid.' ORDER BY tick ASC'); - $kaempfe_query= mysql_query('SELECT * FROM clan_fight_list WHERE clan='.$clanid.' OR gclan='.$clanid.' ORDER BY zeitpunkt DESC'); - $informationen_eigener_clan= getClanInformation($clanid); - while($row = mysql_fetch_assoc($kaempfe_query)){ - if($row['clan'] == $clanid) { - $claninformationen= getClanInformation($row['gclan']); - if($row['status'] == 0){ - if ($informationen_eigener_clan['leader'] == $userid OR $informationen_eigener_clan['co_leader'] == $userid) { - $string .= ''; - } else { - $string .= ''; - } - } elseif ($row['status'] == 1) { - $string .= ''; - } elseif ($row['status'] == 2) { - $string .= ''; - } - } else{ - $claninformationen= getClanInformation($row['clan']); - if($row['status'] == 0){ - if ($informationen_eigener_clan['leader'] == $userid OR $informationen_eigener_clan['co_leader'] == $userid) { - $string .= ''; - } else { - $string .= ''; - } - } elseif ($row['status'] == 1) { - $string .= ''; - } elseif ($row['status'] == 2) { - $string .= ''; - } - } - } - $string .= '
Herausforderung an "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).' (zurückziehen)
Herausforderung an "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).' (zurückziehen)
Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'anschauen
Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'anschauen
Herausforderung von "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'(annehmen | ablehnen)
Herausforderung von "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'(annehmen | ablehnen)
Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'anschauen
Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'anschauen
'; - return $string; -}*/ - -?> diff --git a/db/animegame_svn.sql b/db/animegame_svn.sql index ecfc2b2..933c7f8 100644 --- a/db/animegame_svn.sql +++ b/db/animegame_svn.sql @@ -2249,7 +2249,7 @@ ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; DROP TABLE IF EXISTS `attackenset`; -CREATE TABLE `test_ag`.`attackenset` ( +CREATE TABLE `attackenset` ( `Char_ID` INT NOT NULL, `Attack_ID` INT NOT NULL, `Type` INT NOT NULL DEFAULT 1, @@ -2267,7 +2267,7 @@ CREATE TABLE `test_ag`.`attackenset` ( ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_unicode_ci; -CREATE TABLE `test_ag`.`attack_conditions` ( +CREATE TABLE `attack_conditions` ( `ID` INT NOT NULL AUTO_INCREMENT, `Name` VARCHAR(20) NOT NULL, `Formula` VARCHAR(255) NOT NULL, @@ -2276,6 +2276,110 @@ CREATE TABLE `test_ag`.`attack_conditions` ( ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_unicode_ci; + +-- +-- Definition of table `clan_challenge_clans` +-- + +DROP TABLE IF EXISTS `clan_challenge_clans`; +CREATE TABLE `clan_challenge_clans` ( + `clan_challenge_id` int(11) NOT NULL, + `clan_id` int(11) NOT NULL, + `elo` int(11) NOT NULL, + PRIMARY KEY (`clan_id`,`clan_challenge_id`), + KEY `clan_ch_clans_ch_id` (`clan_challenge_id`), + CONSTRAINT `clan_ch_clans_ch_id` FOREIGN KEY (`clan_challenge_id`) REFERENCES `clan_challenges` (`clan_challenge_id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `clan_challenge_clans` +-- + +/*!40000 ALTER TABLE `clan_challenge_clans` DISABLE KEYS */; +LOCK TABLES `clan_challenge_clans` WRITE; +INSERT INTO `clan_challenge_clans` VALUES (1,786,400); +UNLOCK TABLES; +/*!40000 ALTER TABLE `clan_challenge_clans` ENABLE KEYS */; + + +-- +-- Definition of table `clan_challenge_participants` +-- + +DROP TABLE IF EXISTS `clan_challenge_participants`; +CREATE TABLE `clan_challenge_participants` ( + `clan_challenge_id` int(11) NOT NULL, + `clan_id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `slot` int(11) NOT NULL, + PRIMARY KEY (`clan_challenge_id`,`clan_id`,`slot`), + KEY `clan_challenge_participants_clan_id` (`clan_id`), + KEY `clan_challenge_participants_char_id` (`char_id`), + CONSTRAINT `clan_challenge_participants_char_id` FOREIGN KEY (`char_id`) REFERENCES `chars` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `clan_challenge_participants_clan_id` FOREIGN KEY (`clan_challenge_id`, `clan_id`) REFERENCES `clan_challenge_clans` (`clan_challenge_id`, `clan_id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `clan_challenge_participants` +-- + +/*!40000 ALTER TABLE `clan_challenge_participants` DISABLE KEYS */; +LOCK TABLES `clan_challenge_participants` WRITE; +UNLOCK TABLES; +/*!40000 ALTER TABLE `clan_challenge_participants` ENABLE KEYS */; + + +-- +-- Definition of table `clan_challenge_requests` +-- + +DROP TABLE IF EXISTS `clan_challenge_requests`; +CREATE TABLE `clan_challenge_requests` ( + `clan_requester` int(11) NOT NULL, + `clan_challenged` int(11) NOT NULL, + `challenged_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `type` int(11) NOT NULL, + `anzahl_chars` int(11) NOT NULL DEFAULT '5', + `active` tinyint(1) NOT NULL DEFAULT '1', + PRIMARY KEY (`clan_requester`,`clan_challenged`,`challenged_time`), + KEY `fk_clan_challenge_requests_challenged` (`clan_challenged`), + CONSTRAINT `fk_clan_challenge_requests_challenged` FOREIGN KEY (`clan_challenged`) REFERENCES `clan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_clan_challenge_requests_requester` FOREIGN KEY (`clan_requester`) REFERENCES `clan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `clan_challenge_requests` +-- + +/*!40000 ALTER TABLE `clan_challenge_requests` DISABLE KEYS */; +LOCK TABLES `clan_challenge_requests` WRITE; +UNLOCK TABLES; +/*!40000 ALTER TABLE `clan_challenge_requests` ENABLE KEYS */; + + +-- +-- Definition of table `clan_challenges` +-- + +DROP TABLE IF EXISTS `clan_challenges`; +CREATE TABLE `clan_challenges` ( + `clan_challenge_id` int(11) NOT NULL AUTO_INCREMENT, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `calculated` tinyint(1) NOT NULL, + `type` int(11) NOT NULL, + `anzahl_chars` int(11) NOT NULL, + PRIMARY KEY (`clan_challenge_id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `clan_challenges` +-- + +/*!40000 ALTER TABLE `clan_challenges` DISABLE KEYS */; +LOCK TABLES `clan_challenges` WRITE; +UNLOCK TABLES; +/*!40000 ALTER TABLE `clan_challenges` ENABLE KEYS */; + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;