Skip to content
Browse files

Working on player list

  • Loading branch information...
1 parent 7f65ea1 commit 397b4dc63f180f67bf36d84f7c1ffdfcbedeed1d @samholman committed Aug 7, 2011
View
1 application/configs/application.ini-dist
@@ -10,6 +10,7 @@ resources.frontController.params.displayExceptions = 0
minecraft.serverPath = "/opt/local/minecraft_server.jar"
minecraft.worldPath = "/opt/local/minecraft"
+regenerateTime = 300
c10t.path = "/home/tom/software/c10t/c10t"
View
69 application/models/Server.php
@@ -19,6 +19,9 @@ class Application_Model_Server
array('pipe', 'w'),
array('pipe', 'w'),
);
+
+ private static
+ $_playersArray;
/**
* Returns whether or not the Minecraft server is running
@@ -79,15 +82,18 @@ public function start()
if ($this->isRunning())
{
- register_shutdown_function(array('Application_Model_Server', 'shutdownHandler'));
+ touch(APPLICATION_PATH . self::COMMANDS_FILE);
+ touch(APPLICATION_PATH . self::RESULTS_FILE);
stream_set_blocking($this->_pipes[0], false);
stream_set_blocking($this->_pipes[1], false);
stream_set_blocking($this->_pipes[2], false);
+ $timer = 0;
+
while (true)
{
- sleep(1);
+ //sleep(1);
$commands = file(APPLICATION_PATH . self::COMMANDS_FILE);
file_put_contents(APPLICATION_PATH . self::COMMANDS_FILE, '');
@@ -104,6 +110,16 @@ public function start()
if (!empty($output)) {
file_put_contents(APPLICATION_PATH . self::RESULTS_FILE, trim($output));
}
+
+ if (!$timer) {
+ exec('php ' . APPLICATION_PATH . '/../regenerate.php');
+ }
+
+ $timer++;
+
+ if ($timer >= Zend_Registry::get('config')->get('regenerateTime')) {
+ $timer = 0;
+ }
}
return true;
@@ -128,24 +144,15 @@ public function stop()
//$status = proc_get_status($this->_process);
//exec('kill ' . $status['pid']);
- self::shutdownHandler();
+ unlink(APPLICATION_PATH . self::COMMANDS_FILE);
+ unlink(APPLICATION_PATH . self::RESULTS_FILE);
+ unlink(APPLICATION_PATH . self::PID_FILE);
+
return proc_close($this->_process);
}
}
/**
- * Delete the temp files
- *
- * @return void
- */
- public static function shutdownHandler()
- {
- unlink(APPLICATION_PATH . self::COMMANDS_FILE);
- unlink(APPLICATION_PATH . self::RESULTS_FILE);
- unlink(APPLICATION_PATH . self::PID_FILE);
- }
-
- /**
* Runs a command on the server process and returns the result
*
* @param string $command
@@ -175,30 +182,36 @@ public function runCommand($command)
*/
public function getOnlinePlayers()
{
- $playersArray = false;
-
- do
+ if (!is_array(self::$_playersArray))
{
- $players = $this->runCommand('list');
+ $result = false;
+ self::$_playersArray = array();
- if (substr($players, 27, 18) == 'Connected players:')
+ do
{
- $players = substr($players, 46);
- $playersArray = explode(',', $players);
+ $players = $this->runCommand('list');
- foreach ($playersArray as $key => &$player)
+ if (substr($players, 27, 18) == 'Connected players:')
{
- $player = trim($player);
+ $result = true;
+
+ $players = substr($players, 46);
+ self::$_playersArray = explode(',', $players);
- if (empty($player)) {
- unset($playersArray[$key]);
+ foreach (self::$_playersArray as $key => &$player)
+ {
+ $player = trim($player);
+
+ if (empty($player)) {
+ unset(self::$_playersArray[$key]);
+ }
}
}
}
+ while (!$result);
}
- while (!is_array($playersArray));
- return $playersArray;
+ return self::$_playersArray;
}
/**
View
4 map.php → regenerate.php
@@ -5,5 +5,5 @@
$application->bootstrap();
-$server = new Application_Model_Map();
-$server->regenerate();
+$map = new Application_Model_Map();
+$map->regenerate();
View
BIN tmp/map.png
Deleted file not rendered

0 comments on commit 397b4dc

Please sign in to comment.
Something went wrong with that request. Please try again.