sub handle_line {
my ($handle, $line) = @_;
my $handler = $handler{$handle};
if ($line eq "quit" || $line eq "exit") {
quit($handle);
} elsif ($handler->{'nickname'} eq "") {
$line =~ s/^\s+//;
$line =~ s/\s+$//;
if (defined($nickname{$line})) {
send_msg($handle, "Nickname is in use. " .
"Try another one.");
} elsif ($line =~ /^\w+$/) {
$handler->{'nickname'} = $line;
$nickname{$line} = $handler;
send_msg($handle, "$line, you are welcome!");
broadcast($line, "has joined the channel.");
} elsif ($line =~ /^$/) {
send_msg($handle, "Your nickname, please.");
} else {
send_msg($handle, "Nicknames should be " .
"alphanumeric, please.");
}
} else {
broadcast($handler->{'nickname'}, $line);
}
}
|