Fix newest additions to keepnick module and write the test for it.

Fix the documentation.

See #1324 and #1325
This commit is contained in:
Alexey Sokolov
2016-10-04 01:20:47 +01:00
parent ac0048cc01
commit 222ae86fcc
3 changed files with 58 additions and 27 deletions
+15 -18
View File
@@ -41,27 +41,24 @@ class CIRCNetwork;
/**
* Here is a small explanation of how messages on IRC work, and how you can use
* this class to get useful information from the parsed message. The output varies
* greatly and this advice may not apply to every message type, but this will hopefully
* help you understand how it works more accurately.
* this class to get useful information from the parsed message. The output
* varies greatly and this advice may not apply to every message type, but this
* will hopefully help you understand how it works more accurately.
*
* @time=some-timestamp :server.network.net 366 something #channel :End of /NAMES list.
* tags nick 0 1 2 3
* @t=some-tag :server.network.net 366 something #channel :End of /NAMES list.
* tags nick cmd 0 1 2
*
* `tags` is the IRCv3 tags associated with the message, obtained with GetTag(s).
* the @time tag can also be obtained with GetTime(), some messages have other tags
* with them. Tags may not always be present. Refer to IRCv3 for documentation on tags.
* `nick` is the sender, which can be obtained with GetNick()
* `0` is the command, which is obtained via GetCommand, or with GetParam(0)
* `1` is the first parameter index, which usually includes a sender or a recipient.
* `2` is the target or element the message is about.
* `3` is likely to contain the message, but this may very per message type.
* - `tags` is the IRCv3 tags associated with the message, obtained with
* GetTag("t"). the @time tag can also be obtained with GetTime(), some
* messages have other tags with them. Tags may not always be present. Refer
* to IRCv3 for documentation on tags.
* - `nick` is the sender, which can be obtained with GetNick()
* - `cmd` is command, which is obtained via GetCommand()
* - `0`, `1`, ... are parameters, available via GetParam(n), which removes the
* leading colon (:). If you don't want to remove the colon, use GetParams().
*
* When using GetParam (which corresponds to the numbers given above), ZNC will remove the leading colon (:),
* this is not true for GetParams.
*
* For certain events, like a PRIVMSG, convienience commands like GetChan() and GetNick() are available,
* this is not true for all CMessage extensions.
* For certain events, like a PRIVMSG, convienience commands like GetChan() and
* GetNick() are available, this is not true for all CMessage extensions.
*/
class CMessage {
public:
+18 -9
View File
@@ -163,19 +163,28 @@ class CKeepNickMod : public CModule {
return CONTINUE;
}
EModRet OnNumericMessage(CNumericMessage& numeric) override {
if (m_pTimer &&
(numeric.GetCode() == 433 || /* bad nick */
numeric.GetCode() == 435 || /* user is banned on channel (charybdis) */
numeric.GetCode() == 447)) { /* channel is +N (unrealircd) */
EModRet OnNumericMessage(CNumericMessage& msg) override {
if (m_pTimer) {
// Are we trying to get our primary nick and we caused this error?
// :irc.server.net 433 mynick badnick :Nickname is already in use.
if (numeric.GetCode() == 433 && numeric.GetParam(1).Equals(GetNick())) {
if (msg.GetCode() == 433 && msg.GetParam(1).Equals(GetNick())) {
return HALT;
}
PutModule("Unable to obtain nick: " + numeric.GetParam(2) + ": " + numeric.GetParam(3));
Disable();
// clang-format off
// :leguin.freenode.net 435 mynick badnick #chan :Cannot change nickname while banned on channel
// clang-format on
if (msg.GetCode() == 435) {
PutModule("Unable to obtain nick " + msg.GetParam(1) + ": " +
msg.GetParam(3) + ", " + msg.GetParam(2));
Disable();
}
// clang-format off
// :irc1.unrealircd.org 447 mynick :Can not change nickname while on #chan (+N)
// clang-format on
if (msg.GetCode() == 447) {
PutModule("Unable to obtain nick: " + msg.GetParam(1));
Disable();
}
}
return CONTINUE;
+25
View File
@@ -1940,4 +1940,29 @@ TEST_F(ZNCTest, AutoAttachModule) {
Z;
}
TEST_F(ZNCTest, KeepNickModule) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.Write("znc loadmod keepnick");
client.ReadUntil("Loaded module");
Z;
ircd.ReadUntil("NICK user");
ircd.Write(":server 433 * nick :Nickname is already in use.");
ircd.ReadUntil("NICK user_");
Z;
ircd.Write(":server 001 user_ :Hello");
client.ReadUntil("Connected!");
Z;
ircd.ReadUntil("NICK user");
Z;
ircd.Write(":server 435 user_ user #error :Nope :-P");
client.ReadUntil(
":*keepnick!znc@znc.in PRIVMSG user_ "
":Unable to obtain nick user: Nope :-P, #error");
}
} // namespace