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

  1. /*
  2.  *   IRC - Internet Relay Chat, ircd/class.c
  3.  *   Copyright (C) 1990 Darren Reed
  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 1, or (at your option)
  8.  *   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.  
  20. #ifndef    lint
  21. static char sccsid[] = "@(#)class.c    1.4 6/28/93 (C) 1990 Darren Reed";
  22. #endif
  23.  
  24. #include "struct.h"
  25. #include "common.h"
  26. #include "numeric.h"
  27. #include "h.h"
  28.  
  29. #define BAD_CONF_CLASS        -1
  30. #define BAD_PING        -2
  31. #define BAD_CLIENT_CLASS    -3
  32.  
  33. aClass    *classes;
  34.  
  35. int    get_conf_class(aconf)
  36. aConfItem    *aconf;
  37. {
  38.     if ((aconf) && Class(aconf))
  39.         return (ConfClass(aconf));
  40.  
  41.     Debug((DEBUG_DEBUG,"No Class For %s",
  42.           (aconf) ? aconf->name : "*No Conf*"));
  43.  
  44.     return (BAD_CONF_CLASS);
  45.  
  46. }
  47.  
  48. static    int    get_conf_ping(aconf)
  49. aConfItem    *aconf;
  50. {
  51.     if ((aconf) && Class(aconf))
  52.         return (ConfPingFreq(aconf));
  53.  
  54.     Debug((DEBUG_DEBUG,"No Ping For %s",
  55.           (aconf) ? aconf->name : "*No Conf*"));
  56.  
  57.     return (BAD_PING);
  58. }
  59.  
  60.  
  61.  
  62. int    get_client_class(acptr)
  63. aClient    *acptr;
  64. {
  65.     Reg1    Link    *tmp;
  66.     Reg2    aClass    *cl;
  67.     int    i = 0, retc = BAD_CLIENT_CLASS;
  68.  
  69.     if (acptr && !IsMe(acptr)  && (acptr->confs))
  70.         for (tmp = acptr->confs; tmp; tmp = tmp->next)
  71.             {
  72.             if (!tmp->value.aconf ||
  73.                 !(cl = tmp->value.aconf->class))
  74.                 continue;
  75.             if (Class(cl) > retc)
  76.                 retc = Class(cl);
  77.             }
  78.  
  79.     Debug((DEBUG_DEBUG,"Returning Class %d For %s",retc,acptr->name));
  80.  
  81.     return (retc);
  82. }
  83.  
  84. int    get_client_ping(acptr)
  85. aClient    *acptr;
  86. {
  87.     int    ping = 0, ping2;
  88.     aConfItem    *aconf;
  89.     Link    *link;
  90.  
  91.     link = acptr->confs;
  92.  
  93.     if (link)
  94.         while (link)
  95.             {
  96.             aconf = link->value.aconf;
  97.             if (aconf->status & (CONF_CLIENT|CONF_CONNECT_SERVER|
  98.                          CONF_NOCONNECT_SERVER))
  99.                 {
  100.                 ping2 = get_conf_ping(aconf);
  101.                 if ((ping2 != BAD_PING) && ((ping > ping2) ||
  102.                     !ping))
  103.                     ping = ping2;
  104.                  }
  105.             link = link->next;
  106.             }
  107.     else
  108.         {
  109.         ping = PINGFREQUENCY;
  110.         Debug((DEBUG_DEBUG,"No Attached Confs"));
  111.         }
  112.     if (ping <= 0)
  113.         ping = PINGFREQUENCY;
  114.     Debug((DEBUG_DEBUG,"Client %s Ping %d", acptr->name, ping));
  115.     return (ping);
  116. }
  117.  
  118. int    get_con_freq(clptr)
  119. aClass    *clptr;
  120. {
  121.     if (clptr)
  122.         return (ConFreq(clptr));
  123.     else
  124.         return (CONNECTFREQUENCY);
  125. }
  126.  
  127. /*
  128.  * When adding a class, check to see if it is already present first.
  129.  * if so, then update the information for that class, rather than create
  130.  * a new entry for it and later delete the old entry.
  131.  * if no present entry is found, then create a new one and add it in
  132.  * immeadiately after the first one (class 0).
  133.  */
  134. void    add_class(class, ping, confreq, maxli, sendq)
  135. int    class, ping, confreq, maxli;
  136. long    sendq;
  137. {
  138.     aClass *t, *p;
  139.  
  140.     t = find_class(class);
  141.     if ((t == classes) && (class != 0))
  142.         {
  143.         p = (aClass *)make_class();
  144.         NextClass(p) = NextClass(t);
  145.         NextClass(t) = p;
  146.         }
  147.     else
  148.         p = t;
  149.     Debug((DEBUG_DEBUG,
  150.         "Add Class %d: p %x t %x - cf: %d pf: %d ml: %d sq: %l",
  151.         class, p, t, confreq, ping, maxli, sendq));
  152.     Class(p) = class;
  153.     ConFreq(p) = confreq;
  154.     PingFreq(p) = ping;
  155.     MaxLinks(p) = maxli;
  156.     MaxSendq(p) = (sendq > 0) ? sendq : MAXSENDQLENGTH;
  157.     if (p != t)
  158.         Links(p) = 0;
  159. }
  160.  
  161. aClass    *find_class(cclass)
  162. int    cclass;
  163. {
  164.     aClass *cltmp;
  165.  
  166.     for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
  167.         if (Class(cltmp) == cclass)
  168.             return cltmp;
  169.     return classes;
  170. }
  171.  
  172. void    check_class()
  173. {
  174.     Reg1 aClass *cltmp, *cltmp2;
  175.  
  176.     Debug((DEBUG_DEBUG, "Class check:"));
  177.  
  178.     for (cltmp2 = cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp2))
  179.         {
  180.         Debug((DEBUG_DEBUG,
  181.             "Class %d : CF: %d PF: %d ML: %d LI: %d SQ: %ld",
  182.             Class(cltmp), ConFreq(cltmp), PingFreq(cltmp),
  183.             MaxLinks(cltmp), Links(cltmp), MaxSendq(cltmp)));
  184.         if (MaxLinks(cltmp) < 0)
  185.             {
  186.             NextClass(cltmp2) = NextClass(cltmp);
  187.             if (Links(cltmp) <= 0)
  188.                 free_class(cltmp);
  189.             }
  190.         else
  191.             cltmp2 = cltmp;
  192.         }
  193. }
  194.  
  195. void    initclass()
  196. {
  197.     classes = (aClass *)make_class();
  198.  
  199.     Class(FirstClass()) = 0;
  200.     ConFreq(FirstClass()) = CONNECTFREQUENCY;
  201.     PingFreq(FirstClass()) = PINGFREQUENCY;
  202.     MaxLinks(FirstClass()) = MAXIMUM_LINKS;
  203.     MaxSendq(FirstClass()) = MAXSENDQLENGTH;
  204.     Links(FirstClass()) = 0;
  205.     NextClass(FirstClass()) = NULL;
  206. }
  207.  
  208. void    report_classes(sptr)
  209. aClient    *sptr;
  210. {
  211.     Reg1 aClass *cltmp;
  212.  
  213.     for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
  214.         sendto_one(sptr, rpl_str(RPL_STATSYLINE), me.name, sptr->name,
  215.                'Y', Class(cltmp), PingFreq(cltmp), ConFreq(cltmp),
  216.                MaxLinks(cltmp), MaxSendq(cltmp));
  217. }
  218.  
  219. long    get_sendq(cptr)
  220. aClient    *cptr;
  221. {
  222.     Reg1    int    sendq = MAXSENDQLENGTH, retc = BAD_CLIENT_CLASS;
  223.     Reg2    Link    *tmp;
  224.     Reg2    aClass    *cl;
  225.  
  226.     if (cptr && !IsMe(cptr)  && (cptr->confs))
  227.         for (tmp = cptr->confs; tmp; tmp = tmp->next)
  228.             {
  229.             if (!tmp->value.aconf ||
  230.                 !(cl = tmp->value.aconf->class))
  231.                 continue;
  232.             if (Class(cl) > retc)
  233.                 sendq = MaxSendq(cl);
  234.             }
  235.     return sendq;
  236. }
  237.