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