<?php
	
	include_once __DIR__ . '/include/common.php';
	include_once __DIR__ . '/include/general_functions.php';
	include_once __DIR__ . '/include/utils.php';	
	include_once __DIR__ . '/include/user.php';
	
	if ( ! @$user)
	{
		
		$name	=	'Боец';
		$password
				=	md5(uniqid());
		$token	=	md5(uniqid());
		
		//	User
		@mysql_query(sprintf(
			'INSERT INTO
					`users`
					(
						`login`,
						`password`,
						`token`,
						`align`
					)
					VALUES
					(
						"%s",
						"%s",
						"%s",
						%d
					)
				',
			$name,
			$password,
			$token,
			mt_rand(0, 1)
		));
		
		$id		=	@mysql_insert_id();
		
		//	Training
		@mysql_query(sprintf(
			'INSERT INTO
					`user_train`
					(
						`user_id`
					)
					VALUES
					(
						%d
					)
				',
			$id
		));
		
		@mysql_query(sprintf(
			'INSERT INTO
					`user_sack`
					(
						`user_id`
					)
					VALUES
					(
						%d
					)
				',
			$id
		));
		
		@mysql_query(sprintf(
			'INSERT INTO
					`user_abilities`
					(
						`user_id`
					)
					VALUES
					(
						%d
					)
				',
			$id
		));
		
		@mysql_query(sprintf(
			'INSERT INTO
					`user_abilities_train`
					(
						`user_id`
					)
					VALUES
					(
						%d
					)
				',
			$id
		));
		
		@mysql_query(sprintf(
			'INSERT INTO
					`arena`
					(
						`user_id`
					)
					VALUES
					(
						%d
					)
				',
			$id
		));
		
		@mysql_query(sprintf(
			'INSERT INTO
					`duel`
					(
						`uid`
					)
					VALUES
					(
						%d
					)
				',
			$id
		));
		
		@mysql_query(sprintf(
			'INSERT INTO
					`duel`
					(
						`user_id`,
						`fights`,
						`time`
					)
					VALUES
					(
						%d,
						5,
						%d
					)
				',
			$id,
			time()
		));
		
		@mysql_query(sprintf(
			'INSERT INTO
					`user_inv`
					(
						`user_id`
					)
					VALUES
					(
						%d
					)
				',
			$id
		));
		
		$_SESSION['__user']	=	$token;
		
		redirect('/');
		
	}
	