⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a_protocols_irc.pl

📁 AndyChat 是一种用Perl 来编写的多协议的控制台聊天程序。它的目的在于提供一种共同的控制台界面
💻 PL
📖 第 1 页 / 共 5 页
字号:
sub irc__ctcp {  my ($self, $to, $data) = @_;  if (index($data, " ") > -1)  {    $self->ctcp(substr($data, 0, index($data, " ")), $to, substr($data, index($data, " ") + 1));  }  else  {    $self->ctcp($data, $to);  }}sub irc__on_cunknown {  my ($self, $event) = @_;  $tmpnick = $event->nick;  $tmphost = $event->userhost;  $tmpto = ($event->to)[0];  @args = $event->args;  AddLine(whichcontrol($self, 2, $tmpto), "`8>`7>`%> `0" . DoubleQuote($tmpnick) . " `8[`2" . DoubleQuote($tmphost) . "`8] `2requested unknown ctcp " . DoubleQuote("@args") . " `7from " . DoubleQuote($tmpto));}sub irc__on_cdcc {  my ($self, $event) = @_;  $tmpnick = $event->nick;  $tmphost = $event->userhost;  $tmpto = ($event->to)[0];  @args = $event->args;  @args = split(/ /, $args[0]);  my $tmpip = inet_ntoa pack "N", $args[2];  $whichwin = whichcontrol($self, 2, $tmpto);  if ($args[0] eq "CHAT")  {    AddLine($whichwin, $__irc_mark1 . "DCC `7CHAT `8(`7" . DoubleQuote($args[1]) . "`8) `7request from `%" . DoubleQuote($tmpnick) . "`8[`3" . $tmphost . " `7[". $tmpip . ":" . $args[3] . "]`8]");    $whichdcc = irc__newDCC();    $irc__dcc[$whichdcc]{status} = 1;	# 0 = Non-existant, 1 = Requested, 2 = Ack/Connecting, 5 = Established    $irc__dcc[$whichdcc]{name} = $tmpnick;    $irc__dcc[$whichdcc]{filename} = "chat";    $irc__dcc[$whichdcc]{ip} = $args[2];    $irc__dcc[$whichdcc]{port} = $args[3];    $irc__dcc[$whichdcc]{type} = "chat";    $irc__dcc[$whichdcc]{server} = $self;    $irc__dcc[$whichdcc]{lastwin} = $whichwin;    $irc__dcc[$whichdcc]{active} = time();    if ($config{autodccchat})    {      $irc__dcc[$whichdcc]{status} = 2;      $self->new_chat(0, $tmpnick, $args[2], $args[3]);#      $lastwin = $thiswin;#      ClearChatWindow($thiswin);#      $thiswin = newwindow();#      newWindowInit($thiswin, 2);#      RedrawNicks();#      $window[$thiswin]{control} = $window[$lastwin]{control};#      $window[$thiswin]{sortusers} = 1;#      NewMy($thiswin, $lastwin);#      $window[$thiswin]->{channel} = $ppp;#      ReTitle("[" . $window[$thiswin]{channel} . "] Joining...");#      RedrawChanInfo();#      RedrawActivity();    }  }  elsif ($args[0] eq "SEND")  {    $tmpsize = makekbmbgb($args[4], "", 6, 1);#    $tmpsize = $args[4] / 1024;#    if ($tmpsize > 1024)#    {#      $tmpsize = $tmpsize / 1024;#      if (index($tmpsize, ".") < length($tmpsize) - 3)#      {#        $tmpsize = substr($tmpsize, 0, index($tmpsize, ".") + 3);#      }#      $tmpsize = $tmpsize . " mb";#    }#    else#    {#      if (index($tmpsize, ".") < length($tmpsize) - 3)#      {#        $tmpsize = substr($tmpsize, 0, index($tmpsize, ".") + 3);#      }#      $tmpsize = $tmpsize . " kb";#    }    $whichdcc = irc__newDCC();    $irc__dcc[$whichdcc]{status} = 1;    $irc__dcc[$whichdcc]{name} = $tmpnick;    $tmpfile = $args[1];    if (index($tmpfile, "/") > -1)    {      $tmpfile = substr($tmpfile, rindex($tmpfile, "/") + 1);    }    $tmpfile =~ s/\.\./\./;    if (! $tmpfile)    {      irc__killDCC($whichdcc);      AddLine($whichwin, "Invalid DCC SEND from $tmpnick, file was $args[1]", $__irc_mark14);      return;    }    $irc__dcc[$whichdcc]{fakename} = ($config{incoming} || "files/") . ".in." . (int(rand(99999)) + 1) . "." . $tmpfile;    $irc__dcc[$whichdcc]{filename} = ($config{incoming} || "files/") . $tmpfile;    $irc__dcc[$whichdcc]{realfile} = $args[1];    $irc__dcc[$whichdcc]{filesize} = $args[4];    $irc__dcc[$whichdcc]{viewsize} = $tmpsize;    $irc__dcc[$whichdcc]{ip} = $args[2];    $irc__dcc[$whichdcc]{port} = $args[3];    $irc__dcc[$whichdcc]{type} = "get";    $irc__dcc[$whichdcc]{server} = $self;    $irc__dcc[$whichdcc]{lastwin} = $whichwin;    $irc__dcc[$whichdcc]{active} = time();    AddLine($whichwin, $__irc_mark1 . "DCC `7SEND `8(`7" . DoubleQuote($irc__dcc[$whichdcc]{filename}) . "`8) `7request from `%" . DoubleQuote($tmpnick) . "`8[`3" . $tmphost . " `7[" . $tmpip . ":" . $args[3] . "]`8] `7$tmpsize");    if ($config{autodccget})    {      $irc__dcc[$whichdcc]{status} = 2;      $irc__dcc[$whichdcc]{progress} = -s $irc__dcc[$whichdcc]{filename};      if (-s $irc__dcc[$whichdcc]{filename})      {        if (-s $irc__dcc[$whichdcc]{filename} < $irc__dcc[$whichdcc]{filesize})        {          $irc__dcc[$whichdcc]{fh} = new IO::File ">>$irc__dcc[$whichdcc]{filename}";          delete $irc__dcc[$whichdcc]{fakename};          if (defined $irc__dcc[$whichdcc]{fh})          {            $irc__dcc[$whichdcc]{rcontrol} = $self->new_get($tmpnick, $args[1], $args[2], $args[3], $args[4], $irc__dcc[$whichdcc]{fh}, $irc__dcc[$whichdcc]{progress});          }          else          {            AddLine($whichwin, "Error writing to $irc__dcc[$whichdcc]{filename}", $__irc_mark14);            irc__killDCC($whichdcc);          }        }        elsif (-s $irc__dcc[$whichdcc]{filename} > $irc__dcc[$whichdcc]{filesize})        {          AddLine($whichwin, "Local file $irc__dcc[$whichdcc]{filename} bigger than remote??", $__irc_mark14);          irc__killDCC($whichdcc);        }        else        {          AddLine($whichwin, "File sizes match, $irc__dcc[$whichdcc]{filename}", $__irc_mark14);          irc__killDCC($whichdcc);        }      }      else      {        $irc__dcc[$whichdcc]{progress} = 0;        $irc__dcc[$whichdcc]{fh} = new IO::File ">$irc__dcc[$whichdcc]{fakename}";        if (defined $irc__dcc[$whichdcc]{fh})        {          $irc__dcc[$whichdcc]{rcontrol} = $self->new_get($tmpnick, $args[1], $args[2], $args[3], $args[4], $irc__dcc[$whichdcc]{fh}, $irc__dcc[$whichdcc]{progress});        }        else        {          AddLine($whichwin, "Error writing to $irc__dcc[$whichdcc]{filename}", $__irc_mark14);          irc__killDCC($whichdcc);        }      }    }  }}sub irc__on_chat {  my ($self, $event) = @_;  $tmpnick = $event->nick;  $tmpto = ($event->to)[0];  @args = $event->args;  if (! "@args")  {    return;  }  $whichdcc = irc__whichDCC("", $tmpto);  if ($whichdcc)  {    $whichwin = whichcontrol($irc__dcc[$whichdcc]{control}, 2, $tmpnick, 1);    if (! $whichwin) { $whichwin = whichcontrol($irc__dcc[$whichdcc]{control}, 2, "", 1); }    if (! $whichwin) { $whichwin = whichcontrol($irc__dcc[$whichdcc]{server}, 2, "=" . $tmpnick, 1); }    if (! $whichwin) { $whichwin = $irc__dcc[$whichdcc]{lastwin}; }    AddLine($whichwin, "@args", "`8[`0$tmpnick`8(`2dcc`8)] `7");    $irc__dcc[$whichdcc]{progress} = $irc__dcc[$whichdcc]{progress} + length("@args");    if ($leftwindow eq 8) { DrawLeft(8); }  }  else  {    AddLine($whichwin, "@args", "`8[`0$tmpnick`8(`2dcc`8)(error)] `7");  }}sub irc__on_dcc_open {  my ($self, $event) = @_;  $tmpnick = $event->nick;  $tmpto = ($event->to)[0];  @args = $event->args;  $whichdcc = irc__whichDCC($self, $tmpto, "", lc($args[0]));  if (! $whichdcc) { $whichdcc = irc__whichDCC($self, "", $tmpnick, lc($args[0]), 2); } # Dodgy hack! :)  if ($whichdcc)  {    $irc__dcc[$whichdcc]{status} = 5;    $irc__dcc[$whichdcc]{control} = $tmpto;    $irc__dcc[$whichdcc]{started} = time();    $irc__dcc[$whichdcc]{active} = time();    if (! $irc__dcc[$whichdcc]{ip})    {      $irc__dcc[$whichdcc]{ip} = unpack("N", $args[1]->peeraddr());      $irc__dcc[$whichdcc]{port} = $args[1]->peerport();    }    my $tmpip = $args[1]->peerhost();    AddLine($irc__dcc[$whichdcc]{lastwin}, $__irc_mark1 . "DCC `7" . uc($args[0]) . " with `%" . DoubleQuote($tmpnick) . "`8[`3". $tmpip . "`7:" . $irc__dcc[$whichdcc]{port} . "`8] `7established");  }  else  {    AddLine($thiswin, "I am confused! (Couldn't find " . $tmpnick . "'s DCC " . uc($args[0]) . ")", $__irc_mark14);    irc__on_debug($self, $event);  }}sub irc__on_dcc_update {  my ($self, $event) = @_;  $whichdcc = irc__whichDCC($self, ${($event->to)[0]}{_socket});  if ($whichdcc)  {    if ($event->format eq "GET")    {      $irc__dcc[$whichdcc]{progress} = ${($event->args)[0]}{_bin};    }    elsif ($event->format eq "SEND")    {      $irc__dcc[$whichdcc]{progress} = ${($event->args)[0]}{_bout};    }    $irc__dcc[$whichdcc]{active} = time();    if (! $irc__dcc[$whichdcc]{rcontrol}) { $irc__dcc[$whichdcc]{rcontrol} = ($event->to)[0]; }  }  else  {    $tmpnick = ${($event->args)[0]}{_nick};    AddLine($thiswin, "Packet from $tmpnick received on unknown DCC channel", $__irc_mark14);  }}sub irc__on_dcc_close {  my ($self, $event) = @_;  $tmpnick = $event->from;  $tmpto = ($event->to)[0];  $tmptype = $event->format;  $whichdcc = irc__whichDCC($self, $tmpto);  if ($whichdcc)  {    $whichwin = whichcontrol($irc__dcc[$whichdcc]{control}, 2, "", 1);    if (! $whichwin) { $whichwin = whichcontrol($irc__dcc[$whichdcc]{control}, 2, "", 1); }    if (! $whichwin) { $whichwin = $irc__dcc[$whichdcc]{lastwin}; }    if ($tmptype eq "GET")    {      $irc__dcc[$whichdcc]{fh}->close();    }    if ($tmptype eq "GET" || $tmptype eq "SEND")    {      if (($tmptype eq "SEND" && $irc__dcc[$whichdcc]{progress} + $irc__dcc[$whichdcc]{blocksize} < $irc__dcc[$whichdcc]{filesize}) ||          ($tmptype eq "GET" && -s ($irc__dcc[$whichdcc]{fakename} || $irc__dcc[$whichdcc]{filename}) < $irc__dcc[$whichdcc]{filesize}))      {        AddLine($whichwin, $__irc_mark1 . "DCC `7lost $tmptype `4to " . DoubleQuote($tmpnick) . " `8[`7closed`8]");      }#      elsif ($irc__dcc[$whichdcc]{progress} eq $irc__dcc[$whichdcc]{filesize})      else      {        my $tmptime = (time() - $irc__dcc[$whichdcc]{started});        if (index($tmptime, ".") > -1 && index($tmptime, ".") < length($tmptime) - 5)        {          $tmptime = substr($tmptime, 0, index($tmptime, ".") + 4);        }        my $tmpspeed = ($irc__dcc[$whichdcc]{filesize} / (time() - $irc__dcc[$whichdcc]{started})) / 1000;        if (index($tmpspeed, ".") > -1 && index($tmpspeed, ".") < length($tmpspeed) - 3)        {          $tmpspeed = substr($tmpspeed, 0, index($tmpspeed, ".") + 2);        }        if ($tmptype eq "GET") { $tmpwhich = "from" } else { $tmpwhich = "to"; }        AddLine($whichwin, $__irc_mark1 . "DCC `%" . $tmptype . "`7:`2" . DoubleQuote($irc__dcc[$whichdcc]{realfile}) . " `8[`!$irc__dcc[$whichdcc]{viewsize}`8] `7$tmpwhich " . DoubleQuote($tmpnick) . " completed in " . $tmptime . " secs `8(`%" . $tmpspeed . " `7kb/sec`8)");        rename($irc__dcc[$whichdcc]{fakename}, $irc__dcc[$whichdcc]{filename}) if $irc__dcc[$whichdcc]{fakename};      }#      else#      {#        AddLine($whichwin, $__irc_mark1 . "DCC `7overflew $tmptype `4to " . DoubleQuote($tmpnick) . " `8[`7closed`8]");#      }    }    else    {      AddLine($whichwin, $__irc_mark1 . "DCC `7lost $tmptype `4to " . DoubleQuote($tmpnick) . " `8[`7closed`8]");    }    irc__killDCC($whichdcc);  }  else  {    AddLine($whichwin, $__irc_mark1 . "DCC `7lost $tmptype `4to " . DoubleQuote($tmpnick) . " `8[`7Unknown DCC`8]");  }}sub irc__on_cpizza {  my ($self, $event) = @_;  $tmpnick = $event->nick;  $tmpto = ($event->to)[0];  @args = $event->args;  $tmpdata = "@args";  $whichwin = whichcontrol($self, 2, $tmpto);  if (substr($tmpto, 0, 1) ne "#" && substr($tmpto, 0, 1) ne "&")  {    if (substr($tmpdata, 0, 1) eq "#" || substr($tmpdata, 0, 1) eq "&")    {      if (index($tmpdata, " ") > 1)      {        $tmpto = substr($tmpdata, 0, index($tmpdata, " "));        $tmpdata = substr($tmpdata, index($tmpdata, " ") + 1);      }      else      {        $tmpto = $tmpdata;        $tmpdata = "";      }      $whichwin = whichcontrol($self, 2, $tmpto);    }    else    {      AddLine($whichwin, "$tmpnick sent an invalid PIZZA packet - $tmpdata", $__irc_mark14);      return;    }  }#    # Shouldn't be here..  Yes it should :)  My bad :)  Will fix soon :)  Found @ 5.20am . 0328#    irc__on_cunknown($self, $event);#    return;#  }  $tmpnum = FindUser($whichwin, 1, $event->nick);  if ($tmpnum)  {    if ($window[$whichwin]{pizzahost})    {      if ($window[$whichwin]{pizzahost} eq $usr[$whichwin][$tmpnum]{id})      {        NoMorePizzas($whichwin);        AddLine($whichwin, $__irc_mark9 . DoubleQuote($usr[$whichwin][$tmpnum]{name}) . Lang(86));        return;      }      AddLine($whichwin, "Pizza Server Collision!  But we'll ignore this for now...", $__irc_mark14);    }    $window[$whichwin]{pizzahost} = $usr[$whichwin][$tmpnum]{id};    AddLine($whichwin, $__irc_mark9 . DoubleQuote($usr[$whichwin][$tmpnum]{name}) . Lang(85));    if ($window[$whichwin]{pizzas})    {      for ($ap_i = 1; $ap_i <= $window[$whichwin]{pizzas}; $ap_i++)      {        $pizza[$whichwin][$ap_i]{topping} = "";        $pizza[$whichwin][$ap_i]{price} = 0;      }    }    $window[$whichwin]{pizzas} = "";    if ($tmpdata)    {      while ($tmpdata)      {        if (index($tmpdata, " ") eq 4)        {          if ($window[$whichwin]{pizzas})          {            $window[$whichwin]{pizzas}++;          }          else          {            $window[$whichwin]{pizzas} = 1;          }          $tmppizzas = $window[$whichwin]{pizzas};          $pizza[$whichwin][$tmppizzas]{price} = substr($tmpdata, 0, 4);          $tmpdata = substr($tmpdata, 5);          if (index($tmpdata, "|") > 0)          {            $pizza[$whichwin][$tmppizzas]{topping} = substr($tmpdata, 0, index($tmpdata, "|"));            $tmpdata = substr($tmpdata, index($tmpdata, "|") + 1);          }          else          {            $pizza[$whichwin][$tmppizzas]{topping} = $tmpdata;            $tmpdata = "";          }          AddLine($whichwin, Lang(101), Lang(96));          AddLine($whichwin, Lang(96) . "`%$pizza[$whichwin][$tmppizzas]{topping} `7for only `%\$" . mmoney($pizza[$whichwin][$tmppizzas]{price} / 100) . "`7");        }        else        {          AddLine($whichwin, "Died after Pizza No. $window[$whichwin]{pizzas}");          $tmpdata = "";        }      }    }  }  else  {    AddLine($whichwin, "Imaginary user $tmpnick tried to start a Pizza Server..", $__irc_mark14);  }}sub irc__on_cnewpizza {  my ($self, $event) = @_;  $tmpto = ($event->to)[0];  $tmpnick = $event->nick;  $whichwin = whichcontrol($self, 2, $tmpto);  $tmpnum = FindUser($whichwin, 1, $event->nick);  @args = $event->args;  $tmpdata = "@args";  if ($tmpnum)  {    if ($window[$whichwin]{pizzahost})    {      if ($window[$whichwin]{pizzahost} eq $usr[$whichwin][$tmpnum]{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -