109 lines
2.9 KiB
PHP
109 lines
2.9 KiB
PHP
<?php
|
|
$ini = parse_ini_file("conf.ini", true);
|
|
|
|
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
|
|
mysql_select_db($ini['db']['db']);
|
|
|
|
$postfix=$_REQUEST['postfix'];
|
|
$nick=$_REQUEST['nick'];
|
|
$password=$_REQUEST['password'];
|
|
if (!empty($_REQUEST['u_code']))
|
|
{
|
|
$user_code=$_REQUEST['u_code'];
|
|
}
|
|
else
|
|
{
|
|
$user_code=0;
|
|
}
|
|
|
|
if ($ini['db']['log']=="1"){
|
|
$arrival_time=microtime(true);
|
|
$filename=basename(__FILE__);
|
|
$filename="log_".$filename.".txt";
|
|
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI'].$nick."\r\n";
|
|
file_put_contents($filename,$chunck,FILE_APPEND);
|
|
}
|
|
|
|
mysql_set_charset("utf8");
|
|
|
|
if (strcmp($postfix,'_ita_gen')==0){
|
|
$online_table='online_chat_ita';
|
|
}
|
|
if (strcmp($postfix,'_es_gen')==0){
|
|
$online_table='online_chat_es';
|
|
}
|
|
if (strcmp($postfix,'_eng_gen')==0){
|
|
$online_table='online_chat_eng';
|
|
}
|
|
if (strcmp($postfix,'_pt_gen')==0){
|
|
$online_table='online_chat_pt';
|
|
}
|
|
if (strcmp($postfix,'_jp_gen')==0){
|
|
$online_table='online_chat_jp';
|
|
}
|
|
if (strcmp($postfix,'_zh_gen')==0){
|
|
$online_table='online_chat_zh';
|
|
}
|
|
if (strcmp($postfix,'_tag_gen')==0){
|
|
$online_table='online_chat_tag';
|
|
}
|
|
$filename=$online_table.".txt";
|
|
|
|
if ($nick<>''){
|
|
if ($user_code!=0){
|
|
$sql=mysql_query("select user_code,last_known_user_id,canbemoderator from contest_nick where user_code=$user_code limit 1");
|
|
}
|
|
else{
|
|
$sql=mysql_query("select user_code,last_known_user_id,canbemoderator from contest_nick where nick='$nick' and pwd='$password' limit 1");
|
|
}
|
|
if (mysql_num_rows($sql)){
|
|
$user_code=mysql_result($sql,0,"user_code");
|
|
$canbemoderator=mysql_result($sql,0,"canbemoderator");
|
|
$user_id=mysql_result($sql,0,"last_known_user_id");
|
|
if ($canbemoderator==1){
|
|
$sql=mysql_query("select count(*) as c from $online_table where moderator=1 and status=0");
|
|
$c=mysql_result($sql,0,"c");
|
|
if ($c<=3){
|
|
$moderator=1;
|
|
}
|
|
else{
|
|
$moderator=0;
|
|
}
|
|
$sql=mysql_query("update contest_nick set moderator=$moderator where user_code=$user_code limit 1");
|
|
}
|
|
else{
|
|
$moderator=0;
|
|
}
|
|
$sql=mysql_query("replace into $online_table (user_code,user_id,nick,moderator,date) values ($user_code,$user_id,'$nick',$moderator,NOW())");
|
|
}
|
|
}
|
|
|
|
if (file_exists($filename)){
|
|
$delta_time=time()-filemtime($filename);
|
|
}
|
|
else{
|
|
$delta_time=1000;
|
|
}
|
|
|
|
if ($delta_time>3)
|
|
{
|
|
$sql=mysql_query('SET CHARACTER SET utf8');
|
|
$sql=mysql_query("select user_code,nick,moderator,status,TIMESTAMPDIFF(MINUTE,date,NOW()) AS difference from $online_table where nick<>'' order by status,nick");
|
|
if (mysql_num_rows($sql)){
|
|
while($e=mysql_fetch_assoc($sql))
|
|
$output_file[]=$e;
|
|
$json_file = json_encode($output_file);
|
|
file_put_contents($filename,$json_file);
|
|
}
|
|
else{
|
|
$fh = fopen($filename,'w');
|
|
fclose($fh);
|
|
}
|
|
}
|
|
|
|
$data = file_get_contents($filename);
|
|
print($data);
|
|
|
|
mysql_close();
|
|
?>
|