Esempio n. 1
0
void CChan::ModeChange(const CString& sModes, const CString& sOpNick) {
	CString sModeArg = sModes.Token(0);
	CString sArgs = sModes.Token(1, true);
	bool bAdd = true;

#ifdef _MODULES
	CNick* pOpNick = FindNick(sOpNick);

	if (pOpNick) {
		MODULECALL(OnRawMode(*pOpNick, *this, sModeArg, sArgs), m_pUser, NULL, );
	}
#endif

	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_pUser->GetIRCSock()->IsPermMode(uMode)) {
			CString sArg = GetModeArg(sArgs);
			CNick* pNick = FindNick(sArg);
			if (pNick) {
				unsigned char uPerm = m_pUser->GetIRCSock()->GetPermFromMode(uMode);

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

						if (pNick->GetNick().Equals(m_pUser->GetCurNick())) {
							AddPerm(uPerm);
						}
					} else {
						pNick->RemPerm(uPerm);

						if (pNick->GetNick().Equals(m_pUser->GetCurNick())) {
							RemPerm(uPerm);
						}
					}
#ifdef _MODULES
					bool bNoChange = (pNick->HasPerm(uPerm) == bAdd);

					if (uMode && pOpNick) {
						MODULECALL(OnChanPermission(*pOpNick, *pNick, *this, uMode, bAdd, bNoChange), m_pUser, NULL, );

						if (uMode == CChan::M_Op) {
							if (bAdd) {
								MODULECALL(OnOp(*pOpNick, *pNick, *this, bNoChange), m_pUser, NULL, );
							} else {
								MODULECALL(OnDeop(*pOpNick, *pNick, *this, bNoChange), m_pUser, NULL, );
							}
						} else if (uMode == CChan::M_Voice) {
							if (bAdd) {
								MODULECALL(OnVoice(*pOpNick, *pNick, *this, bNoChange), m_pUser, NULL, );
							} else {
								MODULECALL(OnDevoice(*pOpNick, *pNick, *this, bNoChange), m_pUser, NULL, );
							}
						}
					}
Esempio n. 2
0
File: Chan.cpp Progetto: jimloco/znc
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) {
					if (bAdd) {
						pNick->AddPerm(uPerm);

						if (pNick->GetNick().Equals(m_pNetwork->GetCurNick())) {
							AddPerm(uPerm);
						}
					} else {
						pNick->RemPerm(uPerm);

						if (pNick->GetNick().Equals(m_pNetwork->GetCurNick())) {
							RemPerm(uPerm);
						}
					}
					bool bNoChange = (pNick->HasPerm(uPerm) == bAdd);

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

			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);
			}
		}
	}
}
Esempio n. 3
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);
            }
        }
    }
}