时间:2021-07-01 10:21:17 帮助过:7人阅读
$do = @$_GET['do'];
if ('' == $do)
{
exit('Missing Action');
}
require 'config.php';
require 'dll.php';
session_start();
// check session
if ('' == $_SESSION['sid']) exit('登录超时,请关闭重试!');
switch ($do)
{
case 'init':
// check user && update
dll::import('mysql');
$db = new mysql();
$db->connect($dbs['server'], $dbs['user'], $dbs['password']);
$db->database($dbs['database']);
// update
$rs = $db->update(DBPrefix.'user', 'sid="'.$_SESSION['sid'].'"');
$rs->set('client_to', '');
$rs->set('role', RoleOnline);
$rs->set('last_access_time', time());
$rs->setfunc('login_count', 'login_count+1');
$rs->set('last_login_time', time());
$ip = $_SERVER['REMOTE_ADDR'];
$ipx = explode('.', $ip);
$iplong =
$ipx[0] * 16777216 +
$ipx[1] * 65536 +
$ipx[2] * 256 +
$ipx[3];
$rs->set('last_login_ip', $iplong);
if (!$rs->update())
{
// add new
$rs = $db->insert(DBPrefix.'user');
$rs->set('sid', $_SESSION['sid']);
$rs->set('client_to', '');
$rs->set('role', RoleOnline);
$rs->set('last_access_time', time());
$rs->set('login_count', 1);
$rs->set('last_login_time', time());
$rs->set('last_login_ip', $iplong);
$rs->insert();
}
$db->close();
// display init page
display('init.html');
break;
case 'status':
dll::import('mysql');
// access $dbs
global $dbs;
$db = new mysql();
$db->connect($dbs['server'], $dbs['user'], $dbs['password']);
$db->database($dbs['database']);
// update access
update_access($db);
// import mysql.class
display('server.status.html');
$db->close();
break;
case 'work':
$mode = $_GET['mode'];
// update work mode
dll::import('mysql');
$db = new mysql();
$db->connect($dbs['server'], $dbs['user'], $dbs['password']);
$db->database($dbs['database']);
// update
$rs = $db->update(DBPrefix.'user', 'sid="'.$_SESSION['sid'].'"');
switch ($mode)
{
case 'answer':
$rs->set('role', RoleAnswer);
break;
case 'asker':
$rs->set('role', RoleAsker);
break;
case 'chater':
$rs->set('role', RoleChater);
break;
case 'offline':
$rs->set('role', RoleOffline);
$rs->set('client_to', '');
// delete input status cache
@unlink(dirname('.').'/cache/'.$_SESSION['sid'].'.input.status');
// clear session
unset($_SESSION);
break;
}
$rs->set('last_access_time', time());
$rs->update();
$db->close();
// display mode page
if ($mode != 'offline')
{