function do_facebook($user) { if (!$user->getValue('facebook_id')) { return; } global $db; $fbml = ''; $userid = $user->getValue('userid'); $appapikey = '5502d60d6c4172a6f84ff7269aa8da80'; $appsecret = 'a603ff4995447f220eb65785b7f916fb'; $facebook = new Facebook($appapikey, $appsecret); $nickname = $user->getValue('nickname') ? htmlentities($user->getValue('nickname')) : 'User #' . $userid; $fbml .= '<div class="vcard">'; $fbml .= 'I am <a class="fn nickname url" rel="me" href="http://theproject.singpolyma.net/user/' . $userid . '">' . $nickname . '</a> on The Project<br />'; require_once dirname(__FILE__) . '/../include/connectDB.php'; $servers = mysql_query('SELECT server_id,server_name FROM servers', $db) or die(mysql_error()); while ($server = mysql_fetch_assoc($servers)) { $user = new user($userid, new server($server['server_id'])); $fbml .= '<p>'; $fbml .= ' <b>On ' . htmlentities($server['server_name']) . '</b>'; $fbml .= $user->getValue('rank') ? ' Ranked #' . $user->getValue('rank') : ' Not Ranked'; $fbml .= ' <br /> Score: ' . ceil($user->calculateScore()); $fbml .= ' <br /> Gold: ' . ceil($user->getValue('gold')); $fbml .= '</p>'; } //end while servers $fbml .= '</div>'; $friends = $facebook->api_client->profile_setFBML($fbml, $user->getValue('facebook_id')); echo "DONE FACEBOOK FOR USER#{$userid}\n"; }
$dbcities = mysql_query("SELECT user_id,city_id FROM server_cities WHERE server_id=" . $server->getID() . " AND city_id < {$close_upper_bound} ORDER BY city_id DESC LIMIT 50", $db) or die(mysql_error()); } else { $dbcities = mysql_query("SELECT user_id,city_id FROM server_cities WHERE server_id=" . $server->getID() . " ORDER BY user_id LIMIT 50", $db) or die(mysql_error()); } //end if-else fromcity while ($city = mysql_fetch_assoc($dbcities)) { $user = new user($city['user_id'], $server); $city = new city($city['city_id']); echo '<li>'; echo '<a href="/server/' . $server->getID() . '/attack/' . $city->getValue('id') . '+' . $cities[1] . '">'; if ($city->getValue('name')) { echo htmlentities($city->getValue('name')) . ' / '; } echo 'Location: ' . str_pad($city->getValue('id'), 6, '0', STR_PAD_LEFT); echo '</a>'; echo ' / Population: ' . $city->getValue('population') . ' / Defense: ' . (intval($city->getValue('defense')) + 1) . ' / User: <a href="/server/' . $server->getID() . '/user/' . $user->getValue('userid') . '">' . htmlentities($user->getValue('nickname')) . '</a>'; $can_access = $city->getValue('user_' . $LOGIN_DATA['user_id'] . '_access'); $can_access = $can_access === true || intval($can_access) > time(); if ($can_access) { echo ' - <a href="/server/' . $server->getID() . '/city/' . $city->getValue('id') . '">view</a>'; } echo '</li>'; } //end while cities echo '</ul>'; } //end if ! tocity if (!$fromcity) { echo '<h2>Select a City to Attack/Move From</h2><ul>'; foreach ($current_user->getValue('cities') as $city) { echo '<li>';
require_once dirname(__FILE__) . '/include/processCookie.php'; require_once dirname(__FILE__) . '/include/cron.php'; require_once dirname(__FILE__) . '/include/connectDB.php'; require_once dirname(__FILE__) . '/include/user.php'; require_once dirname(__FILE__) . '/include/server.php'; require_once dirname(__FILE__) . '/include/city.php'; if (!$server) { $server = new server($_REQUEST['server_id']); } if (!$current_user) { $current_user = new user($LOGIN_DATA['user_id'], $server); } ?> <h3>Troop Movements</h3> <ul> <?php $transactions = mysql_query("SELECT unit_count,eta,destination,user_id FROM server_unit_transaction WHERE server_id=" . $server->getID() . " AND user_id=" . $current_user->getValue('userid') . " ORDER BY eta ASC", $db) or die(mysql_query()); while ($transaction = mysql_fetch_assoc($transactions)) { $city = new city($transaction['destination']); $dest = $city->getValue('name') ? htmlentities($city->getValue('name')) : 'City at ' . str_pad($city->getValue('id'), 6, '0', STR_PAD_LEFT); $is_attack = $city->getValue('user')->getValue('userid') != $transaction['user_id']; $time_left = round(($transaction['eta'] - time()) / 60, 2); if ($time_left > 0) { echo "\t\t\t" . '<li>' . ($is_attack ? 'Attacking ' : 'Moving to ') . $dest . ' with ' . $transaction['unit_count'] . ' troops in ' . $time_left . ' minutes </li>' . "\n"; } } //end while unit ?> </ul>
echo $player->getValue('nickname') ? $player->getValue('nickname') : 'User #' . $player->getValue('userid'); echo '</a>'; echo ' (' . $player->getValue('gold') . ' Gold)'; echo $player->online_icon(); echo '</li>'; } //end while close_competitors echo '</ol>'; echo '<a href="/server/' . $server->getID() . '/leaders">View the leaders »</a>'; $friends = mysql_query("SELECT friend_id FROM friends WHERE user_id=" . $current_user->getValue('userid'), $db) or die(mysql_error()); if (mysql_fetch_assoc($friends)) { $friends = mysql_query("SELECT friend_id FROM friends WHERE user_id=" . $current_user->getValue('userid'), $db) or die(mysql_error()); echo '<h3>Friends</h3><ol style="list-style-type:none;padding:0px;">'; while ($player = mysql_fetch_assoc($friends)) { $player = new user($player['friend_id'], $server, true); if (is_numeric($player->getValue('gold'))) { //if the friend is on this server echo '<li>'; echo '<a href="/server/' . $server->getID() . '/user/' . $player->getValue('userid') . '">'; echo '<img style="width:40px;" src="' . htmlentities($player->getValue('photo')) . '" alt="" /> '; echo $player->getValue('nickname') ? $player->getValue('nickname') : 'User #' . $player->getValue('userid'); echo '</a>'; echo ' (' . $player->getValue('gold') . ' Gold)'; echo $player->online_icon(); echo '</li>'; } //end if is_numeric gold } //end while friends echo '</ol>'; }
<?php require_once dirname(__FILE__) . '/include/user.php'; require_once dirname(__FILE__) . '/include/server.php'; $user = new user($_REQUEST['user_id'], new server(1)); $fbml = ''; $userid = $user->getValue('userid'); $nickname = $user->getValue('nickname') ? htmlentities($user->getValue('nickname')) : 'User #' . $userid; $fbml .= '<div class="vcard">'; $fbml .= 'I am <a class="fn nickname url" rel="me" href="http://t.heproject.com/user/' . $userid . '">' . $nickname . '</a> on The Project<br />'; require_once dirname(__FILE__) . '/include/connectDB.php'; $servers = mysql_query('SELECT server_id,server_name FROM servers', $db) or die(mysql_error()); while ($server = mysql_fetch_assoc($servers)) { $user = new user($userid, new server($server['server_id'])); $fbml .= '<p>'; $fbml .= ' <b>On ' . htmlentities($server['server_name']) . '</b>'; $fbml .= $user->getValue('rank') ? ' Ranked #' . $user->getValue('rank') : ' Not Ranked'; $fbml .= ' <br /> Score: ' . ceil($user->calculateScore()); $fbml .= ' <br /> Gold: ' . ceil($user->getValue('gold')); $fbml .= '</p>'; } //end while servers $fbml .= '</div>'; if (isset($_REQUEST['js'])) { header('Content-type: text/javascript'); echo 'document.writeln(\''; echo $fbml; echo '\');'; } else { echo $fbml; }
function reset() { global $db; require_once dirname(__FILE__) . '/connectDB.php'; require_once dirname(__FILE__) . '/user.php'; $today = date('d'); $startdate = strtotime(date('Y-m-') . ($today + 1)); require_once dirname(__FILE__) . '/twitter.php'; post_tweet('Server ' . $this->getName() . ' restarted. New Round begins ' . date('Y-m-d H:i O', $startdate) . '. http://t.heproject.com/server/' . $this->getID()); $players = mysql_query("SELECT user_id FROM server_data WHERE server_id=" . $this->getID() . " AND `key`='gold'", $db) or die(mysql_error()); while ($player = mysql_fetch_assoc($players)) { $player_data = new user($player['user_id'], $this, true); mysql_query("INSERT INTO board (round_end, server_id, user_id, score) VALUES ({$startdate}, {$this->id}, " . $player['user_id'] . ", " . $player_data->calculateScore() . ")") or die(mysql_error()); if ($player_data->getValue('twitter')) { //send_tweet($player_data->getValue('twitter'), 'Server '.$this->getName().' restarted. New Round begins '.date('Y-m-d H:i',$startdate)); } else { if ($player_data->getValue('email')) { mail($player_data->getValue('email'), '[The Project] Server ' . $this->getName() . ' restarted', ' New Round begins ' . date('Y-m-d H:i O', $startdate) . ".\n\n <http://t.heproject.com/server/" . $this->getID() . '>', 'From: t@heproject.com'); } } } mysql_query("UPDATE servers SET previous_week=" . $startdate . ", previous_day=" . $startdate . " WHERE server_id={$this->id}", $db) or die(mysql_error()); mysql_query("DELETE FROM server_data WHERE server_id={$this->id}", $db) or die(mysql_error()); mysql_query("DELETE FROM server_cities WHERE server_id={$this->id}", $db) or die(mysql_error()); mysql_query("DELETE FROM server_cities_data WHERE server_id={$this->id}", $db) or die(mysql_error()); mysql_query("DELETE FROM server_unit_transaction WHERE server_id={$this->id}", $db) or die(mysql_error()); mysql_query("DELETE FROM server_building_transaction WHERE server_id={$this->id}", $db) or die(mysql_error()); mysql_query("DELETE FROM server_attack_results WHERE server_id={$this->id}", $db) or die(mysql_error()); }
require_once dirname(__FILE__) . '/include/cron.php'; if (!$server) { $server = new server($_REQUEST['server_id']); } if (!$current_user) { $current_user = new user($LOGIN_DATA['user_id'], $server); } echo "<h3>Cities</h3><ul>"; foreach ($current_user->getValue('cities') as $city) { echo '<li>'; echo ' ' . str_pad($city->getValue('population'), 3, '0', STR_PAD_LEFT) . ' <img src="/images/group.png" alt="Population" title="Population" />'; echo ' ' . str_pad(intval($city->getValue('defense')) + 1, 2, '0', STR_PAD_LEFT) . ' <img src="/images/shield.png" alt="Defense" title="Defense" />'; echo ' ' . str_pad(intval($city->unit_count()), 3, '0', STR_PAD_LEFT) . ' <img src="/images/car.png" alt="Units" title="Units" />'; echo ' <a href="/server/' . $server->getID() . '/city/' . $city->getValue('id') . '">'; echo ' @ ' . str_pad($city->getValue('id'), 6, '0', STR_PAD_LEFT); if ($city->getValue('name')) { echo ' / ' . htmlentities($city->getValue('name')); } echo '</a>'; $attack = mysql_query("SELECT user_id,unit_count,eta FROM server_unit_transaction WHERE server_id=" . $server->getID() . " AND destination=" . $city->getValue('id') . " AND user_id!=" . $current_user->getValue('userid') . " AND eta < " . (time() + 60 * 5) . " ORDER BY eta DESC LIMIT 1", $db) or die(mysql_error()); $attack = mysql_fetch_assoc($attack); if ($attack) { $attack_user = new user($attack['user_id'], $server); $nickname = $attack_user->getValue('nickname') ? $attack_user->getValue('nickname') : 'User #' . $attack_user->getValue('userid'); echo ' <br /><i>' . $attack['unit_count'] . ' units attacking from <a href="/server/' . $server->getID() . '/user/' . $attack_user->getValue('userid') . '">' . $nickname . '</a> in ' . round(($attack['eta'] - time()) / 60, 2) . " minutes.</i>"; } //end if attack echo "</li>"; } //end foreach cities echo "</ul>";
$data = $data[2]; $reply = ''; switch ($verb) { case 'list': case 'show': case 'cities': $data = 'cities'; case 'near': $mod = 'near'; case 'city': case 'ls': $data = trim(preg_replace('/^city[\\s]+/i', '', $data)); $data = trim(preg_replace('/^near[\\s]+/i', '', $data)); if (!$data || $data == 'cities') { $reply = 'On ' . $server->getName() . ' your cities : '; foreach ($user->getValue('cities') as $city) { $reply .= $city->getValue('name') . '@' . $city->getValue('id') . ' '; } } else { if ($mod == 'near') { foreach ($user->getValue('cities') as $city) { if ($city->getValue('id') == $data || @preg_match('/^' . $data . '$/i', $city->getValue('name'))) { $close_upper_bound = intval($city->getValue('id')) + 30000; $dbcities = mysql_query("SELECT city_id FROM server_cities WHERE server_id=" . $server->getID() . " AND city_id < {$close_upper_bound} ORDER BY city_id DESC LIMIT 10", $db) or die(mysql_error()); $reply = 'On ' . $server->getName() . ' near ' . $city->getValue('name') . '@' . $city->getValue('id') . ' : '; while ($icity = mysql_fetch_assoc($dbcities)) { $cityo = new city($icity['city_id']); $reply .= $cityo->getValue('name') . '@' . $cityo->getValue('id') . ' '; } break; }
<?php require_once dirname(__FILE__) . '/include/processCookie.php'; require_once dirname(__FILE__) . '/include/server.php'; if ($LOGIN_DATA['user_id']) { if ($_REQUEST['server_id']) { $server = new server($_REQUEST['server_id']); require_once dirname(__FILE__) . '/include/user.php'; $current_user = new user($LOGIN_DATA['user_id'], $server); echo round($current_user->calculateScore(), 2) . " Overall Score"; echo ' | ' . round($current_user->calculateDailyGold(), 2) . ' <img src="/images/coins_add.png" alt="Income" title="Income" /> '; echo ' | ' . $current_user->getValue('gold') . ' <img src="/images/coins.png" alt="Gold" title="Gold" /> '; echo ' | <a href="/server/' . $_REQUEST['server_id'] . '">' . $current_user->getValue('city_count') . ' <img src="/images/building.png" alt="Cities" title="Cities" /></a>'; } //end if server_id } //end if user_id
} if ($_REQUEST['user_id'] == $LOGIN_DATA['user_id'] && isset($_REQUEST['nickname'])) { //if this is the logged in user mysql_query("UPDATE users SET \nnickname='" . mysql_real_escape_string($_REQUEST['nickname'], $db) . "',\nphoto='" . mysql_real_escape_string($_REQUEST['photo'], $db) . "',\nemail='" . mysql_real_escape_string($_REQUEST['email'], $db) . "',\ntwitter='" . mysql_real_escape_string($_REQUEST['twitter'], $db) . "'\nWHERE user_id=" . $LOGIN_DATA['user_id'], $db) or die(mysql_error()); $ch = curl_init('http://twitter.com/friendships/create/' . urlencode($_REQUEST['twitter']) . '.xml'); curl_setopt($ch, CURLOPT_USERPWD, file_get_contents('include/twitter.txt')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($ch); curl_close($ch); } //end if user is loggid in and form submitted $this_user = new user(intval($_REQUEST['user_id']), $server ? $server : new server(1), true); ?> <head> <title>The Project - User <?php echo htmlentities($this_user->getValue('nickname')); ?> </title> <?php $xhtmlSite->metaType(); ?> <link rel="stylesheet" href="/styles/main.css" type="text/css" media="screen" /> </head> <body> <?php require_once dirname(__FILE__) . '/include/visible_header.php'; ?> <div style="float:right;"> <?php $openids = $this_user->getValue('openids');
$xhtmlSite->metaType(); ?> <link rel="stylesheet" href="/styles/main.css" type="text/css" media="screen" /> <link rel="shortcut icon" href="/favicon.ico" /> </head> <body> <?php require dirname(__FILE__) . '/include/visible_header.php'; echo '<h3>Recent Attacks</h3><ol style="list-style-type:none;padding:0px;">'; $attacks = mysql_query("SELECT destination,user_id,results,time FROM server_attack_results WHERE server_id=" . $server->getID() . " ORDER BY time DESC LIMIT 50", $db) or die(mysql_error()); while ($attack = mysql_fetch_assoc($attacks)) { $user = new user($attack['user_id'], $server); $dest = new city($attack['destination']); $class = $attack['results'] < 0 ? 'won' : 'lost'; echo '<li class="' . $class . '">'; echo ceil((time() - $attack['time']) / 60) . ' minutes ago: '; echo '<a href="/server/' . $server->getID() . '/user/' . $user->getValue('userid') . '">' . ($user->getValue('nickname') ? htmlentities($user->getValue('nickname')) : 'User #' . $user->getValue('userid')) . '</a>'; echo ' attacked '; echo $dest->getValue('name') . ' (Location: ' . $dest->getValue('id') . ')'; echo ' and '; echo $class; echo ' by ' . abs($attack['results']); echo '</li>'; } //end while attacks echo '</ol>'; ?> </body> </html>
static function subvert($transaction, $city, $db) { $defense = $city->getValue('defense') + 1; foreach ($city->getKeys() as $key) { $key2 = explode('_', $key); if ($key2[0] != 'unit' || !is_numeric($key2[1])) { continue; } $udefense = mysql_query("SELECT value FROM units_data WHERE unit_id=" . $key2[1] . " AND `key`='defense'") or die(mysql_error()); $udefense = mysql_fetch_assoc($udefense); $defense += $udefense['value'] * $city->getValue($key); } //end foreach keys $random_bound = $defense / rand(2, 6); $randomness = rand($random_bound * -1, $random_bound); $skill = mysql_query("SELECT value FROM units_data WHERE unit_id=" . $transaction['unit_id'] . " AND `key`='skill'") or die(mysql_error()); $skill = mysql_fetch_assoc($skill); $skill = $skill['value'] * $transaction['unit_count']; $results = $defense + $randomness - $skill; $pop = 0; $user = new user($transaction['user_id'], new server($transaction['server_id'])); if ($results < 0) { //only do something if successful $has_pop = intval($city->getValue('population')); $pop = $results * -1 * 4; $pop = $pop < $has_pop ? $pop : $has_pop; $city->setValue('population', $has_pop - $pop); $cities = $user->getValue('cities'); $cities[0]->setValue('population', $cities[0]->getValue('population') + $pop); } //end if results < 0 $class = $results < 0 ? 'succeeded' : 'failed'; $city_link .= $city->getValue('name') ? mysql_real_escape_string($city->getValue('name'), $db) : 'City at ' . $city->getValue('id'); mysql_query("INSERT INTO messages (server_id,user_id,time,message) VALUES (" . $transaction['server_id'] . "," . $transaction['user_id'] . "," . time() . ",'<span class=\"{$class}\">Subverting {$city_link} {$class} ({$pop} people turned)</span>')", $db) or die(mysql_error()); if ($user->getValue('twitter')) { send_tweet($user->getValue('twitter'), strip_tags("Subverting {$city_link} {$class} ({$pop} people turned)")); } $other_class = $class == 'succeeded' ? 'failed' : 'succeeded'; $user_link .= '<a href="/server/' . $transaction['server_id'] . '/user/' . $user->getValue('userid') . '">' . ($user->getValue('nickname') ? mysql_real_escape_string($user->getValue('nickname'), $db) : 'User #' . $user->getValue('userid')) . '</a>'; mysql_query("INSERT INTO messages (server_id,user_id,time,message) VALUES (" . $transaction['server_id'] . "," . $city->getValue('user')->getValue('userid') . "," . time() . ",'<span class=\"{$other_class}\">{$user_link} tried subverting {$city_link} and {$class} ({$pop} people turned)</span>')", $db) or die(mysql_error()); if ($city->getValue('user')->getValue('twitter')) { send_tweet($city->getValue('user')->getValue('twitter'), strip_tags("{$user_link} tried subverting {$city_link} and {$class} ({$pop} people turned)")); } }