home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / IRC client Source / ircle sources / IRCNComm.p < prev    next >
Encoding:
Text File  |  1993-07-19  |  8.5 KB  |  339 lines  |  [TEXT/PJMM]

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCNComm    }
  3. {    Copyright © 1992 Olaf Titz (s_titz@ira.uka.de)    }
  4.  
  5. {    This program is free software; you can redistribute it and/or modify    }
  6. {    it under the terms of the GNU General Public License as published by    }
  7. {    the Free Software Foundation; either version 2 of the License, or    }
  8. {    (at your option) any later version.    }
  9.  
  10. {    This program is distributed in the hope that it will be useful,    }
  11. {    but WITHOUT ANY WARRANTY; without even the implied warranty of    }
  12. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    }
  13. {    GNU General Public License for more details.    }
  14.  
  15. {    You should have received a copy of the GNU General Public License    }
  16. {    along with this program; if not, write to the Free Software    }
  17. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    }
  18.  
  19. unit IRCNComm;
  20. { Handles numeric server messages. }
  21.  
  22. interface
  23. uses
  24.     TCPTypes, TCPStuff, TCPConnections, ApplBase, MsgWindows, {}
  25.     IRCGlobals, IRCAux, IRCChannels, IRCNotify, IRCCommands;
  26.  
  27. function NumericComm (comm: integer; var from, target, rest: string): boolean;
  28. { Handles numeric message comm with arguments from, target, rest }
  29.  
  30. implementation
  31.  
  32. function NumericComm (comm: integer; var from, target, rest: string): boolean;
  33.     var
  34.         s: string;
  35.         s1, s2, s3, s4: string[80];
  36.         l: longint;
  37.         i: integer;
  38.         c: char;
  39.     begin
  40.         NumericComm := true;
  41. { Numerics and their meanings taken originally from IRCII 2.1.something. }
  42. { Adapted to RFC 1459 with many additions… }
  43. { Where there are different formats for 2.6/2.7, this will work with 2.7 as tested. }
  44. { Some 2.8 messages found by experimentation }
  45. { Here messages are sorted by type }
  46.         case comm of
  47.  
  48. { generic line }
  49.             251, 255, { new LUSERS reply }
  50.             305, 306, { AWAY confirmation }
  51.             342, { SUMMON confirmation }
  52.             364, { new LINKS reply }
  53.             371, { new INFO reply }
  54.             372, 375, { new MOTD }
  55.             391, { TIME reply }
  56.             395: { nobody logged in }
  57.                 if not flushing then
  58.                     LineMsg(rest);
  59.  
  60. { generic line with from field }
  61.             200..209, 261, 212..218, 241..244, { TRACE/STATS info }
  62.             302, { new USERHOST reply }
  63.             382: { Rehash }
  64.                 if not flushing then begin
  65.                     s := concat(from, ': ', rest);
  66.                     LineMsg(s)
  67.                 end;
  68.  
  69. { generic error or important message }
  70.             1, 3, { 2.8 intro }
  71.             256..259, { new ADMIN reply }
  72.             381, { Operator status }
  73.             401..414, { no such nick/server/channel; cannot send }
  74.             421, { unknown command }
  75.             431, 432, 436, { bogus nick }
  76.             442, { not on channel }
  77. { 461 need passwd for OPER? }
  78.             461, { need more parameters }
  79.             462, { registration problems }
  80.             467, { Channel key set }
  81.             481..483: { no privileges }
  82.                 begin
  83.                 if rest[1] = ':' then
  84.                     delete(rest, 1, 1);
  85.                 s := concat('*** ', rest);
  86.                 LineMsg(s);
  87.             end;
  88.  
  89. { generic error with from field }
  90.             422..424, { Server config error }
  91.             444..446, { SUMMON/USERS failed }
  92.             465, { Banned }
  93.             471..475, { Cannot join/ set mode }
  94.             491, { No O-line }
  95.             501, 502, { Bad usermode }
  96.             331: { Topic bogosity }
  97.                 begin
  98.                 s := concat('*** (', from, ') ', rest);
  99.                 LineMsg(s)
  100.             end;
  101.  
  102. { Status information }
  103.             4: { 2.8 server telling its name, version etc }
  104.                 begin
  105.                 NextArg(rest, s1);
  106.                 CurrentServer := s1;
  107.                 NextArg(rest, s1);
  108.                 if copy(s1, 1, 3) = '2.8' then
  109.                     serverVersion := SV_28
  110.                 else begin
  111.                     s := concat('*** Server version is unknown to client: ', s1);
  112.                     Message(s)
  113.                 end;
  114.                 NextArg(rest, s1);
  115.                 UpdateStatusLine;
  116.                 s := concat('Mode flags for users are: ', s1, '; for channels are: ', rest);
  117.                 Message(s)
  118.             end;
  119.             301:  { user is away }
  120.                 begin
  121.                 NextArg(rest, s1);
  122.                 s := concat(s1, ' is away (', rest, ')');
  123.                 Message(s)
  124.             end;
  125.             324: { Mode }
  126.                 begin
  127.                 NextArg(rest, s1);
  128.                 if length(rest) > 1 then
  129.                     if (length(rest) > 2) or (rest[2] <> ' ') then begin
  130.                         s := concat('Mode is ', rest);
  131.                         ChannelMsg(s1, s);
  132.                     end
  133.             end;
  134.             332: { Topic }
  135.                 begin
  136.                 s := concat('Topic is: ', rest);
  137.                 Message(s)
  138.             end;
  139.             221: { user mode }
  140.                 begin
  141.                 s := concat('User mode is: ', rest);
  142.                 Message(s)
  143.             end;
  144.  
  145.  
  146. { Verbose command replies }
  147.             211: { STATS L reply }
  148.                 begin
  149.                 NextArg(rest, s1);
  150.                 s := concat('**', s1, '**');
  151.                 LineMsg(s);
  152.                 s := '';
  153.                 for i := 1 to 5 do begin
  154.                     NextArg(rest, s1);
  155.                     s := stringof(s, s1 : 12);
  156.                 end;
  157.                 s := concat(s, ' ', rest);
  158.                 LineMsg(s)
  159.             end;
  160.             252..254: { new LUSERS numbers }
  161.                 begin
  162.                 NextArg(rest, s1);
  163.                 s := concat('There are ', s1, ' ', rest);
  164.                 LineMsg(s);
  165.             end;
  166.             303: { ISON reply }
  167.                 IsonReply(rest);
  168.             352:  { new WHO reply }
  169.                 if not flushing then begin
  170.                     NextArg(rest, s1);
  171.                     if s1 <> 'Channel' then begin
  172.                         NextArg(rest, s2);
  173.                         NextArg(rest, s3);
  174.                         s2 := concat(s2, '@', s3);
  175.                         NextArg(rest, s3);
  176.                         NextArg(rest, s3);
  177.                         NextArg(rest, s4);
  178.                         s := StringOf(s1 : 10, ' ', s3 : 9, s4 : 4, '  ', s2, ' (', rest, ')');
  179.                         ChannelMsg(s1, s)
  180.                     end;
  181.                 end;
  182.             353: { new NAMES reply }
  183.                 if not flushing then begin
  184.                     s := copy(rest, 3, 255);
  185.                     i := pos(' ', s);
  186.                     s1 := copy(s, 1, i - 1);
  187.                     ChannelMsg(s1, s)
  188.                 end;
  189.             311: { whois name info }
  190.                 begin
  191.                 NextArg(rest, s1);
  192.                 NextArg(rest, s2);
  193.                 NextArg(rest, s3);
  194.                 s := concat(s1, ' is ', s2, '@', s3, ' (', copy(rest, 4, 255), ')');
  195.                 Message(s)
  196.             end;
  197.             314: { whowas name info }
  198.                 begin
  199.                 NextArg(rest, s1);
  200.                 NextArg(rest, s2);
  201.                 NextArg(rest, s3);
  202.                 s := concat(s1, ' was ', s2, '@', s3, ' (', copy(rest, 4, 255), ')');
  203.                 Message(s)
  204.             end;
  205.             313: { whois operator }
  206.                 begin
  207.                 NextArg(rest, s1);
  208.                 s := concat(s1, ' ', rest);
  209.                 Message(s)
  210.             end;
  211.             319: { whois channels }
  212.                 begin
  213.                 NextArg(rest, s1);
  214.                 s := concat(s1, ' is on channels ', rest);
  215.                 Message(s)
  216.             end;
  217.             312: { whois host/server }
  218.                 begin
  219.                 NextArg(rest, s1);
  220.                 s := concat('On IRC via server ', rest);
  221.                 Message(s)
  222.             end;
  223.             317: { whois idle }
  224.                 begin
  225.                 NextArg(rest, s1);
  226.                 NextArg(rest, s2);
  227.                 s := concat('idle for ', s2, ' seconds');
  228.                 Message(s)
  229.             end;
  230.             321: { LIST header }
  231.                 begin
  232.                 NextArg(rest, s1);
  233.                 NextArg(rest, s2);
  234.                 s := StringOf(copy(s1, 1, 12) : 12, s2 : 4, '  ', copy(rest, 1, 60));
  235.                 LineMsg(s);
  236.             end;
  237.             322: { LIST entry }
  238.                 if not flushing then begin
  239.                     NextArg(rest, s1);
  240.                     c := s1[1];
  241.                     if (listpriv and listglob and (c = '*')) or (listpub and ((listloc and (c = '&')) or (listglob and (c = '#')))) then begin
  242.                         NextArg(rest, s2);
  243.                         stringtonum(s2, l);
  244.                         if (l >= listmin) and (l <= listmax) then begin
  245.                             if listtop or (rest[0] <> chr(0)) then begin
  246.                                 s := StringOf(copy(s1, 1, 12) : 12, s2 : 4, '  ', copy(rest, 1, 60));
  247.                                 LineMsg(s);
  248.                                 lastWindow := nil; { save from net.terrorists with awfully long topics }
  249.                             end
  250.                         end
  251.                     end
  252.                 end;
  253.             341:  { invite confirmation }
  254.                 begin
  255.                 NextArg(rest, s1);
  256.                 s := concat('Inviting ', s1, ' to channel ', rest);
  257.                 lastInvite := rest;
  258.                 ChannelMsg(rest, s)
  259.             end;
  260.             351: { Server version }
  261.                 begin
  262.                 NextArg(rest, s1);
  263.                 s := concat('Server ', from, ' runs version ', s1);
  264.                 Message(s)
  265.             end;
  266.             367: { Ban list }
  267.                 begin
  268.                 NextArg(rest, s1);
  269.                 s := concat(rest, ' is banned on ', s1);
  270.                 ChannelMsg(s1, s)
  271.             end;
  272.             392, 393: { USERS reply }
  273.                 begin
  274.                 NextArg(rest, s1);
  275.                 NextArg(rest, s2);
  276.                 s := StringOf(copy(s1, 1, 8) : 9, copy(s2, 1, 10) : 12, ' ', rest);
  277.                 LineMsg(s);
  278.             end;
  279.  
  280. { End of list }
  281.             219, 323, 315, 318, 365, 366, 368, 369, 374, 376, 394: { End of list }
  282.                 begin
  283.                 flushing := false;
  284.                 Message(rest);
  285.                 UpdateStatusLine
  286.             end;
  287.  
  288. { Various errors }
  289.             433: { Nick in use }
  290.                 begin
  291.                 NextArg(rest, s1);
  292.                 s := concat('*** Nickname ', s1, ' is in use. You have to choose another.');
  293.                 LineMsg(s);
  294.             end;
  295.             441: { Not in channel }
  296.                 begin
  297.                 NextArg(rest, s1);
  298.                 NextArg(rest, s2);
  299.                 s := concat('*** ', s1, ' is not on channel ', s2);
  300.                 Message(s);
  301.             end;
  302.             443: { unnecessary invitation }
  303.                 begin
  304.                 NextArg(rest, s1);
  305.                 NextArg(rest, s2);
  306.                 s := concat('*** ', s1, ' is already on channel ', s2);
  307.                 ChannelMsg(s2, s);
  308.             end;
  309.             463, 466: { server refuses connection }
  310.                 begin
  311.                 s := concat('*** ', from, ' refuses connection: ', rest);
  312.                 LineMsg(s)
  313.             end;
  314.  
  315. { messages that generate a response }
  316.             451: { not registered }
  317.                 begin
  318.                 s := concat('*** Registration failed, trying again...');
  319.                 LineMsg(s);
  320.                 RegUser
  321.             end;
  322.             464: { Need password - to be changed }
  323.                 begin
  324.                 s := concat('*** ', rest);
  325.                 LineMsg(s)
  326.             end;
  327.  
  328. { ignored messages }
  329.             2, { duplicated intro }
  330.             300: { dummy }
  331.                 begin
  332.             end;
  333.  
  334.             otherwise
  335.                 NumericComm := false
  336.         end;
  337.     end;
  338.  
  339. end.