home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / rclesrc.10 / ircle sources / IRCSComm.p < prev    next >
Encoding:
Text File  |  1992-09-06  |  5.8 KB  |  213 lines

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