Added ability to retain topics

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@113 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-04-05 18:48:57 +00:00
parent 66389db912
commit fa4dd02671
6 changed files with 75 additions and 1 deletions

View File

@@ -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;
}

6
Chan.h
View File

@@ -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<string>& GetBans() const { return m_vsBans; }
const vector<string>& 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;

View File

@@ -2,6 +2,7 @@
#include "IRCSock.h"
#include "DCCBounce.h"
#include "UserSock.h"
#include <time.h>
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<CChan*>& 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

View File

@@ -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<CChan*>& CUser::GetChans() const { return m_vChans; }
const CNick& CUser::GetIRCNick() const { return m_IRCNick; }
const string& CUser::GetIRCServer() const { return m_sIRCServer; }
// !Getters

3
User.h
View File

@@ -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<CChan*>& 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;

View File

@@ -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()) {