added some more functionality (adjusted the database aswell)

main
hecht 13 years ago
parent 6d001c990f
commit 88591964c5

@ -18,6 +18,7 @@ include_once (ROOT_PATH . '/include/event.inc.php');
defineIfNotDefined('MIN_MEMBERS', 5); defineIfNotDefined('MIN_MEMBERS', 5);
defineIfNotDefined('MAX_OPEN_REQUESTS', 3); defineIfNotDefined('MAX_OPEN_REQUESTS', 3);
defineIfNotDefined('MAX_LEADER_ASSIGNED_CHARS', 1);
defineIfNotDefined('CLANFIGHTS_MAX_FIGHTS_PER_24H', 6); defineIfNotDefined('CLANFIGHTS_MAX_FIGHTS_PER_24H', 6);
defineIfNotDefined('DAVY_BACK_FIGHT', 1); defineIfNotDefined('DAVY_BACK_FIGHT', 1);
defineIfNotDefined('SURVIVAL', 2); defineIfNotDefined('SURVIVAL', 2);
@ -51,8 +52,8 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH
return 'Entweder bist du nicht in einem Clan oder der andere Clan existiert nicht mehr!!'; 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']){ if(isAuthorizedClanfightCoordinator($user['id'])){
return 'Nur der Leader, bzw. der Co-Leader kann andere Clans herausfordern!!'; return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können andere Clans herausfordern!!';
} }
if($clan['id'] == $oclan['id']) { if($clan['id'] == $oclan['id']) {
@ -159,8 +160,8 @@ function acceptChallengeRequest($challenged_clan, array $user) {
return 'Du bist in keinem Clan!!'; return 'Du bist in keinem Clan!!';
} }
if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ if(isAuthorizedClanfightCoordinator($user['id'])){
return 'Nur der Leader, bzw. der Co-Leader kann herausforderungen anderer Clans annehmen!!'; return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können Herausforderungen anderer Clans annehmen!!';
} }
$sql = 'SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())'; $sql = 'SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())';
@ -184,7 +185,7 @@ function acceptChallengeRequest($challenged_clan, array $user) {
// now calculate how many open fights we currently had or have! // FIXME: Good idea to pach this in a semaphore? // now calculate how many open fights we currently had or have! // FIXME: Good idea to pach this in a semaphore?
$sql = 'select count(*) as anzahl from (SELECT count(*) as anz FROM clan_challenges c inner join clan_challenge_clans ccc on c.clan_challenge_id = ccc.clan_challenge_id where calculated = 0 or TIMESTAMPADD(day, -1, now()) < enddate and clan_id IN ('.$clan_challenge['clan_challenged'].', '.$clan_challenge['clan_requester'].') group by clan_id) k where k.anz >= ' . CLANFIGHTS_MAX_FIGHTS_PER_24H; $sql = 'select count(*) as anzahl from (SELECT count(*) as anz FROM clan_challenges c inner join clan_challenge_clans ccc on c.clan_challenge_id = ccc.clan_challenge_id where calculated = 0 or TIMESTAMPADD(day, -1, now()) < enddate and clan_id IN ('.$clan_challenge['clan_challenged'].', '.$clan_challenge['clan_requester'].') group by clan_id) k where k.anz >= ' . CLANFIGHTS_MAX_FIGHTS_PER_24H;
// echo $sql . '<br>'; // echo $sql . '<br>';
$row = mysql_fetch_assoc(mysql_query($sql)); $row = mysql_fetch_assoc(mysql_query($sql));
if($row['anzahl'] > 0) { if($row['anzahl'] > 0) {
@ -241,8 +242,8 @@ function denyChallengeRequest($challenged_clan, array $user) {
return 'Du bist in keinem Clan!!'; return 'Du bist in keinem Clan!!';
} }
if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ if(isAuthorizedClanfightCoordinator($user['id'])){
return 'Nur der Leader, bzw. der Co-Leader kann Herausforderungen anderer Clans ablehnen!!'; return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können Herausforderungen anderer Clans ablehnen!!';
} }
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())')); $clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())'));
@ -275,7 +276,7 @@ function getChallenge($challenge_id, $buffer = TRUE) {
$qry = mysql_query('SELECT * from clan_challenges WHERE clan_challenge_id = ' .$challenge_id); $qry = mysql_query('SELECT * from clan_challenges WHERE clan_challenge_id = ' .$challenge_id);
$GLOBALS['clan_challenge_buffered_instances'][$challenge_id] = mysql_fetch_assoc($qry); $GLOBALS['clan_challenge_buffered_instances'][$challenge_id] = mysql_fetch_assoc($qry);
return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :) return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :)
} }
function getOpenChallengeRequests($clanid) { function getOpenChallengeRequests($clanid) {
$array = array(); $array = array();
@ -284,7 +285,7 @@ function getOpenChallengeRequests($clanid) {
} }
$sql = 'SELECT * from clan_challenge_requests WHERE challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND (clan_requester = '.$clanid.' OR clan_challenged = '.$clanid.')'; $sql = 'SELECT * from clan_challenge_requests WHERE challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND (clan_requester = '.$clanid.' OR clan_challenged = '.$clanid.')';
// echo $sql . '<br>'; // echo $sql . '<br>';
$qry = mysql_query($sql); $qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) { while($row = mysql_fetch_assoc($qry)) {
$array[] = $row; $array[] = $row;
@ -297,7 +298,7 @@ function getOpenChallengeRequestCount($clanid) {
return 0; 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.')'; $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.')';
// echo $sql . '<br>'; // echo $sql . '<br>';
$row = mysql_fetch_row(mysql_query($sql)); $row = mysql_fetch_row(mysql_query($sql));
return $row[0]; return $row[0];
} }
@ -368,8 +369,8 @@ function isClanLocked($clanid) {
return true; return true;
} }
// 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 // 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() as `lock`, (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; $sql = 'SELECT *, locked_until > now() as `lock`, (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;
// echo $sql.'<br>'; // echo $sql.'<br>';
$lock = mysql_fetch_assoc(mysql_query($sql)); $lock = mysql_fetch_assoc(mysql_query($sql));
if($lock['lock'] == 0) { // don't matter if it is 0 or NULL if($lock['lock'] == 0) { // don't matter if it is 0 or NULL
@ -385,12 +386,12 @@ function isClanLocked($clanid) {
} else if($lock['lock'] === NULL){ // we need to insert a row } else if($lock['lock'] === NULL){ // we need to insert a row
// INSERT // INSERT
$sql = 'INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP))'; $sql = 'INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP))';
// echo $sql.'<br>'; // echo $sql.'<br>';
mysql_query($sql); mysql_query($sql);
} else if($lock['members'] < MIN_MEMBERS){ // we have to update the actual row } else if($lock['members'] < MIN_MEMBERS){ // we have to update the actual row
// UPDATE // UPDATE
$sql = 'UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid; $sql = 'UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid;
// echo $sql.'<br>'; // echo $sql.'<br>';
mysql_query($sql); mysql_query($sql);
} }
} }
@ -410,11 +411,18 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
$clan = getClan($user['clan']); $clan = getClan($user['clan']);
$char = getChar($charid); $char = getChar($charid);
$forced = false;
if(!$clan) { if(!$clan) {
return 'Du bist in keinem Clan!!'; return 'Du bist in keinem Clan!!';
} }
if($char['besitzer'] != $user['id']) { if($char['besitzer'] != $user['id']) {
// the current user is NOT the owner of the char --> check if it is a coordinator
if(isAuthorizedClanfightCoordinator($clan_id, $user['id'], $clan_challenge_id)) {
// okay we may assign an additional char ;) // check if we have reached the limit is later!!
$forced = true;
}
return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er dir nicht gehört!'; return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er dir nicht gehört!';
} }
@ -424,7 +432,7 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
$clan_challenge = getChallenge($clan_challenge_id); $clan_challenge = getChallenge($clan_challenge_id);
if($slot < 1 && $slot > $clan_challenge['anzahl_chars']) { if($slot < 1 || $slot > $clan_challenge['anzahl_chars']) {
return 'Der Slot ' . $slot . ' ist f&uuml;r diesen Kampf nicht verf&uuml;gbar!!'; return 'Der Slot ' . $slot . ' ist f&uuml;r diesen Kampf nicht verf&uuml;gbar!!';
} }
@ -458,10 +466,39 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
return 'Konnte den Char nicht hinzufügen. Da du schon einen Char angemeldet hast!'; return 'Konnte den Char nicht hinzufügen. Da du schon einen Char angemeldet hast!';
} }
mysql_query('INSERT INTO clan_challenge_participants(clan_challenge_id, clan_id, char_id, slot) values('.$clan_challenge_id.', '.$user['clan'].', '.$charid.', '.$slot.')');
if(mysql_affected_rows() == 0) { if($forced && isForceForCharAcknowledged($char['id'])) {
}
$resource2 = 'Clan:'.$clan_id;
if($forced && !semaphoreUP($ressource2)) {
return 'Du kannst den Char nicht zuweisen, da exakt im gleichen Moment jemand aus deinem Clan auch einen Char zuweist!';
}
// okay and now check if we reached the maximum amount of leader assigned chars!!
if($forced && getCountLeaderAssignedChars($clan_id, $clan_challenge_id) >= MAX_LEADER_ASSIGNED_CHARS) {
// shit!!
semaphoreDown($ressource); semaphoreDown($ressource);
return 'Konnte den Char nicht hinzufügen. Slot mittlerweile schon belegt?'; semaphoreDown($ressource2);
return 'Du kannst den Char nicht zuweisen, da die maximale Anzahl der Zuweisungen schon erreicht ist!';
}
mysql_query('INSERT INTO clan_challenge_participants(clan_challenge_id, clan_id, char_id, slot, forced) values('.$clan_challenge_id.', '.$user['clan'].', '.$charid.', '.$slot.', ' .$forced .')');
if(mysql_affected_rows() == 0) {
if(!$forced) {
// maybe the leader has already assigned the char and we now give the official okay for that!
mysql_query('UPDATE clan_challenge_participants SET forced = FALSE, slot = '.$slot.' WHERE clan_challenge_id = '.$clan_challenge_id.' AND clan_id = '.$user['clan'].' AND char_id = '.$charid);
}
if(mysql_affected_rows() == 0) {
semaphoreDown($ressource);
if($forced) {
semaphoreDown($ressource2);
}
return 'Konnte den Char nicht hinzufügen. Slot mittlerweile schon belegt?';
}
} }
// okay, now try to update the challenge to close the challenge and to start the calculating (as long we can do it ;)) // okay, now try to update the challenge to close the challenge and to start the calculating (as long we can do it ;))
@ -477,6 +514,9 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
mysql_query($sql); mysql_query($sql);
$rows = mysql_affected_rows(); $rows = mysql_affected_rows();
semaphoreDown($ressource); semaphoreDown($ressource);
if($forced) {
semaphoreDown($ressource2);
}
if($rows > 0) { if($rows > 0) {
// okay we now have a complete competition and the challenge is closed :) // okay we now have a complete competition and the challenge is closed :)
@ -501,7 +541,10 @@ function leaveChallenge($clan_challenge_id, array $user, $charid) {
} }
if($char['besitzer'] != $user['id']) { if($char['besitzer'] != $user['id']) {
return 'Du kannst den Char nicht vom Kampf zurückziehen, da er dir nicht gehört!'; if(!isAuthorizedClanfightCoordinator($clan_id, $user['id'], $clan_challenge_id)) {
// authorized coordinators may remove a char!! But this one is not authorized
return 'Du kannst den Char nicht vom Kampf zurückziehen, da er dir nicht gehört!';
}
} }
// Okay, the rest we can check with the delete statement much easier! // Okay, the rest we can check with the delete statement much easier!
@ -546,12 +589,12 @@ function calculateChallenge($clan_challenge_id) {
case DAVY_BACK_FIGHT: case DAVY_BACK_FIGHT:
$result = calculateDavyBackClanFight($event_id, $clan_ids, $clan_chars, $start_time); $result = calculateDavyBackClanFight($event_id, $clan_ids, $clan_chars, $start_time);
if(!is_numeric($result)) if(!is_numeric($result))
return $result; return $result;
break; break;
case SURVIVAL: case SURVIVAL:
return calculateSurvivalClanFight($event_id, $clan_ids, $clan_chars, $start_time); return calculateSurvivalClanFight($event_id, $clan_ids, $clan_chars, $start_time);
if(!is_numeric($result)) if(!is_numeric($result))
return $result; return $result;
break; break;
default: default:
// cannot create anything -.- // cannot create anything -.-
@ -614,7 +657,7 @@ function calculateSurvivalClanFight($event_id, array $clan_ids, array $clan_char
$char_clan_2 = $clan_char_array[$clan_ids[1]][++$counter_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 $char_clan_1 = $sieger; // the new array contains the adjusted health parameter
} }
return $start_time + $runde * $duration; return $start_time + $runde * $duration;
} }
} }
@ -691,6 +734,47 @@ function getClanFightCapableClanIds() {
* @param int $clan_fight_id the optional clan_fights that is in scope * @param int $clan_fight_id the optional clan_fights that is in scope
*/ */
function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = NULL) { function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = NULL) {
// do we require this information for a specific clan_fight???
if($clan_fight_id === NULL) {
$sql = 'SELECT COUNT(*) FROM `clan_challenge_clans` WHERE `clan_coordinator` = ' .$user_id. ' AND `clan_id` = '.$clan_id . ' AND `clan_challenge_id` = ' .$clan_fight_id;
$row = mysql_fetch_row(mysql_query($sql));
if($row[0] <= 0) {
// okay, maybe its a leader ;)
$clan = getClan($clan_id);
if($clan['leader'] == $user_id || $clan['co_leader'] = $user_id) {
// the leader or the co_leader is always authorized!
return true;
}
// not authorized!
return false;
}
// the coordinator is always authorized!
return true;
} else {
// it is a more general thing ;)
$sql = 'SELECT COUNT(*) FROM `clan_challenge_whitelist` WHERE `user_id` = ' .$user_id. ' AND `clan_id` = '.$clan_id;
$row = mysql_fetch_row(mysql_query($sql));
}
return true;
}
/**
* Returns how many chars were assigned by the leader for the given fight
* @param int $clan_id
* @param int $clan_fight_id
*/
function getCountLeaderAssignedChars($clan_id, $clan_fight_id) {
$sql = 'SELECT COUNT(*) FROM `clan_challenge_participants` WHERE `clan_challenge_id` = ' .$clan_fight_id . ' AND `clan_id` = '.$clan_id .' AND `forced` = TRUE';
$row = mysql_fetch_row(mysql_query($sql));
return $row[0];
}
/**
* This function checks if there is a char-rule that allows forcing the char for leader assignment!
* @param int $char_id
*/
function isForceForCharAcknowledged($char_id) {
return true; return true;
} }

@ -61,14 +61,17 @@ function insertIntoHallOfFameFull($round = '', $title = '', $charid = '', $charn
return mysql_affected_rows() > 0; return mysql_affected_rows() > 0;
} }
function getHallOfFame($title, $userid) { function getHallOfFameEntryCount($title, $userid) {
$row = mysql_fetch_assoc(mysql_query('Select max(id) as round from online')); $row = mysql_fetch_assoc(mysql_query('Select max(id) as round from online'));
return getHallOfFameFull($row['round'],$title, $userid); return getHallOfFameEntryCountFull($row['round'],$title, $userid);
} }
function getHallOfFameFull($round = '', $title = '', $userid = '') { function getHallOfFameEntryCountFull($round = '', $title = '', $userid = '') {
$sql = 'select count(*) from highscore where runde='.$round.' and userid='.$userid; if(!is_numeric($round) && !is_numeric($userid)) {
$row = mysql_fetch_row($sql); return 0;
}
$sql = 'select count(*) from highscore where art=\''.$title.'\' runde='.$round.' and userid='.$userid;
$row = mysql_fetch_row(mysql_query($sql));
return $row[0]; return $row[0];
} }

@ -43,7 +43,7 @@ function anmelden($user, $charid, $art){
return; return;
} }
if($art == 'klein' && getHallOfFame('Anf&auml;ngerturnier', $user['id']) >= 2) { if($art == 'klein' && getHallOfFameEntryCount('Anf&auml;ngerturnier', $user['id']) >= 2) {
displayErrorMessage(NULL,'Du hast das Anf&auml;ngerturnier schon zu oft gewonnen!!!','<a href="index.php">weiter...</a>'); displayErrorMessage(NULL,'Du hast das Anf&auml;ngerturnier schon zu oft gewonnen!!!','<a href="index.php">weiter...</a>');
} }

@ -20,7 +20,7 @@ $rang1 = getChar($results[0][0]);
// insertIntoHallOfFame($title, $charid, $userid); // insertIntoHallOfFame($title, $charid, $userid);
insertIntoHallOfFame('Anf&auml;ngerturnier', $rang1['id'], $rang1['besitzer']); insertIntoHallOfFame('Anf&auml;ngerturnier', $rang1['id'], $rang1['besitzer']);
if(getHallOfFame('Anf&auml;ngerturnier', $rang1['id']) >= 2) { if(getHallOfFameEntryCount('Anf&auml;ngerturnier', $rang1['id']) >= 2) {
// remove all chars that are registered // remove all chars that are registered
mysql_query('DELETE FROM turnier1 WHERE art = \'klein\' AND besitzer = '.$rang1['besitzer']); mysql_query('DELETE FROM turnier1 WHERE art = \'klein\' AND besitzer = '.$rang1['besitzer']);
} }

@ -405,6 +405,7 @@ CREATE TABLE `clan_challenge_participants` (
`clan_id` int(11) NOT NULL, `clan_id` int(11) NOT NULL,
`char_id` int(11) NOT NULL, `char_id` int(11) NOT NULL,
`slot` int(11) NOT NULL, `slot` int(11) NOT NULL,
`forced` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`clan_challenge_id`,`clan_id`,`slot`), PRIMARY KEY (`clan_challenge_id`,`clan_id`,`slot`),
UNIQUE KEY `new_index` (`clan_challenge_id`,`clan_id`,`slot`), UNIQUE KEY `new_index` (`clan_challenge_id`,`clan_id`,`slot`),
KEY `clan_challenge_participants_clan_id` (`clan_id`), KEY `clan_challenge_participants_clan_id` (`clan_id`),
@ -630,7 +631,7 @@ CREATE TABLE `event_fights` (
`event_id` int(10) unsigned NOT NULL, `event_id` int(10) unsigned NOT NULL,
`event_fight_id` int(10) unsigned NOT NULL, `event_fight_id` int(10) unsigned NOT NULL,
`visible` timestamp NOT NULL, `visible` timestamp NOT NULL,
`started` timestamp NOT NULL, `starting` timestamp NOT NULL,
`host` int(10) unsigned NOT NULL, `host` int(10) unsigned NOT NULL,
`winner` int(10) unsigned NOT NULL, `winner` int(10) unsigned NOT NULL,
PRIMARY KEY (`event_id`,`event_fight_id`), PRIMARY KEY (`event_id`,`event_fight_id`),

Loading…
Cancel
Save