/** * Render the div full of chat messages. * @param $chatlength Essentially the limit on the number of messages. **/ function render_chat_messages($chatlength, $show_elipsis = null) { // Eventually there might be a reason to abstract out get_chats(); $sql = new DBAccess(); $sql->Query("SELECT sender_id, uname, message, age(now(), date) as ago FROM chat join players on chat.sender_id = player_id ORDER BY chat_id DESC LIMIT {$chatlength}"); // Pull messages $chats = $sql->fetchAll(); $message_rows = ''; $messageCount = $sql->QueryItem("select count(*) from chat"); if (!isset($show_elipsis) && $messageCount > $chatlength) { $show_elipsis = true; } $res = "<div class='chatMessages'>"; $previous_date = null; $skip_interval = 3; // minutes foreach ($chats as $messageData) { $l_ago = time_ago($messageData['ago'], $previous_date); $message_rows .= "<li><<a href='player.php?player_id={$messageData['sender_id']}'\n\t\t target='main'>{$messageData['uname']}</a>> " . out($messageData['message']) . " <span class='chat-time'>{$l_ago}</span></li>"; $previous_date = $messageData['ago']; // Store just prior date. } $res .= $message_rows; if ($show_elipsis) { // to indicate there are more chats available $res .= ".<br>.<br>.<br>"; } $res .= "</div>"; return $res; }
/** * Attack function library. * @package combat * @subpackage lib_attack **/ function update_last_attack_time($player_id, $sql = null) { if (!$sql) { $sql = new DBAccess(); } $update_last_attacked = "update players set last_started_attack=now() where player_id='" . intval($player_id) . "'"; $sql->Query($update_last_attacked); // updates the timestamp of the last_attacked column to slow excessive attacks. }
function get_recent_attackers() { $recent_attackers = array(); $user_id = get_user_id(); $sql = new DBAccess(); $q = 'select distinct send_from, uname, level, health from events join players on send_from = player_id where send_to = \'' . sql($user_id) . '\' limit 20'; $sql->Query($q); $recent_attackers = $sql->FetchAll(); return $recent_attackers; }
// *** Max time a person is kept online without being active. $turn_regen_threshold = 100; $out_display = array(); // ******************* END OF CONSTANTS *********************** $sql->Update("UPDATE time SET amount = amount+1 WHERE time_label='hours'"); // Update the hours ticker. $sql->Update("UPDATE time SET amount = 0 WHERE time_label='hours' AND amount>=24"); // Rollover the time to hour zero. $sql->Update("UPDATE players SET turns = 0 WHERE turns < 0"); $sql->Update("UPDATE players SET bounty = 0 WHERE bounty < 0"); $sql->Update("UPDATE players SET turns = turns+1 WHERE class ='Blue' and turns < " . $turn_regen_threshold); // Blue turn code $sql->Update("UPDATE players SET turns = turns+2 where turns < " . $turn_regen_threshold); // add 2 turns on the hour, up to 100. // Database connection information here $sql->Query("DELETE FROM ppl_online WHERE activity < (now() - interval '" . $maxtime . "')"); //Skip error logging this for now. $out_display['Inactive Browsers Deactivated'] = $sql->a_rows; // *** HEAL *** $sql->Update("UPDATE players SET health=numeric_smaller(health+8, {$maximum_heal}) " . "WHERE health BETWEEN 1 AND {$maximum_heal} AND NOT " . "cast(status&" . POISON . " AS boolean)"); // ****************************** RESURRECTION CHECK, DEPENDENT UPON RESURRECTION_TIME **************************** /* OLD System $minimum = 2; $by_percent = true; $maximum = 4; $resurrect_info = revive_appropriate_players($minimum, $maximum, $by_percent, $just_testing=false); assert($resurrect_info['revived']<$resurrect_info['target_number']); */ // New system, potentially move to the halfhour, and then half the major_revive_percent? $params = array('full_max' => 50, 'minor_revive_to' => 150, 'major_revive_percent' => 5); $resurrected = revive_players($params);
<?php require_once dirname(__FILE__) . '/../lib/base.inc.php'; // Currently this forces crons locally to be called from the cron folder. require_once LIB_ROOT . "specific/lib_deity.php"; // Deity-specific functions $sql = new DBAccess(); $sql->Query("truncate player_rank"); $sql->Query("SELECT setval('player_rank_rank_id_seq1', 1, false);"); $sql->Query("insert into player_rank (_player_id, score) select player_id, ((level*900) + (CASE WHEN gold < 1 THEN 0 ELSE floor(gold/200) END) + (kills*3) - (days*5)) AS score from players WHERE confirmed = 1 ORDER BY score DESC"); # Running from a cron script, we don't want any output unless we have an error $out_display['Ranked Players'] = $sql->a_rows; // *********** // Log output: $logMessage = "DEITY_FIVEMINUTE STARTING: " . date(DATE_RFC1036) . "\n"; foreach ($out_display as $loopKey => $loopRowResult) { $logMessage .= "DEITY_FIVEMINUTE: Result type: {$loopKey} yeilded result number: {$loopRowResult} \n"; } $logMessage .= "DEITY_FIVEMINUTE ENDING: " . date(DATE_RFC1036) . "\n"; $log = fopen(LOGS . 'deity.log', 'a'); fwrite($log, $logMessage); fclose($log);