InspIRCd  2.0
Public Member Functions | Public Attributes | List of all members
CommandParser Class Reference

#include <command_parse.h>

Public Member Functions

 CommandParser ()
CmdResult CallHandler (const std::string &commandname, const std::vector< std::string > &parameters, User *user)
CommandGetHandler (const std::string &commandname)
bool IsValidCommand (const std::string &commandname, unsigned int pcnt, User *user)
int LoopCall (User *user, Command *CommandObj, const std::vector< std::string > &parameters, unsigned int splithere, int extra=-1, bool usemax=true)
bool ProcessBuffer (std::string &buffer, LocalUser *user)
bool AddCommand (Command *f)
void RemoveCommand (Command *x)
int TranslateUIDs (TranslateType to, const std::string &source, std::string &dest)
int TranslateUIDs (const std::vector< TranslateType > to, const std::vector< std::string > &source, std::string &dest, bool prefix_final=false, Command *custom_translator=NULL)

Public Attributes

Commandtable cmdlist

Detailed Description

This class handles command management and parsing. It allows you to add and remove commands from the map, call command handlers by name, and chop up comma seperated parameters into multiple calls.

Constructor & Destructor Documentation

◆ CommandParser()

CommandParser::CommandParser ( )

Default constructor.

Member Function Documentation

◆ AddCommand()

bool CommandParser::AddCommand ( Command f)

Add a new command to the commands hash

fThe new Command to add to the list
True if the command was added

◆ CallHandler()

CmdResult CommandParser::CallHandler ( const std::string &  commandname,
const std::vector< std::string > &  parameters,
User user 

Calls the handler for a given command.

commandnameThe command to find. This should be in uppercase.
parametersParameter list
userThe user to call the handler on behalf of
This method will return CMD_SUCCESS if the command handler was found and called, and the command completeld successfully. It will return CMD_FAILURE if the command handler was found and called, but the command did not complete successfully, and it will return CMD_INVALID if the command simply did not exist at all or the wrong number of parameters were given, or the user was not privilaged enough to execute the command.

◆ GetHandler()

Command * CommandParser::GetHandler ( const std::string &  commandname)

Get the handler function for a command.

commandnameThe command required. Always use uppercase for this parameter.
a pointer to the command handler, or NULL

◆ IsValidCommand()

bool CommandParser::IsValidCommand ( const std::string &  commandname,
unsigned int  pcnt,
User user 

This function returns true if a command is valid with the given number of parameters and user.

commandnameThe command name to check
pcntThe parameter count
userThe user to check against
If the user given has permission to execute the command, and the parameter count is equal to or greater than the minimum number of parameters to the given command, then this function will return true, otherwise it will return false.

◆ LoopCall()

int CommandParser::LoopCall ( User user,
Command CommandObj,
const std::vector< std::string > &  parameters,
unsigned int  splithere,
int  extra = -1,
bool  usemax = true 

LoopCall is used to call a command classes handler repeatedly based on the contents of a comma seperated list. There are two overriden versions of this method, one of which takes two potential lists and the other takes one. We need a version which takes two potential lists for JOIN, because a JOIN may contain two lists of items at once, the channel names and their keys as follows:

JOIN #chan1,#chan2,#chan3 key1,,key3

Therefore, we need to deal with both lists concurrently. The first instance of this method does that by creating two instances of irc::commasepstream and reading them both together until the first runs out of tokens. The second version is much simpler and just has the one stream to read, and is used in NAMES, WHOIS, PRIVMSG etc. Both will only parse until they reach ServerInstance->Config->MaxTargets number of targets, to stop abuse via spam.

userThe user who sent the command
CommandObjthe command object to call for each parameter in the list
parametersParameter list as an array of array of char (that's not a typo).
splithereThe first parameter index to split as a comma seperated list
extraThe second parameter index to split as a comma seperated list
usemaxLimit the command to MaxTargets targets
This function will return 1 when there are no more parameters to process. When this occurs, its caller should return without doing anything, otherwise it should continue into its main section of code.

Some lame ircds will weed out dupes using some shitty O(n^2) algorithm. By using std::set (thanks for the idea w00t) we can cut this down a ton. ...VOOODOOOO!

◆ ProcessBuffer()

bool CommandParser::ProcessBuffer ( std::string &  buffer,
LocalUser user 

Take a raw input buffer from a recvq, and process it on behalf of a user.

bufferThe buffer line to process
userThe user to whom this line belongs

◆ RemoveCommand()

void CommandParser::RemoveCommand ( Command x)

Removes a command.

◆ TranslateUIDs() [1/2]

int CommandParser::TranslateUIDs ( TranslateType  to,
const std::string &  source,
std::string &  dest 

Translate nicknames in a string into UIDs, based on the TranslationType given.

toThe translation type to use for the process.
sourceThe input string
destThe output string, it is safe to pass source and dest as the same variable only for translation type TR_TEXT.
returns the number of substitutions made. Will always be 0 or 1

◆ TranslateUIDs() [2/2]

int CommandParser::TranslateUIDs ( const std::vector< TranslateType >  to,
const std::vector< std::string > &  source,
std::string &  dest,
bool  prefix_final = false,
Command custom_translator = NULL 

Translate nicknames in a list of strings into UIDs, based on the TranslateTypes given.

toThe translation types to use for the process. If this list is too short, TR_TEXT is assumed for the rest.
sourceThe strings to translate
destThe output string
prefix_finalTrue if the final source argument should have a colon prepended (if it could contain a space)
custom_translatorUsed to translate the parameter if the TR_CUSTOM type is found in to
returns the number of substitutions made.

Member Data Documentation

◆ cmdlist

Commandtable CommandParser::cmdlist

Command list, a hash_map of command names to Command*

The documentation for this class was generated from the following files: