Source: Command.h


Annotated List
Files
Globals
Hierarchy
Index
/***************************************************************************
 *
 * File:    Command.h
 * Created: Fri Jan 7 2000
 * (C) 2000 by David M. <captjay@superlink.net>
 *
 ***************************************************************************/
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef COMMAND_H
#define COMMAND_H

#include <qobject.h>
#include <qstring.h>

class IRCModule;
class DCCUser;
class Message;

/**
* @short Base class for commands
* @author David M.
* The Command class defines an interface for all
* commands the bot receives from users.
* Each command is a specific Command subclass.
* This allows handling the commands no matter
* what it is, along with undoing commands,
* and smaller parsing/handling methods.
*/
class Command : public QObject  {
public: 
	/**
	* Construct a new Command object.
	*
	* PRECONDITIONS: ircModule != 0 ; pUser != 0
	* @param ircModule A pointer to the IRCModule object the
	*        command should use to interact with the IRC server.
	* @param pUser A pointer to the DCCUser object of the user
	*        initiating the command.
	* @param text A string containing the text the user sent
	*        (including the command's name and parameters).
	*/
	Command(IRCModule* ircModule, DCCUser* pUser, QString text);
	virtual ~Command();

  /**
  * Make the command execute.
  * Subclasses must redefine this method and implement
  * their specific behavior.
  */
  virtual void execute() = 0;

  /**
  * Cancel the effects of a command, if possible.
  * Subclasses can redefine this method to implement
  * command undoing.
  * This method does nothing by default.
  */
  virtual void unExecute();
protected:
  /**
  * Determine if the user pointed to by the _user member has
  * the specified access on his current channel.
  *
  * @param level The minimum level needed to execute the command.
  * @return true if the user's level on his current channel is
  *         equal or higher than level, false otherwise.
  */
  bool hasAccess(unsigned int level);
  /**
  * Determine if the user pointed to by the _user member has
  * the specified global access (access on channel "*")
  *
  * @param level The minimum level needed to execute the command.
  * @return true if the user's level on special channel "*" is
  *         equal or higher than level, false otherwise.
  */
  bool hasGlobalAccess(unsigned int level);

  /**
  * Determine if the user specified enough parameters for the command.
  * If the user specified less than min parameters, he is given an error
  * message with the syntax parameter for more details.
  *
  * @param min Minimum necessary number of parameters to the command.
  * @param syntax A string containing an explanation of the command's syntax.
  *        this string is displayed to the user if he did not supply enough
  *        parameters.
  */
  bool hasEnoughParams(unsigned int min,QString syntax = "");

  IRCModule* _ircModule;
  DCCUser* _user;
  Message* _msg;
};

#endif

Generated by: nightsky@centauri on Sat Jan 15 23:06:10 2000, using kdoc 2.0a30.