Created
November 30, 2011 00:48
-
-
Save reuben/1407418 to your computer and use it in GitHub Desktop.
pbcmd fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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" | |
#include "IRCNetwork.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; | |
} | |
namespace { | |
CChan* FindChan(CUser *user, CString chan) { | |
vector<CIRCNetwork *>::const_iterator vnetwork; | |
const vector<CIRCNetwork *>& vnetworks = user->GetNetworks(); | |
CChan *res; | |
for (vnetwork = vnetworks.begin(); vnetwork != vnetworks.end(); vnetwork++) { | |
res = (*vnetwork)->FindChan(chan); | |
if (res) | |
return res; | |
} | |
return NULL; | |
} | |
} | |
void CPBCmdMod::OnModCommand(const CString& sCommand) | |
{ | |
CString cmd = sCommand.Token(0).AsLower(); | |
if(cmd == "playall") | |
{ | |
vector<CIRCNetwork *>::const_iterator vnetwork; | |
const vector<CIRCNetwork *>& vnetworks = m_pUser->GetNetworks(); | |
for(vnetwork = vnetworks.begin(); vnetwork != vnetworks.end(); vnetwork++) { | |
vector<CChan *>::const_iterator vchan; | |
const vector<CChan *>& vchans = (*vnetwork)->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 = ::FindChan(m_pUser, 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