From 8163765bca59e8367bed0b236c32039ec4b985a6 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 14:54:07 +0100 Subject: [PATCH 01/10] error 400 --- html/index.php | 2 +- src/functions.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/html/index.php b/html/index.php index 37e140c..836cc2a 100644 --- a/html/index.php +++ b/html/index.php @@ -119,4 +119,4 @@ if($currentArena == ""){ - + \ No newline at end of file diff --git a/src/functions.php b/src/functions.php index 2bae4b2..315e245 100644 --- a/src/functions.php +++ b/src/functions.php @@ -86,8 +86,12 @@ function error($code,$message){ header("HTTP/1.0 404 Not Found"); echo 'Page Not found

'.$message.'

'; die; + case 400: + header ("HTTP/1.0 400 Bad Request"); + echo 'Bad request

'.$message.'

'; + die; default: - + die; break; } From d58e155d3bf3a8be70149147d5c93ca46045361b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:10:35 +0100 Subject: [PATCH 02/10] tictactoe act --- src/arenas/tictactoe/act.php | 103 +++++++++++++++++++++++++++++++++++ src/functions.php | 4 ++ 2 files changed, 107 insertions(+) diff --git a/src/arenas/tictactoe/act.php b/src/arenas/tictactoe/act.php index e69de29..7ea0929 100644 --- a/src/arenas/tictactoe/act.php +++ b/src/arenas/tictactoe/act.php @@ -0,0 +1,103 @@ + '','0-1' => '','0-2' => '', + '1-0' => '','1-1' => '','1-2' => '', + '2-0' => '','2-1' => '','2-2' => ''); + + $end=false; + $playerPlayingNow=1; + while($end==false){ + switch($playerPlayingNow){ + case 1: + $playerURL=$bots[$bot1]['url']; + $playerCHAR='X'; + $playerName=$bots[$bot1]['name']; + break; + case 2: + $playerURL=$bots[$bot2]['url']; + $playerCHAR='O'; + $playerName=$bots[$bot2]['name']; + break; + + default: + error(500,"oups"); + die; + } + $playerResponse=get_IA_Response($playerCHAR,$playerURL,$map); + //tester la validité de la réponse + if((isset($map[$playerResponse])) && ($map[$playerResponse]=="")){ + //reponse conforme + echo "

".$playerName." joue en ".$playerResponse." la nouvelle grille est
"; + $map[$playerResponse]=$playerCHAR; + echo ""; + for($j=0;$j<3;$j++){ + echo ""; + for($i=0;$i<3;$i++){ + echo ''; + } + echo ""; + } + echo "
'.$map[$j.'-'.$i].'
"; + //tester si trois caracteres allignés + if( + (($map['0-0']==$map['0-1'])&&($map['0-1']==$map['0-2'])&&($map['0-2']!=="")) + OR (($map['1-0']==$map['1-1'])&&($map['1-1']==$map['1-2'])&&($map['1-2']!=="")) + OR (($map['2-0']==$map['2-1'])&&($map['2-1']==$map['2-2'])&&($map['2-2']!=="")) + OR (($map['0-0']==$map['1-0'])&&($map['1-0']==$map['2-0'])&&($map['2-0']!=="")) + OR (($map['0-1']==$map['1-1'])&&($map['1-1']==$map['2-1'])&&($map['2-1']!=="")) + OR (($map['0-2']==$map['1-2'])&&($map['1-2']==$map['2-2'])&&($map['2-2']!=="")) + OR (($map['0-0']==$map['1-1'])&&($map['1-1']==$map['2-2'])&&($map['2-2']!=="")) + OR (($map['0-2']==$map['1-1'])&&($map['1-1']==$map['2-0'])&&($map['2-0']!=="")) + ){ + echo "

".$playerName." ".$playerCHAR." a gagné.

"; + $end=true; + break; + } + //tester si toutes les cases ne seraient pas prises + $full=true; + foreach($map as $char){ + if($char==""){ + $full=false; + break; + } + } + if($full){ + echo "

Match nul

"; + $end=true; + break; + } + + //on change de joueur + if($playerPlayingNow==1){ + $playerPlayingNow=2; + }else{ + $playerPlayingNow=1; + } + }else{ + echo "

".$playerName." a fait une réponse non conforme. Il perd

"; + break; + + } + } + + die; + break; + default: + break; +} \ No newline at end of file diff --git a/src/functions.php b/src/functions.php index 315e245..ee4c600 100644 --- a/src/functions.php +++ b/src/functions.php @@ -90,6 +90,10 @@ function error($code,$message){ header ("HTTP/1.0 400 Bad Request"); echo 'Bad request

'.$message.'

'; die; + case 500: + header ("HTTP/1.0 500 Internal Server Error"); + echo 'Bad request

'.$message.'

'; + die; default: die; From 70a670836640c51d411b50003445a587f8de1938 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:12:44 +0100 Subject: [PATCH 03/10] fix xd_check --- src/arenas/tictactoe/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tictactoe/public.php b/src/arenas/tictactoe/public.php index 7fc497f..07b9287 100644 --- a/src/arenas/tictactoe/public.php +++ b/src/arenas/tictactoe/public.php @@ -40,6 +40,6 @@ if(!$postParams){ ?>

-

+

\ No newline at end of file From 834db5df206a0a0a06c38ff57cf7c74e57d6efa9 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:17:00 +0100 Subject: [PATCH 04/10] fix js insertion --- html/index.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/html/index.php b/html/index.php index 836cc2a..f5cd2ed 100644 --- a/html/index.php +++ b/html/index.php @@ -9,17 +9,14 @@ # http://www.gnu.org/licenses/gpl-3.0-standalone.html # # -- END LICENSE BLOCK ----------------------------------------- -//démmarrer une session php + @session_start(); require_once("../src/functions.php"); - - $arenas=get_arenas_list(); $lang=get_language_array(); - if(isset($_GET['arena'])){ //check if arena is list $currentArena = false; @@ -65,9 +62,7 @@ if($currentArena == ""){ ?> - - @@ -78,17 +73,15 @@ if($currentArena == ""){ @import url(/style.css); '; } ?> - - - +

From 95feda0639fcf1119eb23ecfd690e45f7bb53543 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:19:02 +0100 Subject: [PATCH 05/10] fix js & del refresh bots list function. (will be a framework role) --- src/arenas/tictactoe/js.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/arenas/tictactoe/js.js b/src/arenas/tictactoe/js.js index 6ff0855..465aaeb 100644 --- a/src/arenas/tictactoe/js.js +++ b/src/arenas/tictactoe/js.js @@ -22,18 +22,5 @@ function tictactoe(bot1,bot2,xd_check){ }}; xhr.open("POST", 'index.php', true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send('act=fight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + ,xd_check); - } - -function refreshBots(){ - var xhr = Ajx(); - xhr.onreadystatechange = function(){if(xhr.readyState == 4){ - if(xhr.status == 200) { - window.location.reload(); - } - }}; - xhr.open("POST", 'index.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send('act=reDownloadBotsList'); - } - \ No newline at end of file + xhr.send('act=fight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check); +} \ No newline at end of file From df59076b027d0e8401ee787e7f0da2ca8143ca4f Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:21:37 +0100 Subject: [PATCH 06/10] fixes --- html/index.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/html/index.php b/html/index.php index f5cd2ed..8a98630 100644 --- a/html/index.php +++ b/html/index.php @@ -35,12 +35,11 @@ if(isset($_GET['arena'])){ $currentArena = ""; } - //form submitting 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'); + error (400, 'Something wrong has appen'); die; } //call the good act.php @@ -77,7 +76,7 @@ if($currentArena == ""){ if(isset($currentArenaArr['jsFile'])){ echo ''; + echo "\n-->"; } ?> From 89c11c8b071451515914858aaef42702d269a784 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:23:49 +0100 Subject: [PATCH 07/10] fix js --- src/arenas/tictactoe/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tictactoe/public.php b/src/arenas/tictactoe/public.php index 07b9287..fda8735 100644 --- a/src/arenas/tictactoe/public.php +++ b/src/arenas/tictactoe/public.php @@ -40,6 +40,6 @@ if(!$postParams){ ?>

-

+

\ No newline at end of file From a397fc5a5b6ec5ad7d2d595eb38d6d6b832089e6 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:41:50 +0100 Subject: [PATCH 08/10] fix path? --- html/index.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/html/index.php b/html/index.php index 8a98630..ce54b79 100644 --- a/html/index.php +++ b/html/index.php @@ -45,10 +45,7 @@ if (isset($_POST['xd_check'])){ //call the good act.php if(($currentArena <> "") && (file_exists("../src/arenas/".$currentArena."/act.php"))){ require_once("../src/arenas/".$currentArena."/act.php"); - }else{ - require_once("../src/arenas/".$currentArena."/act.php"); } - } //title if($currentArena == ""){ From b30535ebfc5bb4204e63010f5633dac9398add4a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:44:16 +0100 Subject: [PATCH 09/10] fix url --- html/index.php | 4 ++-- src/arenas/tictactoe/js.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/html/index.php b/html/index.php index ce54b79..16af2ac 100644 --- a/html/index.php +++ b/html/index.php @@ -44,7 +44,7 @@ if (isset($_POST['xd_check'])){ } //call the good act.php if(($currentArena <> "") && (file_exists("../src/arenas/".$currentArena."/act.php"))){ - require_once("../src/arenas/".$currentArena."/act.php"); + require_once("../src/arenas/".$currentArena."/act.php"); } } //title @@ -108,4 +108,4 @@ if($currentArena == ""){
- \ No newline at end of file + diff --git a/src/arenas/tictactoe/js.js b/src/arenas/tictactoe/js.js index 465aaeb..27908da 100644 --- a/src/arenas/tictactoe/js.js +++ b/src/arenas/tictactoe/js.js @@ -20,7 +20,7 @@ function tictactoe(bot1,bot2,xd_check){ document.getElementById('fightResult').innerHTML = xhr.responseText; } }}; - xhr.open("POST", 'index.php', true); + xhr.open("POST", '/tictactoe', true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send('act=fight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check); -} \ No newline at end of file +} From 341139410312bd5804f92d4355e6860e3b866107 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Sat, 28 Nov 2015 15:57:35 +0100 Subject: [PATCH 10/10] fix --- src/arenas/tictactoe/act.php | 2 +- src/arenas/tictactoe/functions.php | 4 ++-- src/arenas/tictactoe/public.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arenas/tictactoe/act.php b/src/arenas/tictactoe/act.php index 7ea0929..9a72928 100644 --- a/src/arenas/tictactoe/act.php +++ b/src/arenas/tictactoe/act.php @@ -6,7 +6,7 @@ switch ($_POST['act']){ case "fight": $bots=get_Bots_Array(); //clean $_POST vars - $postParams=get_Post_Params(); + $postParams=get_Post_Params(count($bots)); if(!$postParams){ error(400,"wrong parameters send"); die; diff --git a/src/arenas/tictactoe/functions.php b/src/arenas/tictactoe/functions.php index 1545141..0d987e6 100644 --- a/src/arenas/tictactoe/functions.php +++ b/src/arenas/tictactoe/functions.php @@ -1,5 +1,5 @@ count($bots))){ + if(($_POST[$botKey] < 0) OR ($_POST[$botKey] > $botsCount)){ error(400,"wrong parameters"); die; } diff --git a/src/arenas/tictactoe/public.php b/src/arenas/tictactoe/public.php index fda8735..9a043f9 100644 --- a/src/arenas/tictactoe/public.php +++ b/src/arenas/tictactoe/public.php @@ -2,7 +2,7 @@ require_once(__DIR__."/functions.php"); $bots=get_Bots_Array(); -$postParams=get_Post_Params(); +$postParams=get_Post_Params(count($bots)); if(!$postParams){ $bot1=""; $bot2="";