| 1 |
<div id="content"> |
| 2 |
<h2>Recent Deliantra Players</h2> |
| 3 |
|
| 4 |
<p> |
| 5 |
This list is updated every ten minutes to show who is online. |
| 6 |
</p> |
| 7 |
|
| 8 |
<?php |
| 9 |
|
| 10 |
/** |
| 11 |
* array timeDiff(int $t1, int $t2) |
| 12 |
* $t1 and $t2 must be UNIX timestamp integers, order does not matter |
| 13 |
* returns array broken down into years/months/weeks/etc. |
| 14 |
*/ |
| 15 |
function timeDiff($t1, $t2) |
| 16 |
{ |
| 17 |
if($t1 > $t2) |
| 18 |
{ |
| 19 |
$time1 = $t2; |
| 20 |
$time2 = $t1; |
| 21 |
} |
| 22 |
else |
| 23 |
{ |
| 24 |
$time1 = $t1; |
| 25 |
$time2 = $t2; |
| 26 |
} |
| 27 |
$diff = array( |
| 28 |
'years' => 0, |
| 29 |
'months' => 0, |
| 30 |
'weeks' => 0, |
| 31 |
'days' => 0, |
| 32 |
'hours' => 0, |
| 33 |
'minutes' => 0, |
| 34 |
'seconds' =>0 |
| 35 |
); |
| 36 |
|
| 37 |
foreach(array('years','months','weeks','days','hours','minutes','seconds') |
| 38 |
as $unit) |
| 39 |
{ |
| 40 |
while(TRUE) |
| 41 |
{ |
| 42 |
$next = strtotime("+1 $unit", $time1); |
| 43 |
if($next < $time2) |
| 44 |
{ |
| 45 |
$time1 = $next; |
| 46 |
$diff[$unit]++; |
| 47 |
} |
| 48 |
else |
| 49 |
{ |
| 50 |
break; |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
return($diff); |
| 55 |
} |
| 56 |
|
| 57 |
function timeDifferenceText($pastDate) |
| 58 |
{ |
| 59 |
$rightNow = time(); |
| 60 |
$difference = timeDiff($rightNow,$pastDate); |
| 61 |
|
| 62 |
if($difference['years']>0) |
| 63 |
{ |
| 64 |
if($difference['years']==1) |
| 65 |
{ |
| 66 |
$difference = " 1 year ago"; |
| 67 |
} |
| 68 |
else |
| 69 |
{ |
| 70 |
$difference = $difference['years'] . " years ago"; |
| 71 |
} |
| 72 |
} |
| 73 |
else if($difference['months']>0) |
| 74 |
{ |
| 75 |
if($difference['months']==1) |
| 76 |
{ |
| 77 |
$difference = " 1 month ago"; |
| 78 |
} |
| 79 |
else |
| 80 |
{ |
| 81 |
$difference = $difference['months'] . " months ago"; |
| 82 |
} |
| 83 |
} |
| 84 |
else if($difference['weeks']>0) |
| 85 |
{ |
| 86 |
if($difference['weeks']==1) |
| 87 |
{ |
| 88 |
$difference = " 1 week ago"; |
| 89 |
} |
| 90 |
else |
| 91 |
{ |
| 92 |
$difference = $difference['weeks'] . " weeks ago"; |
| 93 |
} |
| 94 |
} |
| 95 |
else if($difference['days']>0) |
| 96 |
{ |
| 97 |
if($difference['days']==1) |
| 98 |
{ |
| 99 |
$difference = "1 day ago"; |
| 100 |
} |
| 101 |
else |
| 102 |
{ |
| 103 |
$difference = $difference['days'] . " days ago"; |
| 104 |
} |
| 105 |
} |
| 106 |
else if($difference['hours']>0) |
| 107 |
{ |
| 108 |
if($difference['hours']==1) |
| 109 |
{ |
| 110 |
$difference = " 1 hour ago"; |
| 111 |
} |
| 112 |
else |
| 113 |
{ |
| 114 |
$difference = $difference['hours'] . " hours ago"; |
| 115 |
} |
| 116 |
} |
| 117 |
else if($difference['minutes']) |
| 118 |
{ |
| 119 |
if($difference['minutes']==1) |
| 120 |
{ |
| 121 |
$difference = " 1 minute ago"; |
| 122 |
} |
| 123 |
else |
| 124 |
{ |
| 125 |
$difference = $difference['minutes'] . " minutes ago"; |
| 126 |
} |
| 127 |
} |
| 128 |
else |
| 129 |
{ |
| 130 |
$difference = " Just now"; |
| 131 |
} |
| 132 |
|
| 133 |
return $difference; |
| 134 |
} |
| 135 |
|
| 136 |
//Generate the highscore table. |
| 137 |
|
| 138 |
$jsonScoresUnparsed = file_get_contents("recent.json"); |
| 139 |
|
| 140 |
$jsonArray = json_decode($jsonScoresUnparsed); |
| 141 |
|
| 142 |
$timestamp = $jsonArray->date; |
| 143 |
$version = $jsonArray->version; |
| 144 |
$players = $jsonArray->data; |
| 145 |
|
| 146 |
echo "<table style='width: 100%'>\n"; |
| 147 |
echo "<tr><th>Player Name</th><th>Last Login</th><th>Last Logout</th><th>Birthdate</th><th style='text-align: right;'>Logins</th><th style='text-align: right;'>Deaths</th><th>OS</th><th>Go</th></tr>"; |
| 148 |
|
| 149 |
$number = 0; |
| 150 |
$size = 100; |
| 151 |
foreach($players as $player) |
| 152 |
{ |
| 153 |
echo "<tr style='font-size: $size%'>"; |
| 154 |
$number++; |
| 155 |
|
| 156 |
if($number>50 & $size>=50) |
| 157 |
{ |
| 158 |
$size -= .5; //Decrease the font size. |
| 159 |
} |
| 160 |
|
| 161 |
$name = $player[0]; |
| 162 |
$birthdate = $player[1]; |
| 163 |
$lastLogin = $player[2]; |
| 164 |
$loginCount = $player[3]; |
| 165 |
$lastLogout = $player[4]; |
| 166 |
$client = $player[5]; |
| 167 |
$deaths = $player[6]; |
| 168 |
$location = $player[7]; |
| 169 |
|
| 170 |
/* |
| 171 |
//A quick PHP side filter. If needed uncomment. |
| 172 |
|
| 173 |
$ancientTest = timeDiff(time(),$lastLogin); |
| 174 |
|
| 175 |
if($ancientTest['months']>0) |
| 176 |
{ |
| 177 |
break; //Haven't logged in for a month.... they aren't exactly recent or online. |
| 178 |
} |
| 179 |
*/ |
| 180 |
|
| 181 |
if($deaths==="?") |
| 182 |
{ |
| 183 |
$deaths = 0; |
| 184 |
} |
| 185 |
|
| 186 |
$loginDifference = timeDifferenceText($lastLogin); |
| 187 |
if($lastLogout==null) |
| 188 |
{ |
| 189 |
$logoutDifference = "Currently online"; |
| 190 |
} |
| 191 |
else |
| 192 |
{ |
| 193 |
$logoutDifference = timeDifferenceText($lastLogout); |
| 194 |
} |
| 195 |
if($birthdate==null) |
| 196 |
{ |
| 197 |
$birthdateDifference = "Before known time"; |
| 198 |
} |
| 199 |
else |
| 200 |
{ |
| 201 |
$birthdateDifference = timeDifferenceText($birthdate); |
| 202 |
} |
| 203 |
|
| 204 |
if(stripos($client,"darwin")!==FALSE) |
| 205 |
{ |
| 206 |
$operatingSystem = "mac"; |
| 207 |
} |
| 208 |
else if(stripos($client,"unix")!==FALSE) |
| 209 |
{ |
| 210 |
$operatingSystem = "mac"; |
| 211 |
} |
| 212 |
else if(stripos($client,"MSWin32")!==FALSE) |
| 213 |
{ |
| 214 |
$operatingSystem = "win"; |
| 215 |
} |
| 216 |
else if(stripos($client,"linux")!==FALSE) |
| 217 |
{ |
| 218 |
$operatingSystem = "lin"; |
| 219 |
} |
| 220 |
|
| 221 |
if($logoutDifference==="Currently online") |
| 222 |
{ |
| 223 |
$loggedInColor = "#96FFB2"; |
| 224 |
echo "<td style='background-color: $loggedInColor;'>$name</td><td style='background-color: $loggedInColor;'>$loginDifference</td><td style='background-color: $loggedInColor;'>$logoutDifference</td><td style='background-color: $loggedInColor;'>$birthdateDifference</td><td style='background-color: $loggedInColor;' align='right'>$loginCount</td><td style='background-color: $loggedInColor;' align='right'>$deaths</td>\n"; |
| 225 |
echo "<td align='center' style='background-color: $loggedInColor;'><img title='$client' style='width: 20px; height: 20px;' src='images/$operatingSystem.png' /></td>\n"; |
| 226 |
|
| 227 |
if(stripos($location,"~")!==FALSE or stripos($location,"?random")!==FALSE) |
| 228 |
{ |
| 229 |
echo "<td align='center' style='background-color: $loggedInColor;'><img title='$name is on a map you can not see: $location' style='width: 20px; height: 20px;' src='images/no.png' /></a></td>\n"; |
| 230 |
} |
| 231 |
else |
| 232 |
{ |
| 233 |
echo "<td align='center' style='background-color: $loggedInColor;'><a href='http://maps.deliantra.net$location'><img title='$location' style='width: 20px; height: 20px;' src='images/arrow.png' /></a></td>\n"; |
| 234 |
} |
| 235 |
} |
| 236 |
else |
| 237 |
{ |
| 238 |
echo "<td>$name</td><td>$loginDifference</td><td>$logoutDifference</td><td>$birthdateDifference</td><td align='right'>$loginCount</td><td align='right'>$deaths</td>\n"; |
| 239 |
echo "<td align='center'><img title='$client' style='width: 20px; height: 20px;' src='images/$operatingSystem.png' /></td>\n"; |
| 240 |
|
| 241 |
if(stripos($location,"~")!==FALSE or stripos($location,"?random")!==FALSE) |
| 242 |
{ |
| 243 |
echo "<td align='center'><img title='$name is on a map you can not see: $location' style='width: 20px; height: 20px;' src='images/no.png' /></a></td>\n"; |
| 244 |
} |
| 245 |
else |
| 246 |
{ |
| 247 |
$location = str_replace ("/world/", "/world-precomposed/", $location); |
| 248 |
echo "<td align='center'><a href='http://maps.deliantra.net$location'><img title='$location' style='width: 20px; height: 20px;' src='images/arrow.png' /></a></td>\n"; |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
echo "</tr>\n"; |
| 253 |
} |
| 254 |
|
| 255 |
echo "</table>\n"; |
| 256 |
?> |
| 257 |
|
| 258 |
</div> |
| 259 |
|
| 260 |
|