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('MAX_OPEN_REQUESTS', 3);
defineIfNotDefined('MAX_LEADER_ASSIGNED_CHARS', 1);
defineIfNotDefined('CLANFIGHTS_MAX_FIGHTS_PER_24H', 6);
defineIfNotDefined('DAVY_BACK_FIGHT', 1);
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!!';
}
if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){
return 'Nur der Leader, bzw. der Co-Leader kann andere Clans herausfordern!!';
if(isAuthorizedClanfightCoordinator($user['id'])){
return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können andere Clans herausfordern!!';
}
if($clan['id'] == $oclan['id']) {
@ -159,8 +160,8 @@ function acceptChallengeRequest($challenged_clan, array $user) {
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!!';
if(isAuthorizedClanfightCoordinator($user['id'])){
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())';
@ -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?
$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));
if($row['anzahl'] > 0) {
@ -241,8 +242,8 @@ function denyChallengeRequest($challenged_clan, array $user) {
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!!';
if(isAuthorizedClanfightCoordinator($user['id'])){
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())'));
@ -275,7 +276,7 @@ function getChallenge($challenge_id, $buffer = TRUE) {
$qry = mysql_query('SELECT * from clan_challenges WHERE clan_challenge_id = ' .$challenge_id);
$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 :)
}
}
function getOpenChallengeRequests($clanid) {
$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.')';
// echo $sql . '<br>';
// echo $sql . '<br>';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$array[] = $row;
@ -297,7 +298,7 @@ function getOpenChallengeRequestCount($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.')';
// echo $sql . '<br>';
// echo $sql . '<br>';
$row = mysql_fetch_row(mysql_query($sql));
return $row[0];
}
@ -368,8 +369,8 @@ function isClanLocked($clanid) {
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
$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>';
$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>';
$lock = mysql_fetch_assoc(mysql_query($sql));
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
// INSERT
$sql = 'INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP))';
// echo $sql.'<br>';
// echo $sql.'<br>';
mysql_query($sql);
} else if($lock['members'] < MIN_MEMBERS){ // we have to update the actual row
// UPDATE
$sql = 'UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid;
// echo $sql.'<br>';
// echo $sql.'<br>';
mysql_query($sql);
}
}
@ -410,11 +411,18 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
$clan = getClan($user['clan']);
$char = getChar($charid);
$forced = false;
if(!$clan) {
return 'Du bist in keinem Clan!!';
}
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!';
}
@ -424,7 +432,7 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
$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!!';
}
@ -458,11 +466,40 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
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($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($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 ;))
$sql = 'update clan_challenges AS cc SET calculated = TRUE WHERE '.
@ -477,6 +514,9 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
mysql_query($sql);
$rows = mysql_affected_rows();
semaphoreDown($ressource);
if($forced) {
semaphoreDown($ressource2);
}
if($rows > 0) {
// okay we now have a complete competition and the challenge is closed :)
@ -501,8 +541,11 @@ function leaveChallenge($clan_challenge_id, array $user, $charid) {
}
if($char['besitzer'] != $user['id']) {
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!
// basically the check consists of a) is the challenge not yet calculated b) is char active in the challenge?
@ -691,6 +734,47 @@ function getClanFightCapableClanIds() {
* @param int $clan_fight_id the optional clan_fights that is in scope
*/
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;
}

@ -61,14 +61,17 @@ function insertIntoHallOfFameFull($round = '', $title = '', $charid = '', $charn
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'));
return getHallOfFameFull($row['round'],$title, $userid);
return getHallOfFameEntryCountFull($row['round'],$title, $userid);
}
function getHallOfFameFull($round = '', $title = '', $userid = '') {
$sql = 'select count(*) from highscore where runde='.$round.' and userid='.$userid;
$row = mysql_fetch_row($sql);
function getHallOfFameEntryCountFull($round = '', $title = '', $userid = '') {
if(!is_numeric($round) && !is_numeric($userid)) {
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];
}

@ -43,7 +43,7 @@ function anmelden($user, $charid, $art){
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>');
}

@ -20,7 +20,7 @@ $rang1 = getChar($results[0][0]);
// insertIntoHallOfFame($title, $charid, $userid);
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
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,
`char_id` int(11) NOT NULL,
`slot` int(11) NOT NULL,
`forced` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`clan_challenge_id`,`clan_id`,`slot`),
UNIQUE KEY `new_index` (`clan_challenge_id`,`clan_id`,`slot`),
KEY `clan_challenge_participants_clan_id` (`clan_id`),
@ -630,7 +631,7 @@ CREATE TABLE `event_fights` (
`event_id` int(10) unsigned NOT NULL,
`event_fight_id` int(10) unsigned NOT NULL,
`visible` timestamp NOT NULL,
`started` timestamp NOT NULL,
`starting` timestamp NOT NULL,
`host` int(10) unsigned NOT NULL,
`winner` int(10) unsigned NOT NULL,
PRIMARY KEY (`event_id`,`event_fight_id`),

Loading…
Cancel
Save