diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php index 3d6c22c..d3f595f 100644 --- a/ag/include/clan_fights.inc.php +++ b/ag/include/clan_fights.inc.php @@ -232,12 +232,41 @@ function acceptChallengeRequest($challenged_clan, array $user) { return NULL; } +function cancelChallengeRequest($challenged_clan, array $user) { + $clan = getClan($user['clan']); + + if(!$clan) { + return 'Du bist in keinem Clan!!'; + } + + if(!isAuthorizedClanfightCoordinator($user['clan'], $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 = ' .$challenged_clan . ' AND clan_requester = ' .$user['clan'] . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())')); + + if(!$clan_challenge) { + return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!'; + } + + // TODO: Check if this conditions are redundant + if($user['clan'] != $clan_challenge['clan_requester']) { + return 'Du kannst die Herausforderung nicht ablehnen, da du nicht im herausfordernden Clan bist!'; + } else if ($clan_challenge['active'] != 1) { + return 'Du kannst die Herausforderung nicht ablehnen, da diese schon angenommen wurde!'; + } + + // okay seems to be okay + mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$challenged_clan . ' AND clan_requester = ' .$user['clan'] . ' AND active = TRUE'); + return NULL; +} + /** * With this function the actual user from the challenged clan denies the challenge request! * @param int $challenged_clan * @param array $user */ -function denyChallengeRequest($challenged_clan, array $user) { +function denyChallengeRequest($challenge_requester, array $user) { $clan = getClan($user['clan']); if(!$clan) { @@ -248,12 +277,13 @@ function denyChallengeRequest($challenged_clan, array $user) { 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 = ' .$challenge_requester . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())')); if(!$clan_challenge) { return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!'; } + // TODO: Check if this conditions are redundant if($user['clan'] != $clan_challenge['clan_challenged']) { return 'Du kannst die Herausforderung nicht ablehnen, da du nicht im herausgeforderten Clan bist!'; } else if ($clan_challenge['active'] != 1) { @@ -759,14 +789,14 @@ function getClanFightCapableClanIds() { function updateAuthorizedClanfightCoordinators($clan_id, array $user_ids) { $ids = getAuthorizedClanfightCoordinatorIDs($clan_id); - + $add = array_diff($user_ids, $ids); $remove = array_diff($ids, $user_ids); - + $sql = 'DELETE FROM `clan_challenge_whitelist` WHERE `user_id` IN (' . implode(',', $remove) .') AND `clan_id` = ' . $clan_id; // echo $sql . '
'; mysql_query($sql); - + foreach($add as $user_id) { $sql = 'INSERT INTO `clan_challenge_whitelist`(`user_id`, `clan_id`) values('.$user_id.', '.$clan_id.')'; // echo $sql . '
';