<?php
#-----------------------------------------------------#
#          ********* WAP-MOTORS *********             #
#             Made by   :  VANTUZ                     #
#               E-mail  :  vsem@pizdec.ru             #
#                 Site  :  http://pizdec.ru           #
#             WAP-Site  :  http://visavi.net          #
#                  ICQ  :  36-44-66                   #
#  Вы не имеете право вносить изменения в код скрипта #
#-----------------------------------------------------#	
require_once"../template/start.php";
require_once"../template/regglobals.php";
require_once"../template/config.php";
require_once"../template/functions.php";
require_once"../template/antidos.php";
require_once"../template/gzip.php";
require_once"../template/header.php";

$text = file("../local/profil/$log.prof"); 
if ($text!=""){
$udata = explode(":||:",$text[0]);
$provlog=trim($udata[0]);
$provpar=trim($udata[1]);}

if ($_SESSION['log']!="" && md5($_SESSION['par'])!="" && md5($_SESSION['par'])==$provpar && $_SESSION['log']==$provlog ) {
$name=$log;

$brow=check($brow);

$date=date("d.m.y");
$time=time(); 
if (isset ($_GET['msg']) or isset ($_GET['name'])){header ("Location: index.php?isset=names&".SID); exit;}
if (strlen($msg) > 1000 || strlen(trim($msg)) < 5) {header ("Location: index.php?isset=posts&".SID);  exit;}

//--------------------- Новый антифлуд -----------------------------//
if($config_floodstime > 0){
if(flooder($ip, $php_self) == TRUE ){header ("Location: index.php?isset=antiflood&".SID); exit;}
$flood_file = fopen(BASEDIR."local/flood.dat", "a+");
flock ($flood_file,LOCK_EX);
fputs ($flood_file, time()."|$ip|$php_self|\r\n");
fflush($flood_file);
flock ($flood_file,LOCK_UN);
fclose($flood_file);   
}

$msg=check($msg);
$name=check($name);
	
if($trans=="y"){$msg=transliter($msg);}

$msg = antimat($msg);
$msg = smiles($msg);


$mmagfi=file("../local/chat.dat");
$mmagcount=count($mmagfi);
$mmagcount=$mmagcount-1; 
$mmagstr=$mmagfi[$mmagcount];
$mmagshow = explode("|",$mmagstr);

$text=$msg.'|'.$name.'|'.$date.'|'.$time.'|'.$brow.'|'.$ip.'|НО|'.$mmagshow[7].'|'.$mmagshow[8].'|';
$text=preg_replace ("|[\r\n]+|si","",$text);

$fp=fopen("../local/chat.dat","a+");
flock ($fp,LOCK_EX);
fputs($fp,"$text\r\n");
flock ($fp,LOCK_UN);
fclose($fp);
$messch="1";

if($config_botnik=="1"){ 
require_once"../template/chat_bot.php";
if(!empty($mssg)){
$text3=$mssg.'|'.$namebots.'|'.$date.'|'.$time.'|MOT-V3|L-O-V-E|НО|'.$mmagshow[7].'|'.$mmagshow[8].'|';
$text3=preg_replace ("|[\r\n]+|si","",$text3);

$fp=fopen("../local/chat.dat","a+");
flock ($fp,LOCK_EX);
fputs($fp,"$text3\r\n");
flock ($fp,LOCK_UN);
fclose($fp);
$messch="2";}
}
/////////////////////////////////////

/////////////////////////////////////
$f = file("../local/local.dat"); 
$u = explode("|",$f[0]);
$u[1]=$u[1]+$messch;
$t=$u[0].'|'.$u[1].'|'.$u[2].'|'.$u[3].'|'.$u[4].'|'.$u[5].'|'.$u[6].'|'.$u[7].'|'.$u[8].'|'.$u[9].'|'.$u[10].'|';

$fp = fopen("../local/local.dat","a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
fputs($fp,$t);
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);
///////////////////////////


$file=file("../local/chat.dat"); 
$i = count($file);
if ($i>=$config_maxpostchat) {
$fp=fopen("../local/chat.dat","w");
flock ($fp,LOCK_EX);
unset($file[0],$file[1],$file[2],$file[3],$file[4]);
fputs($fp, implode("",$file));
flock ($fp,LOCK_UN);
fclose($fp);
}





//------------------------------ Запись в профиль ----------------------------//
$ufile = file(BASEDIR."local/profil/$log.prof"); 
$udata = explode(":||:",$ufile[0]);

$udata[14]=$ip;
$udata[12]++;
$udata[36]++;
$udata[41]++;

for ($u=0; $u<$config_userprofkey; $u++){
$utext.=$udata[$u].':||:';}

if($udata[0]!="" && $udata[1]!="" && $udata[4]!="" && $utext!=""){
$fp=fopen(BASEDIR."local/profil/$log.prof","a+");
flock($fp,LOCK_EX);   
ftruncate($fp,0);                                                                 
fputs($fp,$utext);
fflush($fp);
flock($fp,LOCK_UN);
fclose($fp);  
unset($utext);
}
//--------------------------------------------------------------------------//


if($config_magnik=="1"){
$ttty=$time+60;
if (stristr($msg2, $mmagshow[8])) { 
$magmsg = 'Молодец '.$name.'! Правильный ответ <b>'.$mmagshow[8].'</b>! Следующий вопрос через 2 минуты';	
$mmagshow[8]="-";
$mmtext=$magmsg.'|Вундер-киндер|'.$date.'|'.$time.'|Opera|127.0.0.3|НО|'.$ttty.'||';
$mmtext=preg_replace ("|[\r\n]+|si","",$mmtext);

$fp=fopen("../local/chat.dat","a+");
flock ($fp,LOCK_EX);
fputs($fp,"$mmtext\r\n");
flock ($fp,LOCK_UN);
fclose($fp);
}}

header ("Location: index.php?isset=addon&".SID);
}else{header ("Location: ../index.php?isset=inputoff&".SID); exit;}


?>
