<?php
define('PROTECTOR', 1);
//**********
include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
$textl='Новая игра';
include($path.'files/core.php');
include($path.'files/head.php');
//**********
echo'<div class="foot center"><span style="color: #;">Беспредел в тюряге</span></div><div class="line"></div>';
echo'<div class="main"><center><img src="image/logo/logo2.png"  alt="logo"><div class="mini-line"></div><div class="block_zero">';
//**********
function first(){
$ref=htmlspecialchars(stripslashes($_GET['ref']));
$referer=htmlspecialchars(stripslashes($_GET['refer']));
//**********
if(isset($_GET['ref'])){
echo'<form action="reg.php?mod=goreg&amp;ref='.$ref.'&refer='.$referer.'" method="POST">';
}else{
echo '<form action="reg.php?mod=goreg&refer='.$referer.'" method="POST">';
}
echo'Логин(Лат. буквы и цифры)<small></small><br>
<input class="text" type="text" size="15" name="nick" maxlength="10"><br>Пароль <small></small><br><input class="text" name="pass" size="15" type="password" maxlength="10"><br>Ваш E-Mail <small></small><br><input class="text" type="text" size="10" name="email" maxlength="50"><br>Пол <small></small><br><select name="pol"><option value="m">Мужской</option><option value="w">Женский</option></select><br>Сторона<small></small><br><select name="storona"><option value="black">Красные</option><option value="white">Синие</option></select><br></option>';

echo '<center><span class="btn"><span class="end"><input class="label" type="submit" value="Начать игру!"></span></span></form><center></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="index.php?ref='.$ref.'">На главную</a></div>';
}
function goreg(){

if (isset($_SERVER['HTTP_REFERER'])){
$otkuda=htmlspecialchars(stripslashes($_SERVER['HTTP_REFERER']));
}else{
$otkuda='http://'.$_SERVER['HTTP_HOST'];
}

$brauser=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));
$ip=htmlspecialchars(stripslashes($_SERVER['REMOTE_ADDR']));

$pass = $_POST['pass'];
$_POST['nick'] = addslashes("$_POST[nick]");
$_POST['nick'] = htmlspecialchars($_POST['nick']);
$_POST['pass'] = addslashes("$_POST[pass]");       
$_POST['pass'] = htmlspecialchars($_POST['pass']);
$_POST['email'] = addslashes("$_POST[email]");       
$_POST['email'] = htmlspecialchars($_POST['email']);
$email = $_POST['email'];
$tkr = mysql_query("SELECT * FROM `users` WHERE `usr` = '$_POST[nick]'");
$tkr=mysql_num_rows($tkr);
$temn = mysql_query("SELECT * FROM `users` WHERE `email` = '$_POST[email]'");
$tem=mysql_num_rows($temn);

if(iconv_strlen($_POST['nick'])<3 OR mb_strlen($_POST['nick'])>10){
echo'<div class="block_zero center">Не правильная длина ника!</div></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="reg.php">Назад</a></div>';
}
elseif (preg_replace("#([A-za-z0-9]+)#si", "", $_POST['nick']) || preg_replace("#([A-za-z0-9]+)#si", "", $_POST['pass'])){
echo'<div class="block_zero center">Используете запрещённые символы!</div></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="reg.php">Назад</a></div>';
}
elseif (preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $_POST['email']) == 0 ){
echo'<div class="block_zero center">Не правильно введён e-mail!</div></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="reg.php">Назад</a></div>';
}
elseif (($tkr < 1) && ($tem < 1) && ($_POST['nick'] != "") && ($_POST['pass'] != "") ){
$dater=date("d F, Y", time());
$time=date("H:i:s", time());
$dater = str_replace("January","января",$dater);
$dater = str_replace("February","февраля",$dater);
$dater = str_replace("March","марта",$dater);
$dater = str_replace("April","апреля",$dater);
$dater = str_replace("May","мая",$dater);
$dater = str_replace("June","июня",$dater);
$dater = str_replace("July","июля",$dater);
$dater = str_replace("August","августа",$dater);
$dater = str_replace("September","сентября",$dater);
$dater = str_replace("October","октября",$dater);
$dater = str_replace("November","ноября",$dater);
$dater = str_replace("December","декабря",$dater);

$_POST['pass'] = md5($_POST['pass']);
$storona = $_POST['storona'];

$mp='1000';
$all='150';
$sila='50';
$krit='0';
$ukrit='5';
$lovk='50';
$protect='50';

if(isset($_GET['ref'])){
$_GET['ref'] = htmlspecialchars(stripslashes($_GET['ref']));
$req = mysql_query("SELECT `ip` FROM `users` WHERE `id` = '$_GET[ref]' LIMIT 1");
$avto = mysql_num_rows($req);
if ($avto == 1) {
    $refer = mysql_fetch_array($req);
    if($ip!=$refer['ip']){ 
    mysql_query("INSERT INTO
        `users` SET
        `usr` = '$_POST[nick]',
        `pass` = '$_POST[pass]',
        `email` = '$_POST[email]',
        `ip` = '$ip',
        `pol` = '".mysql_real_escape_string($_POST['pol'])."',
        `storona` = '".mysql_real_escape_string($_POST['storona'])."',
        `lvl` = '1',
        `money` = '5000',
        `skill` = '6',
        `hp` = '$all',
        `hpall` = '$all',
        `mp` = '$mp',
        `mpall` = '$mp',
        `exp` = '0',
        `almaz` = '200',
        `sila` = '$sila',
        `lovk` = '$lovk',
        `prot` = '$protect',
        `krit` = '$krit',
        `ukrit` = '$ukrit',
        `logotip` = '2',
        `pan` = '1',
        `klas` = 'wizard',
        `city` = 'fornost',
        `ref` = '$_GET[ref]',
		`activ` = 'on',
        `lvisit` = '$dater $time'");
         }
    }
    }else{
    mysql_query("INSERT INTO
        `users` SET
        `usr` = '$_POST[nick]',
        `pass` = '$_POST[pass]',
        `email` = '$_POST[email]',
        `ip` = '$ip',
        `pol` = '".mysql_real_escape_string($_POST['pol'])."',
        `storona` = '".mysql_real_escape_string($_POST['storona'])."',
        `lvl` = '1',
        `money` = '5000',
        `skill` = '6',
        `hp` = '$all',
        `hpall` = '$all',
        `mp` = '$mp',
        `mpall` = '$mp',
        `exp` = '0',
        `almaz` = '200',
        `sila` = '$sila',
        `lovk` = '$lovk',
        `prot` = '$protect',
        `krit` = '$krit',
        `ukrit` = '$ukrit',
        `logotip` = '2',
        `pan` = '1',
        `klas` = 'wizard',
        `city` = 'fornost',
        `ref` = 'not',
		`activ` = 'on',
        `lvisit` = '$dater $time'");
}
if(isset($_SESSION['site'])){
$site=htmlspecialchars($_SESSION['site']);
mysql_query("INSERT INTO `set` SET `site` = '$site'");
}
mysql_query("INSERT INTO `res` SET `usr` = '$_POST[nick]', `lat_name` = 'jelezo', `name` = 'Железо',`kol` = '1', `tip`='res', `cena`='10'");
mysql_query("INSERT INTO `res` SET `usr` = '$_POST[nick]', `lat_name` = 'kamen', `name` = 'Камень',`kol` = '1', `tip`='res', `cena`='10'");
mysql_query("INSERT INTO `res` SET `usr` = '$_POST[nick]', `lat_name` = 'nefrit',`name` = 'Нефрит', `kol` = '1', `tip`='res', `cena`='10'");
mysql_query("INSERT INTO `res` SET `usr` = '$_POST[nick]', `lat_name` = 'obsidian',`name` = 'Обсидиан', `kol` = '1', `tip`='res', `cena`='10'");
mysql_query("INSERT INTO `res` SET `usr` = '$_POST[nick]', `lat_name` = 'serebro',`name` = 'Оникс', `kol` = '1', `tip`='res', `cena`='10'");
mysql_query("INSERT INTO `mesto` SET `usr` = '$_POST[nick]',`place` = 'main',`city` = '0'");
$date = time();
mysql_query("INSERT INTO `regenerator` SET `usr` = '$_POST[nick]', `last` = '$date'");
mysql_query("INSERT INTO `mag` SET `usr` = '$_POST[nick]', `yarost` ='0', `bronya`='0', `vihr`='0',`stoika` ='0', `vihr2`= '0'");
mysql_query("INSERT INTO `set` SET `usr` = '$_POST[nick]', `datareg` = '$date', `email` = '$_POST[email]', `brauser` = '$brauser', `referer` = '".mysql_real_escape_string($otkuda)."' , `prim` = 'on', `arenainv`= '0', `invmax`= '0'");

$_SESSION['log'] = $_POST['nick'];
$_SESSION['pas'] = $_POST['pass'];
$_SESSION['klas'] = $_POST['klas'];
$_SESSION['storona'] = $storona;
$_SESSION['pol'] = $_POST['pol'];
header('Location: index.php');exit;
}
elseif($_POST['nick'] == ""){
echo'<div class="block_zero center">Вы оставили пустое поле: Логин!</div></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="reg.php">Назад</a></div>';
}
elseif($_POST['pass'] == ""){
echo'<div class="block_zero center">Вы оставили пустое поле: Пароль!</div></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="reg.php">Назад</a></div>';
}
elseif($tem >= 1){
echo'<div class="block_zero center">E-mail занят!</div></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="reg.php">Назад</a></div>';
}
elseif($tkr > 0){
echo'<div class="block_zero center">Логин занят, выберите другой!</div></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="reg.php">Назад</a></div>';
}
}
function intro(){
if(empty($_SESSION['log']) OR empty($_SESSION['pas']) OR empty($_SESSION['storona']) OR empty($_SESSION['klas']) OR empty($_SESSION['pol'])){
echo'<div class="block_zero center">Ошибка!</div></div><div class="line"></div></div>';
echo'<div class="block_zero center"><a href="reg.php">Назад</a></div>';
}else{
header('Location: index.php');exit;
}
}
if($_GET['mod'] == ''){
first();
}
elseif($_GET['mod'] == 'goreg'){
goreg();
}
elseif($_GET['mod'] == 'intro'){
intro();
}
include($path.'files/end.php');
?>