Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php namespace Drivers\Control;
- use CommandParser;
- class BungeeControl extends ControlBaseDriver implements ControlDriverInterface
- {
- private $properties = "";
- public function start()
- {
- //load config
- $updatePropertiesCommand = CommandParser::parse("echo \"%properties%\" | cat > %properties-path%", array(
- "ram-size"=>$this->server->ram_size,
- "properties"=>$this->parseProperties(),
- "properties-path"=>$this->path."config.yml",
- ));
- $this->ssh()->run($updatePropertiesCommand);
- //start server itself
- $command = CommandParser::parse("java -Xms%ram-size%M -Xmx%ram-size%M -jar server.jar nogui", array(
- "ram-size"=>$this->server->ram_size,
- ));
- return $this->execStart($command[0]);
- }
- public function stop()
- {
- $cmd = "screen -S ".$this->getScreenSession()." -p 0 -X stuff \"stop\"`echo -ne '\015'`";
- return $this->execStop($cmd);
- }
- public function restart()
- {
- $this->stop();
- //sleep(3);
- $this->start();
- }
- public function hardStop()
- {
- return $this->execHardStop();
- }
- private function parseProperties()
- {
- $propertiesCommand = CommandParser::parse("cat %prop-path%", array(
- "prop-path"=>$this->path."config.yml",
- ));
- $this->ssh()->run($propertiesCommand, function($output){
- $this->properties = $output;
- });
- //$this->properties = preg_replace("/server-ip=(\[0-3\])*/", "server-ip=".$this->server->master->ip, $this->properties);
- //$this->properties = preg_replace("/server-port=[0-9]*/", "server-port=".$this->server->port_number, $this->properties);
- //$this->properties = preg_replace("/max-players=[0-9]*/", "max-players=".$this->server->slots, $this->properties);
- //echo $this->properties;
- $properties = array();
- foreach(explode("\n", $this->properties) as $property)
- {
- $exploded = explode(":", $property);
- $properties[$exploded[0]] = (isset($exploded[1]) ? $exploded[1] : '');
- }
- $properties['- max_players'] = " ".$this->server->slots;
- $properties[' host'] = " ".$this->server->master->ip.":".$this->server->port_number;
- foreach($properties as $property_key => $value)
- {
- if( in_array($property_key, $properties) ) {
- $returnProperties[] = $property_key.":".$value;
- }
- }
- return implode("\n", $returnProperties);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement