
The interface used by command parsers. More...
#include <CommandParserInterface.h>

Public Member Functions | |
| CommandParserInterface () | |
| virtual const char * | GetName (void) const =0 |
| virtual bool | GetRegisteredCommand (const char *command, RegisteredCommand *rc) |
| SystemAddress | IntegersToSystemAddress (int binaryAddress, int port) |
| Since there's no way to specify a systemAddress directly, the user needs to specify both the binary address and port. | |
| virtual bool | OnCommand (const char *command, unsigned numParameters, char **parameterList, TransportInterface *transport, SystemAddress systemAddress, const char *originalString)=0 |
| Given command with parameters parameterList , do whatever processing you wish. | |
| virtual void | OnConnectionLost (SystemAddress systemAddress, TransportInterface *transport) |
| A callback for when systemAddress has disconnected, either gracefully or forcefully. | |
| virtual void | OnNewIncomingConnection (SystemAddress systemAddress, TransportInterface *transport) |
| A callback for when systemAddress has connected to us. | |
| virtual void | OnTransportChange (TransportInterface *transport) |
| This is called every time transport interface is registered. | |
| virtual void | RegisterCommand (unsigned char parameterCount, const char *command, const char *commandHelp) |
| virtual void | ReturnResult (int res, const char *command, TransportInterface *transport, SystemAddress systemAddress) |
| virtual void | ReturnResult (char *res, const char *command, TransportInterface *transport, SystemAddress systemAddress) |
| virtual void | ReturnResult (const char *command, TransportInterface *transport, SystemAddress systemAddress) |
| Just writes a string to the remote system when you are calling a function that has no return value. | |
| virtual void | ReturnResult (bool res, const char *command, TransportInterface *transport, SystemAddress systemAddress) |
| Just writes a string to the remote system based on the result ( res ) of your operation. | |
| virtual void | ReturnResult (SystemAddress res, const char *command, TransportInterface *transport, SystemAddress systemAddress) |
| virtual void | SendCommandList (TransportInterface *transport, SystemAddress systemAddress) |
| virtual void | SendHelp (TransportInterface *transport, SystemAddress systemAddress)=0 |
| A callback for when you are expected to send a brief description of your parser to systemAddress. | |
| virtual | ~CommandParserInterface () |
Static Public Member Functions | |
| static void | ParseConsoleString (char *str, const char delineator, unsigned char delineatorToggle, unsigned *numParameters, char **parameterList, unsigned parameterListLength) |
Static Public Attributes | |
| static const unsigned char | VARIABLE_NUMBER_OF_PARAMETERS = 255 |
Protected Attributes | |
| DataStructures::OrderedList < const char *, RegisteredCommand, RegisteredCommandComp > | commandList |
CommandParserInterface provides a set of functions and interfaces that plug into the ConsoleServer class. Each CommandParserInterface works at the same time as other interfaces in the system.
Definition at line 35 of file CommandParserInterface.h.
| CommandParserInterface::CommandParserInterface | ( | ) |
Definition at line 31 of file CommandParserInterface.cpp.
{}
| CommandParserInterface::~CommandParserInterface | ( | ) | [virtual] |
Definition at line 32 of file CommandParserInterface.cpp.
{}
| virtual const char* CommandParserInterface::GetName | ( | void | ) | const [pure virtual] |
You are responsible for overriding this function and returning a static string, which will identifier your parser. This should return a static string
Implemented in LogCommandParser, RakNetCommandParser, and RakNetTransportCommandParser.
Referenced by ConsoleServer::AddCommandParser().
| bool CommandParserInterface::GetRegisteredCommand | ( | const char * | command, | |
| RegisteredCommand * | rc | |||
| ) | [virtual] |
Definition at line 104 of file CommandParserInterface.cpp.
References commandList, and DataStructures::OrderedList< key_type, data_type, default_comparison_function >::GetIndexFromKey().
{
bool objectExists;
unsigned index;
index=commandList.GetIndexFromKey(command, &objectExists);
if (objectExists)
*rc=commandList[index];
return objectExists;
}
| SystemAddress CommandParserInterface::IntegersToSystemAddress | ( | int | binaryAddress, | |
| int | port | |||
| ) |
Given those parameters, this returns the corresponding SystemAddress
| [in] | binaryAddress | The binaryAddress portion of SystemAddress |
| [in] | port | The port portion of SystemAddress |
Definition at line 157 of file CommandParserInterface.cpp.
References SystemAddress::binaryAddress, and SystemAddress::port.
Referenced by RakNetCommandParser::OnCommand().
{
SystemAddress systemAddress;
systemAddress.binaryAddress=binaryAddress;
systemAddress.port=(unsigned short)port;
return systemAddress;
}
| virtual bool CommandParserInterface::OnCommand | ( | const char * | command, | |
| unsigned | numParameters, | |||
| char ** | parameterList, | |||
| TransportInterface * | transport, | |||
| SystemAddress | systemAddress, | |||
| const char * | originalString | |||
| ) | [pure virtual] |
| [in] | command | The command to process |
| [in] | numParameters | How many parameters were passed along with the command |
| [in] | parameterList | The list of parameters. parameterList[0] is the first parameter and so on. |
| [in] | transport | The transport interface we can use to write to |
| [in] | systemAddress | The player that sent this command. |
| [in] | originalString | The string that was actually sent over the network, in case you want to do your own parsing |
Implemented in LogCommandParser, RakNetCommandParser, and RakNetTransportCommandParser.
| void CommandParserInterface::OnConnectionLost | ( | SystemAddress | systemAddress, | |
| TransportInterface * | transport | |||
| ) | [virtual] |
| [in] | systemAddress | The player that has disconnected. |
| [in] | transport | The transport interface that sent us this information. |
Reimplemented in LogCommandParser.
Definition at line 122 of file CommandParserInterface.cpp.
{
(void) systemAddress;
(void) transport;
}
| void CommandParserInterface::OnNewIncomingConnection | ( | SystemAddress | systemAddress, | |
| TransportInterface * | transport | |||
| ) | [virtual] |
| [in] | systemAddress | The player that has connected. |
| [in] | transport | The transport interface that sent us this information. Can be used to send messages to this or other players. |
Reimplemented in LogCommandParser.
Definition at line 117 of file CommandParserInterface.cpp.
{
(void) systemAddress;
(void) transport;
}
| void CommandParserInterface::OnTransportChange | ( | TransportInterface * | transport | ) | [virtual] |
If you want to save a copy of the TransportInterface pointer This is the place to do it
| [in] | transport | The new TransportInterface |
Reimplemented in LogCommandParser.
Definition at line 113 of file CommandParserInterface.cpp.
Referenced by ConsoleServer::AddCommandParser().
{
(void) transport;
}
| void CommandParserInterface::ParseConsoleString | ( | char * | str, | |
| const char | delineator, | |||
| unsigned char | delineatorToggle, | |||
| unsigned * | numParameters, | |||
| char ** | parameterList, | |||
| unsigned | parameterListLength | |||
| ) | [static] |
Definition at line 34 of file CommandParserInterface.cpp.
References RakAssert.
Referenced by ConsoleServer::Update().
{
unsigned strIndex, parameterListIndex;
unsigned strLen;
bool replaceDelineator=true;
strLen = (unsigned) strlen(str);
// Replace every instance of delineator, \n, \r with 0
for (strIndex=0; strIndex < strLen; strIndex++)
{
if (str[strIndex]==delineator && replaceDelineator)
str[strIndex]=0;
if (str[strIndex]=='\n' || str[strIndex]=='\r')
str[strIndex]=0;
if (str[strIndex]==delineatorToggle)
{
str[strIndex]=0;
replaceDelineator=!replaceDelineator;
}
}
// Fill up parameterList starting at each non-0
for (strIndex=0, parameterListIndex=0; strIndex < strLen; )
{
if (str[strIndex]!=0)
{
parameterList[parameterListIndex]=str+strIndex;
parameterListIndex++;
RakAssert(parameterListIndex < parameterListLength);
if (parameterListIndex >= parameterListLength)
break;
strIndex++;
while (str[strIndex]!=0 && strIndex < strLen)
strIndex++;
}
else
strIndex++;
}
parameterList[parameterListIndex]=0;
*numParameters=parameterListIndex;
}
| void CommandParserInterface::RegisterCommand | ( | unsigned char | parameterCount, | |
| const char * | command, | |||
| const char * | commandHelp | |||
| ) | [virtual] |
Registers a command.
| [in] | parameterCount | How many parameters your command requires. If you want to accept a variable number of commands, pass CommandParserInterface::VARIABLE_NUMBER_OF_PARAMETERS |
| [in] | command | A pointer to a STATIC string that has your command. I keep a copy of the pointer here so don't deallocate the string. |
| [in] | commandHelp | A pointer to a STATIC string that has the help information for your command. I keep a copy of the pointer here so don't deallocate the string. |
Definition at line 96 of file CommandParserInterface.cpp.
References RegisteredCommand::command, RegisteredCommand::commandHelp, commandList, DataStructures::OrderedList< key_type, data_type, default_comparison_function >::Insert(), and RegisteredCommand::parameterCount.
Referenced by LogCommandParser::LogCommandParser(), RakNetCommandParser::RakNetCommandParser(), and RakNetTransportCommandParser::RakNetTransportCommandParser().
{
RegisteredCommand rc;
rc.command=command;
rc.commandHelp=commandHelp;
rc.parameterCount=parameterCount;
commandList.Insert( command, rc, true, __FILE__, __LINE__);
}
| void CommandParserInterface::ReturnResult | ( | char * | res, | |
| const char * | command, | |||
| TransportInterface * | transport, | |||
| SystemAddress | systemAddress | |||
| ) | [virtual] |
Definition at line 142 of file CommandParserInterface.cpp.
References TransportInterface::Send().
{
transport->Send(systemAddress, "%s returned %s.\r\n", command, res);
}
| void CommandParserInterface::ReturnResult | ( | int | res, | |
| const char * | command, | |||
| TransportInterface * | transport, | |||
| SystemAddress | systemAddress | |||
| ) | [virtual] |
Definition at line 134 of file CommandParserInterface.cpp.
References TransportInterface::Send().
{
transport->Send(systemAddress, "%s returned %i.\r\n", command, res);
}
| void CommandParserInterface::ReturnResult | ( | SystemAddress | res, | |
| const char * | command, | |||
| TransportInterface * | transport, | |||
| SystemAddress | systemAddress | |||
| ) | [virtual] |
Definition at line 146 of file CommandParserInterface.cpp.
References SystemAddress::binaryAddress, SystemAddress::port, and TransportInterface::Send().
{
#if !defined(_XBOX) && !defined(_X360)
in_addr in;
in.s_addr = systemAddress.binaryAddress;
inet_ntoa( in );
transport->Send(systemAddress, "%s returned %s %i:%i\r\n", command,inet_ntoa( in ),res.binaryAddress, res.port);
#else
transport->Send(systemAddress, "%s returned %i:%i\r\n", command,res.binaryAddress, res.port);
#endif
}
| void CommandParserInterface::ReturnResult | ( | const char * | command, | |
| TransportInterface * | transport, | |||
| SystemAddress | systemAddress | |||
| ) | [virtual] |
This is not necessary to call, but makes it easier to return results of function calls.
| [in] | res | The result to write |
| [in] | command | The command that this result came from |
| [in] | transport | The transport interface that will be written to |
| [in] | systemAddress | The player this result will be sent to |
Definition at line 138 of file CommandParserInterface.cpp.
References TransportInterface::Send().
{
transport->Send(systemAddress, "Successfully called %s.\r\n", command);
}
| void CommandParserInterface::ReturnResult | ( | bool | res, | |
| const char * | command, | |||
| TransportInterface * | transport, | |||
| SystemAddress | systemAddress | |||
| ) | [virtual] |
This is not necessary to call, but makes it easier to return results of function calls.
| [in] | res | The result to write |
| [in] | command | The command that this result came from |
| [in] | transport | The transport interface that will be written to |
| [in] | systemAddress | The player this result will be sent to |
Definition at line 127 of file CommandParserInterface.cpp.
References TransportInterface::Send().
Referenced by RakNetCommandParser::OnCommand().
| void CommandParserInterface::SendCommandList | ( | TransportInterface * | transport, | |
| SystemAddress | systemAddress | |||
| ) | [virtual] |
Definition at line 80 of file CommandParserInterface.cpp.
References commandList, TransportInterface::Send(), and DataStructures::OrderedList< key_type, data_type, default_comparison_function >::Size().
{
unsigned i;
if (commandList.Size())
{
for (i=0; i < commandList.Size(); i++)
{
transport->Send(systemAddress, "%s", commandList[i].command);
if (i < commandList.Size()-1)
transport->Send(systemAddress, ", ");
}
transport->Send(systemAddress, "\r\n");
}
else
transport->Send(systemAddress, "No registered commands\r\n");
}
| virtual void CommandParserInterface::SendHelp | ( | TransportInterface * | transport, | |
| SystemAddress | systemAddress | |||
| ) | [pure virtual] |
| [in] | transport | The transport interface we can use to write to |
| [in] | systemAddress | The player that requested help. |
Implemented in LogCommandParser, RakNetCommandParser, and RakNetTransportCommandParser.
DataStructures::OrderedList<const char*, RegisteredCommand, RegisteredCommandComp> CommandParserInterface::commandList [protected] |
Definition at line 139 of file CommandParserInterface.h.
Referenced by GetRegisteredCommand(), RegisterCommand(), and SendCommandList().
const unsigned char CommandParserInterface::VARIABLE_NUMBER_OF_PARAMETERS = 255 [static] |
Definition at line 99 of file CommandParserInterface.h.
Referenced by LogCommandParser::LogCommandParser(), and ConsoleServer::Update().
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.