diff --git a/bin/ircd b/bin/ircd index f8d8734..0bc397b 100755 --- a/bin/ircd +++ b/bin/ircd @@ -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; } @@ -282,9 +283,11 @@ 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"; @@ -292,7 +295,10 @@ if(!caller) { 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; }; diff --git a/lib/IRCd/Client.pm b/lib/IRCd/Client.pm index 3471e7e..d238c61 100644 --- a/lib/IRCd/Client.pm +++ b/lib/IRCd/Client.pm @@ -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}; diff --git a/lib/IRCd/Client/Packets.pm b/lib/IRCd/Client/Packets.pm index 4749d40..686f3cb 100644 --- a/lib/IRCd/Client/Packets.pm +++ b/lib/IRCd/Client/Packets.pm @@ -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; diff --git a/lib/IRCd/Constants.pm b/lib/IRCd/Constants.pm index a61c132..6a28add 100644 --- a/lib/IRCd/Constants.pm +++ b/lib/IRCd/Constants.pm @@ -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,