Moved awaynick functionality into modules/awaynick.cpp module

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@775 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2006-09-17 22:57:28 +00:00
parent dd83d0604e
commit 70aafdee8f
13 changed files with 188 additions and 176 deletions
+2 -4
View File
@@ -91,7 +91,6 @@ void CIRCSock::ReadLine(const CString& sData) {
PutIRC("WHO " + sNick);
SetNick(sNick);
m_pUser->StartAwayNickTimer();
MODULECALL(OnIRCConnected(), m_pUser, NULL, );
@@ -165,7 +164,7 @@ void CIRCSock::ReadLine(const CString& sData) {
CString sBadNick = sRest.Token(0);
CString sConfNick = m_pUser->GetNick().Left(uMax);
if (sNick == "*" || sNick.CaseCmp(CNick::Concat(sConfNick, m_pUser->GetAwaySuffix(), GetMaxNickLen())) == 0) {
if (sNick == "*") {
CString sAltNick = m_pUser->GetAltNick().Left(uMax);
if (sBadNick.CaseCmp(sConfNick) == 0) {
@@ -597,9 +596,8 @@ void CIRCSock::ReadLine(const CString& sData) {
void CIRCSock::KeepNick(bool bForce) {
const CString& sConfNick = m_pUser->GetNick();
CString sAwayNick = CNick::Concat(sConfNick, m_pUser->GetAwaySuffix(), GetMaxNickLen());
if (m_bAuthed && m_bKeepNick && (!IsOrigNickPending() || bForce) && m_pUser->GetKeepNick() && GetNick().CaseCmp(sConfNick) != 0 && GetNick().CaseCmp(sAwayNick) != 0) {
if (m_bAuthed && m_bKeepNick && (!IsOrigNickPending() || bForce) && m_pUser->GetKeepNick() && GetNick().CaseCmp(sConfNick) != 0) {
PutIRC("NICK " + sConfNick);
SetOrigNickPending(true);
}
-62
View File
@@ -82,66 +82,4 @@ protected:
CUser* m_pUser;
};
class CBackNickTimer : public CCron {
public:
CBackNickTimer(CUser* pUser) : CCron() {
m_pUser = pUser;
Start(3);
}
virtual ~CBackNickTimer() {}
private:
protected:
virtual void RunJob() {
if (m_pUser->IsUserAttached() && m_pUser->IsIRCConnected()) {
CIRCSock* pIRCSock = m_pUser->GetIRCSock();
if (pIRCSock) {
CString sConfNick = m_pUser->GetNick();
if (pIRCSock->GetNick().CaseCmp(CNick::Concat(sConfNick, m_pUser->GetAwaySuffix(), pIRCSock->GetMaxNickLen())) == 0) {
pIRCSock->PutIRC("NICK " + sConfNick);
}
}
}
m_pUser->DelBackNickTimer();
CZNC::Get().GetManager().DelCronByAddr(this);
}
CUser* m_pUser;
};
class CAwayNickTimer : public CCron {
public:
CAwayNickTimer(CUser* pUser) : CCron() {
m_pUser = pUser;
Start(30);
}
virtual ~CAwayNickTimer() {}
private:
protected:
virtual void RunJob() {
if (!m_pUser->IsUserAttached() && m_pUser->IsIRCConnected()) {
CIRCSock* pIRCSock = m_pUser->GetIRCSock();
if (pIRCSock) {
const CString& sSuffix = m_pUser->GetAwaySuffix();
if (!sSuffix.empty()) {
CString sAwayNick = CNick::Concat(m_pUser->GetNick(), sSuffix, pIRCSock->GetMaxNickLen());
pIRCSock->PutIRC("NICK " + sAwayNick);
}
}
}
m_pUser->DelAwayNickTimer();
CZNC::Get().GetManager().DelCronByAddr(this);
}
CUser* m_pUser;
};
#endif // !_TIMERS_H
+17 -49
View File
@@ -37,8 +37,6 @@ CUser::CUser(const CString& sUserName) {
m_bKeepBuffer = false;
m_bAutoCycle = true;
m_bBeingDeleted = false;
m_pBackNickTimer = NULL;
m_pAwayNickTimer = NULL;
m_pKeepNickTimer = new CKeepNickTimer(this);
m_pJoinTimer = new CJoinTimer(this);
m_pMiscTimer = new CMiscTimer(this);
@@ -64,8 +62,6 @@ CUser::~CUser() {
DelModules();
#endif
CZNC::Get().GetManager().DelCronByAddr(m_pBackNickTimer);
CZNC::Get().GetManager().DelCronByAddr(m_pAwayNickTimer);
CZNC::Get().GetManager().DelCronByAddr(m_pKeepNickTimer);
CZNC::Get().GetManager().DelCronByAddr(m_pJoinTimer);
CZNC::Get().GetManager().DelCronByAddr(m_pMiscTimer);
@@ -110,6 +106,23 @@ void CUser::IRCDisconnected() {
}
}
CString CUser::ExpandString(const CString& sStr) const {
CString sRet;
return ExpandString(sStr, sRet);
}
CString& CUser::ExpandString(const CString& sStr, CString& sRet) const {
sRet = sStr;
sRet.Replace("%user%", GetUserName());
sRet.Replace("%nick%", GetUserName());
sRet.Replace("%altnick%", GetAltNick());
sRet.Replace("%ident%", GetIdent());
sRet.Replace("%realname%", GetRealName());
sRet.Replace("%vhost%", GetVHost());
return sRet;
}
void CUser::BounceAllClients() {
for (unsigned int a = 0; a < m_vClients.size(); a++) {
m_vClients[a]->BouncedOff();
@@ -125,7 +138,6 @@ void CUser::UserConnected(CClient* pClient) {
PutStatus("Another client authenticated as your user, use the 'ListClients' command to see all clients");
m_vClients.push_back(pClient);
StartBackNickTimer();
if (m_RawBuffer.IsEmpty()) {
pClient->PutClient(":irc.znc.com 001 " + pClient->GetNick() + " :- Welcome to ZNC -");
@@ -163,34 +175,6 @@ void CUser::UserConnected(CClient* pClient) {
}
}
void CUser::StartAwayNickTimer() {
if (!m_pAwayNickTimer) {
m_pAwayNickTimer = new CAwayNickTimer(this);
CZNC::Get().GetManager().AddCron(m_pAwayNickTimer);
}
}
void CUser::StartBackNickTimer() {
CIRCSock* pIRCSock = GetIRCSock();
if (pIRCSock) {
CString sConfNick = GetNick();
if (pIRCSock->GetNick().CaseCmp(CNick::Concat(sConfNick, GetAwaySuffix(), pIRCSock->GetMaxNickLen())) == 0) {
m_pBackNickTimer = new CBackNickTimer(this);
CZNC::Get().GetManager().AddCron(m_pBackNickTimer);
}
}
}
void CUser::DelAwayNickTimer() {
m_pAwayNickTimer = NULL;
}
void CUser::DelBackNickTimer() {
m_pBackNickTimer = NULL;
}
void CUser::UserDisconnected(CClient* pClient) {
for (unsigned int a = 0; a < m_vClients.size(); a++) {
if (m_vClients[a] == pClient) {
@@ -198,10 +182,6 @@ void CUser::UserDisconnected(CClient* pClient) {
break;
}
}
if (!IsUserAttached()) {
StartAwayNickTimer();
}
}
bool CUser::Clone(const CUser& User, CString& sErrorRet) {
@@ -229,7 +209,6 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet) {
SetAltNick(User.GetAltNick(false));
SetIdent(User.GetIdent(false));
SetRealName(User.GetRealName());
SetAwaySuffix(User.GetAwaySuffix());
SetStatusPrefix(User.GetStatusPrefix());
SetVHost(User.GetVHost());
SetQuitMsg(User.GetQuitMsg());
@@ -368,14 +347,6 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet) {
SetAdmin(User.IsAdmin());
// !Flags
if (!IsUserAttached()) {
if (GetAwaySuffix().empty()) {
StartBackNickTimer();
} else {
StartAwayNickTimer();
}
}
return true;
}
@@ -506,7 +477,6 @@ bool CUser::WriteConfig(CFile& File) {
PrintLine(File, "RealName", GetRealName());
PrintLine(File, "VHost", GetVHost());
PrintLine(File, "QuitMsg", GetQuitMsg());
PrintLine(File, "AwaySuffix", GetAwaySuffix());
PrintLine(File, "StatusPrefix", GetStatusPrefix());
PrintLine(File, "ChanModes", GetDefaultChanModes());
PrintLine(File, "Buffer", CString(GetBufferCount()));
@@ -928,7 +898,6 @@ void CUser::SetUserName(const CString& s) {
void CUser::SetNick(const CString& s) { m_sNick = s; }
void CUser::SetAltNick(const CString& s) { m_sAltNick = s; }
void CUser::SetAwaySuffix(const CString& s) { m_sAwaySuffix = s; }
void CUser::SetIdent(const CString& s) { m_sIdent = s; }
void CUser::SetRealName(const CString& s) { m_sRealName = s; }
void CUser::SetVHost(const CString& s) { m_sVHost = s; }
@@ -980,7 +949,6 @@ const CString& CUser::GetNick(bool bAllowDefault) const { return (bAllowDefault
const CString& CUser::GetAltNick(bool bAllowDefault) const { return (bAllowDefault && m_sAltNick.empty()) ? GetCleanUserName() : m_sAltNick; }
const CString& CUser::GetIdent(bool bAllowDefault) const { return (bAllowDefault && m_sIdent.empty()) ? GetCleanUserName() : m_sIdent; }
const CString& CUser::GetRealName() const { return m_sRealName.empty() ? m_sUserName : m_sRealName; }
const CString& CUser::GetAwaySuffix() const { return m_sAwaySuffix; }
const CString& CUser::GetVHost() const { return m_sVHost; }
const CString& CUser::GetPass() const { return m_sPass; }
bool CUser::IsPassHashed() const { return m_bPassHashed; }
+6 -14
View File
@@ -22,8 +22,6 @@ class CChan;
class CServer;
class CIRCSock;
class CClient;
class CBackNickTimer;
class CAwayNickTimer;
class CKeepNickTimer;
class CJoinTimer;
class CMiscTimer;
@@ -92,15 +90,14 @@ public:
void IRCConnected(CIRCSock* pIRCSock);
void IRCDisconnected();
CString ExpandString(const CString& sStr) const;
CString& ExpandString(const CString& sStr, CString& sRet) const;
bool SendFile(const CString& sRemoteNick, const CString& sFileName, const CString& sModuleName = "");
bool GetFile(const CString& sRemoteNick, const CString& sRemoteIP, unsigned short uRemotePort, const CString& sFileName, unsigned long uFileSize, const CString& sModuleName = "");
bool ResumeFile(const CString& sRemoteNick, unsigned short uPort, unsigned long uFileSize);
CString GetCurNick();
bool Clone(const CUser& User, CString& sErrorRet);
void StartAwayNickTimer();
void StartBackNickTimer();
void DelAwayNickTimer();
void DelBackNickTimer();
void BounceAllClients();
// Setters
@@ -109,7 +106,6 @@ public:
void SetAltNick(const CString& s);
void SetIdent(const CString& s);
void SetRealName(const CString& s);
void SetAwaySuffix(const CString& s);
void SetVHost(const CString& s);
void SetPass(const CString& s, bool bHashed);
void SetBounceDCCs(bool b);
@@ -140,7 +136,6 @@ public:
const CString& GetAltNick(bool bAllowDefault = true) const;
const CString& GetIdent(bool bAllowDefault = true) const;
const CString& GetRealName() const;
const CString& GetAwaySuffix() const;
const CString& GetVHost() const;
const CString& GetPass() const;
bool IsPassHashed() const;
@@ -178,7 +173,6 @@ protected:
CString m_sCleanUserName;
CString m_sNick;
CString m_sAltNick;
CString m_sAwaySuffix;
CString m_sIdent;
CString m_sRealName;
CString m_sVHost;
@@ -196,9 +190,9 @@ protected:
CString m_sDLPath;
// !Paths
CBuffer m_RawBuffer;
CBuffer m_MotdBuffer;
CBuffer m_QueryBuffer;
CBuffer m_RawBuffer;
CBuffer m_MotdBuffer;
CBuffer m_QueryBuffer;
bool m_bIRCConnected;
bool m_bMultiClients;
bool m_bBounceDCCs;
@@ -211,8 +205,6 @@ protected:
bool m_bAutoCycle;
bool m_bBeingDeleted;
CBackNickTimer* m_pBackNickTimer;
CAwayNickTimer* m_pAwayNickTimer;
CKeepNickTimer* m_pKeepNickTimer;
CJoinTimer* m_pJoinTimer;
CMiscTimer* m_pMiscTimer;
+150
View File
@@ -0,0 +1,150 @@
//! @author prozac@rottenboy.com
// @todo handle raw 433 (nick in use)
#include "main.h"
#include "User.h"
#include "Nick.h"
#include "Modules.h"
#include "Chan.h"
#include "IRCSock.h"
class CAwayNickMod;
class CAwayNickTimer : public CTimer {
public:
CAwayNickTimer(CAwayNickMod& Module);
private:
virtual void RunJob();
private:
CAwayNickMod& m_Module;
};
class CBackNickTimer : public CTimer {
public:
CBackNickTimer(CModule& Module)
: CTimer(&Module, 3, 1, "BackNickTimer", "Set your nick back when you reattach"),
m_Module(Module) {}
private:
virtual void RunJob() {
CUser* pUser = m_Module.GetUser();
if (pUser->IsUserAttached() && pUser->IsIRCConnected()) {
CString sConfNick = pUser->GetNick();
m_Module.PutIRC("NICK " + sConfNick);
}
}
private:
CModule& m_Module;
};
class CAwayNickMod : public CModule {
public:
MODCONSTRUCTOR(CAwayNickMod) {}
virtual bool OnLoad(const CString& sArgs) {
m_sFormat = sArgs;
if (m_sFormat.empty()) {
m_sFormat = "zz_%nick%";
}
return true;
}
virtual ~CAwayNickMod() {
}
void StartAwayNickTimer() {
RemTimer("AwayNickTimer");
AddTimer(new CAwayNickTimer(*this));
}
void StartBackNickTimer() {
CIRCSock* pIRCSock = m_pUser->GetIRCSock();
if (pIRCSock) {
CString sConfNick = m_pUser->GetNick();
if (pIRCSock->GetNick().CaseCmp(GetAwayNick().Left(pIRCSock->GetNick().length())) == 0) {
RemTimer("BackNickTimer");
AddTimer(new CBackNickTimer(*this));
}
}
}
virtual void OnIRCConnected() {
if (m_pUser && !m_pUser->IsUserAttached()) {
StartAwayNickTimer();
}
}
virtual void OnIRCDisconnected() {
RemTimer("AwayNickTimer");
RemTimer("BackNickTimer");
}
virtual void OnUserAttached() {
StartBackNickTimer();
}
virtual void OnUserDetached() {
if (!m_pUser->IsUserAttached()) {
StartAwayNickTimer();
}
}
virtual void OnModCommand(const CString& sCommand) {
if (strcasecmp(sCommand.c_str(), "TIMERS") == 0) {
ListTimers();
} else if (sCommand.Token(0).CaseCmp("SET") == 0) {
CString sFormat(sCommand.Token(1));
if (!sFormat.empty()) {
m_sFormat = sFormat;
}
if (m_pUser) {
CString sExpanded = GetAwayNick();
CString sMsg = "AwayNick is set to [" + m_sFormat + "]";
if (m_sFormat != sExpanded) {
sMsg += " (" + sExpanded + ")";
}
PutModule(sMsg);
}
}
}
CString GetAwayNick() {
unsigned int uLen = 9;
CIRCSock* pIRCSock = m_pUser->GetIRCSock();
if (pIRCSock) {
pIRCSock->GetMaxNickLen();
}
return m_pUser->ExpandString(m_sFormat).Left(uLen);
}
private:
CString m_sFormat;
};
CAwayNickTimer::CAwayNickTimer(CAwayNickMod& Module)
: CTimer(&Module, 30, 1, "AwayNickTimer", "Set your nick while you're detached"),
m_Module(Module) {}
void CAwayNickTimer::RunJob() {
CUser* pUser = m_Module.GetUser();
if (!pUser->IsUserAttached() && pUser->IsIRCConnected()) {
m_Module.PutIRC("NICK " + m_Module.GetAwayNick());
}
}
MODULEDEFS(CAwayNickMod, "Change your nick while you are away")
-2
View File
@@ -782,7 +782,6 @@ bool CWebAdminSock::UserPage(CString& sPageRet, CUser* pUser) {
m_Template["Username"] = pUser->GetUserName();
m_Template["Nick"] = pUser->GetNick();
m_Template["AltNick"] = pUser->GetAltNick();
m_Template["AwaySuffix"] = pUser->GetAwaySuffix();
m_Template["StatusPrefix"] = pUser->GetStatusPrefix();
m_Template["Ident"] = pUser->GetIdent();
m_Template["RealName"] = pUser->GetRealName();
@@ -1058,7 +1057,6 @@ CUser* CWebAdminSock::GetNewUser(CString& sPageRet, CUser* pUser) {
sArg = GetParam("nick"); if (!sArg.empty()) { pNewUser->SetNick(sArg); }
sArg = GetParam("altnick"); if (!sArg.empty()) { pNewUser->SetAltNick(sArg); }
sArg = GetParam("awaysuffix"); if (!sArg.empty()) { pNewUser->SetAwaySuffix(sArg); }
sArg = GetParam("statusprefix"); if (!sArg.empty()) { pNewUser->SetStatusPrefix(sArg); }
sArg = GetParam("ident"); if (!sArg.empty()) { pNewUser->SetIdent(sArg); }
sArg = GetParam("realname"); if (!sArg.empty()) { pNewUser->SetRealName(sArg); }
@@ -51,19 +51,16 @@
<div class="inputlabel">Alt. Nickname:</div>
<div><input type="text" name="altnick" value="<? VAR AltNick ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">AwaySuffix:</div>
<div><input type="text" name="awaysuffix" value="<? VAR AwaySuffix ESC=HTML ?>" size="18" maxlength="128" /></div>
<div class="inputlabel">Ident:</div>
<div><input type="text" name="ident" value="<? VAR Ident ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div class="subsection">
<div class="inputlabel">StatusPrefix:</div>
<div><input type="text" name="statusprefix" value="<? VAR StatusPrefix ESC=HTML ?>" size="16" maxlength="5" /></div>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">Ident:</div>
<div><input type="text" name="ident" value="<? VAR Ident ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div class="subsection">
<div class="inputlabel">Realer/Voller Name:</div>
<div><input type="text" name="realname" value="<? VAR RealName ESC=HTML ?>" size="68" maxlength="256" /></div>
+3 -6
View File
@@ -51,19 +51,16 @@
<div class="inputlabel">AltNick:</div>
<div><input type="text" name="altnick" value="<? VAR AltNick ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">AwaySuffix:</div>
<div><input type="text" name="awaysuffix" value="<? VAR AwaySuffix ESC=HTML ?>" size="18" maxlength="128" /></div>
<div class="inputlabel">Ident:</div>
<div><input type="text" name="ident" value="<? VAR Ident ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div class="subsection">
<div class="inputlabel">StatusPrefix:</div>
<div><input type="text" name="statusprefix" value="<? VAR StatusPrefix ESC=HTML ?>" size="16" maxlength="5" /></div>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">Ident:</div>
<div><input type="text" name="ident" value="<? VAR Ident ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div class="subsection">
<div class="inputlabel">RealName:</div>
<div><input type="text" name="realname" value="<? VAR RealName ESC=HTML ?>" size="68" maxlength="256" /></div>
@@ -85,16 +85,6 @@
</td>
</tr>
<tr>
<td class="mainleft">
Away Suffix:
</td>
<td class="mainright">
<input style="width: 100%;" type="text" name="awaysuffix" value="<? VAR AwaySuffix ESC=HTML ?>" size="18" maxlength="128">
</td>
</tr>
<tr>
<td class="mainleft">
Status Prefix:
@@ -85,16 +85,6 @@
</td>
</tr>
<tr>
<td class="mainleft">
Away Suffix:
</td>
<td class="mainright">
<input style="width: 100%;" type="text" name="awaysuffix" value="<? VAR AwaySuffix ESC=HTML ?>" size="18" maxlength="128">
</td>
</tr>
<tr>
<td class="mainleft">
Status Prefix:
+3 -6
View File
@@ -51,19 +51,16 @@
<div class="inputlabel">Alt. Nickname:</div>
<div><input type="text" name="altnick" value="<? VAR AltNick ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">AwaySuffix:</div>
<div><input type="text" name="awaysuffix" value="<? VAR AwaySuffix ESC=HTML ?>" size="18" maxlength="128" /></div>
<div class="inputlabel">Ident:</div>
<div><input type="text" name="ident" value="<? VAR Ident ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div class="subsection">
<div class="inputlabel">StatusPrefix:</div>
<div><input type="text" name="statusprefix" value="<? VAR StatusPrefix ESC=HTML ?>" size="16" maxlength="5" /></div>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">Ident:</div>
<div><input type="text" name="ident" value="<? VAR Ident ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div class="subsection">
<div class="inputlabel">Realer/Voller Name:</div>
<div><input type="text" name="realname" value="<? VAR RealName ESC=HTML ?>" size="68" maxlength="256" /></div>
+3 -6
View File
@@ -51,19 +51,16 @@
<div class="inputlabel">AltNick:</div>
<div><input type="text" name="altnick" value="<? VAR AltNick ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">AwaySuffix:</div>
<div><input type="text" name="awaysuffix" value="<? VAR AwaySuffix ESC=HTML ?>" size="18" maxlength="128" /></div>
<div class="inputlabel">Ident:</div>
<div><input type="text" name="ident" value="<? VAR Ident ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div class="subsection">
<div class="inputlabel">StatusPrefix:</div>
<div><input type="text" name="statusprefix" value="<? VAR StatusPrefix ESC=HTML ?>" size="16" maxlength="5" /></div>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">Ident:</div>
<div><input type="text" name="ident" value="<? VAR Ident ESC=HTML ?>" size="22" maxlength="128" /></div>
</div>
<div class="subsection">
<div class="inputlabel">RealName:</div>
<div><input type="text" name="realname" value="<? VAR RealName ESC=HTML ?>" size="68" maxlength="256" /></div>
+1 -1
View File
@@ -901,7 +901,7 @@ bool CZNC::ParseConfig(const CString& sConfig) {
pUser->SetAltNick(sValue);
continue;
} else if (sName.CaseCmp("AwaySuffix") == 0) {
pUser->SetAwaySuffix(sValue);
CUtils::PrintMessage("WARNING: AwaySuffix has been depricated, instead try -> LoadModule = awaynick %nick%_" + sValue);
continue;
} else if (sName.CaseCmp("Pass") == 0) {
if (sValue.Right(1) == "-") {