Author: Bleep <helveytw@home.com>
[ircu2.10.12-pk.git] / ircd / client.c
1 /*
2  * IRC - Internet Relay Chat, ircd/client.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  * $Id$
20  */
21 #include "client.h"
22 #include "class.h"
23 #include "ircd.h"
24 #include "ircd_reply.h"
25 #include "list.h"
26 #include "numeric.h"
27 #include "s_conf.h"
28 #include "s_debug.h"
29 #include "send.h"
30 #include "struct.h"
31
32 #include <assert.h>
33
34 #define BAD_PING                ((unsigned int)-2)
35
36 /*
37  * client_get_ping
38  * returns shortest ping time in attached server or client conf
39  * classes or PINGFREQUENCY
40  */
41 unsigned int client_get_ping(const struct Client* acptr)
42 {
43   unsigned int     ping = 0;
44   unsigned int     tmp;
45   struct ConfItem* aconf;
46   struct SLink*    link;
47
48   for (link = acptr->confs; link; link = link->next) {
49     aconf = link->value.aconf;
50     if (aconf->status & (CONF_CLIENT | CONF_SERVER)) {
51       tmp = get_conf_ping(aconf);
52       if ((tmp != BAD_PING) && ((ping > tmp) || !ping))
53         ping = tmp;
54     }
55   }
56   if (0 == ping)
57     ping = PINGFREQUENCY;
58
59   Debug((DEBUG_DEBUG, "Client %s Ping %d", acptr->name, ping));
60   return (ping);
61 }
62
63 #if 0
64 #define BAD_CONF_CLASS          ((unsigned int)-1)
65 #define BAD_CLIENT_CLASS        ((unsigned int)-3)
66
67 unsigned int get_client_class(struct Client *acptr)
68 {
69   struct SLink *tmp;
70   struct ConnectionClass *cl;
71   unsigned int retc = BAD_CLIENT_CLASS;
72
73   if (acptr && !IsMe(acptr) && (acptr->confs))
74     for (tmp = acptr->confs; tmp; tmp = tmp->next)
75     {
76       if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
77         continue;
78       if (ConClass(cl) > retc || retc == BAD_CLIENT_CLASS)
79         retc = ConClass(cl);
80     }
81
82   Debug((DEBUG_DEBUG, "Returning Class %d For %s", retc, acptr->name));
83
84   return (retc);
85 }
86
87 unsigned int get_sendq(struct Client *cptr)
88 {
89   assert(0 != cptr);
90   assert(0 != cptr->local);
91
92   if (cptr->max_sendq)
93     return cptr->max_sendq;
94
95   else if (cptr->confs) {
96     struct SLink*     tmp;
97     struct ConnectionClass* cl;
98
99     for (tmp = cptr->confs; tmp; tmp = tmp->next) {
100       if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
101         continue;
102       if (ConClass(cl) != BAD_CLIENT_CLASS) {
103         cptr->max_sendq = MaxSendq(cl);
104         return cptr->max_sendq;
105       }
106     }
107   }
108   return DEFAULTMAXSENDQLENGTH;
109 }
110 #endif