From fa4dd02671053c82ea69d5ef6e212ec008ab4e8f Mon Sep 17 00:00:00 2001 From: prozacx Date: Tue, 5 Apr 2005 18:48:57 +0000 Subject: [PATCH] Added ability to retain topics git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@113 726aef4b-f618-498e-8847-2d620e286838 --- Chan.cpp | 8 +++++++- Chan.h | 6 ++++++ IRCSock.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ User.cpp | 2 ++ User.h | 3 +++ UserSock.cpp | 2 ++ 6 files changed, 75 insertions(+), 1 deletion(-) diff --git a/Chan.cpp b/Chan.cpp index e65f05a4..54f2eb43 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -32,8 +32,14 @@ void CChan::JoinUser() { } m_pUser->PutUser(":" + m_pUser->GetIRCNick().GetNickMask() + " JOIN :" + GetName()); + + if (!GetTopic().empty()) { + m_pUser->PutUser(":" + m_pUser->GetIRCServer() + " 332 " + m_pUser->GetIRCNick().GetNick() + " " + GetName() + " :" + GetTopic()); + m_pUser->PutUser(":" + m_pUser->GetIRCServer() + " 333 " + m_pUser->GetIRCNick().GetNick() + " " + GetName() + " " + GetTopicOwner() + " " + CUtils::ToString(GetTopicDate())); + } + m_pUser->PutIRC("NAMES " + GetName()); - m_pUser->PutIRC("TOPIC " + GetName()); + //m_pUser->PutIRC("TOPIC " + GetName()); m_bDetached = false; } diff --git a/Chan.h b/Chan.h index e79e122c..c7f12793 100644 --- a/Chan.h +++ b/Chan.h @@ -77,6 +77,8 @@ public: void SetVoiced(bool b) { m_bIsVoice = b; } void SetKey(const string& s) { m_sKey = s; } void SetTopic(const string& s) { m_sTopic = s; } + void SetTopicOwner(const string& s) { m_sTopicOwner = s; } + void SetTopicDate(unsigned long u) { m_ulTopicDate = u; } void SetDefaultModes(const string& s) { m_sDefaultModes = s; } void IncOpCount() { m_uOpCount++; } void DecOpCount() { m_uOpCount -= (m_uOpCount > 0); } @@ -98,6 +100,8 @@ public: const string& GetKey() const { return m_sKey; } unsigned int GetLimit() const { return m_uLimit; } const string& GetTopic() const { return m_sTopic; } + const string& GetTopicOwner() const { return m_sTopicOwner; } + unsigned int GetTopicDate() const { return m_ulTopicDate; } const string& GetDefaultModes() const { return m_sDefaultModes; } const vector& GetBans() const { return m_vsBans; } const vector& GetBuffer() const { return m_vsBuffer; } @@ -123,6 +127,8 @@ protected: string m_sName; string m_sKey; string m_sTopic; + string m_sTopicOwner; + unsigned long m_ulTopicDate; CUser* m_pUser; unsigned int m_uLimit; unsigned int m_uModes; diff --git a/IRCSock.cpp b/IRCSock.cpp index 1a88d81f..4f4791fd 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -2,6 +2,7 @@ #include "IRCSock.h" #include "DCCBounce.h" #include "UserSock.h" +#include CIRCSock::CIRCSock(CZNC* pZNC, CUser* pUser) : Csock() { m_pZNC = pZNC; @@ -189,19 +190,61 @@ void CIRCSock::ReadLine(const string& sData) { if (pChan) { pChan->SetWhoDone(); } + + break; + } + case 331: { + // :irc.server.com 331 yournick #chan :No topic is set. + CChan* pChan = m_pUser->FindChan(CUtils::Token(sLine, 3)); + + if (pChan) { + pChan->SetTopic(""); + } + + break; + } + case 332: { + // :irc.server.com 332 yournick #chan :This is a topic + CChan* pChan = m_pUser->FindChan(CUtils::Token(sLine, 3)); + + if (pChan) { + string sTopic = CUtils::Token(sLine, 4, true); + CUtils::LeftChomp(sTopic); + pChan->SetTopic(sTopic); + } + + break; + } + case 333: { + // :irc.server.com 333 yournick #chan setternick 1112320796 + CChan* pChan = m_pUser->FindChan(CUtils::Token(sLine, 3)); + + if (pChan) { + string sNick = CUtils::Token(sLine, 4); + unsigned long ulDate = strtoul(CUtils::Token(sLine, 5).c_str(), NULL, 10); + + pChan->SetTopicOwner(sNick); + pChan->SetTopicDate(ulDate); + } + + break; } case 352: { // :irc.yourserver.com 352 yournick #chan ident theirhost.com irc.theirserver.com theirnick H :0 Real Name + string sServer = CUtils::Token(sLine, 0); string sNick = CUtils::Token(sLine, 7); string sIdent = CUtils::Token(sLine, 4); string sHost = CUtils::Token(sLine, 5); + CUtils::LeftChomp(sServer); + if (strcasecmp(sNick.c_str(), GetNick().c_str()) == 0) { m_Nick.SetIdent(sIdent); m_Nick.SetHost(sHost); } m_pUser->SetIRCNick(m_Nick); + m_pUser->SetIRCServer(sServer); const vector& vChans = m_pUser->GetChans(); @@ -467,6 +510,18 @@ void CIRCSock::ReadLine(const string& sData) { PutUser(":" + sNickMask + " NOTICE " + sTarget + " :" + sMsg); return; + } else if (strcasecmp(sCmd.c_str(), "TOPIC") == 0) { + // :nick!ident@host.com TOPIC #chan :This is a topic + CChan* pChan = m_pUser->FindChan(CUtils::Token(sLine, 2)); + + if (pChan) { + CNick Nick(sNickMask); + string sTopic = CUtils::Token(sLine, 3, true); + CUtils::LeftChomp(sTopic); + pChan->SetTopicOwner(Nick.GetNick()); + pChan->SetTopicDate((unsigned long) time(NULL)); // @todo use local time + pChan->SetTopic(sTopic); + } } else if (strcasecmp(sCmd.c_str(), "PRIVMSG") == 0) { // :nick!ident@host.com PRIVMSG #chan :Message diff --git a/User.cpp b/User.cpp index 307ce243..0e813b1d 100644 --- a/User.cpp +++ b/User.cpp @@ -364,6 +364,7 @@ void CUser::SetKeepNick(bool b) { m_bKeepNick = b; } void CUser::SetDenyLoadMod(bool b) { m_bDenyLoadMod = b; } void CUser::SetDefaultChanModes(const string& s) { m_sDefaultChanModes = s; } void CUser::SetIRCNick(const CNick& n) { m_IRCNick = n; } +void CUser::SetIRCServer(const string& s) { m_sIRCServer = s; } bool CUser::SetStatusPrefix(const string& s) { if ((!s.empty()) && (s.length() < 6) && (s.find(' ') == string::npos)) { @@ -397,4 +398,5 @@ const string& CUser::GetStatusPrefix() const { return m_sStatusPrefix; } const string& CUser::GetDefaultChanModes() const { return m_sDefaultChanModes; } const vector& CUser::GetChans() const { return m_vChans; } const CNick& CUser::GetIRCNick() const { return m_IRCNick; } +const string& CUser::GetIRCServer() const { return m_sIRCServer; } // !Getters diff --git a/User.h b/User.h index 43e83591..ae2f32a7 100644 --- a/User.h +++ b/User.h @@ -68,6 +68,7 @@ public: bool SetStatusPrefix(const string& s); void SetDefaultChanModes(const string& s); void SetIRCNick(const CNick& n); + void SetIRCServer(const string& s); // !Setters // Getters @@ -96,6 +97,7 @@ public: const string& GetDefaultChanModes() const; const vector& GetChans() const; const CNick& GetIRCNick() const; + const string& GetIRCServer() const; // !Getters private: protected: @@ -111,6 +113,7 @@ protected: string m_sStatusPrefix; string m_sDefaultChanModes; CNick m_IRCNick; + string m_sIRCServer; bool m_bPassHashed; bool m_bUseClientIP; diff --git a/UserSock.cpp b/UserSock.cpp index 0c0e938c..b1472f1a 100644 --- a/UserSock.cpp +++ b/UserSock.cpp @@ -469,6 +469,7 @@ void CUserSock::UserCommand(const string& sLine) { Table.AddColumn("Users"); Table.AddColumn("+o"); Table.AddColumn("+v"); + Table.AddColumn("Topic"); for (unsigned int a = 0; a < vChans.size(); a++) { CChan* pChan = vChans[a]; @@ -488,6 +489,7 @@ void CUserSock::UserCommand(const string& sLine) { Table.SetCell("Users", CUtils::ToString(pChan->GetNickCount())); Table.SetCell("+o", CUtils::ToString(pChan->GetOpCount())); Table.SetCell("+v", CUtils::ToString(pChan->GetVoiceCount())); + Table.SetCell("Topic", pChan->GetTopic()); } if (Table.size()) {