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

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCSComm    }
  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 IRCSComm;
  20. { Handles messages and commands from server }
  21.  
  22. interface
  23. uses
  24.     TCPTypes, TCPStuff, TCPConnections, ApplBase, MsgWindows, IRCGlobals,{}
  25.     IRCAux, IRCPreferences, IRCChannels, CTCP, IRCCommands, IRCNComm,{}
  26.     IRCNotify, IRCIgnore;
  27.  
  28. procedure ServerCommands (var s: string);
  29. { Handle command line got from server }
  30.  
  31. implementation
  32.  
  33. procedure ServerCommands (var s: string);
  34.     var
  35.         i: integer;
  36.         ign: boolean;
  37.         from, target, comm: string[40];
  38.         fromuser: string[60];
  39.         st: string;
  40.         dd: MWHndl;
  41.     begin
  42.         st := '';
  43.         if s[1] = ':' then begin
  44.             i := pos(' ', s);
  45.             fromuser := copy(s, 2, i - 2);
  46.             delete(s, 1, i);
  47.         end
  48.         else
  49.             fromuser := '';
  50.         NextArg(s, comm);
  51.         i := pos(' ', s);
  52.         if i = 0 then
  53.             target := ''
  54.         else begin
  55.             target := copy(s, 1, i - 1);
  56.             delete(s, 1, i)
  57.         end;
  58.         ign := IsIgnored(fromuser, (comm <> 'NOTICE'));
  59.         i := pos('!', fromuser); { nick!user@host -> nick }
  60.         if i > 0 then begin
  61.             from := copy(fromuser, 1, i - 1);
  62.             delete(fromuser, 1, i)
  63.         end
  64.         else begin
  65.             from := fromuser;
  66.             fromuser := '';
  67.         end;
  68.         if s[1] = ':' then
  69.             delete(s, 1, 1);
  70.  
  71.         if (comm[1] >= '0') and (comm[1] <= '9') then begin
  72. {the following line will decode an exact-3-digit-number...}
  73.             if not NumericComm(ord(comm[1]) * 100 + ord(comm[2]) * 10 + ord(comm[3]) - 5328, from, target, s) then begin
  74.                 flushing := false;
  75.             end
  76.             else
  77.                 st := 'NUM';
  78.         end
  79. { These are the commands sent to the client as defined in the IRCII and 2.7 server sources. }
  80. { Commands obsoleted by 2.7 are taken out! }
  81.         else if comm = 'NOTICE' then
  82.             if ign then
  83.                 st := 'I'
  84.             else begin
  85.                 if (from = '') or (from = CurrentServer) then
  86.                     st := s
  87.                 else begin
  88.                     if CurrentServer = '' then begin
  89.                         CurrentServer := from;
  90.                         st := s
  91.                     end
  92.                     else
  93.                         st := concat('-', from, '- ', s);
  94.                 end;
  95.                 if IsChannel(target) then
  96.                     ChannelMsg(target, st)
  97.                 else
  98.                     ChannelMsg(from, st);
  99.             end
  100.         else if comm = 'PRIVMSG' then
  101.             if ign then
  102.                 st := 'I'
  103.             else begin
  104.                 doCTCP(from, target, s);
  105.                 if s = '' then
  106.                     st := 'CTCP'
  107.                 else begin
  108.                     if IsChannel(target) then begin
  109.                         st := concat('<', from, '> ', s);    { Public message }
  110.                         ChannelMsg(target, st);
  111.                     end
  112.                     else if equalstring(target, currentNick, false, true) then begin
  113.                         st := concat('*', from, '* ', s);    { Private message }
  114.                         ChannelMsg(from, st);
  115.                         lastMSG := from;
  116.                     end
  117.                     else begin
  118.                         st := concat('(', from, ')', s);    { possibly bogus? }
  119.                         Message(s);
  120.                     end
  121.                 end
  122.             end
  123.         else if comm = 'JOIN' then
  124.             if EqualString(from, CurrentNick, false, true) then begin
  125.                 currentTarget := s;
  126.                 dd := DoJoin(currentTarget);
  127.                 st := concat('MODE ', s);
  128.                 HandleCommand(st);
  129.                 st := 'J';
  130.             end
  131.             else begin
  132.                 OneNotify(from, true);
  133.                 if fromuser = '' then
  134.                     st := concat('*** ', from, ' has joined ', s)
  135.                 else
  136.                     st := concat('*** ', from, ' [', fromuser, '] has joined ', s);
  137.                 lastMSG := from;
  138.                 ChannelMsg(s, st)
  139.             end
  140.         else if comm = 'PART' then
  141.             if from = currentNick then begin
  142.                 st := s;
  143.                 DoPart(st)
  144.             end
  145.             else begin
  146.                 st := concat('*** ', from, ' has left ', s);
  147.                 ChannelMsg(s, st);
  148.             end
  149.         else if comm = 'QUIT' then begin { is special in that it has no target par }
  150.             OneNotify(from, false);
  151.             if target <> '' then begin
  152.                 if target[1] = ':' then
  153.                     delete(target, 1, 1);
  154.                 target := concat(target, ' ')
  155.             end;
  156.             st := concat('*** Signoff: ', from, ' (', target, s, ')');
  157.             Message(st);
  158.         end
  159.         else if comm = 'WALLOPS' then begin
  160.             st := concat('!', from, '! ', s);
  161.             LineMsg(st);
  162.         end
  163.         else if comm = 'PING' then begin
  164.             st := concat('PONG ', default^^.userloginname, ' ', s);
  165.             HandleCommand(st);
  166.             st := 'PONG'
  167.         end
  168.         else if comm = 'TOPIC' then begin
  169.             st := concat(from, ' has set the topic on ', target, ' to ', s);
  170.             ChannelMsg(target, st)
  171.         end
  172.         else if comm = 'PONG' then begin
  173.             st := concat('*** Got PONG from ', from);
  174.             Message(st);
  175.         end
  176.         else if comm = 'INVITE' then begin
  177.             st := concat('*** ', from, ' invites ', target, ' to channel ', s);
  178.             lastInvite := s;
  179.             ChannelMsg(s, st)
  180.         end
  181.         else if comm = 'NICK' then begin
  182.             if EqualString(from, CurrentNick, false, true) then begin
  183.                 CurrentNick := s;
  184.                 SetMainTitle(CurrentNick);
  185.             end;
  186.             OneNotify(from, false);
  187.             OneNotify(s, true);
  188.             st := concat('*** ', from, ' is now known as ', s);
  189.             Message(st)
  190.         end
  191.         else if comm = 'KILL' then begin
  192.             if pos('.', from) > 0 then begin { server kill }
  193.                 st := concat('*** You have been rejected by ', from, ' (', s, ')');
  194.                 LineMsg(st);
  195.             end
  196.             else begin { operator kill: display alert box & quit }
  197. { Incompletely tested; maybe the path gets too long and the reason isn't displayed }
  198.                 paramtext(from, s, '', '');
  199.                 i := Alert(A_OPKILL, nil);
  200.                 QuitRequest := true
  201.             end;
  202.         end
  203.         else if comm = 'MODE' then begin
  204.             st := concat(from, ' changed the mode on ', target, ' to "', s, '"');
  205.             ChannelMsg(target, st);
  206.         end
  207.         else if comm = 'KICK' then begin
  208.             if EqualString(s, CurrentNick, false, true) then begin
  209.                 st := concat('*** You have been kicked from ', target, ' by ', from);
  210.                 ChannelMsg(target, st);
  211.                 Inactive(target);
  212.             end
  213.             else begin
  214.                 st := concat(from, ' kicked ', s, ' from ', target);
  215.                 ChannelMsg(target, st)
  216.             end
  217.         end
  218.         else if (comm = 'ERROR') or (comm = 'ERROR:') then begin {the : form honors buggy servers }
  219.             st := concat('*** (', from, ') ', target, ' ', s)
  220.         end;
  221.         if st = '' then begin { Display unprocessed commands. }
  222.             st := concat('/', comm, '/', from, '/', target, '/', s, '/');
  223.             LineMsg(st);
  224.         end;
  225.     end;
  226.  
  227. end.