Skip to content

Commit

Permalink
Merge pull request #522 from bls1999/tidy-socket-fns
Browse files Browse the repository at this point in the history
Improve server logging, tidy code
  • Loading branch information
jacob-grahn committed Oct 4, 2018
2 parents 9dcde93 + a145436 commit 127e7b3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
31 changes: 14 additions & 17 deletions common/manage_socket/socket_manage_fns.php
Expand Up @@ -36,6 +36,7 @@ function restart_server($script, $address, $port, $salt, $server_id)
{
$pid = read_pid($port);
shut_down_server($pid, $address, $port, $salt);
sleep(1);
start_server($script, $port, $server_id);
}

Expand Down Expand Up @@ -78,11 +79,7 @@ function test_server($script, $address, $port, $salt, $server_id)
output("GOOD - Server #$server_id is running.");
} else {
output("BAD - Bad/No response from server #$server_id.");

$pid = read_pid($port);
shut_down_server($pid, $address, $port, $salt);

start_server($script, $port, $server_id);
restart_server($script, $address, $port, $salt, $server_id);
}

// tell the world
Expand All @@ -93,15 +90,15 @@ function test_server($script, $address, $port, $salt, $server_id)
// starts a server
function start_server($script, $port, $server_id)
{
output("start_server: $script, $port");
output("STARTING SERVER | Script: $script | Port: $port");

$log = '/home/jiggmin/pr2/log/'.$port.'-'.date("Fj-Y-g:ia").'.log';
$log = ROOT_DIR . '/../pr2/log/' . $port . '-' . date("Fj-Y-g:ia") . '.log';
$command = "nohup php $script $server_id > $log & echo $!";
output("Executing command: $command");
$pid = exec($command);

write_pid($pid, $port);
return($pid);
return $pid;
}


Expand All @@ -125,19 +122,19 @@ function shut_down_server($pid, $address, $port, $salt)
}

// tell the world
if ($kill_res === true) {
if (@$kill_res === true) {
output("Shutdown of server running at $address:$port successful.");
} else {
output("Unable to kill port. The server could already be shut down.");
output("A new server can now be started on port $port.");
}
}


// gets the pid file
function get_pid_file($port)
{
$pid_file = '/home/jiggmin/pr2/pid/'.$port.'.txt';
return($pid_file);
$pid_file = ROOT_DIR . '/../pr2/pid/' . $port . '.txt';
return $pid_file;
}


Expand Down Expand Up @@ -165,19 +162,19 @@ function read_pid($port)
if ($handle !== false) {
$pid = fread($handle, 999);
fclose($handle);
output("PID is: $pid \n");
output("PID is: $pid");
} else {
output("The PID file does not exist.");
}
return($pid);
return $pid;
}


// kills a port
function kill_pid($pid)
{
if ($pid != null && $pid != 0 && $pid != '') {
system("kill ".$pid, $k);
if ($pid != null && $pid != 0 && $pid != '' && $pid != false) {
system("kill " . $pid, $k);
$pid = null;
if (!$k) {
return true;
Expand Down Expand Up @@ -274,7 +271,7 @@ function poll_servers($servers, $message, $output = true, $server_ids = array())
}
}

return($results);
return $results;
}


Expand Down
1 change: 1 addition & 0 deletions multiplayer_server/Player.php
Expand Up @@ -598,6 +598,7 @@ public function sendChat($chat_message)
$admin_id,
$ip
);
output("$this->name initiated a server shutdown.");
shutdown_server();
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions multiplayer_server/rooms/Game.php
Expand Up @@ -502,7 +502,7 @@ public function finishRace($player)
$welcome_back_bonus = 1000;
} // level bonus
else {
$level_bonus = $this->appyExpCurve($player, 25 * $time_mod);
$level_bonus = $this->applyExpCurve($player, 25 * $time_mod);

$completed_perc = 0;

Expand Down Expand Up @@ -542,7 +542,7 @@ public function finishRace($player)
$race_stats = $this->finish_array[$i];
if ($race_stats->rank < 100 && PR2SocketServer::$no_prizes === false) {
$exp_gain = ($race_stats->rank+5) * $time_mod;
$exp_gain = ceil($this->appyExpCurve($player, $exp_gain));
$exp_gain = ceil($this->applyExpCurve($player, $exp_gain));
} else {
$exp_gain = 0;
}
Expand Down Expand Up @@ -1049,7 +1049,7 @@ private function getHatStr($player)
}


private function appyExpCurve($player, $exp)
private function applyExpCurve($player, $exp)
{
if ($player->exp_today < 5000) {
$tier = 2.0;
Expand Down

0 comments on commit 127e7b3

Please sign in to comment.