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