more infos if non conform awnser

This commit is contained in:
Gnieark 2016-06-12 21:11:28 +02:00
parent 27b04754fd
commit 72df4b4bd1
2 changed files with 43 additions and 33 deletions

View File

@ -61,6 +61,12 @@ switch ($_POST['act']){
'player-index' => $player 'player-index' => $player
); );
} }
/*
'messageSend' => $data_string,
'httpStatus' => $curl_getinfo($ch)['http_code'],
'response' => $output,
'responseArr' => $arr
*/
get_IA_Response($_SESSION['bot1']['url'],$params[0]); //don't care about result 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 get_IA_Response($_SESSION['bot2']['url'],$params[1]); //don't care about result
@ -118,9 +124,14 @@ switch ($_POST['act']){
'board' => $_SESSION['map'], 'board' => $_SESSION['map'],
'player-index' => $_SESSION['currentPlayer'] - 1 'player-index' => $_SESSION['currentPlayer'] - 1
); );
//send query //send query
$tempPlayer = get_IA_Response($botUrl,$postDatas); $tempPlayer = get_IA_Response($botUrl,$postDatas);
$anwserPlayer = $tempPlayer['play']; if(isset($tempPlayer['arrponseArr']['play'])){
$anwserPlayer = $tempPlayer['arrponseArr']['play'];
}else{
$anwserPlayer = -1;
}
//vérifier la validité de la réponse //vérifier la validité de la réponse
if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){ if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){
@ -296,11 +307,15 @@ switch ($_POST['act']){
}else{ }else{
//reponse non conforme //reponse non conforme
$anwserToJS=array( $anwserToJS=array(
'continue' =>0, 'continue' =>0,
'strikeX' => -1, 'strikeX' => -1,
'strikeY' => -1, 'strikeY' => -1,
'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd".json_encode($tempPlayer), 'log' => $you." ".$currentBotName." made a non conform anwser: <br/>
Bots Arena sent:".$tempPlayer['messageSend']."<br/>
".$currentBotName." HTTP STATUS: ".$tempPlayer['httpStatus']."<br/>
His response: ".html_entities($tempPlayer['response']),
'gameId' => $_SESSION['matchId'] 'gameId' => $_SESSION['matchId']
); );
if($_SESSION['currentPlayer']==1){ if($_SESSION['currentPlayer']==1){

View File

@ -332,8 +332,9 @@ function does_arena_exist($string,$arenasArr){
return false; return false;
} }
function get_IA_Response($iaUrl,$postParams,$verbose=false){ function get_IA_Response($iaUrl,$postParams){
// send params JSON as body // send params JSON as body
// return query detail on an array
$data_string = json_encode($postParams); $data_string = json_encode($postParams);
@ -347,23 +348,17 @@ function get_IA_Response($iaUrl,$postParams,$verbose=false){
'Content-Type: application/json', 'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)) 'Content-Length: ' . strlen($data_string))
); );
//$httpCode = curl_getinfo($ch)['http_code'];
if ($output= curl_exec($ch)){ $output= curl_exec($ch);
$queryOk = true;
}else{
$queryOk = false;
}
curl_close($ch); curl_close($ch);
//echo $iaUrl." ".$data_string." ".$output.'<br/>'; if(! $arr = json_decode($output,TRUE)){
$arr=array();
if($verbose){
}else{
return json_decode($output,TRUE);
} }
return array(
'messageSend' => $data_string,
'httpStatus' => $curl_getinfo($ch)['http_code'],
'response' => $output,
'responseArr' => $arr
);
} }