]> jfr.im git - irc/quakenet/newserv.git/blob - nick/nick.h
5b2c7fc39235a1521ae33cf47668c3b0f08f4d9e
[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 6
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_DEVELOPER 0x0002
42
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)
56 #define IsParanoid(x) ((x)->umodes & UMODE_PARANOID)
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)
71 #define SetParanoid(x) ((x)->umodes |= UMODE_PARANOID)
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)
86 #define ClearParanoid(x) ((x)->umodes &= ~UMODE_PARANOID)
87
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
97 typedef struct host {
98 sstring *name;
99 int clonecount;
100 unsigned int marker;
101 struct nick *nicks;
102 struct host *next;
103 } host;
104
105 typedef struct realname {
106 sstring *name;
107 int usercount;
108 unsigned int marker;
109 struct nick *nicks;
110 struct realname *next;
111 } realname;
112
113 typedef 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;
121 flag_t umodes;
122 char authname[ACCOUNTLEN+1];
123 authname *auth; /* This requires User ID numbers to work */
124 time_t timestamp;
125 time_t accountts;
126 patricia_node_t *ipnode;
127 unsigned int marker;
128 struct nick *next;
129 struct nick *nextbyhost;
130 struct nick *nextbyrealname;
131 struct nick *nextbyauthname;
132 /* These are extensions only used by other modules */
133 array *channels;
134 void *exts[MAXNICKEXTS];
135 } nick;
136
137 #define p_ipaddr ipnode->prefix->sin
138
139 #define NICKHASHSIZE 60000
140 #define HOSTHASHSIZE 40000
141 #define REALNAMEHASHSIZE 40000
142
143 extern nick *nicktable[NICKHASHSIZE];
144 extern nick **servernicks[MAXSERVERS];
145 extern host *hosttable[HOSTHASHSIZE];
146 extern realname *realnametable[REALNAMEHASHSIZE];
147 extern const flag umodeflags[];
148 extern const flag accountflags[];
149
150 #define MAXNUMERIC 0x3FFFFFFF
151
152 #define homeserver(x) (((x)>>18)&(MAXSERVERS-1))
153 #define gethandlebynumericunsafe(x) (&(servernicks[homeserver(x)][(x)&(serverlist[homeserver(x)].maxusernum)]))
154 #define getnickbynumericunsafe(x) (servernicks[homeserver(x)][(x)&(serverlist[homeserver(x)].maxusernum)])
155 #define getnickbynumericstr(x) (getnickbynumeric(numerictolong((x),5)))
156 #define gethandlebynumeric(x) ((serverlist[homeserver(x)].linkstate==LS_INVALID) ? NULL : \
157 (gethandlebynumericunsafe(x)))
158 #define getnickbynumeric(x) ((gethandlebynumeric(x)==NULL)?NULL: \
159 ((*gethandlebynumeric(x)==NULL)?NULL: \
160 (((*gethandlebynumeric(x))->numeric==(x&MAXNUMERIC))?(*gethandlebynumeric(x)):NULL)))
161
162 /* nickalloc.c functions */
163 void initnickalloc();
164 realname *newrealname();
165 void freerealname(realname *rn);
166 nick *newnick();
167 void freenick (nick *np);
168 host *newhost();
169 void freehost (host *hp);
170
171 /* nick.c functions */
172 void handleserverchange(int hooknum, void *arg);
173 void deletenick(nick *np);
174 void addnicktohash(nick *np);
175 void removenickfromhash(nick *np);
176 nick *getnickbynick(const char *nick);
177 int registernickext(const char *name);
178 int findnickext(const char *name);
179 void releasenickext(int index);
180 char *visiblehostmask(nick *np, char *buf);
181 char *visibleuserhost(nick *np, char *buf);
182
183 /* nickhandlers.c functions */
184 int handlenickmsg(void *source, int cargc, char **cargv);
185 int handlequitmsg(void *source, int cargc, char **cargv);
186 int handlekillmsg(void *source, int cargc, char **cargv);
187 int handleusermodemsg(void *source, int cargc, char **cargv);
188 int handlewhoismsg(void *source, int cargc, char **cargv);
189 int handleaccountmsg(void *source, int cargc, char **cargv);
190 int handlestatsmsg(void *source, int cargc, char **cargv);
191
192 /* These functions have been replaced by macros
193 nick **gethandlebynumeric(long numeric);
194 nick *getnickbynumeric(long numeric);
195 nick *getnickbynumericstr(char *numericstr);
196 */
197
198 /* nickhelpers.c functions */
199 void initnickhelpers();
200 void fininickhelpers();
201 host *findhost(const char *hostname);
202 host *findorcreatehost(const char *hostname);
203 void releasehost(host *hp);
204 realname *findrealname(const char *name);
205 realname *findorcreaterealname(const char *name);
206 void releaserealname(realname *rnp);
207
208 unsigned int nexthostmarker();
209 unsigned int nextrealnamemarker();
210 unsigned int nextnickmarker();
211
212 #endif