#!/usr/bin/perl

# CONFIGURE HERE :
#
# your registered nicks in format "nick:pass" space-separated:

my $regnicks = "Zirias:asillypass nick2:anotherpass";

# the servers where your nicks are registered:
# (partial names are matched)

my @servers = qw/mini-chat.ath.cx euirc.net foo.bar.com/;

# END OF CONFIGURATION
#
# do NOT edit below here unless you know perl :)

IRC::print("\cB\cC4AutoGhost \cC7v1.1\cO by \cB\cC10Z\cC3irias\cO loading ...");

IRC::register("AutoGhost","1.1","","");
IRC::add_message_handler("433","mainghost");

my $aghost = 1;

sub mainghost {
  if ($aghost) {
    my $doghost=0;
    my $serv=IRC::get_info(3);
    foreach (@servers) {
      my $th_srv = shift;
      if ($serv =~ /$th_srv/i) { $doghost=1; }
    }
    if ($doghost) {
      my $line = shift;
      $line =~ / ([^ ]*) :/;
      my $tonick = $1;
      if ($regnicks =~ /\b$tonick:([^ ]*)\b/i) {
        my $pass = $1;    
        IRC::print("\cC3\cBAutoGhost :\cO\cC7 hole Nick \cC1$tonick\cC7 zrueck.\cO");
        IRC::send_raw("PRIVMSG NickServ :GHOST $tonick $pass\r\n");
	sleep(1);
        IRC::send_raw("NICK $tonick\r\n");
        IRC::send_raw("PRIVMSG NickServ :IDENTIFY $pass\r\n");
        $aghost=0;
        IRC::add_timeout_handler("3000","activate_aghost");
        return 1;
      } else {
        return 0;
      }
    } else {
      return 0;
    }
  } else {
    return 0;
  }
}

sub activate_aghost {
  $aghost = 1;
}

1;
#end

