#include "../server/server.h"
#include "../parser/parser.h"
#include "../lib/version.h"
+#include "../core/nsmalloc.h"
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
{ 'h', UMODE_SETHOST },
{ 'R', UMODE_REGPRIV },
{ 'I', UMODE_HIDEIDLE },
+ { 'P', UMODE_PARANOID },
+ { '\0', 0 } };
+
+const flag accountflags[] = {
+ { 'q', AFLAG_STAFF },
+ { 'h', AFLAG_SUPPORT },
+ { 'o', AFLAG_OPER },
+ { 'a', AFLAG_ADMIN },
+ { 'd', AFLAG_DEVELOPER },
{ '\0', 0 } };
#define nickhash(x) ((crc32i(x))%NICKHASHSIZE)
void nickstats(int hooknum, void *arg);
void _init() {
+ unsigned int i;
+ authname *anp;
+
+ /* Clear up the nicks in authext */
+ for (i=0;i<AUTHNAMEHASHSIZE;i++)
+ for (anp=authnametable[i];anp;anp=anp->next)
+ anp->nicks=NULL;
+
initnickalloc();
initnickhelpers();
memset(nicktable,0,sizeof(nicktable));
registerserverhandler("Q",&handlequitmsg,1);
registerserverhandler("M",&handleusermodemsg,3);
registerserverhandler("W",&handlewhoismsg,2);
- registerserverhandler("AC",&handleaccountmsg,2);
+ registerserverhandler("AC",&handleaccountmsg,4);
registerserverhandler("R",&handlestatsmsg,2);
+ registerserverhandler("P",&handleprivmsg,2);
/* Fake the addition of our own server */
handleserverchange(HOOK_SERVER_NEWSERVER,(void *)numerictolong(mynumeric->content,2));
}
+void _fini() {
+ nick *np;
+ int i;
+
+ fininickhelpers();
+
+ for (i=0;i<NICKHASHSIZE;i++) {
+ for (np=nicktable[i];np;np=np->next) {
+ freesstring(np->shident);
+ freesstring(np->sethost);
+ freesstring(np->opername);
+ if(!np->auth && np->authname)
+ free(np->authname);
+ }
+ }
+
+ nsfreeall(POOL_NICK);
+
+ /* Free the hooks */
+ deregisterhook(HOOK_SERVER_NEWSERVER,&handleserverchange);
+ deregisterhook(HOOK_SERVER_LOSTSERVER,&handleserverchange);
+ deregisterhook(HOOK_CORE_STATSREQUEST,&nickstats);
+
+ /* And our server handlers */
+ deregisterserverhandler("N",&handlenickmsg);
+ deregisterserverhandler("D",&handlekillmsg);
+ deregisterserverhandler("Q",&handlequitmsg);
+ deregisterserverhandler("M",&handleusermodemsg);
+ deregisterserverhandler("W",&handlewhoismsg);
+ deregisterserverhandler("AC",&handleaccountmsg);
+ deregisterserverhandler("R",&handlestatsmsg);
+ deregisterserverhandler("P",&handleprivmsg);
+}
+
/*
* This function handles servers appearing and disappearing.
* For a new server, the client table is allocated.
*/
void handleserverchange(int hooknum, void *arg) {
- int servernum;
+ long servernum;
int i;
- servernum=(int)arg;
+ servernum=(long)arg;
switch(hooknum) {
case HOOK_SERVER_NEWSERVER:
- servernicks[servernum]=(nick **)malloc((serverlist[servernum].maxusernum+1)*sizeof(nick **));
+ servernicks[servernum]=(nick **)nsmalloc(POOL_NICK,(serverlist[servernum].maxusernum+1)*sizeof(nick **));
memset(servernicks[servernum],0,(serverlist[servernum].maxusernum+1)*sizeof(nick **));
break;
deletenick(servernicks[servernum][i]);
}
}
- free(servernicks[servernum]);
+ nsfree(POOL_NICK,servernicks[servernum]);
break;
}
}
releaserealname(np->realname);
releasehost(np->host);
+ if(IsAccount(np)) {
+ if(!np->auth) {
+ if(np->authname)
+ free(np->authname);
+ } else {
+ np->auth->usercount--;
+
+ for (nh=&(np->auth->nicks);*nh;nh=&((*nh)->nextbyauthname)) {
+ if (*nh==np) {
+ *nh=np->nextbyauthname;
+ break;
+ }
+ }
+
+ releaseauthname(np->auth);
+ }
+ }
+
freesstring(np->shident); /* freesstring(NULL) is OK */
freesstring(np->sethost);
+ freesstring(np->opername);
+
+ node_decrement_usercount(np->ipnode);
+ derefnode(iptree, np->ipnode);
+
+ /* TODO: figure out how to cleanly remove nodes without affecting other modules */
/* Delete the nick from the servernick table */
*(gethandlebynumericunsafe(np->numeric))=NULL;
}
}
- if ((int)arg>5) {
+ if ((long)arg>5) {
/* Full stats */
sprintf(buf,"Nick : %6d nicks (HASH: %6d/%6d, chain %3d)",total,buckets,NICKHASHSIZE,maxchain);
- } else if ((int)arg>2) {
+ } else if ((long)arg>2) {
sprintf(buf,"Nick : %6d users on network.",total);
}
- if ((int)arg>2) {
+ if ((long)arg>2) {
triggerhook(HOOK_CORE_STATSREPLY,buf);
}
}
}
}
- Error("channel",ERR_WARNING,"Tried to register too many extensions: %s",name);
+ Error("nick",ERR_WARNING,"Tried to register too many nick extensions: %s",name);
return -1;
}
*/
char *visiblehostmask(nick *np, char *buf) {
+ char uhbuf[USERLEN+HOSTLEN+2];
+
+ visibleuserhost(np, uhbuf);
+ sprintf(buf,"%s!%s",np->nick,uhbuf);
+
+ return buf;
+}
+
+/* visibleuserhost
+ * As above without nick
+ */
+
+char *visibleuserhost(nick *np, char *buf) {
char hostbuf[HOSTLEN+1];
char *ident, *host;
host=hostbuf;
}
- sprintf(buf,"%s!%s@%s",np->nick,ident,host);
+ sprintf(buf,"%s@%s",ident,host);
return buf;
}
}
#endif
+