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)
39 unsigned int get_conf_class(aConfItem *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(aConfItem *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(aClient *acptr)
64 unsigned int retc = BAD_CLIENT_CLASS;
66 if (acptr && !IsMe(acptr) && !IsPing(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 int unsigned get_client_ping(aClient *acptr)
82 unsigned int ping = 0, ping2;
91 aconf = link->value.aconf;
93 (CONF_CLIENT | CONF_CONNECT_SERVER | CONF_NOCONNECT_SERVER))
95 ping2 = get_conf_ping(aconf);
96 if ((ping2 != BAD_PING) && ((ping > ping2) || !ping))
103 ping = PINGFREQUENCY;
104 Debug((DEBUG_DEBUG, "No Attached Confs"));
107 ping = PINGFREQUENCY;
108 Debug((DEBUG_DEBUG, "Client %s Ping %d", acptr->name, ping));
112 unsigned int get_con_freq(aConfClass * clptr)
115 return (ConFreq(clptr));
117 return (CONNECTFREQUENCY);
121 * When adding a class, check to see if it is already present first.
122 * if so, then update the information for that class, rather than create
123 * a new entry for it and later delete the old entry.
124 * if no present entry is found, then create a new one and add it in
125 * immeadiately after the first one (class 0).
127 void add_class(unsigned int conClass, unsigned int ping, unsigned int confreq,
128 unsigned int maxli, size_t sendq)
132 t = find_class(conClass);
133 if ((t == classes) && (conClass != 0))
135 p = (aConfClass *) make_class();
136 NextClass(p) = NextClass(t);
141 Debug((DEBUG_DEBUG, "Add Class %u: p %p t %p - cf: %u pf: %u ml: %u sq: %d",
142 conClass, p, t, confreq, ping, maxli, sendq));
143 ConClass(p) = conClass;
144 ConFreq(p) = confreq;
147 MaxSendq(p) = (sendq > 0) ? sendq : DEFAULTMAXSENDQLENGTH;
152 aConfClass *find_class(unsigned int cclass)
156 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
157 if (ConClass(cltmp) == cclass)
162 void check_class(void)
164 aConfClass *cltmp, *cltmp2;
166 Debug((DEBUG_DEBUG, "Class check:"));
168 for (cltmp2 = cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp2))
171 "Class %d : CF: %d PF: %d ML: %d LI: %d SQ: %d",
172 ConClass(cltmp), ConFreq(cltmp), PingFreq(cltmp),
173 MaxLinks(cltmp), Links(cltmp), MaxSendq(cltmp)));
174 if (IsMarkedDelete(cltmp))
176 NextClass(cltmp2) = NextClass(cltmp);
177 if (Links(cltmp) == 0)
187 classes = (aConfClass *) make_class();
189 ConClass(FirstClass()) = 0;
190 ConFreq(FirstClass()) = CONNECTFREQUENCY;
191 PingFreq(FirstClass()) = PINGFREQUENCY;
192 MaxLinks(FirstClass()) = MAXIMUM_LINKS;
193 MaxSendq(FirstClass()) = DEFAULTMAXSENDQLENGTH;
194 Links(FirstClass()) = 0;
195 NextClass(FirstClass()) = NULL;
198 void report_classes(aClient *sptr)
202 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
203 sendto_one(sptr, rpl_str(RPL_STATSYLINE), me.name, sptr->name,
204 'Y', ConClass(cltmp), PingFreq(cltmp), ConFreq(cltmp),
205 MaxLinks(cltmp), MaxSendq(cltmp));
208 size_t get_sendq(aClient *cptr)
210 size_t sendq = DEFAULTMAXSENDQLENGTH;
214 if (cptr && !IsMe(cptr) && (cptr->confs))
215 for (tmp = cptr->confs; tmp; tmp = tmp->next)
217 if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
219 if (ConClass(cl) != BAD_CLIENT_CLASS)
220 sendq = MaxSendq(cl);