]> jfr.im git - irc/quakenet/newserv.git/blame - request/lrequest.c
CHANSERV: refactor for autocleanup
[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"
8#include "../localuser/localuser.h"
9
10/* stats counters */
11int lr_noregops = 0;
12int lr_scoretoolow = 0;
13int lr_top5 = 0;
14int lr_floodattempts = 0;
15
16#define min(a,b) ((a > b) ? b : a)
17
95440fe7 18int lr_requestl(nick *svc, nick *np, channel *cp, nick *qnick) {
25b7d0fa
P
19 chanfix *cf;
20 regop *rolist[LR_TOPX], *ro;
21 int i, rocount;
22
23 if (strlen(cp->index->name->content) > LR_MAXCHANLEN) {
43d341bd 24 sendnoticetouser(svc, np, "Sorry, your channel name is too long. You will have to "
25b7d0fa
P
25 "create a channel with a name less than %d characters long.",
26 LR_MAXCHANLEN + 1);
27
28 return RQ_ERROR;
29 }
30
31 cf = cf_findchanfix(cp->index);
32
33 if (cf == NULL) {
43d341bd
C
34 sendnoticetouser(svc, np, "Sorry, your channel '%s' was created recently. "
35 "Please try again in an hour.", cp->index->name->content);
25b7d0fa
P
36
37 lr_noregops++;
38
39 return RQ_ERROR;
40 }
41
42 rocount = cf_getsortedregops(cf, LR_TOPX, rolist);
43
44 ro = NULL;
45
46 for (i = 0; i < min(LR_TOPX, rocount); i++) {
47 if (cf_cmpregopnick(rolist[i], np)) {
48 ro = rolist[i];
49 break;
50 }
51 }
52
53 if (ro == NULL) {
43d341bd
C
54 sendnoticetouser(svc, np, "Sorry, you must be one of the top %d ops "
55 "for the channel '%s'.", LR_TOPX, cp->index->name->content);
25b7d0fa
P
56
57 lr_top5++;
58
59 return RQ_ERROR;
60 }
61
62 /* treat blocked users as if their score is too low */
63 if (ro->score < LR_CFSCORE || rq_findblock(np->authname)) {
64 if (rq_isspam(np)) {
43d341bd 65 sendnoticetouser(svc, np, "Do not flood the request system. "
25b7d0fa
P
66 "Try again in %s.", rq_longtoduration(rq_blocktime(np)));
67
68 lr_floodattempts++;
69
70 return RQ_ERROR;
71 }
72
43d341bd
C
73 sendnoticetouser(svc, np, "Sorry, you do not meet the "
74 "%s request requirements; please try again in an hour, "
75 "see http://www.quakenet.org/faq/faq.php?c=1&f=6#6", RQ_QNICK);
25b7d0fa
P
76
77 lr_scoretoolow++;
78
79 return RQ_ERROR;
80 }
81
95440fe7
P
82
83 sendmessagetouser(svc, qnick, "addchan %s #%s +jp upgrade %s", cp->index->name->content,
25b7d0fa
P
84 np->authname, np->nick);
85
43d341bd
C
86 sendnoticetouser(svc, np, "Success! %s has been added to '%s' "
87 "(contact #help if you require further assistance).",
88 RQ_QNICK, cp->index->name->content);
25b7d0fa
P
89
90 return RQ_OK;
91}
92
93void lr_requeststats(nick *rqnick, nick *np) {
95440fe7
P
94 sendnoticetouser(rqnick, np, "- No registered ops (Q): %d", lr_noregops);
95 sendnoticetouser(rqnick, np, "- Score too low (Q): %d", lr_scoretoolow);
96 sendnoticetouser(rqnick, np, "- Not in top%d (Q): %d", LR_TOPX, lr_top5);
97 sendnoticetouser(rqnick, np, "- Floods (Q): %d", lr_floodattempts);
25b7d0fa 98}