Merge pull request #13 from gnieark/dev

Dev
This commit is contained in:
Gnieark 2015-11-30 22:41:25 +01:00
commit 78ad5ac2a3
9 changed files with 69 additions and 15 deletions

View File

@ -13,7 +13,7 @@
@session_start(); @session_start();
require_once("../src/functions.php"); require_once("../src/functions.php");
$lnMysql=conn_bdd();
$arenas=get_arenas_list(); $arenas=get_arenas_list();
$lang=get_language_array(); $lang=get_language_array();
@ -45,6 +45,8 @@ if (isset($_POST['xd_check'])){
//call the good act.php //call the good act.php
if(($currentArena <> "") && (file_exists("../src/arenas/".$currentArena."/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");
}else{
require_once("../src/act.php");
} }
} }
//title //title
@ -88,7 +90,7 @@ if($currentArena == ""){
<h1><?php echo $siteTitle; ?></h1> <h1><?php echo $siteTitle; ?></h1>
<nav id="languages"><a href="<?php echo $currentArena; ?>-fr">fr</a>&nbsp;<a href="<?php echo $currentArena; ?>-en">en</a></nav> <nav id="languages"><a href="<?php echo $currentArena; ?>-fr">fr</a>&nbsp;<a href="<?php echo $currentArena; ?>-en">en</a></nav>
<nav id="menus"><a href="/"<?php if($currentArena == "") echo ' class="selected"'; ?>><?php echo $lang['HOME']; ?></a> <nav id="menus"><a href="/"<?php if(($currentArena == "") && (!isset($_GET['doc']))) echo ' class="selected"'; ?>><?php echo $lang['HOME']; ?></a>
<?php <?php
foreach($arenas as $arena){ foreach($arenas as $arena){
if( $arena['id'] == $currentArena){ if( $arena['id'] == $currentArena){
@ -128,7 +130,6 @@ if($currentArena == ""){
default: default:
//battle history for this arena //battle history for this arena
$hist=get_battles_history($currentArena); $hist=get_battles_history($currentArena);
echo '<aside id="history"> echo '<aside id="history">
<h2>infos:</h2> <h2>infos:</h2>
<p>'.$lang['DEV-YOUR-OWN-BOT'].'<br/> <a href="/'.$currentArena.'/doc">'.$lang['DOC_SPECS_LINKS'].'</a></p> <p>'.$lang['DEV-YOUR-OWN-BOT'].'<br/> <a href="/'.$currentArena.'/doc">'.$lang['DOC_SPECS_LINKS'].'</a></p>

View File

@ -63,3 +63,12 @@ aside{
width: 28%; width: 28%;
} }
form textarea, form input, form select {width:40%;}
form input[type=checkbox], fieldset input[type=radio] { width:15px; }
form label {
float:left;
width:40%;
margin-right:0.5em;
padding-top:0.2em;
text-align:right;
}

View File

@ -2,7 +2,7 @@
$lang=array( $lang=array(
'lang' => 'en', 'lang' => 'en',
'SITE_NAME' => 'bots\'arena', 'SITE_NAME' => 'bots\'arena',
'SITE_DESCRIPTION' => '<p>BWelcome on the bots\'arena.<br/><b>this website is still in dev. it doesn\'t work yet</b><br/>This vhost is a mirror of dev branch <a href="https://github.com/gnieark/botsArena/tree/dev">this github repo</a></p> 'SITE_DESCRIPTION' => '<p>Welcome on the bots\'arena.<br/><b>this website is still in dev. it doesn\'t work yet</b><br/>This vhost is a mirror of dev branch <a href="https://github.com/gnieark/botsArena/tree/dev">this github repo</a></p>
<p>Many games will be proposed here. You wont play to, but you will developp the bot who will play for you. <p>Many games will be proposed here. You wont play to, but you will developp the bot who will play for you.
This website will be the arena for bots confrontation.</p>', This website will be the arena for bots confrontation.</p>',
'HOME' => 'Home page', 'HOME' => 'Home page',

View File

@ -4,7 +4,7 @@ require_once(__DIR__."/functions.php");
switch ($_POST['act']){ switch ($_POST['act']){
case "fight": case "fight":
$bots=get_Bots_Array(); $bots=get_Bots_Array('tictactoe');
//clean $_POST vars //clean $_POST vars
$postParams=get_Post_Params(count($bots)); $postParams=get_Post_Params(count($bots));
if(!$postParams){ if(!$postParams){

View File

@ -16,6 +16,7 @@ function get_Post_Params($botsCount){
return array('bot1' => $_POST['bot1'],'bot2' => $_POST['bot2']); return array('bot1' => $_POST['bot1'],'bot2' => $_POST['bot2']);
} }
/*
function get_Bots_Array(){ function get_Bots_Array(){
//Recupérer la liste des Bots //Recupérer la liste des Bots
$bots=array(); $bots=array();
@ -29,6 +30,7 @@ function get_Bots_Array(){
} }
return $bots; return $bots;
} }
*/
function get_IA_Response($youChar,$iaBaseUrl,$grille){ function get_IA_Response($youChar,$iaBaseUrl,$grille){
/*transforme la grille en parametres http GET /*transforme la grille en parametres http GET
* et fait la requete vers $iaBaseUrl * et fait la requete vers $iaBaseUrl

View File

@ -1,3 +0,0 @@
stupidAI http://morpionmaster.tinad.fr/stupidIa.php
moul http://tictactoe.m.42.am/
Gnieark http://morpionmaster.tinad.fr/gnieark.php

View File

@ -1,7 +1,7 @@
<?php <?php
require_once(__DIR__."/functions.php"); require_once(__DIR__."/functions.php");
$bots=get_Bots_Array(); $bots=get_Bots_Array('tictactoe');
$postParams=get_Post_Params(count($bots)); $postParams=get_Post_Params(count($bots));
if(!$postParams){ if(!$postParams){
$bot1=""; $bot1="";

View File

@ -3,6 +3,29 @@ function get_arenas_list(){
include (__DIR__."/arenas_lists.php"); include (__DIR__."/arenas_lists.php");
return $arenas; return $arenas;
} }
function get_Bots_Array($arena,$activeOnly=true){
global $lnMysql;
//$bots[]=array("name" => $name, "url" =>$url);
if($activeOnly){
$addClause=" AND active='1'";
}else{
$addClause="";
}
$rs=mysqli_query($lnMysql,
"SELECT id,name,url,description FROM bots WHERE game='".mysqli_real_escape_string($lnMysql,$arena)."'".$addClause);
$bots=array();
while($r=mysqli_fetch_row($rs)){
$bots[]=array(
'id' => $r[0],
'name'=> $r[1],
'url' => $r[2],
'description' => $r[3]
);
}
return $bots;
}
function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'){ function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'){
$chars_length = (strlen($chars) - 1); $chars_length = (strlen($chars) - 1);
@ -14,6 +37,7 @@ function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl
} }
return $string; return $string;
} }
function xd_check_input($id=1){ function xd_check_input($id=1){
/* /*
*On génére un hash aléatoire qui sera *On génére un hash aléatoire qui sera
@ -112,8 +136,9 @@ function conn_bdd(){
} }
function get_battles_history($game){ function get_battles_history($game){
global $lnMysql;
$game=substr($game,0,8); //limit 8 char for limitting mysql index size $game=substr($game,0,8); //limit 8 char for limitting mysql index size
$lnMysql=conn_bdd();
$rs=mysqli_query($lnMysql, $rs=mysqli_query($lnMysql,
" SELECT " SELECT
player1.name, player1.name,
@ -142,15 +167,16 @@ function get_battles_history($game){
); );
} }
mysqli_close($lnMysql);
return $results; return $results;
} }
function save_battle($game,$bot1,$bot2,$resultat){ function save_battle($game,$bot1,$bot2,$resultat){
//resultat: 0 match nul, 1 bot1 gagne 2 bot 2 gagne //resultat: 0 match nul, 1 bot1 gagne 2 bot 2 gagne
global $lnMysql;
$game=substr($game,0,8); //limit 8 char for limitting mysql index size $game=substr($game,0,8); //limit 8 char for limitting mysql index size
$lnMysql=conn_bdd();
//chercher les id de bot 1 et bot2 //chercher les id de bot 1 et bot2
$rs=mysqli_query($lnMysql,"SELECT name,id FROM bots $rs=mysqli_query($lnMysql,"SELECT name,id FROM bots
WHERE name='".mysqli_real_escape_string($lnMysql,$bot1)."' WHERE name='".mysqli_real_escape_string($lnMysql,$bot1)."'
@ -186,6 +212,4 @@ function save_battle($game,$bot1,$bot2,$resultat){
'".$bots[$bot2]."', '".$bots[$bot2]."',
'1') '1')
ON DUPLICATE KEY UPDATE ".$field." = ".$field." + 1;"); ON DUPLICATE KEY UPDATE ".$field." = ".$field." + 1;");
mysqli_close($lnMysql);
} }

View File

@ -1,2 +1,23 @@
<article>
<?php <?php
echo $lang['SITE_DESCRIPTION']; echo $lang['SITE_DESCRIPTION'];?>
</article>
<article id="addBot">
<h2>Ajouter votre bot</h2>
<form method="POST" action="/">
<?php echo xd_check_input(0); ?><input type="hidden" name="act" value="addBot"/>
<p><label for="botName">Nom de votre Bot: </label><input id="botName" type="text" name="botName" placeholder="votre pseudo par exemple"/></p>
<p><label for="botGame">Jeu du bot: </label>
<select id="botGame" name="botGame">
<?php
foreach($arenas as $arena){
echo '<option value="'.$arena['id'].'">'.$arena['id'].'</option>';
}
?>
</select></p>
<p><label for="botURL">URL du bot:</label><input type="text" name="botURL" id="botURL" placeholder="http://"/></p>
<p><label>Description:</label><textarea></textarea></p>
<p><label for="email">Votre e-mail (sera utilisé pour valider l'inscription du bot)</label><input type="text" name="email" id="email"/></p>
<p><input type="submit" value="Enregistrer mon bot"/></p>
</form>
</article>