bool CIRCNetwork::IsUserOnline() const { vector<CClient*>::const_iterator it; for (it = m_vClients.begin(); it != m_vClients.end(); ++it) { CClient *pClient = *it; if (!pClient->IsAway()) { return true; } } return false; }
void SetAwayCommand(const CString &sLine) { const vector<CClient*> vClients = m_pUser->GetAllClients(); CString sHostname = sLine.Token(1); // Valid value of true or false for setting away/unaway bool sToggleFlag = true; CString sToggleValue = "away"; VCString sReturn; // If the hostname argument isn't passed and only arg is true/false, treat that as sToggleFlag if (sHostname.AsLower() == "true" || sHostname.AsLower() == "false" ) { sToggleFlag = sHostname.ToBool(); sHostname = ""; } unsigned int count = 0; for (vector<CClient*>::const_iterator it = vClients.begin(); it != vClients.end(); ++it) { CClient *pClient = *it; //Set all hosts to away if we encounter an empty hostname //Otherwise, set the flag to the provided second argument value if (pClient->GetRemoteIP().Equals(sHostname)) { if (sLine.Token(2).empty()) { sToggleFlag = !pClient->IsAway(); } else { sToggleFlag = sLine.Token(2).ToBool(); } } if (sHostname.empty() || pClient->GetRemoteIP().Equals(sHostname)) { pClient->SetAway(sToggleFlag); ++count; } } if (!sToggleFlag) { sToggleValue = "unaway"; } if (count == 1) { PutModule(CString(count) + " client has been set " + sToggleValue); } else { PutModule(CString(count) + " clients have been set " + sToggleValue); } }
void DecideAwayness() { int notAways = 0; int clients = 0; vector<CClient*> vUserClients = m_pUser->GetAllClients(); for (size_t c = 0; c < vUserClients.size(); ++c) { CClient* pUserClient = vUserClients[c]; if (!pUserClient->IsAway()) { ++notAways; } ++clients; } char tmpchr[256]; tmpchr[255] = '\0'; snprintf(tmpchr, 255, "Clients NOT away: %d/%d", notAways, clients); PutModule(tmpchr); if (clients == 0) { if (!m_isAway) { m_isAway = true; PutIRC("AWAY :Detached"); } return; } else if (notAways == 0) { if (!m_isAway) { m_isAway = true; PutIRC("AWAY :Auto away"); } return; } else { if (m_isAway) { m_isAway = false; PutIRC("AWAY"); } } if (GetClient()->IsAway()) { GetClient()->PutClient(":irc.znc.in 306 + " + GetUser()->GetNick() + " :You are not visibly away yet. " + tmpchr); } }
void ListCommand(const CString &sLine) { CTable Table; Table.AddColumn("Host"); Table.AddColumn("Network"); Table.AddColumn("Away"); const vector<CClient*> vClients = m_pUser->GetAllClients(); for (vector<CClient*>::const_iterator it = vClients.begin(); it != vClients.end(); ++it) { CClient *pClient = *it; Table.AddRow(); Table.SetCell("Host", pClient->GetRemoteIP()); if (pClient->GetNetwork()) { Table.SetCell("Network", pClient->GetNetwork()->GetName()); } Table.SetCell("Away", CString(pClient->IsAway())); } PutModule(Table); }