Skip to content

Commit 0cd3c8f

Browse files
authored
qline mod
1 parent fb39005 commit 0cd3c8f

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

files/qline.c

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Q-LINE MODULE: Provides the /QLINE and /UNQLINE commands, allowing O-lined users with the server-ban:gline privs to manually add Q-lines (global nick bans)
3+
* at the server level, rather than relying on Services to do so via the /(UN)SQLINE server-only command or config file access.
4+
*
5+
* USAGE:
6+
*
7+
* Add a new Q-line entry: /QLINE <nickmask> :<Reason>
8+
* Delete an active Q-line entry: /UNQLINE <nickmask>
9+
* -----------------------------------------------------------------------------------------------------------------------------------------------
10+
* MIT License
11+
*
12+
* Copyright (c) 2022 Avery 'Hexick' Q. [pseudonym]
13+
*
14+
* Permission is hereby granted, free of charge, to any person obtaining a copy
15+
* of this software and associated documentation files (the "Software"), to deal
16+
* in the Software without restriction, including without limitation the rights
17+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
* copies of the Software, and to permit persons to whom the Software is
19+
* furnished to do so, subject to the following conditions:
20+
*
21+
* The above copyright notice and this permission notice shall be included in all
22+
* copies or substantial portions of the Software.
23+
*
24+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*/
32+
33+
/*** <<<MODULE MANAGER START>>>
34+
module
35+
{
36+
documentation "https://github.com/Hexsl/hex-unrealircd-modules/blob/main/modules/qline/README.md";
37+
troubleshooting "I go by Hex on the UnrealIRCd network, and can also be emailed at [email protected]";
38+
min-unrealircd-version "6.*";
39+
max-unrealircd-version "6.*";
40+
post-install-text {
41+
"The module is installed. Now all you need to do is add a loadmodule line:";
42+
"loadmodule \"third/qline\";";
43+
"And then /rehash";
44+
}
45+
}
46+
*** <<<MODULE MANAGER END>>>
47+
*/
48+
49+
#include "unrealircd.h"
50+
51+
CMD_FUNC(cmd_qline);
52+
CMD_FUNC(cmd_unqline);
53+
54+
#define MSG_QLINE "QLINE" /* QLINE */
55+
#define MSG_UNQLINE "UNQLINE" /* UNQLINE */
56+
57+
/* Module header */
58+
ModuleHeader MOD_HEADER = {
59+
"third/qline",
60+
"1.0.0",
61+
"/QLINE and /UNQLINE commands to allow opers to manually add Q-lines (global nick bans).",
62+
"Hexick",
63+
"unrealircd-6",
64+
};
65+
66+
/* Initialiation of the command module */
67+
MOD_INIT() {
68+
CommandAdd(modinfo->handle, MSG_QLINE, cmd_qline, MAXPARA, CMD_USER);
69+
CommandAdd(modinfo->handle, MSG_UNQLINE, cmd_unqline, MAXPARA, CMD_USER);
70+
MARK_AS_GLOBAL_MODULE(modinfo);
71+
return MOD_SUCCESS;
72+
}
73+
74+
/* This function is called when the module is loaded */
75+
MOD_LOAD() {
76+
return MOD_SUCCESS;
77+
}
78+
79+
/* Same as the above, except it's for when the module is unloaded */
80+
MOD_UNLOAD() {
81+
return MOD_SUCCESS;
82+
}
83+
84+
/* The actual structure of the QLINE command to be performed */
85+
CMD_FUNC(cmd_qline) {
86+
char mo[32];
87+
const char *comment = (parc == 3) ? parv[2] : NULL;
88+
const char *tkllayer[9] = {
89+
me.name, /*0 server.name */
90+
"+", /*1 + = X-line add */
91+
"Q", /*2 X-line type */
92+
"*" , /*3 user */
93+
parv[1], /*4 host */
94+
client->name, /*5 Who set the ban */
95+
"0", /*6 expire_at; never expire */
96+
NULL, /*7 set_at */
97+
"no reason" /*8 default reason */
98+
};
99+
100+
/* Verify privs */
101+
if (!ValidatePermissionsForPath("server-ban:gline",client,NULL,NULL,NULL)) {
102+
sendnumeric(client, ERR_NOPRIVILEGES);
103+
return;
104+
}
105+
106+
/* Ensure the proper number of parameters */
107+
if (parc < 2)
108+
return;
109+
110+
/* Do the thang */
111+
ircsnprintf(mo, sizeof(mo), "%lld", (long long)TStime());
112+
tkllayer[7] = mo;
113+
tkllayer[8] = comment ? comment : "no reason";
114+
cmd_tkl(&me, NULL, 9, tkllayer);
115+
}
116+
117+
/* The actual structure of the UNQLINE command to be performed */
118+
CMD_FUNC(cmd_unqline) {
119+
const char *tkllayer[6] = {
120+
me.name, /*0 server.name */
121+
"-", /*1 - = X-line removed */
122+
"Q", /*2 X-line type */
123+
"*", /*3 unused */
124+
parv[1], /*4 host */
125+
client->name /*5 who removed the line */
126+
};
127+
128+
/* Verify privs */
129+
if (!ValidatePermissionsForPath("server-ban:gline",client,NULL,NULL,NULL)) {
130+
sendnumeric(client, ERR_NOPRIVILEGES);
131+
return;
132+
}
133+
134+
/* Ensure the proper number of parameters */
135+
if (parc < 2)
136+
return;
137+
138+
/* Do the thang */
139+
cmd_tkl(&me, NULL, 6, tkllayer);
140+
}

0 commit comments

Comments
 (0)