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