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 InspIRCd* ServerInstance;
51 /* verify that a user's ident and nickname is valid */
53 int isident(const char* n)
59 for (char* i = (char*)n; *i; i++)
61 if ((*i >= 'A') && (*i <= '}'))
65 if (((*i >= '0') && (*i <= '9')) || (*i == '-') || (*i == '.'))
75 int isnick(const char* n)
82 for (char* i = (char*)n; *i; i++, p++)
84 /* "A"-"}" can occur anywhere in a nickname */
85 if ((*i >= 'A') && (*i <= '}'))
89 /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */
90 if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n))
94 /* invalid character! abort */
97 return (p < NICKMAX - 1);
100 /* returns the status character for a given user on a channel, e.g. @ for op,
101 * % for halfop etc. If the user has several modes set, the highest mode
102 * the user has must be returned. */
104 const char* cmode(userrec *user, chanrec *chan)
106 if ((!user) || (!chan))
108 log(DEFAULT,"*** BUG *** cmode was given an invalid parameter");
112 for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
114 if ((*i)->channel == chan)
116 if (((*i)->uc_modes & UCMODE_OP) > 0)
120 if (((*i)->uc_modes & UCMODE_HOP) > 0)
124 if (((*i)->uc_modes & UCMODE_VOICE) > 0)
134 int cflags(userrec *user, chanrec *chan)
136 if ((!chan) || (!user))
139 for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
141 if ((*i)->channel == chan)
143 return (*i)->uc_modes;
149 /* returns the status value for a given user on a channel, e.g. STATUS_OP for
150 * op, STATUS_VOICE for voice etc. If the user has several modes set, the
151 * highest mode the user has must be returned. */
153 int cstatus(userrec *user, chanrec *chan)
155 if ((!chan) || (!user))
157 log(DEFAULT,"*** BUG *** cstatus was given an invalid parameter");
161 if (is_uline(user->server))
164 for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
166 if ((*i)->channel == chan)
168 if (((*i)->uc_modes & UCMODE_OP) > 0)
172 if (((*i)->uc_modes & UCMODE_HOP) > 0)
176 if (((*i)->uc_modes & UCMODE_VOICE) > 0)
180 return STATUS_NORMAL;
183 return STATUS_NORMAL;
186 std::string chlist(userrec *user,userrec* source)
190 if (!user || !source)
193 for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
197 if(rec->channel && rec->channel->name)
199 /* If the target is the same as the sender, let them see all their channels.
200 * If the channel is NOT private/secret OR the user shares a common channel
201 * If the user is an oper, and the <options:operspywhois> option is set.
203 if ((source == user) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source))))
205 list.append(cmode(user, rec->channel)).append(rec->channel->name).append(" ");