Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // cmd.h -- Command buffer and command execution
  4. // Any number of commands can be added in a frame, from several different sources.
  5. // Most commands come from either keybindings or console line input, but remote
  6. // servers can also send across commands and entire text files can be execed.
  7. //
  8. // The + command line options are also added to the command buffer.
  9. //
  10. // The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
  11. //
  12. // $NoKeywords: $
  13. //
  14. //===========================================================================//
  15. #ifndef CMD_H
  16. #define CMD_H
  17. #ifdef _WIN32
  18. #pragma once
  19. #endif
  20. //-----------------------------------------------------------------------------
  21. // Forward declarations
  22. //-----------------------------------------------------------------------------
  23. class CCommand;
  24. class ConCommandBase;
  25. #define MAX_EXECUTION_MARKERS 2048
  26. typedef enum
  27. {
  28. eCmdExecutionMarker_Enable_FCVAR_SERVER_CAN_EXECUTE='a',
  29. eCmdExecutionMarker_Disable_FCVAR_SERVER_CAN_EXECUTE='b',
  30. eCmdExecutionMarker_Enable_FCVAR_CLIENTCMD_CAN_EXECUTE='c',
  31. eCmdExecutionMarker_Disable_FCVAR_CLIENTCMD_CAN_EXECUTE='d'
  32. } ECmdExecutionMarker;
  33. //-----------------------------------------------------------------------------
  34. // Initialization, shutdown of the command buffer
  35. //-----------------------------------------------------------------------------
  36. void Cbuf_Init (void);
  37. void Cbuf_Shutdown( void );
  38. //-----------------------------------------------------------------------------
  39. // Clears the command buffer
  40. //-----------------------------------------------------------------------------
  41. void Cbuf_Clear(void);
  42. //-----------------------------------------------------------------------------
  43. // Escape an argument for a command. This *can* fail as many characters cannot
  44. // actually be passed through the old command syntax...
  45. //-----------------------------------------------------------------------------
  46. bool Cbuf_EscapeCommandArg( const char *pText, char *pOut, unsigned int nOut );
  47. //-----------------------------------------------------------------------------
  48. // as new commands are generated from the console or keybindings,
  49. // the text is added to the end of the command buffer.
  50. //-----------------------------------------------------------------------------
  51. void Cbuf_AddText (const char *text);
  52. //-----------------------------------------------------------------------------
  53. // when a command wants to issue other commands immediately, the text is
  54. // inserted at the beginning of the buffer, before any remaining unexecuted
  55. // commands.
  56. //-----------------------------------------------------------------------------
  57. void Cbuf_InsertText( const char *text );
  58. //-----------------------------------------------------------------------------
  59. // Surround a command with two execution markers. The operation is performed atomically.
  60. //
  61. // These allow you to create blocks in the command stream where certain rules apply.
  62. // ONLY use Cbuf_AddText in between execution markers. If you use Cbuf_InsertText,
  63. // it will put that stuff before the execution marker and the execution marker won't apply.
  64. //
  65. // cl_restrict_server_commands uses this. It inserts a marker that says, "don't run
  66. // anything unless it's marked with FCVAR_SERVER_CAN_EXECUTE", then inserts some commands,
  67. // then removes the execution marker. That way, ANYTIME Cbuf_Execute() is called,
  68. // it will apply the cl_restrict_server_commands rules correctly.
  69. //-----------------------------------------------------------------------------
  70. bool Cbuf_AddTextWithMarkers( ECmdExecutionMarker markerLeft, const char *text, ECmdExecutionMarker markerRight );
  71. // Returns whether or not the execution marker stack has room for N more.
  72. bool Cbuf_HasRoomForExecutionMarkers( int cExecutionMarkers );
  73. // Pulls off \n terminated lines of text from the command buffer and sends
  74. // them through Cmd_ExecuteString. Stops when the buffer is empty.
  75. // Normally called once per frame, but may be explicitly invoked.
  76. // Do not call inside a command function!
  77. //-----------------------------------------------------------------------------
  78. void Cbuf_Execute();
  79. //===========================================================================
  80. /*
  81. Command execution takes a null terminated string, breaks it into tokens,
  82. then searches for a command or variable that matches the first token.
  83. Commands can come from three sources, but the handler functions may choose
  84. to dissallow the action or forward it to a remote server if the source is
  85. not apropriate.
  86. */
  87. enum cmd_source_t
  88. {
  89. src_client, // came in over a net connection as a clc_stringcmd
  90. // host_client will be valid during this state.
  91. src_command // from the command buffer
  92. };
  93. // FIXME: Move these into a field of CCommand?
  94. extern cmd_source_t cmd_source;
  95. extern int cmd_clientslot;
  96. //-----------------------------------------------------------------------------
  97. // Initialization, shutdown
  98. //-----------------------------------------------------------------------------
  99. void Cmd_Init (void);
  100. void Cmd_Shutdown( void );
  101. //-----------------------------------------------------------------------------
  102. // Executes a command given a CCommand argument structure
  103. //-----------------------------------------------------------------------------
  104. const ConCommandBase *Cmd_ExecuteCommand( const CCommand &command, cmd_source_t src, int nClientSlot = -1 );
  105. //-----------------------------------------------------------------------------
  106. // Dispatches a command with the requested arguments
  107. //-----------------------------------------------------------------------------
  108. void Cmd_Dispatch( const ConCommandBase *pCommand, const CCommand &args );
  109. //-----------------------------------------------------------------------------
  110. // adds the current command line as a clc_stringcmd to the client message.
  111. // things like godmode, noclip, etc, are commands directed to the server,
  112. // so when they are typed in at the console, they will need to be forwarded.
  113. // If bReliable is true, it goes into cls.netchan.message.
  114. // If bReliable is false, it goes into cls.datagram.
  115. //-----------------------------------------------------------------------------
  116. void Cmd_ForwardToServer( const CCommand &args, bool bReliable = true );
  117. // This is a list of cvars that are in the client DLL that we want FCVAR_CLIENTCMD_CAN_EXECUTE set on.
  118. // In order to avoid patching the client DLL, we setup this list. Whenever the client DLL has gone out with the
  119. // FCVAR_CLIENTCMD_CAN_EXECUTE flag set, we can get rid of this list.
  120. void Cmd_AddClientCmdCanExecuteVar( const char *pName );
  121. // Used to allow cheats even if cheats aren't theoretically allowed
  122. void Cmd_SetRptActive( bool bActive );
  123. bool Cmd_IsRptActive();
  124. #endif // CMD_H