Skip to content

Commit 07e9abd

Browse files
committed
feat: add server selection
Users can now select a server to view, if you have multiple servers to show. I will update the readme to reflect these changes but, the easiest way to get this working is to add a empty array to the servers file with a name of your choice.
1 parent 10df12b commit 07e9abd

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

index.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
require_once("utils/config.php");
2727
require_once("utils/params.php");
2828
require_once("utils/update_checker.php");
29+
require_once("utils/servers.php");
30+
31+
Servers::init();
2932

3033
Update::getCurrentVersion();
3134

@@ -158,10 +161,24 @@
158161
<img src="https://avatars1.githubusercontent.com/u/1770893?s=460&v=4" style="max-height: 30px" >
159162
Live Map
160163
</a>
161-
164+
162165
<div class="collapse navbar-collapse" id="navbarNav">
163166
<ul class="navbar-nav">
164-
<!-- TODO: Dynamically generate links? -->
167+
<!-- Servers -->
168+
<li class="nav-item dropdown">
169+
<a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
170+
Select a server
171+
</a>
172+
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
173+
<?php
174+
$srvs = Servers::getServers();
175+
foreach ($srvs as $key => $value) {
176+
echo "<a class='dropdown-item' href='$value'>$key</a>";
177+
}
178+
?>
179+
</div>
180+
</li>
181+
165182
</ul>
166183
</div>
167184
</div>
@@ -206,6 +223,12 @@
206223
<div class="list-group border-0 card text-center text-md-left" >
207224
<a class="nav-header">Information</a>
208225

226+
<a class="list-group-item d-inline-block collapsed">Currently viewing:
227+
<p id="server_name" style="white-space: normal; color: #17A2B8">
228+
<?php echo $config->currentServer; ?>
229+
</p>
230+
</a>
231+
209232
<a class="list-group-item d-inline-block collapsed">Blips loaded
210233
<span id="blip_count" class="badge badge-pill badge-info pull-right">0</span>
211234
</a>

utils/config.php

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class Config{
7474
// Note: THIS MAY BE THE PLAYER'S IP ADDRESS
7575
public $showIdentifiers = true;
7676

77+
// DO NOT CHANGE ANYTHING BELOW
78+
79+
public $currentServer = "";
80+
7781
/**
7882
* Gets the URL for the GTA server.
7983
*

utils/servers.php

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
// ************************************************************************** //
3+
// LiveMap Interface - The web interface for the livemap
4+
// Copyright (C) 2017 Jordan Dalton
5+
//
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program in the file "LICENSE". If not, see <http://www.gnu.org/licenses/>.
18+
// ************************************************************************** //
19+
20+
/*
21+
Class used to group different server info together and make swiching between
22+
them easier
23+
*/
24+
class Servers {
25+
/*
26+
An array containing all your servers running the livemap resource.
27+
Only provide the information (e.g. ip) if it differs
28+
29+
For example, if you have another server running on the same server but,
30+
different port just change the "fivemPort" and "socketPort" variables :)
31+
*/
32+
private static $servers = array(
33+
"testy mc test" => array( // The name of the server (make unique)
34+
"ip" => "127.0.0.1", // The IP (if on something different to the one in the config)
35+
"fivemPort" => "30120", // The fivem port
36+
"socketPort" => "30121", // Set to the port that you set in the "socket_port" convar (if different to the one in the config)
37+
"liveMapName" => "live_map" // Set to the resource's name (if different to the one in the config)
38+
)
39+
);
40+
41+
/***********************
42+
*
43+
* NO TOUCHY BELOW
44+
* SERIOUSLY, YOU'LL PROBABLY JUST FUCK SOOMETHING UP
45+
*
46+
***********************/
47+
public function doesServerExist($name){
48+
return array_key_exists($name, self::$servers);
49+
}
50+
51+
public function init(){
52+
$conf = Config::getConfig();
53+
$srv = NULL;
54+
$name = "";
55+
56+
if(ISSET($_GET["server"])){
57+
$name = $_GET["server"];
58+
59+
if(self::doesServerExist($name)){
60+
$srv = self::$servers[$name];
61+
}else{
62+
$name = key(self::$servers); // get the first server in array
63+
$srv = self::$servers[$name];
64+
}
65+
66+
unset($_GET["server"]);
67+
}else{
68+
$name = key(self::$servers); // get the first server in array
69+
$srv = self::$servers[$name];
70+
}
71+
72+
// Update the config for the new server
73+
if(array_key_exists("ip", $srv)){
74+
$conf->fivemIP = $srv["ip"];
75+
}
76+
if(array_key_exists("fivemPort", $srv)){
77+
$conf->fivemPort = $srv["fivemPort"];
78+
}
79+
if(array_key_exists("socketPort", $srv)){
80+
$conf->socketPort = $srv["socketPort"];
81+
}
82+
if(array_key_exists("liveMapName", $srv)){
83+
$conf->liveMapName = $srv["liveMapName"];
84+
}
85+
86+
$conf->currentServer = $name;
87+
}
88+
89+
public function getServers(){
90+
$serverNames = array();
91+
foreach(self::$servers as $key=>$val){
92+
$uri = sprintf("http://%s%s?server=%s", $_SERVER["SERVER_NAME"], $_SERVER["PHP_SELF"], urlencode($key));
93+
$serverNames[$key] = $uri;
94+
}
95+
return $serverNames;
96+
}
97+
98+
}
99+
100+
?>

0 commit comments

Comments
 (0)