Пример #1
0
//-----------------------------------------------------------------------------
// Removes a CClientCommandManager instance for the given name.
//-----------------------------------------------------------------------------
void RemoveCClientCommandManager(const char* szName)
{
	// Find if the given name is a registered client command
	ClientCommandMap::iterator commandMapIter = g_ClientCommandMap.find(szName);
	if( commandMapIter != g_ClientCommandMap.end())
	{
		// If the command is registered, delete the CClientCommandManager instance
		//		and remove the command from the mapping
		delete commandMapIter->second;
		g_ClientCommandMap.erase(commandMapIter);
	}
}
Пример #2
0
//-----------------------------------------------------------------------------
// Returns a CClientCommandManager for the given command name.
//-----------------------------------------------------------------------------
CClientCommandManager* GetClientCommand(const char* szName)
{
	// Find if the given name is a registered client command
	ClientCommandMap::iterator commandMapIter = g_ClientCommandMap.find(szName);
	if( commandMapIter == g_ClientCommandMap.end())
	{
		// If the command is not already registered, add the name and the CClientCommandManager instance to the mapping
		g_ClientCommandMap.insert(std::make_pair(szName, new CClientCommandManager(szName)));

		// Get the client command in the mapping
		commandMapIter = g_ClientCommandMap.find(szName);
	}

	// Return the CClientCommandManager instance for the command
	return commandMapIter->second;
}
Пример #3
0
//-----------------------------------------------------------------------------
// Dispatches a client command.
//-----------------------------------------------------------------------------
PLUGIN_RESULT DispatchClientCommand(edict_t* pEntity, const CCommand &command)
{
	unsigned int iIndex;
	if (!IndexFromEdict(pEntity, iIndex))
		return PLUGIN_CONTINUE;

	// Loop through all registered Client Command Filters
	for(int i = 0; i < s_ClientCommandFilters.m_vecCallables.Count(); i++)
	{
		BEGIN_BOOST_PY()

			// Get the PyObject instance of the callable
			PyObject* pCallable = s_ClientCommandFilters.m_vecCallables[i].ptr();

			// Call the callable and store its return value
			object returnValue = CALL_PY_FUNC(pCallable, boost::ref(command), iIndex);

			// Does the Client Command Filter want to block the command?
			if( !returnValue.is_none() && extract<int>(returnValue) == (int)BLOCK)
			{
				// Block the command
				return PLUGIN_STOP;
			}

		END_BOOST_PY_NORET()
	}

	// Get the command's name
	const char* szCommand = command.Arg(0);

	// Find if the command exists in the mapping
	ClientCommandMap::iterator commandMapIter = g_ClientCommandMap.find(szCommand);
	if( commandMapIter != g_ClientCommandMap.end() )
	{
		// If the command exists, get the CClientCommandManager instance and call its Dispatch method
		CClientCommandManager* pCClientCommandManager = commandMapIter->second;

		// Does the command need to be blocked?
		if( !pCClientCommandManager->Dispatch(command, iIndex))
		{
			// Block the command
			return PLUGIN_STOP;
		}
	}

	return PLUGIN_CONTINUE;
}
Пример #4
0
void Client::readSocket() {
	using boost::format;
	ClientCallbackFunction funcPtr;
	std::string command, commandBuf, arguments;
	size_t endpos, argpos;
	ClientCommandMap commandMap = DC::instance().getClientCommandMap();
	ClientCommandMap::iterator function;
	std::string sendBuf;

	*m_socket >> m_buff;

	logTrace(
		TRACE, format("Client::readSocket: m_buff: %1%")
			% Utils::hexDump(m_buff)
	);

	endpos = m_buff.find("|", 0);
	while (endpos != std::string::npos) {
		commandBuf = m_buff.substr(0, endpos);
		argpos = commandBuf.find(" ");
		command = commandBuf.substr(0, argpos);
		function = commandMap.find(command);
		if (function != commandMap.end()) {
			if (argpos != std::string::npos) {
				arguments = commandBuf.substr(argpos+1);
			}
			sendBuf.append(((*function).second)(this, arguments));
		} else {
			logTrace(
				TRACE, format("Command %s not found") % command
			);
		}
		m_buff.erase(0, endpos + 1);
		endpos = m_buff.find("|", 0);
	}
	// send the sendBuf (this processes commands received in batches,
	// needed for some parts of the protocol expecting same packet replies)
	*m_socket << sendBuf;
}