Skip to content

Commit 22ceed3

Browse files
committed
Get data for servers from other page, to improve first load page speeds, if a server is offline.
1 parent 982682e commit 22ceed3

File tree

11 files changed

+359
-206
lines changed

11 files changed

+359
-206
lines changed

css/style.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ section {
344344
.mcheads {
345345
display: flex;
346346
flex-wrap: wrap;
347+
align-items:flex-start;
348+
align-content:flex-start;
347349
}
348350
.mcheads .mchead {
349351
display: grid;

functions.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ function get_title($url){
3030
return $title[1];
3131
}
3232
}
33-
function convertmodlistark($mod)
34-
{
35-
include ('html/type/arkse/modlist.php');
36-
return $modlist['ArkModName'][$mod];
37-
}
3833
function convertcsgomapname($mapname)
3934
{
4035
include ('html/type/csgo/maplist.php');

html/nav.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<div style="width: 100%;"></div>
55
<?php
66
session_start();
7+
session_write_close();
78
if (isset($_SESSION['username'])) {
89
$username = $_SESSION['username'];
910
echo '<div class="dropdown" style="height: 58px;">';

html/tabs.php

Lines changed: 81 additions & 137 deletions
Large diffs are not rendered by default.

html/type/arkse/modlist.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
$modlist['ArkModName'][1517538187] = 'Ark Arena';
33
$modlist['ArkModName'][2167099222] = 'I+ Structures for UndeadARK';
44
$modlist['ArkModName'][1840739225] = 'Getter Component';
5-
$modlist['ArkModName'][2369305725] = 'UnStacks 1000-80';
65
$modlist['ArkModName'][2412795047] = 'UI with commands';
76
$modlist['ArkModName'][1404697612] = 'Awesome SpyGlass!';
87
$modlist['ArkModName'][1808536179] = 'Spyglass';

html/type/query.php

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,30 @@
7676
$countplayers = $countplayers + 1;
7777
}
7878
}
79+
$playernames = $serverstatus->players;
80+
$count = 0;
81+
foreach ($playernames as $player) {
82+
if(!strlen($player->Name))
83+
continue;
84+
$playerlist[$count]['Name'] = $player->Name;
85+
$rawtime = $player->Time;
86+
$playerlist[$count]['Time'] = sprintf('%02dh:%02dm:%02ds', ($rawtime/ 3600),($rawtime/ 60 % 60), $rawtime% 60);
87+
$count++;
88+
}
89+
$count = 0;
7990
// Get the current game-day
8091
$ingameday = $serverstatus->rules->DayTime_s ?? '';
8192
// Get the cluster id
8293
$clusterid = $serverstatus->rules->ClusterId_s ?? 'Not cluster';
8394
// Check if server has a password
8495
$password = $serverstatus->rules->ServerPassword_b ?? '';
96+
if ($password == "True") {$password = $language[$lang][14];} else {$password = $language[$lang][15];}
8597
// Check if battleye is enabled
8698
$battleye = $serverstatus->rules->SERVERUSESBATTLEYE_b ?? '';
99+
if ($battleye) {$battleye=$language[$lang][14];}else {$battleye=$language[$lang][15];}
87100
// Check if pve is enabled
88101
$pve = $serverstatus->rules->SESSIONISPVE_i ?? '';
102+
if($pve){$pvp=$language[$lang][15];}else{$pvp=$language[$lang][14];}
89103
// CHeck if server has mods
90104
$hasmods = $serverstatus->rules->HASACTIVEMODS_i ?? '';
91105
// If the server has mods get the mod id's and store them in an array
@@ -103,6 +117,12 @@
103117
$mods[$value] = $modcontent;
104118
}
105119
}
120+
$officialmaps = array("Aberration", "CrystalIsles", "Gen2", "Gen", "LostIsland", "Ragnarok", "ScorchedEarth", "TheCenter", "TheIsland", "Valguero", "Viking_P", "Valhalla", "TheVolcano");
121+
if (in_array($map, $officialmaps)) {
122+
$maplink = "html/img/map/$map.webp";
123+
} else {
124+
$maplink = "html/img/map/modmap.webp";
125+
}
106126
break;
107127
case "minecraft":
108128
// Create connect link
@@ -114,7 +134,7 @@
114134
// Get Max Players
115135
$maxplayers = $serverstatus->players->max ?? '0';
116136
// Get the game logo
117-
$img = $serverstatus->favicon ?? $img;
137+
$img = "https://api.mcsrvstat.us/icon/".$ip;
118138
// Get the server version
119139
$version = $serverstatus->version->name ?? '0';
120140
// If the server is offline, the variable will be empty. That' how I check if the server is online.
@@ -161,14 +181,35 @@
161181
} else {
162182
$status = 0;
163183
}
184+
// Get List of Players
185+
$count = 0;
186+
if (!empty($serverstatus->players)) {
187+
foreach ($serverstatus->players as $player) {
188+
$playerlist[$count]['Name'] = $player;
189+
$playerlist[$count]['Skin'] = "https://crafatar.com/avatars/". minecraftcache($player);
190+
$count++;
191+
}
192+
}
164193
}
165194
// Check if title was set if not use cached title from db
166195
if (empty($title)) {
167196
$title = $name;
168197
}
169198
break;
170199
case "csgo":
200+
$playernames = $serverstatus->players;
201+
$count = 0;
202+
foreach ($playernames as $player) {
203+
if(!strlen($player->Name))
204+
continue;
205+
$playerlist[$count]['Name'] = $player->Name;
206+
$rawtime = $player->Time;
207+
$playerlist[$count]['Time'] = sprintf('%02dh:%02dm:%02ds', ($rawtime/ 3600),($rawtime/ 60 % 60), $rawtime% 60);
208+
$count++;
209+
}
210+
$count = 0;
171211
$password = $serverstatus->rules->ServerPassword_b ?? '';
212+
if (empty($password)) {$password=$language[$lang][14];}else{$password=$language[$lang][15];}
172213
if (isset($serverstatus->rules)) {
173214
$count = 0;
174215
foreach ($serverstatus->rules as $rulename => $rule) {
@@ -179,8 +220,31 @@
179220
if (empty($csgorule[$count][2])) {$csgorule[$count][2] = "0";}
180221
}
181222
}
223+
$officialmaps = array("ar_baggage", "ar_dizzy", "ar_lunacy", "ar_monastery", "ar_shoots", "cs_agency", "cs_assault", "cs_climb", "cs_italy", "cs_militia", "cs_office", "de_ancient", "de_bank", "de_cache", "de_canals", "de_cbble", "de_crete", "de_dust2", "de_hive", "de_inferno", "de_iris", "de_lake", "de_mirage", "de_nuke", "de_overpass", "de_safehouse", "de_shortdust", "de_shortnuke", "de_stmarc", "de_sugarcane", "de_train", "de_vertigo", "dz_blacksite", "dz_ember", "dz_sirocco", "dz_vineyard", "ze_Bathroom_v2_5");
224+
if (in_array($map, $officialmaps)) {
225+
$maplink = "html/img/map/$map.webp";
226+
$mapname = convertcsgomapname($map) ?? $map;
227+
} else {
228+
$substr = substr($map, 0, 3);
229+
if (preg_match('/[a-zA-Z]{2}\_{1}/m', $substr)) {
230+
$map = substr($map, 3);
231+
}
232+
$mapname = ucwords(str_replace("_"," ", $map));
233+
$maplink = "html/img/map/csgo_modmap.webp";
234+
}
182235
break;
183236
case "vrising":
237+
$playernames = $serverstatus->players;
238+
$count = 0;
239+
foreach ($playernames as $player) {
240+
if(!strlen($player->Name))
241+
continue;
242+
$playerlist[$count]['Name'] = $player->Name;
243+
$rawtime = $player->Time;
244+
$playerlist[$count]['Time'] = sprintf('%02dh:%02dm:%02ds', ($rawtime/ 3600),($rawtime/ 60 % 60), $rawtime% 60);
245+
$count++;
246+
}
247+
$count = 0;
184248
// Check if server has a password
185249
$password = $serverstatus->info->Password ?? '';
186250
if ($password == "True") {$password = $language[$lang][14];} else {$password = $language[$lang][15];}
@@ -196,8 +260,20 @@
196260
// Get the game tags
197261
$GameTags = $serverstatus->info->GameTags;
198262
$GameTags = str_replace(",", ", ", $GameTags);
263+
$maplink = "html/img/map/$map.webp";
199264
break;
200265
case "rust":
266+
$playernames = $serverstatus->players;
267+
$count = 0;
268+
foreach ($playernames as $player) {
269+
if(!strlen($player->Name))
270+
continue;
271+
$playerlist[$count]['Name'] = $player->Name;
272+
$rawtime = $player->Time;
273+
$playerlist[$count]['Time'] = sprintf('%02dh:%02dm:%02ds', ($rawtime/ 3600),($rawtime/ 60 % 60), $rawtime% 60);
274+
$count++;
275+
}
276+
$count = 0;
201277
// Get the seed and world size
202278
$seed = $serverstatus->rules->{'world.seed'};
203279
$worldsize = $serverstatus->rules->{'world.size'};

index.php

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,34 @@
2828
echo $lang ?>">
2929
<?php
3030
include('html/head.php') ?>
31-
<body>
31+
<body onload="callLoadData()">
3232
<?php
3333
include('html/nav.php'); ?>
34+
<?php if (!isset($_COOKIE["develop"])):?>
35+
<script>alert('Im working on the website right now')</script>
36+
<?php setcookie("develop", '1', time()+3600); /* expire in 1 hour */;
37+
endif;
38+
?>
3439
<div class="container">
3540
<table class="server_list_table">
3641
<tbody>
37-
<tr class="server_list_table_top">
38-
<th class="status_cell"><?php
39-
echo $language[$lang][6] ?></th>
40-
<th class="connectlink_cell"><?php
41-
echo $language[$lang][7] ?></th>
42-
<th class="servername_cell"><?php
43-
echo $language[$lang][8] ?></th>
44-
<th class="players_cell"><?php
45-
echo $language[$lang][4] ?></th>
46-
<th class="img-cell">
47-
<div></div>
48-
</th>
49-
</tr>
42+
<tr class="server_list_table_top">
43+
<th class="status_cell">
44+
<?php echo $language[$lang][6] ?>
45+
</th>
46+
<th class="connectlink_cell">
47+
<?php echo $language[$lang][7] ?>
48+
</th>
49+
<th class="servername_cell">
50+
<?php echo $language[$lang][8] ?>
51+
</th>
52+
<th class="players_cell">
53+
<?php echo $language[$lang][4] ?>
54+
</th>
55+
<th class="img-cell">
56+
<div></div>
57+
</th>
58+
</tr>
5059
</tbody>
5160
</table>
5261
<?php
@@ -67,39 +76,45 @@
6776
} else {
6877
echo "Query failed! Talk to your server administrator.";
6978
}
79+
$idimp = implode(',', $serverjson);
80+
// Get server information from database
81+
$sql = "SELECT ID, type FROM serverconfig WHERE ID IN ({$idimp})";
82+
$result = mysqli_query($conn, $sql);
83+
if (mysqli_num_rows($result) > 0) {
84+
while($row = mysqli_fetch_assoc($result)) {
85+
$ID = $row['ID'];
86+
$typearr[$ID] = $row['type'];
87+
88+
}
89+
}
7090
if (isset($serverjson)) {
71-
foreach ($serverjson as $ServerID) :
72-
if(!$ServerID){
91+
foreach ($serverjson as $ServerID) {
92+
if (!$ServerID) {
7393
continue;
7494
}
75-
unset($queryresult);
76-
if (!empty($ServerID)) {
77-
if (!$conn) {
78-
die("Connection failed: " . mysqli_connect_error());
79-
}
80-
$sql = "SELECT * FROM serverconfig WHERE ID='$ServerID'";
81-
$result = mysqli_query($conn, $sql);
82-
if (mysqli_num_rows($result) > 0) {
83-
while ($row = mysqli_fetch_assoc($result)) {
84-
$ip = $row["IP"];
85-
$type = $row["type"];
86-
$qport = $row["QueryPort"];
87-
$gport = $row["GamePort"];
88-
$rport = $row["RconPort"];
89-
$name = $row["Name"];
90-
}
91-
} else {
92-
echo "0 results";
93-
}
94-
}
95+
$type = $typearr[$ServerID];
96+
$sidscript[] = $ServerID;
9597
require 'server.php';
96-
endforeach;
98+
}
9799
$conn->close();
98100
}
99101
if ($username == "public") {
100102
echo "<div class='white-inftext'>" . $language[$lang][9] . "</div>";
101103
}
102104
?>
105+
<div>
106+
<button type="button" onclick="callLoadData()">Change Content</button>
107+
</div>
108+
<script>
109+
function callLoadData() {
110+
let serverid = JSON.parse('<?php echo json_encode($sidscript);?>');
111+
for (const value in serverid) {
112+
let modlink = `${serverid[value]}`;
113+
LoadData(modlink);
114+
}
115+
}
116+
</script>
117+
<script src="script.js"></script>
103118
</div>
104119
</body>
105120
</html>

query/minecraftquery.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$queryresult["info"] = ($Query->GetInfo());
2525
$queryresult["players"] = ($Query->GetPlayers());
2626
$queryresult = json_encode($queryresult);
27+
$queryresult = '{"info":{"HostName":"?4Linux?aGSM?3 von ?eLeo","GameType":"SMP","GameName":"MINECRAFT","Version":"1.18.2","Plugins":"","Map":"world","Players":1,"MaxPlayers":20,"HostPort":25565,"HostIp":"193.23.126.118","Software":"Vanilla"},"players":["tomctl2", "tomctl2", "tomctl2", "tomctl2", "tomctl2", "tomctl2", "tomctl2", "tomctl2", "tomctl2"]}';
2728
} catch (MinecraftQueryException $e) {
2829
}
2930
}

reload.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
2-
//ini_set('display_errors', 1);
3-
//ini_set('display_startup_errors', 1);
4-
//error_reporting(E_ALL);
52
$Timer = MicroTime(true);
63
// Get all files
74
require_once 'html/config.php';
5+
require_once 'functions.php';
86
require 'query/SourceQuery/bootstrap.php';
97
require 'query/minecraft/src/MinecraftPing.php';
108
require 'query/minecraft/src/MinecraftPingException.php';
@@ -49,15 +47,6 @@
4947
}
5048
}
5149
mysqli_close($conn);
52-
// Convert OS to Full OS Name
53-
function convertos($Os) {
54-
$Opers = array(
55-
'l' => 'Linux',
56-
'w' => 'Windows',
57-
'm' => 'Mac'
58-
);
59-
return $Opers[$Os];
60-
}
6150
switch ($type) {
6251
case "csgo":
6352
case "valheim":
@@ -101,19 +90,12 @@ function convertos($Os) {
10190
break;
10291
case "minecraft":
10392
$response['raw']['MOTD'] = $motd;
93+
$response['raw']['Players'] = $playerlist;
10494
break;
10595
}
10696
switch ($type) {
10797
case "arkse":
10898
include ('html/type/arkse/modlist.php');
109-
function get_title($url){
110-
$str = file_get_contents($url);
111-
if(strlen($str)>0){
112-
$str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside <title>
113-
preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title); // ignore case
114-
return $title[1];
115-
}
116-
}
11799
$response['raw']['Players'] = $playerlist;
118100
$response['raw']['InGameDay'] = $ingameday;
119101
$response['raw']['ClusterID'] = $clusterid;

0 commit comments

Comments
 (0)