mirror of
https://github.com/znc/znc.git
synced 2026-06-24 20:11:51 +02:00
Modernize several modules to use CMessage
This commit is contained in:
@@ -68,17 +68,15 @@ class CAdminLogMod : public CModule {
|
||||
"] disconnected from IRC");
|
||||
}
|
||||
|
||||
EModRet OnRaw(CString& sLine) override {
|
||||
if (sLine.StartsWith("ERROR ")) {
|
||||
EModRet OnRawMessage(CMessage& Message) override {
|
||||
if (Message.GetCommand().Equals("ERROR")) {
|
||||
// ERROR :Closing Link: nick[24.24.24.24] (Excess Flood)
|
||||
// ERROR :Closing Link: nick[24.24.24.24] Killer (Local kill by
|
||||
// Killer (reason))
|
||||
CString sError(sLine.substr(6));
|
||||
if (sError.Left(1) == ":") sError.LeftChomp();
|
||||
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() +
|
||||
"] disconnected from IRC: " +
|
||||
GetNetwork()->GetCurrentServer()->GetName() + " [" +
|
||||
sError + "]",
|
||||
Message.GetParams(1) + "]",
|
||||
LOG_NOTICE);
|
||||
}
|
||||
return CONTINUE;
|
||||
|
||||
@@ -47,22 +47,20 @@ class CBlockMotd : public CModule {
|
||||
}
|
||||
}
|
||||
|
||||
EModRet OnRaw(CString& sLine) override {
|
||||
const CString sCmd = sLine.Token(1);
|
||||
|
||||
if ((sCmd == "375" /* begin of MOTD */ || sCmd == "372" /* MOTD */) &&
|
||||
EModRet OnNumericMessage(CNumericMessage& Message) override {
|
||||
if ((Message.GetCode() == 375 /* begin of MOTD */ ||
|
||||
Message.GetCode() == 372 /* MOTD */) &&
|
||||
!ShouldTemporarilyAcceptMotd())
|
||||
return HALT;
|
||||
|
||||
if (sCmd == "376" /* End of MOTD */) {
|
||||
if (Message.GetCode() == 376 /* End of MOTD */) {
|
||||
if (!ShouldTemporarilyAcceptMotd()) {
|
||||
sLine = sLine.Token(0) + " 422 " + sLine.Token(2) + " :" +
|
||||
t_s("MOTD blocked by ZNC");
|
||||
Message.SetParam(1, t_s("MOTD blocked by ZNC"));
|
||||
}
|
||||
StopTemporarilyAcceptingMotd();
|
||||
}
|
||||
|
||||
if (sCmd == "422") {
|
||||
if (Message.GetCode() == 422) {
|
||||
// Server has no MOTD
|
||||
StopTemporarilyAcceptingMotd();
|
||||
}
|
||||
|
||||
+6
-8
@@ -334,20 +334,18 @@ class CCryptMod : public CModule {
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
EModRet OnRaw(CString& sLine) override {
|
||||
if (!sLine.Token(1).Equals("332")) {
|
||||
EModRet OnNumericMessage(CNumericMessage& Message) override {
|
||||
if (Message.GetCode() != 332) {
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
CChan* pChan = GetNetwork()->FindChan(sLine.Token(3));
|
||||
CChan* pChan = GetNetwork()->FindChan(Message.GetParam(1));
|
||||
if (pChan) {
|
||||
CNick* Nick = pChan->FindNick(sLine.Token(2));
|
||||
CString sTopic = sLine.Token(4, true);
|
||||
sTopic.TrimPrefix(":");
|
||||
CNick* Nick = pChan->FindNick(Message.GetParam(0));
|
||||
CString sTopic = Message.GetParam(2);
|
||||
|
||||
FilterIncoming(pChan->GetName(), *Nick, sTopic);
|
||||
sLine = sLine.Token(0) + " " + sLine.Token(1) + " " +
|
||||
sLine.Token(2) + " " + pChan->GetName() + " :" + sTopic;
|
||||
Message.SetParam(2, sTopic);
|
||||
}
|
||||
|
||||
return CONTINUE;
|
||||
|
||||
@@ -138,18 +138,16 @@ class CKeepNickMod : public CModule {
|
||||
m_pTimer = nullptr;
|
||||
}
|
||||
|
||||
EModRet OnUserRaw(CString& sLine) override {
|
||||
EModRet OnUserRawMessage(CMessage& Message) override {
|
||||
// We don't care if we are not connected to IRC
|
||||
if (!GetNetwork()->IsIRCConnected()) return CONTINUE;
|
||||
|
||||
// We are trying to get the config nick and this is a /nick?
|
||||
if (!m_pTimer || !sLine.Token(0).Equals("NICK")) return CONTINUE;
|
||||
if (!m_pTimer || Message.GetType() != CMessage::Type::Nick)
|
||||
return CONTINUE;
|
||||
|
||||
// Is the nick change for the nick we are trying to get?
|
||||
CString sNick = sLine.Token(1);
|
||||
|
||||
// Don't even think of using spaces in your nick!
|
||||
if (sNick.Left(1) == ":") sNick.LeftChomp();
|
||||
const CString sNick = Message.As<CNickMessage>().GetNewNick();
|
||||
|
||||
if (!sNick.Equals(GetNick())) return CONTINUE;
|
||||
|
||||
|
||||
+16
-18
@@ -204,17 +204,14 @@ class CPartylineMod : public CModule {
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
EModRet OnRaw(CString& sLine) override {
|
||||
if (sLine.Token(1) == "005") {
|
||||
CString::size_type uPos = sLine.AsUpper().find("CHANTYPES=");
|
||||
if (uPos != CString::npos) {
|
||||
uPos = sLine.find(" ", uPos);
|
||||
|
||||
if (uPos == CString::npos)
|
||||
sLine.append(CHAN_PREFIX_1);
|
||||
else
|
||||
sLine.insert(uPos, CHAN_PREFIX_1);
|
||||
m_spInjectedPrefixes.insert(GetNetwork());
|
||||
EModRet OnNumericMessage(CNumericMessage& Msg) override {
|
||||
if (Msg.GetCode() == 5) {
|
||||
for (int i = 0; i < Msg.GetParams().size(); ++i) {
|
||||
if (Msg.GetParams()[i].StartsWith("CHANTYPES=")) {
|
||||
Msg.SetParam(i, Msg.GetParam(i) + CHAN_PREFIX_1);
|
||||
m_spInjectedPrefixes.insert(GetNetwork());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,14 +299,15 @@ class CPartylineMod : public CModule {
|
||||
}
|
||||
}
|
||||
|
||||
EModRet OnUserRaw(CString& sLine) override {
|
||||
if (sLine.StartsWith("WHO " CHAN_PREFIX_1)) {
|
||||
EModRet OnUserRawMessage(CMessage& Msg) override {
|
||||
if ((Msg.GetCommand().Equals("WHO") ||
|
||||
Msg.GetCommand().Equals("MODE")) &&
|
||||
Msg.GetParam(0).StartsWith(CHAN_PREFIX_1)) {
|
||||
return HALT;
|
||||
} else if (sLine.StartsWith("MODE " CHAN_PREFIX_1)) {
|
||||
return HALT;
|
||||
} else if (sLine.StartsWith("TOPIC " CHAN_PREFIX)) {
|
||||
CString sChannel = sLine.Token(1);
|
||||
CString sTopic = sLine.Token(2, true);
|
||||
} else if (Msg.GetCommand().Equals("TOPIC") &&
|
||||
Msg.GetParam(0).StartsWith(CHAN_PREFIX)) {
|
||||
const CString sChannel = Msg.As<CTopicMessage>().GetTarget();
|
||||
CString sTopic = Msg.As<CTopicMessage>().GetText();
|
||||
|
||||
sTopic.TrimPrefix(":");
|
||||
|
||||
|
||||
+13
-13
@@ -193,7 +193,7 @@ class CRouteTimeout : public CTimer {
|
||||
};
|
||||
|
||||
struct queued_req {
|
||||
CString sLine;
|
||||
CMessage msg;
|
||||
const struct reply* reply;
|
||||
};
|
||||
|
||||
@@ -218,7 +218,7 @@ class CRouteRepliesMod : public CModule {
|
||||
it = m_vsPending.begin();
|
||||
|
||||
while (!it->second.empty()) {
|
||||
PutIRC(it->second[0].sLine);
|
||||
PutIRC(it->second[0].msg);
|
||||
it->second.erase(it->second.begin());
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ class CRouteRepliesMod : public CModule {
|
||||
// :server 461 nick WHO :Not enough parameters
|
||||
CString sOrigCmd = msg.GetParam(1);
|
||||
|
||||
if (m_sLastRequest.Token(0).Equals(sOrigCmd)) {
|
||||
if (m_LastRequest.GetCommand().Equals(sOrigCmd)) {
|
||||
// This is the reply to the last request
|
||||
if (RouteReply(msg, true)) return HALTCORE;
|
||||
return CONTINUE;
|
||||
@@ -290,22 +290,22 @@ class CRouteRepliesMod : public CModule {
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
EModRet OnUserRaw(CString& sLine) override {
|
||||
CString sCmd = sLine.Token(0).AsUpper();
|
||||
EModRet OnUserRawMessage(CMessage& Message) override {
|
||||
const CString& sCmd = Message.GetCommand();
|
||||
|
||||
if (!GetNetwork()->GetIRCSock() ||
|
||||
!GetNetwork()->GetIRCSock()->IsConnected())
|
||||
return CONTINUE;
|
||||
|
||||
if (sCmd.Equals("MODE")) {
|
||||
if (Message.GetType() == CMessage::Type::Mode) {
|
||||
// Check if this is a mode request that needs to be handled
|
||||
|
||||
// If there are arguments to a mode change,
|
||||
// we must not route it.
|
||||
if (!sLine.Token(3, true).empty()) return CONTINUE;
|
||||
if (!Message.GetParams(2).empty()) return CONTINUE;
|
||||
|
||||
// Grab the mode change parameter
|
||||
CString sMode = sLine.Token(2);
|
||||
CString sMode = Message.GetParam(1);
|
||||
|
||||
// If this is a channel mode request, znc core replies to it
|
||||
if (sMode.empty()) return CONTINUE;
|
||||
@@ -331,7 +331,7 @@ class CRouteRepliesMod : public CModule {
|
||||
|
||||
for (size_t i = 0; vRouteReplies[i].szRequest != nullptr; i++) {
|
||||
if (vRouteReplies[i].szRequest == sCmd) {
|
||||
struct queued_req req = {sLine, vRouteReplies[i].vReplies};
|
||||
struct queued_req req = {Message, vRouteReplies[i].vReplies};
|
||||
m_vsPending[GetClient()].push_back(req);
|
||||
SendRequest();
|
||||
|
||||
@@ -355,7 +355,7 @@ class CRouteRepliesMod : public CModule {
|
||||
PutModule(
|
||||
t_f("To disable this message, do \"/msg {1} silent yes\"")(
|
||||
GetModNick()));
|
||||
PutModule(t_f("Last request: {1}")(m_sLastRequest));
|
||||
PutModule(t_f("Last request: {1}")(m_LastRequest.ToString()));
|
||||
PutModule(t_s("Expected replies:"));
|
||||
|
||||
for (size_t i = 0; m_pReplies[i].szReply != nullptr; i++) {
|
||||
@@ -419,8 +419,8 @@ class CRouteRepliesMod : public CModule {
|
||||
|
||||
m_pDoing = it->first;
|
||||
m_pReplies = it->second[0].reply;
|
||||
m_sLastRequest = it->second[0].sLine;
|
||||
PutIRC(it->second[0].sLine);
|
||||
m_LastRequest = it->second[0].msg;
|
||||
PutIRC(it->second[0].msg);
|
||||
it->second.erase(it->second.begin());
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ class CRouteRepliesMod : public CModule {
|
||||
const struct reply* m_pReplies;
|
||||
requestQueue m_vsPending;
|
||||
// This field is only used for display purpose.
|
||||
CString m_sLastRequest;
|
||||
CMessage m_LastRequest;
|
||||
};
|
||||
|
||||
void CRouteTimeout::RunJob() {
|
||||
|
||||
Reference in New Issue
Block a user