diff --git a/html/.htaccess b/html/.htaccess new file mode 100644 index 0000000..9caecf4 --- /dev/null +++ b/html/.htaccess @@ -0,0 +1,8 @@ +RewriteEngine On +RewriteBase / +RewriteRule ^([a-zA-Z]{1,})-([a-z]{2})$ index\.php?arena=$1&lang=$2 [L] +RewriteRule ^([a-zA-Z]{1,})$ index\.php?arena=$1 [L] +RewriteRule ^-([a-z]{2})$ index\.php?lang=$1 [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^index.php$ index.php/ [L] \ No newline at end of file diff --git a/html/index.php b/html/index.php index 242fece..6683c23 100644 --- a/html/index.php +++ b/html/index.php @@ -18,19 +18,39 @@ require_once("../src/functions.php"); $arenas=get_arenas_list(); $lang=get_language_array(); + + +if(isset($_GET['arena'])){ + //check if arena is list + $currentArena = false; + foreach($arenas as $arena){ + if($arena['id'] == $_GET['arena']){ + $currentArena = $_GET['arena']; + $currentArenaArr=$arena; + break; + } + } + if(!$currentArena){ + error(404,"Wrong parameter"); + die; + } +}else{ + $currentArena = ""; +} + + //form submitting -if (isset($_POST['xd_check'])) -{ +if (isset($_POST['xd_check'])){ //vérifier le numero de formulaire if (($_SESSION['xd_check']!=$_POST['xd_check']) AND ($_POST['xd_check'] !="")){ erreur ('Something wrong has appen'); die; } //call the good act.php - if((isset($arenas['current'])) && (file_exists("src/arenas/act.php"))){ - require_once("src/arenas/act.php"); + if(($currentArena <> "") && (file_exists("../src/arenas/".$currentArena."/act.php"))){ + require_once("../src/arenas/".$currentArena."/act.php"); }else{ - require_once("src/default/act.php"); + require_once("../src/arenas/".$currentArena."/act.php"); } } @@ -51,15 +71,37 @@ if (isset($_POST['xd_check']))
- + +
+ Accueil"; + break; + default: + include ("../src/arenas/".$currentArena."/public.php"); + break; + } + ?>
diff --git a/lang/en.php b/lang/en.php index 59648a8..cdc02e1 100644 --- a/lang/en.php +++ b/lang/en.php @@ -1,5 +1,6 @@ 'Artificials Intelligences\' arena', - 'SITE_DESCRIPTION' => 'blah blah blah but english' + 'SITE_DESCRIPTION' => 'blah blah blah but english', + 'HOME' => 'Home page' ); \ No newline at end of file diff --git a/lang/fr.php b/lang/fr.php index cb8fbfe..26a686a 100644 --- a/lang/fr.php +++ b/lang/fr.php @@ -1,5 +1,6 @@ 'Arène pour intelligences (ou persque) artificielles', - 'SITE_DESCRIPTION' => 'blah blah blah mais en francais' + 'SITE_DESCRIPTION' => 'blah blah blah mais en francais', + 'HOME' => 'accueil' ); \ No newline at end of file diff --git a/src/arenas/Battleship/public.php b/src/arenas/Battleship/public.php new file mode 100644 index 0000000..61aa218 --- /dev/null +++ b/src/arenas/Battleship/public.php @@ -0,0 +1 @@ +

Battle ship

\ No newline at end of file diff --git a/src/arenas/tictactoe/public.php b/src/arenas/tictactoe/public.php new file mode 100644 index 0000000..020f14a --- /dev/null +++ b/src/arenas/tictactoe/public.php @@ -0,0 +1 @@ +

tic tac toe

\ No newline at end of file diff --git a/src/arenas_lists.php b/src/arenas_lists.php index 71b4e4e..99a99df 100644 --- a/src/arenas_lists.php +++ b/src/arenas_lists.php @@ -7,7 +7,7 @@ $arenas=array( ), array( 'id' => "Battleship", - 'url' => "/battleship", + 'url' => "/Battleship", 'title' => "bataille Navale" ) diff --git a/src/functions.php b/src/functions.php index b73107c..2bae4b2 100644 --- a/src/functions.php +++ b/src/functions.php @@ -1,16 +1,52 @@ un input type hidden sans id + * 1=> un input type hidden avec id + * 2=> juste la valeur + */ + if(!isset($_SESSION['xd_check'])){ + //le générer + $_SESSION['xd_check']=rand_str(25); + } + switch($id){ + case 0: + return ""; + break; + case 1: + return ""; + break; + case 2: + return $_SESSION['xd_check']; + break; + default: + return ""; + break; + } +} + function get_language_array(){ /* * Choisir la langue de l'utilisateur @@ -43,4 +79,17 @@ function get_language_array(){ include (__DIR__."/../lang/".$language.".php"); return $lang; +} +function error($code,$message){ + switch($code){ + case 404: + header("HTTP/1.0 404 Not Found"); + echo 'Page Not found

'.$message.'

'; + die; + default: + + die; + break; + } + } \ No newline at end of file