Skip to content

Commit

Permalink
Ajout server date
Browse files Browse the repository at this point in the history
téléchargement du xml serverdata
parsing simple du fichier avec affichage en html
  • Loading branch information
machine62 committed Feb 28, 2024
1 parent 546270d commit de62b4b
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 45 deletions.
3 changes: 3 additions & 0 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ traitement_alliance_rank($value, $sNameXml);
} elseif (strstr($sNameXml, "CST_PLAYERS_RANK_")) {
traitement_player_rank($value, $sNameXml);
logmemoryusage("fin traitement_player_rank " . $sNameXml);
} elseif (strstr($sNameXml, "CST_SERVERDATA")) {
traitement_serverdata($value);
logmemoryusage("Pas de traitement d'insertion pour " . $sNameXml);
} else {
// si pas pris en charge
jsonResponse(array("ERROR" => "Moi pas comprendre", "temps" => GetTimer($uStartTimer), "State" => "Error"));
Expand Down
11 changes: 5 additions & 6 deletions include/cst.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function uni_replace($string)

function constante_array()
{
$tab = array("CST_PLAYERS" => CST_PLAYERS, "CST_ALLIANCES" => CST_ALLIANCES);
$tab = array("CST_PLAYERS" => CST_PLAYERS, "CST_ALLIANCES" => CST_ALLIANCES , "CST_SERVERDATA" => CST_SERVERDATA);
$retour = array_merge($tab, constante_array_rank_alliance(), constante_array_rank_player(), constante_array_universe());
return $retour;
}
Expand Down Expand Up @@ -107,12 +107,11 @@ function constante_stepper()
global $server_config;

$retour = array();
$tab = array("CST_PLAYERS" => CST_PLAYERS, "CST_ALLIANCES" => CST_ALLIANCES);
$retour = array_merge($tab, constante_array_rank_alliance(), constante_array_rank_player());

//$tab = array("CST_PLAYERS" => CST_PLAYERS, "CST_ALLIANCES" => CST_ALLIANCES);
//$retour = array_merge($tab, constante_array_rank_alliance(), constante_array_rank_player());
$retour = constante_array();
$my_retour = array();


foreach ($retour as $key => $val) {
$my_retour[] = $key;
}
Expand All @@ -121,7 +120,7 @@ function constante_stepper()
// for ($i = 1; $i <= $server_config['num_of_galaxies']; $i++) {
// $my_retour[] = "CST_UNIVERSE_".$i ;
// }
$my_retour[] = "CST_UNIVERSE";
// $my_retour[] = "CST_UNIVERSE";

return $my_retour;
}
Expand Down
39 changes: 29 additions & 10 deletions include/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
die("Hacking attempt");

// par defaut 19, nb de colonne dans l array
function progress_barre($value, $nom, $valueMax = 19)
function progress_barre($value, $nom, $valueMax = 21)
{
$pct = (int) ((int) $value * 100 / (int) $valueMax);
$retour = "";

$retour = '<progress value="' . $pct . '" max="100" width="80%" height="20%" background-color="red">' . $nom . ' (' . $pct . '%)</progress>';

$retour .= '<progress value="' . $pct . '" max="100" width="80%" height="20%" background-color="red">' . $nom . ' (' . $pct . '%)</progress>';

return $retour;
}
Expand Down Expand Up @@ -86,7 +88,8 @@ function _is_out_of_date($type, $origin)
"CST_ALLIANCES_RANK_MILITARY_DESTROYED" => "8",
"CST_ALLIANCES_RANK_MILITARY_LOST" => "8",
"CST_ALLIANCES_RANK_MILITARY_HONNOR" => "8",
"CST_UNIVERSE" => "168" // modif suite a maj api ogame a tester ... ( pas d editeur sur pc pour le moment )
"CST_UNIVERSE" => "168", // modif suite a maj api ogame a tester ... ( pas d editeur sur pc pour le moment )
"CST_SERVERDATA" => "168" // constante univers, pas de modif reguliere, on met comme uni sur une semaine
);

$retour = true; // retour par defaut
Expand Down Expand Up @@ -151,7 +154,6 @@ function f_chargement_fichier_xml($s_fichier_xml)

if (file_exists($s_fichier_xml)) {
$o_xml = simplexml_load_file($s_fichier_xml);

return $o_xml;
} else {
exit('Echec lors de l\'ouverture du fichier ' . $s_fichier_xml . '.');
Expand Down Expand Up @@ -400,6 +402,20 @@ function traitement_universe($value)
change_date($type, $timestamp);
}




function traitement_serverdata($value)
{
global $type;
// stub de traitement
$timestamp = find_timestamp($value);


insert_config("last_" . $type, $timestamp);
change_date($type, $timestamp);
}

function traitement_player($value)
{
global $db, $type;
Expand Down Expand Up @@ -722,9 +738,10 @@ function findSpaId()
}

// le chemin distant renvoit il a un xml ?????
function DistantIsFileIXml($url) {
function DistantIsFileIXml($url)
{
try {
if ($stream = fopen($url, 'r')) {
if ($stream = fopen($url, 'r')) {
// 5 premier octet => verif bidons
$sStream = stream_get_contents($stream, 5);
if ($sStream == "<?xml") {
Expand All @@ -735,10 +752,10 @@ function DistantIsFileIXml($url) {
loggeur("check fichier XML No Ok " . $url);
fclose($stream);
}
} catch (Exception $e) {
loggeur("fichier non disponible via fopen " . $url);
loggeur($e->getMessage());
return false;
} catch (Exception $e) {
loggeur("fichier non disponible via fopen " . $url);
loggeur($e->getMessage());
return false;
}
return false;
}
Expand All @@ -761,3 +778,5 @@ function fileInfoExist($sUri)

return false;
}


4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
case "superapix":
include(MOD_ROOT_VUE . "index.php");
break;
case 2:
echo "i equals 2";
case "xml":
include(MOD_ROOT_VUE . "xml.php");
break;
default:
include(MOD_ROOT_VUE . "index.php");
Expand Down
3 changes: 2 additions & 1 deletion js/cross_domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ $(document).ready(function () {

function next_step(nb) {
nb = nb + 1;
if (nb == 19) { window.location = "index.php?action=superapix&step=0"; }
limit = count(constante_stepper()) +1 ;
if (nb == limit) { window.location = "index.php?action=superapix&step=0"; }
else {
window.location = "index.php?action=superapix&sub_action=cross&step=" + nb;
}
Expand Down
2 changes: 1 addition & 1 deletion vue/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
<?php if ($tcheckSecurity != NULL) :
?>
<?php foreach ($tcheckSecurity as $error) : ?>
<div class="og-msg og-msg-error">
<div class="og-msg og-msg-danger">
<p class="og-content"><?php echo $error; ?> </p>
<br>

Expand Down
21 changes: 0 additions & 21 deletions vue/help.php

This file was deleted.

4 changes: 1 addition & 3 deletions vue/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
$tcallbacks = constante_xtense_callbacks();
$uIdSuperapix = spaModId();



//include_once MOD_ROOT_VUE . "css.php";

?>
Expand All @@ -26,7 +24,7 @@
<p class="og-content">Celui ci est maintenant profilé pour automatiquement se mettre à jour sans actions utilisateurs </p>
</div>
<?php if ($tcheckSecurity != NULL) : ?>
<div class="og-msg og-msg-error ">
<div class="og-msg og-msg-danger ">
<h3 class="og-title">Mod Superapix</h3>
<p class="og-content"> La configuration du mod semble incorrecte (<?php echo count($tcheckSecurity); ?> erreur(s)).</p>
</div>
Expand Down
7 changes: 6 additions & 1 deletion vue/page_menu_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$activelink = ($pub_subaction == "link") ? "active" : "";
$activeadmin = ($pub_subaction == "admin") ? "active" : "";
$activesuperadmin = ($pub_subaction == "superapix") ? "active" : "";
$activexml = ($pub_subaction == "xml") ? "active" : "";

?>

Expand All @@ -26,7 +27,11 @@
Liens
</a>
</div>
<div class="nav-page-menu-item <?php echo $activeadmin; ?> ">
<div class="nav-page-menu-item <?php echo $activexml; ?> ">
<a class="nav-page-menu-link" href="index.php?action=superapix&amp;subaction=xml">
Info Serveur
</a>
</div> <div class="nav-page-menu-item <?php echo $activeadmin; ?> ">
<a class="nav-page-menu-link" href="index.php?action=superapix&amp;subaction=admin">
Administration
</a>
Expand Down
55 changes: 55 additions & 0 deletions vue/xml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* @package [Mod] Superapix
* @author Machine
* @copyright Copyright &copy; 2016, https://ogsteam.eu/
* @license https://opensource.org/licenses/gpl-license.php GNU Public License
*/
if (!defined('IN_SPYOGAME') || !defined('IN_SUPERAPIX'))
die("Hacking attempt");
?>
<?php $xml = MOD_ROOT_XML . "CST_SERVERDATA.xml"; ?>
<?php if (is_file($xml)) : ?>
<?php $simplexml = simplexml_load_file($xml); ?>
<?php echo ConvertXmlToHtmlTable($simplexml); ?>
<?php else : ?>
<div class="og-msg og-msg-danger ">
<h3 class="og-title">Fichier absent</h3>
<p class="og-content"> Le XML de configuration du serveur ogame n'est pas present?</p>
</div>
<?php endif; ?>




<?php
function ConvertXmlToHtmlTable($xml) {
$html = "<table align='center' border='1' class='og-table og-full-table'>\r\n";
$html .= "<thead><tr><th colspan='2'>".$xml->getName()."</th></tr></thead>\r\n";
$html .= "<tbody>";
foreach ($xml->children() as $ele) {
$elename = $ele->getName();
$attributes = "";

if ($ele->attributes()->count()) {
foreach ($ele->attributes() as $attribName => $attribValue) {
$attributes .= "\r\n" . $attribName . "=" . $attribValue;
}
}

$html .= "<tr><td>{$elename}{$attributes}</td>";

if ($ele->count()) {
$html .= "<td>" . ConvertXmlToHtmlTable($ele) . "</td>";
} else {
$html .= "<td>{$ele}</td>";
}

$html .= "</tr>";
}
$html .= "</tbody>";
$html .= "</table>";

return $html;
}

0 comments on commit de62b4b

Please sign in to comment.