]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanservhash.c
3 * Handles insertion and retrieval of various data structures
4 * from their respective hashes. Hopefully it's obvious from
5 * the name of each function what it does.
11 #include "../lib/irc_string.h"
13 reguser
*regusernicktable
[REGUSERHASHSIZE
];
14 reguser
*reguserIDtable
[REGUSERHASHSIZE
];
16 #define regusernickhash(x) ((crc32i(x))%REGUSERHASHSIZE)
17 #define reguserIDhash(x) ((x)%REGUSERHASHSIZE)
19 void chanservhashinit() {
20 memset(regusernicktable
,0,REGUSERHASHSIZE
*sizeof(reguser
*));
21 memset(reguserIDtable
,0,REGUSERHASHSIZE
*sizeof(reguser
*));
24 void addregusertohash(reguser
*rup
) {
27 hash
=regusernickhash(rup
->username
);
29 rup
->nextbyname
=regusernicktable
[hash
];
30 regusernicktable
[hash
]=rup
;
32 hash
=reguserIDhash(rup
->ID
);
34 rup
->nextbyID
=reguserIDtable
[hash
];
35 reguserIDtable
[hash
]=rup
;
38 reguser
*findreguserbynick(const char *nick
) {
39 unsigned int hashnick
;
42 hashnick
=regusernickhash(nick
);
43 for (rup
=regusernicktable
[hashnick
];rup
;rup
=rup
->nextbyname
) {
44 if (!ircd_strcmp(nick
,rup
->username
)) {
53 reguser
*findreguserbyID(unsigned int ID
) {
57 hash
=reguserIDhash(ID
);
58 for (rup
=reguserIDtable
[hash
];rup
;rup
=rup
->nextbyID
)
68 * This function does the standard "nick or #user" lookup.
69 * If "sender" is not NULL, a suitable error message will
70 * be sent if the lookup fails
73 reguser
*findreguser(nick
*sender
, const char *str
) {
83 chanservstdmessage(sender
, QM_UNKNOWNUSER
, str
);
86 if (!(rup
=findreguserbynick(str
+1)) && sender
)
87 chanservstdmessage(sender
, QM_UNKNOWNUSER
, str
);
89 if (!(np
=getnickbynick(str
))) {
91 chanservstdmessage(sender
, QM_UNKNOWNUSER
, str
);
94 if (!(rup
=getreguserfromnick(np
)) && sender
)
95 chanservstdmessage(sender
, QM_USERNOTAUTHED
, str
);
98 if (rup
&& (UIsSuspended(rup
) || (rup
->status
& QUSTAT_DEAD
))) {
99 chanservstdmessage(sender
, QM_USERHASBADAUTH
, rup
->username
);
107 * findreguserbyemail()
109 reguser
*findreguserbyemail(const char *email
) {
113 for (i
=0;i
<REGUSERHASHSIZE
;i
++) {
114 for (rup
=regusernicktable
[i
];rup
;rup
=rup
->nextbyname
) {
115 if (!ircd_strcmp(email
,rup
->email
->content
)) {
124 void removereguserfromhash(reguser
*rup
) {
129 hash
=regusernickhash(rup
->username
);
132 for (ruh
=&(regusernicktable
[hash
]);*ruh
;ruh
=&((*ruh
)->nextbyname
)) {
134 *ruh
=(rup
->nextbyname
);
141 Error("chanserv",ERR_ERROR
,"Unable to remove reguser %s from nickhash",
145 hash
=reguserIDhash(rup
->ID
);
148 for (ruh
=&(reguserIDtable
[hash
]);*ruh
;ruh
=&((*ruh
)->nextbyID
)) {
150 *ruh
=(rup
->nextbyID
);
157 Error("chanserv",ERR_ERROR
,"Unable to remove reguser %s from ID hash",rup
->ID
);
161 void addregusertochannel(regchanuser
*rcup
) {
162 rcup
->nextbyuser
=(rcup
->user
->knownon
);
163 rcup
->nextbychan
=(rcup
->chan
->regusers
[(rcup
->user
->ID
)%REGCHANUSERHASHSIZE
]);
165 rcup
->user
->knownon
=rcup
;
166 rcup
->chan
->regusers
[(rcup
->user
->ID
)%REGCHANUSERHASHSIZE
]=rcup
;
169 regchanuser
*findreguseronchannel(regchan
*rcp
, reguser
*rup
) {
172 for (rcup
=rcp
->regusers
[(rup
->ID
)%REGCHANUSERHASHSIZE
];rcup
;rcup
=rcup
->nextbychan
) {
173 if (rcup
->user
==rup
) {
182 void delreguserfromchannel(regchan
*rcp
, reguser
*rup
) {
186 for (rcuh
=&(rcp
->regusers
[(rup
->ID
)%REGCHANUSERHASHSIZE
]);*rcuh
;
187 rcuh
=&((*rcuh
)->nextbychan
)) {
188 if ((*rcuh
)->user
==rup
) {
190 freesstring((*rcuh
)->info
);
191 *rcuh
=(*rcuh
)->nextbychan
;
198 Error("chanserv",ERR_ERROR
,"Unable to remove user %s from channel %s",
199 rup
->username
,rcp
->index
->name
->content
);
203 for (rcuh
=&(rup
->knownon
);*rcuh
;rcuh
=&((*rcuh
)->nextbyuser
)) {
204 if ((*rcuh
)->chan
==rcp
) {
205 /* Found the channel */
206 *rcuh
=(*rcuh
)->nextbyuser
;
211 Error("chanserv",ERR_ERROR
,"Unable to remove channel %s from user %s",
212 rcp
->index
->name
->content
,rup
->username
);