Exemple #1
0
void CommandMode::DisplayCurrentModes(User* user, User* targetuser, Channel* targetchannel)
{
	if (targetchannel)
	{
		// Display channel's current mode string
		user->WriteNumeric(RPL_CHANNELMODEIS, targetchannel->name, (std::string("+") + targetchannel->ChanModes(targetchannel->HasUser(user))));
		user->WriteNumeric(RPL_CHANNELCREATED, targetchannel->name, (unsigned long)targetchannel->age);
	}
	else
	{
		if (targetuser == user || user->HasPrivPermission("users/auspex"))
		{
			// Display user's current mode string
			// XXX: Use WriteServ() because WriteNumeric() assumes the target (i.e. next word after the number)
			// is 'user' and puts his nick there which is not what we want
			user->WriteServ("%03d %s :+%s", RPL_UMODEIS, targetuser->nick.c_str(), targetuser->FormatModes());
			if (targetuser->IsOper())
			{
				ModeHandler* snomask = ServerInstance->Modes->FindMode('s', MODETYPE_USER);
				std::string snomaskstr = snomask->GetUserParameter(user);
				// snomaskstr is empty if the snomask mode isn't set, otherwise it begins with a '+'.
				// In the former case output a "+", not an empty string.
				user->WriteServ("%03d %s %s%s :Server notice mask", RPL_SNOMASKIS, targetuser->nick.c_str(), (snomaskstr.empty() ? "+" : ""), snomaskstr.c_str());
			}
		}
		else
		{
			user->WriteNumeric(ERR_USERSDONTMATCH, "Can't view modes for other users");
		}
	}
}
Exemple #2
0
void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targetchannel, const char* text)
{
	if (targetchannel)
	{
		/* Display channel's current mode string */
		user->WriteNumeric(RPL_CHANNELMODEIS, "%s +%s", targetchannel->name.c_str(), targetchannel->ChanModes(targetchannel->HasUser(user)));
		user->WriteNumeric(RPL_CHANNELCREATED, "%s %lu", targetchannel->name.c_str(), (unsigned long)targetchannel->age);
		return;
	}
	else
	{
		if (targetuser == user || user->HasPrivPermission("users/auspex"))
		{
			/* Display user's current mode string */
			user->WriteNumeric(RPL_UMODEIS, ":+%s", targetuser->FormatModes());
			if ((targetuser->IsOper()))
			{
				ModeHandler* snomask = FindMode('s', MODETYPE_USER);
				user->WriteNumeric(RPL_SNOMASKIS, "%s :Server notice mask", snomask->GetUserParameter(user).c_str());
			}
			return;
		}
		else
		{
			user->WriteNumeric(ERR_USERSDONTMATCH, ":Can't view modes for other users");
			return;
		}
	}
}
void DataKeeper::DoSaveUsers()
{
	ModesExts currdata;

	const user_hash& users = ServerInstance->Users->GetUsers();
	for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i)
	{
		User* const user = i->second;

		// Serialize user modes
		for (size_t j = 0; j < handledmodes[MODETYPE_USER].size(); j++)
		{
			ModeHandler* mh = handledmodes[MODETYPE_USER][j].mh;
			if (user->IsModeSet(mh))
				currdata.modelist.push_back(InstanceData(j, mh->GetUserParameter(user)));
		}

		// Serialize all extensions attached to the User
		SaveExtensions(user, currdata.extlist);

		// Add to list if the user has any modes or extensions set that we are interested in, otherwise we don't
		// have to do anything with this user when restoring
		if (!currdata.empty())
		{
			userdatalist.push_back(UserData(user->uuid));
			userdatalist.back().swap(currdata);
		}
	}
}
Exemple #4
0
const char* User::FormatModes(bool showparameters)
{
	static std::string data;
	std::string params;
	data.clear();

	for (unsigned char n = 0; n < 64; n++)
	{
		ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
		if (mh && IsModeSet(mh))
		{
			data.push_back(n + 65);
			if (showparameters && mh->GetNumParams(true))
			{
				std::string p = mh->GetUserParameter(this);
				if (p.length())
					params.append(" ").append(p);
			}
		}
	}
	data += params;
	return data.c_str();
}
Exemple #5
0
const char* User::FormatModes(bool showparameters)
{
	static char data[MAXBUF];
	std::string params;
	int offset = 0;

	for (unsigned char n = 0; n < 64; n++)
	{
		if (modes[n])
		{
			data[offset++] = n + 65;
			ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
			if (showparameters && mh && mh->GetNumParams(true))
			{
				std::string p = mh->GetUserParameter(this);
				if (p.length())
					params.append(" ").append(p);
			}
		}
	}
	data[offset] = 0;
	strlcat(data, params.c_str(), MAXBUF);
	return data;
}