Fix webadmin when editing a user

Since this creates a new user, and then clones it. It would clear all
the networks. To fix this, I have made an option bCloneNetworks to
CUser::Clone. This replaces the bCloneChans because this is unnessecery
now.

Fixes #88
This commit is contained in:
Kyle Fuller
2011-11-13 00:18:43 +00:00
parent 2ffcbed5bb
commit 01b15bfb5b
4 changed files with 40 additions and 40 deletions
+33 -32
View File
@@ -563,7 +563,7 @@ void CUser::UserDisconnected(CClient* pClient) {
}
}
bool CUser::Clone(const CUser& User, CString& sErrorRet, bool bCloneChans) {
bool CUser::Clone(const CUser& User, CString& sErrorRet, bool bCloneNetworks) {
unsigned int a = 0;
sErrorRet.clear();
@@ -615,40 +615,41 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet, bool bCloneChans) {
// !Allowed Hosts
// Networks
const vector<CIRCNetwork*>& vNetworks = User.GetNetworks();
for (vector<CIRCNetwork*>::const_iterator it = vNetworks.begin(); it != vNetworks.end(); ++it) {
CIRCNetwork *pNetwork = FindNetwork((*it)->GetName());
if (bCloneNetworks) {
const vector<CIRCNetwork*>& vNetworks = User.GetNetworks();
for (vector<CIRCNetwork*>::const_iterator it = vNetworks.begin(); it != vNetworks.end(); ++it) {
CIRCNetwork *pNetwork = FindNetwork((*it)->GetName());
if (pNetwork) {
pNetwork->Clone(*(*it), bCloneChans);
} else {
new CIRCNetwork(this, *(*it), bCloneChans);
}
}
set<CString> ssDeleteNetworks;
for (vector<CIRCNetwork*>::const_iterator it = m_vIRCNetworks.begin(); it != m_vIRCNetworks.end(); ++it) {
if (!(User.FindNetwork((*it)->GetName()))) {
ssDeleteNetworks.insert((*it)->GetName());
}
}
for (set<CString>::const_iterator it = ssDeleteNetworks.begin(); it != ssDeleteNetworks.end(); ++it) {
// The following will move all the clients to the user.
// So the clients are not disconnected. The client could
// have requested the rehash. Then when we do
// client->PutStatus("Rehashing succeeded!") we would
// crash if there was no client anymore.
vector<CClient*>& vClients = FindNetwork(*it)->GetClients();
while (vClients.begin() != vClients.end()) {
CClient *pClient = vClients.front();
// This line will remove pClient from vClients,
// because it's a reference to the internal Network's vector.
pClient->SetNetwork(NULL);
if (pNetwork) {
pNetwork->Clone(*(*it));
} else {
new CIRCNetwork(this, *(*it));
}
}
DeleteNetwork(*it);
set<CString> ssDeleteNetworks;
for (vector<CIRCNetwork*>::const_iterator it = m_vIRCNetworks.begin(); it != m_vIRCNetworks.end(); ++it) {
if (!(User.FindNetwork((*it)->GetName()))) {
ssDeleteNetworks.insert((*it)->GetName());
}
}
for (set<CString>::const_iterator it = ssDeleteNetworks.begin(); it != ssDeleteNetworks.end(); ++it) {
// The following will move all the clients to the user.
// So the clients are not disconnected. The client could
// have requested the rehash. Then when we do
// client->PutStatus("Rehashing succeeded!") we would
// crash if there was no client anymore.
vector<CClient*>& vClients = FindNetwork(*it)->GetClients();
while (vClients.begin() != vClients.end()) {
CClient *pClient = vClients.front();
// This line will remove pClient from vClients,
// because it's a reference to the internal Network's vector.
pClient->SetNetwork(NULL);
DeleteNetwork(*it);
}
}
}
// !Networks