Beispiel #1
0
 void HandleMessage(CNick& Nick, const CString& sMessage) {
     CString sNickServName = (!GetNV("NickServName").empty())
                                 ? GetNV("NickServName")
                                 : "NickServ";
     if (!GetNV("Password").empty() && Nick.NickEquals(sNickServName) &&
         (sMessage.find("msg") != CString::npos ||
          sMessage.find("authenticate") != CString::npos ||
          sMessage.find("choose a different nickname") != CString::npos ||
          sMessage.find("please choose a different nick") != CString::npos ||
          sMessage.find("If this is your nick, identify yourself with") !=
              CString::npos ||
          sMessage.find("If this is your nick, type") != CString::npos ||
          sMessage.find("This is a registered nickname, please identify") !=
              CString::npos ||
          sMessage.StripControls_n().find(
              "type /NickServ IDENTIFY password") != CString::npos ||
          sMessage.StripControls_n().find(
              "type /msg NickServ IDENTIFY password") != CString::npos) &&
         sMessage.AsUpper().find("IDENTIFY") != CString::npos &&
         sMessage.find("help") == CString::npos) {
         MCString msValues;
         msValues["password"] = GetNV("Password");
         PutIRC(CString::NamedFormat(GetNV("IdentifyCmd"), msValues));
     } else if(Nick.NickEquals(sNickServName) && m_bJoinAfterIdentified &&
              (sMessage.find("Password accepted") != CString::npos ||
               sMessage.find("now recognized") != CString::npos ||
               sMessage.find("now identified") != CString::npos ||
               sMessage.find("now logged in as") != CString::npos)) {
         m_bIdentified = true;
         GetNetwork()->JoinChans();
     }
 }
Beispiel #2
0
 void OnQuit(const CNick& Nick, const CString& sMessage,
             const vector<CChan*>& vChans) override {
     // If someone with the nick we want quits, be fast and get the nick
     if (Nick.NickEquals(GetNick())) {
         KeepNick();
     }
 }
Beispiel #3
0
Datei: q.cpp Projekt: Adam-/znc
 EModRet OnInvite(const CNick& Nick, const CString& sChan) override {
     if (!Nick.NickEquals("Q") ||
         !Nick.GetHost().Equals("CServe.quakenet.org"))
         return CONTINUE;
     if (m_bJoinOnInvite) GetNetwork()->AddChan(sChan, false);
     return CONTINUE;
 }
Beispiel #4
0
	void OnOp2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange) override {
		if (Nick.NickEquals(GetNetwork()->GetNick())) {
			const map<CString,CNick>& msNicks = Channel.GetNicks();

			for (const auto& it : msNicks) {
				if (!it.second.HasPerm(CChan::Voice)) {
					CheckAutoVoice(it.second, Channel);
				}
			}
		}
	}
Beispiel #5
0
    void OnNick(const CNick& Nick, const CString& sNewNick,
                const vector<CChan*>& vChans) override {
        if (sNewNick == GetNetwork()->GetIRCSock()->GetNick()) {
            // We are changing our own nick
            if (Nick.NickEquals(GetNick())) {
                // We are changing our nick away from the conf setting.
                // Let's assume the user wants this and disable
                // this module (to avoid fighting nickserv).
                Disable();
            } else if (sNewNick.Equals(GetNick())) {
                // We are changing our nick to the conf setting,
                // so we don't need that timer anymore.
                Disable();
            }
            return;
        }

        // If the nick we want is free now, be fast and get the nick
        if (Nick.NickEquals(GetNick())) {
            KeepNick();
        }
    }
Beispiel #6
0
bool CChan::AddNick(const CString& sNick) {
	const char* p = sNick.c_str();
	CString sPrefix, sTmp, sIdent, sHost;

	while (m_pNetwork->GetIRCSock()->IsPermChar(*p)) {
		sPrefix += *p;

		if (!*++p) {
			return false;
		}
	}

	sTmp = p;

	// The UHNames extension gets us nick!ident@host instead of just plain nick
	sIdent = sTmp.Token(1, true, "!");
	sHost  = sIdent.Token(1, true, "@");
	sIdent = sIdent.Token(0, false, "@");
	// Get the nick
	sTmp   = sTmp.Token(0, false, "!");

	CNick tmpNick(sTmp);
	CNick* pNick = FindNick(sTmp);
	if (!pNick) {
		pNick = &tmpNick;
		pNick->SetNetwork(m_pNetwork);
	}

	if (!sIdent.empty())
		pNick->SetIdent(sIdent);
	if (!sHost.empty())
		pNick->SetHost(sHost);

	for (CString::size_type i = 0; i < sPrefix.length(); i++) {
		pNick->AddPerm(sPrefix[i]);
	}

	if (pNick->NickEquals(m_pNetwork->GetCurNick())) {
		for (CString::size_type i = 0; i < sPrefix.length(); i++) {
			AddPerm(sPrefix[i]);
		}
	}

	m_msNicks[pNick->GetNick()] = *pNick;

	return true;
}
Beispiel #7
0
	void HandleMessage(CNick& Nick, const CString& sMessage) {
		CString sNickServName = (!GetNV("NickServName").empty()) ? GetNV("NickServName") : "NickServ";
		if (!GetNV("Password").empty()
				&& Nick.NickEquals(sNickServName)
				&& (sMessage.find("msg") != CString::npos
				 || sMessage.find("authenticate") != CString::npos
				 || sMessage.find("choose a different nickname") != CString::npos
				 || sMessage.find("please choose a different nick") != CString::npos
				 || sMessage.find("If this is your nick, identify yourself with") != CString::npos
				 || sMessage.find("If this is your nick, type") != CString::npos
				 || sMessage.find("This is a registered nickname, please identify") != CString::npos
				 || sMessage.StripControls_n().find("type /NickServ IDENTIFY password") != CString::npos)
				&& sMessage.AsUpper().find("IDENTIFY") != CString::npos
				&& sMessage.find("help") == CString::npos) {
			MCString msValues;
			msValues["password"] = GetNV("Password");
			PutIRC(CString::NamedFormat(GetNV("IdentifyCmd"), msValues));
		}
	}
Beispiel #8
0
Datei: q.cpp Projekt: Adam-/znc
 bool IsSelf(const CNick& Nick) {
     return Nick.NickEquals(GetNetwork()->GetCurNick());
 }
Beispiel #9
0
Datei: q.cpp Projekt: Adam-/znc
    EModRet HandleMessage(const CNick& Nick, CString sMessage) {
        if (!Nick.NickEquals("Q") ||
            !Nick.GetHost().Equals("CServe.quakenet.org"))
            return CONTINUE;

        sMessage.Trim();

#if Q_DEBUG_COMMUNICATION
        PutModule("[ZNC <-- Q] " + sMessage);
#endif

        // WHOAMI
        if (sMessage.find("WHOAMI is only available to authed users") !=
            CString::npos) {
            m_bAuthed = false;
            Auth();
            m_bCatchResponse = m_bRequestedWhoami;
        } else if (sMessage.find("Information for user") != CString::npos) {
            m_bAuthed = true;
            m_msChanModes.clear();
            m_bCatchResponse = m_bRequestedWhoami;
            m_bRequestedWhoami = true;
        } else if (m_bRequestedWhoami && sMessage.WildCmp("#*")) {
            CString sChannel = sMessage.Token(0);
            CString sFlags = sMessage.Token(1, true).Trim_n().TrimLeft_n("+");
            m_msChanModes[sChannel] = sFlags;
        } else if (m_bRequestedWhoami && m_bCatchResponse &&
                   (sMessage.Equals("End of list.") ||
                    sMessage.Equals(
                        "account, or HELLO to create an account."))) {
            m_bRequestedWhoami = m_bCatchResponse = false;
            return HALT;
        }

        // AUTH
        else if (sMessage.Equals("Username or password incorrect.")) {
            m_bAuthed = false;
            PutModule("Auth failed: " + sMessage);
            return HALT;
        } else if (sMessage.WildCmp("You are now logged in as *.")) {
            m_bAuthed = true;
            PutModule("Auth successful: " + sMessage);
            WhoAmI();
            return HALT;
        } else if (m_bRequestedChallenge &&
                   sMessage.Token(0).Equals("CHALLENGE")) {
            m_bRequestedChallenge = false;
            if (sMessage.find("not available once you have authed") !=
                CString::npos) {
                m_bAuthed = true;
            } else {
                if (sMessage.find("HMAC-SHA-256") != CString::npos) {
                    ChallengeAuth(sMessage.Token(1));
                } else {
                    PutModule(
                        "Auth failed: Q does not support HMAC-SHA-256 for "
                        "CHALLENGEAUTH, falling back to standard AUTH.");
                    SetUseChallenge(false);
                    Auth();
                }
            }
            return HALT;
        }

        // prevent buffering of Q's responses
        return !m_bCatchResponse && GetUser()->IsUserAttached() ? CONTINUE
                                                                : HALT;
    }
Beispiel #10
0
void CChan::ModeChange(const CString& sModes, const CNick* pOpNick) {
	CString sModeArg = sModes.Token(0);
	CString sArgs = sModes.Token(1, true);
	bool bAdd = true;

	/* Try to find a CNick* from this channel so that pOpNick->HasPerm()
	 * works as expected. */
	if (pOpNick) {
		CNick* OpNick = FindNick(pOpNick->GetNick());
		/* If nothing was found, use the original pOpNick, else use the
		 * CNick* from FindNick() */
		if (OpNick)
			pOpNick = OpNick;
	}

	if (pOpNick) {
		NETWORKMODULECALL(OnRawMode(*pOpNick, *this, sModeArg, sArgs), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
	}

	for (unsigned int a = 0; a < sModeArg.size(); a++) {
		const unsigned char& uMode = sModeArg[a];

		if (uMode == '+') {
			bAdd = true;
		} else if (uMode == '-') {
			bAdd = false;
		} else if (m_pNetwork->GetIRCSock()->IsPermMode(uMode)) {
			CString sArg = GetModeArg(sArgs);
			CNick* pNick = FindNick(sArg);
			if (pNick) {
				unsigned char uPerm = m_pNetwork->GetIRCSock()->GetPermFromMode(uMode);

				if (uPerm) {
					bool bNoChange = (pNick->HasPerm(uPerm) == bAdd);

					if (bAdd) {
						pNick->AddPerm(uPerm);

						if (pNick->NickEquals(m_pNetwork->GetCurNick())) {
							AddPerm(uPerm);
						}
					} else {
						pNick->RemPerm(uPerm);

						if (pNick->NickEquals(m_pNetwork->GetCurNick())) {
							RemPerm(uPerm);
						}
					}

					if (uMode && pOpNick) {
						NETWORKMODULECALL(OnChanPermission(*pOpNick, *pNick, *this, uMode, bAdd, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);

						if (uMode == CChan::M_Op) {
							if (bAdd) {
								NETWORKMODULECALL(OnOp(*pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
							} else {
								NETWORKMODULECALL(OnDeop(*pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
							}
						} else if (uMode == CChan::M_Voice) {
							if (bAdd) {
								NETWORKMODULECALL(OnVoice(*pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
							} else {
								NETWORKMODULECALL(OnDevoice(*pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
							}
						}
					}
				}
			}
		} else {
			bool bList = false;
			CString sArg;

			switch (m_pNetwork->GetIRCSock()->GetModeType(uMode)) {
				case CIRCSock::ListArg:
					bList = true;
					sArg = GetModeArg(sArgs);
					break;
				case CIRCSock::HasArg:
					sArg = GetModeArg(sArgs);
					break;
				case CIRCSock::NoArg:
					break;
				case CIRCSock::ArgWhenSet:
					if (bAdd) {
						sArg = GetModeArg(sArgs);
					}

					break;
			}

			if (pOpNick) {
				bool bNoChange;
				if (bList) {
					bNoChange = false;
				} else if (bAdd) {
					bNoChange = HasMode(uMode) && GetModeArg(uMode) == sArg;
				} else {
					bNoChange = !HasMode(uMode);
				}
				NETWORKMODULECALL(OnMode(*pOpNick, *this, uMode, sArg, bAdd, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
			}

			if (!bList) {
				(bAdd) ? AddMode(uMode, sArg) : RemMode(uMode);
			}
		}
	}
}
Beispiel #11
0
void CChan::ModeChange(const CString& sModes, const CNick* pOpNick) {
    CString sModeArg = sModes.Token(0);
    CString sArgs = sModes.Token(1, true);
    bool bAdd = true;

    /* Try to find a CNick* from this channel so that pOpNick->HasPerm()
     * works as expected. */
    if (pOpNick) {
        CNick* OpNick = FindNick(pOpNick->GetNick());
        /* If nothing was found, use the original pOpNick, else use the
         * CNick* from FindNick() */
        if (OpNick) pOpNick = OpNick;
    }

    NETWORKMODULECALL(OnRawMode2(pOpNick, *this, sModeArg, sArgs),
                      m_pNetwork->GetUser(), m_pNetwork, nullptr, NOTHING);

    for (unsigned int a = 0; a < sModeArg.size(); a++) {
        const char& cMode = sModeArg[a];

        if (cMode == '+') {
            bAdd = true;
        } else if (cMode == '-') {
            bAdd = false;
        } else if (m_pNetwork->GetIRCSock()->IsPermMode(cMode)) {
            CString sArg = GetModeArg(sArgs);
            CNick* pNick = FindNick(sArg);
            if (pNick) {
                char cPerm =
                    m_pNetwork->GetIRCSock()->GetPermFromMode(cMode);

                if (cPerm) {
                    bool bNoChange = (pNick->HasPerm(cPerm) == bAdd);

                    if (bAdd) {
                        pNick->AddPerm(cPerm);

                        if (pNick->NickEquals(m_pNetwork->GetCurNick())) {
                            AddPerm(cPerm);
                        }
                    } else {
                        pNick->RemPerm(cPerm);

                        if (pNick->NickEquals(m_pNetwork->GetCurNick())) {
                            RemPerm(cPerm);
                        }
                    }

                    NETWORKMODULECALL(OnChanPermission3(pOpNick, *pNick, *this,
                                                        cMode, bAdd, bNoChange),
                                      m_pNetwork->GetUser(), m_pNetwork,
                                      nullptr, NOTHING);

                    if (cMode == CChan::M_Op) {
                        if (bAdd) {
                            NETWORKMODULECALL(
                                OnOp2(pOpNick, *pNick, *this, bNoChange),
                                m_pNetwork->GetUser(), m_pNetwork, nullptr,
                                NOTHING);
                        } else {
                            NETWORKMODULECALL(
                                OnDeop2(pOpNick, *pNick, *this, bNoChange),
                                m_pNetwork->GetUser(), m_pNetwork, nullptr,
                                NOTHING);
                        }
                    } else if (cMode == CChan::M_Voice) {
                        if (bAdd) {
                            NETWORKMODULECALL(
                                OnVoice2(pOpNick, *pNick, *this, bNoChange),
                                m_pNetwork->GetUser(), m_pNetwork, nullptr,
                                NOTHING);
                        } else {
                            NETWORKMODULECALL(
                                OnDevoice2(pOpNick, *pNick, *this, bNoChange),
                                m_pNetwork->GetUser(), m_pNetwork, nullptr,
                                NOTHING);
                        }
                    }
                }
            }
        } else {
            bool bList = false;
            CString sArg;

            switch (m_pNetwork->GetIRCSock()->GetModeType(cMode)) {
                case CIRCSock::ListArg:
                    bList = true;
                    sArg = GetModeArg(sArgs);
                    break;
                case CIRCSock::HasArg:
                    sArg = GetModeArg(sArgs);
                    break;
                case CIRCSock::NoArg:
                    break;
                case CIRCSock::ArgWhenSet:
                    if (bAdd) {
                        sArg = GetModeArg(sArgs);
                    }

                    break;
            }

            bool bNoChange;
            if (bList) {
                bNoChange = false;
            } else if (bAdd) {
                bNoChange = HasMode(cMode) && GetModeArg(cMode) == sArg;
            } else {
                bNoChange = !HasMode(cMode);
            }
            NETWORKMODULECALL(
                OnMode2(pOpNick, *this, cMode, sArg, bAdd, bNoChange),
                m_pNetwork->GetUser(), m_pNetwork, nullptr, NOTHING);

            if (!bList) {
                (bAdd) ? AddMode(cMode, sArg) : RemMode(cMode);
            }

            // This is called when we join (ZNC requests the channel modes
            // on join) *and* when someone changes the channel keys.
            // We ignore channel key "*" because of some broken nets.
            if (cMode == M_Key && !bNoChange && bAdd && sArg != "*") {
                SetKey(sArg);
            }
        }
    }
}