Made the GFCSS theme work a bit better
[specialops2.git] / con.php
blob95037193e6fa795c6d64d98889314563a668cdb4
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;
63 // there's no reason for using this class at all any more but it makes the code look more important
64 $dbtype = 'debugmysqli';
65 } else {
66 function e_handler($exception)
68 if ( !headers_sent() ) {
69 header('HTTP/1.1 500 Internal Server Error');
70 header('Content-Type: text/html; charset=UTF-8');
73 $GLOBALS['page']->errorfooter('runtime');
76 $dbtype = 'so2mysqli';
79 set_exception_handler('e_handler');
80 require 'mysql.php';
82 if ( mysqli_connect_errno() ) {
83 include 'res/server-error.inc';
84 throw new Exception('No database connection.');
88 // dogshit brownies
89 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
90 list($_COOKIE['u'], $_COOKIE['p']) = array($_POST['u'], $_POST['p']);
93 // Destroy user cookie details on logout
94 if ( isset($_POST['logout']) ) {
95 setcookie('u', null, 1, '/');
96 setcookie('p', null, 1, '/');
97 unset($_COOKIE);
101 // overspong
102 if ( isset($_COOKIE['u'], $_COOKIE['p']) ) {
103 // WHERE IS SARAH CONNOR
104 $q = $DB->query('SELECT @userid := `userid` FROM `users`
105 WHERE `alias` = '.$DB->string($_COOKIE['u']).'
106 AND (`password` = AES_ENCRYPT('.$DB->string($_COOKIE['p']).', `reg_ip`)
107 OR `password` IS NULL)');
109 // I'M RICK JAMES BITCH
110 if ( 1 === $q->num_rows ) {
111 // Keep login cookie valid for 2 days
112 setcookie('u', $_COOKIE['u'], time()+172800, '/');
113 setcookie('p', $_COOKIE['p'], time()+172800, '/');
115 $user = new User_Authenticated(isset($prefetch) ? $prefetch : null);
116 } else {
117 // NO WAI
118 setcookie('u', null, 1, '/');
119 setcookie('p', null, 1, '/');
120 unset($_COOKIE);
122 $user = new User_Anonymous;
124 } else
125 $user = new User_Anonymous;