Database rewrite, first half
[specialops2.git] / con.php
blobe3c78d571eb76432d55d35ac86a43c3a4aaec36c
1 <?php
2 // $Id$
4 define('CLOCK', microtime(1));
5 define('SO2VER', '$Rev$');
6 define('DEFAULT_LANGUAGE', 'en_GB, en_GB.UTF-8');
9 // Empty exception types
10 class InvalidInputException extends Exception { }
11 class DatabaseException extends Exception { }
12 class RateLimitException extends Exception { }
15 // These are useless
16 define('LVL_RESTRICTED', 0);
17 define('LVL_NEW', 10);
18 define('LVL_USER', 20);
19 define('LVL_VETERAN', 30);
20 define('LVL_VIP', 40);
21 define('LVL_MOD', 50);
22 define('LVL_ADMIN', 60);
23 define('LVL_DEV', 70);
26 // Some compatibility
27 if ( !function_exists('gettext') ) {
28 function _($message)
30 return $message;
32 function ngettext($msgid1, $msgid2, $n)
34 return 1 == $n ? $msgid1 : $msgid2;
36 define('NO_GETTEXT', 1);
37 } else {
38 bindtextdomain('so', './lang/locale');
39 textdomain('so');
43 //Class loader
44 function __autoload($classname)
46 require 'lib/class.'.$classname.'.php';
50 //Debug settings
51 if ( !isset($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'] || $_SERVER['REMOTE_ADDR'] === '84.24.205.182' )
52 define('DEVELOPER', 1);
55 //Exception handler
56 if ( defined('DEVELOPER') ) {
57 function e_handler($exception)
59 header('Content-Type: text/html; charset=UTF-8');
60 echo '<pre class="error">',$exception->__toString(),'</pre>';
61 exit;
63 } else {
64 function e_handler($exception)
66 restore_error_handler();
67 ini_set('display_errors', 0);
68 if ( !headers_sent() )
69 header('Content-Type: text/html; charset=UTF-8');
70 echo '<div class="error">',_('An unrecoverable error has been detected and page execution has been halted.'),"</div>\n",
71 '<div class="error">',_('Try reloading the page, or contact the site owner if this happens again.'),'</div>';
72 trigger_error($exception->getMessage(), E_USER_ERROR);
73 exit;
76 set_exception_handler('e_handler');
79 // Database Auth+object
80 require 'mysql_ident.php';
82 if ( defined('DEVELOPER') )
83 $DB = new debugmysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
84 else
85 $DB = new mysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
87 if ( mysqli_connect_errno() )
88 die('FUX');
91 // Login cookie setting hack
92 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
93 list($_COOKIE['u'], $_COOKIE['p']) = array($_POST['u'], $_POST['p']);
97 // User Auth+object
98 if ( isset($_POST['logout']) ) {
100 setcookie('u', null, 1);
101 setcookie('p', null, 1);
102 unset($_COOKIE);
103 $user = new anonuser($DB);
105 } elseif ( isset($_COOKIE['u'], $_COOKIE['p']) ) {
107 $q = $DB->query('SELECT `userid` FROM `users`
108 WHERE `alias` = \''.$DB->escape_string($_COOKIE['u']).'\'
109 AND `password` = AES_ENCRYPT(\''.$DB->escape_string($_COOKIE['p']).'\', `reg_ip`)');
111 if ( 1 === $q->num_rows ) {
112 setcookie('u', $_COOKIE['u'], time()+86400*7);
113 setcookie('p', $_COOKIE['p'], time()+86400*7);
115 if ( isset($_POST['login']) )
116 $DB->query('UPDATE `users` SET `last_login_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
117 WHERE `alias` = \''.$DB->escape_string($_COOKIE['u']).'\'');
119 if ( empty($prefetch) )
120 $prefetch = array();
122 $user = new authuser($DB, $q->fetch_object()->userid, $prefetch);
123 } else {
124 setcookie('u', null, 1);
125 setcookie('p', null, 1);
126 $user = new anonuser($DB);
129 } else {
130 $user = new anonuser($DB);
134 // Page object
135 if ( defined('DEVELOPER') )
136 $page = new debugpage();
137 else
138 $page = new page();