From 14bf0944c7b04ea0966a97eb482bf73ae2f7a47f Mon Sep 17 00:00:00 2001 From: hecht Date: Wed, 9 Nov 2011 22:52:42 +0000 Subject: [PATCH] fixed buffer problem ... also implemented some new stuff for whitelist (so non-leader may start cfs) --- ag/clan/clan_info.php | 71 +++++++-------------- ag/include/clan.inc.php | 112 ++++++++++++++++++++++++++++----- ag/include/clan_fights.inc.php | 16 ++++- db/animegame_svn.sql | 27 +++++++- 4 files changed, 162 insertions(+), 64 deletions(-) diff --git a/ag/clan/clan_info.php b/ag/clan/clan_info.php index af46329..e43d0b6 100644 --- a/ag/clan/clan_info.php +++ b/ag/clan/clan_info.php @@ -101,10 +101,8 @@ function displayClanProfileReadOnly($clan, $ownclan, $userid){ } else { $openChallengeRequestsDisplay[] = displayClanLink($request['clan_challenged']) ; } - } - ?>
@@ -128,8 +126,10 @@ function displayClanProfileReadOnly($clan, $ownclan, $userid){ if($leader == null && $coleader == null){ if($ownclan) { echo ''; - } else { + } else if(count($member) > 0){ echo ''; + } else { + echo ''; } } else{ echo ''; @@ -375,8 +375,8 @@ function displayClanProfileEditable($clan, $userid){ + href="javascript:if(confirm('Wirklich auflösen? der Clan kann ggf. durch jemand übernommen werden!')==true) window.location.href='index.php?as=clan/clan_info&action=kill'">Clan + auflösen (Achtung! Clans ggf. nur geleert!) @@ -408,8 +408,9 @@ function displayClanProfileEditable($clan, $userid){ weiter...'); - } else { - displayErrorMessage(NULL,'Nachricht erfolgreich verschickt', 'weiter...'); - } -} - function setProfile($what, $value1, $value2, $clanid, $rootlvl){ if($rootlvl < 1) { return 'Du hast keine Rechte um diese Aktion auszuführen!'; @@ -568,21 +547,6 @@ function displayEdit($what, $clanid, $rootlvl){ weiter'); + } $displayMore = false; break; case 'reject': @@ -646,6 +623,6 @@ if($action !== NULL) { // this is done to not require to reprogramm the whole st } if($displayMore){ - displayClanProfile($clan_id, $user_ida); + displayClanProfile($clan_id, $user_ida['id']); } ?> diff --git a/ag/include/clan.inc.php b/ag/include/clan.inc.php index 719e010..3ff1c5f 100644 --- a/ag/include/clan.inc.php +++ b/ag/include/clan.inc.php @@ -15,7 +15,7 @@ $GLOBALS['clan_buffered_instances'] = array (); function getClan($clanid, $buffer = TRUE) { if(!is_numeric($clanid) || $clanid === NULL) { return NULL; } - if(buffer && isset($GLOBALS['clan_buffered_instances'][$clanid])) { + if($buffer && isset($GLOBALS['clan_buffered_instances'][$clanid])) { return $GLOBALS['clan_buffered_instances'][$clanid]; // okay, we already buffered the clan :) } @@ -68,12 +68,12 @@ function getClanMemberBonusByLevel($level) { default: return 8; } - } +} function getMaximumMembers($clanid) { // okay, this is a more tricky calculation as this requires the information (are leader and co_leader the same person??) // the second parameter is the clan level. Each 2 levels (where the maximum clan level is about 20) one more member can - // be invited :) + // be invited :) $clan = getClan($clanid); if($clan === NULL){ return 0; } @@ -164,8 +164,8 @@ function inviteUser(array $user, $userid, array $clan = NULL){ } function fireMember($user, $member){ - $row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user['clan'])); - if($member != $row['leader'] && $member != $row['co_leader'] && ($user['id'] == $row['leader'] || $user['id'] == $row['co_leader'] || $member == $user['id'])){ + $clan = getClan($user['clan']); + if($member != $clan['leader'] && $member != $clan['co_leader'] && ($user['id'] == $clan['leader'] || $user['id'] == $clan['co_leader'] || $member == $user['id'])){ $sql = 'Update user set clan = NULL where id = '.$member.' AND clan = '.$user['clan']; // echo $sql.'
'; mysql_query($sql); @@ -174,11 +174,12 @@ function fireMember($user, $member){ mysql_query($sql); if($user['id'] != $member) { sendMessage($user['nickname'], $member, 'Clan rauswurf!', 'Du wurdest von '.$user['nickname'].' aus deinem Clan geworfen. Du wirst dir wohl einen neuen suchen müssen!'); - } else if(getClanMembersCount($user['clan']) == 0) { + } else if($clan['exp'] == 0 && $clan['level'] == 1 && getClanMembersCount($user['clan']) == 0) { mysql_query('DELETE FROM clan WHERE id =' .$user['clan']); } // delete the participation in open clan fights! Thats tricky because the user itself is not stored in the database!! + mysql_query('DELETE FROM clan_challenge_whitelist WHERE clan_id = ' .$clan['id'] . ' AND user_id = ' .$user['id']); mysql_query('DELETE FROM clan_challenge_participants WHERE clan_challenge_id in (SELECT clan_challenge_id FROM clan_challenge where calculated = FALSE) and char_id IN (Select id FROM chars where besitzer = '.$user['id'].')'); } } else{ @@ -199,17 +200,17 @@ function getAllClans() { return $clans; } -function joinClan($user, $clanid){ +function joinClan($user, $clanid, $check_invitation = true){ // last chance to lock the clan if in the old situation it was having to few members ;) isClanLocked($clanid); // we only require the calculation not the result! $sql = 'SELECT * FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid.' and valid > now();'; $clan_user = mysql_fetch_assoc(mysql_query($sql)); - if($clan_user){ - $clan = getClan($clanid); - $members = getClanMembersCount($clanid); - $members_max = getMaximumMembers($clan['id']); + if($clan_user || !$check_invitation){ + $clan = getClan($clanid); + $members = getClanMembersCount($clanid); + $members_max = getMaximumMembers($clan['id']); if($members >= $members_max){ displayErrorMessage(NULL,'Konnte die Einladung des Clans nicht annehmen (Clan voll)!',displayHistoryBackLink()); @@ -220,10 +221,13 @@ function joinClan($user, $clanid){ mysql_query($sql); // unset the leader if the user is moving from one clan to another - mysql_query('UPDATE clan SET leader = NULL WHERE leader = ' .$user['id']); - mysql_query('UPDATE clan SET co_leader = NULL WHERE co_leader = ' .$user['id']); + mysql_query('UPDATE clan SET leader = NULL WHERE leader = ' .$user['id'] . ' and id != ' .$clanid); + mysql_query('UPDATE clan SET co_leader = NULL WHERE co_leader = ' .$user['id'] . ' and id != ' .$clanid); + mysql_query('DELETE FROM clan_challenge_whitelist WHERE clan_id = ' .$clanid . ' AND user_id = ' .$user['id']); - displayErrorMessage('Aufgenommen','Du wurdest erfolgreich in den Clan aufgenommen!','weiter'); + if($check_invitation) { + displayErrorMessage('Aufgenommen','Du wurdest erfolgreich in den Clan aufgenommen!','weiter'); + } } } else{ displayErrorMessage(NULL,'Konnte die Einladung des Clans nicht annehmen!',displayHistoryBackLink()); @@ -241,6 +245,86 @@ function denyClan($user, $clanid){ } } +function deleteClan($userid) { + $user = getUser($userid); + $clanid = $user['clan']; + $clan = getClan($clanid); + + if($userid != $clan['leader']) { + return 'Du kannst den Clan nicht auflösen!'; + } + + // Okay notify the members :) + + $qry = mysql_query('SELECT id FROM user WHERE clan = '.$user['clan']); + while($member = mysql_fetch_assoc($qry)) { + sendMessage($user['nickname'], $member['id'], 'Clan wurde gelöscht!', 'Dein Clan wurde von '.$user['nickname'].' gelöscht. Du wirst dir wohl einen neuen suchen müssen!'); + } + + // Check if this clan is level 0 and has 0 exp ... + if($clan['exp'] == 0 && $clan['level'] == 1) { + // really do delete the clan !! + mysql_query('DELETE FROM clan where id = '.$user['clan']); + } else { + // cleanup the clan! + $sql1 = 'UPDATE user SET clan = NULL WHERE clan = ' . $clanid; + $sql2 = 'UPDATE clan SET leader = NULL, co_leader = NULL WHERE id = ' .$clanid; + $sql3 = 'DELETE FROM clan_challenge_whitelist WHERE clan_id = ' .$clanid; // cleanup the whitelist + +// echo $sql1 . '
'; +// echo $sql2 . '
'; + + mysql_query($sql1); + mysql_query($sql2); + } + return NULL; + +} + +function conquerClan($clanid, $userid) { + // It is possible to enter a clan that is empty :) + $user = getUser($userid); + $result = mysql_fetch_row(mysql_query('SELECT count(*) FROM user WHERE clan = ' . $clanid)); + if($result[0] != 0) { + return 'Der Clan ('.$clanid.') ist nicht leer!'; + } + + $sql = 'UPDATE clan SET leader = ' . $userid . ' WHERE leader is NULL AND id = '. $clanid; + mysql_query($sql); + + $done = mysql_affected_rows() > 0; + if(!$done) { + return 'Der Clan ist schon übernommen worden!'; + } + + // Cool we got em !! Now move to the new clan :) + joinClan($user, $clanid, false); + return NULL; +} + +function setMeAsLeader($user){ + mysql_query('UPDATE clan set leader = '.$user['id'].' WHERE id = '.$user['clan'].' and leader IS null AND co_leader IS null'); + return mysql_affected_rows() > 0; + +} + +function sendClanNewsletter($user, $text){ + $qry = mysql_query('SELECT * FROM clan WHERE id = ' . $user['clan']); + $clan = mysql_fetch_assoc($qry); + + $errors = FALSE; + $sql = 'SELECT id FROM user WHERE clan='.$user['clan']; + $clans = mysql_query($sql); + while($row = mysql_fetch_assoc($clans)) { + $errors |= !sendMessage($user['nickname'], $row['id'], $clan['clanname'].' Nachricht', $text); + } + if($errors) { + displayErrorMessage(NULL,'Beim Versenden sind Fehler aufgetreten', 'weiter...'); + } else { + displayErrorMessage(NULL,'Nachricht erfolgreich verschickt', 'weiter...'); + } +} + ?> diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php index cf19214..685c230 100644 --- a/ag/include/clan_fights.inc.php +++ b/ag/include/clan_fights.inc.php @@ -268,7 +268,7 @@ function denyChallengeRequest($challenged_clan, array $user) { * @param bool $buffer */ function getChallenge($challenge_id, $buffer = TRUE) { - if(buffer && isset($GLOBALS['clan_challenge_buffered_instances'][$challenge_id])) { + if($buffer && isset($GLOBALS['clan_challenge_buffered_instances'][$challenge_id])) { return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :) } @@ -364,6 +364,9 @@ function getHistoricalChallengeIDs($clanid, $limit = NULL) { // Checks if the clan is locked, will lock it if required! function isClanLocked($clanid) { + if(!is_numeric($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.'
'; @@ -680,4 +683,15 @@ function getClanFightCapableClanIds() { return $ids; } +/** + * Checks if the user is authorized to coordinate clanfights (if a id is given, it checks this for a given clan_fight) + * + * @param int $clan_id the clan that is in scope + * @param int $user_id the user 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) { + return true; +} + ?> diff --git a/db/animegame_svn.sql b/db/animegame_svn.sql index ff26e82..1e8e0f8 100644 --- a/db/animegame_svn.sql +++ b/db/animegame_svn.sql @@ -348,8 +348,9 @@ CREATE TABLE `clan` ( `homepage` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Keine', `banner` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', `level` int(2) NOT NULL DEFAULT '1', - `min_exp` int(20) NOT NULL DEFAULT '0', + `exp` int(20) NOT NULL DEFAULT '0', `elo` int(11) NOT NULL DEFAULT '1000', + `inactive` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `leader` (`leader`), KEY `co_leader` (`co_leader`), @@ -358,6 +359,23 @@ CREATE TABLE `clan` ( ) ENGINE=InnoDB AUTO_INCREMENT=787 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +DROP TABLE IF EXISTS `clan_challenge_whitelist`; +CREATE TABLE `clan_challenge_whitelist` ( + `clan_id` INTEGER NOT NULL, + `user_id` INTEGER NOT NULL, + PRIMARY KEY (`clan_id`, `user_id`), + CONSTRAINT `fk_clan_ch_whitelist_usr` FOREIGN KEY `fk_clan_ch_whitelist_usr` (`user_id`) + REFERENCES `user` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_clan_ch_whitelist_clan` FOREIGN KEY `fk_clan_ch_whitelist_clan` (`clan_id`) + REFERENCES `clan` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE +) +ENGINE = InnoDB +CHARACTER SET utf8 COLLATE utf8_general_ci; + -- -- Definition of table `clan_challenge_clans` @@ -368,9 +386,12 @@ CREATE TABLE `clan_challenge_clans` ( `clan_challenge_id` int(11) NOT NULL, `clan_id` int(11) NOT NULL, `elo` int(11) NOT NULL, + `clan_coordinator` int(11) DEFAULT NULL, PRIMARY KEY (`clan_id`,`clan_challenge_id`), KEY `clan_ch_clans_ch_id` (`clan_challenge_id`), - CONSTRAINT `clan_ch_clans_ch_id` FOREIGN KEY (`clan_challenge_id`) REFERENCES `clan_challenges` (`clan_challenge_id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `clan_ch_clans_ch_id` FOREIGN KEY (`clan_challenge_id`) REFERENCES `clan_challenges` (`clan_challenge_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_clan_ch_coordinator` FOREIGN KEY `fk_clan_ch_coordinator` (`clan_coordinator`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE SET NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -402,6 +423,7 @@ CREATE TABLE `clan_challenge_requests` ( `clan_requester` int(11) NOT NULL, `clan_challenged` int(11) NOT NULL, `challenged_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `clan_challenge_creator` int(11) DEFAULT NULL, `type` int(11) NOT NULL, `anzahl_chars` int(11) NOT NULL DEFAULT '5', `active` tinyint(1) NOT NULL DEFAULT '1', @@ -409,6 +431,7 @@ CREATE TABLE `clan_challenge_requests` ( KEY `fk_clan_challenge_requests_challenged` (`clan_challenged`), CONSTRAINT `fk_clan_challenge_requests_challenged` FOREIGN KEY (`clan_challenged`) REFERENCES `clan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_clan_challenge_requests_requester` FOREIGN KEY (`clan_requester`) REFERENCES `clan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `fk_clan_challenge_requests_creator` FOREIGN KEY (`clan_challenge_creator`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Macht übernehmenKeine LeaderClan übernehmen'.$leader.'
Clan auflösen Clan - löschen