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