Y_Less

Command_Process

Jul 3rd, 2012
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.25 KB | None | 0 0
  1. #define COMMAND_PROCESS_RETURN%0; return ret = %0, cmdtext[length] = ch, ret;
  2.  
  3. static stock Command_Process(playerid, cmdtext[], help)
  4. {
  5.     P:4("Command_Process FS called: %i, \"%s\", %i", playerid, cmdtext, help);
  6.     // Support for very old problems!
  7.     // TODO: Add back.
  8.     P:2("Command_Process called: %d %s", playerid, cmdtext);
  9.     /*#if !_DEBUG && !defined _YSI_SPECIAL_DEBUG
  10.         // For testing purposes.
  11.         if (!IsPlayerConnected(playerid))
  12.         {
  13.             return Command_DisconnectReturn();
  14.         }
  15.     #endif*/
  16.     P:4("Command_Process: Connected");
  17.     new
  18.         ret,
  19.         ch,
  20.         idx,
  21.         length,
  22.         //prelen = help ? 0 : 1,
  23.         index = help ? 0 : 1; //prelen;
  24.     /*// Shortcuts.
  25.     if (cmdtext[2] <= ' ')
  26.     {
  27.         // Get a player's shortcut information for this letter.
  28.     }
  29.     else*/
  30.     {
  31.         // No more faffing about with random alternate code - it's all done in
  32.         // one nice function instead of having to handle both separately.
  33.         new
  34.             prelen = index, //help ? 0 : 1,
  35.             hash = Command_Hash(cmdtext, index, length);
  36.         P:2("Command_Process: Hash = %d, Length = %d", hash, length);
  37.         // NOTE: No prefix support here.
  38.         //length += prelen;
  39.         ch = cmdtext[length += prelen];
  40.         cmdtext[length] = '\0';
  41.         //ch = cmdtext[length];
  42.         #if YSIM_HAS_MASTER
  43.             ret = YSI_g_sPlayerProvider{playerid};
  44.             P:2("Command_Process: Provider: %d", ret);
  45.             idx = Command_FindFast(cmdtext[prelen], hash, ret);
  46.             if (idx == COMMAND_NOT_FOUND && ret != 0xFF)
  47.             {
  48.                 // Check default commands if no specialised commands were found.
  49.                 idx = Command_FindFast(cmdtext[prelen], hash);
  50.             }
  51.         #else
  52.             idx = Command_FindFast(cmdtext[prelen], hash);
  53.         #endif
  54.         // TODO: Replace!
  55.         //idx = Command_FindSlow(cmdtext[prelen]);//, hash);
  56.         //prelen += length;
  57.     }
  58.     P:2("Command_Process: Index = %d", idx);
  59.     if (idx != COMMAND_NOT_FOUND)
  60.     {
  61.         // Get the master data for the underlying command, not the possibly
  62.         // changed name.
  63.         new
  64.             pointer = Command_GetPointer(idx);
  65.         P:4("Command_Process: Found %d, %d", idx, pointer);
  66.         // Found a command with this name - check the permissions.
  67.         //if (Bit_Get(YSI_g_sCommands[idx][E_COMMANDS_PLAYERS], playerid))
  68.         if (Command_CheckPlayer(idx, playerid))
  69.         {
  70.             P:4("Command_Process: Allowed");
  71.             // Allowed to use the command, get the real function.  Note that
  72.             // this may well be the same as "idx", but we loose no time.
  73.             #if YSIM_HAS_MASTER
  74.                 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]);
  75.                 //if (master & 1 << YSI_g_sMaster23)
  76.                 //{
  77.                 //  master = YSI_g_sMaster23;
  78.                 //}
  79.                 //else
  80.                 //{
  81.                 new
  82.                     script = Command_Provider(idx);
  83.                 if (script == 0xFF)
  84.                 {
  85.                     script = YSI_g_sCommands[pointer][E_COMMANDS_MASTERS];
  86.                     if (!script)
  87.                     {
  88.                         // No scripts can serve the code.
  89.                         COMMAND_PROCESS_RETURN Command_UnknownReturn();
  90.                     }
  91.                     // Find the lowest set bit.  We use this to broadcastfunc the
  92.                     // command.  If it uses MASTER 23, this will select only
  93.                     // one script to use.  If it doesn't use MASTER 23, this is
  94.                     // ignored as a parameter and _YCM is used instead.
  95.                     static const
  96.                         scDeBruijn[] =
  97.                             {
  98.                                 0,  1,  28, 2,  29, 14, 24, 3,  30, 22, 20, 15, 25, 17, 4,  8,
  99.                                 31, 27, 13, 23, 21, 19, 16, 7,  26, 12, 18, 6,  11, 5,  10, 9
  100.                             };
  101.                     // http://supertech.csail.mit.edu/papers/debruijn.pdf
  102.                     script = scDeBruijn[((script & -script) * 0x077CB531) >>> 27];
  103.                 }
  104.                 //}
  105.                 P:2("Command_Process: script = %d", script);
  106.                 //if (master == _@)
  107.                 //{
  108.             /*#endif
  109.                     // This script has it!
  110.                     addr = YSI_g_sCommands[pointer][E_COMMANDS_AMX_ADDRESS];
  111.                     P:4("Command_Process: %04x%04x", addr >>> 16, addr & 0xFFFF);
  112.                     // Make sure all the "#emits" are together as they don't
  113.                     // seem to be affected by pre-processor directives.
  114.                     #emit PUSH.S     master
  115.                     #emit PUSH.S     help
  116.                     #emit LOAD.S.alt cmdtext
  117.                     #emit LOAD.S.pri index
  118.                     #emit SMUL.C     4
  119.                     #emit ADD
  120.                     #emit PUSH.pri
  121.                     #emit PUSH.S     playerid
  122.                     #emit PUSH.C     16
  123.                     #emit LCTRL      6
  124.                     #emit ADD.C      28
  125.                     #emit PUSH.pri
  126.                     #emit LOAD.S.pri addr
  127.                     #emit SCTRL      6
  128.                     #emit STOR.S.pri addr
  129.             #if YSIM_HAS_MASTER*/
  130.                 //}
  131.                 //else
  132.                 //{
  133.                     #pragma tabsize 4
  134.                     P:2("Command_Process: call %s (%d, %d)", unpack(Command_GetFuncName(pointer)), pointer, script);
  135.                     if (cmdtext[index])
  136.                     {
  137.                         // Call it!
  138.                         Command_CallR(pointer, cmdtext[index]);
  139.                     }
  140.                     else
  141.                     {
  142.                         Command_CallR(pointer, NULL);
  143.                     }
  144.                     #pragma tabsize 4
  145.                 //}
  146.                 // Get the real return.
  147.                 P:1("Command_Process: return: %d", getproperty(8, YSIM_RETURN));
  148.                 COMMAND_PROCESS_RETURN getproperty(8, YSIM_RETURN);
  149.             #else
  150.                 if (cmdtext[index])
  151.                 {
  152.                     // Call it!
  153.                     COMMAND_PROCESS_RETURN Command_CallL(pointer, cmdtext[index]);
  154.                 }
  155.                 else
  156.                 {
  157.                     COMMAND_PROCESS_RETURN Command_CallL(pointer, NULL);
  158.                 }
  159.                 //return addr;
  160.             #endif
  161.         }
  162.         else
  163.         {
  164.             COMMAND_PROCESS_RETURN Command_DeniedReturn();
  165.         }
  166.     }
  167.     P:5("Command_Process: Not found");
  168.     COMMAND_PROCESS_RETURN Command_UnknownReturn();
  169. }
  170.  
  171. #undef COMMAND_PROCESS_RETURN
Advertisement
Add Comment
Please, Sign In to add comment