Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define COMMAND_PROCESS_RETURN%0; return ret = %0, cmdtext[length] = ch, ret;
- static stock Command_Process(playerid, cmdtext[], help)
- {
- P:4("Command_Process FS called: %i, \"%s\", %i", playerid, cmdtext, help);
- // Support for very old problems!
- // TODO: Add back.
- P:2("Command_Process called: %d %s", playerid, cmdtext);
- /*#if !_DEBUG && !defined _YSI_SPECIAL_DEBUG
- // For testing purposes.
- if (!IsPlayerConnected(playerid))
- {
- return Command_DisconnectReturn();
- }
- #endif*/
- P:4("Command_Process: Connected");
- new
- ret,
- ch,
- idx,
- length,
- //prelen = help ? 0 : 1,
- index = help ? 0 : 1; //prelen;
- /*// Shortcuts.
- if (cmdtext[2] <= ' ')
- {
- // Get a player's shortcut information for this letter.
- }
- else*/
- {
- // No more faffing about with random alternate code - it's all done in
- // one nice function instead of having to handle both separately.
- new
- prelen = index, //help ? 0 : 1,
- hash = Command_Hash(cmdtext, index, length);
- P:2("Command_Process: Hash = %d, Length = %d", hash, length);
- // NOTE: No prefix support here.
- //length += prelen;
- ch = cmdtext[length += prelen];
- cmdtext[length] = '\0';
- //ch = cmdtext[length];
- #if YSIM_HAS_MASTER
- ret = YSI_g_sPlayerProvider{playerid};
- P:2("Command_Process: Provider: %d", ret);
- idx = Command_FindFast(cmdtext[prelen], hash, ret);
- if (idx == COMMAND_NOT_FOUND && ret != 0xFF)
- {
- // Check default commands if no specialised commands were found.
- idx = Command_FindFast(cmdtext[prelen], hash);
- }
- #else
- idx = Command_FindFast(cmdtext[prelen], hash);
- #endif
- // TODO: Replace!
- //idx = Command_FindSlow(cmdtext[prelen]);//, hash);
- //prelen += length;
- }
- P:2("Command_Process: Index = %d", idx);
- if (idx != COMMAND_NOT_FOUND)
- {
- // Get the master data for the underlying command, not the possibly
- // changed name.
- new
- pointer = Command_GetPointer(idx);
- P:4("Command_Process: Found %d, %d", idx, pointer);
- // Found a command with this name - check the permissions.
- //if (Bit_Get(YSI_g_sCommands[idx][E_COMMANDS_PLAYERS], playerid))
- if (Command_CheckPlayer(idx, playerid))
- {
- P:4("Command_Process: Allowed");
- // Allowed to use the command, get the real function. Note that
- // this may well be the same as "idx", but we loose no time.
- #if YSIM_HAS_MASTER
- P:4("Command_Process: %08x%08x%08x%08x", YSI_g_sCommands[idx][E_COMMANDS_FUNCTION][0], YSI_g_sCommands[idx][E_COMMANDS_FUNCTION][1], YSI_g_sCommands[idx][E_COMMANDS_FUNCTION][2], YSI_g_sCommands[idx][E_COMMANDS_FUNCTION][3]);
- //if (master & 1 << YSI_g_sMaster23)
- //{
- // master = YSI_g_sMaster23;
- //}
- //else
- //{
- new
- script = Command_Provider(idx);
- if (script == 0xFF)
- {
- script = YSI_g_sCommands[pointer][E_COMMANDS_MASTERS];
- if (!script)
- {
- // No scripts can serve the code.
- COMMAND_PROCESS_RETURN Command_UnknownReturn();
- }
- // Find the lowest set bit. We use this to broadcastfunc the
- // command. If it uses MASTER 23, this will select only
- // one script to use. If it doesn't use MASTER 23, this is
- // ignored as a parameter and _YCM is used instead.
- static const
- scDeBruijn[] =
- {
- 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
- 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
- };
- // http://supertech.csail.mit.edu/papers/debruijn.pdf
- script = scDeBruijn[((script & -script) * 0x077CB531) >>> 27];
- }
- //}
- P:2("Command_Process: script = %d", script);
- //if (master == _@)
- //{
- /*#endif
- // This script has it!
- addr = YSI_g_sCommands[pointer][E_COMMANDS_AMX_ADDRESS];
- P:4("Command_Process: %04x%04x", addr >>> 16, addr & 0xFFFF);
- // Make sure all the "#emits" are together as they don't
- // seem to be affected by pre-processor directives.
- #emit PUSH.S master
- #emit PUSH.S help
- #emit LOAD.S.alt cmdtext
- #emit LOAD.S.pri index
- #emit SMUL.C 4
- #emit ADD
- #emit PUSH.pri
- #emit PUSH.S playerid
- #emit PUSH.C 16
- #emit LCTRL 6
- #emit ADD.C 28
- #emit PUSH.pri
- #emit LOAD.S.pri addr
- #emit SCTRL 6
- #emit STOR.S.pri addr
- #if YSIM_HAS_MASTER*/
- //}
- //else
- //{
- #pragma tabsize 4
- P:2("Command_Process: call %s (%d, %d)", unpack(Command_GetFuncName(pointer)), pointer, script);
- if (cmdtext[index])
- {
- // Call it!
- Command_CallR(pointer, cmdtext[index]);
- }
- else
- {
- Command_CallR(pointer, NULL);
- }
- #pragma tabsize 4
- //}
- // Get the real return.
- P:1("Command_Process: return: %d", getproperty(8, YSIM_RETURN));
- COMMAND_PROCESS_RETURN getproperty(8, YSIM_RETURN);
- #else
- if (cmdtext[index])
- {
- // Call it!
- COMMAND_PROCESS_RETURN Command_CallL(pointer, cmdtext[index]);
- }
- else
- {
- COMMAND_PROCESS_RETURN Command_CallL(pointer, NULL);
- }
- //return addr;
- #endif
- }
- else
- {
- COMMAND_PROCESS_RETURN Command_DeniedReturn();
- }
- }
- P:5("Command_Process: Not found");
- COMMAND_PROCESS_RETURN Command_UnknownReturn();
- }
- #undef COMMAND_PROCESS_RETURN
Advertisement
Add Comment
Please, Sign In to add comment