From: splidge Date: Thu, 3 Dec 2009 17:13:42 +0000 (+0000) Subject: NICK: Add "away" functionality. X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/5144ddc4eb819c4bff9b931d320c7a2324c6998c?ds=sidebyside NICK: Add "away" functionality. - New member of nick structure + Code to initialize in localuser / nick modules - Handler for "A" token to update value + Code to register it - Added to control's "WHOIS" command - Added newsearch term --- diff --git a/control/control.c b/control/control.c index d29f9387..43e584be 100644 --- a/control/control.c +++ b/control/control.c @@ -267,6 +267,10 @@ int controlwhois(void *sender, int cargc, char **cargv) { } } + if (target->away) { + controlreply((nick *)sender, "Away : %s",target->away->content); + } + hooknick=(nick *)sender; registerhook(HOOK_CONTROL_WHOISREPLY,&handlewhois); triggerhook(HOOK_CONTROL_WHOISREQUEST,target); diff --git a/irc/irc_config.h b/irc/irc_config.h index 4d8202d0..4f7f254b 100644 --- a/irc/irc_config.h +++ b/irc/irc_config.h @@ -10,6 +10,7 @@ #define TOPICLEN 250 #define CHANNELLEN 200 #define KEYLEN 23 +#define AWAYLEN 160 #define MAXSERVERS 4096 diff --git a/localuser/localuser.c b/localuser/localuser.c index c7db7cb1..dd11918b 100644 --- a/localuser/localuser.c +++ b/localuser/localuser.c @@ -114,6 +114,7 @@ nick *registerlocaluserflags(char *nickname, char *ident, char *host, char *real newuser->timestamp=getnettime(); newuser->shident=NULL; newuser->sethost=NULL; + newuser->away=NULL; newuser->marker=0; memset(newuser->exts, 0, MAXNICKEXTS * sizeof(void *)); diff --git a/newsearch/newsearch.c b/newsearch/newsearch.c index 100ddf94..d4531b4c 100644 --- a/newsearch/newsearch.c +++ b/newsearch/newsearch.c @@ -178,6 +178,7 @@ void _init() { /* Nickname operations */ registersearchterm(reg_nicksearch, "hostmask",hostmask_parse, 0, "The user's nick!user@host; \"hostmask real\" returns nick!user@host\rreal"); /* nick only */ registersearchterm(reg_nicksearch, "realname",realname_parse, 0, "User's current realname"); /* nick only */ + registersearchterm(reg_nicksearch, "away",away_parse, 0, "User's current away message"); /* nick only */ registersearchterm(reg_nicksearch, "authname",authname_parse, 0, "User's current authname or false"); /* nick only */ registersearchterm(reg_nicksearch, "authts",authts_parse, 0, "User's Auth timestamp"); /* nick only */ registersearchterm(reg_nicksearch, "ident",ident_parse, 0, "User's current ident"); /* nick only */ diff --git a/newsearch/newsearch.h b/newsearch/newsearch.h index 9b4a26e9..727886a0 100644 --- a/newsearch/newsearch.h +++ b/newsearch/newsearch.h @@ -126,6 +126,7 @@ struct searchNode *modes_parse(searchCtx *ctx, int argc, char **argv); /* Nick functions (various types) */ struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *realname_parse(searchCtx *ctx, int argc, char **argv); +struct searchNode *away_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *authname_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *authts_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *ident_parse(searchCtx *ctx, int argc, char **argv); diff --git a/newsearch/ns-away.c b/newsearch/ns-away.c new file mode 100644 index 00000000..fb09e78c --- /dev/null +++ b/newsearch/ns-away.c @@ -0,0 +1,38 @@ +/* + * AWAY functionality + */ + +#include "newsearch.h" + +#include +#include + +void *away_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); +void away_free(searchCtx *ctx, struct searchNode *thenode); + +struct searchNode *away_parse(searchCtx *ctx, int argc, char **argv) { + struct searchNode *thenode; + + if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { + parseError = "malloc: could not allocate memory for this search."; + return NULL; + } + + thenode->returntype = RETURNTYPE_STRING; + thenode->localdata = NULL; + thenode->exe = away_exe; + thenode->free = away_free; + + return thenode; +} + +void *away_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { + nick *np = (nick *)theinput; + + return (np->away) ? np->away->content : ""; +} + +void away_free(searchCtx *ctx, struct searchNode *thenode) { + free(thenode); +} + diff --git a/nick/nick.c b/nick/nick.c index c43a87e0..3b9dead2 100644 --- a/nick/nick.c +++ b/nick/nick.c @@ -91,6 +91,7 @@ void _init() { registerserverhandler("AC",&handleaccountmsg,4); registerserverhandler("R",&handlestatsmsg,2); registerserverhandler("P",&handleprivmsg,2); + registerserverhandler("A",&handleawaymsg,1); /* Fake the addition of our own server */ handleserverchange(HOOK_SERVER_NEWSERVER,(void *)numerictolong(mynumeric->content,2)); @@ -128,6 +129,7 @@ void _fini() { deregisterserverhandler("AC",&handleaccountmsg); deregisterserverhandler("R",&handlestatsmsg); deregisterserverhandler("P",&handleprivmsg); + deregisterserverhandler("A",&handleawaymsg); } /* diff --git a/nick/nick.h b/nick/nick.h index 8fbe01e4..004aa4b1 100644 --- a/nick/nick.h +++ b/nick/nick.h @@ -140,6 +140,7 @@ typedef struct nick { authname *auth; /* This requires User ID numbers to work */ time_t timestamp; time_t accountts; + sstring *away; patricia_node_t *ipnode; unsigned int marker; struct nick *next; @@ -207,6 +208,7 @@ int handlewhoismsg(void *source, int cargc, char **cargv); int handleaccountmsg(void *source, int cargc, char **cargv); int handlestatsmsg(void *source, int cargc, char **cargv); int handleprivmsg(void *source, int cargc, char **cargv); +int handleawaymsg(void *source, int cargc, char **cargv); /* These functions have been replaced by macros nick **gethandlebynumeric(long numeric); diff --git a/nick/nickhandlers.c b/nick/nickhandlers.c index 86c35905..282139f3 100644 --- a/nick/nickhandlers.c +++ b/nick/nickhandlers.c @@ -143,6 +143,7 @@ int handlenickmsg(void *source, int cargc, char **cargv) { np->ipnode = refnode(iptree, &ipaddress, PATRICIA_MAXBITS); node_increment_usercount(np->ipnode); + np->away=NULL; np->shident=NULL; np->sethost=NULL; np->opername=NULL; @@ -527,3 +528,22 @@ int handleprivmsg(void *source, int cargc, char **cargv) { return CMD_OK; } +int handleawaymsg(void *source, int cargc, char **cargv) { + nick *sender; + + /* Check source is a valid user */ + if (!(sender=getnickbynumericstr(source))) { + return CMD_OK; + } + + /* Done with the old away message either way */ + freesstring(sender->away); + sender->away=NULL; + + /* If we have an arg and it isn't an empty string, this sets a new message */ + if (cargc > 0 && *(cargv[0])) { + sender->away=getsstring(cargv[0], AWAYLEN); + } + + return CMD_OK; +}