-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_changeidentonick.cpp
94 lines (79 loc) · 2.48 KB
/
m_changeidentonick.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2024 Jean Chevronnet <[email protected]>
*
* This file contains a third party module for InspIRCd. You can
* redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/// $ModAuthor: Jean Chevronnet (reverse) <[email protected]>
/// $ModDesc: Sets the user's ident to match their nickname on connect.
/// $ModDepends: core 4
#include "inspircd.h"
class CommandSetNickIdent : public Command
{
public:
CommandSetNickIdent(Module* Creator)
: Command(Creator, "SETNICKIDENT", 1)
{
access_needed = CmdAccess::OPERATOR;
syntax = { "<username>" };
}
CmdResult Handle(User* user, const Params& parameters) override
{
const size_t max_ident_length = 12;
std::string ident = parameters[0];
if (ident.size() > max_ident_length)
{
ident.resize(max_ident_length); // Truncate ident to 12 characters
user->WriteNotice("*** SETNICKIDENT: Username truncated to 12 characters");
}
for (char c : ident)
{
if (!isalnum(c) && c != '-' && c != '_')
{
user->WriteNotice("*** SETNICKIDENT: Invalid characters in username");
return CmdResult::FAILURE;
}
}
user->ChangeDisplayedUser(ident);
ServerInstance->SNO.WriteGlobalSno('a', INSP_FORMAT("{} used SETNICKIDENT to change their username to '{}'", user->nick, ident));
return CmdResult::SUCCESS;
}
};
class ModuleSetNickIdent : public Module
{
private:
CommandSetNickIdent cmd;
public:
ModuleSetNickIdent()
: Module(VF_VENDOR, "Sets the user's ident to match their nickname on connect.")
, cmd(this)
{
}
void OnUserConnect(LocalUser* user) override
{
if (IS_LOCAL(user))
{
std::string newident = user->nick;
const size_t max_ident_length = 12;
if (newident.size() > max_ident_length)
newident.resize(max_ident_length); // Truncate to maximum length
user->ChangeDisplayedUser(newident);
}
}
~ModuleSetNickIdent() override
{
// Clean up resources if any (standard practice even if not necessary)
}
};
MODULE_INIT(ModuleSetNickIdent)