]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/message.cpp
6d5941f7e7ea5042eaa1d795e593b552c3c2d0cd
[user/henk/code/inspircd.git] / src / message.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "configreader.h"
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <sys/errno.h>
25 #include <sys/utsname.h>
26 #include <time.h>
27 #include <string>
28 #include <ext/hash_map>
29 #include <map>
30 #include <sstream>
31 #include <vector>
32 #include <deque>
33 #include "users.h"
34 #include "ctables.h"
35 #include "globals.h"
36 #include "modules.h"
37 #include "dynamic.h"
38 #include "wildcard.h"
39 #include "commands.h"
40 #include "message.h"
41 #include "inspstring.h"
42 #include "dns.h"
43 #include "helperfuncs.h"
44
45 extern int MODCOUNT;
46 extern std::vector<Module*> modules;
47 extern std::vector<ircd_module*> factory;
48 extern time_t TIME;
49 extern InspIRCd* ServerInstance;
50
51 /* verify that a user's ident and nickname is valid */
52
53 int isident(const char* n)
54 {
55         if (!n || !*n)
56         {
57                 return 0;
58         }
59         for (char* i = (char*)n; *i; i++)
60         {
61                 if ((*i >= 'A') && (*i <= '}'))
62                 {
63                         continue;
64                 }
65                 if (((*i >= '0') && (*i <= '9')) || (*i == '-') || (*i == '.'))
66                 {
67                         continue;
68                 }
69                 return 0;
70         }
71         return 1;
72 }
73
74
75 int isnick(const char* n)
76 {
77         if (!n || !*n)
78         {
79                 return 0;
80         }
81         int p = 0;
82         for (char* i = (char*)n; *i; i++, p++)
83         {
84                 /* "A"-"}" can occur anywhere in a nickname */
85                 if ((*i >= 'A') && (*i <= '}'))
86                 {
87                         continue;
88                 }
89                 /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */
90                 if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n))
91                 {
92                         continue;
93                 }
94                 /* invalid character! abort */
95                 return 0;
96         }
97         return (p < NICKMAX - 1);
98 }
99
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. */
103
104 const char* cmode(userrec *user, chanrec *chan)
105 {
106         if ((!user) || (!chan))
107         {
108                 log(DEFAULT,"*** BUG *** cmode was given an invalid parameter");
109                 return "";
110         }
111
112         for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
113         {
114                 if ((*i)->channel == chan)
115                 {
116                         if (((*i)->uc_modes & UCMODE_OP) > 0)
117                         {
118                                 return "@";
119                         }
120                         if (((*i)->uc_modes & UCMODE_HOP) > 0)
121                         {
122                                 return "%";
123                         }
124                         if (((*i)->uc_modes & UCMODE_VOICE) > 0)
125                         {
126                                 return "+";
127                         }
128                         return "";
129                 }
130         }
131         return "";
132 }
133
134 int cflags(userrec *user, chanrec *chan)
135 {
136         if ((!chan) || (!user))
137                 return 0;
138
139         for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
140         {
141                 if ((*i)->channel == chan)
142                 {
143                         return (*i)->uc_modes;
144                 }
145         }
146         return 0;
147 }
148
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. */
152
153 int cstatus(userrec *user, chanrec *chan)
154 {
155         if ((!chan) || (!user))
156         {
157                 log(DEFAULT,"*** BUG *** cstatus was given an invalid parameter");
158                 return 0;
159         }
160
161         if (is_uline(user->server))
162                 return STATUS_OP;
163
164         for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
165         {
166                 if ((*i)->channel == chan)
167                 {
168                         if (((*i)->uc_modes & UCMODE_OP) > 0)
169                         {
170                                 return STATUS_OP;
171                         }
172                         if (((*i)->uc_modes & UCMODE_HOP) > 0)
173                         {
174                                 return STATUS_HOP;
175                         }
176                         if (((*i)->uc_modes & UCMODE_VOICE) > 0)
177                         {
178                                 return STATUS_VOICE;
179                         }
180                         return STATUS_NORMAL;
181                 }
182         }
183         return STATUS_NORMAL;
184 }
185