Permalink
Browse files

[chansaver] Add support for loading as a global module

This also fixes a bug where loading the module as a network causes other
channels in different networks to be saved

Closes #529
  • Loading branch information...
1 parent 3706598 commit ef5050e3ab187f99ad4472e64e22b6e7ba50bb6f @kylef kylef committed Apr 16, 2014
Showing with 36 additions and 13 deletions.
  1. +36 −13 modules/chansaver.cpp
View
@@ -25,24 +25,46 @@ class CChanSaverMod : public CModule {
MODCONSTRUCTOR(CChanSaverMod) {
m_bWriteConf = false;
- vector<CIRCNetwork*> vNetworks = pUser->GetNetworks();
- for (vector<CIRCNetwork*>::iterator it = vNetworks.begin(); it != vNetworks.end(); ++it) {
- const vector<CChan*>& vChans = (*it)->GetChans();
+ if (GetNetwork()) {
+ LoadNetwork(*GetNetwork());
@DarthGandalf

DarthGandalf Apr 16, 2014

Owner

A bug: /znc loadmod --type=user while connected with a network does have non-NULL GetNetwork()

@DarthGandalf

DarthGandalf Apr 16, 2014

Owner

Use GetType() instead

+ } else if (GetUser()) {
+ LoadUser(*GetUser());
+ } else {
+ LoadUsers();
+ }
+ }
- for (vector<CChan*>::const_iterator it2 = vChans.begin(); it2 != vChans.end(); ++it2) {
- CChan *pChan = *it2;
+ virtual ~CChanSaverMod() {
+ }
- // If that channel isn't yet in the config,
- // we'll have to add it...
- if (!pChan->InConfig()) {
- pChan->SetInConfig(true);
- m_bWriteConf = true;
- }
- }
+ void LoadUsers() {
+ std::map<CString, CUser *> vUsers = CZNC::Get().GetUserMap();
+ for (std::map<CString, CUser *>::iterator it = vUsers.begin(); it != vUsers.end(); ++it) {
+ LoadUser(*it->second);
}
}
- virtual ~CChanSaverMod() {
+ void LoadUser(CUser &user) {
+ vector<CIRCNetwork*> vNetworks = user.GetNetworks();
+ for (vector<CIRCNetwork*>::iterator it = vNetworks.begin(); it != vNetworks.end(); ++it) {
+ CIRCNetwork &network = **it;
+ LoadNetwork(network);
+ }
+ }
+
+ void LoadNetwork(CIRCNetwork &network) {
+ const vector<CChan*>& vChans = network.GetChans();
+
+ for (vector<CChan*>::const_iterator it = vChans.begin(); it != vChans.end(); ++it) {
+ CChan &chan = **it;
+
+ // If that channel isn't yet in the config,
+ // we'll have to add it...
+ if (!chan.InConfig()) {
+ chan.SetInConfig(true);
+ m_bWriteConf = true;
+ }
+ }
}
virtual EModRet OnRaw(CString& sLine) {
@@ -86,6 +108,7 @@ class CChanSaverMod : public CModule {
template<> void TModInfo<CChanSaverMod>(CModInfo& Info) {
Info.SetWikiPage("chansaver");
Info.AddType(CModInfo::NetworkModule);
+ Info.AddType(CModInfo::UserModule);
@DarthGandalf

DarthGandalf Apr 16, 2014

Owner

Are you sure?

}
USERMODULEDEFS(CChanSaverMod, "Keep config up-to-date when user joins/parts")

0 comments on commit ef5050e

Please sign in to comment.