sub {
use Digest::MD5 qw( md5_hex );
my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+ $what =~ s/\s+$//;
my $nargs = ($what =~ s/ / /g);
if( !$nargs ) {
- $nargs = 1;
+ if( $what =~ /.+/ ) {
+ $nargs = 1;
+ } else {
+ $nargs = 0;
+ }
} else {
- $nargs++;
+ $nargs++;
}
+
if( $nargs < 1 || $nargs > 2 ) {
- $kernel->post( $src, $replypath, "Usage: REGISTER [<name>] <password>", $dest );
+ $kernel->post( $src, $replypath, "Usage: REGISTER [<name>] <password> ($nargs args received)", $dest );
return;
}
-
+
my( $whom, $password );
+
if( $nargs == 1 ) {
$password = $what;
$whom = $who;
( $whom, $password ) = split( / /, $what, 2 );
}
+ if( exists( $heap->{ 'users' }->{ uc( $whom ) } ) ) {
+ $kernel->post( $src, $replypath, "Sorry, but the nick '$whom' is already registered.", $dest );
+ return;
+ }
+
if( $password ) {
$heap->{ 'users' }->{ uc( $whom ) } = md5_hex( $password );
DumpFile( "users.yaml", $heap->{ 'users' } );