fixed buffer problem ... also implemented some new stuff for whitelist (so non-leader may start cfs)

main
hecht 13 years ago
parent da1a0deb76
commit 14bf0944c7

@ -101,10 +101,8 @@ function displayClanProfileReadOnly($clan, $ownclan, $userid){
} else {
$openChallengeRequestsDisplay[] = displayClanLink($request['clan_challenged']) ;
}
}
?>
<div align="center">
<table width="100%">
@ -128,8 +126,10 @@ function displayClanProfileReadOnly($clan, $ownclan, $userid){
if($leader == null && $coleader == null){
if($ownclan) {
echo '<td rowspan="2"><a href="index.php?as=clan/clan_info&action=putsch">Macht &uuml;bernehmen</a></td>';
} else {
} else if(count($member) > 0){
echo '<td rowspan="2">Keine Leader</td>';
} else {
echo '<td rowspan="2"><a href="index.php?as=clan/clan_info&action=putsch&clan_id='.$clan['id'].'">Clan &uuml;bernehmen</a></td>';
}
} else{
echo '<td>'.$leader.'</td>';
@ -375,8 +375,8 @@ function displayClanProfileEditable($clan, $userid){
<tr>
<th align="left">Clan aufl&ouml;sen</th>
<td><a
href="javascript:if(confirm('Wirklich l&ouml;schen?')==true) window.location.href='index.php?as=clan/clan_info&action=kill'">Clan
l&ouml;schen</a></td>
href="javascript:if(confirm('Wirklich aufl&ouml;sen? der Clan kann ggf. durch jemand &uuml;bernommen werden!')==true) window.location.href='index.php?as=clan/clan_info&action=kill'">Clan
aufl&ouml;sen (Achtung! Clans ggf. nur geleert!)</a></td>
</tr>
<tr>
<td>&nbsp;</td>
@ -408,8 +408,9 @@ function displayClanProfileEditable($clan, $userid){
<?php
}
function displayClanProfile($clanid, $user){
function displayClanProfile($clanid, $userid){
$clan = getClan($clanid, FALSE);
$user = getUser($userid, false);
if(!$clan) {
echo displayErrorMessage(NULL, 'Es gibt den Clan mit der ID ' .$clanid.' nicht oder nicht mehr!', displayHistoryBackLink());
return;
@ -422,28 +423,6 @@ function displayClanProfile($clanid, $user){
}
}
function setMeAsLeader($user){
mysql_query('UPDATE clan set leader = '.$user['id'].' WHERE id = '.$user['clan'].' and leader is null and co_leader is null');
}
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', '<a href="index.php?as=clan/clan_info">weiter...</a>');
} else {
displayErrorMessage(NULL,'Nachricht erfolgreich verschickt', '<a href="index.php?as=clan/clan_info">weiter...</a>');
}
}
function setProfile($what, $value1, $value2, $clanid, $rootlvl){
if($rootlvl < 1) {
return 'Du hast keine Rechte um diese Aktion auszuf&uuml;hren!';
@ -568,21 +547,6 @@ function displayEdit($what, $clanid, $rootlvl){
<?php
}
function deleteClan($user){
$row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user['clan']));
if($user['id'] == $row['leader']){
$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&ouml;scht. Du wirst dir wohl einen neuen suchen m&uuml;ssen!');
}
mysql_query('DELETE FROM clan where id = '.$user['clan']);
} else{
echo displayErrorMessage(NULL, 'Du kannst den Clan nicht aufl&ouml;sen!', displayHistoryBackLink());
}
}
if($action !== NULL) { // this is done to not require to reprogramm the whole stuff!
@ -601,6 +565,7 @@ if($action !== NULL) { // this is done to not require to reprogramm the whole st
$row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user_ida['clan']));
if($row['leader'] != $user_ida['id'] && $row['co_leader'] != $user_ida['id']){
displayErrorMessage(NULL, 'Du bist weder Leader noch Co-Leader des Clans!', displayHistoryBackLink());
$displayMore = false;
} else if(isset($value1) || isset($value2)){
$errorMsg = setProfile($what, $value1, $value2, $user_ida['clan'], $rootlvl);
} else{
@ -608,7 +573,7 @@ if($action !== NULL) { // this is done to not require to reprogramm the whole st
$displayMore = false;
}
if($errorMsg !== NULL) {
echo displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink());
displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink());
$displayMore = false;
}
@ -620,10 +585,22 @@ if($action !== NULL) { // this is done to not require to reprogramm the whole st
}
break;
case 'putsch':
setMeAsLeader($user_ida);
if($clan_id == $user_ida['clan']) {
if(!setMeAsLeader($user_ida)) {
displayErrorMessage(NULL, 'Konnte den Clan nicht übernehmen ...', displayHistoryBackLink());
$displayMore = false;
}
} else if ($clan_id !== NULL && ($errorMsg = conquerClan($clan_id, $user_ida['id'])) !== NULL) {
displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink());
$displayMore = false;
}
break;
case 'kill':
deleteClan($user_ida);
if(($errorMsg = deleteClan($user_ida['id'])) != NULL) {
displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink());
} else {
displayErrorMessage(NULL, 'Clan erfolgreich aufgel&ouml;st.', '<a href="index.php">weiter</a>');
}
$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']);
}
?>

@ -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.'<br>';
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&uuml;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!','<a href="index.php?as=clan/clan_info">weiter</a>');
if($check_invitation) {
displayErrorMessage('Aufgenommen','Du wurdest erfolgreich in den Clan aufgenommen!','<a href="index.php?as=clan/clan_info">weiter</a>');
}
}
} 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&ouml;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&ouml;scht. Du wirst dir wohl einen neuen suchen m&uuml;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 . '<br>';
// echo $sql2 . '<br>';
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 &uuml;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', '<a href="index.php?as=clan/clan_info">weiter...</a>');
} else {
displayErrorMessage(NULL,'Nachricht erfolgreich verschickt', '<a href="index.php?as=clan/clan_info">weiter...</a>');
}
}
?>

@ -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.'<br>';
@ -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;
}
?>

@ -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;

Loading…
Cancel
Save