2015-11-23 21:54:25 +01:00
< ? php
#- BEGIN LICENSE BLOCK ---------------------------------------
#
2015-11-25 22:32:58 +01:00
# This file is part of botsArena.
2015-11-23 21:54:25 +01:00
#
# Copyright (C) Gnieark et contributeurs
# Licensed under the GPL version 3.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/gpl-3.0-standalone.html
#
# -- END LICENSE BLOCK -----------------------------------------
2015-11-28 15:17:00 +01:00
2015-11-23 21:54:25 +01:00
@ session_start ();
2015-11-25 22:13:36 +01:00
require_once ( " ../src/functions.php " );
2015-11-30 00:16:01 +01:00
$lnMysql = conn_bdd ();
2015-11-26 19:38:09 +01:00
$arenas = get_arenas_list ();
2015-11-26 21:18:11 +01:00
$lang = get_language_array ();
2015-11-27 18:59:04 +01:00
2015-12-08 22:58:17 +01:00
//check type of page
//$_GET['arena'] -> an arena
//$_GET['doc'] -> arena documentation
//$_GET['page'] -> a simple page like about page, legals etc...
//Nothing -> home page
$permitIndex = true ; //will be set to false for pages that google or other bot must not index
2015-11-27 18:59:04 +01:00
if ( isset ( $_GET [ 'arena' ])){
2015-12-08 22:58:17 +01:00
//Arena
//check if arena exists
$currentArena = false ;
foreach ( $arenas as $arena ){
2015-11-27 22:25:57 +01:00
if ( $arena [ 'id' ] == $_GET [ 'arena' ]){
$currentArena = $_GET [ 'arena' ];
2015-11-27 22:29:37 +01:00
$currentArenaArr = $arena ;
2015-11-27 18:59:04 +01:00
break ;
}
}
if ( ! $currentArena ){
2015-11-27 22:25:57 +01:00
error ( 404 , " Wrong parameter " );
2015-11-27 18:59:04 +01:00
die ;
}
2015-12-08 22:58:17 +01:00
$hist = get_battles_history ( $currentArena );
2015-12-10 22:45:59 +01:00
$siteTitle = $currentArenaArr [ 'title' ];
2015-12-08 22:58:17 +01:00
$siteDescription = $currentArenaArr [ 'metaDescription' ];
$mainSectionScript = " ../src/arenas/ " . $currentArena . " /public.php " ;
$asideSectionContent = '<h2>infos:</h2><p>' . $lang [ 'DEV-YOUR-OWN-BOT' ] . '<br/> <a href="/' . $currentArena . '/doc">' . $lang [ 'DOC_SPECS_LINKS' ] . ' </ a ></ p >
< h2 > Scores </ h2 > ' ;
2016-06-10 00:21:57 +02:00
$podium = ELO_get_podium ( $currentArena );
$count = 0 ;
2016-06-10 00:26:22 +02:00
$asideSectionContent .= '<ul class="podium">' ;
2016-06-10 00:21:57 +02:00
foreach ( $podium as $sc ){
$count ++ ;
2016-06-10 00:24:50 +02:00
switch ( $count ){
2016-06-10 00:21:57 +02:00
case 1 :
2016-06-10 00:23:35 +02:00
$img = '<img src="/imgs/Gold_Medal.svg" alt="Gold_Medal.svg"/>' ;
2016-06-10 00:21:57 +02:00
break ;
case 2 :
2016-06-10 00:23:35 +02:00
$img = '<img src="/imgs/Silver_Medal.svg" alt="Silver_Medal.svg"/>' ;
2016-06-10 00:21:57 +02:00
break ;
case 3 :
2016-06-10 00:23:35 +02:00
$img = '<img src="/imgs/Bronze_Medal.svg" alt="Bronze_Medal.svg"/>' ;
2016-06-10 00:21:57 +02:00
break ;
default :
2016-06-10 00:23:35 +02:00
$img = '<img src="/imgs/Emoji_u1f4a9.svg" alt="caca"/>' ;
2016-06-10 00:21:57 +02:00
break ;
}
2016-06-10 00:23:35 +02:00
2016-06-10 11:28:48 +02:00
$asideSectionContent .= '<li>' . $img . ' <a href="/p/aboutBot/' . urlencode ( htmlentities (( $sc [ 'name' ]))) . '">' . htmlentities ( $sc [ 'name' ]) . '</a> ELO rank: ' . $sc [ 'ELO' ] . '</li>' ;
2016-06-10 00:21:57 +02:00
}
2016-06-10 16:19:41 +02:00
$asideSectionContent .= '</ul><h2><a href="#" onclick="document.getElementById(\'detailMatches\').class=\'\';">Détail des matchs</a></h2>' ;
2016-06-10 00:21:57 +02:00
2015-12-08 22:58:17 +01:00
foreach ( $hist as $sc ){
2016-06-10 11:26:39 +02:00
$asideSectionContent .= '<h3><a href="/p/aboutBot/' . urlencode ( htmlentities ( $sc [ 'bot1' ])) . '">' . $sc [ 'bot1' ] . '</a> VS <a href="/p/aboutBot/' . urlencode ( htmlentities ( $sc [ 'bot2' ])) . '">' . $sc [ 'bot2' ] . ' </ a ></ h3 >
2016-06-10 16:19:41 +02:00
< ul id = " detailMatches " class = " hidden " >
2015-12-08 22:58:17 +01:00
< li > '.$sc[' bot1 ']." ".$lang[' VICTORIES '].":".$sc[' player1Wins '].' </ li >
< li > '.$sc[' bot2 ']." ".$lang[' VICTORIES '].":".$sc[' player2Wins '].' </ li >
< li > '.$lang[' DRAW '].":".$sc[' draws '].' </ li >
</ ul > ' ;
}
$cssAdditionalScript = " " ;
if ( isset ( $currentArenaArr [ 'cssFile' ])){
$cssAdditionalScript .= '<style type="text/css"><!--' . " \n " . file_get_contents ( " ../src/arenas/ " . $currentArena . " / " . $currentArenaArr [ 'cssFile' ]) . " \n --></style> " ;
}
//arena specific script js (if needed)
$jsAdditionalScript = " " ;
if ( isset ( $currentArenaArr [ 'jsFile' ])){
$jsAdditionalScript .= '<script type="text/javascript"><!--' . " \n " . file_get_contents ( " ../src/arenas/ " . $currentArena . " / " . $currentArenaArr [ 'jsFile' ]) . " \n --></script> " ;
}
} elseif ( isset ( $_GET [ 'doc' ])){
//arena's documentation page
//check if arena exists
$currentArena = false ;
foreach ( $arenas as $arena ){
if ( $arena [ 'id' ] == $_GET [ 'doc' ]){
$currentArena = $_GET [ 'doc' ];
$currentArenaArr = $arena ;
break ;
}
}
if ( ! $currentArena ){
error ( 404 , " Wrong parameter " );
die ;
}
2015-12-10 22:45:59 +01:00
$siteTitle = " Specifications " . $currentArenaArr [ 'title' ];
2015-12-08 22:58:17 +01:00
$siteDescription = " documentation, faites votre propre bot pour " . $currentArenaArr [ 'metaDescription' ];
$mainSectionScript = " ../src/arenas/ " . $currentArenaArr [ 'id' ] . " /doc- " . $lang [ 'lang' ] . " .html " ;
$asideSectionContent = '' ; //to do
$cssAdditionalScript = " " ;
2015-12-16 10:10:31 +01:00
if ( isset ( $currentArenaArr [ 'cssFile' ])){
$cssAdditionalScript .= '<style type="text/css"><!--' . " \n " . file_get_contents ( " ../src/arenas/ " . $currentArena . " / " . $currentArenaArr [ 'cssFile' ]) . " \n --></style> " ;
}
2015-12-08 22:58:17 +01:00
$jsAdditionalScript = " " ;
} elseif ( isset ( $_GET [ 'page' ])){
//simple page
switch ( $_GET [ 'page' ]){
case " legals " :
$siteTitle = " Mentions légales - bots Arena " ;
$siteDescription = " OSEF " ;
$mainSectionScript = " ../src/legals.html " ;
$asideSectionContent = '' ; //to do or not to do
$cssAdditionalScript = " " ;
$jsAdditionalScript = " " ;
break ;
case " About " :
2015-12-10 22:45:59 +01:00
$siteTitle = " About " ;
2015-12-08 22:58:17 +01:00
$siteDescription = " bots arena about page " ;
$mainSectionScript = " ../src/about.html " ;
$asideSectionContent = '' ; //to do or not to do
$cssAdditionalScript = " " ;
$jsAdditionalScript = " " ;
break ;
case " addBot " :
2015-12-10 22:45:59 +01:00
$siteTitle = " Valider l'ajout d'une IA " ;
2015-12-08 22:58:17 +01:00
$siteDescription = " bots arena about page " ;
$permitIndex = false ;
$mainSectionScript = " ../src/addBot.php " ;
$asideSectionContent = '' ; //to do
$cssAdditionalScript = " " ;
2015-12-08 22:59:29 +01:00
$jsAdditionalScript = " " ;
2015-12-08 22:58:17 +01:00
break ;
2015-12-26 21:59:05 +01:00
case " aboutBot " :
if ( ! isset ( $_GET [ 'params' ])){
error ( 404 , " Page does not exists " );
die ;
}
$rs = mysqli_query ( $lnMysql ,
" SELECT id,game,url,description,date_inscription
FROM bots
WHERE name = '".mysqli_real_escape_string($lnMysql,$_GET[' params '])."'
AND active = '1' " );
if ( ! $r = mysqli_fetch_row ( $rs )){
error ( 404 , " Page doesn't exist " );
die ;
}
$theBot = array (
'id' => $r [ 0 ],
'game' => $r [ 1 ],
'url' => $r [ 2 ],
'description' => $r [ 3 ],
'date_inscription' => $r [ 4 ]
);
$siteTitle = htmlentities ( $_GET [ 'params' ]);
$siteDescription = htmlentities ( $_GET [ 'params' ]) . " bot details " ;
$mainSectionScript = " ../src/aboutBot.php " ;
2015-12-26 22:08:09 +01:00
$hist = get_battles_history ( $r [ 1 ]);
2015-12-26 21:59:05 +01:00
$asideSectionContent = '<h2>Scores</h2>' ;
foreach ( $hist as $sc ){
$asideSectionContent .= '<h3>' . $sc [ 'bot1' ] . ' VS ' . $sc [ 'bot2' ] . ' </ h3 >
< ul >
< li > '.$sc[' bot1 ']." ".$lang[' VICTORIES '].":".$sc[' player1Wins '].' </ li >
< li > '.$sc[' bot2 ']." ".$lang[' VICTORIES '].":".$sc[' player2Wins '].' </ li >
< li > '.$lang[' DRAW '].":".$sc[' draws '].' </ li >
</ ul > ' ;
}
$cssAdditionalScript = " " ;
$jsAdditionalScript = " " ;
break ;
2015-12-27 13:03:45 +01:00
case " editBot " :
2016-06-09 15:16:10 +02:00
if ( ! isset ( $_GET [ 'params' ])){
2015-12-27 16:50:10 +01:00
error ( 404 , " Page does not exists " );
die ;
}
$rs = mysqli_query ( $lnMysql ,
2016-06-09 15:05:13 +02:00
" SELECT id,name,game,url,description,unclean_description,date_inscription
2015-12-27 16:50:10 +01:00
FROM bots
WHERE id = '".mysqli_real_escape_string($lnMysql,$_GET[' params '])."'
AND active = '1' " );
if ( ! $r = mysqli_fetch_row ( $rs )){
error ( 404 , " Page doesn't exist " );
die ;
}
$theBot = array (
'id' => $r [ 0 ],
'name' => $r [ 1 ],
'game' => $r [ 2 ],
'url' => $r [ 3 ],
'description' => $r [ 4 ],
2016-06-09 15:05:13 +02:00
'unclean_description' => $r [ 5 ],
'date_inscription' => $r [ 6 ]
2015-12-27 16:50:10 +01:00
);
2015-12-27 13:03:45 +01:00
$siteTitle = " Modifier un bot " ;
$siteDescription = " bots arena " ;
$permitIndex = false ;
$mainSectionScript = " ../src/editBot.php " ;
$asideSectionContent = '' ; //to do
$cssAdditionalScript = " " ;
$jsAdditionalScript = " " ;
break ;
2016-06-09 15:16:10 +02:00
2016-06-09 15:17:06 +02:00
case " validateEditBot " :
2016-06-09 16:21:01 +02:00
//check if secret is ok
if ( ! isset ( $_GET [ 'params' ])){
error ( 404 , " Page does not exists " );
die ;
}
$rs = mysqli_query ( $lnMysql , " SELECT 1 FROM bots_modifs WHERE validate_secret=' " . mysqli_real_escape_string ( $lnMysql , $_GET [ 'params' ]) . " '; " );
if ( ! $r = mysqli_fetch_row ( $rs )){
error ( 404 , " Page doesn't exist " );
die ;
}
2016-06-09 15:16:10 +02:00
$siteTitle = " Your bot is changed " ;
$siteDescription = " bots arena " ;
$permitIndex = false ;
$mainSectionScript = " ../src/validateEditBot.php " ;
$asideSectionContent = '' ; //to do
$cssAdditionalScript = " " ;
$jsAdditionalScript = " " ;
break ;
2015-12-08 22:58:17 +01:00
default :
error ( 404 , " Not found " );
break ;
}
2015-11-27 18:59:04 +01:00
} else {
2015-12-08 22:58:17 +01:00
//home page
$siteTitle = " Bots Arena " ;
$siteDescription = " bots arena main page. Program your own artificiel intelligence and let it play here " ;
$mainSectionScript = " ../src/home.php " ;
2015-12-25 01:16:31 +01:00
$asideSectionContent = '<h2>Principe:</h2><p class="center"><img src="/principe.gif" alt=""/></p>' ;
2015-12-08 22:58:17 +01:00
$cssAdditionalScript = " " ;
2015-12-08 22:59:29 +01:00
$jsAdditionalScript = " " ;
2015-11-27 18:59:04 +01:00
}
2015-12-08 22:58:17 +01:00
2015-12-09 00:00:05 +01:00
if ( ! isset ( $currentArena )){
$currentArena = " " ;
}
2015-12-08 22:58:17 +01:00
2015-11-23 21:54:25 +01:00
//form submitting
2015-11-27 18:59:04 +01:00
if ( isset ( $_POST [ 'xd_check' ])){
2015-12-08 22:58:17 +01:00
//vérifier le numero de formulaire
if (( $_SESSION [ 'xd_check' ] != $_POST [ 'xd_check' ]) AND ( $_POST [ 'xd_check' ] != " " )){
error ( 400 , 'Something wrong has appen' );
die ;
}
//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/act.php " );
}
2015-11-28 11:18:21 +01:00
}
2015-11-23 21:54:25 +01:00
?>
<! DOCTYPE html >
2015-12-24 13:29:15 +01:00
< html lang = " <?php echo $lang['lang'] ; ?> " >
2015-11-23 21:54:25 +01:00
< head >
< meta charset = " UTF-8 " >
< meta name = " viewport " content = " width=device-width, initial-scale=1 " >
2015-12-08 22:58:17 +01:00
< meta name = " ROBOTS " content = " <?php if( $permitIndex ) { echo " INDEX , FOLLOW " ;}else { echo " noindex , nofollow " ;}?> " />
2015-11-28 11:18:21 +01:00
< meta http - equiv = " X-UA-Compatible " content = " IE=edge " >
< meta name = " author " content = " Gnieark " />
2015-12-08 22:58:17 +01:00
< meta name = " description " content = " <?php echo $siteDescription ; ?> " />
2015-11-28 11:18:21 +01:00
< title >< ? php echo $siteTitle ; ?> </title>
< style type = " text/css " >
2015-12-08 22:58:17 +01:00
@ import url ( / style . css );
2015-11-28 11:18:21 +01:00
</ style >
2015-12-08 22:58:17 +01:00
< ? php echo $cssAdditionalScript . " \n " . $jsAdditionalScript ; ?>
2015-11-23 21:54:25 +01:00
</ head >
2015-12-08 22:58:17 +01:00
< body >
2015-11-23 21:54:25 +01:00
< header >
2015-12-08 22:58:17 +01:00
< h1 >< ? php echo $siteTitle ; ?> </h1>
2016-06-06 11:11:09 +02:00
< ? php
if ( isset ( $_GET [ 'doc' ])){
echo '<nav id="languages"><a href="/' . $currentArena . '/doc-fr">fr</a> <a href="/' . $currentArena . '/doc-en">en</a></nav>' ;
} else {
echo '<nav id="languages"><a href="/' . $currentArena . '-fr">fr</a> <a href="/' . $currentArena . '-en">en</a></nav>' ;
}
2016-06-06 11:13:44 +02:00
echo '<nav id="menus"><a href="/"' ;
if (( $currentArena == " " ) && ( ! isset ( $_GET [ 'doc' ]))){
echo ' class="selected"' ;
}
2016-06-06 11:14:10 +02:00
echo '>' . $lang [ 'HOME' ] . '</a>' ;
2015-12-08 23:06:59 +01:00
2015-12-08 23:06:04 +01:00
foreach ( $arenas as $arena ){
if ( $arena [ 'id' ] == $currentArena ){
$class = " selected " ;
} else {
$class = " " ;
2015-11-27 18:59:04 +01:00
}
2015-12-08 23:06:04 +01:00
echo '<a href="' . $arena [ 'url' ] . '" class="' . $class . '">' . $arena [ 'title' ] . '</a>' ;
}
2015-12-08 22:58:17 +01:00
?> </nav>
2015-11-23 21:54:25 +01:00
</ header >
< section >
2015-12-08 22:58:17 +01:00
< ? php
if ( $asideSectionContent <> " " ){
echo " <aside> " . $asideSectionContent . " </aside> " ;
2015-12-08 23:01:56 +01:00
}
2015-12-25 01:16:31 +01:00
include $mainSectionScript ;
?>
2015-11-23 21:54:25 +01:00
</ section >
< footer >
2015-12-26 19:35:11 +01:00
< a href = " /p/About " >< ? php echo $lang [ 'ABOUT' ]; ?> </a><a href="https://github.com/gnieark/botsArena">Bots'Arena source code</a><a href="/p/legals"><?php echo $lang['LEGALS']; ?></a>
2015-11-23 21:54:25 +01:00
</ footer >
</ body >
2015-12-27 12:57:16 +01:00
</ html >