]> jfr.im git - irc/quakenet/newserv.git/blob - request/lrequest.c
51d7ebd86008606c395d05d250131dffd09ae557
[irc/quakenet/newserv.git] / request / lrequest.c
1 /* required modules: splitlist, chanfix(3) */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include "request.h"
6 #include "lrequest.h"
7 #include "request_block.h"
8 #include "request_fasttrack.h"
9 #include "../localuser/localuser.h"
10
11 /* stats counters */
12 int lr_top5 = 0;
13 int lr_notargets = 0;
14
15 #define min(a,b) ((a > b) ? b : a)
16
17 int lr_requestl(nick *svc, nick *np, channel *cp, nick *qnick) {
18 chanfix *cf;
19 regop *rolist[LR_TOPX], *ro;
20 int i, rocount;
21
22 if (strlen(cp->index->name->content) > LR_MAXCHANLEN) {
23 sendnoticetouser(svc, np, "Sorry, your channel name is too long. You will have to "
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
32 if(cf) {
33 rocount = cf_getsortedregops(cf, LR_TOPX, rolist);
34
35 ro = NULL;
36
37 for (i = 0; i < min(LR_TOPX, rocount); i++) {
38 if (cf_cmpregopnick(rolist[i], np)) {
39 ro = rolist[i];
40 break;
41 }
42 }
43
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);
47
48 lr_top5++;
49
50 return RQ_ERROR;
51 }
52 }
53
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 "
57 "channel at this time. Please try again in an hour.", RQ_QNICK);
58
59 lr_notargets++;
60
61 return RQ_ERROR;
62 }
63
64 sendmessagetouser(svc, qnick, "addchan %s #%s +jp upgrade %s", cp->index->name->content,
65 np->authname, np->nick);
66
67 sendnoticetouser(svc, np, "Success! %s has been added to '%s' "
68 "(contact #help if you require further assistance).",
69 RQ_QNICK, cp->index->name->content);
70
71 return RQ_OK;
72 }
73
74 void lr_requeststats(nick *rqnick, nick *np) {
75 sendnoticetouser(rqnick, np, "- Too many requests (Q): %d", lr_notargets);
76 sendnoticetouser(rqnick, np, "- Not in top%d (Q): %d", LR_TOPX, lr_top5);
77 }