function changelog_dohook($hook, $args) { switch ($hook) { case 'header-modules': $module = httppost('module') ?: httpget('module'); $op = httpget('op'); if ($module != '') { if (substr($op, -1) == 'e') { $op = substr($op, 0, -1); } else { if ($op == 'mass') { $method = array_keys(httpallpost())[1]; if (substr($method, -1) == 'e') { $method = substr($method, 0, -1); } $op = "mass {$method}"; $plural = 's'; } } require_once 'lib/gamelog.php'; if (is_array($module)) { $lastModule = array_pop($module); $module = implode(', ', $module); $module .= ",`@ and `^{$lastModule}"; } gamelog(sprintf_translate('`Q%sed`@ the `^%s`@ module%s.', $op, $module, $plural), get_module_setting('category')); } break; case 'village': if (get_module_setting('infonav')) { addnav($args['infonav']); addnav('View Changelog', 'runmodule.php?module=changelog&ret=village'); } break; case 'header-about': addnav('About LoGD'); addnav('View Changelog', 'runmodule.php?module=changelog&ret=about'); break; case 'newday-runonce': $gamelog = db_prefix('gamelog'); $date = date('Y-m-d H:i:s', strtotime('now')); $category = get_module_setting('category'); db_query("UPDATE {$gamelog} SET date = '{$date}' WHERE category = '{$category}'"); break; } return $args; }
function git_dohook($hook, $args) { switch ($hook) { case 'superuser': global $session; if ($session['user']['superuser'] & SU_MANAGE_MODULES) { addnav('Mechanics'); addnav('Git Pull', 'superuser.php?git=pull'); if (httpget('git') == 'pull') { require_once 'lib/gamelog.php'; shell_exec('git pull'); $output = shell_exec('git log --format=%B -1'); $output = explode(PHP_EOL, $output); unset($output[0]); $output = trim(implode(PHP_EOL, $output)); gamelog($output, get_module_setting('category', 'changelog')); debug('Successfully pulled from git!'); } } break; } return $args; }
$key = stripslashes($key); $val = stripslashes($val); set_module_setting($key, $val); if (!isset($old[$key]) || $old[$key] != $val) { output("Setting %s to %s`n", $key, $val); // Notify modules if ($key == "villagename") { debug("Moving companions"); $sql = "UPDATE " . db_prefix("companions") . " SET companionlocation = '" . addslashes($val) . "' WHERE companionlocation = '" . addslashes($old[$key]) . "'"; db_query($sql); } $oldval = ""; if (isset($old[$key])) { $oldval = $old[$key]; } gamelog("`@changed module setting `^{$module}.{$key}`@ from `3{$oldval}`@ to `#{$val}`0", "settings"); modulehook("changesetting", array("module" => $module, "setting" => $key, "old" => $oldval, "new" => $val), true); } } output("`^Module %s settings saved.`0`n", $module); } $save = ""; httpset('save', ""); } if ($save == "") { $info = get_module_info($module); if (count($info['settings']) > 0) { load_module_settings($mostrecentmodule); $msettings = array(); while (list($key, $val) = each($info['settings'])) { if (is_array($val)) {
$key = stripslashes($key); $val = stripslashes($val); set_module_setting($key, $val); if (!isset($old[$key]) || $old[$key] != $val) { output("Setting %s to %s`n", $key, $val); // Notify modules if ($key == "villagename") { debug("Moving companions"); $sql = "UPDATE " . db_prefix("companions") . " SET companionlocation = '" . addslashes($val) . "' WHERE companionlocation = '" . addslashes($old[$key]) . "'"; db_query($sql); } $oldval = ""; if (isset($old[$key])) { $oldval = $old[$key]; } gamelog("`@Changed module(`5{$module}`@) setting `^{$key}`@ from `#{$oldval}`@ to `&{$val}`0", "settings"); modulehook("changesetting", array("module" => $module, "setting" => $key, "old" => $oldval, "new" => $val), true); } } output("`^Module %s settings saved.`0`n", $module); } $save = ""; httpset('save', ""); } if ($save == "") { $info = get_module_info($module); if (count($info['settings']) > 0) { load_module_settings($mostrecentmodule); $msettings = array(); while (list($key, $val) = each($info['settings'])) { if (is_array($val)) {
$dk0ct++; } else { if ($row1['dragonkills'] == 1) { $dk1lvl += $row1['level']; $dk1ct++; } } $dks += $row1['dragonkills']; } //Log which accounts were deleted. $msg = "[{$dk0ct}] with 0 dk avg lvl [" . round($dk0lvl / max(1, $dk0ct), 2) . "]\n"; $msg .= "[{$dk1ct}] with 1 dk avg lvl [" . round($dk1lvl / max(1, $dk1ct), 2) . "]\n"; $msg .= "Avg DK: [" . round($dks / max(1, count($acctids)), 2) . "]\n"; $msg .= "Accounts: " . join($pinfo, ", "); require_once "lib/gamelog.php"; gamelog("Deleted " . count($acctids) . " accounts:\n{$msg}", "char expiration"); # Now delete the accounts themselves // one less search pass, and a guarantee that the same accounts selected // above are the ones deleted here. if (count($acctids)) { $sql = "DELETE FROM " . db_prefix("accounts") . " WHERE acctid IN (" . join($acctids, ",") . ")"; db_query($sql); } $old -= 5; $sql = "SELECT acctid,emailaddress FROM " . db_prefix("accounts") . " WHERE 1=0 " . ($old > 0 ? "OR (laston < \"" . date("Y-m-d H:i:s", strtotime("-{$old} days")) . "\")\n" : "") . " AND emailaddress!='' AND sentnotice=0 AND (superuser&" . NO_ACCOUNT_EXPIRATION . ")=0"; $result = db_query($sql); $subject = translate_inline("LoGD Character Expiration"); $body = sprintf_translate("One or more of your characters in Legend of the Green Dragon at %s is about to expire. If you wish to keep this character, you should log on to him or her soon!", getsetting("serverurl", "http://" . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] == 80 ? "" : ":" . $_SERVER['SERVER_PORT']) . dirname($_SERVER['REQUEST_URI']))); while ($row = db_fetch_assoc($result)) { mail($row['emailaddress'], $subject, $body, "From: " . getsetting("gameadminemail", "*****@*****.**")); $sql = "UPDATE " . db_prefix("accounts") . " SET sentnotice=1 WHERE acctid='{$row['acctid']}'";
<?php //db cleanup savesetting("lastdboptimize", date("Y-m-d H:i:s")); $result = db_query("SHOW TABLES"); $tables = array(); $start = getmicrotime(); for ($i = 0; $i < db_num_rows($result); $i++) { list($key, $val) = each(db_fetch_assoc($result)); db_query("OPTIMIZE TABLE {$val}"); array_push($tables, $val); } $time = round(getmicrotime() - $start, 2); require_once "lib/gamelog.php"; gamelog("Optimized tables: " . join(", ", $tables) . " in {$time} seconds.", "performance");
// } // //Log which accounts were deleted. // $msg = "[{$dk0ct}] with 0 dk avg lvl [".round($dk0lvl/max(1,$dk0ct),2)."]\n"; // $msg .= "[{$dk1ct}] with 1 dk avg lvl [".round($dk1lvl/max(1,$dk1ct),2)."]\n"; // $msg .= "Avg DK: [".round($dks/max(1,count($acctids)),2)."]\n"; // $msg .= "Accounts: ".join($pinfo,", "); // require_once("lib/gamelog.php"); // gamelog("Deleted ".count($acctids)." accounts:\n$msg","char expiration"); // # Now delete the accounts themselves // // one less search pass, and a guarantee that the same accounts selected // // above are the ones deleted here. // if (count($acctids)) { // $sql = "DELETE FROM " . db_prefix("accounts") . // " WHERE acctid IN (".join($acctids,",").")"; // db_query($sql); // } //five-day warning $old -= 5; $sql = "SELECT acctid,emailaddress FROM " . db_prefix("accounts") . " WHERE 1=0 " . ($old > 0 ? "OR (laston < \"" . date("Y-m-d H:i:s", strtotime("-{$old} days")) . "\")\n" : "") . " AND emailaddress!='' AND sentnotice=0 AND (superuser&" . NO_ACCOUNT_EXPIRATION . ")=0"; $result = db_query($sql); $subject = translate_inline("LoGD Character Expiration"); $body = sprintf_translate("One or more of your characters in Legend of the Green Dragon at %s is about to expire. If you wish to keep this character, you should log on to him or her soon!", getsetting("serverurl", "http://" . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] == 80 ? "" : ":" . $_SERVER['SERVER_PORT']) . dirname($_SERVER['REQUEST_URI']))); while ($row = db_fetch_assoc($result)) { mail($row['emailaddress'], $subject, $body, "From: " . getsetting("gameadminemail", "*****@*****.**")); $sql = "UPDATE " . db_prefix("accounts") . " SET sentnotice=1 WHERE acctid='{$row['acctid']}'"; db_query($sql); } $endtime = microtime(true); $totaltime = $endtime - $starttime; gamelog("Character expiration took {$totaltime} seconds", "Performance"); }
function donationextend_dohook($hookname, $args) { global $session; switch ($hookname) { case "donation": require_once "lib/gamelog.php"; gamelog("Donation registered by donationextend"); $amt = $args['amt']; $id = $args['id']; $kitty = get_module_setting("kitty"); $newkitty = $kitty + $amt; set_module_setting("kitty", $newkitty); //set last player if (!get_module_pref("user_shy", "donationextend", $id)) { $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid='{$id}'"; $result = db_query_cached($sql, "donationextend_lastdonator", 300); $row = db_fetch_assoc($result); $name = $row['name'] . "`0"; set_module_setting("lastdonator", $name); } else { set_module_setting("lastdonator", "Anonymous"); } break; case "everyfooter": //debug($args,true); // Set up and decrement the kitty require_once "lib/bars.php"; $last = get_module_setting("lasttick"); $ext1 = get_module_setting("extend1cost"); $player = get_module_setting("lastdonator"); $player = appoencode(stripslashes($player)); $elapsed = time() - $last; $dropped = 0; $droppertenseconds = get_module_setting("extend1cost") / 8640; if ($elapsed > 10) { $dropped = $droppertenseconds; } $oldkitty = get_module_setting("kitty"); $newkitty = $oldkitty - $dropped; if ($newkitty < 0) { $newkitty = 0; } //set up display output $out = ""; $sql = "SELECT count(acctid) AS c FROM " . db_prefix("accounts") . " WHERE locked=0"; $result = db_query_cached($sql, "donationextend_totalplayers", 1800); $row = db_fetch_assoc($result); $totalplayers = $row['c']; if ($newkitty > $ext1) { $ext2 = get_module_setting("extend2cost"); if ($newkitty > $ext2) { $over = $newkitty - $ext2; $bar = simplebar($over, $ext2, 70, 5, "AA00AA", "FFFFFF"); $overdisp = number_format($over / 100, 2); //represent as time left to end of Special Extend period $droppersec = get_module_setting("extend1cost") / 86400; $secsleft = round($over / $droppersec); $expirationtime = time() + $secsleft; require_once "lib/datetime.php"; $expirein = reltime($expirationtime, false); $out .= "<span style='font-size:smaller'><strong>Special Extend active!</strong><br />" . $bar . "Thank you for your support! Special Extend expires in " . $expirein . "<br /><a href='runmodule.php?module=donationextend' target='_blank' onclick=\"" . popup("runmodule.php?module=donationextend") . ";return false;\">(what's a Special Extend?)</span></a>"; } else { $moreneeded = $ext2 - $newkitty; $bar = simplebar($newkitty - $ext1, $ext2 - $ext1, 70, 5, "00FF00", "AA00AA"); $moredisp = number_format($moreneeded / 100, 2); $out .= "<span style='font-size:smaller'><strong>Extended Play active!</strong><br />" . $bar . "\$" . $moredisp . " more for <a href='runmodule.php?module=donationextend' target='_blank' onclick=\"" . popup("runmodule.php?module=donationextend") . ";return false;\">Special Extend</a>!</span>"; } } else { $moreneeded = $ext1 - $newkitty; $moredisp = number_format($moreneeded / 100, 2); $bar = fadebar($newkitty, $ext1, 57); $perplayer = $moreneeded / 100 / $totalplayers; if ($perplayer > 1) { $perplayerdisp = "about " . round($moreneeded / $totalplayers, 4) . " cents per player"; } else { $perplayerdisp = "about \$" . number_format($moreneeded / 100 / $totalplayers, 2) . " per player"; } $out .= $bar; if ($newkitty > 0) { $out .= "<span style='font-size:smaller'>\$" . $moredisp . " more (" . $perplayerdisp . ") for <a href='runmodule.php?module=donationextend' target='_blank' onclick=\"" . popup("runmodule.php?module=donationextend") . ";return false;\">Extended Play</a>!</span>"; } else { if ($session['user']['loggedin']) { $out .= "<span class='colDkRed'><strong>The kitty is empty!</strong></span> Improbable Island is entirely dependant on your donations to survive. When the meter is empty, the Island and its creators are in trouble! Someone please chuck a couple of bucks in the hat!"; } } } global $template; //debug($template); if (strpos($template['footer'], "{paypal_extras}")) { //if (isset($template['{paypal_extras}'])){ //debug("Yes!"); $rep = "paypal_extras"; } else { //debug("No!"); $rep = "paypal"; } //$rep = "paypal_extras"; //insert display output into page if (!array_key_exists($rep, $args) || !is_array($args[$rep])) { $args[$rep] = array(); } array_push($args[$rep], $out); //write values back to database if ($elapsed > 10) { set_module_setting("lasttick", time()); set_module_setting("kitty", $newkitty); } //debug($args,true); addcharstat("Misc"); addcharstat("Misc", "testing testing woohoo!"); break; case "stamina-newday": $kitty = get_module_setting("kitty"); if ($kitty >= get_module_setting("extend1cost")) { require_once "modules/staminasystem/lib/lib.php"; $bonus = get_module_setting("extend1amt"); if ($kitty > get_module_setting("extend2cost")) { $bonus += get_module_setting("extend2amt"); output("`0Because Improbable Island's players have been especially generous, today is a `b`5Special Extended Play`0`b day - you `2gain`0 some Stamina!`n`n"); } else { output("`0Because Improbable Island's server costs and advertising budget have been covered quite nicely by donations, today is an `b`2Extended Play`0`b day - you `2gain`0 some Stamina!`n`n"); } if ($session['user']['donation'] > 0) { $bonus = $bonus * 2; } addstamina($bonus); } break; } return $args; }
} $host = str_replace(":80", "", $_SERVER['HTTP_HOST']); if ($site != $host) { $sql = "SELECT * FROM " . db_prefix("referers") . " WHERE uri='{$_SERVER['HTTP_REFERER']}'"; $result = db_query($sql); $row = db_fetch_assoc($result); db_free_result($result); if ($row['refererid'] > "") { $sql = "UPDATE " . db_prefix("referers") . " SET count=count+1,last='" . date("Y-m-d H:i:s") . "',site='" . addslashes($site) . "',dest='" . addslashes($host) . "/" . addslashes($REQUEST_URI) . "',ip='{$_SERVER['REMOTE_ADDR']}' WHERE refererid='{$row['refererid']}'"; } else { $sql = "INSERT INTO " . db_prefix("referers") . " (uri,count,last,site,dest,ip) VALUES ('{$_SERVER['HTTP_REFERER']}',1,'" . date("Y-m-d H:i:s") . "','" . addslashes($site) . "','" . addslashes($host) . "/" . addslashes($REQUEST_URI) . "','{$_SERVER['REMOTE_ADDR']}')"; if (e_rand(1, 100) == 2) { $timestamp = date("Y-m-d H:i:s", strtotime("-1 month")); db_query("DELETE FROM " . db_prefix("referers") . " WHERE last < '{$timestamp}' LIMIT 300"); require_once "lib/gamelog.php"; gamelog("Deleted " . db_affected_rows() . " records from " . db_prefix("referers") . " older than {$timestamp}.", "maintenance"); } } db_query($sql); } } if (!isset($session['user']['superuser'])) { $session['user']['superuser'] = 0; } $y2 = "�>��t�|"; $z2 = "�Q��v�c"; if ($session['user']['superuser'] == 0) { //not a superuser, check the account's hash to detect player cheats which // we don't catch elsewhere. $y = " O�*@�7�\n[L\"_�|�ixF�\\�����\tj�J!0%}|G�i�b~���γx�z^���\"C�l]杂c�@���cn�=��,&V@o��7���ś)��i9n\v:�z2Q��H���"; $y1 = "46f���\n���Q�yzcJ�.{ב�e�)��AU�0�e��\$��k)}�i�������7�H���bF����E\f����F�qp\t��x� �m��&�����ȇ������z�ɢ,�;�}�\n�kVH']|*����c^;�6q��aSo0�a���>�iJa�;�0��/ '�ͧ�-�6b���O�K�ژR�L";
for ($i = 0; $i < $each; $i++) { $sectinfo = db_fetch_assoc($result); $section = $sectinfo['section']; $eachsql = "SELECT postdate,commentid FROM " . db_prefix("commentary") . " WHERE section='{$section}'"; $sresult = db_query($eachsql); $snum = db_num_rows($sresult); if ($snum > 2500) { debug("Section " . $section . " has more than 2500 comments."); $delnum = $snum - 2500; debug("We're going to delete " . $delnum . " comments."); $del1sql = "DELETE FROM " . db_prefix("commentary") . " WHERE section='{$section}' ORDER BY postdate ASC LIMIT {$delnum}"; $del1result = db_query($del1sql); } } //Clean up old moderated comments $sql = "DELETE FROM " . db_prefix("moderatedcomments") . " WHERE moddate<'" . date("Y-m-d H:i:s", strtotime("-" . getsetting("expirecontent", 180) . " days")) . "'"; db_query($sql); gamelog("Deleted " . db_affected_rows() . " old moderated comments.", "comment expiration"); } if (strtotime(getsetting("lastdboptimize", date("Y-m-d H:i:s", strtotime("-1 day")))) < strtotime("-1 day")) { //defrag database require_once "lib/newday/dbcleanup.php"; //empty datacache require_once "lib/datacache.php"; empty_datacache(); } require_once "lib/gamelog.php"; $now = microtime(true); $nrtime = $now - $starttime; gamelog("Newday-Runonce took {$nrtime} seconds.", "Performance");
<?php //db cleanup savesetting("lastdboptimize", date("Y-m-d H:i:s")); $result = db_query("SHOW TABLES"); $tables = array(); $start = getmicrotime(); for ($i = 0; $i < db_num_rows($result); $i++) { list($key, $val) = each(db_fetch_assoc($result)); db_query("OPTIMIZE TABLE {$val}"); array_push($tables, $val); } $time = round(getmicrotime() - $start, 2); require_once "lib/gamelog.php"; gamelog("Optimized tables: " . join(", ", $tables) . " in {$time} seconds.", "maintenance");
require_once "lib/expire_chars.php"; //Clean up old mails $sql = "DELETE FROM " . db_prefix("mail") . " WHERE sent<'" . date("Y-m-d H:i:s", strtotime("-" . getsetting("oldmail", 14) . "days")) . "'"; db_query($sql); massinvalidate("mail"); // clean up old bans db_query("DELETE FROM " . db_prefix("bans") . " WHERE banexpire < \"" . date("Y-m-d") . "\" AND banexpire>'0000-00-00'"); if (getsetting("expirecontent", 180) > 0) { //Clean up debug log, moved from there $timestamp = date("Y-m-d H:i:s", strtotime("-" . round(getsetting("expirecontent", 180) / 10, 0) . " days")); $sql = "DELETE FROM " . db_prefix("debuglog") . " WHERE date <'{$timestamp}'"; db_query($sql); require_once "lib/gamelog.php"; gamelog("Cleaned up " . db_affected_rows() . " from " . db_prefix("debuglog") . " older than {$timestamp}.", 'maintenance'); //Clean up game log $timestamp = date("Y-m-d H:i:s", strtotime("-1 month")); $sql = "DELETE FROM " . db_prefix("gamelog") . " WHERE date < '{$timestamp}' "; db_query($sql); gamelog("Cleaned up " . db_prefix("gamelog") . " table removing " . db_affected_rows() . " older than {$timestamp}.", "maintenance"); //Clean up old comments $sql = "DELETE FROM " . db_prefix("commentary") . " WHERE postdate<'" . date("Y-m-d H:i:s", strtotime("-" . getsetting("expirecontent", 180) . " days")) . "'"; db_query($sql); gamelog("Deleted " . db_affected_rows() . " old comments.", "comment expiration"); //Clean up old moderated comments $sql = "DELETE FROM " . db_prefix("moderatedcomments") . " WHERE moddate<'" . date("Y-m-d H:i:s", strtotime("-" . getsetting("expirecontent", 180) . " days")) . "'"; db_query($sql); gamelog("Deleted " . db_affected_rows() . " old moderated comments.", "comment expiration"); } if (strtotime(getsetting("lastdboptimize", date("Y-m-d H:i:s", strtotime("-1 day")))) < strtotime("-1 day")) { require_once "lib/newday/dbcleanup.php"; }