Skip to content

Commit

Permalink
Save channel key on user JOIN even if user was not on the channel yet,
Browse files Browse the repository at this point in the history
which is the usual case.

Fix #1223
  • Loading branch information
DarthGandalf committed Feb 14, 2018
1 parent 986bb8d commit 5cb50ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Client.cpp
Expand Up @@ -1065,13 +1065,20 @@ bool CClient::OnJoinMessage(CJoinMessage& Message) {
CString sChannel = Message.GetTarget();
CString sKey = Message.GetKey();

CChan* pChan = m_pNetwork ? m_pNetwork->FindChan(sChannel) : nullptr;
if (pChan) {
if (pChan->IsDetached())
pChan->AttachUser(this);
else
pChan->JoinUser(sKey);
continue;
if (m_pNetwork) {
CChan* pChan = m_pNetwork->FindChan(sChannel);
if (pChan) {
if (pChan->IsDetached())
pChan->AttachUser(this);
else
pChan->JoinUser(sKey);
continue;
} else if (!sChannel.empty()) {
pChan = new CChan(sChannel, m_pNetwork, false);
if (m_pNetwork->AddChan(pChan)) {
pChan->SetKey(sKey);
}
}
}

if (!sChannel.empty()) {
Expand Down
20 changes: 20 additions & 0 deletions test/integration/tests/core.cpp
Expand Up @@ -262,5 +262,25 @@ TEST_F(ZNCTest, AwayNotify) {
client.ReadUntil("DEL :away-notify");
}

TEST_F(ZNCTest, JoinKey) {
QFile conf(m_dir.path() + "/configs/znc.conf");
ASSERT_TRUE(conf.open(QIODevice::Append | QIODevice::Text));
QTextStream(&conf) << "ServerThrottle = 1\n";
auto znc = Run();

auto ircd = ConnectIRCd();
auto client = LoginClient();
ircd.Write(":server 001 nick :Hello");
client.Write("JOIN #znc secret");
ircd.ReadUntil("JOIN #znc secret");
ircd.Write(":nick JOIN :#znc");
client.ReadUntil("JOIN :#znc");
ircd.Close();

ircd = ConnectIRCd();
ircd.Write(":server 001 nick :Hello");
ircd.ReadUntil("JOIN #znc secret");
}

} // namespace
} // namespace znc_inttest

0 comments on commit 5cb50ec

Please sign in to comment.