]> jfr.im git - irc/quakenet/newserv.git/blame - request/lrequest.c
LUA: port luadb to dbapi2 to drop postgres dependency
[irc/quakenet/newserv.git] / request / lrequest.c
CommitLineData
25b7d0fa
P
1/* required modules: splitlist, chanfix(3) */
2
052247fa 3#include <stdio.h>
f011b15a 4#include <string.h>
25b7d0fa
P
5#include "request.h"
6#include "lrequest.h"
7#include "request_block.h"
6fec1818 8#include "request_fasttrack.h"
25b7d0fa
P
9#include "../localuser/localuser.h"
10
11/* stats counters */
25b7d0fa 12int lr_top5 = 0;
7db1638d 13int lr_notargets = 0;
25b7d0fa
P
14
15#define min(a,b) ((a > b) ? b : a)
16
95440fe7 17int lr_requestl(nick *svc, nick *np, channel *cp, nick *qnick) {
25b7d0fa
P
18 chanfix *cf;
19 regop *rolist[LR_TOPX], *ro;
20 int i, rocount;
21
22 if (strlen(cp->index->name->content) > LR_MAXCHANLEN) {
43d341bd 23 sendnoticetouser(svc, np, "Sorry, your channel name is too long. You will have to "
25b7d0fa
P
24 "create a channel with a name less than %d characters long.",
25 LR_MAXCHANLEN + 1);
26
27 return RQ_ERROR;
28 }
29
30 cf = cf_findchanfix(cp->index);
31
6fec1818
GB
32 if(cf) {
33 rocount = cf_getsortedregops(cf, LR_TOPX, rolist);
25b7d0fa 34
6fec1818 35 ro = NULL;
25b7d0fa 36
6fec1818
GB
37 for (i = 0; i < min(LR_TOPX, rocount); i++) {
38 if (cf_cmpregopnick(rolist[i], np)) {
39 ro = rolist[i];
40 break;
41 }
25b7d0fa 42 }
25b7d0fa 43
6fec1818
GB
44 if (ro == NULL) {
45 sendnoticetouser(svc, np, "Sorry, you must be one of the top %d ops "
46 "for the channel '%s'.", LR_TOPX, cp->index->name->content);
25b7d0fa 47
6fec1818 48 lr_top5++;
25b7d0fa 49
6fec1818
GB
50 return RQ_ERROR;
51 }
25b7d0fa
P
52 }
53
7db1638d
GB
54 /* treat blocked users as if they're out of targets */
55 if(rq_findblock(np->authname) || !rq_tryfasttrack(np)) {
56 sendnoticetouser(svc, np, "Sorry, you may not request %s for another "
7e6b4e43 57 "channel at this time. Please try again in an hour.", rq_qnick->content);
25b7d0fa 58
7db1638d 59 lr_notargets++;
25b7d0fa 60
7db1638d 61 return RQ_ERROR;
25b7d0fa 62 }
7db1638d 63
95440fe7 64 sendmessagetouser(svc, qnick, "addchan %s #%s +jp upgrade %s", cp->index->name->content,
25b7d0fa
P
65 np->authname, np->nick);
66
43d341bd
C
67 sendnoticetouser(svc, np, "Success! %s has been added to '%s' "
68 "(contact #help if you require further assistance).",
7e6b4e43 69 rq_qnick->content, cp->index->name->content);
25b7d0fa
P
70
71 return RQ_OK;
72}
73
74void lr_requeststats(nick *rqnick, nick *np) {
bb4ad676 75 sendnoticetouser(rqnick, np, "- Too many requests (Q): %d", lr_notargets);
95440fe7 76 sendnoticetouser(rqnick, np, "- Not in top%d (Q): %d", LR_TOPX, lr_top5);
25b7d0fa 77}