This commit is contained in:
gnieark 2016-06-12 18:11:05 +02:00
parent be5b07fa9a
commit 27b04754fd
2 changed files with 26 additions and 12 deletions

View File

@ -280,15 +280,14 @@ function save_battle($game,$bot1,$bot2,$resultat){
} }
function get_unique_id(){ function get_unique_id(){
//increment the number
$fp = fopen(__DIR__.'/../countBattles.txt', 'c+'); $fp = fopen(__DIR__.'/../countBattles.txt', 'c+');
flock($fp, LOCK_EX); flock($fp, LOCK_EX);
$count = (int)fread($fp, filesize(__DIR__.'/../countBattles.txt')); $count = (int)fread($fp, filesize(__DIR__.'/../countBattles.txt'));
ftruncate($fp, 0); ftruncate($fp, 0);
fseek($fp, 0); fseek($fp, 0);
fwrite($fp, $count + 1); fwrite($fp, $count + 1);
flock($fp, LOCK_UN); flock($fp, LOCK_UN);
fclose($fp); fclose($fp);
return $count; return $count;
@ -333,7 +332,7 @@ function does_arena_exist($string,$arenasArr){
return false; return false;
} }
function get_IA_Response($iaUrl,$postParams){ function get_IA_Response($iaUrl,$postParams,$verbose=false){
//send params JSON as body //send params JSON as body
$data_string = json_encode($postParams); $data_string = json_encode($postParams);
@ -348,8 +347,23 @@ function get_IA_Response($iaUrl,$postParams){
'Content-Type: application/json', 'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)) 'Content-Length: ' . strlen($data_string))
); );
$output= curl_exec($ch);
if ($output= curl_exec($ch)){
$queryOk = true;
}else{
$queryOk = false;
}
curl_close($ch); curl_close($ch);
//echo $iaUrl." ".$data_string." ".$output.'<br/>'; //echo $iaUrl." ".$data_string." ".$output.'<br/>';
if($verbose){
}else{
return json_decode($output,TRUE); return json_decode($output,TRUE);
} }
}