From cf745f186bee4c8ea952c391d71a81496ff3c1f0 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 12 Jun 2016 00:08:54 +0200 Subject: [PATCH 1/6] for debog --- html/testBotScripts/connectfour.html | 6 +++--- src/arenas/connectFour/act.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/html/testBotScripts/connectfour.html b/html/testBotScripts/connectfour.html index 4b13fb8..638e4dc 100644 --- a/html/testBotScripts/connectfour.html +++ b/html/testBotScripts/connectfour.html @@ -222,7 +222,7 @@ function play(player){ var arrToSend= { "game-id": "" + gameId, "action" : "play-turn", - "game" : "connectfour", + "game" : "connectFour", "players" : 2, "board" : board, "you" : symbol, @@ -301,9 +301,9 @@ function startGame(){ var xhr = new XMLHttpRequest(); xhr.open("POST", document.getElementById('url' + p).value, false); xhr.setRequestHeader("Content-Type", "application/json"); - xhr.send(' {"game-id":"' + gameId + '","action":"init","game":"connectfour","players":2,"board":"","player-index":' + (p - 1) +'}'); + xhr.send(' {"game-id":"' + gameId + '","action":"init","game":"connectFour","players":2,"board":"","player-index":' + (p - 1) +'}'); if(xhr.status == 200) { - addLog('Message d\'init envoyé au bot player ' + p + ' {"game-id":"' + gameId + '","action":"init","game":"connectfour","players":2,"board":"","player-index":' + (p - 1) +'}
il a répondu ' + xhr.responseText ); + addLog('Message d\'init envoyé au bot player ' + p + ' {"game-id":"' + gameId + '","action":"init","game":"connectFour","players":2,"board":"","player-index":' + (p - 1) +'}
il a répondu ' + xhr.responseText ); }else{ addLog('player ' + p + ' n est pas joignable ' + xhr.status); return; diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 9d1fabb..acfbe87 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -294,7 +294,7 @@ switch ($_POST['act']){ 'continue' =>0, 'strikeX' => -1, 'strikeY' => -1, - 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd" + 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd".json_encode($tempPlayer)."|"; ); if($_SESSION['currentPlayer']==1){ save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],2); From 4d8ef34c7958aebc4fd390c251786d47b7003804 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 12 Jun 2016 00:09:31 +0200 Subject: [PATCH 2/6] for debog --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index acfbe87..d7ae7b8 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -294,7 +294,7 @@ switch ($_POST['act']){ 'continue' =>0, 'strikeX' => -1, 'strikeY' => -1, - 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd".json_encode($tempPlayer)."|"; + 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd".json_encode($tempPlayer)."|" ); if($_SESSION['currentPlayer']==1){ save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],2); From 8500bc8d815c0aae47a4b9f3a3c0297733a69dc9 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 12 Jun 2016 01:04:42 +0200 Subject: [PATCH 3/6] check game ID on AJAX communications --- src/arenas/connectFour/act.php | 23 +++++++++++++++++------ src/arenas/connectFour/js.js | 10 ++++++---- src/arenas/connectFour/public.php | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index d7ae7b8..c70e182 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -2,10 +2,11 @@ require_once(__DIR__."/functions.php"); $bots=get_Bots_Array('connectFou'); - +$new=false; switch ($_POST['act']){ case "newFight": + $new=true; //remove $_SESSION less xd_check $xd=$_SESSION['xd_check']; session_unset(); @@ -66,11 +67,17 @@ switch ($_POST['act']){ //echo "plop".json_encode($_SESSION['map']); + case "fight": - if($_SESSION['game'] <> "connectFou"){ + + if( + ($_SESSION['game'] <> "connectFou")  + || ((!$new) && ($_POST['gameId'] <> $_SESSION['matchId')) + ){ error(500,"game non found"); } + //What player has to play? if(!isset($_SESSION['currentPlayer'])){ @@ -245,7 +252,8 @@ switch ($_POST['act']){ 'strikeY' => $strikeY, 'strikeSymbol'=> $you, 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." et a gagné", - 'cellsWin' => json_encode($cellsWin) + 'cellsWin' => json_encode($cellsWin), + 'gameId' => $_SESSION['matchId'] ); if($_SESSION['currentPlayer']==1){ save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],1); @@ -273,7 +281,8 @@ switch ($_POST['act']){ 'strikeX' => $strikeX, 'strikeY' => $strikeY, 'strikeSymbol'=> $you, - 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." match nul" + 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." match nul", + 'gameId' => $_SESSION['matchId'] ); }else{ @@ -283,7 +292,8 @@ switch ($_POST['act']){ 'strikeX' => $strikeX, 'strikeY' => $strikeY, 'strikeSymbol'=> $you, - 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer + 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer, + 'gameId' => $_SESSION['matchId'] ); } } @@ -294,7 +304,8 @@ switch ($_POST['act']){ 'continue' =>0, 'strikeX' => -1, 'strikeY' => -1, - 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd".json_encode($tempPlayer)."|" + 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd".json_encode($tempPlayer), + 'gameId' => $_SESSION['matchId'] ); if($_SESSION['currentPlayer']==1){ save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],2); diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 4f88e38..072bbd0 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -18,9 +18,10 @@ function createElem(type,attributes){ {elem.setAttribute(i,attributes[i]);} return elem; } -function connectFour(bot1,bot2,xd_check, newGame){ +function connectFour(bot1,bot2,xd_check, gameId, newGame){ if (newGame === undefined){ - newGame = true; + newGame = true; + gameId=0; } if (newGame){ @@ -58,6 +59,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ } //log document.getElementById('logs').innerHTML += reponse['log'] + '
'; + //fill the grid if( reponse['strikeX'] > -1){ document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; @@ -76,7 +78,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ //if game isn't finished, continue if(reponse['continue'] == 1){ - connectFour(bot1,bot2,xd_check, false); + connectFour(bot1,bot2,xd_check,reponse['gameId'], false); } }else{ alert ('error ' + xhr.status); @@ -90,5 +92,5 @@ function connectFour(bot1,bot2,xd_check, newGame){ }else{ var act='fight'; } - xhr.send('act=' + act + '&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check); + xhr.send('act=' + act + '&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check + '&gameId=' + gameId); } diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index 9cfbe7e..1e12634 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -23,5 +23,5 @@ $bots=get_Bots_Array('connectFou'); ?>

-

+

From 0e8ac74417b99805e89dca328db1574070a78f75 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 12 Jun 2016 01:06:26 +0200 Subject: [PATCH 4/6] check game ID on AJAX communications --- src/arenas/connectFour/act.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index c70e182..ec631bd 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -70,11 +70,9 @@ switch ($_POST['act']){ case "fight": - if( - ($_SESSION['game'] <> "connectFou")  - || ((!$new) && ($_POST['gameId'] <> $_SESSION['matchId')) - ){ + ($_SESSION['game'] <> "connectFou") || ((!$new) && ($_POST['gameId'] <> $_SESSION['matchId')) + ){ error(500,"game non found"); } From ab4cd8eb3ada1b25119d071f0a5cff8bd0d67506 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 12 Jun 2016 01:07:30 +0200 Subject: [PATCH 5/6] check game ID on AJAX communications --- src/arenas/connectFour/act.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index ec631bd..899112c 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -64,15 +64,10 @@ switch ($_POST['act']){ get_IA_Response($_SESSION['bot1']['url'],$params[0]); //don't care about result get_IA_Response($_SESSION['bot2']['url'],$params[1]); //don't care about result - - - //echo "plop".json_encode($_SESSION['map']); - + case "fight": - if( - ($_SESSION['game'] <> "connectFou") || ((!$new) && ($_POST['gameId'] <> $_SESSION['matchId')) - ){ + if(($_SESSION['game'] <> "connectFou") || ((!$new) && ($_POST['gameId'] <> $_SESSION['matchId']))){ error(500,"game non found"); } From 92db3755c51d5f9c339ffff385fd38add1ae4f17 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 12 Jun 2016 01:14:56 +0200 Subject: [PATCH 6/6] check game ID on AJAX communications --- src/arenas/connectFour/act.php | 9 ++++++--- src/arenas/connectFour/js.js | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 899112c..74902fd 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -67,10 +67,13 @@ switch ($_POST['act']){ case "fight": - if(($_SESSION['game'] <> "connectFou") || ((!$new) && ($_POST['gameId'] <> $_SESSION['matchId']))){ - error(500,"game non found"); + if($_SESSION['game'] <> "connectFou"){ + error(500,"game non found"); + die; + } + if((!$new) && ($_POST['gameId'] <> $_SESSION['matchId'])){ + error (512, "not correct gameId"); } - //What player has to play? if(!isset($_SESSION['currentPlayer'])){ diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 072bbd0..045fc2b 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -80,6 +80,9 @@ function connectFour(bot1,bot2,xd_check, gameId, newGame){ if(reponse['continue'] == 1){ connectFour(bot1,bot2,xd_check,reponse['gameId'], false); } + }else if(xhr.status == 512){ + //just forget + return; }else{ alert ('error ' + xhr.status); return;