<?php require "init.php"; $script = Script::find_by_code('delete_sessions'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Deleting old RPC sessions\r\n\r\n"; RPCSession::clear(); $script = Script::find_by_code('delete_sessions'); $output = ob_get_clean(); $script->finish($output);
<?php require "init.php"; $script = Script::find_by_code('twitter'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Processing Twitter Queue\r\n\r\n"; Tweet::process($script); $script = Script::find_by_code('twitter'); $output = ob_get_clean(); $script->finish($output);
<?php require "init.php"; $script = Script::find_by_code("unpaid_emails"); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Forums\r\n\r\n"; $offset = 31; $lower = strtotime("-{$offset} days midnight"); $offset--; $upper = strtotime("-{$offset} days midnight"); $signups = EventSignup::find_all("\n\t\tevent_signups.paid = false\n\t\tAND event_signups.voucher = false\n\t\tAND event_signups.created_at BETWEEN FROM_UNIXTIME({$lower}) AND FROM_UNIXTIME({$upper})\n\t\tAND events.startdate > NOW()\n\t\tAND users.allow_emails = true\n\t\tAND users.suspended = false\n\t\tAND users.activated = true\n\t"); $users = array(); foreach ($signups as $signup) { if (!in_array($signup->user->id, $users)) { if ($signup->event_ticket->participant && $signup->event->count_participants("paid") < $signup->event->capacity) { $users[] = $signup->user->id; $script->addlog("Reminder sent to {$signup->user->email} ({$signup->user->nickname}) for [{$signup->id}]"); echo "Sending reminder to {$signup->user->email} ({$signup->user->nickname}) for signup {$signup->id}\n"; Email::send_signup_reminder($signup); } } } $script = Script::find_by_code("unpaid_emails"); $output = ob_get_contents(); $script->finish($output);
require "init.php"; $script = Script::find_by_code('loyalty_attendance'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Attendance Loyalty Points\r\n\r\n"; $page = EventSignup::paginate("event_signups.paid = 1 AND event_signups.processed = 0 AND events.startdate <= NOW()", "event_signups.created_at ASC", 1, 50); $count = count($page->collection); echo " Processing {$count} / {$page->total} signups\r\n"; foreach ($page->collection as $obj) { mysql_query('BEGIN'); $loyalty = true; if ($obj->event_ticket->points_value > 0 && !$obj->event_ticket->staff) { $loyalty = $obj->user->award_loyalty($obj->event_ticket->points_value, "Attendance: {$obj->event->shortname} {$obj->event_ticket->name}"); $script->addlog("Awarded {$obj->event_ticket->points_value}pts to [{$obj->user}] {$obj->user->nickname} for [{$obj->event_ticket}] {$obj->event->shortname} {$obj->event_ticket->name}"); } $obj->processed = true; $ua = $obj->save(); if ($loyalty && $ua) { mysql_query('COMMIT'); } else { echo "Error processing [{$obj}]\r\n"; print_r($obj); mysql_query('ROLLBACK'); $script->addlog("Error processing [{$obj}]", 'Critical'); } } $script = Script::find_by_code('loyalty_attendance'); $output = ob_get_clean(); $script->finish($output);
$page = UserAchievement::paginate("user_achievements.processed = 0", "user_achievements.created_at ASC", 1, 50); $count = count($page->collection); echo " Processing {$count} / {$page->total} achievements\r\n"; foreach ($page->collection as $obj) { mysql_query('BEGIN'); $loyalty = true; if ($obj->achievement->points_value > 0) { $loyalty = $obj->user->award_loyalty($obj->achievement->points_value, "Achievement: {$obj->achievement->name}"); $script->addlog("Awarded {$obj->achievement->points_value}pts to [{$obj->user}] {$obj->user->nickname} for [{$obj->achievement}] {$obj->achievement->name}"); } $obj->processed = true; $ua = $obj->save(); if ($loyalty && $ua) { mysql_query('COMMIT'); } else { echo "Error processing [{$obj}]\r\n"; print_r($obj); mysql_query('ROLLBACK'); $script->addlog("Error processing [{$obj}]", 'Critical'); print_r($obj->errors); print_r($obj->errors[0]); if (count($obj->errors) > 0 && $obj->errors[0] == 'User has already been awarded that achievement') { $obj->processed = true; $obj->save(); $script->addlog("[{$obj}] was already processed. Marking it as processed", 'Warning'); } } } $script = Script::find_by_code('loyalty_achievements'); $output = ob_get_clean(); $script->finish($output);
// Grab all results from the stats db in 1 query to avoid hundreds of hits $stats_connection = mysql_connect($config['epicstats']['hostname'], $config['epicstats']['username'], $config['epicstats']['password']); if (!$stats_connection) { throw new Error500('Unable to connect to database'); } $result = mysql_select_db($config['epicstats']['database'], $stats_connection); if (!$result) { throw new Error500('Unable to select database'); } $results = mysql_query("\n\t\t\tSELECT `playerId`, `uniqueId`, `game`\n\t\t\tFROM `hlstats_playeruniqueids`\n\t\t", $stats_connection); // Represent the data while ($row = mysql_fetch_assoc($results)) { $stats_results["{$row['uniqueId']}"]["{$row['game']}"] = $row['playerId']; } mysql_close($stats_connection); // Re-establish database connection for epic database_connect(); // Update each user foreach ($users as $user) { echo " * Updating [{$user}] {$user->nickname}\r\n"; $profile = $user->profile; $steam_id = substr($user->steam_id, strpos($user->steam_id, ":") + 1, strlen($user->steam_id) - 1); $profile->hlstatsx_l4d_user = isset($stats_results["{$steam_id}"]["l4d"]) ? $stats_results["{$steam_id}"]["l4d"] : ""; $profile->hlstatsx_l4d2_user = isset($stats_results["{$steam_id}"]["l4d2"]) ? $stats_results["{$steam_id}"]["l4d2"] : ""; $profile->hlstatsx_tf2_user = isset($stats_results["{$steam_id}"]["tf"]) ? $stats_results["{$steam_id}"]["tf"] : ""; $profile->save(); } } $script = Script::find_by_code('sync_stats_profiles'); $output = ob_get_clean(); $script->finish($output);
<?php require "init.php"; $script = Script::find_by_code('loyalty_referrals'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Referral Loyalty Points\r\n\r\n"; $page = AffiliateReferral::paginate("users.activated = 1 AND event_signups.paid = 1 AND event_tickets.participant = 1 AND affiliate_referrals.processed = 0 AND events.startdate <= NOW()", "users.created_at ASC", 1, 50); $count = count($page->collection); echo " Processing {$count} / {$page->total} referrals\r\n"; foreach ($page->collection as $obj) { mysql_query('BEGIN'); $loyalty = $obj->referer->award_loyalty(500, "Referral: {$obj->user->nickname}"); $script->addlog("Awarded {$obj->achievement->points_value}pts to [{$obj->referer}] {$obj->referer->nickname} for referring [{$obj->user}] {$obj->user->nickname}"); $obj->processed = true; $ua = $obj->save(); if ($loyalty && $ua) { mysql_query('COMMIT'); } else { echo "Error processing [{$obj}]\r\n"; print_r($obj); mysql_query('ROLLBACK'); $script->addlog("Error processing [{$obj}]", 'Critical'); } } $script = Script::find_by_code('loyalty_referrals'); $output = ob_get_clean(); $script->finish($output);
<?php require "init.php"; $script = Script::find_by_code('gameservers'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Updating Game Servers\r\n\r\n"; $servers = GameServer::find_all(); foreach ($servers as $server) { echo " * Updating [{$server}]\r\n"; $server->update_stats(); } $script = Script::find_by_code('gameservers'); $output = ob_get_clean(); $script->finish($output);
<?php require_once 'init.php'; $script = Script::find_by_code('forums'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] News Posts\r\n\r\n"; $newsPosts = News::find_all("news.published = true AND news.publish_at <= NOW() and news.ipb_id IS NULL"); foreach ($newsPosts as $news) { $response = $news->forumSync(); var_dump($response); $script->addlog("Posting on forums for [{$news}] {$news->title}"); echo " * {$news->title}\r\n"; } $script = Script::find_by_code('forums'); $output = ob_get_clean(); $script->finish($output);
<?php require "init.php"; $script = Script::find_by_code('loyalty_newusers'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] New User Loyalty Points\r\n\r\n"; $page = User::paginate("users.activated = 1 AND users.processed = 0", "users.created_at ASC", 1, 50); $count = count($page->collection); echo " Processing {$count} / {$page->total} users\r\n"; foreach ($page->collection as $obj) { mysql_query('BEGIN'); $loyalty = $obj->award_loyalty(25, "Welcome to epic.LAN!"); $script->addlog("Awarded 25pts to [{$obj}] {$obj->nickname} for a new account"); $obj->processed = true; $ua = $obj->save(); if ($loyalty && $ua) { mysql_query('COMMIT'); } else { echo "Error processing [{$obj}]\r\n"; print_r($obj); mysql_query('ROLLBACK'); $script->addlog("Error processing [{$obj}]", 'Critical'); } } $script = Script::find_by_code('loyalty_newusers'); $output = ob_get_clean(); $script->finish($output);
<?php require "init.php"; $script = Script::find_by_code('twitch'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Updating Twitch Streams\r\n\r\n"; Twitch::process($script); $script = Script::find_by_code('twitch'); $output = ob_get_clean(); $script->finish($output);
<?php require_once 'init.php'; ob_start(); $script = Script::find_by_code('scheduler'); $script->start(); $scripts = Script::find_all("scripts.code <> 'scheduler' AND scripts.enabled AND (scripts.started_at + scripts.interval) < NOW() AND not scripts.locked"); foreach ($scripts as $script) { if (!$script->locked && $script->started_at + $script->interval < time()) { echo date(' [d/m/y H:i:s]') . " Executing {$script->name}\r\n"; // Execute a background process to run this script $script->run(true); } } $scheduler = Script::find_by_code('scheduler'); $output = ob_get_clean(); $script = Script::find_by_code('scheduler'); $script->finish($output);
<?php require_once 'init.php'; $script = Script::find_by_code('newscomments'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] News Post Comments\r\n\r\n"; $newsPosts = News::find_all("news.published = true AND news.publish_at <= NOW() and news.ipb_id IS NOT NULL"); if (count($newsPosts) > 0) { $response = file_get_contents("{$config['forums']['url']}index.php?app=core&module=epic§ion=comments"); $data = unserialize($response); foreach ($newsPosts as $news) { if (array_key_exists($news->ipb_id, $data)) { $news->updateForumPostCount($data, $script); } else { /* $count = file_get_contents("{$config['forums']['url']}index.php?app=core&module=epic§ion=newscomment&id={$news->ipb_id}"); if ($count != $news->ipb_postcount) { $news->ipb_postcount = $count; $news->save(); } */ } } } $script = Script::find_by_code('newscomments'); $output = ob_get_clean(); $script->finish($output);
<?php require "init.php"; $script = Script::find_by_code('unlockgameservers'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Unlocking Game Servers\r\n\r\n"; $gs = Script::find_by_code('gameservers'); if ($gs->locked) { $diff = time() - $gs->started_at; if ($diff >= 600) { echo "\tScript has been locked for {$diff}s, unlocking"; $gs->addlog("Script unlocked automatically after 10 minutes", 'High'); $gs->unlock(); $script->addlog("Unlocking script, it had been locked for {$diff}s"); } else { echo " * Script has been locked for {$diff}s"; } } else { echo " * Script is not locked"; } $script = Script::find_by_code('unlockgameservers'); $output = ob_get_clean(); $script->finish($output);