]>
Commit | Line | Data |
---|---|---|
1 | /* nick.h */ | |
2 | ||
3 | #ifndef __NICK_H | |
4 | #define __NICK_H | |
5 | ||
6 | #include "../lib/sstring.h" | |
7 | #include "../irc/irc_config.h" | |
8 | #include "../lib/flags.h" | |
9 | #include "../lib/array.h" | |
10 | #include "../server/server.h" | |
11 | #include "../lib/base64.h" | |
12 | #include "../lib/irc_ipv6.h" | |
13 | #include "../patricia/patricia.h" | |
14 | ||
15 | #include "../authext/authext.h" | |
16 | ||
17 | #include <time.h> | |
18 | ||
19 | #ifndef MAXNICKEXTS | |
20 | #define MAXNICKEXTS 10 | |
21 | #endif | |
22 | ||
23 | #define UMODE_INV 0x0001 | |
24 | #define UMODE_WALLOPS 0x0002 | |
25 | #define UMODE_DEBUG 0x0004 | |
26 | #define UMODE_OPER 0x0008 | |
27 | #define UMODE_SERVICE 0x0010 | |
28 | #define UMODE_XOPER 0x0020 | |
29 | #define UMODE_DEAF 0x0040 | |
30 | #define UMODE_ACCOUNT 0x0080 | |
31 | #define UMODE_HIDECHAN 0x0100 | |
32 | #define UMODE_HIDEHOST 0x0200 | |
33 | #define UMODE_SETHOST 0x0400 | |
34 | #define UMODE_REGPRIV 0x0800 | |
35 | #define UMODE_HIDEIDLE 0x1000 | |
36 | #define UMODE_PARANOID 0x2000 | |
37 | #define UMODE_CLOAKED 0x4000 | |
38 | #define UMODE_COMCHANS 0x8000 | |
39 | #define UMODE_COMCHANSRESTR 0x10000 | |
40 | ||
41 | #define UMODE_ALL 0x1FFFF | |
42 | ||
43 | #define AFLAG_STAFF 0x0001 | |
44 | #define AFLAG_SUPPORT 0x0002 | |
45 | #define AFLAG_OPER 0x0004 | |
46 | #define AFLAG_ADMIN 0x0008 | |
47 | #define AFLAG_DEVELOPER 0x0010 | |
48 | ||
49 | #define AFLAG_ALL 0x001F | |
50 | ||
51 | #define IsInvisible(x) ((x)->umodes & UMODE_INV) | |
52 | #define IsWallops(x) ((x)->umodes & UMODE_WALLOPS) | |
53 | #define IsDebug(x) ((x)->umodes & UMODE_DEBUG) | |
54 | #define IsOper(x) ((x)->umodes & UMODE_OPER) | |
55 | #define IsService(x) ((x)->umodes & UMODE_SERVICE) | |
56 | #define IsXOper(x) ((x)->umodes & UMODE_XOPER) | |
57 | #define IsDeaf(x) ((x)->umodes & UMODE_DEAF) | |
58 | #define IsAccount(x) ((x)->umodes & UMODE_ACCOUNT) | |
59 | #define IsHideChan(x) ((x)->umodes & UMODE_HIDECHAN) | |
60 | #define IsHideHost(x) ((x)->umodes & UMODE_HIDEHOST) | |
61 | #define IsSetHost(x) ((x)->umodes & UMODE_SETHOST) | |
62 | #define IsRegPriv(x) ((x)->umodes & UMODE_REGPRIV) | |
63 | #define IsHideIdle(x) ((x)->umodes & UMODE_HIDEIDLE) | |
64 | #define IsParanoid(x) ((x)->umodes & UMODE_PARANOID) | |
65 | #define IsComChans(x) ((x)->umodes & UMODE_COMCHANS) | |
66 | #define IsComChansRestr(x) ((x)->umodes & UMODE_COMCHANSRESTR) | |
67 | #define IsCloaked(x) ((x)->umodes & UMODE_CLOAKED) | |
68 | ||
69 | #define SetInvisible(x) ((x)->umodes |= UMODE_INV) | |
70 | #define SetWallops(x) ((x)->umodes |= UMODE_WALLOPS) | |
71 | #define SetDebug(x) ((x)->umodes |= UMODE_DEBUG) | |
72 | #define SetOper(x) ((x)->umodes |= UMODE_OPER) | |
73 | #define SetService(x) ((x)->umodes |= UMODE_SERVICE) | |
74 | #define SetXOper(x) ((x)->umodes |= UMODE_XOPER) | |
75 | #define SetDeaf(x) ((x)->umodes |= UMODE_DEAF) | |
76 | #define SetAccount(x) ((x)->umodes |= UMODE_ACCOUNT) | |
77 | #define SetHideChan(x) ((x)->umodes |= UMODE_HIDECHAN) | |
78 | #define SetHideHost(x) ((x)->umodes |= UMODE_HIDEHOST) | |
79 | #define SetSetHost(x) ((x)->umodes |= UMODE_SETHOST) | |
80 | #define SetRegPriv(x) ((x)->umodes |= UMODE_REGPRIV) | |
81 | #define SetHideIdle(x) ((x)->umodes |= UMODE_HIDEIDLE) | |
82 | #define SetParanoid(x) ((x)->umodes |= UMODE_PARANOID) | |
83 | #define SetComChans(x) ((x)->umodes |= UMODE_COMCHANS) | |
84 | #define SetComChansRestr(x) ((x)->umodes |= UMODE_COMCHANSRESTR) | |
85 | #define SetCloaked(x) ((x)->umodes |= UMODE_CLOAKED) | |
86 | ||
87 | #define ClearInvisible(x) ((x)->umodes &= ~UMODE_INV) | |
88 | #define ClearWallops(x) ((x)->umodes &= ~UMODE_WALLOPS) | |
89 | #define ClearDebug(x) ((x)->umodes &= ~UMODE_DEBUG) | |
90 | #define ClearOper(x) ((x)->umodes &= ~UMODE_OPER) | |
91 | #define ClearService(x) ((x)->umodes &= ~UMODE_SERVICE) | |
92 | #define ClearXOper(x) ((x)->umodes &= ~UMODE_XOPER) | |
93 | #define ClearDeaf(x) ((x)->umodes &= ~UMODE_DEAF) | |
94 | #define ClearAccount(x) ((x)->umodes &= ~UMODE_ACCOUNT) | |
95 | #define ClearHideChan(x) ((x)->umodes &= ~UMODE_HIDECHAN) | |
96 | #define ClearHideHost(x) ((x)->umodes &= ~UMODE_HIDEHOST) | |
97 | #define ClearSetHost(x) ((x)->umodes &= ~UMODE_SETHOST) | |
98 | #define ClearRegPriv(x) ((x)->umodes &= ~UMODE_REGPRIV) | |
99 | #define ClearHideIdle(x) ((x)->umodes &= ~UMODE_HIDEIDLE) | |
100 | #define ClearParanoid(x) ((x)->umodes &= ~UMODE_PARANOID) | |
101 | #define ClearComChans(x) ((x)->umodes &= ~UMODE_COMCHANS) | |
102 | #define ClearComChansRestr(x) ((x)->umodes &= ~UMODE_COMCHANSRESTR) | |
103 | #define ClearCloaked(x) ((x)->umodes &= ~UMODE_CLOAKED) | |
104 | ||
105 | #define IsStaff(x) ((x)->flags & AFLAG_STAFF) | |
106 | #define IsDeveloper(x) ((x)->flags & AFLAG_DEVELOPER) | |
107 | #define IsSupport(x) ((x)->flags & AFLAG_SUPPORT) | |
108 | #define IsAdmin(x) ((x)->flags & AFLAG_ADMIN) | |
109 | #define IsOperFlag(x) ((x)->flags & AFLAG_OPER) | |
110 | ||
111 | #define SetStaff(x) ((x)->flags |= AFLAG_STAFF) | |
112 | #define SetDeveloper(x) ((x)->flags |= AFLAG_DEVELOPER) | |
113 | #define SetSupport(x) ((x)->flags |= AFLAG_SUPPORT) | |
114 | #define SetAdmin(x) ((x)->flags |= AFLAG_ADMIN) | |
115 | #define SetOperFlag(x) ((x)->flags |= AFLAG_OPER) | |
116 | ||
117 | #define ClearStaff(x) ((x)->flags &= ~AFLAG_STAFF) | |
118 | #define ClearDeveloper(x) ((x)->flags &= ~AFLAG_DEVELOPER) | |
119 | #define ClearSupport(x) ((x)->flags &= ~AFLAG_SUPPORT) | |
120 | #define ClearAdmin(x) ((x)->flags &= ~AFLAG_ADMIN) | |
121 | #define ClearOperFlag(x) ((x)->flags &= ~AFLAG_OPER) | |
122 | ||
123 | #define NickOnServiceServer(target) SIsService(&serverlist[homeserver((target)->numeric)]) | |
124 | ||
125 | typedef struct host { | |
126 | sstring *name; | |
127 | int clonecount; | |
128 | unsigned int marker; | |
129 | struct nick *nicks; | |
130 | struct host *next; | |
131 | } host; | |
132 | ||
133 | typedef struct realname { | |
134 | sstring *name; | |
135 | int usercount; | |
136 | unsigned int marker; | |
137 | struct nick *nicks; | |
138 | struct realname *next; | |
139 | } realname; | |
140 | ||
141 | typedef struct nick { | |
142 | char nick[NICKLEN+1]; | |
143 | long numeric; | |
144 | char ident[USERLEN+1]; | |
145 | host *host; | |
146 | realname *realname; | |
147 | sstring *shident; /* +h users: fake ident/host goes here */ | |
148 | sstring *sethost; | |
149 | sstring *opername; | |
150 | flag_t umodes; | |
151 | char *authname; | |
152 | authname *auth; /* This requires User ID numbers to work */ | |
153 | time_t timestamp; | |
154 | time_t accountts; | |
155 | sstring *away; | |
156 | struct irc_in_addr ipaddress; | |
157 | patricia_node_t *ipnode; | |
158 | unsigned int cloak_count; | |
159 | struct nick *cloak_extra; | |
160 | unsigned int marker; | |
161 | struct nick *next; | |
162 | struct nick *nextbyhost; | |
163 | struct nick *nextbyrealname; | |
164 | struct nick *nextbyauthname; | |
165 | /* These are extensions only used by other modules */ | |
166 | array *channels; | |
167 | sstring *message; | |
168 | void *exts[MAXNICKEXTS]; | |
169 | } nick; | |
170 | ||
171 | #define NICKHASHSIZE 60000 | |
172 | #define HOSTHASHSIZE 40000 | |
173 | #define REALNAMEHASHSIZE 40000 | |
174 | ||
175 | extern nick *nicktable[NICKHASHSIZE]; | |
176 | extern nick **servernicks[MAXSERVERS]; | |
177 | extern host *hosttable[HOSTHASHSIZE]; | |
178 | extern realname *realnametable[REALNAMEHASHSIZE]; | |
179 | extern const flag umodeflags[]; | |
180 | extern const flag accountflags[]; | |
181 | extern char *NULLAUTHNAME; | |
182 | ||
183 | #define MAXNUMERIC 0x3FFFFFFF | |
184 | ||
185 | #define homeserver(x) (((x)>>18)&(MAXSERVERS-1)) | |
186 | #define gethandlebynumericunsafe(x) (&(servernicks[homeserver(x)][(x)&(serverlist[homeserver(x)].maxusernum)])) | |
187 | #define getnickbynumericunsafe(x) (servernicks[homeserver(x)][(x)&(serverlist[homeserver(x)].maxusernum)]) | |
188 | #define getnickbynumericstr(x) (getnickbynumeric(numerictolong((x),5))) | |
189 | #define gethandlebynumeric(x) ((serverlist[homeserver(x)].linkstate==LS_INVALID) ? NULL : \ | |
190 | (gethandlebynumericunsafe(x))) | |
191 | #define getnickbynumeric(x) ((gethandlebynumeric(x)==NULL)?NULL: \ | |
192 | ((*gethandlebynumeric(x)==NULL)?NULL: \ | |
193 | (((*gethandlebynumeric(x))->numeric==(x&MAXNUMERIC))?(*gethandlebynumeric(x)):NULL))) | |
194 | ||
195 | /* nickalloc.c functions */ | |
196 | realname *newrealname(); | |
197 | void freerealname(realname *rn); | |
198 | nick *newnick(); | |
199 | void freenick(nick *np); | |
200 | host *newhost(); | |
201 | void freehost(host *hp); | |
202 | ||
203 | /* nick.c functions */ | |
204 | void handleserverchange(int hooknum, void *arg); | |
205 | void deletenick(nick *np); | |
206 | void addnicktohash(nick *np); | |
207 | void removenickfromhash(nick *np); | |
208 | nick *getnickbynick(const char *nick); | |
209 | int registernickext(const char *name); | |
210 | int findnickext(const char *name); | |
211 | void releasenickext(int index); | |
212 | char *visiblehostmask(nick *np, char *buf); | |
213 | char *visibleuserhost(nick *np, char *buf); | |
214 | int canseeuser(nick *np, nick *cloaked); | |
215 | void addcloaktarget(nick *cloaked, nick *target); | |
216 | void removecloaktarget(nick *target); | |
217 | void clearcloaktargets(nick *cloaked); | |
218 | ||
219 | /* nickhandlers.c functions */ | |
220 | int handlenickmsg(void *source, int cargc, char **cargv); | |
221 | int handlequitmsg(void *source, int cargc, char **cargv); | |
222 | int handlekillmsg(void *source, int cargc, char **cargv); | |
223 | int handleusermodemsg(void *source, int cargc, char **cargv); | |
224 | int handleaccountmsg(void *source, int cargc, char **cargv); | |
225 | int handleprivmsg(void *source, int cargc, char **cargv); | |
226 | int handleawaymsg(void *source, int cargc, char **cargv); | |
227 | int handleaddcloak(void *source, int cargc, char **cargv); | |
228 | int handleclearcloak(void *source, int cargc, char **cargv); | |
229 | ||
230 | /* These functions have been replaced by macros | |
231 | nick **gethandlebynumeric(long numeric); | |
232 | nick *getnickbynumeric(long numeric); | |
233 | nick *getnickbynumericstr(char *numericstr); | |
234 | */ | |
235 | ||
236 | /* nickhelpers.c functions */ | |
237 | void initnickhelpers(); | |
238 | void fininickhelpers(); | |
239 | host *findhost(const char *hostname); | |
240 | host *findorcreatehost(const char *hostname); | |
241 | void releasehost(host *hp); | |
242 | realname *findrealname(const char *name); | |
243 | realname *findorcreaterealname(const char *name); | |
244 | void releaserealname(realname *rnp); | |
245 | ||
246 | unsigned int nexthostmarker(); | |
247 | unsigned int nextrealnamemarker(); | |
248 | unsigned int nextnickmarker(); | |
249 | ||
250 | #endif |