1
0

card.h 2.4 KB

12345678910111213141516171819202122232425262728293031
  1. ign Command_ReProcess(p,string:c[],h);
  2. global Command_ReProcess(playerid,string:cmdName[],help)
  3. {
  4. static sCmd[64] = "@yC_", sPos, sReturn, sHash, e_COMMAND_ERRORS:sErr;
  5. // Check that the input is a valid command. Note that changing the command prefix here would be VERY trivial!
  6. if ((sReturn = _:_Command_IsPrefix(cmdName[0])) && !cmdName[1]) return Command_OnReceived(INVALID_INPUT, playerid, cmdName);
  7. else if (isnull(cmdName)) return Command_OnReceived(INVALID_INPUT, playerid, NULL);
  8. #if !defined Y_COMMANDS_NO_IPC // Check for a valid player when debugging is disabled
  9. if (!IsPlayerConnected(playerid)) return Command_OnReceived(NO_PLAYER, playerid, cmdName);
  10. if (PA_Get(YSI_g_sDisabledPlayers, playerid)) return Command_OnReceived(DISABLED, playerid, cmdName);
  11. playerid:1("Commands_OnPlayerCommandText called: %d %s", playerid, cmdName);
  12. new prevID = YSI_g_sCurrentID; // To add "next" to the intrusive linked list.
  13. // Get the hashed version of the decoded string, skipping the possible "/".
  14. sPos = Puny_EncodeHash(sCmd[4], cmdName[sReturn], sHash, .delimiter = '@') + sReturn;
  15. while (cmdName[sPos] == ' ') ++sPos; // Better/slower: ('\0' < cmdName[sPos] <= ' ').
  16. YSI_g_sCurrentID = HashMap_GetWithHash(YSI_g_sCommandMap, sCmd[4], sHash);
  17. playerid:5("Commands_OnPlayerCommandText: %s, %d, %d, %d", sCmd[4], sPos, sHash, YSI_g_sCurrentID);
  18. if (YSI_g_sCurrentID == COMMAND_NOT_FOUND) return YSI_g_sCurrentID = prevID, Command_OnReceived(UNDEFINED, playerid, cmdName);
  19. #if defined Y_COMMANDS_USE_CHARS // Not everything starts with '/', some are custom.
  20. // Have a prefix, but not the right one despite calling this function directly
  21. if (sReturn && _Command_GetPrefix(YSI_g_sCurrentID) != cmdName[0]) return Command_OnReceived(BAD_PREFIX, playerid, cmdName);
  22. playerid:5("Commands_OnPlayerCommandText: Use %d", _Command_GetPlayer(YSI_g_sCurrentID, playerid));
  23. if (_Command_GetPlayer(YSI_g_sCurrentID, playerid)) { // Can the player use this command?
  24. if (!Command_OnReceived(OK, playerid, cmdName)) return YSI_g_sCurrentID = prevID, 0;
  25. _Command_GetReal(sHash, YSI_g_sCurrentID, sCmd[4]); // Find the true version of the command (alts etc).
  26. P:5("Commands_OnPlayerCommandText: Read %d", YSI_g_sCurrentID);
  27. P:5("Commands_OnPlayerCommandText: Master %d %d", Master_ID(), _:MASTER_GET<YSI_g_sCurrentID>);
  28. #if YSIM_HAS_MASTER
  29. if (MASTER_EXCLUSIVE<YSI_g_sCurrentID>)
  30. #endif