Advertisement
galovikCode

Untitled

Jul 5th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <?php namespace Drivers\Control;
  2.  
  3. use CommandParser;
  4.  
  5. class BungeeControl extends ControlBaseDriver implements ControlDriverInterface
  6. {
  7. private $properties = "";
  8. public function start()
  9. {
  10. //load config
  11. $updatePropertiesCommand = CommandParser::parse("echo \"%properties%\" | cat > %properties-path%", array(
  12. "ram-size"=>$this->server->ram_size,
  13. "properties"=>$this->parseProperties(),
  14. "properties-path"=>$this->path."config.yml",
  15. ));
  16. $this->ssh()->run($updatePropertiesCommand);
  17. //start server itself
  18. $command = CommandParser::parse("java -Xms%ram-size%M -Xmx%ram-size%M -jar server.jar nogui", array(
  19. "ram-size"=>$this->server->ram_size,
  20. ));
  21. return $this->execStart($command[0]);
  22. }
  23.  
  24. public function stop()
  25. {
  26. $cmd = "screen -S ".$this->getScreenSession()." -p 0 -X stuff \"stop\"`echo -ne '\015'`";
  27. return $this->execStop($cmd);
  28. }
  29.  
  30. public function restart()
  31. {
  32. $this->stop();
  33. //sleep(3);
  34. $this->start();
  35. }
  36.  
  37. public function hardStop()
  38. {
  39. return $this->execHardStop();
  40. }
  41.  
  42. private function parseProperties()
  43. {
  44. $propertiesCommand = CommandParser::parse("cat %prop-path%", array(
  45. "prop-path"=>$this->path."config.yml",
  46. ));
  47. $this->ssh()->run($propertiesCommand, function($output){
  48. $this->properties = $output;
  49. });
  50. //$this->properties = preg_replace("/server-ip=(\[0-3\])*/", "server-ip=".$this->server->master->ip, $this->properties);
  51. //$this->properties = preg_replace("/server-port=[0-9]*/", "server-port=".$this->server->port_number, $this->properties);
  52. //$this->properties = preg_replace("/max-players=[0-9]*/", "max-players=".$this->server->slots, $this->properties);
  53. //echo $this->properties;
  54. $properties = array();
  55.  
  56. foreach(explode("\n", $this->properties) as $property)
  57. {
  58. $exploded = explode(":", $property);
  59. $properties[$exploded[0]] = (isset($exploded[1]) ? $exploded[1] : '');
  60. }
  61.  
  62. $properties['- max_players'] = " ".$this->server->slots;
  63. $properties[' host'] = " ".$this->server->master->ip.":".$this->server->port_number;
  64. foreach($properties as $property_key => $value)
  65. {
  66. if( in_array($property_key, $properties) ) {
  67. $returnProperties[] = $property_key.":".$value;
  68. }
  69. }
  70. return implode("\n", $returnProperties);
  71.  
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement