function check_for_resurrection($echo = FALSE) { $dbObj = new DBAccess(); $dbObj->Update("UPDATE players\n SET status = 0,\n health = (CASE WHEN class='White' THEN (150+(level*3)) ELSE 100 END)\n WHERE confirmed = 1\n AND health < 0\n AND resurrection_time = (SELECT amount from time where time_label='hours')\n AND\n ( days<31 OR\n \t\t\t\t(\n \t\t\t\t\t((days %\n \t\t\t\t\t cast(floor(days / 10) AS integer))\n \t\t\t\t\t =0\n \t\t\t\t\t)\n \t\t\t\t)\n \t\t\t)\n "); // *** Resurrect and heal all players at this countdown spot. if ($echo) { $healedPlayers = $dbObj->a_rows; echo "Number of healed/resurrected players: " . $healedPlayers; } }
function update_activity_log($username) { $sql = new DBAccess(); $user_ip = $_SERVER['REMOTE_ADDR']; $sql->Update("UPDATE players SET days = 0, ip = '{$user_ip}' WHERE uname='{$username}'"); }
$logMessage = "DEITY_HOURLY STARTING: " . date(DATE_RFC1036) . "\n"; $score = get_score_formula(); /// @ TODO - This script should be secured. $sql = new DBAccess(); // ******************* INITIALIZATION ****************************** $poisonHealthDecrease = 50; // *** The amount that poison decreases health each half-hour. $maximum_heal = 150; $maximum_turns = 300; // *** Turn # beyond which you will drop back down to, though normal turn increase stops earlier. $maxtime = '6 hours'; // *** 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 ****************************
<?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 $logMessage = "DEITY_HALFHOUR STARTING: " . date(DATE_RFC1036) . "\n"; $regen_rate = 1; $turn_regen_threshold = 100; $maximum_heal = 150; $maxtime = '15 minutes'; // *** Max time a person is kept online without being active. 6 hours is not online. 15m minustes is better $score = get_score_formula(); $sql = new DBAccess(); $sql->Update("UPDATE players SET turns = 0 WHERE turns < 0"); // if anyone has less than 0 turns, set it to 0 $sql->Update("UPDATE players SET turns = turns+{$regen_rate} WHERE turns < " . $turn_regen_threshold); // add turns at the regen rate for anyone below the threshold $sql->Update("UPDATE players SET bounty = 0 WHERE bounty < 0"); // if anyone has negative bounty, set it to 0 $sql->Query("DELETE FROM ppl_online WHERE activity < (now() - interval '" . $maxtime . "')"); $out_display['Inactive Browsers Deactivated'] = $sql->a_rows; // *** HEAL CODE *** $sql->Update("UPDATE players SET health = numeric_smaller(health+8+cast(floor(level/10) AS int), {$maximum_heal})\n\t WHERE health BETWEEN 1 AND {$maximum_heal} AND NOT cast(status&" . POISON . " AS bool)"); // Higher levels now heal faster. // ************** // Visual output: foreach ($out_display as $loopKey => $loopRowResult) { $logMessage .= "DEITY_HALFHOUR: Result type: {$loopKey} yeilded result number: {$loopRowResult}\n"; } $logMessage .= "DEITY_HALFHOUR ENDING: " . date(DATE_RFC1036) . "\n";
function confirm_player($player_name, $confirmation = 0, $autoconfirm = false) { $sql = new DBAccess(); // Preconfirmed or the email didn't send, so automatically confirm the player. $require_confirm = $autoconfirm ? '' : "and confirm = '{$confirmation}'"; $up = "update players set confirmed = 1, confirm='55555' where uname = '" . $player_name . "' " . $require_confirm; $up_res = $sql->Update($up); $res = $autoconfirm ? true : !!$up_res; return $res; }
function setStatus($who, $what) { //if (!is_numeric($what)) // *** If the status being sent in isn't a number... //{ // (isset($status_array[$what])? ' //} global $sql; if (!$sql) { $sql = new DBAccess(); } $sql->Update("UPDATE players SET status = {$what} WHERE uname = '{$who}'"); if ($who == $_SESSION['username']) { $_SESSION['status'] = $what; if ($what == 0) { echo "<br>You have returned to normal.<br>\n"; } else { if ($what == 1) { echo "<br>You have been poisoned.<br>\n"; } else { if ($what == 2) { echo "<br>You are now stealthed.<br>\n"; } } } } return $what; }
/** * Revive up to a small max in minor hours, and a stable percent on major hours. * Defaults * sample_use: revive_players(array('just_testing'=>true)); * @params array('full_max'=>80, 'minor_revive_to'=>100, 'major_revive_percent'=>5, * 'just_testing'=>false) **/ function revive_players($params = array()) { // Previous min/max was 2-4% always, ~3000 players, so 60-120 each time. // In: full_max, default 80% $full_max = isset($params['full_max']) ? $params['full_max'] : 80; // minor_revive_to, default 100 $minor_revive_to = isset($params['minor_revive_to']) ? $params['minor_revive_to'] : 100; // major_revive_percent, default 5% $major_revive_percent = isset($params['major_revive_percent']) ? $params['major_revive_percent'] : 5; $just_testing = isset($params['just_testing']) ? 'true' : 'false'; $major_hour = 3; // Hour for the major revive. $revive_amount = 0; // Initial. /* New schedule should be: 1: revive to 100 2: revive to 100 (probably 0) 3: revive 150, (250 total) to a max of 80% of total, ~2500. 4: revive to 100 (almost certainly no more) 5: revive to 100 (almost certainly no more) 6: revive 150, (400 total) to a max of 80% of total, ~2500 7: ...etc. */ // SQL pulls. $db = new DBAccess(); // Determine the total dead (& confirmed). $sel_dead = 'select count(*) from players where health<1 and confirmed=1'; $dead_count = $db->QueryItem($sel_dead); // If none dead, return false. if (!$dead_count) { return array(0, 0); } // Determine the total confirmed. $sel_total_active = 'select count(*) from players where confirmed=1'; $total_active = $db->QueryItem($sel_total_active); // Calc the total alive. $total_alive = $total_active - $dead_count; // Determine major or minor based on the hour. $sel_current_time = "SELECT amount from time where time_label='hours'"; $current_time = $db->QueryItem($sel_current_time); assert(is_numeric($current_time)); $major = false; if ($current_time % $major_hour == 0) { $major = true; } // If minor, and total_alive is more than minor_revive_to-1, return 0/total. if (!$major) { // minor if ($total_alive > $minor_revive_to - 1) { // minor_revive_to already met. return array(0, $dead_count); } else { // else revive minor_revive_to - total_alive. $revive_amount = floor($minor_revive_to - $total_alive); } } else { // major. $percent_int = floor($major_revive_percent / 100 * $total_active); if ($dead_count < $percent_int) { // If major, and total_dead is less than target_num (major_revive_percent*total, floored) // just revive those that are dead. $revive_amount = $dead_count; } else { // Else revive target_num (major_revive_percent*total, floored) $revive_amount = $percent_int; } } //die(); assert(isset($revive_amount)); assert(isset($current_time)); assert(isset($just_testing)); assert(isset($dead_count)); assert(isset($major)); // Actually perform the revive on those integers. // Use the order by clause to determine who revives, by time, days and then by level, using the limit set previously. //select uname, player_id, level,floor(($major_revive_percent/100)*$total_active) days, resurrection_time from players where confirmed = 1 AND health < 1 ORDER BY abs(8 - resurrection_time) asc, level desc, days asc $select = "select player_id from players where confirmed = 1 AND health < 1 ORDER BY abs(" . intval($current_time) . "\n \t- resurrection_time) asc, level desc, days asc limit " . $revive_amount; $up_revive_players = "UPDATE players\n SET status = 0,\n health =\n \tCASE WHEN " . $just_testing . "\n \tTHEN health\n \tELSE\n \t\t(\n \t\tCASE WHEN class='White'\n \t\tTHEN (150+(level*3))\n \t\tELSE (100+(level*3)) END\n \t\t)\n \tEND\n WHERE\n player_id IN (" . $select . ")\n "; $db->Update($up_revive_players); $truly_revived = $db->getAffectedRows(); // Return the 'revived/total' actually revived. return array($truly_revived, $dead_count); }