Skip to content

Instantly share code, notes, and snippets.

@ohlol
Forked from jgeboski/pbcmd.cpp
Created December 7, 2011 06:09
Show Gist options
  • Save ohlol/1441669 to your computer and use it in GitHub Desktop.
Save ohlol/1441669 to your computer and use it in GitHub Desktop.
ZNC Playback on Command
/*
* Copyright (C) 2011 James Geboski <jgeboski@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#include "Chan.h"
#include "Client.h"
#include "Modules.h"
#include "User.h"
class CPBCmdMod: public CModule
{
protected:
bool allowPlay;
public:
MODCONSTRUCTOR(CPBCmdMod) {};
virtual bool OnLoad(const CString& sArgsi, CString& sMessage);
virtual void OnModCommand(const CString& sCommand);
virtual EModRet OnChanBufferStarting(CChan& Chan, CClient& Client);
virtual EModRet OnChanBufferEnding(CChan& Chan, CClient& Client);
virtual EModRet OnChanBufferPlayLine(CChan& Chan, CClient& Client, CString& sLine);
virtual EModRet OnPrivBufferPlayLine(CClient& Client, CString& sLine);
};
bool CPBCmdMod::OnLoad(const CString& sArgsi, CString& sMessage)
{
allowPlay = false;
return true;
}
void CPBCmdMod::OnModCommand(const CString& sCommand)
{
CString cmd = sCommand.Token(0).AsLower();
if(cmd == "playall")
{
vector<CChan *>::const_iterator vchan;
const vector<CChan *>& vchans = m_pUser->GetChans();
allowPlay = true;
for(vchan = vchans.begin(); vchan != vchans.end(); vchan++)
{
if(!(*vchan)->IsOn())
continue;
(*vchan)->SendBuffer(m_pClient);
}
allowPlay = false;
}
else if(cmd == "play")
{
CString schan = sCommand.Token(1);
if(schan.empty())
{
PutModule("Usage: play <#channel>");
return;
}
CChan * chan = m_pUser->FindChan(schan);
if(!chan || !chan->IsOn())
{
PutModule("Not on channel: " + schan);
return;
}
allowPlay = true;
chan->SendBuffer(m_pClient);
allowPlay = false;
}
else
{
PutModule("Commands:");
PutModule(" PlayAll Play back the buffer for all channels");
PutModule(" Play <#channel> Play back the buffer for a given channel");
}
}
CModule::EModRet CPBCmdMod::OnChanBufferStarting(CChan& Chan, CClient& Client)
{
if(allowPlay)
return CONTINUE;
return HALT;
}
CModule::EModRet CPBCmdMod::OnChanBufferEnding(CChan& Chan, CClient& Client)
{
if(allowPlay)
return CONTINUE;
return HALT;
}
CModule::EModRet CPBCmdMod::OnChanBufferPlayLine(CChan& Chan, CClient& Client, CString& sLine)
{
if(allowPlay)
return CONTINUE;
return HALT;
}
CModule::EModRet CPBCmdMod::OnPrivBufferPlayLine(CClient& Client, CString& sLine)
{
if(allowPlay)
return CONTINUE;
return HALT;
}
MODULEDEFS(CPBCmdMod, "Plays back buffer on command")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment