Skip to content

Commit

Permalink
Add RULES and fix blank lines in MOTD
Browse files Browse the repository at this point in the history
  • Loading branch information
joshoxe authored and thesamesam committed Aug 24, 2016
1 parent 93a336e commit 7c59dfc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
10 changes: 8 additions & 2 deletions bin/ircd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ sub new {
'pingtimeout' => undef,
'maxtargets' => undef,
};
$self->{motd_path} = shift;
$self->{motd_path} = shift;
$self->{rules_path} = shift;
bless $self, $class;
return $self;
}
Expand Down Expand Up @@ -282,17 +283,22 @@ if(!caller) {
};
my $config = "/etc/cmpctircd/ircd.xml";
my $motd = "/etc/cmpctircd/ircd.motd";
my $rules = "/etc/cmpctircd/ircd.rules";
Getopt::Long::GetOptions(
"config=s" => \$config,
"motd=s" => \$motd,
"rules=s" => \$rules,
);
if(!-e $config) {
die "Config file [$config] does not exist! Please create it or tell me where it is (--config) and try again.\r\n";
}
if(!-e $motd) {
die "MOTD file [$motd] does not exist! Please create it or tell me where it is (--motd) and try again.\r\n";
}
my $ircd = IRCd::Run->new($config, $motd);
if(!-e $rules) {
die "RULES file [$rules] does not exist! Please create it or tell me where it is (--rules) and try again.\r\n";
}
my $ircd = IRCd::Run->new($config, $motd, $rules);
$ircd->setup;
$ircd->run;
};
24 changes: 23 additions & 1 deletion lib/IRCd/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,33 @@ sub motd {
open($motd, "<", $ircd->{motd_path});
my @motd = <$motd>;
$self->{socket}->{sock}->write(":$ircd->{host} " . IRCd::Constants::RPL_MOTDSTART . " $self->{nick} :- $ircd->{host} Message of the Day -\r\n");
$self->{socket}->{sock}->write(":$ircd->{host} " . IRCd::Constants::RPL_MOTD . " $self->{nick} :- " . $_ . "\r\n") foreach(@motd);
for (my $i = 0; $i < @motd; $i++) {
my $line = $motd[$i];
$line =~ s/\r?\n//;
last if ($i + 1 == @motd && $line =~ /^\s*$/);
$self->{socket}->{sock}->write(":$ircd->{host} " . IRCd::Constants::RPL_MOTD . " $self->{nick} :- " . $line . "\r\n");
}
$self->{socket}->{sock}->write(":$ircd->{host} " . IRCd::Constants::RPL_ENDOFMOTD . " $self->{nick} :End of /MOTD command.\r\n");
close($motd);
}

sub rules {
my $self = shift;
my $ircd = $self->{ircd};
my $rules;
open($rules, "<", $ircd->{rules_path});
my @rules = <$rules>;
$self->{socket}->{sock}->write(":$ircd->{host} " . IRCd::Constants::RPL_RULESSTART . " $self->{nick} :- $ircd->{host} server rules -\r\n");
for (my $i = 0; $i < @rules; $i++) {
my $line = $rules[$i];
$line =~ s/\r?\n//;
last if ($i + 1 == @rules && $line =~ /^\s*$/);
$self->{socket}->{sock}->write(":$ircd->{host} " . IRCd::Constants::RPL_RULES . " $self->{nick} :- " . $line . "\r\n");
}
$self->{socket}->{sock}->write(":$ircd->{host} " . IRCd::Constants::RPL_ENDOFRULES . " $self->{nick} :End of RULES command.\r\n");
close($rules);
}

sub checkTimeout {
my $self = shift;
my $ircd = $self->{ircd};
Expand Down
10 changes: 10 additions & 0 deletions lib/IRCd/Client/Packets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,16 @@ sub motd {
$client->motd();
}

sub rules {
my $client = shift;
my $msg = shift;
my $socket = $client->{socket}->{sock};
my $config = $client->{config};
my $ircd = $client->{ircd};
my $mask = $client->getMask(1);

$client->rules();
}

# :card.freenode.net 451 * :You have not registered
1;
4 changes: 4 additions & 0 deletions lib/IRCd/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ use constant {
RPL_ISUPPORT => '005',

RPL_UMODEIS => 221,
RPL_RULES => 232,
RPL_AWAY => 301,
RPL_USERHOST => 302,
RPL_UNAWAY => 305,
RPL_NOWAWAY => 306,
RPL_RULESSTART => 308,
RPL_ENDOFRULES => 309,


RPL_WHOISUSER => 311,
RPL_WHOISSERVER => 312,
Expand Down

0 comments on commit 7c59dfc

Please sign in to comment.