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.
33 #define BAD_CONF_CLASS ((unsigned int)-1)
34 #define BAD_PING ((unsigned int)-2)
35 #define BAD_CLIENT_CLASS ((unsigned int)-3)
37 struct ConfClass *classes;
39 unsigned int get_conf_class(struct ConfItem *aconf)
41 if ((aconf) && (aconf->confClass))
42 return (ConfClass(aconf));
44 Debug((DEBUG_DEBUG, "No Class For %s", (aconf) ? aconf->name : "*No Conf*"));
46 return (BAD_CONF_CLASS);
50 static unsigned int get_conf_ping(struct ConfItem *aconf)
52 if ((aconf) && (aconf->confClass))
53 return (ConfPingFreq(aconf));
55 Debug((DEBUG_DEBUG, "No Ping For %s", (aconf) ? aconf->name : "*No Conf*"));
60 unsigned int get_client_class(struct Client *acptr)
64 unsigned int retc = BAD_CLIENT_CLASS;
66 if (acptr && !IsMe(acptr) && (acptr->confs))
67 for (tmp = acptr->confs; tmp; tmp = tmp->next)
69 if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
71 if (ConClass(cl) > retc || retc == BAD_CLIENT_CLASS)
75 Debug((DEBUG_DEBUG, "Returning Class %d For %s", retc, acptr->name));
80 unsigned int get_client_ping(struct Client *acptr)
82 unsigned int ping = 0;
84 struct ConfItem *aconf;
91 aconf = link->value.aconf;
92 if (aconf->status & (CONF_CLIENT | CONF_SERVER)) {
93 ping2 = get_conf_ping(aconf);
94 if ((ping2 != BAD_PING) && ((ping > ping2) || !ping))
101 ping = PINGFREQUENCY;
102 Debug((DEBUG_DEBUG, "No Attached Confs for: %s", acptr->name));
105 ping = PINGFREQUENCY;
106 Debug((DEBUG_DEBUG, "Client %s Ping %d", acptr->name, ping));
110 unsigned int get_con_freq(struct ConfClass * clptr)
113 return (ConFreq(clptr));
115 return (CONNECTFREQUENCY);
119 * When adding a class, check to see if it is already present first.
120 * if so, then update the information for that class, rather than create
121 * a new entry for it and later delete the old entry.
122 * if no present entry is found, then create a new one and add it in
123 * immeadiately after the first one (class 0).
125 void add_class(unsigned int conClass, unsigned int ping, unsigned int confreq,
126 unsigned int maxli, size_t sendq)
128 struct ConfClass *t, *p;
130 t = find_class(conClass);
131 if ((t == classes) && (conClass != 0))
133 p = (struct ConfClass *) make_class();
134 NextClass(p) = NextClass(t);
139 Debug((DEBUG_DEBUG, "Add Class %u: p %p t %p - cf: %u pf: %u ml: %u sq: %d",
140 conClass, p, t, confreq, ping, maxli, sendq));
141 ConClass(p) = conClass;
142 ConFreq(p) = confreq;
145 MaxSendq(p) = (sendq > 0) ? sendq : DEFAULTMAXSENDQLENGTH;
150 struct ConfClass *find_class(unsigned int cclass)
152 struct ConfClass *cltmp;
154 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
155 if (ConClass(cltmp) == cclass)
160 void check_class(void)
162 struct ConfClass *cltmp, *cltmp2;
164 Debug((DEBUG_DEBUG, "Class check:"));
166 for (cltmp2 = cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp2))
169 "Class %d : CF: %d PF: %d ML: %d LI: %d SQ: %d",
170 ConClass(cltmp), ConFreq(cltmp), PingFreq(cltmp),
171 MaxLinks(cltmp), Links(cltmp), MaxSendq(cltmp)));
172 if (IsMarkedDelete(cltmp))
174 NextClass(cltmp2) = NextClass(cltmp);
175 if (Links(cltmp) == 0)
185 classes = (struct ConfClass *) make_class();
187 ConClass(FirstClass()) = 0;
188 ConFreq(FirstClass()) = CONNECTFREQUENCY;
189 PingFreq(FirstClass()) = PINGFREQUENCY;
190 MaxLinks(FirstClass()) = MAXIMUM_LINKS;
191 MaxSendq(FirstClass()) = DEFAULTMAXSENDQLENGTH;
192 Links(FirstClass()) = 0;
193 NextClass(FirstClass()) = NULL;
196 void report_classes(struct Client *sptr)
198 struct ConfClass *cltmp;
200 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
201 sendto_one(sptr, rpl_str(RPL_STATSYLINE), me.name, sptr->name,
202 'Y', ConClass(cltmp), PingFreq(cltmp), ConFreq(cltmp),
203 MaxLinks(cltmp), MaxSendq(cltmp));
206 size_t 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;