Skip to content

Commit 1d8586e

Browse files
authored
Add third/qline module from Hexsl
Q-line Oper CMD Module (PR #83)
2 parents eb55786 + a38c7e5 commit 1d8586e

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

files/qline.c

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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[10] = {
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+
NULL /*9 Extra NULL element to prevent OOB */
99+
};
100+
101+
/* Verify privs */
102+
if (!ValidatePermissionsForPath("server-ban:gline", client, NULL, NULL, NULL)) {
103+
sendnumeric(client, ERR_NOPRIVILEGES);
104+
return;
105+
}
106+
107+
/* Ensure the proper number of parameters */
108+
if (parc < 2)
109+
return;
110+
111+
/* Do the thang */
112+
ircsnprintf(mo, sizeof(mo), "%lld", (long long)TStime());
113+
tkllayer[7] = mo;
114+
tkllayer[8] = comment ? comment : "no reason";
115+
cmd_tkl(&me, NULL, 10, tkllayer);
116+
}
117+
118+
/* The actual structure of the UNQLINE command to be performed */
119+
CMD_FUNC(cmd_unqline) {
120+
const char* tkllayer[7] = {
121+
me.name, /*0 server.name */
122+
"-", /*1 - = X-line removed */
123+
"Q", /*2 X-line type */
124+
"*", /*3 unused */
125+
parv[1], /*4 host */
126+
client->name, /*5 who removed the line */
127+
NULL /*6 Extra NULL element to prevent OOB */
128+
};
129+
130+
/* Verify privs */
131+
if (!ValidatePermissionsForPath("server-ban:gline", client, NULL, NULL, NULL)) {
132+
sendnumeric(client, ERR_NOPRIVILEGES);
133+
return;
134+
}
135+
136+
/* Ensure the proper number of parameters */
137+
if (parc < 2)
138+
return;
139+
140+
/* Do the thang */
141+
cmd_tkl(&me, NULL, 7, tkllayer);
142+
}

0 commit comments

Comments
 (0)