3 * con.php: Generic setup file.
5 * Contains user authentication, database connection and other exciting stuff.
6 * Everything else depends on this file. Don't touch it unless you know what
7 * you're doing, all the config is done in other places (mostly mysql.php).
9 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
10 * @license file://COPYING
14 // The truck have started to move
15 define('SO2VER', '$Rev$');
18 // Do you have stairs in your house
19 if ( version_compare(PHP_VERSION
, '5.1', '<') ) {
20 include 'res/server-error.inc';
21 throw new Exception('PHP 5.1 or higher is required to run SO2.');
25 // [23:30:44] <~velociraptor> oh dear god
26 // [23:39:26] <&Flash> OH FUCK NO
27 require 'lib/class.Page.php';
28 require 'lib/class.so2mysqli.php';
29 require 'lib/class.User_Anonymous.php';
30 class InvalidInputException
extends Exception
{}
31 class DatabaseException
extends Exception
{}
32 class RateLimitException
extends Exception
{}
33 function __autoload($classname)
35 require 'lib/class.'.$classname.'.php';
39 // cordially welcomely in the Tutorial. Here you find the most important texts for Ogame on a view.
40 if ( $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'] ) {
41 define('DEVELOPER', 1);
45 // Unfortunately some texts already became outdated.
49 // If you have desire and and you are well in speaking englisch and german just mail to me
50 if ( defined('DEVELOPER') ) {
52 // (...waaaaaaaaaaay tmi.)
53 function e_handler($exception)
55 header('HTTP/1.1 500 Internal Server Error');
56 header('Content-Type: text/html; charset=UTF-8');
57 echo "<h1 onmouseover='blank_stare()'>OMFG!!1</h1>\n",
58 '<pre class="error">',$exception,'</pre>';
62 // there's no reason for using this class at all any more but it makes the code look more important
63 $dbtype = 'debugmysqli';
65 function e_handler($exception)
67 if ( !headers_sent() ) {
68 header('HTTP/1.1 500 Internal Server Error');
69 header('Content-Type: text/html; charset=UTF-8');
72 $GLOBALS['page']->errorfooter('runtime');
75 $dbtype = 'so2mysqli';
78 set_exception_handler('e_handler');
81 if ( mysqli_connect_errno() ) {
82 include 'res/server-error.inc';
83 throw new Exception('No database connection.');
88 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
89 list($_COOKIE['u'], $_COOKIE['p']) = array($_POST['u'], $_POST['p']);
92 // Destroy user cookie details on logout
93 if ( isset($_POST['logout']) ) {
94 setcookie('u', null, 1, '/');
95 setcookie('p', null, 1, '/');
101 if ( isset($_COOKIE['u'], $_COOKIE['p']) ) {
102 // WHERE IS SARAH CONNOR
103 $q = $DB->query('SELECT @userid := `userid` FROM `users`
104 WHERE `alias` = '.$DB->string($_COOKIE['u']).'
105 AND (`password` = AES_ENCRYPT('.$DB->string($_COOKIE['p']).', `reg_ip`)
106 OR `password` IS NULL)');
108 // I'M RICK JAMES BITCH
109 if ( 1 === $q->num_rows
) {
110 // Keep login cookie valid for 2 days
111 setcookie('u', $_COOKIE['u'], time()+
172800, '/');
112 setcookie('p', $_COOKIE['p'], time()+
172800, '/');
114 $user = new User_Authenticated(isset($prefetch) ?
$prefetch : null);
117 setcookie('u', null, 1, '/');
118 setcookie('p', null, 1, '/');
121 $user = new User_Anonymous
;
124 $user = new User_Anonymous
;