Logo Search packages:      
Sourcecode: sbnc version File versions  Download package

void CChannel::ParseModeChange ( const char *  Source,
const char *  Modes,
int  pargc,
const char **  pargv 
)

ParseModeChange

Parses a mode change and updates the internal structures.

Parameters:
Source the source of the mode change
Modes the modified modes
pargc the number of parameters
pargv the parameters

Definition at line 186 of file Channel.cpp.

References CNick::AddPrefix(), FindSlot(), CUser::GetKeyring(), CVector< Type >::GetLength(), CCore::GetModules(), CObject< CChannel, CIRCConnection >::GetOwner(), CObject< CChannel, CIRCConnection >::GetUser(), CIRCConnection::IsNickMode(), m_Banlist, m_HasBans, m_Modes, m_Name, m_Nicks, m_TempModes, chanmode_s::Mode, chanmode_s::Parameter, CNick::RemovePrefix(), CIRCConnection::RequiresParameter(), CBanlist::SetBan(), CKeyring::SetKey(), SetModesValid(), CBanlist::UnsetBan(), and CConnection::WriteLine().

Referenced by CIRCConnection::ParseLineArgV().

                                                                                                   {
      bool Flip = true;
      int p = 0;

      /* free any cached chanmodes */
      if (m_TempModes != NULL) {
            ufree(m_TempModes);
            m_TempModes = NULL;
      }

      const CVector<CModule *> *Modules = g_Bouncer->GetModules();

      for (unsigned int i = 0; i < strlen(Modes); i++) {
            char Current = Modes[i];

            if (Current == '+') {
                  Flip = true;
                  continue;
            } else if (Current == '-') {
                  Flip = false;
                  continue;
            } else if (GetOwner()->IsNickMode(Current)) {
                  if (p >= pargc) {
                        return; // should not happen
                  }

                  CNick *NickObj = m_Nicks.Get(pargv[p]);

                  if (NickObj != NULL) {
                        if (Flip) {
                              NickObj->AddPrefix(GetOwner()->PrefixForChanMode(Current));
                        } else {
                              NickObj->RemovePrefix(GetOwner()->PrefixForChanMode(Current));
                        }
                  }

                  for (unsigned int i = 0; i < Modules->GetLength(); i++) {
                        (*Modules)[i]->SingleModeChange(GetOwner(), m_Name, Source, Flip, Current, pargv[p]);
                  }

                  if (Flip && Current == 'o' && strcasecmp(pargv[p], GetOwner()->GetCurrentNick()) == 0) {
                        // invalidate channel modes so we can get channel-modes which require +o (e.g. +k)
                        SetModesValid(false);

                        // update modes immediatelly if we don't have a client
                        if (GetUser()->GetClientConnectionMultiplexer() == NULL) {
                              GetOwner()->WriteLine("MODE %s", m_Name);
                        }
                  }

                  p++;

                  continue;
            }

            chanmode_t *Slot = FindSlot(Current);

            int ModeType = GetOwner()->RequiresParameter(Current);

            if (Current == 'b' && m_Banlist != NULL && p < pargc) {
                  if (Flip) {
                        if (IsError(m_Banlist->SetBan(pargv[p], Source, g_CurrentTime))) {
                              m_HasBans = false;
                        }
                  } else {
                        m_Banlist->UnsetBan(pargv[p]);
                  }
            }

            if (Current == 'k' && Flip && p < pargc && strcmp(pargv[p], "*") != 0) {
                  GetUser()->GetKeyring()->SetKey(m_Name, pargv[p]);
            }

            for (unsigned int i = 0; i < Modules->GetLength(); i++) {
                  const char *arg = NULL;

                  if (((Flip && ModeType != 0) || (!Flip && ModeType != 0 && ModeType != 1)) && p < pargc) {
                        arg = pargv[p];
                  }

                  (*Modules)[i]->SingleModeChange(GetOwner(), m_Name, Source, Flip, Current, arg);
            }

            if (Flip) {
                  if (Slot != NULL) {
                        ufree(Slot->Parameter);
                  } else {
                        Slot = m_Modes.GetNew();
                  }

                  if (Slot == NULL) {
                        if (ModeType) {
                              p++;
                        }

                        continue;
                  }

                  Slot->Mode = Current;

                  if (ModeType != 0 && p < pargc) {
                        Slot->Parameter = ustrdup(pargv[p++]);
                  } else {
                        Slot->Parameter = NULL;
                  }
            } else {
                  if (Slot != NULL) {
                        Slot->Mode = '\0';
                        ufree(Slot->Parameter);

                        Slot->Parameter = NULL;
                  }

                  if (ModeType != 0 && ModeType != 1) {
                        p++;
                  }
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index