]> jfr.im git - irc/quakenet/newserv.git/blob - nick/nick.h
Build fix for FreeBSD.
[irc/quakenet/newserv.git] / nick / nick.h
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
39 #define UMODE_ALL 0x7FFF
40
41 #define AFLAG_STAFF 0x0001
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
48
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)
62 #define IsParanoid(x) ((x)->umodes & UMODE_PARANOID)
63 #define IsCloaked(x) ((x)->umodes & UMODE_CLOAKED)
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)
78 #define SetParanoid(x) ((x)->umodes |= UMODE_PARANOID)
79 #define SetCloaked(x) ((x)->umodes |= UMODE_CLOAKED)
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)
94 #define ClearParanoid(x) ((x)->umodes &= ~UMODE_PARANOID)
95 #define ClearCloaked(x) ((x)->umodes &= ~UMODE_CLOAKED)
96
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)
114
115 #define NickOnServiceServer(target) SIsService(&serverlist[homeserver((target)->numeric)])
116
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;
141 sstring *opername;
142 flag_t umodes;
143 char *authname;
144 authname *auth; /* This requires User ID numbers to work */
145 time_t timestamp;
146 time_t accountts;
147 sstring *away;
148 patricia_node_t *ipnode;
149 unsigned int cloak_count;
150 struct nick *cloak_extra;
151 unsigned int marker;
152 struct nick *next;
153 struct nick *nextbyhost;
154 struct nick *nextbyrealname;
155 struct nick *nextbyauthname;
156 /* These are extensions only used by other modules */
157 array *channels;
158 void *exts[MAXNICKEXTS];
159 } nick;
160
161 #define p_ipaddr ipnode->prefix->sin
162
163 #define NICKHASHSIZE 60000
164 #define HOSTHASHSIZE 40000
165 #define REALNAMEHASHSIZE 40000
166
167 extern nick *nicktable[NICKHASHSIZE];
168 extern nick **servernicks[MAXSERVERS];
169 extern host *hosttable[HOSTHASHSIZE];
170 extern realname *realnametable[REALNAMEHASHSIZE];
171 extern const flag umodeflags[];
172 extern const flag accountflags[];
173 extern char *NULLAUTHNAME;
174
175 #define MAXNUMERIC 0x3FFFFFFF
176
177 #define homeserver(x) (((x)>>18)&(MAXSERVERS-1))
178 #define gethandlebynumericunsafe(x) (&(servernicks[homeserver(x)][(x)&(serverlist[homeserver(x)].maxusernum)]))
179 #define getnickbynumericunsafe(x) (servernicks[homeserver(x)][(x)&(serverlist[homeserver(x)].maxusernum)])
180 #define getnickbynumericstr(x) (getnickbynumeric(numerictolong((x),5)))
181 #define gethandlebynumeric(x) ((serverlist[homeserver(x)].linkstate==LS_INVALID) ? NULL : \
182 (gethandlebynumericunsafe(x)))
183 #define getnickbynumeric(x) ((gethandlebynumeric(x)==NULL)?NULL: \
184 ((*gethandlebynumeric(x)==NULL)?NULL: \
185 (((*gethandlebynumeric(x))->numeric==(x&MAXNUMERIC))?(*gethandlebynumeric(x)):NULL)))
186
187 /* nickalloc.c functions */
188 realname *newrealname();
189 void freerealname(realname *rn);
190 nick *newnick();
191 void freenick(nick *np);
192 host *newhost();
193 void freehost(host *hp);
194
195 /* nick.c functions */
196 void handleserverchange(int hooknum, void *arg);
197 void deletenick(nick *np);
198 void addnicktohash(nick *np);
199 void removenickfromhash(nick *np);
200 nick *getnickbynick(const char *nick);
201 int registernickext(const char *name);
202 int findnickext(const char *name);
203 void releasenickext(int index);
204 char *visiblehostmask(nick *np, char *buf);
205 char *visibleuserhost(nick *np, char *buf);
206 int canseeuser(nick *np, nick *cloaked);
207 void addcloaktarget(nick *cloaked, nick *target);
208 void removecloaktarget(nick *target);
209 void clearcloaktargets(nick *cloaked);
210
211 /* nickhandlers.c functions */
212 int handlenickmsg(void *source, int cargc, char **cargv);
213 int handlequitmsg(void *source, int cargc, char **cargv);
214 int handlekillmsg(void *source, int cargc, char **cargv);
215 int handleusermodemsg(void *source, int cargc, char **cargv);
216 int handleaccountmsg(void *source, int cargc, char **cargv);
217 int handleprivmsg(void *source, int cargc, char **cargv);
218 int handleawaymsg(void *source, int cargc, char **cargv);
219 int handleaddcloak(void *source, int cargc, char **cargv);
220 int handleclearcloak(void *source, int cargc, char **cargv);
221
222 /* These functions have been replaced by macros
223 nick **gethandlebynumeric(long numeric);
224 nick *getnickbynumeric(long numeric);
225 nick *getnickbynumericstr(char *numericstr);
226 */
227
228 /* nickhelpers.c functions */
229 void initnickhelpers();
230 void fininickhelpers();
231 host *findhost(const char *hostname);
232 host *findorcreatehost(const char *hostname);
233 void releasehost(host *hp);
234 realname *findrealname(const char *name);
235 realname *findorcreaterealname(const char *name);
236 void releaserealname(realname *rnp);
237
238 unsigned int nexthostmarker();
239 unsigned int nextrealnamemarker();
240 unsigned int nextnickmarker();
241
242 #endif