1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include "configreader.h"
24 #include <sys/errno.h>
25 #include <sys/utsname.h>
28 #include <ext/hash_map>
41 #include "inspstring.h"
43 #include "helperfuncs.h"
46 extern std::vector<Module*> modules;
47 extern std::vector<ircd_module*> factory;
49 extern ServerConfig* Config;
53 int flags = fcntl(s, F_GETFL, 0);
54 fcntl(s, F_SETFL, flags ^ O_NONBLOCK);
57 void NonBlocking(int s)
59 int flags = fcntl(s, F_GETFL, 0);
60 fcntl(s, F_SETFL, flags | O_NONBLOCK);
63 int c_count(userrec* u)
66 for (std::vector<ucrec*>::const_iterator i = u->chans.begin(); i != u->chans.end(); i++)
73 void ChangeName(userrec* user, const char* gecos)
78 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(user,gecos));
81 FOREACH_MOD(I_OnChangeName,OnChangeName(user,gecos));
83 strlcpy(user->fullname,gecos,MAXGECOS+1);
86 void ChangeDisplayedHost(userrec* user, const char* host)
91 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(user,host));
94 FOREACH_MOD(I_OnChangeHost,OnChangeHost(user,host));
96 strlcpy(user->dhost,host,63);
97 user->WriteServ("396 %s %s :is now your hidden host",user->nick,user->dhost);
100 /* verify that a user's ident and nickname is valid */
102 int isident(const char* n)
108 for (char* i = (char*)n; *i; i++)
110 if ((*i >= 'A') && (*i <= '}'))
114 if (((*i >= '0') && (*i <= '9')) || (*i == '-') || (*i == '.'))
124 int isnick(const char* n)
131 for (char* i = (char*)n; *i; i++, p++)
133 /* "A"-"}" can occur anywhere in a nickname */
134 if ((*i >= 'A') && (*i <= '}'))
138 /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */
139 if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n))
143 /* invalid character! abort */
146 return (p < NICKMAX - 1);
149 /* returns the status character for a given user on a channel, e.g. @ for op,
150 * % for halfop etc. If the user has several modes set, the highest mode
151 * the user has must be returned. */
153 const char* cmode(userrec *user, chanrec *chan)
155 if ((!user) || (!chan))
157 log(DEFAULT,"*** BUG *** cmode was given an invalid parameter");
161 for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
163 if ((*i)->channel == chan)
165 if (((*i)->uc_modes & UCMODE_OP) > 0)
169 if (((*i)->uc_modes & UCMODE_HOP) > 0)
173 if (((*i)->uc_modes & UCMODE_VOICE) > 0)
183 int cflags(userrec *user, chanrec *chan)
185 if ((!chan) || (!user))
188 for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
190 if ((*i)->channel == chan)
192 return (*i)->uc_modes;
198 /* returns the status value for a given user on a channel, e.g. STATUS_OP for
199 * op, STATUS_VOICE for voice etc. If the user has several modes set, the
200 * highest mode the user has must be returned. */
202 int cstatus(userrec *user, chanrec *chan)
204 if ((!chan) || (!user))
206 log(DEFAULT,"*** BUG *** cstatus was given an invalid parameter");
210 if (is_uline(user->server))
213 for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
215 if ((*i)->channel == chan)
217 if (((*i)->uc_modes & UCMODE_OP) > 0)
221 if (((*i)->uc_modes & UCMODE_HOP) > 0)
225 if (((*i)->uc_modes & UCMODE_VOICE) > 0)
229 return STATUS_NORMAL;
232 return STATUS_NORMAL;
235 std::string chlist(userrec *user,userrec* source)
239 if (!user || !source)
242 for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
246 if(rec->channel && rec->channel->name)
248 /* If the target is the same as the sender, let them see all their channels.
249 * If the channel is NOT private/secret OR the user shares a common channel
250 * If the user is an oper, and the <options:operspywhois> option is set.
252 if ((source == user) || (*source->oper && Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source))))
254 list.append(cmode(user, rec->channel)).append(rec->channel->name).append(" ");