it is now possible to assign a char from an offline user into a clanfight. Additionally the clan fight coordinators may kick chars from a clan challenge. Both actions will result into a notify pm. As there is a limit of the maximum amount of chars that can be assigned from offline users (also they have to be in free state) it is possible for the owner to give its okay when coming online.

main
hecht 13 years ago
parent 792b3ac6e3
commit 6a1932ea54

@ -33,10 +33,17 @@ $type = validateUnsignedInteger($_GET['type'], null);
if($action == null) {
$action = $_POST['action'];
}
if($char_id == null) {
$char_id = validateUnsignedInteger($_POST['char'], null);
if(isset($_POST['other_submit'])) {
$slot = validateUnsignedInteger($_POST['oslot'], null);
$char_id = validateUnsignedInteger($_POST['o_char'], null);
} else {
if($char_id == null) {
$char_id = validateUnsignedInteger($_POST['char'], null);
}
$slot = validateUnsignedInteger($_POST['slot'], null);
}
$slot = validateUnsignedInteger($_POST['slot'], null);
if($clan_challange_id == null) {
$clan_challange_id = validateUnsignedInteger($_POST['challenge'], null);
}
@ -132,6 +139,9 @@ function displayShowChallenge($clan_challenge_id, $user) {
$user_clan_chars = getParticipatingCharIDs($clan_challenge_id, $user_clan['id']);
$other_clan_chars = getParticipatingCharIDs($clan_challenge_id, $other_clan['id']);
$user_chars = getCharsOfUser($user['id']);
$authorized = isAuthorizedClanfightCoordinator($user['clan'], $user['id'], $clan_challenge_id);
$slots = array();
?>
@ -156,6 +166,9 @@ function displayShowChallenge($clan_challenge_id, $user) {
echo '</tr>';
}
?>
<tr>
<th colspan="3"><hr/></th>
</tr>
<tr>
<th colspan="3"><?php echo $user_clan['clanname'];?></th>
</tr>
@ -165,10 +178,13 @@ function displayShowChallenge($clan_challenge_id, $user) {
echo '<td><b>Slot '.$i.'</b></td>';
if($user_clan_chars[$i] != null) {
$char = getChar($user_clan_chars[$i]);
$participant = getParticipatingChar($clan_challenge_id, $user_clan['id'], $user_clan_chars[$i]);
$char_owner = getOwnerOfChar($char['id']);
echo '<td align="center">'.generateCharLinkByID($char['id']);
echo '('.generateUserLinkByID($char_owner['id'], FALSE).')</td>';
if(isUserOwnerOf($user['id'], $char['id'])) {
if(isUserOwnerOf($user['id'], $char['id']) && $participant['forced'] == TRUE) {
echo '<td align="center"><a href="index.php?as=clan/kampf_info&action=joinchallenge&challenge='.$clan_challenge_id.'&char='.$char['id'].'">ok</a> | <a href="index.php?as=clan/kampf_info&action=leavechallenge&challenge='.$clan_challenge_id.'&char='.$char['id'].'">abmelden</a></td>';
} else if(isUserOwnerOf($user['id'], $char['id']) || $authorized) {
echo '<td align="center"><a href="index.php?as=clan/kampf_info&action=leavechallenge&challenge='.$clan_challenge_id.'&char='.$char['id'].'">abmelden</a></td>';
}
} else {
@ -178,12 +194,14 @@ function displayShowChallenge($clan_challenge_id, $user) {
echo '</tr>';
}
?>
<tr>
<th colspan="3"><hr /></th>
</tr>
<tr>
<th colspan="3">Teilnahme</th>
</tr>
<tr>
<td><b>Charakter:</b></td>
<th>Charakter:</th>
<td align="center"><select id="input" name="char">
<option value="-1">Charakter ausw&auml;hlen</option>
<?php
@ -195,7 +213,7 @@ function displayShowChallenge($clan_challenge_id, $user) {
</td>
</tr>
<tr>
<td><b>Slot:</b></td>
<th>Slot:</th>
<td align="center"><select id="input" name="slot">
<option value="-1">Slot ausw&auml;hlen</option>
<?php
@ -207,9 +225,100 @@ function displayShowChallenge($clan_challenge_id, $user) {
</td>
</tr>
<tr>
<td align="center" colspan="3"><input id="input" type=submit
<td align="center" colspan="3"><input id="input" name="submit" type="submit"
value='anmelden'></td>
</tr>
<?php if($authorized) {
$qry = db_query('SELECT user.id AS user_id, chars.id AS char_id, user.nickname AS user_name, chars.name AS char_name FROM user inner join chars on user.id = chars.besitzer where clan = 769 and user.id NOT IN (Select besitzer from chars inner join clan_challenge_participants on chars.id = clan_challenge_participants.char_id WHERE clan_challenge_id = '.$clan_challenge_id.' and clan_id = '.$user['clan'].')');
$users = array();
while($row = mysql_fetch_assoc($qry)) {
if(!isset($users[$row['user_id']])){
$users[$row['user_id']] = array('user_name' => $row['user_name']);
}
$users[$row['user_id']]['chars'][] = array('char_name' => $row['char_name'], 'char_id' => $row['char_id']);
}
// print_r($users);
?>
<tr>
<th colspan="3"><hr /></th>
</tr>
<tr>
<th colspan="3">Chars zuweisen von Offline Usern:</th>
</tr>
<tr>
<th>User:</th>
<td align="center">
<script type="text/javascript">
function switchDaSelect(){
user_select = document.getElementsByName('o_user')[0];
char_select = document.getElementsByName('o_char')[0];
// alert(user_select.value);
char_select.options.length = 1;
<?php
foreach($users as $user_id => $user_info){
$first = TRUE;
if($user_id != $user['id']) {
// echo '<option value="'.$user_id.'">'.$user_info['user_name'].'</option>';
echo 'if(user_select.value == '.$user_id.') {'. PHP_EOL;
foreach ($user_info['chars'] as $char_info) {
if($first) {
echo 'char_select.options[char_select.options.length] = new Option(\''.$char_info['char_name'].'\', \''.$char_info['char_id'].'\', false, true);'. PHP_EOL;
$first = !$first;
} else {
echo 'char_select.options[char_select.options.length] = new Option(\''.$char_info['char_name'].'\', \''.$char_info['char_id'].'\');'. PHP_EOL;
}
}
echo '}'. PHP_EOL;
}
}
?>
}
</script>
<select id="input" name="o_user" onchange="javascript:switchDaSelect()">
<option value="-1">User ausw&auml;hlen</option>
<?php
foreach($users as $user_id => $user_info){
if($user_id != $user['id'] && !isUserOnline($user_id)) {
echo '<option value="'.$user_id.'">'.$user_info['user_name'].'</option>';
}
}
?>
</select>
</td>
</tr>
<tr>
<th>Charakter:</th>
<td align="center">
<select id="input" name="o_char">
<option value="-1">Charakter ausw&auml;hlen</option>
</select>
</td>
</tr>
<tr>
<th>Slot:</th>
<td align="center"><select id="input" name="oslot">
<option value="-1">Slot ausw&auml;hlen</option>
<?php
foreach($slots as $slot){
echo '<option value="'.$slot.'">'.$slot.'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td align="center" colspan="3"><input id="input" type="submit"
name="other_submit" value='anmelden'></td>
</tr>
<?php } ?>
<tr>
<td align="center" colspan="3"><?php echo '<a href="index.php?as=clan/kampf_info">zur&uuml;ck</a>';?>
</td>

@ -490,6 +490,13 @@ function getParticipatingCharIDs($clan_challenge_id, $clan_id) {
return $array;
}
function getParticipatingChar($clan_challenge_id, $clan_id, $char_id) {
$qry = db_query('SELECT * FROM clan_challenge_participants WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = ' .$clan_id . ' AND char_id = ' . $char_id);
$row = mysql_fetch_assoc($qry);
return $row;
}
function getClanLockedTime($clan_id) {
if(!isClanLocked($clan_id)) {
return 0;
@ -572,16 +579,27 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
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)) {
if(isAuthorizedClanfightCoordinator($clan['id'], $user['id'], $clan_challenge_id)) {
if(isUserOnline($char['besitzer'])) {
return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da der Besitzer online ist!';
}
// okay we may assign an additional char ;) // check if we have reached the limit is later!!
$forced = true;
$requestor = $user;
$user = getUser($char['besitzer']);
} else {
return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er dir nicht gehört!';
}
}
if($char['status'] != 'Frei') {
return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er nicht frei ist!';
// char is not free but is he already participating?
$participant = getParticipatingChar($clan_challenge_id, $clan['id'], $charid);
if(!$participant || !$participant['forced']) {
return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da er nicht frei ist!';
}
db_query('UPDATE clan_challenge_participants SET forced = FALSE WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = '.$clan['id'].' AND char_id = ' . $charid);
return NULL;
}
$clan_challenge = getChallenge($clan_challenge_id);
@ -598,7 +616,7 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
}
// block the user actions so we can ensure he won't register multiple of its chars here!
$resource = 'User:'.$user['id'];
$ressource = 'User:'.$user['id'];
if(!semaphoreUP($ressource)) {
return 'Du kannst den Char nicht an dem Kampf teilnehmen lassen, da du scheinbar gerade auch mit was anderem beschäftigt bist, versuche es bitte nochmal!';
}
@ -623,18 +641,18 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
}
$resource2 = 'Clan:'.$clan_id;
$ressource2 = 'Clan:'.$clan['id'];
if($forced && !semaphoreUP($ressource2)) {
semaphoreDown($ressource);
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) {
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!';
return 'Du kannst den Char nicht zuweisen, da die maximale Anzahl der erlaubten Zuweisungen ('.MAX_LEADER_ASSIGNED_CHARS.') schon erreicht ist!';
}
$sql = 'INSERT INTO clan_challenge_participants(clan_challenge_id, clan_id, char_id, slot, forced) values('.$clan_challenge_id.', '.$user['clan'].', '.$charid.', '.$slot.', ' .($forced?'TRUE':'FALSE') .')';
$res = mysql_query($sql);
@ -677,6 +695,11 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
// okay we now have a complete competition and the challenge is closed :)
return calculateChallenge($clan_challenge_id);
}
if($forced) {
sendMessage($requestor['nickname'], $char['besitzer'], 'Clanfightteilnahme', 'Dein Char ' . $char['name'] . ' wurde zu einem Clanfight hinzugezogen, du kannst ihn im Clanfight Men&uuml; abmelden oder dein OK geben, damit evtl. weitere Chars von offline Usern hinzugef&uuml;gt werden k&ouml;nnen!');
}
return NULL;
}
@ -695,8 +718,11 @@ function leaveChallenge($clan_challenge_id, array $user, $charid) {
return 'Du bist in keinem Clan!!';
}
$forced = false;
if($char['besitzer'] != $user['id']) {
if(!isAuthorizedClanfightCoordinator($clan['id'], $user['id'], $clan_challenge_id)) {
$forced = true;
// 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!';
}
@ -711,6 +737,10 @@ function leaveChallenge($clan_challenge_id, array $user, $charid) {
return 'Der Char kann nicht aus dem Kampf zurückgezogen werden.';
}
if($forced) {
sendMessage($user['nickname'], $char['besitzer'], 'Kick aus Clanfight', 'Dein Char ' . $char['name'] . ' wurde aus einem Clanfight gekickt!');
}
return NULL;
}
@ -993,7 +1023,7 @@ function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = N
// 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;
//echo $sql . '<br>';
// echo $sql . '<br>';
$row = mysql_fetch_row(mysql_query($sql));
if($row[0] <= 0) {
// okay, maybe its a leader ;)
@ -1050,8 +1080,8 @@ function calculateClanExperience(array $clan1, array $clan2, $winner) {
* @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));
$qry = db_query('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($qry);
return $row[0];
}

@ -31,6 +31,7 @@
$GLOBALS['semaphorecount'] = 0;
function semaphoreUP($ressource){
// echo 'semaphoreUp('.$ressource.')<br>' . PHP_EOL ;
if($GLOBALS['semaphorecount'] == 0){
ignore_user_abort(true); // Verarbeitung darf NICHT abgebrochen werden!!
// echo 'DEBUG: kritischer Bereich betreten<br>';

@ -19,12 +19,17 @@ function getUser($userid, $buffer_enabled = true) {
}
// Wenn Char nicht im Puffer ist, oder nicht gepuffert werden soll
if ($GLOBALS['user_buffered_instances'][$userid] == null || !$buffer_enabled) {
$user = mysql_fetch_assoc(mysql_query('SELECT * FROM user WHERE id = '.$userid));
$user = mysql_fetch_assoc(db_query('SELECT *, online_zeit between TIMESTAMPADD(Minute, -15, now()) and now() as online FROM user WHERE id = '.$userid));
$GLOBALS['user_buffered_instances'][$userid] = $user;
}
return $GLOBALS['user_buffered_instances'][$userid];
}
function isUserOnline($userid) {
$user = getUser($userid);
return $user['online'];
}
/**
*
* Returns the user of the Character. (attributes of the user-table should be added here if needed)

Loading…
Cancel
Save