Three things:
[specialops2.git] / con.php
bloba11ccd5ca1bcd3a8d92953d4229892a61acf439b
1 <?php
2 /**
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
11 * @version $Id$
14 // The truck have started to move
15 define('SO2VER', '$Rev$');
16 define('T_START', microtime(1));
19 // Do you have stairs in your house
20 if ( version_compare(PHP_VERSION, '5.1', '<') ) {
21 include 'res/server-error.inc';
22 throw new Exception('PHP 5.1 or higher is required to run SO2.');
26 // [23:30:44] <~velociraptor> oh dear god
27 // [23:39:26] <&Flash> OH FUCK NO
28 require 'lib/class.Page.php';
29 require 'lib/class.so2mysqli.php';
30 require 'lib/class.User_Anonymous.php';
31 class InvalidInputException extends Exception {}
32 class DatabaseException extends Exception {}
33 class RateLimitException extends Exception {}
34 function __autoload($classname)
36 require 'lib/class.'.$classname.'.php';
40 // cordially welcomely in the Tutorial. Here you find the most important texts for Ogame on a view.
41 if ( $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'] ) {
42 define('DEVELOPER', 1);
46 // Unfortunately some texts already became outdated.
47 $page = new Page;
50 // If you have desire and and you are well in speaking englisch and german just mail to me
51 if ( defined('DEVELOPER') ) {
52 ob_start();
53 // (...waaaaaaaaaaay tmi.)
54 function e_handler($exception)
56 header('HTTP/1.1 500 Internal Server Error');
57 header('Content-Type: text/html; charset=UTF-8');
58 echo "<h1 onmouseover='blank_stare()'>OMFG!!1</h1>\n",
59 '<pre class="error">',$exception,'</pre>';
60 exit;
62 } else {
63 function e_handler($exception)
65 if ( !headers_sent() ) {
66 header('HTTP/1.1 500 Internal Server Error');
67 header('Content-Type: text/html; charset=UTF-8');
70 $GLOBALS['page']->errorfooter('runtime');
74 set_exception_handler('e_handler');
75 require 'mysql.php';
77 if ( mysqli_connect_errno() ) {
78 include 'res/server-error.inc';
79 throw new Exception('No database connection.');
83 // dogshit brownies
84 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
85 list($_COOKIE['u'], $_COOKIE['p']) = array($_POST['u'], $_POST['p']);
88 // Destroy user cookie details on logout
89 if ( isset($_POST['logout']) ) {
90 setcookie('u', null, 1, '/');
91 setcookie('p', null, 1, '/');
92 unset($_COOKIE);
96 // overspong
97 if ( isset($_COOKIE['u'], $_COOKIE['p']) ) {
98 // WHERE IS SARAH CONNOR
99 $q = $DB->query('SELECT @userid := `userid` FROM `users`
100 WHERE `alias` = '.$DB->string($_COOKIE['u']).'
101 AND (`password` = AES_ENCRYPT('.$DB->string($_COOKIE['p']).', `reg_ip`)
102 OR `password` IS NULL)');
104 // I'M RICK JAMES BITCH
105 if ( 1 === $q->num_rows ) {
106 // Keep login cookie valid for 2 days
107 setcookie('u', $_COOKIE['u'], time()+172800, '/');
108 setcookie('p', $_COOKIE['p'], time()+172800, '/');
110 $user = new User_Authenticated(isset($prefetch) ? $prefetch : null);
111 } else {
112 // NO WAI
113 setcookie('u', null, 1, '/');
114 setcookie('p', null, 1, '/');
115 unset($_COOKIE);
117 $user = new User_Anonymous;
119 } else
120 $user = new User_Anonymous;