From: Kyle Fuller Date: Mon, 18 Mar 2013 22:01:36 +0000 (+0000) Subject: Add a command to list all registered devices X-Git-Tag: 1.0.0~30 X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=b6ffcc41c514d72d4d51e5782b3c205ccbf50e16;p=znc-palaver.git Add a command to list all registered devices --- diff --git a/palaver.cpp b/palaver.cpp index 55f35bb..9ea38de 100644 --- a/palaver.cpp +++ b/palaver.cpp @@ -318,6 +318,10 @@ public: module.AddSocket(pSocket); } + std::map GetNetworks() const { + return m_msvsNetworks; + } + private: CString m_sToken; CString m_sVersion; @@ -344,6 +348,8 @@ public: AddHelpCommand(); AddCommand("test", static_cast(&CPalaverMod::HandleTestCommand), "", "Send notifications to registered devices"); + AddCommand("list", static_cast(&CPalaverMod::HandleListCommand), + "", "List all registered devices"); } #pragma mark - Cap @@ -574,6 +580,54 @@ public: } } + void HandleListCommand(const CString &sLine) { + if (m_pUser->IsAdmin() == false) { + PutModule("Permission denied"); + return; + } + + CTable Table; + + Table.AddColumn("Device"); + Table.AddColumn("User"); + Table.AddColumn("Network"); + Table.AddColumn("Negotiating"); + + for (std::vector::const_iterator it = m_vDevices.begin(); + it != m_vDevices.end(); ++it) + { + CDevice &device = **it; + + const std::map msvsNetworks = device.GetNetworks(); + std::map::const_iterator it2 = msvsNetworks.begin(); + for (;it2 != msvsNetworks.end(); ++it2) { + const CString sUsername = it2->first; + const VCString &networks = it2->second; + + for (VCString::const_iterator it3 = networks.begin(); it3 != networks.end(); ++it3) { + const CString sNetwork = *it3; + + Table.AddRow(); + Table.SetCell("Device", device.GetToken()); + Table.SetCell("User", sUsername); + Table.SetCell("Network", sNetwork); + Table.SetCell("Negotiating", CString(device.InNegotiation())); + } + } + } + + if (PutModule(Table) == 0) { + PutModule("There are no devices registered with this server."); + } + + CDevice *pDevice = DeviceForClient(*m_pClient); + if (pDevice) { + PutModule("You are connected from Palaver. (" + pDevice->GetToken() + ")"); + } else { + PutModule("You are not connected from a Palaver client."); + } + } + private: std::vector m_vDevices;