Example #1
0
bool ModeManager::AddChannelMode(ChannelMode *cm)
{
	if (cm->mchar && ModeManager::FindChannelModeByChar(cm->mchar) != NULL)
		return false;
	if (ModeManager::FindChannelModeByName(cm->name) != NULL)
		return false;

	if (cm->name.empty())
	{
		cm->name = stringify(++GenericChannelModes);
		Log() << "ModeManager: Added generic support for channel mode " << cm->mchar;
	}

	if (cm->mchar)
	{
		unsigned want = cm->mchar;
		if (want >= ChannelModesIdx.size())
			ChannelModesIdx.resize(want + 1);
		ChannelModesIdx[want] = cm;
	}

	if (cm->type == MODE_STATUS)
	{
		ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm);
		unsigned want = cms->symbol;
		if (want >= ChannelModesIdx.size())
			ChannelModesIdx.resize(want + 1);
		ChannelModesIdx[want] = cms;

		RebuildStatusModes();
	}

	ChannelModesByName[cm->name] = cm;

	ChannelModes.push_back(cm);

	FOREACH_MOD(OnChannelModeAdd, (cm));

	for (unsigned int i = 0; i < ChannelModes.size(); ++i)
		ChannelModes[i]->Check();

	return true;
}
Example #2
0
void ModeManager::RemoveChannelMode(ChannelMode *cm)
{
	if (!cm)
		return;

	if (cm->mchar)
	{
		unsigned want = cm->mchar;
		if (want >= ChannelModesIdx.size())
			return;
	
		if (ChannelModesIdx[want] != cm)
			return;
	
		ChannelModesIdx[want] = NULL;
	}

	if (cm->type == MODE_STATUS)
	{
		ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm);
		unsigned want = cms->symbol;

		if (want >= ChannelModesIdx.size())
			return;

		if (ChannelModesIdx[want] != cm)
			return;

		ChannelModesIdx[want] = NULL;

		RebuildStatusModes();
	}

	ChannelModesByName.erase(cm->name);

	std::vector<ChannelMode *>::iterator it = std::find(ChannelModes.begin(), ChannelModes.end(), cm);
	if (it != ChannelModes.end())
		ChannelModes.erase(it);

	StackerDel(cm);
}
Example #3
0
bool ModeManager::AddChannelMode(ChannelMode *cm)
{
    if (cm->mchar && ModeManager::FindChannelModeByChar(cm->mchar) != NULL)
        return false;
    if (ModeManager::FindChannelModeByName(cm->name) != NULL)
        return false;

    if (cm->mchar)
    {
        unsigned want = cm->mchar;
        if (want >= ChannelModesIdx.size())
            ChannelModesIdx.resize(want + 1);
        ChannelModesIdx[want] = cm;
    }

    if (cm->type == MODE_STATUS)
    {
        ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm);
        unsigned want = cms->symbol;
        if (want >= ChannelModesIdx.size())
            ChannelModesIdx.resize(want + 1);
        ChannelModesIdx[want] = cms;

        RebuildStatusModes();
    }

    ChannelModesByName[cm->name] = cm;

    ChannelModes.push_back(cm);

    Event::OnChannelModeAdd(&Event::ChannelModeAdd::OnChannelModeAdd, cm);

    for (unsigned int i = 0; i < ChannelModes.size(); ++i)
        ChannelModes[i]->Check();

    return true;
}