Added support for AwayPrefix

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@315 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-05-16 05:07:26 +00:00
parent 21af04df7d
commit 94b37a2fd9
7 changed files with 69 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
#include "IRCSock.h"
#include "DCCBounce.h"
#include "UserSock.h"
#include "Timers.h"
#include <time.h>
CIRCSock::CIRCSock(CZNC* pZNC, CUser* pUser) : Csock() {
@@ -86,6 +87,7 @@ void CIRCSock::ReadLine(const CString& sData) {
case 1: {// :irc.server.com 001 nick :Welcome to the Internet Relay Network nick
SetTimeout(900); // Now that we are connected, let nature take its course
PutServ("WHO " + sNick);
m_pZNC->GetManager().AddCron(new CAwayNickTimer(m_pUser));
#ifdef _MODULES
m_pUser->GetModules().OnIRCConnected();
#endif
@@ -156,7 +158,7 @@ void CIRCSock::ReadLine(const CString& sData) {
CString sBadNick = sRest.Token(0);
CString sConfNick = m_pUser->GetNick().Left(uMax);
if (sNick == "*") {
if (sNick == "*" || sNick.CaseCmp(CNick::Concat(sConfNick, m_pUser->GetAwaySuffix(), GetMaxNickLen())) == 0) {
CString sAltNick = m_pUser->GetAltNick();
if (sBadNick.CaseCmp(sConfNick) == 0) {
@@ -194,7 +196,7 @@ void CIRCSock::ReadLine(const CString& sData) {
return;
} else {
// :irc.server.net 433 mynick badnick :Nickname is already in use.
if ((m_bKeepNick) && (m_pUser->KeepNick())) {
if ((m_bKeepNick) && (m_pUser->GetKeepNick())) {
if (sBadNick.CaseCmp(sConfNick) == 0) {
if ((!m_pUserSock) || (!m_pUserSock->DecKeepNickCounter())) {
return;
@@ -378,10 +380,6 @@ void CIRCSock::ReadLine(const CString& sData) {
if (sNick.CaseCmp(GetNick()) == 0) {
SetNick(sNewNick);
if (sNick.CaseCmp(m_pUser->GetNick()) == 0) {
// If the user changes his nick away from the config nick, we shut off keepnick for this session
m_bKeepNick = false;
}
} else if (sNick.CaseCmp(m_pUser->GetNick()) == 0) {
KeepNick();
}
@@ -609,8 +607,9 @@ void CIRCSock::ReadLine(const CString& sData) {
void CIRCSock::KeepNick() {
const CString& sConfNick = m_pUser->GetNick();
CString sAwayNick = CNick::Concat(sConfNick, m_pUser->GetAwaySuffix(), GetMaxNickLen());
if ((m_bAuthed) && (m_bKeepNick) && (m_pUser->KeepNick()) && (GetNick().CaseCmp(sConfNick) != 0)) {
if ((m_bAuthed) && (m_bKeepNick) && (m_pUser->GetKeepNick()) && (GetNick().CaseCmp(sConfNick) != 0) && (GetNick().CaseCmp(sAwayNick) != 0)) {
PutServ("NICK " + sConfNick);
}
}
@@ -769,6 +768,11 @@ void CIRCSock::UserConnected(CUserSock* pUserSock) {
}
m_pUserSock = pUserSock;
CString sConfNick = m_pUser->GetNick();
if (GetNick().CaseCmp(CNick::Concat(sConfNick, m_pUser->GetAwaySuffix(), GetMaxNickLen())) == 0) {
PutServ("NICK " + sConfNick);
}
if (m_RawBuffer.IsEmpty()) {
PutUser(":irc.znc.com 001 " + m_pUserSock->GetNick() + " :- Welcome to ZNC -");
@@ -807,6 +811,10 @@ void CIRCSock::UserConnected(CUserSock* pUserSock) {
}
void CIRCSock::UserDisconnected() {
if (m_pUserSock) {
m_pZNC->GetManager().AddCron(new CAwayNickTimer(m_pUser));
}
m_pUserSock = NULL;
}

View File

@@ -51,9 +51,11 @@ public:
// Setters
void SetPass(const CString& s) { m_sPass = s; }
void SetKeepNick(bool b) { m_bKeepNick = b; }
// !Setters
// Getters
bool GetKeepNick() const { return m_bKeepNick; }
unsigned int GetMaxNickLen() const { return m_uMaxNickLen; }
EChanModeArgs GetModeType(unsigned char uMode) const;
unsigned char GetPermFromMode(unsigned char uMode) const;

View File

@@ -47,3 +47,32 @@ protected:
CUser* m_pUser;
};
class CAwayNickTimer : public CCron {
public:
CAwayNickTimer(CUser* pUser) : CCron() {
m_pUser = pUser;
Start(10);
}
virtual ~CAwayNickTimer() {}
private:
protected:
virtual void RunJob() {
if (!m_pUser->IsUserAttached()) {
CIRCSock* pSock = m_pUser->GetIRCSock();
if (pSock) {
const CString& sSuffix = m_pUser->GetAwaySuffix();
if (!sSuffix.empty()) {
CString sNewNick = CNick::Concat(m_pUser->GetNick(), sSuffix, pSock->GetMaxNickLen());
pSock->PutServ("NICK " + sNewNick);
}
}
}
m_pUser->GetZNC()->GetManager().DelCronByAddr(this);
}
CUser* m_pUser;
};

View File

@@ -437,6 +437,7 @@ CString CUser::GetCurNick() {
// Setters
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; }
@@ -466,6 +467,7 @@ bool CUser::SetStatusPrefix(const CString& s) {
const CString& CUser::GetUserName() const { return m_sUserName; }
const CString& CUser::GetNick() const { return m_sNick; }
const CString& CUser::GetAltNick() const { return m_sAltNick; }
const CString& CUser::GetAwaySuffix() const { return m_sAwaySuffix; }
const CString& CUser::GetIdent() const { return m_sIdent; }
const CString& CUser::GetRealName() const { return m_sRealName; }
const CString& CUser::GetVHost() const { return m_sVHost; }
@@ -479,7 +481,7 @@ const CString& CUser::GetDataPath() const { return m_pZNC->GetDataPath(); }
CString CUser::GetPemLocation() const { return m_pZNC->GetPemLocation(); }
bool CUser::UseClientIP() const { return m_bUseClientIP; }
bool CUser::KeepNick() const { return m_bKeepNick; }
bool CUser::GetKeepNick() const { return m_bKeepNick; }
bool CUser::DenyLoadMod() const { return m_bDenyLoadMod; }
const CString& CUser::GetStatusPrefix() const { return m_sStatusPrefix; }
const CString& CUser::GetDefaultChanModes() const { return m_sDefaultChanModes; }

5
User.h
View File

@@ -63,6 +63,7 @@ public:
// Setters
void SetNick(const CString& s);
void SetAltNick(const CString& s);
void SetAwaySuffix(const CString& s);
void SetIdent(const CString& s);
void SetRealName(const CString& s);
void SetVHost(const CString& s);
@@ -88,6 +89,7 @@ public:
const CString& GetUserName() const;
const CString& GetNick() const;
const CString& GetAltNick() const;
const CString& GetAwaySuffix() const;
const CString& GetIdent() const;
const CString& GetRealName() const;
const CString& GetVHost() const;
@@ -101,7 +103,7 @@ public:
CString GetPemLocation() const;
bool UseClientIP() const;
bool KeepNick() const;
bool GetKeepNick() const;
bool DenyLoadMod() const;
const CString& GetStatusPrefix() const;
const CString& GetDefaultChanModes() const;
@@ -121,6 +123,7 @@ protected:
CString m_sUserName;
CString m_sNick;
CString m_sAltNick;
CString m_sAwaySuffix;
CString m_sIdent;
CString m_sRealName;
CString m_sVHost;

View File

@@ -84,6 +84,19 @@ void CUserSock::ReadLine(const CString& sData) {
if ((m_pUser) && (sNick.CaseCmp(m_pUser->GetNick()) == 0)) {
m_uKeepNickCounter++;
// If the user is changing his nick to the conifg nick, set keepnick to the config value
if (m_pUser->GetKeepNick() && !m_pIRCSock->GetKeepNick()) {
m_pIRCSock->SetKeepNick(true);
PutStatusNotice("Reset KeepNick back to true");
}
}
if (m_pUser && GetNick().CaseCmp(m_pUser->GetNick()) == 0) {
// If the user changes his nick away from the config nick, we shut off keepnick for this session
if (m_pUser->GetKeepNick()) {
m_pIRCSock->SetKeepNick(false);
PutStatusNotice("Set KeepNick to false");
}
}
} else if (sCommand.CaseCmp("USER") == 0) {
if ((!m_bAuthed) && (m_sUser.empty())) {

View File

@@ -600,6 +600,9 @@ bool CZNC::ParseConfig(const CString& sConfig) {
} else if (sName.CaseCmp("AltNick") == 0) {
pUser->SetAltNick(sValue);
continue;
} else if (sName.CaseCmp("AwaySuffix") == 0) {
pUser->SetAwaySuffix(sValue);
continue;
} else if (sName.CaseCmp("Pass") == 0) {
if (sValue.Right(1) == "-") {
sValue.RightChomp();