Crossfire Server, Trunk
commands.cpp File Reference
#include "global.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "commands.h"
#include "sproto.h"
#include "assert.h"
#include <map>
#include <string>
+ Include dependency graph for commands.cpp:

Go to the source code of this file.

Data Structures

struct  registered_command
 

Macros

#define RC(name, func, time)   command_register(name, COMMAND_TYPE_COMMUNICATION, func, time)
 
#define RN(name, func, time)   command_register(name, COMMAND_TYPE_NORMAL, func, time)
 
#define RW(name, func, time)   command_register(name, COMMAND_TYPE_WIZARD, func, time)
 

Functions

void command_execute (object *pl, char *command)
 
static registered_commandcommand_find (const char *name, object *pl)
 
void command_list (object *pl, bool is_dm)
 
static void command_partial_commands (object *op, const char *params)
 
command_registration command_register (const char *name, uint8_t type, command_function func, float time)
 
command_registration command_register_extra (const char *name, const char *extra, uint8_t type, command_function_extra func, float time)
 
void command_unregister (command_registration command)
 
void commands_clear ()
 
void commands_init (void)
 
static command_registration do_register (const char *name, uint8_t type, command_function func_std, command_function_extra func_extra, const char *extra, float time)
 
static void show_commands (object *op, uint8_t type, const char *legend)
 

Variables

static command_registration next_registration = 1
 
static std::map< std::string, std::vector< registered_command * > > registered_commands
 

Detailed Description

Contains the definition for all in-game commands a player can issue.

Definition in file commands.cpp.

Macro Definition Documentation

◆ RC

#define RC (   name,
  func,
  time 
)    command_register(name, COMMAND_TYPE_COMMUNICATION, func, time)

◆ RN

#define RN (   name,
  func,
  time 
)    command_register(name, COMMAND_TYPE_NORMAL, func, time)

◆ RW

#define RW (   name,
  func,
  time 
)    command_register(name, COMMAND_TYPE_WIZARD, func, time)

Function Documentation

◆ command_execute()

void command_execute ( object pl,
char *  command 
)

Handle a player-issued command.

Parameters
plplayer who is issuing the command
commandthe actual command with its arguments. Will be modified in-place.

Definition at line 456 of file commands.cpp.

References devourers::command, command_find(), registered_command::extra, registered_command::func_extra, registered_command::func_std, llevDebug, LOG(), altar_valkyrie::pl, registered_command::time, and tolower.

Referenced by new_player_cmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ command_find()

static registered_command* command_find ( const char *  name,
object pl 
)
static

Find a command by its name.

Parameters
namecommand name.
plplayer to get the command for.
Returns
matching command, nullptr if no match or multiple matches, in which case the player was warned.

Definition at line 407 of file commands.cpp.

References devourers::command, COMMAND_TYPE_WIZARD, draw_ext_info_format(), FLAG_WIZ, matches(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, give::name, NDI_UNIQUE, altar_valkyrie::pl, QUERY_FLAG, and registered_commands.

Referenced by command_execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ command_list()

void command_list ( object pl,
bool  is_dm 
)

Display the list of commands to a player.

Parameters
plplayer asking for commands.
is_dmtrue if the player is a DM, false else.

Definition at line 390 of file commands.cpp.

References COMMAND_TYPE_COMMUNICATION, COMMAND_TYPE_NORMAL, COMMAND_TYPE_WIZARD, draw_ext_info(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO, NDI_UNIQUE, altar_valkyrie::pl, and show_commands().

Referenced by command_help().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ command_partial_commands()

static void command_partial_commands ( object op,
const char *  params 
)
static

Definition at line 83 of file commands.cpp.

References draw_ext_info_format(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO, NDI_UNIQUE, give::op, and roll-o-matic::params.

Referenced by commands_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ command_register()

command_registration command_register ( const char *  name,
uint8_t  type,
command_function  func,
float  time 
)

Register a player-issued command. The only cause of failure is trying to override an existing command with one having a different type.

Parameters
namecommand name.
typetype of the command, one of COMMAND_TYPE_xxx.
funcfunction to call for the command.
timehow long the command takes.
Returns
identifier to unregister the command, 0 if adding failed.

Definition at line 102 of file commands.cpp.

References do_register(), give::name, and is_valid_types_gen::type.

Referenced by cfapi_register_command().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ command_register_extra()

command_registration command_register_extra ( const char *  name,
const char *  extra,
uint8_t  type,
command_function_extra  func,
float  time 
)

Register a player-issued command with an extra parameter. This allow commands that need a supplemental fixed argument. The only cause of failure is trying to override an existing command with one having a different type.

Parameters
namecommand name.
extraextra data to give the command, must not be null.
typetype of the command, one of COMMAND_TYPE_xxx.
funcfunction to call for the command.
timehow long the command takes.
Returns
identifier to unregister the command, 0 if adding failed.

Definition at line 526 of file commands.cpp.

References do_register(), give::name, and is_valid_types_gen::type.

Referenced by cfapi_register_command().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ command_unregister()

void command_unregister ( command_registration  command)

Unregister a previously registered command.

Parameters
commandidentifier returned by command_register() or command_register_extra().

Definition at line 535 of file commands.cpp.

References devourers::command, and registered_commands.

Referenced by cfapi_unregister_command().

+ Here is the caller graph for this function:

◆ commands_clear()

void commands_clear ( )

Clear all registered commands.

Definition at line 346 of file commands.cpp.

References next_registration, and registered_commands.

Referenced by cleanup().

+ Here is the caller graph for this function:

◆ commands_init()

void commands_init ( void  )

Init standard commands.

Wizard commands.

Definition at line 109 of file commands.cpp.

References command_abil(), command_accountpasswd(), command_accuse(), command_addexp(), command_afk(), command_apply(), command_applymode(), command_arrest(), command_banish(), command_beg(), command_bleed(), command_blush(), command_body(), command_bounce(), command_bow(), command_bowmode(), command_brace(), command_burp(), command_cackle(), command_cast(), command_chat(), command_chuckle(), command_clap(), command_cointoss(), command_cough(), command_create(), command_cringe(), command_cry(), command_dance(), command_debug(), command_delete(), command_diff(), command_disarm(), command_dm(), command_dmhide(), command_dmtell(), command_drop(), command_dropall(), command_dump(), command_dumpabove(), command_dumpallarchetypes(), command_dumpallmaps(), command_dumpallobjects(), command_dumpbelow(), command_dumpfriendlyobjects(), command_dumpmap(), command_east(), command_empty(), command_examine(), command_face(), command_fire(), command_fire_stop(), command_fix_me(), command_flip(), command_follow(), command_forget_spell(), command_free(), command_freeze(), command_frown(), command_gasp(), command_giggle(), command_glare(), command_goto(), command_grin(), command_groan(), command_growl(), command_gsay(), command_help(), command_hiccup(), command_hide(), command_hiscore(), command_hug(), command_insert_into(), command_inventory(), command_invisible(), command_invoke(), command_kick(), command_kill_pets(), command_kiss(), command_knowledge(), command_language(), command_laugh(), command_learn_special_prayer(), command_learn_spell(), command_lick(), command_listen(), command_listplugins(), command_loadplugin(), command_loadtest(), command_lock_item(), command_malloc(), command_mapinfo(), command_maps(), command_mark(), command_me(), command_mon_aggr(), command_motd(), command_news(), command_nod(), command_north(), command_northeast(), command_northwest(), command_nowiz(), command_orcknuckle(), command_overlay_reset(), command_overlay_save(), command_partial_commands(), command_party(), command_party_rejoin(), command_passwd(), command_patch(), command_peaceful(), command_petmode(), command_pickup(), command_players(), command_poke(), command_pout(), command_printlos(), command_puke(), command_purge_quest(), command_purge_quest_definitions(), command_quest(), command_quit(), command_recollect(), command_remove(), command_rename_item(), command_reply(), command_reset(), command_resistances(), command_rotateshoottype(), command_rskill(), command_rules(), command_run(), command_run_stop(), command_save(), command_say(), command_scream(), command_search(), command_search_items(), command_setgod(), command_settings(), command_shake(), command_shiver(), command_shout(), command_showpets(), command_shrug(), command_shutdown(), command_sigh(), command_skills(), command_slap(), command_smile(), command_smirk(), command_snap(), command_sneeze(), command_snicker(), command_sniff(), command_snore(), command_sound(), command_south(), command_southeast(), command_southwest(), command_speed(), command_spit(), command_ssdumptable(), command_stack_clear(), command_stack_list(), command_stack_pop(), command_stack_push(), command_statistics(), command_stats(), command_stay(), command_strings(), command_strut(), command_style_map_info(), command_sulk(), command_summon(), command_swap(), command_take(), command_teleport(), command_tell(), command_thank(), command_think(), command_throw(), command_time(), command_title(), command_toggle_shout(), command_twiddle(), command_unarmed_skill(), command_unloadplugin(), command_use(), command_usekeys(), command_uskill(), command_version(), command_wave(), command_west(), command_whereabouts(), command_whereami(), command_whistle(), command_who(), command_wimpy(), command_wink(), command_wizcast(), command_wizpass(), command_yawn(), RC, RN, and RW.

Referenced by init().

+ Here is the caller graph for this function:

◆ do_register()

static command_registration do_register ( const char *  name,
uint8_t  type,
command_function  func_std,
command_function_extra  func_extra,
const char *  extra,
float  time 
)
static

Register a player-issued command. The only cause of failure is trying to override an existing command with one having a different type. If extra is null, then func_std must not be null, else func_extra must not be null.

Parameters
namecommand name.
typetype of the command, one of COMMAND_TYPE_xxx.
func_stdfunction to call for the command.
func_extrafunction to call for the command with an extra argument.
extraextra argument to give to func_extra.
timehow long the command takes.
Returns
identifier to unregister the command, 0 if adding failed.

Definition at line 59 of file commands.cpp.

References COMMAND_TYPE_NORMAL, COMMAND_TYPE_WIZARD, registered_command::extra, registered_command::func_extra, registered_command::func_std, give::name, next_registration, registered_commands, registered_command::registration, registered_command::time, is_valid_types_gen::type, and registered_command::type.

Referenced by command_register(), and command_register_extra().

+ Here is the caller graph for this function:

◆ show_commands()

static void show_commands ( object op,
uint8_t  type,
const char *  legend 
)
static

Helper function to display commands.

Parameters
opplayer asking for information.
typetype of commands to display.
legendbanner to print before the commands.

Definition at line 369 of file commands.cpp.

References draw_ext_info(), HUGE_BUF, is_valid_types_gen::line, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO, NDI_UNIQUE, give::op, registered_commands, and is_valid_types_gen::type.

Referenced by command_list().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ next_registration

command_registration next_registration = 1
static

Next identifier for a command registration.

Definition at line 43 of file commands.cpp.

Referenced by commands_clear(), and do_register().

◆ registered_commands

std::map<std::string, std::vector<registered_command *> > registered_commands
static

All registered commands, key is the name, vector is all registered handlers in registration order (last one is used).

Definition at line 45 of file commands.cpp.

Referenced by command_find(), command_unregister(), commands_clear(), do_register(), and show_commands().