You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
10 KiB

<?php
/*
*
* @copyright (c) 2011 animegame.eu
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
*
*/
$GLOBALS['clan_buffered_instances'] = array ();
function getClan($clanid, $buffer = TRUE) {
if(!is_numeric($clanid)) { return NULL; }
if(buffer && isset($GLOBALS['clan_buffered_instances'][$clanid])) {
return $GLOBALS['clan_buffered_instances'][$clanid]; // okay, we already buffered the clan :)
}
$clan = mysql_fetch_assoc(mysql_query('SELECT * FROM clan WHERE id = '. $clanid));
// now calculate the member, max_exp fields :D
if($clan) {
$GLOBALS['clan_buffered_instances'][$clanid] = $clan;
return $clan;
} else {
return NULL;
}
}
function getClanMembersCount($clanid) {
if(!is_numeric($clanid)) { return NULL; }
$row = mysql_fetch_assoc(mysql_query('SELECT count(id) as amount FROM user WHERE clan = '. $clanid));
return $row['amount'];
}
function getClanMemberBonusByLevel($level) {
switch($level) {
case 1:
case 2:
case 3:
return 0;
case 4:
case 5:
case 6:
return 1;
case 7:
case 8:
return 2;
case 9:
case 10:
return 3;
case 11:
case 12:
return 4;
case 13:
case 14:
return 5;
case 15:
case 16:
return 6;
case 17:
return 7;
default:
return 8;
}
}
function getMaximumMembers($clanid) {
// okay, this is a more tricky calculation as this requires the information (are leader and co_leader the same person??)
// the second parameter is the clan level. Each 2 levels (where the maximum clan level is about 20) one more member can
// be invited :)
$clan = getClan($clanid);
if($clan === NULL){ return 0; }
$base = 12;
$members_by_level = getClanMemberBonusByLevel($clan['level']);
$malus = 0;
if($clan['co_leader'] == NULL || $clan['co_leader'] == $clan['leader']) {
$malus = 1;
}
return $base + $members_by_level - $malus;
}
function getRequiredClanExp($level) {
return pow(2, $level) * 10;
}
function revokeInvitation($user, $userid, $clan = NULL){
if($user['clan'] === NULL) {
return 'Du bist in keinem Clan!';
}
if($clan === NULL) {
$qry = mysql_query('Select * from clan where id = ' . $user['clan']);
$clan = mysql_fetch_assoc($qry);
}
if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){
return 'Nur der Leader, bzw. der Co-Leader kann Einladungen zur&uuml;ckziehen!!';
}
$sql = 'DELETE FROM user_clan_invitations WHERE clanid = '.$clan['id'].' AND userid = '.$userid;
// echo $sql . '<br>';
mysql_query($sql);
if(mysql_affected_rows() > 0){
return NULL;
} else{
return 'Einladung konnte nicht zur&uuml;ckgezogen werden!';
}
}
/**
*
* Enter description here ...
* @param array $user the user that wants to invite
* @param int $userid the id of the user that should be invited
* @param array $clan the optional clan array (if available)
*/
function inviteUser(array $user, $userid, array $clan = NULL){
if($user['clan'] === NULL) {
return 'Du bist in keinem Clan!';
}
if($clan === NULL) {
$qry = mysql_query('Select * from clan where id = ' . $user['clan']);
$clan = mysql_fetch_assoc($qry);
}
if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){
return 'Nur der Leader, bzw. der Co-Leader kann neue Member einladen!';
}
$row = mysql_fetch_assoc(mysql_query('SELECT * FROM user where id = \''. $userid.'\''));
if(!row) {
return 'Fehler! Nutzer exisitiert nicht!!';
}
if($row['clan'] == $user['clan']){
return 'Fehler! Nutzer ist schon in deinem Clan!';
}
$sql = 'INSERT INTO user_clan_invitations(userid, clanid, valid) values('.$userid.','.$user['clan'].',TIMESTAMPADD(DAY, 5, now()))';
// echo $sql.'<br>';
mysql_query($sql);
if(mysql_affected_rows() <= 0){ // Fehler?
$sql = 'UPDATE user_clan_invitations SET valid = TIMESTAMPADD(DAY, 5, now()) where userid = '.$userid.' and clanid = '.$user['clan'];
// echo $sql.'<br>';
mysql_query($sql);
if(mysql_affected_rows() <= 0){ // Fehler?
return 'Fehler! Konnte Nutzer nicht einladen!';
} else{
sendMessage($user['nickname'], $userid, 'Einladung in Clan', 'Die Einladung des Clans '.$clan['clanname'].' wurde aufgefrischt! Klicke auf "Clan beitreten" um die Einladung anzunehmen!');
return NULL;
}
} else{
sendMessage($user['nickname'], $userid, 'Einladung in Clan', 'Du wurdest eingeladen dich dem Clan '.$clan['clanname'].' anzuschliessen! Klicke auf "Clan beitreten" um die Einladung anzunehmen!');
return 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) {
}
?>