|
| 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