#include "../core/schedule.h"
#include "../lib/irc_string.h"
#include "../lib/splitline.h"
+#include "../lib/version.h"
#include "../control/control.h"
#include "../splitlist/splitlist.h"
#include "request.h"
#include "sqrequest.h"
#include "user.h"
+MODULE_VERSION("");
+
nick *rqnick;
CommandTree *rqcommands;
/* log fd */
FILE *rq_logfd;
+static int extloaded = 0;
+
void _init(void) {
+ if(!rq_initblocks())
+ return;
+
+ extloaded = 1;
+
rqcommands = newcommandtree();
addcommandtotree(rqcommands, "showcommands", RQU_ANY, 1, &rqcmd_showcommands);
addcommandtotree(rqcommands, "changelev", RQU_OPER, 2, &rqcmd_changelev);
addcommandtotree(rqcommands, "userlist", RQU_OPER, 1, &rqcmd_userlist);
- rq_initblocks();
qr_initrequest();
ru_load();
}
void _fini(void) {
+ if(!extloaded)
+ return;
+
deregisterlocaluser(rqnick, NULL);
deletecommandfromtree(rqcommands, "showcommands", &rqcmd_showcommands);
void rq_registeruser(void) {
channel *cp;
- rqnick = registerlocaluser(RQ_REQUEST_NICK, RQ_REQUEST_USER, RQ_REQUEST_HOST,
- RQ_REQUEST_REAL, RQ_REQUEST_AUTH,
+ rqnick = registerlocaluserflags(RQ_REQUEST_NICK, RQ_REQUEST_USER, RQ_REQUEST_HOST,
+ RQ_REQUEST_REAL, RQ_REQUEST_AUTH, 1780711, 0,
UMODE_ACCOUNT | UMODE_SERVICE | UMODE_OPER,
rq_handler);
break;
case LU_PRIVNOTICE:
- qr_handlenotice(params[0], params[1]);
+ qr_handle_notice(params[0], params[1]);
break;
}
}
int rqcmd_showcommands(void *user, int cargc, char **cargv) {
+ nick* np = (nick*)user;
int n, i;
Command* cmdlist[50];
n = getcommandlist(rqcommands, cmdlist, 50);
- sendnoticetouser(rqnick, (nick*)user, "Available commands:");
- sendnoticetouser(rqnick, (nick*)user, "-------------------");
+ sendnoticetouser(rqnick, np, "Available commands:");
+ sendnoticetouser(rqnick, np, "-------------------");
for (i = 0; i < n; i++) {
- if ((((cmdlist[i]->level & RQU_OPER) == 0) || IsOper((nick*)user)) &&
- ((((cmdlist[i]->level & RQU_ACCOUNT) == 0) || (IsOper((nick*)user) || (IsAccount((nick*)user)) && (ru_getlevel((nick*)user) > 0)))))
- sendnoticetouser(rqnick, (nick*)user, "%s", cmdlist[i]->command->content);
+ if ((cmdlist[i]->level & RQU_OPER) && !IsOper(np))
+ continue;
+
+ if ((cmdlist[i]->level & RQU_ACCOUNT) && !(IsOper(np) || (IsAccount(np) && ru_getlevel(np) > 0)))
+ continue;
+
+ sendnoticetouser(rqnick, np, "%s", cmdlist[i]->command->content);
}
- sendnoticetouser(rqnick, (nick*)user, "End of SHOWCOMMANDS");
+ sendnoticetouser(rqnick, np, "End of SHOWCOMMANDS");
return 0;
}
-int rq_genericrequestcheck(nick *np, char *channelname, channel **cp, nick **lnick, nick **qnick) {
+int rq_genericrequestcheck(nick *np, char *channelname, channel **cp, nick **qnick) {
unsigned long *userhand;
rq_block *block;
if (!IsAccount(np)) {
- sendnoticetouser(rqnick, np, "Error: You must be authed.");
+ sendnoticetouser(rqnick, np, "Error: You must be authed to perform a service request.");
return RQ_ERROR;
}
*cp = findchannel(channelname);
if (*cp == NULL) {
- sendnoticetouser(rqnick, np, "Error: Channel %s does not exist.",
+ sendnoticetouser(rqnick, np, "Error: Channel '%s' does not exist on the network.",
channelname);
return RQ_ERROR;
}
- *lnick = getnickbynick(RQ_LNICK);
-
- if (*lnick == NULL || findserver(RQ_LSERVER) < 0) {
- sendnoticetouser(rqnick, np, "Error: %s does not seem to be online. "
- "Try again later.", RQ_LNICK);
-
- return RQ_ERROR;
- }
-
*qnick = getnickbynick(RQ_QNICK);
if (*qnick == NULL || findserver(RQ_QSERVER) < 0) {
sendnoticetouser(rqnick, np, "Error: %s does not seem to be online. "
- "Try again later.", RQ_QNICK);
+ "Please try again later.", RQ_QNICK);
return RQ_ERROR;
}
block = rq_findblock(channelname);
if (block != NULL) {
- sendnoticetouser(rqnick, np, "Error: You are not allowed to request a "
- "service to this channel.");
+ /* only say when block expires if <7 days */
+ if ( block->expires < getnettime() + 3600 * 24 * 7) {
+ sendnoticetouser(rqnick, np, "Error: You are not allowed to request a "
+ "service to '%s'. Keep waiting for at least %s before you try again.",
+ channelname, rq_longtoduration(block->expires - getnettime()));
+ /* give them another 5 minutes to think about it */
+ block->expires += 300;
+ rq_saveblocks();
+ } else {
+ sendnoticetouser(rqnick, np, "Error: You are not allowed to request a "
+ "service to '%s'.", channelname);
+ }
sendnoticetouser(rqnick, np, "Reason: %s", block->reason->content);
rq_blocked++;
int rqcmd_request(void *user, int cargc, char **cargv) {
nick *np = (nick*)user;
- nick *lnick, *qnick;
- unsigned long *lhand, *qhand;
+ nick *qnick;
+ unsigned long *qhand;
channel *cp;
int retval;
time_t now_ts;
rq_count++;
- if (rq_genericrequestcheck(np, cargv[0], &cp, &lnick, &qnick) == RQ_ERROR) {
+ if (rq_genericrequestcheck(np, cargv[0], &cp, &qnick) == RQ_ERROR) {
rq_failed++;
return RQ_ERROR;
}
- lhand = getnumerichandlefromchanhash(cp->users, lnick->numeric);
-
qhand = getnumerichandlefromchanhash(cp->users, qnick->numeric);
if (qhand != NULL) {
retval = RQ_ERROR;
- if (lhand == NULL && qhand == NULL) {
- /* try 'instant' Q request */
- retval = qr_instantrequestq(np, cp);
- }
-
- if (retval == RQ_ERROR) {
- if (lhand == NULL) {
- /* user 'wants' L */
-
- retval = lr_requestl(rqnick, np, cp, lnick);
+ retval = lr_requestl(rqnick, np, cp, qnick);
- if (rq_logfd != NULL) {
- now[0] = '\0';
- now_ts = time(NULL);
- strftime(now, sizeof(now), "%c", localtime(&now_ts));
+ if (rq_logfd != NULL) {
+ now[0] = '\0';
+ now_ts = time(NULL);
+ strftime(now, sizeof(now), "%c", localtime(&now_ts));
- fprintf(rq_logfd, "%s: request (%s) for %s from %s: Request was %s.\n", now, RQ_LNICK, cp->index->name->content, np->nick, (retval == RQ_OK) ? "accepted" : "denied");
- fflush(rq_logfd);
- }
- } else {
- /* user 'wants' Q */
-
- retval = qr_requestq(rqnick, np, cp, lnick, qnick);
- }
+ fprintf(rq_logfd, "%s: request (%s) for %s from %s!%s@%s%s%s: Request was %s.\n",
+ now, RQ_QNICK, cp->index->name->content,
+ np->nick, np->ident, np->host->name->content, IsAccount(np)?"/":"", IsAccount(np)?np->authname:"",
+ (retval == RQ_OK) ? "accepted" : "denied");
+ fflush(rq_logfd);
}
if (retval == RQ_ERROR)
int rqcmd_requestspamscan(void *user, int cargc, char **cargv) {
nick *np = (nick*)user;
channel *cp;
- nick *lnick, *qnick, *snick;
- unsigned long *lhand, *qhand, *shand;
+ nick *qnick, *snick;
+ unsigned long *qhand, *shand;
int retval;
if (cargc < 1) {
rq_count++;
- if (rq_genericrequestcheck(np, cargv[0], &cp, &lnick, &qnick) == RQ_ERROR) {
+ if (rq_genericrequestcheck(np, cargv[0], &cp, &qnick) == RQ_ERROR) {
rq_failed++;
return RQ_ERROR;
if (snick == NULL || findserver(RQ_SSERVER) < 0) {
sendnoticetouser(rqnick, np, "Error: %s does not seem to be online. "
- "Try again later.", RQ_SNICK);
+ "Please try again later.", RQ_SNICK);
rq_failed++;
return RQ_ERROR;
}
- /* we need either L or Q */
- lhand = getnumerichandlefromchanhash(cp->users, lnick->numeric);
+ /* we need Q */
qhand = getnumerichandlefromchanhash(cp->users, qnick->numeric);
- if (lhand || qhand) {
+ if (qhand) {
/* great, now try to request */
- retval = qr_requests(rqnick, np, cp, lnick, qnick);
+ retval = qr_requests(rqnick, np, cp, qnick);
if (retval == RQ_OK)
rq_success++;
return retval;
} else {
- /* channel apparently doesn't have L or Q */
+ /* channel apparently doesn't have Q */
- sendnoticetouser(rqnick, np, "Error: You need %s or %s in order to be "
- "able to request %s.", RQ_LNICK, RQ_QNICK, RQ_SNICK);
+ sendnoticetouser(rqnick, np, "Error: You need %s in order to be "
+ "able to request %s.", RQ_QNICK, RQ_SNICK);
rq_failed++;
cp = findchannel(cargv[0]);
if (cp == NULL) {
- sendnoticetouser(rqnick, np, "Error: No such channel.");
+ sendnoticetouser(rqnick, np, "Error: Channel '%s' does not exist on the network.",
+ cargv[0]);
return CMD_ERROR;
}
hand = getnumerichandlefromchanhash(cp->users, user->numeric);
if (!hand) {
- sendnoticetouser(rqnick, np, "Error: User %s is not on channel %s.", user->nick, cargv[0]);
+ sendnoticetouser(rqnick, np, "Error: User %s is not on channel '%s'.", user->nick, cargv[0]);
return CMD_ERROR;
}
if(cp->users->content[a] != nouser) {
np2 = getnickbynumeric(cp->users->content[a]);
- if (IsService(np2) && !(cp->users->content[a] & CUMODE_OP)) {
+ if (IsService(np2) && (np2->nick[1] == '\0') && !(cp->users->content[a] & CUMODE_OP)) {
localdosetmode_nick(&changes, np2, MC_OP);
count++;
}
for (a=0;a<cp->users->hashsize;a++) {
if ((cp->users->content[a] != nouser) && (cp->users->content[a] & CUMODE_OP)) {
- sendnoticetouser(rqnick, np, "There are ops on channel %s. This command can only be"
+ sendnoticetouser(rqnick, np, "There are ops on channel '%s'. This command can only be"
" used if there are no ops.", cargv[0]);
return CMD_ERROR;