Commit c2fe5063 authored by Astor Bizard's avatar Astor Bizard
Browse files

Merge branch 'dev' into 'test'

Execution server choice now prioritizes local servers.

See merge request !16
parents dccff423 3d6d41be
......@@ -143,26 +143,41 @@ class vpl_jailserver_manager {
*
* @param string $localserverlisttext=''
* List of local server in text
* @param bool $shuffle
* Whether to shuffle servers or not (local servers will always be before global ones).
* @return array of servers
*/
static public function get_server_list($localserverlisttext) {
static public function get_server_list($localserverlisttext, $shuffle = false) {
$plugincfg = get_config('mod_vpl');
$nllocal = vpl_detect_newline( $localserverlisttext );
$nlglobal = vpl_detect_newline( $plugincfg->jail_servers );
$tempserverlist = array_merge( explode( $nllocal, $localserverlisttext ), explode( $nlglobal, $plugincfg->jail_servers ) );
$serverlist = array ();
// Clean temp server list and search for 'end_of_jails'.
foreach ($tempserverlist as $server) {
$server = trim( $server );
if ($server > '' && $server [0] != '#') {
if (strtolower( $server ) == 'end_of_jails') {
break;
} else {
$serverlist [] = $server;
$allservers = array();
foreach(array(explode( $nllocal, $localserverlisttext ), explode( $nlglobal, $plugincfg->jail_servers )) as $servers) {
$subserverslist = array ();
$endofjails = false;
// Clean server list and search for 'end_of_jails'.
foreach ($servers as $server) {
$server = trim( $server );
if ($server > '' && $server [0] != '#') {
if (strtolower( $server ) == 'end_of_jails') {
$endofjails = true;
break;
} else {
$subserverslist [] = $server;
}
}
}
if ($shuffle) {
shuffle($subserverslist);
}
$allservers = array_merge($allservers, $subserverslist);
if ($endofjails) {
break;
}
}
return $serverlist;
return $allservers;
}
/**
......@@ -180,8 +195,7 @@ class vpl_jailserver_manager {
if (! function_exists( 'xmlrpc_encode_request' )) {
throw new Exception( 'PHP XMLRPC required' );
}
$serverlist = self::get_server_list( $localserverlisttext );
shuffle( $serverlist );
$serverlist = self::get_server_list( $localserverlisttext, true );
$data = new stdClass();
$data->maxmemory = $maxmemory;
$requestready = xmlrpc_encode_request( 'available', $data, array ( 'encoding' => 'UTF-8' ) );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment