Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include the main header.
- #include <a_samp>
- #define _ALS_OnPlayerCommandText
- // Include the YSI headers.
- //#define _DEBUG 5
- #define OnPlayerCommandText ycmd_OPCT
- forward ycmd_OPCT(playerid, cmdtext[]);
- #include <YSI\y_commands>
- #include <YSI\y_master>
- #undef OnPlayerCommandText
- // Undefine the macros used by both YSI and zcmd.
- #undef CMD
- #undef COMMAND
- // Include the zcmd headers.
- #define OnPlayerCommandText zcmd_OPCT
- forward zcmd_OPCT(playerid, cmdtext[]);
- #include <zcmd>
- #undef OnPlayerCommandText
- // Include the mcmd headers.
- #include <mcmd>
- // Define dcmd.
- #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- // Define the enum for all commands.
- enum E_COMM_PERM
- {
- // Command permissions super macro.
- #define COMM(%0) E_COMM_%0,
- #include "cmdcmp_macro1"
- #include "cmdcmp_macro2"
- E_COMM_zzz,
- _E_COMM_END
- }
- // Permissions for playes to use a command.
- new
- BitArray:g_perm[E_COMM_PERM]<MAX_PLAYERS>;
- // Define the commands for zcmd. Include permission checks as ycmd has it in-
- // built, so the others need it explicitly to match.
- #define COMM(%0) CMD:%0(playerid,params[]){if(Bit_Get(g_perm[E_COMM_%0], playerid))return 1;return 0;}
- #include "cmdcmp_macro1"
- #include "cmdcmp_macro2"
- CMD:zzz(playerid, params[])
- {
- if(Bit_Get(g_perm[E_COMM_zzz], playerid))
- {
- //printf("zcmd zzz called");
- return 1;
- }
- return 0;
- }
- // Define the commands for ycmd. This has internal permission checks so we
- // don't need to include anything in the command itself.
- #define COMM(%0) YCMD:%0(playerid,params[],help){return 1;}
- #include "cmdcmp_macro1"
- #include "cmdcmp_macro2"
- YCMD:zzz(playerid, params[], help)
- {
- //printf("ycmd zzz called");
- }
- // Define the commands for dcmd.
- #define COMM(%0) dcmd_%0(playerid,params[]){if(Bit_Get(g_perm[E_COMM_%0], playerid))return 1;return 0;}
- #include "cmdcmp_macro1"
- #include "cmdcmp_macro2"
- dcmd_zzz(playerid, params[])
- {
- if(Bit_Get(g_perm[E_COMM_zzz], playerid))
- {
- //printf("dcmd zzz called");
- return 1;
- }
- return 0;
- }
- // Define the commands for mcmd. Because this differentiates between commands
- // with parameters and commands with none we need to do two sets.
- #define COMM(%0) mcmd_%0(playerid,params[]){if(Bit_Get(g_perm[E_COMM_%0], playerid))return 1;return 0;}
- #include "cmdcmp_macro1"
- #undef COMM
- #define COMM(%0) mcmd_%0(playerid){if(Bit_Get(g_perm[E_COMM_%0], playerid))return 1;return 0;}
- #include "cmdcmp_macro2"
- mcmd_zzz(playerid)
- {
- if(Bit_Get(g_perm[E_COMM_zzz], playerid))
- {
- //printf("mcmd zzz called");
- return 1;
- }
- return 0;
- }
- // dcmd
- dcmd_OPCT(playerid, cmdtext[])
- {
- #define COMM(%0) dcmd(%0,3,cmdtext);
- #include "cmdcmp_macro1"
- #include "cmdcmp_macro2"
- dcmd(zzz, 3, cmdtext);
- return 0;
- }
- // mcmd
- mcmd_OPCT(playerid, cmdtext[])
- {
- mcmd_init(cmdtext);
- #define COMM(%0) mcmd(%0,cmdtext,3,playerid);
- #include "cmdcmp_macro1"
- #undef COMM
- #define COMM(%0) mcmd2(%0,cmdtext,playerid);
- #include "cmdcmp_macro2"
- mcmd2(zzz, cmdtext, playerid);
- return 0;
- }
- // strcmp
- strcmp_OPCT(playerid, cmdtext[])
- {
- #define COMM(%0) if (!strcmp(#%0,cmdtext[1],true,3)){if(Bit_Get(g_perm[E_COMM_%0], playerid))return 1;return 0;}
- #include "cmdcmp_macro1"
- #include "cmdcmp_macro2"
- if (!strcmp("zzz", cmdtext[1], true, 3))
- {
- if(Bit_Get(g_perm[E_COMM_zzz], playerid))
- {
- //printf("strcmp zzz called");
- return 1;
- }
- return 0;
- }
- return 0;
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- // strtok
- strtok_OPCT(playerid, cmdtext[])
- {
- new
- idx,
- cmd[128];
- cmd = strtok(cmdtext, idx);
- #define COMM(%0) if (!strcmp("/"#%0,cmd,true,4)){if(Bit_Get(g_perm[E_COMM_%0], playerid))return 1;return 0;}
- #include "cmdcmp_macro1"
- #include "cmdcmp_macro2"
- if (!strcmp("/zzz", cmd, true, 4))
- {
- if(Bit_Get(g_perm[E_COMM_zzz], playerid))
- {
- //printf("strtok zzz called");
- return 1;
- }
- return 0;
- }
- return 0;
- }
- main()
- {
- printf("================================");
- printf(" Command processor comparisons.");
- printf("================================");
- // Disable all ycmd commands by default.
- for (new E_COMM_PERM:i; i != _E_COMM_END; ++i)
- {
- Command_SetPlayer(i, 0, false);
- Command_SetPlayer(i, 499, false);
- }
- Tests();
- // Now enable all the commands and rerun the tests.
- for (new E_COMM_PERM:i; i != _E_COMM_END; ++i)
- {
- // ycmd.
- Command_SetPlayer(i, 0, true);
- Command_SetPlayer(i, 499, true);
- // All others.
- Bit_Set(g_perm[i], 0, true);
- Bit_Set(g_perm[i], 499, true);
- }
- Tests();
- /*mcmd_OPCT(0, "/aaa hello");
- mcmd_OPCT(0, "/azz hello");
- mcmd_OPCT(0, "/zzz hello");
- mcmd_OPCT(0, "/zzz");*/
- return 0;
- }
- Tests()
- {
- new
- t0a,
- t0b,
- t1a,
- t1b,
- t2a,
- t2b,
- t3a,
- t3b,
- t4a,
- t4b,
- t5a,
- t5b;
- // Call the ycmd command versions.
- printf("ycmd:");
- // Enable the command for this player so it gets called correctly.
- ycmd_OPCT(0, "/zzz");
- ycmd_OPCT(0, "/zzzz");
- ycmd_OPCT(0, "/zzz ");
- t0a = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- ycmd_OPCT(0, "/aaa hello");
- ycmd_OPCT(499, "/anz hello");
- ycmd_OPCT(0, "/amz");
- ycmd_OPCT(499, "/azz");
- }
- t0b = GetTickCount();
- // Call the zcmd command versions.
- printf("zcmd:");
- zcmd_OPCT(0, "/zzz");
- zcmd_OPCT(0, "/zzzz");
- zcmd_OPCT(0, "/zzz ");
- t1a = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- zcmd_OPCT(0, "/aaa hello");
- zcmd_OPCT(499, "/anz hello");
- zcmd_OPCT(0, "/amz");
- zcmd_OPCT(499, "/azz");
- }
- t1b = GetTickCount();
- // Call the dcmd command versions.
- printf("dcmd:");
- dcmd_OPCT(0, "/zzz");
- dcmd_OPCT(0, "/zzzz");
- dcmd_OPCT(0, "/zzz ");
- t2a = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- dcmd_OPCT(0, "/aaa hello");
- dcmd_OPCT(499, "/anz hello");
- dcmd_OPCT(0, "/amz");
- dcmd_OPCT(499, "/azz");
- }
- t2b = GetTickCount();
- // Call the mcmd command versions.
- printf("mcmd:");
- mcmd_OPCT(0, "/zzz");
- mcmd_OPCT(0, "/zzzz");
- mcmd_OPCT(0, "/zzz ");
- t3a = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- mcmd_OPCT(0, "/aaa hello");
- mcmd_OPCT(499, "/anz hello");
- mcmd_OPCT(0, "/amz");
- mcmd_OPCT(499, "/azz");
- }
- t3b = GetTickCount();
- // Call the strcmp command versions.
- printf("strcmp:");
- strcmp_OPCT(0, "/zzz");
- strcmp_OPCT(0, "/zzzz");
- strcmp_OPCT(0, "/zzz ");
- t4a = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- strcmp_OPCT(0, "/aaa hello");
- strcmp_OPCT(499, "/anz hello");
- strcmp_OPCT(0, "/amz");
- strcmp_OPCT(499, "/azz");
- }
- t4b = GetTickCount();
- // Call the strtok command versions.
- printf("strtok:");
- strtok_OPCT(0, "/zzz");
- strtok_OPCT(0, "/zzzz");
- strtok_OPCT(0, "/zzz ");
- t5a = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- strtok_OPCT(0, "/aaa hello");
- strtok_OPCT(499, "/anz hello");
- strtok_OPCT(0, "/amz");
- strtok_OPCT(499, "/azz");
- }
- t5b = GetTickCount();
- printf("Results:");
- printf(" ycmd: %d", t0b - t0a);
- printf(" zcmd: %d", t1b - t1a);
- printf(" dcmd: %d", t2b - t2a);
- printf(" mcmd: %d", t3b - t3a);
- printf("strcmp: %d", t4b - t4a);
- printf("strtok: %d", t5b - t5a);
- return 0;
- }
Add Comment
Please, Sign In to add comment