y_commands.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**--------------------------------------------------------------------------**\
  2. ================================
  3. Y Sever Includes - Commands Core
  4. ================================
  5. Description:
  6. Runs commands registered with the system and calls the required functions.
  7. Also handles alternate names and prefixes. Based very loosely on dcmd.
  8. Legal:
  9. Version: MPL 1.1
  10. The contents of this file are subject to the Mozilla Public License Version
  11. 1.1 (the "License"); you may not use this file except in compliance with
  12. the License. You may obtain a copy of the License at
  13. http://www.mozilla.org/MPL/
  14. Software distributed under the License is distributed on an "AS IS" basis,
  15. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. for the specific language governing rights and limitations under the
  17. License.
  18. The Original Code is the YSI commands include.
  19. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  20. Portions created by the Initial Developer are Copyright (C) 2011
  21. the Initial Developer. All Rights Reserved.
  22. Contributors:
  23. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  24. Thanks:
  25. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  26. ZeeX - Very productive conversations.
  27. koolk - IsPlayerinAreaEx code.
  28. TheAlpha - Danish translation.
  29. breadfish - German translation.
  30. Fireburn - Dutch translation.
  31. yom - French translation.
  32. 50p - Polish translation.
  33. Zamaroht - Spanish translation.
  34. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  35. for me to strive to better.
  36. Pixels^ - Running XScripters where the idea was born.
  37. Matite - Pestering me to release it and using it.
  38. Very special thanks to:
  39. Thiadmer - PAWN, whose limits continue to amaze me!
  40. Kye/Kalcor - SA:MP.
  41. SA:MP Team past, present and future - SA:MP.
  42. Version:
  43. 0.1.4
  44. Changelog:
  45. 20/10/10:
  46. Fixed a bug with insensitive commands - my fault for not testing.
  47. 06/01/08:
  48. Improved master and /help support.
  49. 04/01/08:
  50. Fixed bad element in Command_SetDeniedReturn.
  51. 12/08/07:
  52. Added master support.
  53. 24/06/07:
  54. Modifed a few functions to use Bit_GetBit for speed.
  55. 04/05/07:
  56. Completed command use support.
  57. Added invalid character protection.
  58. 02/05/07:
  59. Added YSI_ prefix to all globals.
  60. 14/04/07:
  61. Updated header documentation with more than changelog/functions.
  62. Added function name requesting.
  63. 13/04/07:
  64. Added function documentation.
  65. Added wrapped functions for e_COMM_FLAG values missing them.
  66. Added header function list.
  67. 12/04/07:
  68. Added command removal.
  69. 11/04/07:
  70. Changed system slightly to handle names and alt names separately. Still
  71. need a better way of ignoring names when alt names are used.
  72. 10/04/07:
  73. First version.
  74. Functions:
  75. Public:
  76. Command_Add - Adds a command to the array for processing.
  77. Command_Remove - Removes a command.
  78. Command_Name - Gets the name of a command in a property.
  79. Core:
  80. Command_Process - Called from OnPlayerCommandText to process entered commands.
  81. Command_Parse - Sorts added commands into a binary tree.
  82. Command_Hash - Hashes a word for command hashing.
  83. Command_ProcRem - Processes a help command in the master script.
  84. Stock:
  85. Command_SetDisconnectReturn - Sets the return value for unconnected players.
  86. Command_UseShortCuts - Toggles use of per-player command shortcuts.
  87. Command_SetDeniedReturn - Sets the return value for denied use commands.
  88. Command_UseDeniedMessage - Toggles the use of an error message for denied.
  89. Command_SetIllegalReturn - Sets the return value for illegal characters.
  90. Command_UseAltNames - Toggles the use of ini defined alternate names.
  91. Command_UsePrefix - Toggles the use of a global prefix.
  92. Command_UseSpace - Toggles the use of a space between prefix and command.
  93. Command_SetAltName - Sets the alternate name of a function.
  94. Command_SetPrefix - Sets the pfexix to be typed.
  95. Comamnd_SetPlayerUse - Sets wether or not a player can use a command.
  96. Comamnd_SetPlayerUseByID - Sets wether or not a player can use a command.
  97. Command_FindByName - Finds a command in a possibly sorted list.
  98. Static:
  99. -
  100. Inline:
  101. -
  102. API:
  103. -
  104. Callbacks:
  105. -
  106. Definitions:
  107. MAX_COMMAND_LENGTH - The maximum length of a command string.
  108. COMMAND_NOT_FOUND - Indicates that a searched for string is not a function.
  109. Enums:
  110. e_COMM_FLAG - Bit mappings for command options.
  111. E_COMMANDS - Structure of the array holding the string data.
  112. Macros:
  113. Command_(%1) - Forwards and declares a standard command for calling.
  114. ycmd(%1) - Adds a command to the array (wrapper for Command_Add).
  115. Tags:
  116. e_COMM_FLAG - Flag type.
  117. Variables:
  118. Global:
  119. -
  120. Static:
  121. YSI_g_sCommands - Holds all the textual data of the commands.
  122. YSI_g_sSearchTree - Tree of hashes for function names.
  123. YSI_g_sAltTree - Tree of hashes for alternate names.
  124. YSI_g_sPrefix - The command prefix.
  125. YSI_g_sPrefixLength - Length of the prefix.
  126. YSI_g_sCommandIndex - Pointer to the next free index in the function array.
  127. YSI_g_sAltCount - The number of commands with altnames.
  128. YSI_g_sCommandFlags - Bit array of command options.
  129. Commands:
  130. commands - Lists all commands available to you.
  131. Compile options:
  132. COMMAND_SENSITIVE - Make commands case sensitive.
  133. COMMAND_ACCURATE - Can use '@' in command names.
  134. MAX_COMMANDS - The maximum number of commands which can be used.
  135. \**--------------------------------------------------------------------------**/
  136. #if defined _INC_y_commands
  137. #endinput
  138. #endif
  139. #define _INC_y_commands
  140. #include "..\YSI_Internal\y_version"
  141. #define MAX_COMMAND_LENGTH (32)
  142. #define COMMAND_NOT_FOUND (-1)
  143. #if !defined MAX_COMMANDS
  144. #define MAX_COMMANDS (512)
  145. #endif
  146. // Set commands as master 25.
  147. #define MASTER 63
  148. #define YSIM_U_DISABLE
  149. #include "..\YSI_Core\y_master"
  150. // Misc includes.
  151. #include "..\YSI_Storage\y_amx"
  152. #include "..\YSI_Coding\y_hooks"
  153. #include "..\YSI_Data\y_hashmap"
  154. #include "..\YSI_Data\y_iterate"
  155. #include "..\YSI_Data\y_playerarray"
  156. #include "..\YSI_Server\y_punycode"
  157. #include "..\YSI_Internal\y_distribute"
  158. // Include the group functions (maybe).
  159. #define _GROUP_MAKE_NAME<%0...%1> %0Command%1
  160. #define _GROUP_MAKE_LIMIT MAX_COMMANDS
  161. #include "..\YSI_Players\y_groups\_funcs"
  162. #if defined YSI_TESTS
  163. #if !defined Y_COMMANDS_NO_IPC
  164. #define Y_COMMANDS_NO_IPC
  165. #endif
  166. #endif
  167. // Include the main implementation.
  168. #include "y_commands/impl"
  169. #if defined YSI_TESTS
  170. #include "..\YSI_Core\y_testing"
  171. #include "y_commands/tests"
  172. #endif
  173. // Restore previous settings.
  174. #undef _GROUP_MAKE_LIMIT
  175. #undef _GROUP_MAKE_NAME
  176. #include "..\YSI_Core\y_master"