More cleanup.
This commit is contained in:
1 parent
02bb546587
commit
f60a42f28a
1 file changed
+39
-40
@@ -16,7 +16,7 @@ use IO::Select;
|
|||||||
use Class::Unload;
|
use Class::Unload;
|
||||||
use FindBin qw($Bin);
|
use FindBin qw($Bin);
|
||||||
our $Bin = $Bin;
|
our $Bin = $Bin;
|
||||||
BEGIN {
|
BEGIN {
|
||||||
unshift(@INC, "$Bin/../src");
|
unshift(@INC, "$Bin/../src");
|
||||||
|
|
||||||
# Set version information.
|
# Set version information.
|
||||||
@@ -42,7 +42,7 @@ our $VERSION = 3.0.0;
|
|||||||
local $0 = 'auto';
|
local $0 = 'auto';
|
||||||
|
|
||||||
# Check for build files.
|
# Check for build files.
|
||||||
unless (-e "$Bin/../build/os" and -e "$Bin/../build/perl" and -e "$Bin/../build/time" and -e "$Bin/../build/ver") {
|
if (!-e "$Bin/../build/os" or !-e "$Bin/../build/perl" or !-e "$Bin/../build/time" or !-e "$Bin/../build/ver") {
|
||||||
println 'Missing build file(s). Please build Auto before running it.' and exit;
|
println 'Missing build file(s). Please build Auto before running it.' and exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,17 +250,17 @@ alog 'Auto successfully started.';
|
|||||||
# Fork into the background if not in debug mode.
|
# Fork into the background if not in debug mode.
|
||||||
if (!$DEBUG) {
|
if (!$DEBUG) {
|
||||||
println '*** Becoming a daemon...';
|
println '*** Becoming a daemon...';
|
||||||
open(STDIN, q{<}, '/dev/null') or err(2, "Can't read /dev/null: $!", 1);
|
open(STDIN, '<', '/dev/null') or err(2, "Can't read /dev/null: $!", 1);
|
||||||
open(STDOUT, q{>>}, '/dev/null') or err(2, "Can't write to /dev/null: $!", 1);
|
open(STDOUT, '>>', '/dev/null') or err(2, "Can't write to /dev/null: $!", 1);
|
||||||
open(STDERR, q{>>}, '/dev/null') or err(2, "Can't write to /dev/null: $!", 1);
|
open(STDERR, '>>', '/dev/null') or err(2, "Can't write to /dev/null: $!", 1);
|
||||||
$APID = fork();
|
$APID = fork();
|
||||||
unless ($APID == 0) {
|
if ($APID != 0) {
|
||||||
alog "* Successfully forked into the background. Process ID: ".$APID;
|
alog '* Successfully forked into the background. Process ID: '.$APID;
|
||||||
unless (-e "$Bin/auto.pid") {
|
unless (-e "$Bin/auto.pid") {
|
||||||
system("touch $Bin/auto.pid");
|
system("touch $Bin/auto.pid");
|
||||||
}
|
}
|
||||||
open(my $FPID, q{>}, "$Bin/auto.pid") or exit;
|
open(my $FPID, '>', "$Bin/auto.pid") or exit;
|
||||||
print $FPID "$APID\n" or exit;
|
print {$FPID} "$APID\n" or exit;
|
||||||
close $FPID or exit;
|
close $FPID or exit;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -271,22 +271,22 @@ else {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Events.
|
# Events.
|
||||||
API::Std::event_add("on_preconnect");
|
API::Std::event_add('on_preconnect');
|
||||||
|
|
||||||
# Load modules.
|
# Load modules.
|
||||||
if (conf_get("module")) {
|
if (conf_get('module')) {
|
||||||
alog "* Loading modules...";
|
alog '* Loading modules...';
|
||||||
dbug "* Loading modules...";
|
dbug '* Loading modules...';
|
||||||
foreach (@{ (conf_get("module"))[0] }) {
|
foreach (@{ (conf_get('module'))[0] }) {
|
||||||
mod_load($_);
|
mod_load($_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
## Create sockets.
|
## Create sockets.
|
||||||
alog "* Connecting to servers...";
|
alog '* Connecting to servers...';
|
||||||
dbug "* Connecting to servers...";
|
dbug '* Connecting to servers...';
|
||||||
# Get servers from config.
|
# Get servers from config.
|
||||||
my %cservers = conf_get("server");
|
my %cservers = conf_get('server');
|
||||||
# Set the hashes and processes hashes.
|
# Set the hashes and processes hashes.
|
||||||
our (%SOCKET, $SELECT);
|
our (%SOCKET, $SELECT);
|
||||||
$SELECT = IO::Select->new();
|
$SELECT = IO::Select->new();
|
||||||
@@ -295,7 +295,7 @@ my $it = 0;
|
|||||||
foreach my $cskey (keys %cservers) {
|
foreach my $cskey (keys %cservers) {
|
||||||
# Prepare socket data.
|
# Prepare socket data.
|
||||||
my %conndata = (
|
my %conndata = (
|
||||||
Proto => "tcp",
|
Proto => 'tcp',
|
||||||
LocalAddr => $cservers{$cskey}{'bind'}[0],
|
LocalAddr => $cservers{$cskey}{'bind'}[0],
|
||||||
PeerAddr => $cservers{$cskey}{'host'}[0],
|
PeerAddr => $cservers{$cskey}{'host'}[0],
|
||||||
PeerPort => $cservers{$cskey}{'port'}[0],
|
PeerPort => $cservers{$cskey}{'port'}[0],
|
||||||
@@ -317,43 +317,43 @@ foreach my $cskey (keys %cservers) {
|
|||||||
|
|
||||||
# Send PASS if we have one.
|
# Send PASS if we have one.
|
||||||
if (defined $cservers{$cskey}{'pass'}[0]) {
|
if (defined $cservers{$cskey}{'pass'}[0]) {
|
||||||
socksnd($cskey, "PASS :".$cservers{$cskey}{'pass'}[0]) or
|
socksnd($cskey, 'PASS :'.$cservers{$cskey}{'pass'}[0]) or
|
||||||
err(2, "Failed to connect to server: ".$cskey." [".$cservers{$cskey}{'host'}[0].":".$cservers{$cskey}{'port'}[0]."]", 0)
|
err(2, 'Failed to connect to server: '.$cskey.' ['.$cservers{$cskey}{'host'}[0].':'.$cservers{$cskey}{'port'}[0].']', 0)
|
||||||
and next;
|
and next;
|
||||||
}
|
}
|
||||||
API::Std::event_run("on_preconnect", $cskey);
|
API::Std::event_run('on_preconnect', $cskey);
|
||||||
# Send USER and NICK.
|
# Send USER and NICK.
|
||||||
socksnd($cskey, "USER ".$cservers{$cskey}{'ident'}[0]." * * :".$cservers{$cskey}{'realname'}[0]) or
|
socksnd($cskey, 'USER '.$cservers{$cskey}{'ident'}[0].' * * :'.$cservers{$cskey}{'realname'}[0]) or
|
||||||
err(2, "Failed to connect to server: ".$cskey." [".$cservers{$cskey}{'host'}[0].":".$cservers{$cskey}{'port'}[0]."]", 0)
|
err(2, 'Failed to connect to server: '.$cskey.' ['.$cservers{$cskey}{'host'}[0].':'.$cservers{$cskey}{'port'}[0].']', 0)
|
||||||
and next;
|
and next;
|
||||||
API::IRC::nick($cskey, $cservers{$cskey}{'nick'}[0]);
|
API::IRC::nick($cskey, $cservers{$cskey}{'nick'}[0]);
|
||||||
# Add to select.
|
# Add to select.
|
||||||
$SELECT->add($SOCKET{$cskey});
|
$SELECT->add($SOCKET{$cskey});
|
||||||
# Success!
|
# Success!
|
||||||
alog "** Successfully connected to server: ".$cskey;
|
alog '** Successfully connected to server: '.$cskey;
|
||||||
dbug "** Successfully connected to server: ".$cskey;
|
dbug '** Successfully connected to server: '.$cskey;
|
||||||
$it = 1;
|
$it = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Success!
|
# Success!
|
||||||
if ($it) {
|
if ($it) {
|
||||||
alog "** Success: Connected to server(s).";
|
alog '** Success: Connected to server(s).';
|
||||||
dbug "** Success: Connected to server(s).";
|
dbug '** Success: Connected to server(s).';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
err(2, "No server connections.", 1);
|
err(2, 'No server connections.', 1);
|
||||||
}
|
}
|
||||||
undef $it;
|
undef $it;
|
||||||
|
|
||||||
# Create core hooks.
|
# Create core hooks.
|
||||||
API::Std::hook_add("on_uprivmsg", "ctcp_version_reply", \&Core::IRC::version_reply);
|
API::Std::hook_add('on_uprivmsg', 'ctcp_version_reply', \&Core::IRC::version_reply);
|
||||||
# Create core commands.
|
# Create core commands.
|
||||||
API::Std::cmd_add("MODLOAD", 1, "cfunc.modules", \%Core::IRC::HELP_MODLOAD, \&Core::IRC::cmd_modload);
|
API::Std::cmd_add('MODLOAD', 1, 'cfunc.modules', \%Core::IRC::HELP_MODLOAD, \&Core::IRC::cmd_modload);
|
||||||
API::Std::cmd_add("MODUNLOAD", 1, "cfunc.modules", \%Core::IRC::HELP_MODUNLOAD, \&Core::IRC::cmd_modunload);
|
API::Std::cmd_add('MODUNLOAD', 1, 'cfunc.modules', \%Core::IRC::HELP_MODUNLOAD, \&Core::IRC::cmd_modunload);
|
||||||
API::Std::cmd_add("MODRELOAD", 1, "cfunc.modules", \%Core::IRC::HELP_MODRELOAD, \&Core::IRC::cmd_modreload);
|
API::Std::cmd_add('MODRELOAD', 1, 'cfunc.modules', \%Core::IRC::HELP_MODRELOAD, \&Core::IRC::cmd_modreload);
|
||||||
API::Std::cmd_add("SHUTDOWN", 2, "cmd.shutdown", \%Core::IRC::HELP_SHUTDOWN, \&Core::IRC::cmd_shutdown);
|
API::Std::cmd_add('SHUTDOWN', 2, 'cmd.shutdown', \%Core::IRC::HELP_SHUTDOWN, \&Core::IRC::cmd_shutdown);
|
||||||
API::Std::cmd_add("RESTART", 2, "cmd.restart", \%Core::IRC::HELP_RESTART, \&Core::IRC::cmd_restart);
|
API::Std::cmd_add('RESTART', 2, 'cmd.restart', \%Core::IRC::HELP_RESTART, \&Core::IRC::cmd_restart);
|
||||||
API::Std::cmd_add("HELP", 2, 0, \%Core::IRC::HELP_HELP, \&Core::IRC::cmd_help);
|
API::Std::cmd_add('HELP', 2, 0, \%Core::IRC::HELP_HELP, \&Core::IRC::cmd_help);
|
||||||
|
|
||||||
# Infinite while loop.
|
# Infinite while loop.
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -402,7 +402,7 @@ while (1) {
|
|||||||
# Remove the newlines.
|
# Remove the newlines.
|
||||||
chomp $line;
|
chomp $line;
|
||||||
# Debug.
|
# Debug.
|
||||||
dbug $sockid." >> ".$line;
|
dbug $sockid.' >> '.$line;
|
||||||
|
|
||||||
# Parse data.
|
# Parse data.
|
||||||
Parser::IRC::ircparse($sockid, $line);
|
Parser::IRC::ircparse($sockid, $line);
|
||||||
@@ -434,11 +434,10 @@ sub mod_load {
|
|||||||
my ($module) = @_;
|
my ($module) = @_;
|
||||||
|
|
||||||
if (-e "$Bin/../modules/".$module.".pm") {
|
if (-e "$Bin/../modules/".$module.".pm") {
|
||||||
do "$Bin/../modules/".$module.".pm" and return 1 or print $@ and return 0;
|
do "$Bin/../modules/".$module.".pm" and return 1;
|
||||||
}
|
|
||||||
else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user