-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpretendclient.cpp
More file actions
80 lines (71 loc) · 2.42 KB
/
pretendclient.cpp
File metadata and controls
80 lines (71 loc) · 2.42 KB
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
/*
*
* pretendclient.cpp
*
* Connect to networks when your IRC client connects to znc.
* Disconnect from network when your IRC client disconnects from znc.
*
* Known issues:
* Servers can have rate limiting and other measures. This can cause a
* delay in connecting to the network.
*
*
*/
#include <znc/IRCNetwork.h>
#include <znc/Modules.h>
#include <znc/User.h>
#include <znc/znc.h>
class Cpretendclient : public CModule {
public:
MODCONSTRUCTOR(Cpretendclient) {}
virtual ~Cpretendclient() {}
void OnClientLogin() override {
CIRCNetwork* pNetwork = GetNetwork();
if (!pNetwork) {
PutModule("No network provided. Not connecting.");
return;
}
if (!pNetwork->GetIRCConnectEnabled()) {
pNetwork->SetIRCConnectEnabled(true);
PutModule("Enabled IRC connection for this network");
}
if (!pNetwork->IsIRCConnected()) {
if (pNetwork->Connect()) {
PutModule("Connection initiated successfully");
} else {
PutModule(
"Failed to initiate connection - likely due to server "
"throttling. Connection will be retried automatically.");
}
}
}
void OnClientDisconnect() override {
CIRCNetwork* pNetwork = GetNetwork();
if (pNetwork && pNetwork->IsIRCConnected()) {
// Check if this was the last client
if (GetUser()->GetAllClients().size() <= 1) {
pNetwork->SetIRCConnectEnabled(false);
}
}
}
// Disable the network if banned.
EModRet OnNumericMessage(CNumericMessage& msg) override {
if (msg.GetCode() == 465) {
CString sPrefix = GetUser()->GetStatusPrefix();
// :irc.server.com 465 mynick :You are banned from this server-
// Temporary K-line 1 min. - Example (2024/12/29 15.39)
m_pNetwork->SetIRCConnectEnabled(false);
m_pNetwork->PutStatus(
"You are banned from the network. ZNC has disabled the "
"network. Use ` /msg " +
sPrefix +
"status jump ` to reconnect. (Sent from pretendclient module)");
}
return CONTINUE;
}
};
template <>
void TModInfo<Cpretendclient>(CModInfo& Info) {
Info.SetHasArgs(false);
}
NETWORKMODULEDEFS(Cpretendclient, "Make ZNC act like a IRC client.")