Permalink
Browse files

Update autoop.cpp

Added support for multiple comma separated hostmasks per user. Added new commands to add and remove hostmasks. Kept the table column names the same so as to not break back-compatability.

I have tested adding and removing several hostmasks for multiple users and checked that it does auto-op them correctly, looks good!
  • Loading branch information...
1 parent 638b3b5 commit ba1ff0ec2a8c0b1ea371574783c4b3780d22cf9f @orchid-hybrid orchid-hybrid committed Jun 8, 2014
Showing with 83 additions and 14 deletions.
  1. +83 −14 modules/autoop.cpp
View
@@ -50,18 +50,17 @@ class CAutoOpUser {
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);
}
virtual ~CAutoOpUser() {}
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<CString>::const_iterator it = m_ssChans.begin(); it != m_ssChans.end(); ++it) {
@@ -74,7 +73,26 @@ class CAutoOpUser {
}
bool HostMatches(const CString& sHostmask) {
- return sHostmask.WildCmp(m_sHostmask);
+ for (set<CString>::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<CString>::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 @@ class CAutoOpUser {
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 @@ class CAutoOpUser {
CString ToString() const {
CString sChans;
+ CString sHostmasks;
+
+ for (set<CString>::const_iterator it = m_ssHostmasks.begin(); it != m_ssHostmasks.end(); ++it) {
+ if (!sHostmasks.empty()) {
+ sHostmasks += ",";
+ }
+
+ sHostmasks += *it;
+ }
for (set<CString>::const_iterator it = m_ssChans.begin(); it != m_ssChans.end(); ++it) {
if (!sChans.empty()) {
@@ -120,12 +165,12 @@ class CAutoOpUser {
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 @@ class CAutoOpUser {
protected:
CString m_sUsername;
CString m_sUserKey;
- CString m_sHostmask;
+ set<CString> m_ssHostmasks;
set<CString> m_ssChans;
};
@@ -165,7 +210,6 @@ class CAutoOpMod : public CModule {
for (map<CString, CAutoOpUser*>::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) {
delete it->second;
}
-
m_msUsers.clear();
}
@@ -226,7 +270,7 @@ class CAutoOpMod : public CModule {
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 @@ class CAutoOpMod : public CModule {
for (map<CString, CAutoOpUser*>::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());
}
@@ -295,6 +339,31 @@ class CAutoOpMod : public CModule {
}
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 + " <user> <mask> [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 @@ class CAutoOpMod : public CModule {
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;
}

0 comments on commit ba1ff0e

Please sign in to comment.