Skip to content

Commit

Permalink
Moved awaynick functionality into modules/awaynick.cpp module
Browse files Browse the repository at this point in the history
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@775 726aef4b-f618-498e-8847-2d620e286838
  • Loading branch information
prozacx committed Sep 17, 2006
1 parent dd83d06 commit 70aafde
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 176 deletions.
6 changes: 2 additions & 4 deletions IRCSock.cpp
Expand Up @@ -91,7 +91,6 @@ void CIRCSock::ReadLine(const CString& sData) {
PutIRC("WHO " + sNick);

SetNick(sNick);
m_pUser->StartAwayNickTimer();

MODULECALL(OnIRCConnected(), m_pUser, NULL, );

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
62 changes: 0 additions & 62 deletions Timers.h
Expand Up @@ -82,66 +82,4 @@ class CJoinTimer : public CCron {
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
66 changes: 17 additions & 49 deletions User.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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 -");
Expand Down Expand Up @@ -163,45 +175,13 @@ 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) {
m_vClients.erase(m_vClients.begin() + a);
break;
}
}

if (!IsUserAttached()) {
StartAwayNickTimer();
}
}

bool CUser::Clone(const CUser& User, CString& sErrorRet) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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; }
Expand Down
20 changes: 6 additions & 14 deletions User.h
Expand Up @@ -22,8 +22,6 @@ class CChan;
class CServer;
class CIRCSock;
class CClient;
class CBackNickTimer;
class CAwayNickTimer;
class CKeepNickTimer;
class CJoinTimer;
class CMiscTimer;
Expand Down Expand Up @@ -92,15 +90,14 @@ class CUser {
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
Expand All @@ -109,7 +106,6 @@ class CUser {
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);
Expand Down Expand Up @@ -140,7 +136,6 @@ class CUser {
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;
Expand Down Expand Up @@ -178,7 +173,6 @@ class CUser {
CString m_sCleanUserName;
CString m_sNick;
CString m_sAltNick;
CString m_sAwaySuffix;
CString m_sIdent;
CString m_sRealName;
CString m_sVHost;
Expand All @@ -196,9 +190,9 @@ class CUser {
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;
Expand All @@ -211,8 +205,6 @@ class CUser {
bool m_bAutoCycle;
bool m_bBeingDeleted;

CBackNickTimer* m_pBackNickTimer;
CAwayNickTimer* m_pAwayNickTimer;
CKeepNickTimer* m_pKeepNickTimer;
CJoinTimer* m_pJoinTimer;
CMiscTimer* m_pMiscTimer;
Expand Down

0 comments on commit 70aafde

Please sign in to comment.