Last active
January 11, 2020 18:17
-
-
Save gloony/b75122c29a98ed88afcdb4ba725ca212 to your computer and use it in GitHub Desktop.
Add view per user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Screen for Server must be open with : screen -dmS minecraft -L -Logfile /home/ubuntu/minecraft/screen.log | |
$cnx = array(); | |
$handle = fopen("/home/ubuntu/minecraft/screen.log", "r"); | |
if($handle){ | |
while(($line = fgets($handle))!== false){ | |
$line = str_replace(array("\r", "\n"), '', $line); | |
if($line=='^C'){} | |
elseif(substr($line, 0, 1)!='[') continue; | |
$time = strtotime(substr($line, 1, 20)); | |
$info = substr($line, 27); | |
if(substr($info, 0, 18)=='Player connected: '){ | |
$user = substr($info, 18); | |
$user = substr($user, 0, strpos($user, ",")); | |
$cnx[$user]['join'][] = $time; | |
}elseif(substr($info, 0, 21)=='Player disconnected: '){ | |
$user = substr($info, 21); | |
$user = substr($user, 0, strpos($user, ",")); | |
$cnx[$user]['leave'][] = $time; | |
}elseif(substr($info, 0, 21)=='Server started.'){ | |
foreach($cnx as $user => $value){ | |
if(count($value['join'])!=count($value['leave'])){ | |
if($time+300>$cnx[$user]['join'][count($cnx[$user]['join'])-1]){ | |
$time -= 300; // Assuming that we doesn't have a disconnect more than 5 minutes ... Be a good hoster :) | |
} | |
$cnx[$user]['leave'][] = $time; | |
} | |
} | |
} | |
} | |
fclose($handle); | |
} | |
foreach($cnx as $user => $value){ | |
if(count($value['join'])!=count($value['leave'])){ | |
$cnx[$user]['leave'][] = time(); | |
} | |
} | |
foreach($cnx as $user => $value){ | |
$dCount = 0; | |
$Total = 0; | |
$lDay = ''; | |
for($i=0;$i<=(count($value['join'])-1);$i++){ | |
if($lDay!=date('dm', $value['join'][$i])){ | |
$dCount++; | |
$lDay = date('dm', $value['join'][$i]); | |
} | |
$cTime = $value['leave'][$i] - $value['join'][$i]; | |
$Total += $cTime; | |
if($lDay!=date('dm', $value['leave'][$i])){ | |
$lDay = date('dm', $value['leave'][$i]); | |
} | |
} | |
$cnx[$user]['countDays'] = $dCount; | |
$cnx[$user]['loginTime'] = $Total; | |
} | |
?><html> | |
<head> | |
<title>NPF::Statistiques</title> | |
<meta name="apple-mobile-web-app-title" content="NPF::Statistiques" /> | |
<link rel="shortcut icon" href="favicon.ico"/> | |
<link rel="apple-touch-icon" href="favicon.png" /> | |
<meta name="apple-mobile-web-app-capable" content="yes" /> | |
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> | |
</head> | |
<body> | |
<?php | |
foreach($cnx as $user => $value){ | |
if(isset($_GET['gamertag'])){ | |
if($user!=$_GET['gamertag']) continue; | |
} | |
echo "\t\t\t".'<a href="?gamertag='.$user.'"><img src="https://www.xboxgamertag.com/gamercard/'.$user.'/fullnxe/card.png" /></a>'."<br />\n"; | |
echo "\t\t\t".' <i>Temps de connection</i> = '.WriteLapse(intval($value['loginTime']))."<br />\n"; | |
echo "\t\t\t".' <i>Temps de connection moyenne</i> = '.WriteLapse(intval(intval($value['loginTime'])/count($value['join'])))."<br />\n"; | |
echo "\t\t\t".' <i>Première connection</i> = '.date('d.m.Y', $value['join'][0])."<br />\n"; | |
echo "\t\t\t".' <i>Nombres de connections</i> = '.count($value['join'])." sur ".$value['countDays']." Jours<br /><br />\n\n"; | |
if(isset($_GET['gamertag'])){ | |
$lDay = ''; | |
for($i=0;$i<=(count($value['join'])-1);$i++){ | |
$cTime = $value['leave'][$i] - $value['join'][$i]; | |
if($cTime<=120) continue; | |
if($lDay!=date('dm', $value['join'][$i])){ | |
$lDay = date('dm', $value['join'][$i]); | |
echo "\n\t\t\t".'<br /><b>'.date('d.m.Y', $value['join'][$i])."</b><br />\n"; | |
} | |
echo "\t\t\t".' De <b>'.date('H:i:s', $value['join'][$i]).'</b> à <b>'.date('H:i:s', $value['join'][$i] + $cTime).'</b> pour <b>'.WriteLapse($cTime)."</b><br />\n"; | |
} | |
} | |
} | |
function WriteLapse($total){ | |
$days = intval($total / 86400); | |
if($days > 0){ | |
$sTime .= $days.' Jours '; | |
$total -= $days * 86400; | |
} | |
$hours = intval($total / 3600); | |
if($hours > 0){ | |
$sTime .= $hours.' Heures '; | |
$total -= $hours * 3600; | |
} | |
$mins = intval($total / 60); | |
if($mins > 0){ | |
$sTime .= $mins.' Minutes '; | |
$total -= $mins * 60; | |
} | |
if($total > 0) $sTime .= $total.' Secondes'; | |
return $sTime; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read ScreenLog of minecraft BDS to export ingame time for each player.
This can be used to export it on DB for further use or simply display data in this script but it will be slow on large instance.