Skip to content

Commit 48e093c

Browse files
ValwareIRCk4bek4be
authored andcommitted
Create display-name.c
1 parent 784283f commit 48e093c

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

files/display-name.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
Licence: GPLv3 or later
3+
Copyright Ⓒ 2022 Valerie Pond
4+
draft/display-name
5+
6+
*/
7+
/*** <<<MODULE MANAGER START>>>
8+
module
9+
{
10+
documentation "https://github.com/ValwareIRC/valware-unrealircd-mods/blob/main/display-name/README.md";
11+
troubleshooting "In case of problems, documentation or e-mail me at [email protected]";
12+
min-unrealircd-version "6.*";
13+
max-unrealircd-version "6.*";
14+
post-install-text {
15+
"The module is installed. Now all you need to do is add a loadmodule line:";
16+
"loadmodule \"third/display-name\";";
17+
"You need to restart your server for this to show up in CLIENTTAGDENY";
18+
"The module does not need any other configuration.";
19+
}
20+
}
21+
*** <<<MODULE MANAGER END>>>
22+
*/
23+
24+
#define MTAG_DISPLAYNAME "+draft/display-name"
25+
#include "unrealircd.h"
26+
27+
ModuleHeader MOD_HEADER =
28+
{
29+
"third/display-name",
30+
"1.0",
31+
"+draft/display-name (IRCv3)",
32+
"Valware",
33+
"unrealircd-6",
34+
};
35+
int i3display_name_mtag_is_ok(Client *client, const char *name, const char *value);
36+
void mtag_add_i3_display_name(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature);
37+
int IsValidDisplayName(Client *client, const char *value);
38+
39+
MOD_INIT()
40+
{
41+
MessageTagHandlerInfo mtag;
42+
43+
MARK_AS_GLOBAL_MODULE(modinfo);
44+
45+
memset(&mtag, 0, sizeof(mtag));
46+
mtag.is_ok = i3display_name_mtag_is_ok;
47+
mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
48+
mtag.name = MTAG_DISPLAYNAME;
49+
MessageTagHandlerAdd(modinfo->handle, &mtag);
50+
51+
HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_i3_display_name);
52+
53+
54+
return MOD_SUCCESS;
55+
}
56+
57+
MOD_LOAD()
58+
{
59+
return MOD_SUCCESS;
60+
}
61+
62+
MOD_UNLOAD()
63+
{
64+
return MOD_SUCCESS;
65+
}
66+
67+
int i3display_name_mtag_is_ok(Client *client, const char *name, const char *value)
68+
{
69+
/* we COULD return IsValidDisplayName() direcly but I don't like that. */
70+
int IsValid = IsValidDisplayName(client,value);
71+
return IsValid;
72+
}
73+
74+
void mtag_add_i3_display_name(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature)
75+
{
76+
MessageTag *m;
77+
78+
if (IsUser(client))
79+
{
80+
m = find_mtag(recv_mtags, MTAG_DISPLAYNAME);
81+
if (m)
82+
{
83+
m = duplicate_mtag(m);
84+
AddListItem(m, *mtag_list);
85+
}
86+
}
87+
}
88+
89+
int IsValidDisplayName(Client *client, const char *value)
90+
{
91+
if (BadPtr(value))
92+
{
93+
sendto_one(client, NULL, "FAIL * DISPLAY_NAME_ERRONEOUS :Your display-name cannot be empty.");
94+
return 0;
95+
}
96+
const char *illegalchars = "!+%@&~#$:'\"?*,.";
97+
const char *p;
98+
if (strstr(value,"\n") || strstr(value,"\r"))
99+
{
100+
sendto_one(client, NULL, "FAIL * DISPLAY_NAME_ERRONEOUS :The display-name you used contained an illegal character");
101+
return 0;
102+
}
103+
for (p = value; *p; p++)
104+
{
105+
if (strchr(illegalchars, *p))
106+
{
107+
sendto_one(client, NULL, "FAIL * DISPLAY_NAME_ERRONEOUS :The display-name you used contained an illegal character (%s).",illegalchars);
108+
return 0;
109+
}
110+
}
111+
if (strlen(value) > NICKLEN)
112+
{
113+
sendto_one(client, NULL, "FAIL * DISPLAY_NAME_TOO_LONG :The display-name you used exceeded the maximum length and was not included. (Maximum length: %d)", NICKLEN);
114+
return 0;
115+
}
116+
return 1;
117+
}

0 commit comments

Comments
 (0)