diff --git a/modules/autoop.cpp b/modules/autoop.cpp index e71ac785..96ddfe8a 100644 --- a/modules/autoop.cpp +++ b/modules/autoop.cpp @@ -50,10 +50,10 @@ public: FromString(sLine); } - CAutoOpUser(const CString& sUsername, const CString& sUserKey, const CString& sHostmask, const CString& sChannels) : + CAutoOpUser(const CString& sUsername, const CString& sUserKey, const CString& sHostmasks, const CString& sChannels) : m_sUsername(sUsername), - m_sUserKey(sUserKey), - m_sHostmask(sHostmask) { + m_sUserKey(sUserKey) { + AddHostmasks(sHostmasks); AddChans(sChannels); } @@ -61,7 +61,6 @@ public: const CString& GetUsername() const { return m_sUsername; } const CString& GetUserKey() const { return m_sUserKey; } - const CString& GetHostmask() const { return m_sHostmask; } bool ChannelMatches(const CString& sChan) const { for (set::const_iterator it = m_ssChans.begin(); it != m_ssChans.end(); ++it) { @@ -74,7 +73,26 @@ public: } bool HostMatches(const CString& sHostmask) { - return sHostmask.WildCmp(m_sHostmask); + for (set::const_iterator it = m_ssHostmasks.begin(); it != m_ssHostmasks.end(); ++it) { + if (sHostmask.WildCmp(*it)) { + return true; + } + } + return false; + } + + CString GetHostmasks() const { + CString sRet; + + for (set::const_iterator it = m_ssHostmasks.begin(); it != m_ssHostmasks.end(); ++it) { + if (!sRet.empty()) { + sRet += ","; + } + + sRet += *it; + } + + return sRet; } CString GetChannels() const { @@ -91,6 +109,24 @@ public: return sRet; } + void DelHostmasks(const CString& sHostmasks) { + VCString vsHostmasks; + sHostmasks.Split(",", vsHostmasks); + + for (unsigned int a = 0; a < vsHostmasks.size(); a++) { + m_ssHostmasks.erase(vsHostmasks[a]); + } + } + + void AddHostmasks(const CString& sHostmasks) { + VCString vsHostmasks; + sHostmasks.Split(",", vsHostmasks); + + for (unsigned int a = 0; a < vsHostmasks.size(); a++) { + m_ssHostmasks.insert(vsHostmasks[a]); + } + } + void DelChans(const CString& sChans) { VCString vsChans; sChans.Split(" ", vsChans); @@ -111,6 +147,15 @@ public: CString ToString() const { CString sChans; + CString sHostmasks; + + for (set::const_iterator it = m_ssHostmasks.begin(); it != m_ssHostmasks.end(); ++it) { + if (!sHostmasks.empty()) { + sHostmasks += ","; + } + + sHostmasks += *it; + } for (set::const_iterator it = m_ssChans.begin(); it != m_ssChans.end(); ++it) { if (!sChans.empty()) { @@ -120,12 +165,12 @@ public: sChans += *it; } - return m_sUsername + "\t" + m_sHostmask + "\t" + m_sUserKey + "\t" + sChans; + return m_sUsername + "\t" + sHostmasks + "\t" + m_sUserKey + "\t" + sChans; } bool FromString(const CString& sLine) { m_sUsername = sLine.Token(0, false, "\t"); - m_sHostmask = sLine.Token(1, false, "\t"); + sLine.Token(1, false, "\t").Split(",", m_ssHostmasks); m_sUserKey = sLine.Token(2, false, "\t"); sLine.Token(3, false, "\t").Split(" ", m_ssChans); @@ -135,7 +180,7 @@ private: protected: CString m_sUsername; CString m_sUserKey; - CString m_sHostmask; + set m_ssHostmasks; set m_ssChans; }; @@ -165,7 +210,6 @@ public: for (map::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) { delete it->second; } - m_msUsers.clear(); } @@ -226,7 +270,7 @@ public: CString sCommand = sLine.Token(0).AsUpper(); if (sCommand.Equals("HELP")) { - PutModule("Commands are: ListUsers, AddChans, DelChans, AddUser, DelUser"); + PutModule("Commands are: ListUsers, AddChans, DelChans, AddMasks, DelMasks, AddUser, DelUser"); } else if (sCommand.Equals("TIMERS")) { ListTimers(); } else if (sCommand.Equals("ADDUSER") || sCommand.Equals("DELUSER")) { @@ -264,7 +308,7 @@ public: for (map::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) { Table.AddRow(); Table.SetCell("User", it->second->GetUsername()); - Table.SetCell("Hostmask", it->second->GetHostmask()); + Table.SetCell("Hostmask", it->second->GetHostmasks()); Table.SetCell("Key", it->second->GetUserKey()); Table.SetCell("Channels", it->second->GetChannels()); } @@ -294,6 +338,31 @@ public: PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]"); } + SetNV(pUser->GetUsername(), pUser->ToString()); + } else if (sCommand.Equals("ADDMASKS") || sCommand.Equals("DELMASKS")) { + CString sUser = sLine.Token(1); + CString sHostmasks = sLine.Token(2, true); + + if (sHostmasks.empty()) { + PutModule("Usage: " + sCommand + " [mask] ..."); + return; + } + + CAutoOpUser* pUser = FindUser(sUser); + + if (!pUser) { + PutModule("No such user"); + return; + } + + if (sCommand.Equals("ADDMASKS")) { + pUser->AddHostmasks(sHostmasks); + PutModule("Hostmasks(s) added to user [" + pUser->GetUsername() + "]"); + } else { + pUser->DelHostmasks(sHostmasks); + PutModule("Hostmasks(s) Removed from user [" + pUser->GetUsername() + "]"); + } + SetNV(pUser->GetUsername(), pUser->ToString()); } else { PutModule("Unknown command, try HELP"); @@ -351,15 +420,15 @@ public: PutModule("User [" + sUser + "] removed"); } - CAutoOpUser* AddUser(const CString& sUser, const CString& sKey, const CString& sHost, const CString& sChans) { + CAutoOpUser* AddUser(const CString& sUser, const CString& sKey, const CString& sHosts, const CString& sChans) { if (m_msUsers.find(sUser) != m_msUsers.end()) { PutModule("That user already exists"); return NULL; } - CAutoOpUser* pUser = new CAutoOpUser(sUser, sKey, sHost, sChans); + CAutoOpUser* pUser = new CAutoOpUser(sUser, sKey, sHosts, sChans); m_msUsers[sUser.AsLower()] = pUser; - PutModule("User [" + sUser + "] added with hostmask [" + sHost + "]"); + PutModule("User [" + sUser + "] added with hostmask(s) [" + sHosts + "]"); return pUser; }