Skip to content

Commit

Permalink
The test is now working
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthGandalf committed Jan 7, 2024
1 parent 7ee3892 commit b5a6ff5
Showing 4 changed files with 40 additions and 6 deletions.
6 changes: 6 additions & 0 deletions include/znc/Modules.h
Original file line number Diff line number Diff line change
@@ -1292,6 +1292,10 @@ class CModule {
virtual EModRet OnUnknownUserRaw(CClient* pClient, CString& sLine);
virtual EModRet OnUnknownUserRawMessage(CMessage& Message);

/** Called after login, upon disconnect, and also during JumpNetwork. */
virtual void OnClientAttached();
virtual void OnClientDetached();

/** Called when a client told us CAP LS. Use ssCaps.insert("cap-name")
* for announcing capabilities which your module supports.
* @param pClient The client which requested the list.
@@ -1550,6 +1554,8 @@ class CModules : public std::vector<CModule*>, private CCoreTranslationMixin {
bool OnSendToClientMessage(CMessage& Message);
bool OnSendToIRC(CString& sLine);
bool OnSendToIRCMessage(CMessage& Message);
bool OnClientAttached();
bool OnClientDetached();

bool OnServerCapAvailable(const CString& sCap, const CString& sValue);
bool OnServerCapResult(const CString& sCap, bool bSuccess);
2 changes: 2 additions & 0 deletions src/Client.cpp
Original file line number Diff line number Diff line change
@@ -271,6 +271,7 @@ void CClient::SetNetwork(CIRCNetwork* pNetwork, bool bDisconnect,
m_pNetwork->ClientDisconnected(this);

if (bDisconnect) {
NETWORKMODULECALL(OnClientDetached(), m_pUser, m_pNetwork, this, NOTHING);
ClearServerDependentCaps();
// Tell the client they are no longer in these channels.
const vector<CChan*>& vChans = m_pNetwork->GetChans();
@@ -293,6 +294,7 @@ void CClient::SetNetwork(CIRCNetwork* pNetwork, bool bDisconnect,
} else if (m_pUser) {
m_pUser->UserConnected(this);
}
NETWORKMODULECALL(OnClientAttached(), m_pUser, m_pNetwork, this, NOTHING);
}
}

10 changes: 10 additions & 0 deletions src/Modules.cpp
Original file line number Diff line number Diff line change
@@ -997,6 +997,8 @@ CModule::EModRet CModule::OnSendToIRC(CString& sLine) { return CONTINUE; }
CModule::EModRet CModule::OnSendToIRCMessage(CMessage& Message) {
return CONTINUE;
}
void CModule::OnClientAttached() {}
void CModule::OnClientDetached() {}

bool CModule::OnServerCapAvailable(const CString& sCap) { return false; }
bool CModule::OnServerCap302Available(const CString& sCap, const CString& sValue) {
@@ -1492,6 +1494,14 @@ bool CModules::OnModCTCP(const CString& sMessage) {
MODUNLOADCHK(OnModCTCP(sMessage));
return false;
}
bool CModules::OnClientAttached() {
MODUNLOADCHK(OnClientAttached());
return false;
}
bool CModules::OnClientDetached() {
MODUNLOADCHK(OnClientDetached());
return false;
}

// Why MODHALTCHK works only with functions returning EModRet ? :(
bool CModules::OnServerCapAvailable(const CString& sCap, const CString& sValue) {
28 changes: 22 additions & 6 deletions test/integration/tests/core.cpp
Original file line number Diff line number Diff line change
@@ -585,13 +585,17 @@ TEST_F(ZNCTest, ServerDependentCapInModule) {
}
void OnServerCapResult(const CString& sCap, bool bSuccess) override {
if (sCap == "testcap") {
GetNetwork()->NotifyClientsAboutServerDependentCap("testcap", bSuccess, [=](CClient* pClient, bool bState) {
PutModule("OnServerCapResult " + sCap + " " + CString(bSuccess) + " " + CString(bState));
});
PutModule("OnServerCapResult " + sCap + " " + CString(bSuccess));
if (GetNetwork()->GetIRCSock()->IsAuthed()) {
GetNetwork()->NotifyClientsAboutServerDependentCap("testcap", bSuccess, [=](CClient* pClient, bool bState) {
PutModule("OnServerCapResult " + sCap + " " + CString(bSuccess) + " " + CString(bState));
});
}
}
}
void OnIRCConnected() override {
if (GetNetwork()->IsServerCapAccepted("testcap")) {
PutModule("OnIRCConnected");
GetNetwork()->NotifyClientsAboutServerDependentCap("testcap", true, [=](CClient* pClient, bool bState) {
PutModule("OnIRCConnected " + CString(bState));
});
@@ -602,6 +606,14 @@ TEST_F(ZNCTest, ServerDependentCapInModule) {
PutModule("OnIRCDisconnected " + CString(bState));
});
}
void OnClientAttached() override {
if (GetNetwork()->IsServerCapAccepted("testcap")) {
GetClient()->NotifyServerDependentCap("testcap", true, GetNetwork()->GetIRCSock()->GetCapLsValue("testcap"), nullptr);
}
}
void OnClientDetached() override {
GetClient()->NotifyServerDependentCap("testcap", false, "", [](CClient*, bool) {});
}
~TestModule() override {
// TODO user module
GetNetwork()->NotifyClientsAboutServerDependentCap("testcap", false, [=](CClient* pClient, bool bState) {
@@ -646,18 +658,22 @@ TEST_F(ZNCTest, ServerDependentCapInModule) {
ircd.ReadUntil("CAP REQ :testcap");
ircd.Write("CAP nick ACK :testcap");
ircd.ReadUntil("CAP END");
// TODO should NEW wait until 001?
// NEW waits until 001
ASSERT_THAT(ircd.ReadRemainder().toStdString(), Not(HasSubstr("testcap")));
ircd.Write("001 nick Welcome");
// TODO combine multiple NEWs to single line
client.ReadUntil("CAP nick NEW :testcap=new");
ircd.Write("001 nick Welcome");
client.ReadUntil("Welcome");

// NEW with new value without DEL
ircd.Write("CAP nick NEW testcap=another");
client.ReadUntil("CAP nick NEW :testcap=another");

client.Write("znc jumpnetwork net2");
client.ReadUntil("AAAAA");
client.ReadUntil("CAP nick DEL :testcap");

client.Write("znc jumpnetwork test");
client.ReadUntil("CAP nick NEW :testcap=another");
}

TEST_F(ZNCTest, HashUpgrade) {

0 comments on commit b5a6ff5

Please sign in to comment.