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())';
@ -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())'));
@ -368,7 +369,7 @@ 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));
@ -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,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!'; 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) { if(mysql_affected_rows() == 0) {
semaphoreDown($ressource); semaphoreDown($ressource);
if($forced) {
semaphoreDown($ressource2);
}
return 'Konnte den Char nicht hinzufügen. Slot mittlerweile schon belegt?'; 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 ;))
$sql = 'update clan_challenges AS cc SET calculated = TRUE WHERE '. $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); 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,8 +541,11 @@ function leaveChallenge($clan_challenge_id, array $user, $charid) {
} }
if($char['besitzer'] != $user['id']) { 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!'; 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!
// basically the check consists of a) is the challenge not yet calculated b) is char active in the challenge? // 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 * @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