fix: initialize the tick manager
This commit is contained in:
parent
dcec07be8a
commit
4772e7cdc4
3 changed files with 4 additions and 93 deletions
scripts
|
@ -110,11 +110,6 @@ chmod 0770, $ctrlPath;
|
|||
NOEND => \&gameCancelEnd,
|
||||
"END" => \&gameChangeEnd,
|
||||
SETDEF => \&setDefaultGame,
|
||||
BOTON => \&startBot,
|
||||
BOTOFF => \&killBot,
|
||||
PCPID => \&proxyDetectorID,
|
||||
PCON => \&startProxyDetector,
|
||||
PCOFF => \&stopProxyDetector
|
||||
);
|
||||
|
||||
# Reader loop
|
||||
|
@ -164,14 +159,8 @@ sub start {
|
|||
print "LegacyWorlds - Initialising game\n";
|
||||
print " -> Controller\n";
|
||||
sleep(1);
|
||||
print " -> Proxy detector\n";
|
||||
&sendMessage("PCON");
|
||||
sleep(1);
|
||||
print " -> Ticks manager\n";
|
||||
&sendMessage("TMINIT");
|
||||
sleep(1);
|
||||
print " -> IRC bot\n";
|
||||
&sendMessage("BOTON");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -179,15 +168,9 @@ sub start {
|
|||
|
||||
sub stop {
|
||||
print "LegacyWolrds - Shutting down\n";
|
||||
print " -> IRC bot\n";
|
||||
&sendMessage("BOTOFF");
|
||||
sleep(1);
|
||||
print " -> Ticks manager\n";
|
||||
&sendMessage("TMSTOP");
|
||||
sleep(1);
|
||||
print " -> Proxy detector\n";
|
||||
&sendMessage("PCOFF");
|
||||
sleep(1);
|
||||
print " -> Controller\n";
|
||||
&sendMessage("DIE");
|
||||
exit(0);
|
||||
|
@ -261,7 +244,7 @@ sub tickManagerStart {
|
|||
return if &tickManagerStatus();
|
||||
return unless -f "$Bin/ticks.php";
|
||||
if ($> == 0) {
|
||||
system("su - lwticks");
|
||||
system("runuser -u lwticks -- bash -c 'cd $Bin; php ticks.php'");
|
||||
} else {
|
||||
system("cd $Bin; php ticks.php");
|
||||
}
|
||||
|
@ -277,28 +260,6 @@ sub tickManagerStop {
|
|||
unlink("$ctrlPath/tickManager.pid");
|
||||
}
|
||||
|
||||
#
|
||||
# Start IRC bot
|
||||
#
|
||||
sub startBot {
|
||||
&killBot();
|
||||
if ($> == 0) {
|
||||
system("su - lwbot");
|
||||
} else {
|
||||
system("cd $Bin/../ircbot; (php bot.php &) </dev/null >/dev/null 2>&1");
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Stop IRC bot
|
||||
#
|
||||
sub killBot {
|
||||
return unless -f "$ctrlPath/ircbot.pid";
|
||||
my $pid = `cat $ctrlPath/ircbot.pid`;
|
||||
kill 15, $pid;
|
||||
unlink("$ctrlPath/ircbot.pid");
|
||||
}
|
||||
|
||||
#
|
||||
# Check tick manager status
|
||||
#
|
||||
|
@ -522,53 +483,3 @@ sub setDefaultGame {
|
|||
print NEWCONF @newConf;
|
||||
close(NEWCONF);
|
||||
}
|
||||
|
||||
#
|
||||
# Proxy detector PID update
|
||||
#
|
||||
sub proxyDetectorID {
|
||||
my $pid = shift;
|
||||
return unless $pid;
|
||||
|
||||
open(PIDFILE, "> $ctrlPath/proxyDetector.pid");
|
||||
print PIDFILE "$pid " . time() . "\n";
|
||||
close(PIDFILE);
|
||||
}
|
||||
|
||||
#
|
||||
# Start proxy detector
|
||||
#
|
||||
sub startProxyDetector {
|
||||
return if &proxyDetectorStatus();
|
||||
return unless -f "$Bin/proxycheck.php";
|
||||
if ($> == 0) {
|
||||
system("su - lwproxy");
|
||||
} else {
|
||||
system("cd $Bin; php proxycheck.php");
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Stop proxy detector
|
||||
#
|
||||
sub stopProxyDetector {
|
||||
my $pid;
|
||||
return unless ($pid = &proxyDetectorStatus());
|
||||
kill 15, $pid;
|
||||
unlink("$ctrlPath/proxyDetector.pid");
|
||||
}
|
||||
|
||||
#
|
||||
# Check proxy detector status
|
||||
#
|
||||
sub proxyDetectorStatus {
|
||||
return 0 unless -f "$ctrlPath/proxyDetector.pid";
|
||||
|
||||
open(PIDFILE, "< $ctrlPath/proxyDetector.pid");
|
||||
my $data = <PIDFILE>;
|
||||
close(PIDFILE);
|
||||
|
||||
chomp($data);
|
||||
my ($pid, $time) = split / /, $data;
|
||||
return (time() - $time < 22 ? $pid : 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue