public function test_replace_shotcodes() { $server_data = array('server_ip' => '127.0.0.1', 'server_port' => '27015', 'screen_name' => 'gameap', 'query_port' => '27016', 'rcon_port' => '27017', 'start_command' => 'start', 'id' => 1337, 'dir' => 'my_server', 'script_path' => '/home/servers', 'start_code' => 'cstrike', 'su_user' => 'nik', 'cpu_limit' => '50', 'ram_limit' => '256', 'net_limit' => '1000', 'aliases' => array('maxplayers'), 'aliases_list' => json_encode(array(array('alias' => 'maxplayers'))), 'aliases_values' => array('maxplayers' => 32)); $this->assertEquals('start', replace_shotcodes('{command}', $server_data)); $this->assertEquals('1337', replace_shotcodes('{id}', $server_data)); $this->assertEquals('/home/servers', replace_shotcodes('{script_path}', $server_data)); $this->assertEquals('my_server', replace_shotcodes('{game_dir}', $server_data)); $this->assertEquals('/home/servers/my_server', replace_shotcodes('{dir}', $server_data)); $this->assertEquals('gameap', replace_shotcodes('{name}', $server_data)); $this->assertEquals('127.0.0.1', replace_shotcodes('{ip}', $server_data)); $this->assertEquals('27015', replace_shotcodes('{port}', $server_data)); $this->assertEquals('27016', replace_shotcodes('{query_port}', $server_data)); $this->assertEquals('27017', replace_shotcodes('{rcon_port}', $server_data)); $this->assertEquals('nik', replace_shotcodes('{user}', $server_data)); $this->assertEquals('32', replace_shotcodes('{maxplayers}', $server_data)); $command = '{dir} {ip} {name} {query_port} {rcon_port} {maxplayers}'; $this->assertEquals('/home/servers/my_server 127.0.0.1 gameap 27016 27017 32', replace_shotcodes($command, $server_data)); }
function send_command($command, &$server_data, $path = false) { $CI =& get_instance(); $CI->load->driver('control'); if (isset($server_data['enabled']) && !$server_data['enabled']) { throw new Exception(lang('server_command_gs_disabled')); } if (isset($server_data['ds_disabled']) && $server_data['ds_disabled']) { throw new Exception(lang('server_command_ds_disabled')); } $command = replace_shotcodes($command, $server_data); $path = $path ? $path : $server_data['script_path']; $CI->control->set_data(array('os' => $server_data['os'], 'path' => $path)); $CI->control->set_driver($server_data['control_protocol']); $CI->control->connect($server_data['control_ip'], $server_data['control_port']); $CI->control->auth($server_data['control_login'], $server_data['control_password']); $result = $CI->control->command($command, $path); return $result; }
private function _replace_shotcodes_in_string($command, &$server_data) { $this->load->helper('ds'); return replace_shotcodes($command, $server_data); }
/** * Отправка ркон команды на сервер */ public function send_command($server_id = false) { if (!$server_id) { show_404(); } if (false == $this->servers->get_server_data($server_id)) { show_404(); } // Получение прав на сервер $this->users->get_server_privileges($this->servers->server_data['id']); if (!$this->users->auth_data['is_admin'] && !$this->users->auth_servers_privileges['RCON_SEND']) { show_404(); } $this->form_validation->set_rules('command', 'rcon command', 'trim|required|max_length[64]|min_length[1]|xss_clean'); if ($this->form_validation->run() == false) { show_404(); } $rcon_command = $this->input->post('command'); if (!$this->servers->server_status($this->servers->server_data['server_ip'], $this->servers->server_data['query_port'])) { $this->output->append_output('Server is down'); return false; } if (strtolower($this->servers->server_data['os']) == 'windows') { // Для Windows отправка через RCON if (!$this->_check_rcon_command($rcon_command)) { show_404(); } $this->load->driver('rcon'); $this->rcon->set_variables($this->servers->server_data['server_ip'], $this->servers->server_data['rcon_port'], $this->servers->server_data['rcon'], $this->servers->servers->server_data['engine'], $this->servers->servers->server_data['engine_version']); if ($this->rcon->connect()) { $this->rcon->command($rcon_command); } else { $this->output->append_output('Rcon connect error'); } } else { // Для Linux отправка прямиков в Screen $this->load->helper('ds'); $command = $this->servers->server_data['script_send_command']; if ($command == '' or $command == './server.sh') { $command = './server.sh send_command {dir} {name} {ip} {port} "{command}" {user}'; } /* На некоторых серверах могут использоваться двойные кавычки*/ //~ $command = str_replace('"', "'", $command); $command = str_replace('{command}', $rcon_command, $command); $send_command = replace_shotcodes($command, $this->servers->server_data); try { send_command($send_command, $this->servers->server_data); } catch (Exception $e) { $this->output->append_output($e->getMessage()); return false; } } }