mirror of
https://github.com/znc/znc.git
synced 2026-08-07 09:22:55 +02:00
Make all the modules support networks
This commit is contained in:
+39
-38
@@ -7,16 +7,22 @@
|
||||
*/
|
||||
|
||||
#include "User.h"
|
||||
#include "IRCNetwork.h"
|
||||
#include "znc.h"
|
||||
|
||||
class CSendRaw_Mod: public CModule {
|
||||
|
||||
void SendClient(const CString& sLine) {
|
||||
CUser *pUser = CZNC::Get().FindUser(sLine.Token(1));
|
||||
|
||||
if (pUser) {
|
||||
pUser->PutUser(sLine.Token(2, true));
|
||||
PutModule("Sent [" + sLine.Token(2, true) + "] to " + pUser->GetUserName());
|
||||
CIRCNetwork *pNetwork = pUser->FindNetwork(sLine.Token(2));
|
||||
|
||||
if (pNetwork) {
|
||||
pNetwork->PutUser(sLine.Token(3, true));
|
||||
PutModule("Sent [" + sLine.Token(3, true) + "] to " + pUser->GetUserName() + "/" + pNetwork->GetName());
|
||||
} else {
|
||||
PutModule("Network [" + sLine.Token(2) + "] not found for user [" + sLine.Token(1) + "]");
|
||||
}
|
||||
} else {
|
||||
PutModule("User [" + sLine.Token(1) + "] not found");
|
||||
}
|
||||
@@ -26,16 +32,21 @@ class CSendRaw_Mod: public CModule {
|
||||
CUser *pUser = CZNC::Get().FindUser(sLine.Token(1));
|
||||
|
||||
if (pUser) {
|
||||
pUser->PutIRC(sLine.Token(2, true));
|
||||
PutModule("Sent [" + sLine.Token(2, true) + "] to IRC Server of " + pUser->GetUserName());
|
||||
CIRCNetwork *pNetwork = pUser->FindNetwork(sLine.Token(2));
|
||||
|
||||
if (pNetwork) {
|
||||
pNetwork->PutIRC(sLine.Token(3, true));
|
||||
PutModule("Sent [" + sLine.Token(3, true) + "] to IRC Server of " + pUser->GetUserName() + "/" + pNetwork->GetName());
|
||||
} else {
|
||||
PutModule("Network [" + sLine.Token(2) + "] not found for user [" + sLine.Token(1) + "]");
|
||||
}
|
||||
} else {
|
||||
PutModule("User [" + sLine.Token(1) + "] not found");
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~CSendRaw_Mod() {
|
||||
}
|
||||
virtual ~CSendRaw_Mod() {}
|
||||
|
||||
virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) {
|
||||
if (!m_pUser->IsAdmin()) {
|
||||
@@ -52,23 +63,29 @@ public:
|
||||
virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
|
||||
if (sPageName == "index") {
|
||||
if (WebSock.IsPost()) {
|
||||
CUser *pUser = CZNC::Get().FindUser(WebSock.GetParam("user"));
|
||||
bool bToServer = WebSock.GetParam("send_to") == "server";
|
||||
const CString sLine = WebSock.GetParam("line");
|
||||
|
||||
CUser *pUser = CZNC::Get().FindUser(WebSock.GetParam("user").Token(0, false, "/"));
|
||||
if (!pUser) {
|
||||
WebSock.GetSession()->AddError("User not found");
|
||||
return true;
|
||||
}
|
||||
|
||||
CIRCNetwork *pNetwork = pUser->FindNetwork(WebSock.GetParam("user").Token(1, false, "/"));
|
||||
if (!pNetwork) {
|
||||
WebSock.GetSession()->AddError("Network not found");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bToServer = WebSock.GetParam("send_to") == "server";
|
||||
const CString sLine = WebSock.GetParam("line");
|
||||
|
||||
Tmpl["user"] = pUser->GetUserName();
|
||||
Tmpl[bToServer ? "to_server" : "to_client"] = "true";
|
||||
Tmpl["line"] = sLine;
|
||||
|
||||
if (bToServer) {
|
||||
pUser->PutIRC(sLine);
|
||||
pNetwork->PutIRC(sLine);
|
||||
} else {
|
||||
pUser->PutUser(sLine);
|
||||
pNetwork->PutUser(sLine);
|
||||
}
|
||||
|
||||
WebSock.GetSession()->AddSuccess("Line sent");
|
||||
@@ -78,6 +95,13 @@ public:
|
||||
for (map<CString,CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); ++it) {
|
||||
CTemplate& l = Tmpl.AddRow("UserLoop");
|
||||
l["Username"] = (*it->second).GetUserName();
|
||||
|
||||
vector<CIRCNetwork*> vNetworks = (*it->second).GetNetworks();
|
||||
for (vector<CIRCNetwork*>::const_iterator it2 = vNetworks.begin(); it2 != vNetworks.end(); ++it2) {
|
||||
CTemplate& NetworkLoop = l.AddRow("NetworkLoop");
|
||||
NetworkLoop["Username"] = (*it->second).GetUserName();
|
||||
NetworkLoop["Network"] = (*it2)->GetName();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -86,35 +110,12 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This is here for backwards compatibility. We used to accept commands in this format:
|
||||
<user> [<in|out>] <line> */
|
||||
virtual void OnUnknownModCommand(const CString& sLine) {
|
||||
const CString sUser = sLine.Token(0);
|
||||
const CString sDirection = sLine.Token(1);
|
||||
CUser *pUser = CZNC::Get().FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
/* Since the user doesn't exist we'll adopt the default action of this method */
|
||||
PutModule("Unknown command!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sDirection.Equals("IN")) {
|
||||
SendClient("Client " + sUser + " " + sLine.Token(2, true));
|
||||
} else if (sDirection.Equals("OUT")) {
|
||||
SendServer("Server " + sUser + " " + sLine.Token(2, true));
|
||||
} else {
|
||||
/* No direction given -- assume it's out for compatibility */
|
||||
SendServer("Server " + sUser + " " + sLine.Token(1, true));
|
||||
}
|
||||
}
|
||||
|
||||
MODCONSTRUCTOR(CSendRaw_Mod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Client", static_cast<CModCommand::ModCmdFunc>(&CSendRaw_Mod::SendClient),
|
||||
"[user] [data to send]", "The data will be sent to the user's IRC client(s)");
|
||||
"[user] [network] [data to send]", "The data will be sent to the user's IRC client(s)");
|
||||
AddCommand("Server", static_cast<CModCommand::ModCmdFunc>(&CSendRaw_Mod::SendServer),
|
||||
"[user] [data to send]", "The data will be sent to the IRC server the user is connected to");
|
||||
"[user] [network] [data to send]", "The data will be sent to the IRC server the user is connected to");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user