home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / other / irc / ircd / s_numeric.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-14  |  3.6 KB  |  119 lines

  1. /************************************************************************
  2.  *   IRC - Internet Relay Chat, ircd/s_numeric.c
  3.  *   Copyright (C) 1990 Jarkko Oikarinen
  4.  *
  5.  *   Numerous fixes by Markku Savela
  6.  *
  7.  *   This program is free software; you can redistribute it and/or modify
  8.  *   it under the terms of the GNU General Public License as published by
  9.  *   the Free Software Foundation; either version 1, or (at your option)
  10.  *   any later version.
  11.  *
  12.  *   This program is distributed in the hope that it will be useful,
  13.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *   GNU General Public License for more details.
  16.  *
  17.  *   You should have received a copy of the GNU General Public License
  18.  *   along with this program; if not, write to the Free Software
  19.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. #ifndef lint
  23. static  char sccsid[] = "@(#)s_numeric.c    2.14 1/30/94 (C) 1988 University of Oulu, \
  24. Computing Center and Jarkko Oikarinen";
  25. #endif
  26.  
  27. #include "struct.h"
  28. #include "common.h"
  29. #include "sys.h" 
  30. #include "numeric.h"
  31. #include "h.h"
  32.  
  33. static char buffer[1024];
  34.  
  35. /*
  36. ** DoNumeric (replacement for the old do_numeric)
  37. **
  38. **    parc    number of arguments ('sender' counted as one!)
  39. **    parv[0]    pointer to 'sender' (may point to empty string) (not used)
  40. **    parv[1]..parv[parc-1]
  41. **        pointers to additional parameters, this is a NULL
  42. **        terminated list (parv[parc] == NULL).
  43. **
  44. ** *WARNING*
  45. **    Numerics are mostly error reports. If there is something
  46. **    wrong with the message, just *DROP* it! Don't even think of
  47. **    sending back a neat error message -- big danger of creating
  48. **    a ping pong error message...
  49. */
  50. int    do_numeric(numeric, cptr, sptr, parc, parv)
  51. int    numeric;
  52. aClient *cptr, *sptr;
  53. int    parc;
  54. char    *parv[];
  55. {
  56.     aClient *acptr;
  57.     aChannel *chptr;
  58.     char    *nick, *p;
  59.     int    i;
  60.  
  61.     if (parc < 1 || !IsServer(sptr))
  62.         return 0;
  63.     /* Remap low number numerics. */
  64.     if (numeric < 100)
  65.         numeric += 100;
  66.     /*
  67.     ** Prepare the parameter portion of the message into 'buffer'.
  68.     ** (Because the buffer is twice as large as the message buffer
  69.     ** for the socket, no overflow can occur here... ...on current
  70.     ** assumptions--bets are off, if these are changed --msa)
  71.     ** Note: if buffer is non-empty, it will begin with SPACE.
  72.     */
  73.     buffer[0] = '\0';
  74.     if (parc > 1)
  75.         {
  76.         for (i = 2; i < (parc - 1); i++)
  77.             {
  78.             (void)strcat(buffer, " ");
  79.             (void)strcat(buffer, parv[i]);
  80.             }
  81.         (void)strcat(buffer, " :");
  82.         (void)strcat(buffer, parv[parc-1]);
  83.         }
  84.     for (; (nick = strtoken(&p, parv[1], ",")); parv[1] = NULL)
  85.         {
  86.         if ((acptr = find_client(nick, (aClient *)NULL)))
  87.             {
  88.             /*
  89.             ** Drop to bit bucket if for me...
  90.             ** ...one might consider sendto_ops
  91.             ** here... --msa
  92.             ** And so it was done. -avalon
  93.             ** And regretted. Dont do it that way. Make sure
  94.             ** it goes only to non-servers. -avalon
  95.             ** Check added to make sure servers don't try to loop
  96.             ** with numerics which can happen with nick collisions.
  97.             ** - Avalon
  98.             */
  99.             if (!IsMe(acptr) && IsPerson(acptr))
  100.                 sendto_prefix_one(acptr, sptr,":%s %d %s%s",
  101.                     parv[0], numeric, nick, buffer);
  102.             else if (IsServer(acptr) && acptr->from != cptr)
  103.                 sendto_prefix_one(acptr, sptr,":%s %d %s%s",
  104.                     parv[0], numeric, nick, buffer);
  105.             }
  106.         else if ((acptr = find_server(nick, (aClient *)NULL)))
  107.             {
  108.             if (!IsMe(acptr) && acptr->from != cptr)
  109.                 sendto_prefix_one(acptr, sptr,":%s %d %s%s",
  110.                     parv[0], numeric, nick, buffer);
  111.             }
  112.         else if ((chptr = find_channel(nick, (aChannel *)NULL)))
  113.             sendto_channel_butone(cptr,sptr,chptr,":%s %d %s%s",
  114.                           parv[0],
  115.                           numeric, chptr->chname, buffer);
  116.         }
  117.     return 0;
  118. }
  119.