2 * IRC - Internet Relay Chat, ircd/class.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_CONF_CLASS ((unsigned int)-1)
35 #define BAD_PING ((unsigned int)-2)
36 #define BAD_CLIENT_CLASS ((unsigned int)-3)
38 struct ConfClass *classes;
40 unsigned int get_conf_class(struct ConfItem *aconf)
42 if ((aconf) && (aconf->confClass))
43 return (ConfClass(aconf));
45 Debug((DEBUG_DEBUG, "No Class For %s", (aconf) ? aconf->name : "*No Conf*"));
47 return (BAD_CONF_CLASS);
51 static unsigned int get_conf_ping(struct ConfItem *aconf)
53 if ((aconf) && (aconf->confClass))
54 return (ConfPingFreq(aconf));
56 Debug((DEBUG_DEBUG, "No Ping For %s", (aconf) ? aconf->name : "*No Conf*"));
61 unsigned int get_client_class(struct Client *acptr)
65 unsigned int retc = BAD_CLIENT_CLASS;
67 if (acptr && !IsMe(acptr) && (acptr->confs))
68 for (tmp = acptr->confs; tmp; tmp = tmp->next)
70 if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
72 if (ConClass(cl) > retc || retc == BAD_CLIENT_CLASS)
76 Debug((DEBUG_DEBUG, "Returning Class %d For %s", retc, acptr->name));
81 unsigned int get_client_ping(struct Client *acptr)
83 unsigned int ping = 0;
85 struct ConfItem *aconf;
92 aconf = link->value.aconf;
93 if (aconf->status & (CONF_CLIENT | CONF_SERVER)) {
94 ping2 = get_conf_ping(aconf);
95 if ((ping2 != BAD_PING) && ((ping > ping2) || !ping))
102 ping = PINGFREQUENCY;
103 Debug((DEBUG_DEBUG, "No Attached Confs for: %s", acptr->name));
106 ping = PINGFREQUENCY;
107 Debug((DEBUG_DEBUG, "Client %s Ping %d", acptr->name, ping));
111 unsigned int get_con_freq(struct ConfClass * clptr)
114 return (ConFreq(clptr));
116 return (CONNECTFREQUENCY);
120 * When adding a class, check to see if it is already present first.
121 * if so, then update the information for that class, rather than create
122 * a new entry for it and later delete the old entry.
123 * if no present entry is found, then create a new one and add it in
124 * immeadiately after the first one (class 0).
126 void add_class(unsigned int conClass, unsigned int ping, unsigned int confreq,
127 unsigned int maxli, unsigned int sendq)
129 struct ConfClass *t, *p;
131 t = find_class(conClass);
132 if ((t == classes) && (conClass != 0))
134 p = (struct ConfClass *) make_class();
135 NextClass(p) = NextClass(t);
140 Debug((DEBUG_DEBUG, "Add Class %u: p %p t %p - cf: %u pf: %u ml: %u sq: %d",
141 conClass, p, t, confreq, ping, maxli, sendq));
142 ConClass(p) = conClass;
143 ConFreq(p) = confreq;
146 MaxSendq(p) = (sendq > 0) ? sendq : DEFAULTMAXSENDQLENGTH;
151 struct ConfClass *find_class(unsigned int cclass)
153 struct ConfClass *cltmp;
155 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
156 if (ConClass(cltmp) == cclass)
161 void check_class(void)
163 struct ConfClass *cltmp, *cltmp2;
165 Debug((DEBUG_DEBUG, "Class check:"));
167 for (cltmp2 = cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp2))
170 "Class %d : CF: %d PF: %d ML: %d LI: %d SQ: %d",
171 ConClass(cltmp), ConFreq(cltmp), PingFreq(cltmp),
172 MaxLinks(cltmp), Links(cltmp), MaxSendq(cltmp)));
173 if (IsMarkedDelete(cltmp))
175 NextClass(cltmp2) = NextClass(cltmp);
176 if (Links(cltmp) == 0)
186 classes = (struct ConfClass *) make_class();
188 ConClass(FirstClass()) = 0;
189 ConFreq(FirstClass()) = CONNECTFREQUENCY;
190 PingFreq(FirstClass()) = PINGFREQUENCY;
191 MaxLinks(FirstClass()) = MAXIMUM_LINKS;
192 MaxSendq(FirstClass()) = DEFAULTMAXSENDQLENGTH;
193 Links(FirstClass()) = 0;
194 NextClass(FirstClass()) = NULL;
197 void report_classes(struct Client *sptr)
199 struct ConfClass *cltmp;
201 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
202 send_reply(sptr, RPL_STATSYLINE, 'Y', ConClass(cltmp), PingFreq(cltmp),
203 ConFreq(cltmp), MaxLinks(cltmp), MaxSendq(cltmp));
206 unsigned int get_sendq(struct Client *cptr)
209 assert(0 != cptr->local);
212 return cptr->max_sendq;
214 else if (cptr->confs) {
216 struct ConfClass* cl;
218 for (tmp = cptr->confs; tmp; tmp = tmp->next) {
219 if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
221 if (ConClass(cl) != BAD_CLIENT_CLASS) {
222 cptr->max_sendq = MaxSendq(cl);
223 return cptr->max_sendq;
227 return DEFAULTMAXSENDQLENGTH;