138 lines
3.4 KiB
PHP
138 lines
3.4 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']);
|
|
|
|
if ($ini['db']['log']=="1"){
|
|
$arrival_time=microtime(true);
|
|
$filename=basename(__FILE__);
|
|
$filename="log_".$filename.".txt";
|
|
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
|
|
file_put_contents($filename,$chunck,FILE_APPEND);
|
|
}
|
|
|
|
mysql_set_charset("utf8");
|
|
|
|
$user_id=$_REQUEST['u_id'];
|
|
$nick=$_REQUEST['nick'];
|
|
$password=$_REQUEST['password'];
|
|
$message_gcm=$_REQUEST['message'];
|
|
$message=mysql_real_escape_string($message_gcm);
|
|
$user_code_to=$_REQUEST['user_code_to'];
|
|
|
|
if (!empty($_REQUEST['u_code'])){
|
|
$user_code_from=$_REQUEST['u_code'];
|
|
}
|
|
else{
|
|
$user_code_from=0;
|
|
}
|
|
|
|
|
|
$sql=mysql_query("select * from banned where user_id=$user_id");
|
|
if (mysql_num_rows($sql))
|
|
{
|
|
$banned=1;
|
|
}
|
|
else
|
|
{
|
|
$banned=0;
|
|
}
|
|
|
|
if($message!=='' && $banned==0 && $user_id<>0)
|
|
{
|
|
if ($user_code_from==0){
|
|
$sql=mysql_query("select ID,user_code from contest_nick where nick='$nick' and pwd='$password' limit 1");
|
|
if (mysql_num_rows($sql))
|
|
{
|
|
$user_code_from=mysql_result($sql,0,"user_code");
|
|
$match=1;
|
|
}
|
|
else
|
|
{
|
|
$match=0;
|
|
}
|
|
}
|
|
else{
|
|
$match=1;
|
|
}
|
|
|
|
if ($match==1){
|
|
$sql=mysql_query("select last_known_user_id,nick from contest_nick where user_code=$user_code_to limit 1");
|
|
if (mysql_num_rows($sql))
|
|
{
|
|
$user_id_to=mysql_result($sql,0,"last_known_user_id");
|
|
$user_nick_to=mysql_result($sql,0,"nick");
|
|
|
|
$sql=mysql_query("select count(*) as ban_count from personal_ban where user_id_from=$user_id_to and user_id_to=$user_id limit 1");
|
|
$ban_count=mysql_result($sql,0,"ban_count");
|
|
|
|
if ($ban_count==0){
|
|
if ($user_id_to<>0){
|
|
$sql=mysql_query("insert into personal_chat (user_id_from,user_id_to,nick_from,nick_to,message) values ($user_id,$user_id_to,'$nick','$user_nick_to','$message')");
|
|
|
|
$sql=mysql_query("select reg_id from gcm where user_id=$user_id_to limit 1");
|
|
if (mysql_num_rows($sql)){
|
|
$dataArray = array('message'=>$message_gcm,
|
|
'user_code_from'=>$user_code_from,
|
|
'user_code_to'=>$user_code_to,
|
|
'user_nick_from'=>$nick,
|
|
'user_nick_to'=>$user_nick_to,
|
|
'type'=>'chat_personal');
|
|
|
|
$regidArray[0]=mysql_result($sql,0,"reg_id");
|
|
$headers = array(
|
|
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
|
|
'Content-Type: application/json');
|
|
$fields = array(
|
|
'registration_ids' => $regidArray,
|
|
'data' => $dataArray);
|
|
|
|
$context = stream_context_create(array(
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' => $headers,
|
|
'content' => json_encode($fields))));
|
|
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
|
|
$response=json_decode($response);
|
|
if ($response->success==1)
|
|
{
|
|
print("ok");
|
|
}
|
|
else
|
|
{
|
|
print("wrong");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
print("usergone");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
print("usergone");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
print("banned");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
print("wrong");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
print("wrong");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
print("wrong");
|
|
}
|
|
mysql_close();
|
|
?>
|