CClient: add ATTACH command

The main benefit is that (unlike JOIN) ATTACH allows wildcards.
It's also nicely symmetric with DETACH.
This commit is contained in:
J-P Nurmi
2015-09-08 00:17:02 +02:00
parent 832430659f
commit 7f03484899
3 changed files with 48 additions and 1 deletions

View File

@@ -349,7 +349,22 @@ void CClient::ReadLine(const CString& sData) {
return;
}
if (sCommand.Equals("DETACH")) {
if (sCommand.Equals("ATTACH")) {
CString sPatterns = sLine.Token(1, true);
if (sPatterns.empty()) {
PutStatusNotice("Usage: /attach <#chans|queries>");
return;
}
set<CChan*> sChans = MatchChans(sPatterns);
unsigned int uAttachedChans = AttachChans(sChans);
PutStatusNotice("There were [" + CString(sChans.size()) + "] channels matching [" + sPatterns + "]");
PutStatusNotice("Attached [" + CString(uAttachedChans) + "] channels");
return;
} else if (sCommand.Equals("DETACH")) {
if (!m_pNetwork) {
return;
}
@@ -1061,6 +1076,18 @@ set<CChan*> CClient::MatchChans(const CString& sPatterns) const
return sChans;
}
unsigned int CClient::AttachChans(const std::set<CChan*>& sChans)
{
unsigned int uAttached = 0;
for (CChan* pChan : sChans) {
if (!pChan->IsDetached())
continue;
uAttached++;
pChan->AttachUser();
}
return uAttached;
}
unsigned int CClient::DetachChans(const std::set<CChan*>& sChans)
{
unsigned int uDetached = 0;