]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/formats.c
LUA: port luadb to dbapi2 to drop postgres dependency
[irc/quakenet/newserv.git] / newsearch / formats.c
1
2 #include <stdio.h>
3 #include "newsearch.h"
4
5 #include "../irc/irc_config.h"
6 #include "../lib/irc_string.h"
7 #include "../parser/parser.h"
8 #include "../control/control.h"
9 #include "../lib/splitline.h"
10 #include "../lib/version.h"
11
12 void printnick(searchCtx *ctx, nick *sender, nick *np) {
13 char hostbuf[HOSTLEN+NICKLEN+USERLEN+4];
14
15 ctx->reply(sender,"%s [%s] (%s) (%s)",visiblehostmask(np,hostbuf),
16 IPtostr(np->ipaddress), printflags(np->umodes, umodeflags), np->realname->name->content);
17 }
18
19 void printnick_channels(searchCtx *ctx, nick *sender, nick *np) {
20 char chanlistbuf[512];
21 unsigned int bufpos=0, overflow=0;
22 channel **cs, *cp;
23 unsigned int i;
24 unsigned long *lp;
25
26 /* Include the default format too */
27 printnick(ctx, sender,np);
28
29 /* Now add the channels.. */
30 cs=(channel **)(np->channels->content);
31 for (i=0;i<np->channels->cursi;i++) {
32 cp=cs[i];
33
34 if (!(lp=getnumerichandlefromchanhash(cp->users,np->numeric)))
35 /* "Impossible" error case - nick not on this channel */
36 continue;
37
38 if (bufpos + cp->index->name->length > 400) {
39 overflow=1;
40 break;
41 }
42
43 if (*lp & CUMODE_OP) {
44 chanlistbuf[bufpos++]='@';
45 } else if (*lp & CUMODE_VOICE) {
46 chanlistbuf[bufpos++]='+';
47 }
48
49 bufpos+=sprintf(chanlistbuf+bufpos,"%s ",cp->index->name->content);
50 }
51
52 if (!bufpos) {
53 ctx->reply(sender," Not an any channels.");
54 } else {
55 ctx->reply(sender," On channel%s: %s%s",np->channels->cursi>1?"s":"", chanlistbuf, overflow?"[...]":"");
56 }
57 }
58
59 void printchannel(searchCtx *ctx, nick *sender, chanindex *cip) {
60 /* shamelessly stolen from (now defunct) chansearch.c */
61 int i;
62 int op,voice,peon;
63 int oper,service,hosts;
64 nick *np;
65 chanuserhash *cuhp;
66 unsigned int marker;
67
68 op=voice=peon=oper=service=hosts=0;
69 marker=nexthostmarker();
70
71 if (cip->channel==NULL) {
72 ctx->reply(sender,"[ Channel currently empty ] %s",cip->name->content);
73 } else {
74 cuhp=cip->channel->users;
75 for (i=0;i<cuhp->hashsize;i++) {
76 if (cuhp->content[i]!=nouser) {
77 if (cuhp->content[i]&CUMODE_OP) {
78 op++;
79 } else if (cuhp->content[i]&CUMODE_VOICE) {
80 voice++;
81 } else {
82 peon++;
83 }
84 if ((np=getnickbynumeric(cuhp->content[i]&CU_NUMERICMASK))!=NULL) {
85 if (IsOper(np)) {
86 oper++;
87 }
88 if (IsService(np)) {
89 service++;
90 }
91 if (np->host->marker!=marker) {
92 np->host->marker=marker;
93 hosts++;
94 }
95 }
96 }
97 }
98 ctx->reply(sender,"[ %4dU %4d@ %4d+ %4d %4d* %4dk %4dH ] %s (%s)",cuhp->totalusers,op,voice,peon,oper,
99 service,hosts,cip->name->content, printflags(cip->channel->flags, cmodeflags));
100 }
101 }
102
103
104 void printchannel_topic(searchCtx *ctx, nick *sender, chanindex *cip) {
105 if (cip->channel==NULL) {
106 ctx->reply(sender,"[ empty ] %-30s",cip->name->content);
107 } else {
108 ctx->reply(sender,"[%4u users] %s (%s)",cip->channel->users->totalusers,cip->name->content,cip->channel->topic?cip->channel->topic->content:"no topic");
109 }
110 }
111
112 void printchannel_services(searchCtx *ctx, nick *sender, chanindex *cip) {
113 int i;
114 chanuserhash *cuhp;
115 char servlist[300];
116 int slpos=0,slfull=0;
117 nick *np;
118 int servs=0;
119
120 if (cip->channel==NULL) {
121 ctx->reply(sender,"%-30s empty",cip->name->content);
122 } else {
123 cuhp=cip->channel->users;
124 for (i=0;i<cuhp->hashsize;i++) {
125 if (cuhp->content[i]!=nouser) {
126 if ((np=getnickbynumeric(cuhp->content[i]&CU_NUMERICMASK))) {
127 if (IsService(np)) {
128 servs++;
129 if (!slfull) {
130 if (slpos) {
131 slpos+=sprintf(&servlist[slpos],", ");
132 }
133 slpos+=sprintf(&servlist[slpos],"%s",np->nick);
134 if (slpos>280) {
135 sprintf(&servlist[slpos],", ...");
136 slfull=1;
137 }
138 }
139 }
140 }
141 }
142 }
143
144 ctx->reply(sender,"%-30s %5d user%c %2d service%c %s%s%s",cip->name->content,cuhp->totalusers,
145 cuhp->totalusers>1?'s':' ',servs,(servs==1)?' ':'s',servs?"(":"",slpos?servlist:"",servs?")":"");
146 }
147 }
148
149 void printuser(searchCtx *ctx, nick *sender, authname *aup) {
150 ctx->reply(sender,"%d", aup->userid);
151 }
152
153 void printwhowas(searchCtx *ctx, nick *sender, whowas *ww) {
154 ctx->reply(sender,"%s", whowas_format(ww));
155 ctx->reply(sender,"%s", whowas_formatchannels(ww));
156 }