Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement (bf2sclone): Show offline servers in servers page #145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/bf2sclone/template/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" class="inner">
<head>
<title>' . (isset($s['data']) ? esc_attr($s['data']['server']['hostname']) . ', ' : 'Unknown server, ') . esc_attr(TITLE) . '</title>
<title>' . ($s['data'] ? esc_attr($s['data']['server']['hostname']) : esc_attr($s['name'])) . ', ' . esc_attr(TITLE) . '</title>

<link rel="icon" href="'.$ROOT.'favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="'.$ROOT.'favicon.ico" type="image/x-icon">
Expand All @@ -22,7 +22,7 @@
<div id="page-1">
<div id="page-2">

<h1 id="page-title">' . ($s['data'] ? esc_attr($s['data']['server']['hostname']) : '-') . '</h1>
<h1 id="page-title">' . ($s['data'] ? esc_attr($s['data']['server']['hostname']) : esc_attr($s['name'])) . '</h1>
<div id="page-3">

<div id="content">
Expand Down Expand Up @@ -50,7 +50,7 @@
</tr>
<tr>
<td class="column-key">Status</td>
<td>' . ($s['data'] ? esc_attr($s['data']['server']['gamemode']) : '-') . '</td>
<td>' . ($s['data'] ? esc_attr($s['data']['server']['gamemode']) : 'OFFLINE') . '</td>
<td class="column-key">Players</td>
<td>' . ($s['data'] ? esc_attr("{$s['data']['server']['numplayers']}/{$s['data']['server']['maxplayers']}") : '-') . '</td>
</tr>
Expand Down
177 changes: 98 additions & 79 deletions src/bf2sclone/template/servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,94 +43,113 @@
</tr>';

foreach($servers as $s) {
if (!$s['data']) {
continue;
}
// Show only online servers?
// if ($s['data'] === false) {
// continue;
// }

$template .= '
<tr>
<td style="white-space: nowrap;">';

$serverLoad = $s['data']['server']['numplayers'] / $s['data']['server']['maxplayers'];
if ($serverLoad >= 0.66) {
$template .= '<img src="game-images/serverIcons/Serverload_red.png" alt="High Load" />';
} else if ($serverLoad >= 0.33) {
$template .= '<img src="game-images/serverIcons/Serverload_orange.png" alt="Medium Load" />';
<tr>
<td style="white-space: nowrap; cursor: default;">';
if ($s['data'] === false) {
$template .= '
<div style="display: inline-block; vertical-align: middle; width: 10px; height: 10px; border: 0px solid #000; border-radius: 50%; background: #F6B620;" title="OFF"></div>
<span style="vertical-align: middle; color: #F6B620;">OFF</span>
<img style="vertical-align: middle;" src="game-images/serverIcons/blank.png" alt="" />
</td>

<td><a href="?go=servers&sid=' . esc_attr($s['id']) . '">' . esc_attr($s['name']) . '</a></td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>';
} else {
$template .= '<img src="game-images/serverIcons/Serverload_green.png" alt="Low Load" />';
}
$template .= '<div style="display: inline-block; vertical-align: middle; width: 10px; height: 10px; border: 0px solid #000; border-radius: 50%; background: #b8ff6abd;" title="ONLINE"></div>';
$serverLoad = $s['data']['server']['numplayers'] / $s['data']['server']['maxplayers'];
if ($serverLoad >= 0.66) {
$template .= '<img src="game-images/serverIcons/Serverload_red.png" alt="High Load" />';
} else if ($serverLoad >= 0.33) {
$template .= '<img src="game-images/serverIcons/Serverload_orange.png" alt="Medium Load" />';
} else {
$template .= '<img src="game-images/serverIcons/Serverload_green.png" alt="Low Load" />';
}

if (preg_match('/^linux/', $s['data']['server']['bf2_os'])) {
$template .= '<img src="game-images/serverIcons/linux.png" alt="Linux" />';
} else {
$template .= '<img src="game-images/serverIcons/Windows.png" alt="Windows" />';
}
if (preg_match('/^linux/', $s['data']['server']['bf2_os'])) {
$template .= '<img src="game-images/serverIcons/linux.png" alt="Linux" />';
} else {
$template .= '<img src="game-images/serverIcons/Windows.png" alt="Windows" />';
}

if (preg_match('/-64$/', $s['data']['server']['bf2_os'])) {
$template .= '<img src="game-images/serverIcons/64bit.png" alt="64-bit" />';
} else {
$template .= '<img src="game-images/serverIcons/Windows.png" alt="Not 64-bit" />';
}

if (file_exists(ROOT . "/game-images/mods/{$s['data']['server']['gamevariant']}/mod_icon.png")) {
$mod = esc_attr($s['data']['server']['gamevariant']);
$template .= '<img src="game-images/mods/' . esc_attr($mod) . '/mod_icon.png" alt="' . esc_attr($mod) . '" />';
} else {
$template .= '<img src="game-images/serverIcons/unknown_mod.png" alt="unknown_mod" />';
}
if (preg_match('/-64$/', $s['data']['server']['bf2_os'])) {
$template .= '<img src="game-images/serverIcons/64bit.png" alt="64-bit" />';
} else {
$template .= '<img src="game-images/serverIcons/Windows.png" alt="Not 64-bit" />';
}
if (file_exists(ROOT . "/game-images/mods/{$s['data']['server']['gamevariant']}/mod_icon.png")) {
$mod = esc_attr($s['data']['server']['gamevariant']);
$template .= '<img src="game-images/mods/' . esc_attr($mod) . '/mod_icon.png" alt="' . esc_attr($mod) . '" />';
} else {
$template .= '<img src="game-images/serverIcons/unknown_mod.png" alt="unknown_mod" />';
}

if ($s['data']['server']['bf2_ranked']) {
$template .= '<img src="game-images/serverIcons/Ranked.png" alt="Ranked" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="Unranked" />';
}
if ($s['data']['server']['bf2_ranked']) {
$template .= '<img src="game-images/serverIcons/Ranked.png" alt="Ranked" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="Unranked" />';
}

if ($s['data']['server']['bf2_autorec']) {
$template .= '<img src="game-images/serverIcons/battlerec.png" alt="BattleRecorder On" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="BattleRecorder Off" />';
}
if ($s['data']['server']['bf2_autorec']) {
$template .= '<img src="game-images/serverIcons/battlerec.png" alt="BattleRecorder On" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="BattleRecorder Off" />';
}

if ($s['data']['server']['bf2_voip']) {
$template .= '<img src="game-images/serverIcons/battleCom.png" alt="BattleCommo On" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="BattleCommo Off" />';
}
if ($s['data']['server']['bf2_voip']) {
$template .= '<img src="game-images/serverIcons/battleCom.png" alt="BattleCommo On" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="BattleCommo Off" />';
}

if ($s['data']['server']['bf2_anticheat']) {
$template .= '<img src="game-images/serverIcons/punkBuster.png" alt="Punkbuster On" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="Punkbuster Off" />';
}

if ($s['data']['server']['bf2_pure']) {
$template .= '<img src="game-images/serverIcons/PureContent.png" alt="Pure" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="Not Pure" />';
}

if ($s['data']['server']['password']) {
$template .= '<img src="game-images/serverIcons/PasswordEnabled.png" alt="PasswordEnabled" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="No Password" />';
}
if ($s['data']['server']['bf2_anticheat']) {
$template .= '<img src="game-images/serverIcons/punkBuster.png" alt="Punkbuster On" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="Punkbuster Off" />';
}
if ($s['data']['server']['bf2_pure']) {
$template .= '<img src="game-images/serverIcons/PureContent.png" alt="Pure" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="Not Pure" />';
}
if ($s['data']['server']['password']) {
$template .= '<img src="game-images/serverIcons/PasswordEnabled.png" alt="PasswordEnabled" />';
} else {
$template .= '<img src="game-images/serverIcons/blank.png" alt="No Password" />';
}

$map = str_replace(' ', '_', strtolower($s['data']['server']['mapname']));
// devil's Perch Fix
$map = str_replace('\'', '', $map);
$mapUrl = file_exists(ROOT . "/game-images/levels/$map.png") ? "$ROOT/game-images/levels/$map.png" : "$ROOT/game-images/levels/default.png";
$template .= '
</td>
<td><a href="?go=servers&sid=' . esc_attr($s['id']) . '">' . esc_attr($s['data']['server']['hostname']) . '</a></td>
<td>' . esc_attr("{$s['data']['server']['numplayers']}/{$s['data']['server']['maxplayers']}"). '</td>
<td>
<img src="' . esc_attr($mapUrl) . '" alt="' . esc_attr($map) . '" />' .
' ' . esc_attr($s['data']['server']['mapname']) . '
</td>
<td>' . esc_attr($s['data']['server']['bf2_mapsize']) . '</td>
<td>' . (preg_match('/gpm_coop/i', $s['data']['server']['gametype']) ? 'Co-op' : 'Conquest') . '</td>
<td>' . esc_attr($s['data']['server']['gamevariant']). '</td>
<td>' . esc_attr(preg_replace('/^(\d+\.\d+).*$/', '$1', $s['data']['server']['gamever'])). '</td>
</tr>';
$map = str_replace(' ', '_', strtolower($s['data']['server']['mapname']));
// devil's Perch Fix
$map = str_replace('\'', '', $map);
$mapUrl = file_exists(ROOT . "/game-images/levels/$map.png") ? "$ROOT/game-images/levels/$map.png" : "$ROOT/game-images/levels/default.png";
$template .= '
</td>
<td><a href="?go=servers&sid=' . esc_attr($s['id']) . '">' . esc_attr($s['data']['server']['hostname']) . '</a></td>
<td>' . esc_attr("{$s['data']['server']['numplayers']}/{$s['data']['server']['maxplayers']}"). '</td>
<td>
<img src="' . esc_attr($mapUrl) . '" alt="' . esc_attr($map) . '" />' .
' ' . esc_attr($s['data']['server']['mapname']) . '
</td>
<td>' . esc_attr($s['data']['server']['bf2_mapsize']) . '</td>
<td>' . (preg_match('/gpm_coop/i', $s['data']['server']['gametype']) ? 'Co-op' : 'Conquest') . '</td>
<td>' . esc_attr($s['data']['server']['gamevariant']). '</td>
<td>' . esc_attr(preg_replace('/^(\d+\.\d+).*$/', '$1', $s['data']['server']['gamever'])). '</td>
</tr>';
}
}

$template .= '
Expand Down