]> jfr.im git - irc/quakenet/newserv.git/blame - nick/nick.h
Various changes to support authname being stored inside the authext.
[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 40#define AFLAG_STAFF 0x0001
c4ffdb9b
CP
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
c153c0dc 47
c86edd1d
Q
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)
e98d808a 61#define IsParanoid(x) ((x)->umodes & UMODE_PARANOID)
c86edd1d
Q
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)
e98d808a 76#define SetParanoid(x) ((x)->umodes |= UMODE_PARANOID)
c86edd1d
Q
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)
e98d808a 91#define ClearParanoid(x) ((x)->umodes &= ~UMODE_PARANOID)
c86edd1d 92
3294b10b
CP
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)
c153c0dc 110
c86edd1d
Q
111typedef struct host {
112 sstring *name;
113 int clonecount;
114 unsigned int marker;
115 struct nick *nicks;
116 struct host *next;
117} host;
118
119typedef struct realname {
120 sstring *name;
121 int usercount;
122 unsigned int marker;
123 struct nick *nicks;
124 struct realname *next;
125} realname;
126
127typedef struct nick {
128 char nick[NICKLEN+1];
129 long numeric;
130 char ident[USERLEN+1];
131 host *host;
132 realname *realname;
133 sstring *shident; /* +h users: fake ident/host goes here */
134 sstring *sethost;
843184e3 135 sstring *opername;
c86edd1d 136 flag_t umodes;
3294b10b 137 char *authname;
47657339 138 authname *auth; /* This requires User ID numbers to work */
c86edd1d
Q
139 time_t timestamp;
140 time_t accountts;
526e7c1d 141 patricia_node_t *ipnode;
c86edd1d
Q
142 unsigned int marker;
143 struct nick *next;
144 struct nick *nextbyhost;
145 struct nick *nextbyrealname;
47657339 146 struct nick *nextbyauthname;
c86edd1d
Q
147 /* These are extensions only used by other modules */
148 array *channels;
149 void *exts[MAXNICKEXTS];
150} nick;
151
526e7c1d
P
152#define p_ipaddr ipnode->prefix->sin
153
c86edd1d
Q
154#define NICKHASHSIZE 60000
155#define HOSTHASHSIZE 40000
156#define REALNAMEHASHSIZE 40000
157
158extern nick *nicktable[NICKHASHSIZE];
159extern nick **servernicks[MAXSERVERS];
160extern host *hosttable[HOSTHASHSIZE];
161extern realname *realnametable[REALNAMEHASHSIZE];
162extern const flag umodeflags[];
c153c0dc 163extern const flag accountflags[];
c86edd1d
Q
164
165#define MAXNUMERIC 0x3FFFFFFF
166
167#define homeserver(x) (((x)>>18)&(MAXSERVERS-1))
168#define gethandlebynumericunsafe(x) (&(servernicks[homeserver(x)][(x)&(serverlist[homeserver(x)].maxusernum)]))
169#define getnickbynumericunsafe(x) (servernicks[homeserver(x)][(x)&(serverlist[homeserver(x)].maxusernum)])
170#define getnickbynumericstr(x) (getnickbynumeric(numerictolong((x),5)))
171#define gethandlebynumeric(x) ((serverlist[homeserver(x)].linkstate==LS_INVALID) ? NULL : \
172 (gethandlebynumericunsafe(x)))
173#define getnickbynumeric(x) ((gethandlebynumeric(x)==NULL)?NULL: \
174 ((*gethandlebynumeric(x)==NULL)?NULL: \
175 (((*gethandlebynumeric(x))->numeric==(x&MAXNUMERIC))?(*gethandlebynumeric(x)):NULL)))
176
177/* nickalloc.c functions */
178void initnickalloc();
179realname *newrealname();
180void freerealname(realname *rn);
181nick *newnick();
182void freenick (nick *np);
183host *newhost();
184void freehost (host *hp);
185
186/* nick.c functions */
187void handleserverchange(int hooknum, void *arg);
188void deletenick(nick *np);
189void addnicktohash(nick *np);
190void removenickfromhash(nick *np);
191nick *getnickbynick(const char *nick);
192int registernickext(const char *name);
193int findnickext(const char *name);
194void releasenickext(int index);
195char *visiblehostmask(nick *np, char *buf);
28252fef 196char *visibleuserhost(nick *np, char *buf);
c86edd1d
Q
197
198/* nickhandlers.c functions */
199int handlenickmsg(void *source, int cargc, char **cargv);
200int handlequitmsg(void *source, int cargc, char **cargv);
201int handlekillmsg(void *source, int cargc, char **cargv);
202int handleusermodemsg(void *source, int cargc, char **cargv);
203int handlewhoismsg(void *source, int cargc, char **cargv);
204int handleaccountmsg(void *source, int cargc, char **cargv);
205int handlestatsmsg(void *source, int cargc, char **cargv);
6885ae9c 206int handleprivmsg(void *source, int cargc, char **cargv);
c86edd1d
Q
207
208/* These functions have been replaced by macros
209nick **gethandlebynumeric(long numeric);
210nick *getnickbynumeric(long numeric);
211nick *getnickbynumericstr(char *numericstr);
212*/
213
214/* nickhelpers.c functions */
215void initnickhelpers();
707c5824 216void fininickhelpers();
c86edd1d
Q
217host *findhost(const char *hostname);
218host *findorcreatehost(const char *hostname);
219void releasehost(host *hp);
220realname *findrealname(const char *name);
221realname *findorcreaterealname(const char *name);
222void releaserealname(realname *rnp);
223
224unsigned int nexthostmarker();
225unsigned int nextrealnamemarker();
226unsigned int nextnickmarker();
227
228#endif