2 * IRC - Internet Relay Chat, ircd/client.c
3 * Copyright (C) 1990 Darren Reed
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)
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.
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.
24 #include "ircd_reply.h"
34 #define BAD_PING ((unsigned int)-2)
36 unsigned int client_get_ping(const struct Client* acptr)
38 unsigned int ping = 0;
40 struct ConfItem* aconf;
43 for (link = acptr->confs; link; link = link->next) {
44 aconf = link->value.aconf;
45 if (aconf->status & (CONF_CLIENT | CONF_SERVER)) {
46 tmp = get_conf_ping(aconf);
47 if ((tmp != BAD_PING) && ((ping > tmp) || !ping))
54 Debug((DEBUG_DEBUG, "Client %s Ping %d", acptr->name, ping));
59 #define BAD_CONF_CLASS ((unsigned int)-1)
60 #define BAD_CLIENT_CLASS ((unsigned int)-3)
62 unsigned int get_conf_class(struct ConfItem *aconf)
64 if ((aconf) && (aconf->confClass))
65 return (ConfClass(aconf));
67 Debug((DEBUG_DEBUG, "No Class For %s", (aconf) ? aconf->name : "*No Conf*"));
69 return (BAD_CONF_CLASS);
73 static unsigned int get_conf_ping(struct ConfItem *aconf)
75 if ((aconf) && (aconf->confClass))
76 return (ConfPingFreq(aconf));
78 Debug((DEBUG_DEBUG, "No Ping For %s", (aconf) ? aconf->name : "*No Conf*"));
83 unsigned int get_client_class(struct Client *acptr)
87 unsigned int retc = BAD_CLIENT_CLASS;
89 if (acptr && !IsMe(acptr) && (acptr->confs))
90 for (tmp = acptr->confs; tmp; tmp = tmp->next)
92 if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
94 if (ConClass(cl) > retc || retc == BAD_CLIENT_CLASS)
98 Debug((DEBUG_DEBUG, "Returning Class %d For %s", retc, acptr->name));
102 unsigned int get_con_freq(struct ConfClass * clptr)
105 return (ConFreq(clptr));
107 return (CONNECTFREQUENCY);
111 * When adding a class, check to see if it is already present first.
112 * if so, then update the information for that class, rather than create
113 * a new entry for it and later delete the old entry.
114 * if no present entry is found, then create a new one and add it in
115 * immeadiately after the first one (class 0).
117 void add_class(unsigned int conClass, unsigned int ping, unsigned int confreq,
118 unsigned int maxli, unsigned int sendq)
120 struct ConfClass *t, *p;
122 t = find_class(conClass);
123 if ((t == classes) && (conClass != 0))
125 p = (struct ConfClass *) make_class();
126 NextClass(p) = NextClass(t);
131 Debug((DEBUG_DEBUG, "Add Class %u: p %p t %p - cf: %u pf: %u ml: %u sq: %d",
132 conClass, p, t, confreq, ping, maxli, sendq));
133 ConClass(p) = conClass;
134 ConFreq(p) = confreq;
137 MaxSendq(p) = (sendq > 0) ? sendq : DEFAULTMAXSENDQLENGTH;
142 struct ConfClass *find_class(unsigned int cclass)
144 struct ConfClass *cltmp;
146 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
147 if (ConClass(cltmp) == cclass)
152 void check_class(void)
154 struct ConfClass *cltmp, *cltmp2;
156 Debug((DEBUG_DEBUG, "Class check:"));
158 for (cltmp2 = cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp2))
161 "Class %d : CF: %d PF: %d ML: %d LI: %d SQ: %d",
162 ConClass(cltmp), ConFreq(cltmp), PingFreq(cltmp),
163 MaxLinks(cltmp), Links(cltmp), MaxSendq(cltmp)));
164 if (IsMarkedDelete(cltmp))
166 NextClass(cltmp2) = NextClass(cltmp);
167 if (Links(cltmp) == 0)
177 classes = (struct ConfClass *) make_class();
179 ConClass(FirstClass()) = 0;
180 ConFreq(FirstClass()) = CONNECTFREQUENCY;
181 PingFreq(FirstClass()) = PINGFREQUENCY;
182 MaxLinks(FirstClass()) = MAXIMUM_LINKS;
183 MaxSendq(FirstClass()) = DEFAULTMAXSENDQLENGTH;
184 Links(FirstClass()) = 0;
185 NextClass(FirstClass()) = NULL;
188 void report_classes(struct Client *sptr)
190 struct ConfClass *cltmp;
192 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
193 send_reply(sptr, RPL_STATSYLINE, 'Y', ConClass(cltmp), PingFreq(cltmp),
194 ConFreq(cltmp), MaxLinks(cltmp), MaxSendq(cltmp));
197 unsigned int get_sendq(struct Client *cptr)
200 assert(0 != cptr->local);
203 return cptr->max_sendq;
205 else if (cptr->confs) {
207 struct ConfClass* cl;
209 for (tmp = cptr->confs; tmp; tmp = tmp->next) {
210 if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
212 if (ConClass(cl) != BAD_CLIENT_CLASS) {
213 cptr->max_sendq = MaxSendq(cl);
214 return cptr->max_sendq;
218 return DEFAULTMAXSENDQLENGTH;