forked from jpnurmi/znc-clientbuffer
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage as a user module #10
Comments
Here is a draft patch: diff --git a/clientbuffer.cpp b/clientbuffer.cpp
index a207072..e92a6d8 100644
--- a/clientbuffer.cpp
+++ b/clientbuffer.cpp
@@ -106,6 +106,8 @@ private:
bool m_bDirty = false;
int m_iTimeLimit = 0;
+ CString GetClientIdentifier(const CClient &client);
+
bool AddClient(const CString& identifier);
bool DelClient(const CString& identifier);
bool SetClientTimeLimit(const CString& identifier, const int timeLimit);
@@ -188,10 +190,18 @@ void CClientBufferMod::OnSetClientTimeLimit(const CString& line)
PutModule("Client's " + identifier + " cleared time limit.");
}
+CString CClientBufferMod::GetClientIdentifier(const CClient &client)
+{
+ if (GetType() == CModInfo::NetworkModule)
+ return client.GetIdentifier();
+ else
+ return client.GetIdentifier() + "@" + client.GetNetwork()->GetName();
+}
+
/// Callback for the ListClients module command.
void CClientBufferMod::OnListClientsCommand(const CString& line)
{
- const CString& current = GetClient()->GetIdentifier();
+ const CString& current = GetClientIdentifier(*GetClient());
CTable table;
table.AddColumn("Client");
@@ -220,7 +230,7 @@ void CClientBufferMod::OnListClientsCommand(const CString& line)
/// Implements the "autoadd" option.
void CClientBufferMod::OnClientLogin()
{
- const CString& current = GetClient()->GetIdentifier();
+ const CString& current = GetClientIdentifier(*GetClient());
if (!HasClient(current) && m_bAutoAdd) {
AddClient(current);
@@ -253,7 +263,7 @@ CModule::EModRet CClientBufferMod::OnUserRawMessage(CMessage& Message)
return CONTINUE;
if (WantMessageType(Message.GetType()))
- UpdateTimestamp(client->GetIdentifier(), GetTarget(Message), Message.GetTime());
+ UpdateTimestamp(GetClientIdentifier(*client), GetTarget(Message), Message.GetTime());
return CONTINUE;
}
@@ -277,7 +287,7 @@ CModule::EModRet CClientBufferMod::OnUserTextMessage(CTextMessage& Message)
{
CClient* client = Message.GetClient();
if (client)
- UpdateTimestamp(client->GetIdentifier(), GetTarget(Message), Message.GetTime());
+ UpdateTimestamp(GetClientIdentifier(*client), GetTarget(Message), Message.GetTime());
return CONTINUE;
}
@@ -295,7 +305,7 @@ CModule::EModRet CClientBufferMod::OnSendToClientMessage(CMessage& Message)
// make sure not to update the timestamp for a channel when attaching it
CChan* chan = Message.GetChan();
if (!chan || !chan->IsDetached())
- UpdateTimestamp(Message.GetClient()->GetIdentifier(), GetTarget(Message), Message.GetTime());
+ UpdateTimestamp(GetClientIdentifier(*Message.GetClient()), GetTarget(Message), Message.GetTime());
return CONTINUE;
}
#else
@@ -322,7 +332,7 @@ CModule::EModRet CClientBufferMod::OnChanBufferStarting(CChan& chan, CClient& cl
if (client.HasServerTime())
return HALTCORE;
- const CString& identifier = client.GetIdentifier();
+ const CString& identifier = GetClientIdentifier(client);
if (!HasClient(identifier))
return HALTCORE;
@@ -344,7 +354,7 @@ CModule::EModRet CClientBufferMod::OnChanBufferEnding(CChan& chan, CClient& clie
if (client.HasServerTime())
return HALTCORE;
- const CString& identifier = client.GetIdentifier();
+ const CString& identifier = GetClientIdentifier(client);
if (!HasClient(identifier))
return HALTCORE;
@@ -368,7 +378,7 @@ CModule::EModRet CClientBufferMod::OnChanBufferPlayMessage(CMessage& Message)
if (!client)
return CONTINUE;
- const CString& identifier = client->GetIdentifier();
+ const CString& identifier = GetClientIdentifier(*client);
if (!HasClient(identifier))
return HALTCORE;
@@ -383,7 +393,7 @@ CModule::EModRet CClientBufferMod::OnChanBufferPlayMessage(CMessage& Message)
#else
CModule::EModRet CClientBufferMod::OnChanBufferPlayLine2(CChan& chan, CClient& client, CString& line, const timeval& tv)
{
- const CString& identifier = client.GetIdentifier();
+ const CString& identifier = GetClientIdentifier(client);
if (!HasClient(identifier))
return HALTCORE;
@@ -406,7 +416,7 @@ CModule::EModRet CClientBufferMod::OnPrivBufferPlayMessage(CMessage& Message)
if (!client)
return CONTINUE;
- const CString& identifier = client->GetIdentifier();
+ const CString& identifier = GetClientIdentifier(*client);
if (!HasClient(identifier))
return HALTCORE;
@@ -421,7 +431,7 @@ CModule::EModRet CClientBufferMod::OnPrivBufferPlayMessage(CMessage& Message)
#else
CModule::EModRet CClientBufferMod::OnPrivBufferPlayLine2(CClient& client, CString& line, const timeval& tv)
{
- const CString& identifier = client.GetIdentifier();
+ const CString& identifier = GetClientIdentifier(client);
if (!HasClient(identifier))
return HALTCORE;
@@ -585,7 +595,7 @@ bool CClientBufferMod::UpdateTimestamp(const CString& identifier, const CString&
void CClientBufferMod::UpdateTimestamp(const CClient* client, const CString& target)
{
if (client && !client->IsPlaybackActive()) {
- const CString& identifier = client->GetIdentifier();
+ const CString& identifier = GetClientIdentifier(*client);
if (HasClient(identifier)) {
timeval tv;
gettimeofday(&tv, NULL);
@@ -607,6 +617,7 @@ bool CClientBufferMod::WithinTimeLimit(const timeval& tv, const CString& identif
template<> void TModInfo<CClientBufferMod>(CModInfo& info) {
info.SetWikiPage("Clientbuffer");
+ info.AddType(CModInfo::UserModule);
info.SetHasArgs(true);
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be great if I could turn this on at the user level and it would act as if I'd gone to each of my networks and enabled it for each network.
Thanks for maintaining this, by the way :-)
The text was updated successfully, but these errors were encountered: