@ -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 kan n andere Clans herausfordern!!';
return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder könne n 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 h erausforderungen anderer Clans annehmen!!';
return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können H erausforderungen 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 kan n Herausforderungen anderer Clans ablehnen!!';
return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder könne n 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ü r diesen Kampf nicht verfü gbar!!';
return 'Der Slot ' . $slot . ' ist fü r diesen Kampf nicht verfü 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;
}
}