<?php
session_start();
include("functions.php");
include("serverConnect.php");

$displayError = true;
if (isset($_POST['pseudo']) && isset($_POST['password']) && isset($_POST['email'])) {	
	
	$pseudo=htmlspecialchars($_POST['pseudo']);
	$password = hash("sha256", $_POST['password']);
	$mail=htmlspecialchars($_POST['email']);
	 
	$req = $bdd->prepare('SELECT * FROM cUsers WHERE pseudo = ?');
	$req->execute(array($pseudo));

	if(!$req->fetch()) {
		$req = $bdd->prepare('INSERT INTO cUsers (pseudo, password, mail) VALUES(?, ?, ?)');
		$req->execute(array($pseudo, $password, $mail));
		
		$req = $bdd->prepare('SELECT id FROM nUsers WHERE pseudo = ?');
		$req->execute(array($pseudo));
		$data = $req->fetch();
		$_SESSION['id'] = $data['id'];
		
		$ok = false;
		while(!$ok) {
			$i=rand(0, getMapWidth() / getRegionWidth());
			$j=rand(0, getMapHeight() / getRegionHeight());
			
			$req = $bdd->prepare('SELECT * FROM cRegions WHERE id = ? AND owner = 0');
			$req->execute(array(getRegionId($i, $j)));
			
			if ($data = $req->fetch()) {
				$req = $bdd->prepare('UPDATE cRegions SET owner = ? WHERE id = ?');
				$req->execute(array($_SESSION['id'], getRegionId($i, $j)));
				
				$req = $bdd->prepare('UPDATE cUsers SET capital = ? WHERE id = ?');
				$req->execute(array($data['id'], $_SESSION['id']));
				
				$ok = true;
			}
		}
		
		
		$displayError = false;
	}

	$req->closeCursor();	
}

if (!$displayError){
	header("Location:home.php");
	exit;
}

?>

<!DOCTYPE html>
<html>
<head>
  <!-- Site made with Mobirise Website Builder v2.8.4, https://mobirise.com -->
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="generator" content="Mobirise v2.8.4, mobirise.com">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="shortcut icon" href="assets/images/logo.png" type="image/x-icon">
  <meta name="description" content="">
  
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:700,400&amp;subset=cyrillic,latin,greek,vietnamese">
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="assets/mobirise/css/style.css">
  <link rel="stylesheet" href="assets/mobirise/css/mbr-additional.css" type="text/css">
  
  
  
</head>
<body>


<section class="engine"><a rel="nofollow" href="https://mobirise.com">Mobirise web design software free
</a></section>
<section class="mbr-navbar mbr-navbar--freeze mbr-navbar--absolute mbr-navbar--sticky mbr-navbar--auto-collapse" id="ext_menu-2">
    <div class="mbr-navbar__section mbr-section">
        <div class="mbr-section__container container">
            <div class="mbr-navbar__container">
                
                <div class="mbr-navbar__hamburger mbr-hamburger text-white"><span class="mbr-hamburger__line"></span></div>
                <div class="mbr-navbar__column mbr-navbar__menu">
                    <nav class="mbr-navbar__menu-box mbr-navbar__menu-box--inline-right">
                        <div class="mbr-navbar__column"><ul class="mbr-navbar__items mbr-navbar__items--right mbr-buttons mbr-buttons--freeze mbr-buttons--right btn-decorator mbr-buttons--active mbr-buttons--only-links"><li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="https://mobirise.com">PLAY</a></li> <li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="https://mobirise.com">DISCOVER</a></li> <li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="https://mobirise.com">CONTACT</a></li></ul></div>
                        
                    </nav>
                </div>
            </div>
        </div>
    </div>
</section>

<section class="mbr-section mbr-after-navbar" id="header3-11">
    <div class="mbr-section__container container mbr-section__container--isolated">
        <div class="mbr-header mbr-header--wysiwyg row">
            <div class="col-sm-8 col-sm-offset-2">
                <h3 class="mbr-header__text">Bad password or pseudonym</h3>
                
            </div>
        </div>
    </div>
</section>


  <script src="assets/web/assets/jquery/jquery.min.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>
  <script src="assets/smooth-scroll/SmoothScroll.js"></script>
  <script src="assets/mobirise/js/script.js"></script>
  
  
</body>
</html>
