checked in the current state of the clan fights. most of the functions are not yet tested and may contain bugs! The databases are sill work in progress (e.g. the codebase for blocking the char is not yet started). But it is a really good point to begin the implementation of the presentation!
parent
0535167230
commit
f6fea3bfa0
@ -0,0 +1,502 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* @copyright (c) 2011 animegame.eu
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
|
||||
*
|
||||
*/
|
||||
|
||||
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/clan.inc.php');
|
||||
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/semaphore.inc.php');
|
||||
|
||||
|
||||
define("MIN_MEMBERS", 5);
|
||||
define("MAX_OPEN_REQUESTS", 3);
|
||||
define("DAVY_BACK_FIGHT", 1);
|
||||
define("SURVIVAL", 2);
|
||||
|
||||
define("ATTACK_SET_DAVY_BACK_FIGHT", 2);
|
||||
define("ATTACK_SET_SURVIVAL", 2);
|
||||
|
||||
$GLOBALS['clan_challenge_buffered_instances'] = array ();
|
||||
|
||||
|
||||
// Methods required within the request/accept phase
|
||||
|
||||
/**
|
||||
*
|
||||
* 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) {
|
||||
$clan = getClan($user['clan']);
|
||||
$oclan = getClan($clanid);
|
||||
|
||||
$ressource_clan1 = 'Clan:' . $user['clan'];
|
||||
$ressource_clan2 = 'Clan:' . $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!!';
|
||||
}
|
||||
|
||||
if(isClanLocked($user['clan']) || isClanLocked($clanid)) {
|
||||
// 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)!';
|
||||
}
|
||||
|
||||
if(!semaphoreUP($ressource_clan1)) {
|
||||
return 'Fehler beim Verarbeiten der Anfrage für \'' . $clan['clanname'] . '\' versuche es bitte nochmal! ';
|
||||
}
|
||||
|
||||
if(!semaphoreUP($ressource_clan2)) {
|
||||
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
|
||||
return 'Fehler beim Verarbeiten der Anfrage für \'' . $oclan['clanname'] . '\' versuche es bitte nochmal! ';
|
||||
}
|
||||
|
||||
// okay we have both semaphores :)
|
||||
|
||||
$clan_challenges_my_clan = getOpenChallengesRequestCount($user['clan']);
|
||||
$clan_challenges_oth_clan = getOpenChallengesRequestCount($clanid);
|
||||
|
||||
if($clan_challenges_my_clan > 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 ...
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -1,749 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* @copyright (c) 2009 animegame.eu
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
|
||||
*
|
||||
*/
|
||||
/******
|
||||
Funktionen fuer die Clanfights
|
||||
Muss noch bearbeitet werden !!
|
||||
|
||||
******/
|
||||
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/ag/include/config.inc.php');
|
||||
|
||||
function getClanMember($clanid) {
|
||||
//$sql = 'SELECT * FROM user where clan = '.$clanid;
|
||||
$qry = mysql_query('SELECT * FROM user where clan = '.$clanid);
|
||||
$options = '';
|
||||
while ($row = mysql_fetch_assoc($qry)) {
|
||||
$options .= '<option value="'.$row['id'].'">'.$row['nickname'].'</option>';
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
function getMemberCharacters($userid) {
|
||||
$qry = mysql_query('SELECT * FROM chars where besitzer = '.$userid);
|
||||
$options = '';
|
||||
while ($row = mysql_fetch_assoc($qry)) {
|
||||
$options .= '<option value="'.$row['id'].'">'.$row['name'].'</option>';
|
||||
}
|
||||
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 .= '<option value="'.$row['id'].'">'.$row['clanname'].'</option>';
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
function displayClanFights($userid) {
|
||||
$clanid = getClanOfUser($userid);
|
||||
$claninfos= getClanInformation($clanid);
|
||||
?>
|
||||
<table width="548" cellspacing="0" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<th height="29" valign="top" colspan="2">Clan Kämpfe</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<?php echo getActualClanChallengeInformation($clanid,$userid); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
if ($claninfos['leader'] == $userid OR $claninfos['co_leader'] == $userid) {
|
||||
$anzahl_herausforderungen= mysql_num_rows(mysql_query('SELECT id FROM clan_fight_list WHERE clan='.$clanid.' AND status<2'));
|
||||
if ($anzahl_herausforderungen == 3) {
|
||||
?>
|
||||
<tr>
|
||||
<th height="29" valign="top" colspan="2">Dein Clan hat bereits 3 Herausforderungen. Mehr sind nicht möglich.</td>
|
||||
</tr>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<tr>
|
||||
<th height="29" valign="top" colspan="2"><a href="index.php?as=clan/c_kampf&id=create">Clan herausfordern</a></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
function displayClanFightType($userid) {
|
||||
$clanid = getClanOfUser($userid);
|
||||
?>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?as=clan/c_kampf" method="POST">
|
||||
<input type="hidden" name="id" value="1">
|
||||
<table width="548" cellspacing="0" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<th>Kampftyp: </th>
|
||||
<td height="25">
|
||||
<select class="input" name="clanfighttyp">
|
||||
<option value="1">1 vs. 1</option>
|
||||
<option value="2">Survival</option>
|
||||
<!--<option value="4">2 vs. 2</option>
|
||||
<option value="7">4 vs. 4</option>
|
||||
<option value="12">7 vs. 7</option>-->
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="25" align="center">
|
||||
<input id="input" type="submit" value="weiter">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
function displaySelectNumberOfFighter($clanfighttyp) {
|
||||
?>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?as=clan/c_kampf" method="POST">
|
||||
<input type="hidden" name="id" value="2">
|
||||
<input type="hidden" name="clanfighttyp" value="<?php echo $clanfighttyp; ?>">
|
||||
<table width="548" cellspacing="0" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<th>Anzahl Kämpfer: </th>
|
||||
<td height="25">
|
||||
<select class="input" name="numberoffighter">
|
||||
<?php
|
||||
switch ($clanfighttyp) {
|
||||
case "1":
|
||||
?>
|
||||
<option value="4">4 Kämpfer</option>
|
||||
<option value="6">6 Kämpfer</option>
|
||||
<?php
|
||||
break;
|
||||
case "2":
|
||||
?>
|
||||
<option value="4">4 Kämpfer</option>
|
||||
<option value="6">6 Kämpfer</option>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="25" align="center">
|
||||
<input id="input" type="submit" value="weiter">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
function displayClanUser($userid,$numberoffighter,$clanfighttyp,$type){
|
||||
$clanid = getClanOfUser($userid);
|
||||
$optionen = getCharacterOptions($clanid);
|
||||
?>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?as=clan/c_kampf" method="POST">
|
||||
<?php
|
||||
if ($type == 'create') {
|
||||
echo '<input type="hidden" name="id" value="3">';
|
||||
} elseif ($type == 'accept') {
|
||||
echo '<input type="hidden" name="id" value="acc2">';
|
||||
echo '<input type="hidden" name="kid" value="'.$_GET['kid'].'">';
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="numberoffighter" value="<?php echo $numberoffighter;?>">
|
||||
<?php
|
||||
if (!empty($clanfighttyp)) {
|
||||
?>
|
||||
<input type="hidden" name="clanfighttyp" value="<?php echo $clanfighttyp; ?>">
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<table width="548" cellspacing="0" cellpadding="0" border="0">
|
||||
<?php
|
||||
for($i=1;$i<=$numberoffighter;$i++){
|
||||
?>
|
||||
<tr>
|
||||
<th>User <?php echo $i; ?></th>
|
||||
<td height="25">
|
||||
<select class="input" name="user[<?php echo $i; ?>]">
|
||||
<option value="-1">User wählen...
|
||||
<?php echo getClanMember($clanid); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td height="25" align="center">
|
||||
<input id="input" type="submit" value="weiter">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
function displayCharsOfClanUser($userid, $wahluser, $numberoffighter, $clanfighttyp='', $type){
|
||||
$anzahl_gewaehlt= 0;
|
||||
|
||||
for($i=1;$i<count($wahluser)+1;$i++) {
|
||||
if($wahluser[$i] != -1) {
|
||||
$anzahl_gewaehlt++;
|
||||
}
|
||||
}
|
||||
|
||||
$count_member_array= array_count_values($wahluser);
|
||||
|
||||
for($i=1;$i<count($wahluser)+1;$i++) {
|
||||
if($wahluser[$i] == -1) {
|
||||
$errmsg .= '<p>Es sind nicht genug Clanmitglieder ausgewählt worden für einen Clankampf!</p>';
|
||||
$errmsg .= '<p>Leider nur '.$anzahl_gewaehlt.' von '.count($wahluser).' Clanmitglieder ausgewählt!</p>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($count_member_array as $key => $value) {
|
||||
if ($value > 1 AND $key != -1) {
|
||||
$errmsg .= '<p>Du hast leider ein Clanmitglied mehrfach ausgewählt!</p>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$clanid = getClanOfUser($userid);
|
||||
$optionen = getCharacterOptions($clanid);
|
||||
|
||||
if (empty($errmsg)) {
|
||||
?>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?as=clan/c_kampf" method="POST">
|
||||
<?php
|
||||
if ($type == 'create') {
|
||||
echo '<input type="hidden" name="id" value="4">';
|
||||
echo '<input type="hidden" name="numberoffighter" value="'.$numberoffighter.'">';
|
||||
echo '<input type="hidden" name="clanfighttyp" value="'.$clanfighttyp.'">';
|
||||
} elseif ($type == 'accept') {
|
||||
echo '<input type="hidden" name="id" value="acc_fin">';
|
||||
echo '<input type="hidden" name="kid" value="'.$_POST['kid'].'">';
|
||||
}
|
||||
?>
|
||||
<table width="548" cellspacing="0" cellpadding="0" border="0">
|
||||
<?php
|
||||
for($i=1;$i<=$numberoffighter;$i++){
|
||||
?>
|
||||
<tr>
|
||||
<th>User <?php echo $i; ?></th>
|
||||
<td height="25">
|
||||
<select class="input" name="char[<?php echo $i; ?>]">
|
||||
<option value="0">Charakter wählen...
|
||||
<?php echo getMemberCharacters($wahluser[$i]); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td height="25" align="center">
|
||||
<input id="input" type="submit" value="weiter">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
} else {
|
||||
$errmsg .= '<div style="text-align:center;"><input type="button" value="Zurück" onClick="history.back()"></div>';
|
||||
echo $errmsg1;
|
||||
echo $errmsg;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function displaySelectClanToFight($userid,$numberoffighter,$clanfighttyp) {
|
||||
$clanid = getClanOfUser($userid);
|
||||
/*for ($i=1;$i<sizeof($_POST['char'])+1;$i++) {
|
||||
if (getStatusOfChar($_POST['char'][$i]) != 'Frei') {
|
||||
$fehlerhafter_status += 1;
|
||||
$chars_mit_falschem_status[]= $_POST['char'][$i];
|
||||
}
|
||||
}
|
||||
if (isset($fehlerhafter_status)) {
|
||||
echo '<div style="text-align:center;"><input type="button" value="Zurück" onClick="history.back()"></div>';
|
||||
echo '<p>Folgende Charaktere sind nicht verfügbar:</p>';
|
||||
echo '<ul>';
|
||||
for ($i=0;$i<count($chars_mit_falschem_status);$i++) {
|
||||
echo '<li>'.getNameOfChar($chars_mit_falschem_status[$i]).'</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
exit;
|
||||
}*/
|
||||
?>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?as=clan/c_kampf" method="POST">
|
||||
<input type="hidden" name="id" value="5">
|
||||
<input type="hidden" name="chars" value=<?php echo serialize($_POST['char']);?>>
|
||||
<input type="hidden" name="numberoffighter" value="<?php echo $numberoffighter;?>">
|
||||
<input type="hidden" name="clanfighttyp" value="<?php echo $clanfighttyp;?>">
|
||||
<table width="548" cellspacing="0" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<th>Clan: </th>
|
||||
<td height="25">
|
||||
<select class="input" name="clan">
|
||||
<option value="0">Clan wählen...
|
||||
<?php echo getClans($clanid); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Datum: </th>
|
||||
<td height="25">
|
||||
<select class="input" name="datum">
|
||||
<?php
|
||||
$timestamp= time();
|
||||
for ($i=0;$i<14;$i++) {
|
||||
$datum= date("d.m.Y",$timestamp+$i*60*60*24);
|
||||
$timestamp_changed= strtotime(date("d.m.Y",$timestamp+$i*60*60*24));
|
||||
echo '<option value="'.$timestam_changed.'">'.$datum.'</datum>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Zeitpunkt: </th>
|
||||
<td height="25">
|
||||
<select class="input" name="zeitpunkt">
|
||||
<option value="0">nachts (0 Uhr)</option>
|
||||
<option value="8">morgens (8 Uhr)</option>
|
||||
<option value="16">nachmittags (16 Uhr)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<!--<tr>
|
||||
<th>Ausrüstung: </th>
|
||||
<td height="25">
|
||||
<select class="input" name="ausruestung">
|
||||
<option value="1">mit Ausrüstung</option>
|
||||
<option value="0">ohne Ausrüstung</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>-->
|
||||
<tr>
|
||||
<td height="25" align="center">
|
||||
<input id="input" type="submit" value="weiter">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
function declineClanfight($clanfightid,$true='') {
|
||||
if (empty($true)) {
|
||||
echo '<p>Willst du den Clankamp wirklich ablehnen?</p>';
|
||||
echo '<p><a href="index.php?as=clan/c_kampf&id=dec&kid='.$clanfightid.'&true=1">Ja</a> | <a href="index.php?as=clan/c_kampf">Nein</a></p>';
|
||||
} else {
|
||||
$clankampf_loeschen= mysql_query('DELETE FROM clan_fight_list WHERE id='.$clanfightid.' LIMIT 1');
|
||||
echo '<p>Clankampf erfolgreich abgelehnt!</p>';
|
||||
echo '<p><a href="index.php?as=clan/c_kampf">zurück zur Übersicht</a></p>';
|
||||
}
|
||||
}
|
||||
|
||||
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= '<p>Dieser Clankampf ist nicht von deinem Clan erstellt und kann somit nicht zurückgezogen werden!</p>';
|
||||
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= '<p>Die Herausforderung von diesem Clankampf ist nicht an deinem Clan gerichtet!</p>';
|
||||
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= '<p>Der Clankampf wurde bereits angenommen / abgelehnt!</p>';
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
global $errmsg;
|
||||
$errmsg= '<p>Diesen Clankampf gibt es nicht!</p>';
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
global $errmsg;
|
||||
$errmsg= '<p>Die ID des Clankampfes ist kein numerischer Wert!</p>';
|
||||
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 '<p>Der Clankampf wurde erfolgreich angenommen!</p>';
|
||||
echo '<a href="index.php?as=clan/c_kampf">zurück zur Übersicht</a>';
|
||||
} else {
|
||||
echo '<p>Dieser Clankampf kann nichtmehr angenommen werden. Er wurde bereits angenommen!</p>';
|
||||
echo '<a href="index.php?as=clan/c_kampf">zurück zur Übersicht</a>';
|
||||
}
|
||||
}
|
||||
|
||||
function deleteClanFight($clanfightid) {
|
||||
$clankampf_loeschen= mysql_query('DELETE FROM clan_fight_list WHERE id='.$clanfightid.' LIMIT 1');
|
||||
echo '<p>Herausforderung erfolgreich zurückgezogen!</p>';
|
||||
echo '<a href="index.php?as=clan/c_kampf">zurück zur Übersicht</a>';
|
||||
}
|
||||
|
||||
function getClanOptions(){
|
||||
$sql = 'SELECT clanname, id FROM clan order by clanname';
|
||||
$qry = mysql_query($sql);
|
||||
$options = '';
|
||||
while($row = mysql_fetch_assoc($qry)){
|
||||
$options .= '<option value="'.$row[id].'">'.$row[clanname].'</option>';
|
||||
}
|
||||
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 .= '<option value='.$row[id].'>'.$row[name].' ('.$row[nickname].')</option>';
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
function getActualClanChallengeInformation($clanid,$userid){
|
||||
$string = '<table>';
|
||||
#$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 .= '<tr><th valign="top">Herausforderung an "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td> (<a href="index.php?as=clan/c_kampf&id=del&kid='.$row['id'].'">zurückziehen</a>) </td></tr>';
|
||||
} else {
|
||||
$string .= '<tr><th valign="top">Herausforderung an "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td> (zurückziehen) </td></tr>';
|
||||
}
|
||||
} else {
|
||||
$claninformationen= getClanInformation($row['clan']);
|
||||
if ($informationen_eigener_clan['leader'] == $userid OR $informationen_eigener_clan['co_leader'] == $userid) {
|
||||
$string .= '<tr><th valign="top">Herausforderung von "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td>(<a href="index.php?as=clan/c_kampf&id=acc&kid='.$row['id'].'">annehmen</a> | <a href="index.php?as=clan/c_kampf&id=dec&kid='.$row['id'].'">ablehnen</a>)</td></tr>';
|
||||
} else {
|
||||
$string .= '<tr><th valign="top">Herausforderung von "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td>(annehmen | ablehnen)</td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$string .= '</table>';
|
||||
return $string;
|
||||
}
|
||||
|
||||
function getActualClanFightInformation($clanid,$userid){
|
||||
$string = '<table>';
|
||||
#$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 .= '<tr><th valign="top">Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td>anschauen</td></tr>';
|
||||
} elseif ($row['status'] == 2) {
|
||||
$string .= '<tr><th valign="top">Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td><a href="index.php?as=clan/c_kampf&id=look&kid='.$row['id'].'">anschauen</a></td></tr>';
|
||||
}
|
||||
} else {
|
||||
$claninformationen= getClanInformation($row['clan']);
|
||||
if ($row['status'] == 1) {
|
||||
$string .= '<tr><th valign="top">Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td>anschauen</td></tr>';
|
||||
} elseif ($row['status'] == 2) {
|
||||
$string .= '<tr><th valign="top">Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td><a href="index.php?as=clan/c_kampf&id=look&kid='.$row['id'].'">anschauen</a></td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$string .= '</table>';
|
||||
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 '<div style="text-align:center;"><input type="button" value="Zurück" onClick="history.back()"></div>';
|
||||
echo '<p>Eine Anfrage für den '.date("d.m.Y H:i:s",$time).' an den Clan "'.$claninfo2['clanname'].'" wurde bereits gestellt!</p>';
|
||||
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 '<div style="text-align:center;"><input type="button" value="Zurück" onClick="history.back()"></div>';
|
||||
echo '<p>Eine Herausforderung für den '.date("d.m.Y H:i:s",$time).' vom Clan "'.$claninfo2['clanname'].'" wurde bereits an deinen Clan gestellt!</p>';
|
||||
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.'<br>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 = '<table>';
|
||||
#$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 .= '<tr><th valign="top">Herausforderung an "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td> (<a href="index.php?as=clan/c_kampf&id=del&kid='.$row['id'].'">zurückziehen</a>) </td></tr>';
|
||||
} else {
|
||||
$string .= '<tr><th valign="top">Herausforderung an "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td> (zurückziehen) </td></tr>';
|
||||
}
|
||||
} elseif ($row['status'] == 1) {
|
||||
$string .= '<tr><th valign="top">Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td>anschauen</td></tr>';
|
||||
} elseif ($row['status'] == 2) {
|
||||
$string .= '<tr><th valign="top">Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td><a href="index.php?as=clan/c_kampf&id=look&kid='.$row['id'].'">anschauen</a></td></tr>';
|
||||
}
|
||||
} else{
|
||||
$claninformationen= getClanInformation($row['clan']);
|
||||
if($row['status'] == 0){
|
||||
if ($informationen_eigener_clan['leader'] == $userid OR $informationen_eigener_clan['co_leader'] == $userid) {
|
||||
$string .= '<tr><th valign="top">Herausforderung von "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td>(<a href="index.php?as=clan/c_kampf&id=acc&kid='.$row['id'].'">annehmen</a> | <a href="index.php?as=clan/c_kampf&id=dec&kid='.$row['id'].'">ablehnen</a>)</td></tr>';
|
||||
} else {
|
||||
$string .= '<tr><th valign="top">Herausforderung von "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td>(annehmen | ablehnen)</td></tr>';
|
||||
}
|
||||
} elseif ($row['status'] == 1) {
|
||||
$string .= '<tr><th valign="top">Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td>anschauen</td></tr>';
|
||||
} elseif ($row['status'] == 2) {
|
||||
$string .= '<tr><th valign="top">Clankampf gegen "'.$claninformationen['clanname'].'" am '.date("d.m.Y H:i:s",$row['zeitpunkt']).'</td><td><a href="index.php?as=clan/c_kampf&id=look&kid='.$row['id'].'">anschauen</a></td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$string .= '</table>';
|
||||
return $string;
|
||||
}*/
|
||||
|
||||
?>
|
Loading…
Reference in new issue