public/IRootConsoleMenu.h
author David Anderson <dvander@alliedmods.net>
Sun Aug 25 11:59:47 2013 -0700 (2013-08-25)
changeset 4066 c055944bdfd6
parent 2728 96022dad7e53
permissions -rw-r--r--
Switch smn_maplists off KTrie (bug 5884 part 4, r=ds).
     1 /**
     2  * vim: set ts=4 sw=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2009 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
    33 #define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
    34 
    35 /**
    36  * @file IRootConsoleMenu.h
    37  * @brief Defines the interface for adding options to the "sm" console command.
    38  *
    39  * You must be using the compat_wrappers.h header file to use this on 
    40  * Original/Episode1 builds.  
    41  */
    42 
    43 #define SMINTERFACE_ROOTCONSOLE_NAME			"IRootConsole"
    44 #define SMINTERFACE_ROOTCONSOLE_VERSION			2
    45 
    46 class CCommand;
    47 
    48 namespace SourceMod
    49 {
    50 	/**
    51 	 * @brief Wrapper around CCommand.
    52 	 */
    53 	class ICommandArgs
    54 	{
    55 	public:
    56 		/**
    57 		 * @brief Returns an argument by number.
    58 		 *
    59 		 * @brief n		Argument number.
    60 		 * @return		Argument string.
    61 		 */
    62 		virtual const char *Arg(int n) const = 0;
    63 
    64 		/**
    65 		 * @brief Returns the argument count.
    66 		 *
    67 		 * @return		Argument count.
    68 		 */
    69 		virtual int ArgC() const = 0;
    70 
    71 		/**
    72 		 * @brief Returns the full argument string.
    73 		 *
    74 		 * @return		Argument string.
    75 		 */
    76 		virtual const char *ArgS() const = 0;
    77 	};
    78 
    79 	/**
    80 	 * @brief Handles a root console menu action.
    81 	 */
    82 	class IRootConsoleCommand
    83 	{
    84 	public:
    85 		virtual void OnRootConsoleCommand(const char *cmdname, const CCommand &command)
    86 		{
    87 		}
    88 
    89 		virtual void OnRootConsoleCommand2(const char *cmdname, const ICommandArgs *args)
    90 		{
    91 		}
    92 	};
    93 
    94 	/**
    95 	 * @brief Manages the root console menu - the "sm" command for servers.
    96 	 */
    97 	class IRootConsole : public SMInterface
    98 	{
    99 	public:
   100 		/**
   101 		 * @brief Adds a root console command handler.  The command must be unique.
   102 		 *
   103 		 * @param cmd			String containing the console command.
   104 		 * @param text			Description text.
   105 		 * @param pHandler		An IRootConsoleCommand pointer to handle the command.
   106 		 * @return				True on success, false on too many commands or duplicate command.
   107 		 */
   108 		virtual bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler) =0;
   109 
   110 		/**
   111 		 * @brief Removes a root console command handler.
   112 		 *
   113 		 * @param cmd			String containing the console command.
   114 		 * @param pHandler		An IRootConsoleCommand pointer for verification.
   115 		 * @return				True on success, false otherwise.
   116 		 */
   117 		virtual bool RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler) =0;
   118 
   119 		/**
   120 		 * @brief Prints text back to the console.
   121 		 *
   122 		 * @param fmt			Format of string.
   123 		 * @param ...			Format arguments.
   124 		 */
   125 		virtual void ConsolePrint(const char *fmt, ...) =0;
   126 
   127 		/**
   128 		 * @brief Draws a generic command/description pair.
   129 		 * NOTE: The pair is currently four spaces indented and 16-N spaces of separation,
   130 		 * N being the length of the command name.  This is subject to change in case we
   131 		 * account for Valve's font choices.
   132 		 *
   133 		 * @param cmd		String containing the command option.
   134 		 * @param text		String containing the command description.
   135 		 */
   136 		virtual void DrawGenericOption(const char *cmd, const char *text) =0;
   137 
   138 		/**
   139 		 * @brief Adds a root console command handler.  The command must be unique.
   140 		 *
   141 		 * This version of the function uses the OnRootConsoleCommand2 callback.
   142 		 *
   143 		 * @param cmd			String containing the console command.
   144 		 * @param text			Description text.
   145 		 * @param pHandler		An IRootConsoleCommand pointer to handle the command.
   146 		 * @return				True on success, false on too many commands or duplicate command.
   147 		 */
   148 		virtual bool AddRootConsoleCommand2(const char *cmd,
   149 											const char *text,
   150 											IRootConsoleCommand *pHandler) =0;
   151 	};
   152 }
   153 
   154 #endif //_INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
   155