2014-01-26 11:03:52 +01:00
< ? php
/**
* File : functions_gs . php .
* Author : Ulrich Block
* Date : 26.01 . 14
* Time : 10 : 46
* Contact : < ulrich . block @ easy - wi . com >
*
* This file is part of Easy - WI .
*
* Easy - WI is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* Easy - WI is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with Easy - WI . If not , see < http :// www . gnu . org / licenses />.
*
* Diese Datei ist Teil von Easy - WI .
*
* Easy - WI ist Freie Software : Sie koennen es unter den Bedingungen
* der GNU General Public License , wie von der Free Software Foundation ,
* Version 3 der Lizenz oder ( nach Ihrer Wahl ) jeder spaeteren
* veroeffentlichten Version , weiterverbreiten und / oder modifizieren .
*
* Easy - WI wird in der Hoffnung , dass es nuetzlich sein wird , aber
* OHNE JEDE GEWAEHELEISTUNG , bereitgestellt ; sogar ohne die implizite
* Gewaehrleistung der MARKTFAEHIGKEIT oder EIGNUNG FUER EINEN BESTIMMTEN ZWECK .
* Siehe die GNU General Public License fuer weitere Details .
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben . Wenn nicht , siehe < http :// www . gnu . org / licenses />.
*/
if ( ! defined ( 'EASYWIDIR' )) {
define ( 'EASYWIDIR' , '' );
}
2014-11-23 12:53:36 +01:00
if ( ! function_exists ( 'eacchange' )) {
2014-01-26 11:03:52 +01:00
function eacchange ( $what , $serverid , $rcon , $reseller_id ) {
global $sql ;
2014-02-01 15:07:29 +01:00
global $dbConnect ;
2014-04-23 20:08:59 +02:00
2014-01-26 11:03:52 +01:00
$subfolder = '' ;
$parameter = '' ;
2014-02-01 15:07:29 +01:00
$query = $sql -> prepare ( " SELECT `active`,`cfgdir`,`type`,`mysql_server`,`mysql_port`,`mysql_db`,`mysql_table`,`mysql_user`,`mysql_password` FROM `eac` WHERE `resellerid`=? LIMIT 1 " );
2014-01-26 11:03:52 +01:00
$query -> execute ( array ( $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-10-05 12:13:20 +02:00
2014-01-26 11:03:52 +01:00
$cfgdir = $row [ 'cfgdir' ];
$active = $row [ 'active' ];
2014-02-01 15:07:29 +01:00
$type = $row [ 'type' ];
$mysql_server = $row [ 'mysql_server' ];
$mysql_port = $row [ 'mysql_port' ];
$mysql_db = $row [ 'mysql_db' ];
$mysql_table = $row [ 'mysql_table' ];
$mysql_user = $row [ 'mysql_user' ];
$mysql_password = $row [ 'mysql_password' ];
2014-01-26 11:03:52 +01:00
2014-10-05 12:13:20 +02:00
$query2 = $sql -> prepare ( " SELECT g.`serverip`,g.`port`,s.`anticheat`,t.`shorten` FROM `gsswitch` g LEFT JOIN `serverlist` s ON g.`serverid`=s.`id` LEFT JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`id`=? AND g.`resellerid`=? LIMIT 1 " );
$query2 -> execute ( array ( $serverid , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
2014-02-01 15:07:29 +01:00
2014-10-05 12:13:20 +02:00
$gsip = $row2 [ 'serverip' ];
$gsport = $row2 [ 'port' ];
2014-02-01 15:07:29 +01:00
$sqlParameter = 0 ;
2014-01-26 11:03:52 +01:00
2014-10-05 12:13:20 +02:00
if ( $row2 [ 'anticheat' ] == 3 ) {
2014-01-26 11:03:52 +01:00
$parameter = '' ;
2014-10-05 12:13:20 +02:00
} else if ( $row2 [ 'anticheat' ] == 4 ) {
2014-01-26 11:03:52 +01:00
$parameter = '-2' ;
2014-02-01 15:07:29 +01:00
$sqlParameter = 2 ;
2014-10-05 12:13:20 +02:00
} else if ( $row2 [ 'anticheat' ] == 5 ) {
2014-01-26 11:03:52 +01:00
$parameter = '-1' ;
2014-02-01 15:07:29 +01:00
$sqlParameter = 1 ;
2014-10-05 12:13:20 +02:00
} else if ( $row2 [ 'anticheat' ] == 6 ) {
2014-01-26 11:03:52 +01:00
$parameter = '-3' ;
2014-02-01 15:07:29 +01:00
$sqlParameter = 3 ;
2014-01-26 11:03:52 +01:00
}
2014-02-01 15:07:29 +01:00
$gameID = 0 ;
2014-10-05 12:13:20 +02:00
if ( $row2 [ 'shorten' ] == 'cstrike' or $row2 [ 'shorten' ] == 'czero' ) {
2014-02-01 15:07:29 +01:00
2014-01-26 11:03:52 +01:00
$subfolder = 'hl1' ;
2014-02-01 15:07:29 +01:00
$gameID = 1 ;
2014-10-05 12:13:20 +02:00
} else if ( $row2 [ 'shorten' ] == 'css' or $row2 [ 'shorten' ] == 'tf' ) {
2014-02-01 15:07:29 +01:00
2014-01-26 11:03:52 +01:00
$subfolder = 'hl2' ;
2014-02-01 15:07:29 +01:00
$gameID = 2 ;
2014-10-05 12:13:20 +02:00
} else if ( $row2 [ 'shorten' ] == 'csgo' ) {
2014-02-01 15:07:29 +01:00
2014-01-26 22:59:56 +01:00
$subfolder = 'csgo' ;
2014-02-01 15:07:29 +01:00
$gameID = 4 ;
2014-01-26 11:03:52 +01:00
}
2014-02-01 15:07:29 +01:00
if ( $type == 'M' ) {
2014-01-26 11:03:52 +01:00
2014-02-01 15:07:29 +01:00
$mysql_port = ( port ( $mysql_port )) ? $mysql_port : 3306 ;
$eacSql = new PDO ( " mysql:host= ${ mysql_server};dbname=${mysql_db};port=${mysql_port } " , $mysql_user , $mysql_password , array ( PDO :: MYSQL_ATTR_INIT_COMMAND => " SET NAMES utf8 " ));
2014-01-26 11:03:52 +01:00
2014-02-01 15:07:29 +01:00
if ( $dbConnect [ 'debug' ] == 1 ) {
$eacSql -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION );
2014-01-26 11:03:52 +01:00
}
2014-02-01 15:07:29 +01:00
2014-10-05 12:13:20 +02:00
$query3 = $eacSql -> prepare ( " SELECT 1 FROM ` " . $mysql_table . " ` WHERE `IP`=? LIMIT 1 " );
$query3 -> execute ( array ( $gsip . ':' . $gsport ));
$entryExists = $query3 -> rowCount ();
2014-02-01 15:07:29 +01:00
if ( $entryExists > 0 and $what == 'change' ) {
2014-10-05 12:13:20 +02:00
$query3 = $eacSql -> prepare ( " UPDATE ` " . $mysql_table . " ` SET `GAME`=?,`RCONPWD`=?,`FLAGS`=?,`EAC_ENABLED`=1 WHERE `IP`=? LIMIT 1 " );
$query3 -> execute ( array ( $gameID , $rcon , $sqlParameter , $gsip . ':' . $gsport ));
2014-02-01 15:07:29 +01:00
} else if ( $entryExists == 0 and $what == 'change' ) {
2014-10-05 12:13:20 +02:00
$query3 = $eacSql -> prepare ( " INSERT INTO ` " . $mysql_table . " ` (`GAME`,`IP`,`RCONPWD`,`FLAGS`,`EAC_ENABLED`) VALUES (?,?,?,?,1) " );
$query3 -> execute ( array ( $gameID , $gsip . ':' . $gsport , $rcon , $sqlParameter ));
2014-02-01 15:07:29 +01:00
} else if ( $entryExists > 0 and $what == 'remove' ) {
2014-10-05 12:13:20 +02:00
$query3 = $eacSql -> prepare ( " DELETE FROM ` " . $mysql_table . " ` WHERE `IP`=? " );
$query3 -> execute ( array ( $gsip . ':' . $gsport ));
2014-02-01 15:07:29 +01:00
}
} else {
$file = $cfgdir . '/' . $subfolder . '/' . $gsip . '-' . $gsport ;
$file = preg_replace ( '/\/\//' , '/' , $file );
if ( $what == 'change' ) {
$ssh2cmd = 'echo "' . $gsip . ':' . $gsport . '-' . $rcon . $parameter . '" > ' . $file ;
} else if ( $what == 'remove' ) {
$ssh2cmd = 'rm -f ' . $file ;
}
if ( isset ( $ssh2cmd ) and $active == 'Y' ) {
if ( ! function_exists ( 'ssh2_execute' )) {
2014-02-23 13:13:48 +01:00
include ( EASYWIDIR . '/stuff/methods/functions_ssh_exec.php' );
2014-02-01 15:07:29 +01:00
}
if ( isset ( $ssh2cmd )) {
ssh2_execute ( 'eac' , $reseller_id , $ssh2cmd );
}
2014-01-26 11:03:52 +01:00
}
}
}
}
}
2014-01-30 19:03:02 +01:00
function normalizeName ( $value ) {
// control characters
$value = str_replace ( array ( " \r " , " \n " ), '' , $value );
// COD colors
$value = preg_replace ( '/\^[0-9]/i' , '' , $value );
// Unreal Tournament Colors
$value = preg_replace ( '/\x1B...|\^\d/' , '' , $value );
// Minecraft Motd Colors
$value = preg_replace ( '/\\[u]00A7[\w]/i' , '' , $value );
// Minecraft standard colors
$value = preg_replace ( '/§[0-9a-f]/i' , '' , $value );
return $value ;
}
2014-09-28 13:47:14 +02:00
2016-02-27 08:19:33 +01:00
function getAppMasterList ( $resellerID , $modifyGS = false ) {
2014-09-28 13:47:14 +02:00
$table = array ();
global $sql ;
2016-02-27 08:19:33 +01:00
if ( is_numeric ( $modifyGS )) {
2016-04-16 12:20:03 +02:00
$query = $sql -> prepare ( " SELECT r.`id`,r.`ip`,r.`description`,(r.`maxserver` - COUNT(DISTINCT s.`id`)) AS `freeserver` , ((CASE WHEN r.`ram` IS NULL OR r.`ram`=0 THEN 999999 ELSE r.`ram` END) - SUM( s.`maxram` )) AS `free_ram`,r.`active` AS `hostactive`,r.`resellerid` AS `resellerid` FROM `rserverdata` r LEFT JOIN `gsswitch` s ON s.`rootID` = r.`id` WHERE r.`active`='Y' AND r.`resellerid`=? GROUP BY r.`id` HAVING (r.`id`=? OR ((`freeserver`>0 OR `freeserver` IS NULL) AND (`free_ram`>0 OR `free_ram` IS NULL))) ORDER BY `freeserver` DESC, `free_ram` DESC " );
2016-02-27 08:19:33 +01:00
$query -> execute ( array ( $resellerID , $modifyGS ));
} else {
2016-04-16 12:20:03 +02:00
$query = $sql -> prepare ( " SELECT r.`id`,r.`ip`,r.`description`,(r.`maxserver` - COUNT(DISTINCT s.`id`)) AS `freeserver` , ((CASE WHEN r.`ram` IS NULL OR r.`ram`=0 THEN 999999 ELSE r.`ram` END) - SUM( s.`maxram` )) AS `free_ram`,r.`active` AS `hostactive`,r.`resellerid` AS `resellerid` FROM `rserverdata` r LEFT JOIN `gsswitch` s ON s.`rootID` = r.`id` WHERE r.`active`='Y' AND r.`resellerid`=? GROUP BY r.`id` HAVING ((`freeserver`>0 OR `freeserver` IS NULL) AND (`free_ram`>0 OR `free_ram` IS NULL)) ORDER BY `freeserver` DESC, `free_ram` DESC " );
2016-02-27 08:19:33 +01:00
$query -> execute ( array ( $resellerID ));
}
2014-09-28 13:47:14 +02:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
$table [ $row [ 'id' ]] = ( $row [ 'description' ] != null and $row [ 'description' ] != '' ) ? $row [ 'ip' ] . ' ' . $row [ 'description' ] : $row [ 'ip' ];
}
return $table ;
}
2015-10-17 12:01:12 +02:00
function getGameQ3List () {
$protocols = array ();
$protocols_path = EASYWIDIR . '/third_party/gameq/GameQ/Protocols/' ;
// Grab the dir with all the classes available
$dir = dir ( $protocols_path );
// Now lets loop the directories
while ( false !== ( $entry = $dir -> read ())) {
if ( ! is_file ( $protocols_path . $entry )) {
continue ;
}
// Figure out the class name
$class_name = ucfirst ( pathinfo ( $entry , PATHINFO_FILENAME ));
try {
require_once ( $protocols_path . $entry );
// Lets get some info on the class
$reflection = new ReflectionClass ( 'GameQ\Protocols\\' . $class_name );
// Check to make sure we can actually load the class
if ( ! $reflection -> IsInstantiable ()) {
continue ;
}
// Load up the class so we can get info
$classGeneratedName = 'GameQ\Protocols\\' . $class_name ;
$class = new $classGeneratedName ;
$ReflectionName = new ReflectionProperty ( get_class ( $class ), 'name' );
$ReflectionName -> setAccessible ( true );
$ReflectionNameLong = new ReflectionProperty ( get_class ( $class ), 'name_long' );
$ReflectionNameLong -> setAccessible ( true );
// Add it to the list
$protocols [ $ReflectionName -> getValue ( $class )] = $ReflectionNameLong -> getValue ( $class );
// Unset the class
unset ( $class , $ReflectionName , $ReflectionNameLong );
} catch ( ReflectionException $e ) {
$errors [] = $e -> getMessage ();
}
}
// Close the directory
unset ( $dir );
return $protocols ;
}
function getGameQ2List () {
$protocols = array ();
// Protocol list code taken from https://github.com/Austinb/GameQ/blob/v2/examples/list.php
$protocols_path = GAMEQ_BASE . 'gameq/protocols/' ;
// Grab the dir with all the classes available
$dir = dir ( $protocols_path );
// Now lets loop the directories
while ( false !== ( $entry = $dir -> read ())) {
if ( ! is_file ( $protocols_path . $entry )) {
continue ;
}
// Figure out the class name
$class_name = 'GameQ_Protocols_' . ucfirst ( pathinfo ( $entry , PATHINFO_FILENAME ));
// Lets get some info on the class
$reflection = new ReflectionClass ( $class_name );
// Check to make sure we can actually load the class
try {
if ( ! $reflection -> IsInstantiable ()) {
continue ;
}
// Load up the class so we can get info
$class = new $class_name ;
// Add it to the list
if ( ! isset ( $protocols [ $class -> name ()])) {
$protocols [ $class -> name ()] = $class -> name_long ();
}
// Unset the class
unset ( $class );
} catch ( ReflectionException $e ) {
$errors [ 'reflection' ] = $e -> getMessage ();
}
}
// Close the directory
unset ( $dir );
return $protocols ;
}
2014-01-26 11:03:52 +01:00
}