diff --git a/modules/adminlog.cpp b/modules/adminlog.cpp index ea316758..d8451f92 100644 --- a/modules/adminlog.cpp +++ b/modules/adminlog.cpp @@ -9,6 +9,7 @@ #include "Client.h" #include "FileUtils.h" #include "Server.h" +#include "IRCNetwork.h" #include "User.h" #include @@ -42,11 +43,11 @@ public: } virtual void OnIRCConnected() { - Log("[" + m_pUser->GetUserName() + "] connected to IRC: " + m_pUser->GetCurrentServer()->GetName()); + Log("[" + m_pUser->GetUserName() + "/" + m_pNetwork->GetName() + "] connected to IRC: " + m_pNetwork->GetCurrentServer()->GetName()); } virtual void OnIRCDisconnected() { - Log("[" + m_pUser->GetUserName() + "] disconnected from IRC"); + Log("[" + m_pUser->GetUserName() + "/" + m_pNetwork->GetName() + "] disconnected from IRC"); } virtual EModRet OnRaw(CString& sLine) { @@ -56,8 +57,8 @@ public: CString sError(sLine.substr(6)); if (sError.Left(1) == ":") sError.LeftChomp(); - Log("[" + m_pUser->GetUserName() + "] disconnected from IRC: " + - m_pUser->GetCurrentServer()->GetName() + " [" + sError + "]", LOG_NOTICE); + Log("[" + m_pUser->GetUserName() + "/" + m_pNetwork->GetName() + "] disconnected from IRC: " + + m_pNetwork->GetCurrentServer()->GetName() + " [" + sError + "]", LOG_NOTICE); } return CONTINUE; } diff --git a/modules/autocycle.cpp b/modules/autocycle.cpp index 969cf81a..71bd2c42 100644 --- a/modules/autocycle.cpp +++ b/modules/autocycle.cpp @@ -8,6 +8,7 @@ #include "Chan.h" #include "User.h" +#include "IRCNetwork.h" class CAutoCycleMod : public CModule { public: @@ -125,7 +126,7 @@ protected: // Is that person us and we don't have op? const CNick& pNick = Channel.GetNicks().begin()->second; - if (!pNick.HasPerm(CChan::Op) && pNick.GetNick().Equals(m_pUser->GetCurNick())) + if (!pNick.HasPerm(CChan::Op) && pNick.GetNick().Equals(m_pNetwork->GetCurNick())) Channel.Cycle(); } diff --git a/modules/autoop.cpp b/modules/autoop.cpp index ebbf34d2..93702662 100644 --- a/modules/autoop.cpp +++ b/modules/autoop.cpp @@ -6,8 +6,8 @@ * by the Free Software Foundation. */ +#include "IRCNetwork.h" #include "Chan.h" -#include "User.h" class CAutoOpMod; @@ -345,7 +345,7 @@ public: // First verify that the guy who challenged us matches a user's host if (pUser->HostMatches(Nick.GetHostMask())) { - const vector& Chans = m_pUser->GetChans(); + const vector& Chans = m_pNetwork->GetChans(); bMatchedHost = true; // Also verify that they are opped in at least one of the user's chans @@ -440,7 +440,7 @@ public: } void OpUser(const CNick& Nick, const CAutoOpUser& User) { - const vector& Chans = m_pUser->GetChans(); + const vector& Chans = m_pNetwork->GetChans(); for (size_t a = 0; a < Chans.size(); a++) { const CChan& Chan = *Chans[a]; @@ -467,4 +467,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("autoop"); } -MODULEDEFS(CAutoOpMod, "Auto op the good guys") +NETWORKMODULEDEFS(CAutoOpMod, "Auto op the good guys") diff --git a/modules/autoreply.cpp b/modules/autoreply.cpp index 72145264..2792efdc 100644 --- a/modules/autoreply.cpp +++ b/modules/autoreply.cpp @@ -8,6 +8,7 @@ */ #include "Modules.h" +#include "IRCNetwork.h" #include "IRCSock.h" #include "User.h" @@ -42,7 +43,7 @@ public: } void Handle(const CString& sNick) { - CIRCSock *pIRCSock = GetUser()->GetIRCSock(); + CIRCSock *pIRCSock = m_pNetwork->GetIRCSock(); if (!pIRCSock) // WTF? return; diff --git a/modules/awaynick.cpp b/modules/awaynick.cpp index 298f90ed..e6960c36 100644 --- a/modules/awaynick.cpp +++ b/modules/awaynick.cpp @@ -9,6 +9,7 @@ // @todo handle raw 433 (nick in use) #include "IRCSock.h" #include "User.h" +#include "IRCNetwork.h" class CAwayNickMod; @@ -31,10 +32,10 @@ public: private: virtual void RunJob() { - CUser* pUser = m_Module.GetUser(); + CIRCNetwork* pNetwork = m_Module.GetNetwork(); - if (pUser->IsUserAttached() && pUser->IsIRCConnected()) { - CString sConfNick = pUser->GetNick(); + if (pNetwork->IsUserAttached() && pNetwork->IsIRCConnected()) { + CString sConfNick = pNetwork->GetUser()->GetNick(); m_Module.PutIRC("NICK " + sConfNick); } } @@ -76,7 +77,7 @@ public: } void StartBackNickTimer() { - CIRCSock* pIRCSock = m_pUser->GetIRCSock(); + CIRCSock* pIRCSock = m_pNetwork->GetIRCSock(); if (pIRCSock) { CString sConfNick = m_pUser->GetNick(); @@ -159,7 +160,7 @@ public: CString GetAwayNick() { unsigned int uLen = 9; - CIRCSock* pIRCSock = m_pUser->GetIRCSock(); + CIRCSock* pIRCSock = m_pNetwork->GetIRCSock(); if (pIRCSock) { uLen = pIRCSock->GetMaxNickLen(); @@ -179,9 +180,9 @@ CAwayNickTimer::CAwayNickTimer(CAwayNickMod& Module) m_Module(Module) {} void CAwayNickTimer::RunJob() { - CUser* pUser = m_Module.GetUser(); + CIRCNetwork* pNetwork = m_Module.GetNetwork(); - if (!pUser->IsUserAttached() && pUser->IsIRCConnected()) { + if (!pNetwork->IsUserAttached() && pNetwork->IsIRCConnected()) { m_Module.PutIRC("NICK " + m_Module.GetAwayNick()); } } @@ -190,4 +191,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("awaynick"); } -MODULEDEFS(CAwayNickMod, "Change your nick while you are away") +NETWORKMODULEDEFS(CAwayNickMod, "Change your nick while you are away") diff --git a/modules/blockuser.cpp b/modules/blockuser.cpp index 51d420b6..108b8b30 100644 --- a/modules/blockuser.cpp +++ b/modules/blockuser.cpp @@ -7,6 +7,7 @@ */ #include "User.h" +#include "IRCNetwork.h" #include "IRCSock.h" #include "znc.h" @@ -147,17 +148,21 @@ private: return false; // Disconnect all clients - vector& vpClients = pUser->GetClients(); + vector vpClients = pUser->GetAllClients(); vector::iterator it; for (it = vpClients.begin(); it != vpClients.end(); ++it) { (*it)->PutStatusNotice(MESSAGE); (*it)->Close(Csock::CLT_AFTERWRITE); } - // Disconnect from IRC... - CIRCSock *pIRCSock = pUser->GetIRCSock(); - if (pIRCSock) { - pIRCSock->Quit(); + // Disconnect all networks from irc + vector vNetworks = pUser->GetNetworks(); + for (vector::iterator it2 = vNetworks.begin(); it2 != vNetworks.end(); ++it2) { + CIRCNetwork *pNetwork = *it2; + CIRCSock *pIRCSock = pNetwork->GetIRCSock(); + if (pIRCSock) { + pIRCSock->Quit(); + } } // ...and don't reconnect diff --git a/modules/chansaver.cpp b/modules/chansaver.cpp index 1da6614a..8443a31c 100644 --- a/modules/chansaver.cpp +++ b/modules/chansaver.cpp @@ -8,25 +8,27 @@ #include "Chan.h" #include "User.h" +#include "IRCNetwork.h" #include "znc.h" class CChanSaverMod : public CModule { public: MODCONSTRUCTOR(CChanSaverMod) { - const vector& vChans = m_pUser->GetChans(); - vector::const_iterator it = vChans.begin(); - vector::const_iterator end = vChans.end(); - m_bWriteConf = false; - for (; it != end; ++it) { - CChan *pChan = *it; + vector vNetworks = pUser->GetNetworks(); + for (vector::iterator it = vNetworks.begin(); it != vNetworks.end(); ++it) { + const vector& vChans = (*it)->GetChans(); - // If that channel isn't yet in the config, - // we'll have to add it... - if (!pChan->InConfig()) { - pChan->SetInConfig(true); - m_bWriteConf = true; + for (vector::const_iterator it2 = vChans.begin(); it2 != vChans.end(); ++it2) { + CChan *pChan = *it2; + + // If that channel isn't yet in the config, + // we'll have to add it... + if (!pChan->InConfig()) { + pChan->SetInConfig(true); + m_bWriteConf = true; + } } } } @@ -55,14 +57,14 @@ public: } virtual void OnJoin(const CNick& Nick, CChan& Channel) { - if (Nick.GetNick() == m_pUser->GetIRCNick().GetNick()) { + if (Nick.GetNick() == m_pNetwork->GetIRCNick().GetNick()) { Channel.SetInConfig(true); CZNC::Get().WriteConfig(); } } virtual void OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage) { - if (Nick.GetNick() == m_pUser->GetIRCNick().GetNick()) { + if (Nick.GetNick() == m_pNetwork->GetIRCNick().GetNick()) { Channel.SetInConfig(false); CZNC::Get().WriteConfig(); } diff --git a/modules/clientnotify.cpp b/modules/clientnotify.cpp index 59b1c085..c97c99ac 100644 --- a/modules/clientnotify.cpp +++ b/modules/clientnotify.cpp @@ -55,7 +55,7 @@ public: if(!m_bNewOnly || m_sClientsSeen.find(m_pClient->GetRemoteIP()) == m_sClientsSeen.end()) { SendNotification("Another client authenticated as your user. " "Use the 'ListClients' command to see all " + - CString(m_pUser->GetClients().size()) + " clients."); + CString(m_pUser->GetAllClients().size()) + " clients."); // the set<> will automatically disregard duplicates: m_sClientsSeen.insert(m_pClient->GetRemoteIP()); @@ -66,7 +66,7 @@ public: if(m_bOnDisconnect) { SendNotification("A client disconnected from your user. " "Use the 'ListClients' command to see the " + - CString(m_pUser->GetClients().size()) + " remaining client(s)."); + CString(m_pUser->GetAllClients().size()) + " remaining client(s)."); } } diff --git a/modules/crypt.cpp b/modules/crypt.cpp index e492d521..9382f0b2 100644 --- a/modules/crypt.cpp +++ b/modules/crypt.cpp @@ -24,6 +24,7 @@ #include "Chan.h" #include "User.h" +#include "IRCNetwork.h" #define REQUIRESSL 1 @@ -43,11 +44,11 @@ public: MCString::iterator it = FindNV(sTarget.AsLower()); if (it != EndNV()) { - CChan* pChan = m_pUser->FindChan(sTarget); + CChan* pChan = m_pNetwork->FindChan(sTarget); if (pChan) { if (pChan->KeepBuffer()) - pChan->AddBuffer(":\244" + m_pUser->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage); - m_pUser->PutUser(":\244" + m_pUser->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage, NULL, m_pClient); + pChan->AddBuffer(":\244" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage); + m_pUser->PutUser(":\244" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage, NULL, m_pClient); } CString sMsg = MakeIvec() + sMessage; @@ -155,4 +156,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("crypt"); } -MODULEDEFS(CCryptMod, "Encryption for channel/private messages") +NETWORKMODULEDEFS(CCryptMod, "Encryption for channel/private messages") diff --git a/modules/disconkick.cpp b/modules/disconkick.cpp index 60938122..3c62e5bc 100644 --- a/modules/disconkick.cpp +++ b/modules/disconkick.cpp @@ -8,7 +8,7 @@ #include "Modules.h" -#include "User.h" +#include "IRCNetwork.h" #include "Chan.h" class CKickClientOnIRCDisconnect: public CModule { @@ -17,12 +17,12 @@ public: void OnIRCDisconnected() { - const vector& vChans = m_pUser->GetChans(); + const vector& vChans = m_pNetwork->GetChans(); for(vector::const_iterator it = vChans.begin(); it != vChans.end(); ++it) { if((*it)->IsOn()) { - PutUser(":ZNC!znc@znc.in KICK " + (*it)->GetName() + " " + m_pUser->GetIRCNick().GetNick() + PutUser(":ZNC!znc@znc.in KICK " + (*it)->GetName() + " " + m_pNetwork->GetIRCNick().GetNick() + " :You have been disconnected from the IRC server"); } } diff --git a/modules/extra/antiidle.cpp b/modules/extra/antiidle.cpp index c6c1a95d..3b515daf 100644 --- a/modules/extra/antiidle.cpp +++ b/modules/extra/antiidle.cpp @@ -7,7 +7,7 @@ */ #include "Nick.h" -#include "User.h" +#include "IRCNetwork.h" class CAntiIdle; @@ -65,7 +65,7 @@ public: virtual EModRet OnPrivMsg(CNick &Nick, CString &sMessage) { - if(Nick.GetNick() == GetUser()->GetIRCNick().GetNick() + if(Nick.GetNick() == m_pNetwork->GetIRCNick().GetNick() && sMessage == "\xAE") return HALT; @@ -94,8 +94,8 @@ private: //! This function sends a query with (r) back to the user void CAntiIdleJob::RunJob() { - CString sNick = GetModule()->GetUser()->GetIRCNick().GetNick(); + CString sNick = GetModule()->GetNetwork()->GetIRCNick().GetNick(); GetModule()->PutIRC("PRIVMSG " + sNick + " :\xAE"); } -MODULEDEFS(CAntiIdle, "Hides your real idle time") +NETWORKMODULEDEFS(CAntiIdle, "Hides your real idle time") diff --git a/modules/extra/away.cpp b/modules/extra/away.cpp index 0f939d05..697aca6d 100644 --- a/modules/extra/away.cpp +++ b/modules/extra/away.cpp @@ -13,6 +13,7 @@ #include "Client.h" #include "User.h" +#include "IRCNetwork.h" #include "FileUtils.h" #include @@ -438,7 +439,7 @@ private: void AddMessage(time_t iTime, const CNick & Nick, CString & sMessage) { - if (m_pUser && Nick.GetNick() == m_pUser->GetIRCNick().GetNick()) + if (Nick.GetNick() == m_pNetwork->GetIRCNick().GetNick()) return; // ignore messages from self AddMessage(CString(iTime) + ":" + Nick.GetNickMask() + ":" + sMessage); } @@ -474,5 +475,5 @@ void CAwayJob::RunJob() } } -MODULEDEFS(CAway, "You don't need this module, ZNC works ok without it") +NETWORKMODULEDEFS(CAway, "You don't need this module, ZNC works ok without it") diff --git a/modules/extra/clearbufferonmsg.cpp b/modules/extra/clearbufferonmsg.cpp index 5ed6be70..84f74bd6 100644 --- a/modules/extra/clearbufferonmsg.cpp +++ b/modules/extra/clearbufferonmsg.cpp @@ -6,29 +6,30 @@ * by the Free Software Foundation. */ +#include "IRCNetwork.h" #include "Chan.h" #include "Modules.h" -#include "User.h" class CClearBufferOnMsgMod : public CModule { public: MODCONSTRUCTOR(CClearBufferOnMsgMod) {} void ClearAllBuffers() { - const vector& vChans = GetUser()->GetChans(); - vector::const_iterator it; + if (m_pNetwork) { + const vector& vChans = m_pNetwork->GetChans(); + vector::const_iterator it; - for (it = vChans.begin(); it != vChans.end(); ++it) { - // Skip detached channels, they weren't read yet - if ((*it)->IsDetached()) - continue; + for (it = vChans.begin(); it != vChans.end(); ++it) { + // Skip detached channels, they weren't read yet + if ((*it)->IsDetached()) + continue; - (*it)->ClearBuffer(); - // We force KeepBuffer on all channels since this module - // doesnt make any sense without - (*it)->SetKeepBuffer(true); + (*it)->ClearBuffer(); + // We force KeepBuffer on all channels since this module + // doesnt make any sense without + (*it)->SetKeepBuffer(true); + } } - } virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) { diff --git a/modules/extra/dcc.cpp b/modules/extra/dcc.cpp index a741022f..4b8d7f3f 100644 --- a/modules/extra/dcc.cpp +++ b/modules/extra/dcc.cpp @@ -241,7 +241,7 @@ public: unsigned long uLongIP = sMessage.Token(3).ToULong(); unsigned short uPort = sMessage.Token(4).ToUShort(); unsigned long uFileSize = sMessage.Token(5).ToULong(); - GetFile(m_pUser->GetCurNick(), CUtils::GetIP(uLongIP), uPort, sLocalFile, uFileSize); + GetFile(m_pClient->GetNick(), CUtils::GetIP(uLongIP), uPort, sLocalFile, uFileSize); } } }; diff --git a/modules/extra/fakeonline.cpp b/modules/extra/fakeonline.cpp index 8111dbff..9d63c879 100644 --- a/modules/extra/fakeonline.cpp +++ b/modules/extra/fakeonline.cpp @@ -7,6 +7,7 @@ */ #include "User.h" +#include "IRCNetwork.h" #include "znc.h" class CFOModule : public CModule { @@ -45,10 +46,10 @@ public: // Remove the leading space sBNCNicks.LeftChomp(); - if (!m_pUser->GetIRCSock()) { + if (!m_pNetwork->GetIRCSock()) { // if we are not connected to any IRC server, send // an empty or module-nick filled response. - PutUser(":irc.znc.in 303 " + m_pUser->GetNick() + " :" + sBNCNicks); + PutUser(":irc.znc.in 303 " + m_pClient->GetNick() + " :" + sBNCNicks); } else { // We let the server handle this request and then act on // the 303 response from the IRC server. @@ -61,9 +62,9 @@ public: CString sNick = sLine.Token(1); if (IsOnlineModNick(sNick)) { - PutUser(":znc.in 311 " + m_pUser->GetCurNick() + " " + sNick + " " + sNick + " znc.in * :" + sNick); - PutUser(":znc.in 312 " + m_pUser->GetCurNick() + " " + sNick + " *.znc.in :Bouncer"); - PutUser(":znc.in 318 " + m_pUser->GetCurNick() + " " + sNick + " :End of /WHOIS list."); + PutUser(":znc.in 311 " + m_pNetwork->GetCurNick() + " " + sNick + " " + sNick + " znc.in * :" + sNick); + PutUser(":znc.in 312 " + m_pNetwork->GetCurNick() + " " + sNick + " *.znc.in :Bouncer"); + PutUser(":znc.in 318 " + m_pNetwork->GetCurNick() + " " + sNick + " :End of /WHOIS list."); return HALT; } @@ -96,4 +97,4 @@ private: VCString m_ISONRequests; }; -MODULEDEFS(CFOModule, "Fakes online status of ZNC *-users.") +NETWORKMODULEDEFS(CFOModule, "Fakes online status of ZNC *-users.") diff --git a/modules/extra/flooddetach.cpp b/modules/extra/flooddetach.cpp index 3db1401c..35f24f5c 100644 --- a/modules/extra/flooddetach.cpp +++ b/modules/extra/flooddetach.cpp @@ -9,6 +9,7 @@ #include "Chan.h" #include "Modules.h" #include "User.h" +#include "IRCNetwork.h" class CFloodDetachMod : public CModule { public: @@ -62,7 +63,7 @@ public: if (it->second.first + (time_t)m_iThresholdSecs >= now) continue; - CChan *pChan = m_pUser->FindChan(it->first); + CChan *pChan = m_pNetwork->FindChan(it->first); if (it->second.second >= m_iThresholdMsgs && pChan && pChan->IsDetached()) { // The channel is detached and it is over the diff --git a/modules/extra/log.cpp b/modules/extra/log.cpp index 77c720c8..05a9a11a 100644 --- a/modules/extra/log.cpp +++ b/modules/extra/log.cpp @@ -9,6 +9,7 @@ #include "FileUtils.h" #include "User.h" +#include "IRCNetwork.h" #include "Chan.h" #include "Server.h" @@ -74,6 +75,7 @@ void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/ sPath = buffer; // $WINDOW has to be handled last, since it can contain % + sPath.Replace("$NETWORK", (m_pNetwork ? m_pNetwork->GetName() : "znc")); sPath.Replace("$WINDOW", sWindow.Replace_n("/", "?")); // Check if it's allowed to write in this specific path @@ -109,7 +111,7 @@ void CLogMod::PutLog(const CString& sLine, const CNick& Nick) CString CLogMod::GetServer() { - CServer* pServer = m_pUser->GetCurrentServer(); + CServer* pServer = m_pNetwork->GetCurrentServer(); CString sSSL; if (!pServer) @@ -126,12 +128,12 @@ bool CLogMod::OnLoad(const CString& sArgs, CString& sMessage) m_sLogPath = sArgs; // Add default filename to path if it's a folder - if (m_sLogPath.Right(1) == "/" || m_sLogPath.find("$WINDOW")==string::npos) + if (m_sLogPath.Right(1) == "/" || m_sLogPath.find("$WINDOW") == string::npos || m_sLogPath.find("$NETWORK") == string::npos) { if (!m_sLogPath.empty()) { m_sLogPath += "/"; } - m_sLogPath += "$WINDOW_%Y%m%d.log"; + m_sLogPath += "$NETWORK_$WINDOW_%Y%m%d.log"; } // Check if it's allowed to write in this path in general @@ -204,7 +206,10 @@ CModule::EModRet CLogMod::OnTopic(CNick& Nick, CChan& Channel, CString& sTopic) /* notices */ CModule::EModRet CLogMod::OnUserNotice(CString& sTarget, CString& sMessage) { - PutLog("-" + GetUser()->GetCurNick() + "- " + sMessage, sTarget); + if (m_pNetwork) { + PutLog("-" + m_pNetwork->GetCurNick() + "- " + sMessage, sTarget); + } + return CONTINUE; } @@ -223,7 +228,10 @@ CModule::EModRet CLogMod::OnChanNotice(CNick& Nick, CChan& Channel, CString& sMe /* actions */ CModule::EModRet CLogMod::OnUserAction(CString& sTarget, CString& sMessage) { - PutLog("* " + GetUser()->GetCurNick() + " " + sMessage, sTarget); + if (m_pNetwork) { + PutLog("* " + m_pNetwork->GetCurNick() + " " + sMessage, sTarget); + } + return CONTINUE; } @@ -242,7 +250,10 @@ CModule::EModRet CLogMod::OnChanAction(CNick& Nick, CChan& Channel, CString& sMe /* msgs */ CModule::EModRet CLogMod::OnUserMsg(CString& sTarget, CString& sMessage) { - PutLog("<" + GetUser()->GetCurNick() + "> " + sMessage, sTarget); + if (m_pNetwork) { + PutLog("<" + m_pNetwork->GetCurNick() + "> " + sMessage, sTarget); + } + return CONTINUE; } diff --git a/modules/extra/send_raw.cpp b/modules/extra/send_raw.cpp index 1c6a4533..e15f9ca8 100644 --- a/modules/extra/send_raw.cpp +++ b/modules/extra/send_raw.cpp @@ -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::const_iterator it = msUsers.begin(); it != msUsers.end(); ++it) { CTemplate& l = Tmpl.AddRow("UserLoop"); l["Username"] = (*it->second).GetUserName(); + + vector vNetworks = (*it->second).GetNetworks(); + for (vector::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: - [] */ - 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(&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(&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"); } }; diff --git a/modules/extra/shell.cpp b/modules/extra/shell.cpp index f2fd5ae6..9e58309e 100644 --- a/modules/extra/shell.cpp +++ b/modules/extra/shell.cpp @@ -93,7 +93,7 @@ public: void PutShell(const CString& sMsg) { CString sPath = m_sPath.Replace_n(" ", "_"); CString sSource = ":" + GetModNick() + "!shell@" + sPath; - CString sLine = sSource + " PRIVMSG " + m_pUser->GetCurNick() + " :" + sMsg; + CString sLine = sSource + " PRIVMSG " + m_pClient->GetNick() + " :" + sMsg; PutUser(sLine); } diff --git a/modules/identfile.cpp b/modules/identfile.cpp index b51e9543..04a7e6c0 100644 --- a/modules/identfile.cpp +++ b/modules/identfile.cpp @@ -9,6 +9,7 @@ #include "FileUtils.h" #include "IRCSock.h" #include "User.h" +#include "IRCNetwork.h" #include "znc.h" class CIdentFileModule : public CModule { @@ -141,7 +142,7 @@ public: } virtual void OnIRCConnected() { - if (m_pIRCSock == m_pUser->GetIRCSock()) { + if (m_pIRCSock == m_pNetwork->GetIRCSock()) { m_pIRCSock = NULL; ReleaseISpoof(); } @@ -155,7 +156,7 @@ public: } virtual void OnIRCDisconnected() { - if (m_pIRCSock == m_pUser->GetIRCSock()) { + if (m_pIRCSock == m_pNetwork->GetIRCSock()) { m_pIRCSock = NULL; ReleaseISpoof(); } diff --git a/modules/keepnick.cpp b/modules/keepnick.cpp index 601607b3..c85e95bb 100644 --- a/modules/keepnick.cpp +++ b/modules/keepnick.cpp @@ -8,6 +8,7 @@ #include "Modules.h" #include "User.h" +#include "IRCNetwork.h" #include "IRCSock.h" class CKeepNickMod; @@ -33,7 +34,7 @@ public: m_pTimer = NULL; // Check if we need to start the timer - if (m_pUser->IsIRCConnected()) + if (m_pNetwork->IsIRCConnected()) OnIRCConnected(); return true; @@ -44,7 +45,7 @@ public: // No timer means we are turned off return; - CIRCSock* pIRCSock = GetUser()->GetIRCSock(); + CIRCSock* pIRCSock = m_pNetwork->GetIRCSock(); if (!pIRCSock) return; @@ -58,7 +59,7 @@ public: CString GetNick() { CString sConfNick = m_pUser->GetNick(); - CIRCSock* pIRCSock = GetUser()->GetIRCSock(); + CIRCSock* pIRCSock = m_pNetwork->GetIRCSock(); if (pIRCSock) sConfNick = sConfNick.Left(pIRCSock->GetMaxNickLen()); @@ -67,7 +68,7 @@ public: } void OnNick(const CNick& Nick, const CString& sNewNick, const vector& vChans) { - if (sNewNick == GetUser()->GetIRCSock()->GetNick()) { + if (sNewNick == m_pNetwork->GetIRCSock()->GetNick()) { // We are changing our own nick if (Nick.GetNick().Equals(GetNick())) { // We are changing our nick away from the conf setting. @@ -101,7 +102,7 @@ public: } void OnIRCConnected() { - if (!GetUser()->GetIRCSock()->GetNick().Equals(GetNick())) { + if (!m_pNetwork->GetIRCSock()->GetNick().Equals(GetNick())) { // We don't have the nick we want, try to get it Enable(); } @@ -126,7 +127,7 @@ public: virtual EModRet OnUserRaw(CString& sLine) { // We dont care if we are not connected to IRC - if (!m_pUser->IsIRCConnected()) + if (!m_pNetwork->IsIRCConnected()) return CONTINUE; // We are trying to get the config nick and this is a /nick? @@ -145,7 +146,7 @@ public: // Indeed trying to change to this nick, generate a 433 for it. // This way we can *always* block incoming 433s from the server. - PutUser(":" + m_pUser->GetIRCServer() + " 433 " + m_pUser->GetIRCNick().GetNick() + PutUser(":" + m_pNetwork->GetIRCServer() + " 433 " + m_pNetwork->GetIRCNick().GetNick() + " " + sNick + " :ZNC is already trying to get this nickname"); return CONTINUE; } @@ -196,4 +197,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("keepnick"); } -MODULEDEFS(CKeepNickMod, "Keep trying for your primary nick") +NETWORKMODULEDEFS(CKeepNickMod, "Keep trying for your primary nick") diff --git a/modules/kickrejoin.cpp b/modules/kickrejoin.cpp index 68b05c23..20e980e1 100644 --- a/modules/kickrejoin.cpp +++ b/modules/kickrejoin.cpp @@ -14,7 +14,7 @@ */ #include "Chan.h" -#include "User.h" +#include "IRCNetwork.h" class CRejoinJob: public CTimer { public: @@ -26,8 +26,8 @@ public: protected: virtual void RunJob() { - CUser* user = m_pModule->GetUser(); - CChan* pChan = user->FindChan(GetName().Token(1, true)); + CIRCNetwork* pNetwork = m_pModule->GetNetwork(); + CChan* pChan = pNetwork->FindChan(GetName().Token(1, true)); if (pChan) { pChan->Enable(); @@ -96,7 +96,7 @@ public: } virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& pChan, const CString& sMessage) { - if (m_pUser->GetCurNick().Equals(sKickedNick)) { + if (m_pNetwork->GetCurNick().Equals(sKickedNick)) { if (!delay) { PutIRC("JOIN " + pChan.GetName() + " " + pChan.GetKey()); pChan.Enable(); @@ -112,4 +112,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("kickrejoin"); } -MODULEDEFS(CRejoinMod, "Autorejoin on kick") +NETWORKMODULEDEFS(CRejoinMod, "Autorejoin on kick") diff --git a/modules/lastseen.cpp b/modules/lastseen.cpp index 957c5c5d..b88ccc96 100644 --- a/modules/lastseen.cpp +++ b/modules/lastseen.cpp @@ -107,25 +107,6 @@ public: Row["Username"] = pUser->GetUserName(); Row["IsSelf"] = CString(pUser == WebSock.GetSession()->GetUser()); Row["LastSeen"] = FormatLastSeen(pUser, "never"); - - Row["Info"] = CString(pUser->GetClients().size()) + - " client" + CString(pUser->GetClients().size() == 1 ? "" : "s"); - if (!pUser->IsIRCConnected()) { - Row["Info"] += ", not connected to IRC"; - } else { - unsigned int uChans = 0; - const vector& vChans = pUser->GetChans(); - for (unsigned int a = 0; a < vChans.size(); ++a) { - if (vChans[a]->IsOn()) ++uChans; - } - unsigned int n = uChans; - Row["Info"] += ", joined to " + CString(uChans); - if(uChans != vChans.size()) { - Row["Info"] += " out of " + CString(vChans.size()) + " configured"; - n = vChans.size(); - } - Row["Info"] += " channel" + CString(n == 1 ? "" : "s"); - } } return true; diff --git a/modules/modperl/module.h b/modules/modperl/module.h index decebfe4..027e533a 100644 --- a/modules/modperl/module.h +++ b/modules/modperl/module.h @@ -17,9 +17,9 @@ class CPerlModule : public CModule { CString m_sPerlID; VWebSubPages* _GetSubPages(); public: - CPerlModule(CUser* pUser, const CString& sModName, const CString& sDataPath, + CPerlModule(CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sDataPath, const CString& sPerlID) - : CModule(NULL, pUser, sModName, sDataPath) { + : CModule(NULL, pUser, pNetwork, sModName, sDataPath) { m_sPerlID = sPerlID; } CString GetPerlID() { return m_sPerlID; } diff --git a/modules/nickserv.cpp b/modules/nickserv.cpp index 05da5b35..186396e9 100644 --- a/modules/nickserv.cpp +++ b/modules/nickserv.cpp @@ -80,4 +80,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("nickserv"); } -MODULEDEFS(CNickServ, "Auths you with NickServ") +NETWORKMODULEDEFS(CNickServ, "Auths you with NickServ") diff --git a/modules/partyline.cpp b/modules/partyline.cpp index 20877af8..7a963366 100644 --- a/modules/partyline.cpp +++ b/modules/partyline.cpp @@ -655,7 +655,7 @@ public: return; } - const vector& vClients = pUser->GetClients(); + const vector& vClients = pUser->GetAllClients(); vector::const_iterator it; for (it = vClients.begin(); it != vClients.end(); ++it) { (*it)->PutClient(sPre + (*it)->GetNick() + sPost); diff --git a/modules/q.cpp b/modules/q.cpp index 157eb36f..fff68640 100644 --- a/modules/q.cpp +++ b/modules/q.cpp @@ -8,6 +8,7 @@ #include "Modules.h" #include "User.h" +#include "IRCNetwork.h" #include "IRCSock.h" #include "Nick.h" #include "Chan.h" @@ -39,7 +40,7 @@ public: if (IsIRCConnected()) { // check for usermode +x if we are already connected - set scUserModes = GetUser()->GetIRCSock()->GetUserModes(); + set scUserModes = m_pNetwork->GetIRCSock()->GetUserModes(); if (scUserModes.find('x') != scUserModes.end()) m_bCloaked = true; @@ -254,7 +255,7 @@ private: return; PutModule("Cloak: Trying to cloak your hostname, setting +x..."); - PutIRC("MODE " + GetUser()->GetIRCSock()->GetNick() + " +x"); + PutIRC("MODE " + m_pNetwork->GetIRCSock()->GetNick() + " +x"); } void WhoAmI() { @@ -404,12 +405,12 @@ private: /* Utility Functions */ bool IsIRCConnected() { - CIRCSock* pIRCSock = GetUser()->GetIRCSock(); + CIRCSock* pIRCSock = m_pNetwork->GetIRCSock(); return pIRCSock && pIRCSock->IsAuthed(); } bool IsSelf(const CNick& Nick) { - return Nick.GetNick().Equals(m_pUser->GetCurNick()); + return Nick.GetNick().Equals(m_pNetwork->GetCurNick()); } bool PackHex(const CString& sHex, CString& sPackedHex) { @@ -487,4 +488,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("Q"); } -MODULEDEFS(CQModule, "Auths you with QuakeNet's Q bot.") +NETWORKMODULEDEFS(CQModule, "Auths you with QuakeNet's Q bot.") diff --git a/modules/route_replies.cpp b/modules/route_replies.cpp index 925e8893..1dd8d59c 100644 --- a/modules/route_replies.cpp +++ b/modules/route_replies.cpp @@ -7,7 +7,7 @@ */ #include "znc.h" -#include "User.h" +#include "IRCNetwork.h" #include "IRCSock.h" struct reply { @@ -249,7 +249,7 @@ public: { CString sCmd = sLine.Token(0).AsUpper(); - if (!m_pUser->GetIRCSock()) + if (!m_pNetwork->GetIRCSock()) return CONTINUE; if (sCmd.Equals("MODE")) { @@ -334,7 +334,7 @@ private: // 353 needs special treatment due to NAMESX and UHNAMES if (bIsRaw353) - GetUser()->GetIRCSock()->ForwardRaw353(sLine, m_pDoing); + m_pNetwork->GetIRCSock()->ForwardRaw353(sLine, m_pDoing); else m_pDoing->PutClient(sLine); @@ -426,4 +426,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("route_replies"); } -MODULEDEFS(CRouteRepliesMod, "Send replies (e.g. to /who) to the right client only") +NETWORKMODULEDEFS(CRouteRepliesMod, "Send replies (e.g. to /who) to the right client only") diff --git a/modules/sample.cpp b/modules/sample.cpp index 68d5bc4f..d213c276 100644 --- a/modules/sample.cpp +++ b/modules/sample.cpp @@ -6,6 +6,7 @@ * by the Free Software Foundation. */ +#include "Client.h" #include "Chan.h" #include "User.h" #include "Modules.h" @@ -183,7 +184,7 @@ public: } virtual EModRet OnUserTopic(CString& sTarget, CString& sTopic) { - PutModule("* " + m_pUser->GetCurNick() + " changed topic on " + sTarget + " to '" + sTopic + "'"); + PutModule("* " + m_pClient->GetNick() + " changed topic on " + sTarget + " to '" + sTopic + "'"); return CONTINUE; } diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index eca5f2cc..9a5d5d2a 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -16,6 +16,7 @@ #include "Chan.h" #include "User.h" +#include "IRCNetwork.h" #include "FileUtils.h" #include @@ -84,7 +85,7 @@ public: { m_bFirstLoad = true; AddTimer(new CSaveBuffJob(this, 60, 0, "SaveBuff", "Saves the current buffer to disk every 1 minute")); - const vector& vChans = m_pUser->GetChans(); + const vector& vChans = m_pNetwork->GetChans(); for (u_int a = 0; a < vChans.size(); a++) { if (!vChans[a]->KeepBuffer()) @@ -130,7 +131,7 @@ public: { if (!m_sPassword.empty()) { - const vector& vChans = m_pUser->GetChans(); + const vector& vChans = m_pNetwork->GetChans(); for (u_int a = 0; a < vChans.size(); a++) { CString sPath = GetPath(vChans[a]->GetName()); @@ -246,7 +247,7 @@ public: void AddBuffer(CChan& chan, const CString &sLine) { // If they have keep buffer disabled, only add messages if no client is connected - if (!chan.KeepBuffer() && m_pUser->IsUserAttached()) + if (!chan.KeepBuffer() && m_pNetwork->IsUserAttached()) return; chan.AddBuffer(sLine); } @@ -339,5 +340,5 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("savebuff"); } -MODULEDEFS(CSaveBuff, "Stores channel buffers to disk, encrypted") +NETWORKMODULEDEFS(CSaveBuff, "Stores channel buffers to disk, encrypted") diff --git a/modules/schat.cpp b/modules/schat.cpp index bdfa78c9..c983abd3 100644 --- a/modules/schat.cpp +++ b/modules/schat.cpp @@ -13,6 +13,7 @@ #include "FileUtils.h" #include "User.h" +#include "IRCNetwork.h" #include "znc.h" #include @@ -384,13 +385,13 @@ public: void SendToUser(const CString & sFrom, const CString & sText) { //:*schat!znc@znc.in PRIVMSG Jim : - CString sSend = ":" + sFrom + " PRIVMSG " + m_pUser->GetCurNick() + " :" + sText; + CString sSend = ":" + sFrom + " PRIVMSG " + m_pNetwork->GetCurNick() + " :" + sText; PutUser(sSend); } bool IsAttached() { - return(m_pUser->IsUserAttached()); + return(m_pNetwork->IsUserAttached()); } private: @@ -468,5 +469,5 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("schat"); } -MODULEDEFS(CSChat, "Secure cross platform (:P) chat system") +NETWORKMODULEDEFS(CSChat, "Secure cross platform (:P) chat system") diff --git a/modules/stickychan.cpp b/modules/stickychan.cpp index 5c7a9f0c..ae1b1188 100644 --- a/modules/stickychan.cpp +++ b/modules/stickychan.cpp @@ -7,7 +7,7 @@ */ #include "Chan.h" -#include "User.h" +#include "IRCNetwork.h" class CStickyChan : public CModule { @@ -25,7 +25,7 @@ public: { if (sChannel.Equals(it->first)) { - CChan* pChan = m_pUser->FindChan(sChannel); + CChan* pChan = m_pNetwork->FindChan(sChannel); if (pChan) { @@ -76,17 +76,17 @@ public: virtual void RunJob() { - if (!m_pUser->GetIRCSock()) + if (!m_pNetwork->GetIRCSock()) return; for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) { - CChan *pChan = m_pUser->FindChan(it->first); + CChan *pChan = m_pNetwork->FindChan(it->first); if (!pChan) { - pChan = new CChan(it->first, m_pUser, true); + pChan = new CChan(it->first, m_pNetwork, true); if (!it->second.empty()) pChan->SetKey(it->second); - if (!m_pUser->AddChan(pChan)) { + if (!m_pNetwork->AddChan(pChan)) { /* AddChan() deleted that channel */ PutModule("Could not join [" + it->first + "] (# prefix missing?)"); @@ -107,7 +107,7 @@ public: if (sPageName == "index") { bool bSubmitted = (WebSock.GetParam("submitted").ToInt() != 0); - const vector& Channels = m_pUser->GetChans(); + const vector& Channels = m_pNetwork->GetChans(); for (unsigned int c = 0; c < Channels.size(); c++) { const CString sChan = Channels[c]->GetName(); bool bStick = FindNV(sChan) != EndNV(); diff --git a/modules/watch.cpp b/modules/watch.cpp index 41898b5f..bb236bf0 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -8,6 +8,7 @@ #include "Chan.h" #include "User.h" +#include "IRCNetwork.h" #include using std::list; @@ -167,7 +168,7 @@ public: virtual void OnClientLogin() { CString sBufLine; - while (m_Buffer.GetNextLine(m_pUser->GetCurNick(), sBufLine)) { + while (m_Buffer.GetNextLine(m_pNetwork->GetCurNick(), sBufLine)) { PutUser(sBufLine); } @@ -287,9 +288,9 @@ private: CWatchEntry& WatchEntry = *it; if (WatchEntry.IsMatch(Nick, sMessage, sSource, m_pUser)) { - if (m_pUser->IsUserAttached()) { - m_pUser->PutUser(":" + WatchEntry.GetTarget() + "!watch@znc.in PRIVMSG " + - m_pUser->GetCurNick() + " :" + sMessage); + if (m_pNetwork->IsUserAttached()) { + m_pNetwork->PutUser(":" + WatchEntry.GetTarget() + "!watch@znc.in PRIVMSG " + + m_pNetwork->GetCurNick() + " :" + sMessage); } else { m_Buffer.AddLine(":" + WatchEntry.GetTarget() + "!watch@znc.in PRIVMSG ", " :" + m_pUser->AddTimestamp(sMessage)); @@ -554,4 +555,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("watch"); } -MODULEDEFS(CWatcherMod, "Copy activity from a specific user into a separate window") +NETWORKMODULEDEFS(CWatcherMod, "Copy activity from a specific user into a separate window")