Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. static void ProcessCommand(cell playerid, const char *cmdtext) {
  2. if (
  3. !cmdtext
  4. || cmdtext[0] != '/'
  5. ) {
  6. return;
  7. }
  8. _logprintf("1: ");
  9. char cmd[32]{};
  10. const char *params{};
  11.  
  12. int i = 1;
  13. while (cmdtext[i] == ' ') {
  14. i++;
  15. } // remove extra spaces before cmd name
  16. params = &cmdtext[i];
  17. _logprintf("2: ");
  18. i = 0;
  19.  
  20. char symbol{};
  21. while (
  22. (symbol = params[i])
  23. && symbol != ' '
  24. ) {
  25. if (i >= sizeof(cmd)) {
  26. return;
  27. }
  28.  
  29. cmd[i++] = std::tolower(symbol, _locale);
  30. }
  31. _logprintf("3: ");
  32. while (params[i] == ' ') {
  33. i++;
  34. } // remove extra spaces before params
  35. _logprintf("4: ");
  36. params = &params[i];
  37.  
  38. CommandMap::const_iterator iter_cmd{};
  39. cell addr_cmdtext{}, addr_cmd_name{}, addr_params{}, retval{}, flags{};
  40. bool command_exists{};
  41. _logprintf("4: ");
  42. for (const auto &script : _scripts) {
  43. if (script.opct_addr) {
  44. amx_PushString(script.amx, &addr_cmdtext, nullptr, cmdtext, 0, 0);
  45. amx_Push(script.amx, playerid);
  46. ExecAmxPublic(script.amx, &retval, script.opct_addr);
  47. amx_Release(script.amx, addr_cmdtext);
  48.  
  49. if (retval == 1) {
  50. break;
  51. }
  52. }
  53.  
  54. if (command_exists = ((iter_cmd = script.cmds.find(cmd)) != script.cmds.end())) {
  55. flags = iter_cmd->second.flags;
  56. }
  57.  
  58. if (script.opcr_addr) {
  59. amx_Push(script.amx, flags);
  60. amx_PushString(script.amx, &addr_params, nullptr, params, 0, 0);
  61. amx_PushString(script.amx, &addr_cmd_name, nullptr, cmd, 0, 0);
  62. amx_Push(script.amx, playerid);
  63. ExecAmxPublic(script.amx, &retval, script.opcr_addr);
  64. amx_Release(script.amx, addr_cmd_name);
  65. amx_Release(script.amx, addr_params);
  66.  
  67. if (!retval) {
  68. continue;
  69. }
  70. }
  71.  
  72. if (command_exists) {
  73. amx_PushString(script.amx, &addr_params, nullptr, params, 0, 0);
  74. amx_Push(script.amx, playerid);
  75. ExecAmxPublic(script.amx, &retval, iter_cmd->second.addr);
  76. amx_Release(script.amx, addr_params);
  77. } else {
  78. retval = -1;
  79. }
  80.  
  81. if (script.opcp_addr) {
  82. amx_Push(script.amx, flags);
  83. amx_Push(script.amx, retval);
  84. amx_PushString(script.amx, &addr_params, nullptr, params, 0, 0);
  85. amx_PushString(script.amx, &addr_cmd_name, nullptr, cmd, 0, 0);
  86. amx_Push(script.amx, playerid);
  87. ExecAmxPublic(script.amx, &retval, script.opcp_addr);
  88. amx_Release(script.amx, addr_cmd_name);
  89. amx_Release(script.amx, addr_params);
  90. }
  91.  
  92. if (retval == 1) {
  93. break;
  94. }
  95. }
  96. _logprintf("5: ");
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement