[Plugin] mcmd Command Engine - Plugin based command processing
#1

mcmd - beta 0.0.1

This is the latest project I have been working on. mcmd, the first command processor which a) completely overwrites the default SA-MP command system and b) processes commands without PAWN interaction to pass OnPlayerCommandText parameters to the plugin. Even tho of it's memory hacking, it was designed to work with any version of the 0.3 branch.

Defining commands
To create commands, simply go to any location in your code and using following syntax. Commands are processed in lower case meaning /HellO is the same as /HELLo or /hello.
pawn Код:
mcmd:examplecommand(playerid, params[])
{
     return 1;
}
Handling user input
To control any player input before the actual command gets executed, this callback is being called in the gamemode.
playeridThe id of the player who requested the command.
cmdtext[]The full command string including slash and parameters.
exists1 = command was found in the script, 0 = command not found
pawn Код:
forward OnPlayerRequestCommand(playerid, cmdtext[], exists);
Returning 0 stops any further processing of this command request, returning 1 calls the command as long as it exists. So giving the player an error if the command doesn't exist would be:
pawn Код:
public OnPlayerRequestCommand(playerid, cmdtext[], exists)
{
     if(!exists)
     {
          SendClientMessage(playerid, 0xFFFFFFFF, "This command does not exist!");
          return 0;
     }
     return 1;
}
Anti spam
mcmd provides an inbuild function to control command spam.
pawn Код:
native GetPlayerLastRequestTime(playerid);
This function returns the passed time since the last command request of a specific player. In other words, the time since the player sent a command to the server in seconds (Will be milliseconds in future releases). To prevent command spam, you can restrict the player under OnPlayerRequestCommand. Exmaple:
pawn Код:
public OnPlayerRequestCommand(playerid, cmdtext[], exists)
{
     if(GetPlayerLastRequestTime(playerid) < 1)
     {
          SendClientMessage(playerid, 0xFFFFFFFF, "You may only use 1 command per second!");
          return 0; // Do not call the command
     }

     if(!exists)
     {
          SendClientMessage(playerid, 0xFFFFFFFF, "This command does not exist!");
          return 0;
     }
     return 1;
}
How it works
Here are the assembly instructions from the SA-MP 0.3z R2-2 server where it calls OnPlayerCommandText.
http://i.imgur.com/veUXSa2.png
mcmd erases everything from 0x46AA17 to 0x46AA85 and places a JMP to the internal function engine_opct_hook. cmdtext is located in register ebx and playerid in ebp, these are being pushed onto the stack and engine_command_detour is being called.

Linux:
http://urlremoved/SAMP/mcmd/opct.txt
The return locations differ (See engine.c for more information). cmdtext is located at EBP-0x14, playerid at EBP+0xC.

Speed
I did not create this plugin to make a faster version of y_commands or any other cmd processor. It was more like out of fun since I do find reverse engineering really interesting. I had this idea in mind for a long time but wasn't able to accomplish it until recently. Anyways, here is the speedtest I did in the early phase of the plugin. To test mcmd I've created an additional native function to call the internal engine_command_detour.
Quote:

Defaults:
100000 iterations
+2700 commands in the gamemode
custom callbacks enabled
3 cmd calls per iteration:
(0, "/first testparams yes")
(0, "/last testparams yes")
(0, "/none testparams yes")

Results:
mcmd: 199 ms
zcmd: 626 ms + internal OnPlayerCommandText execution from the samp-server (not measured)

Download
v0.0.1-beta for Windows:
https://github.com/Mellnik/mcmd/rele...-beta/mcmd.rar

Source hosted at GitHub
https://github.com/Mellnik/mcmd

Credits:
MyU for helping me with IDA
maddinat0r for general coding help
Reply
#2

First time i see a Command Processor inside a plugin :P
Anyway Good Job, Keep it up
Reply
#3

Great job, fantastic times.
Reply
#4

try the second not first - https://sampforum.blast.hk/showthread.php?tid=423815
Reply
#5

Quote:
Originally Posted by Jessyy
Посмотреть сообщение
Read the thread.
Reply
#6

It will be interesting to see what ****** says about this but your not after speed so I predict leniency.
Reply
#7

its interesting, but i dont know if is more secure than zcmd, i like to see what ****** says about this, i will whait to see.
Reply
#8

love the implementation, but i find all that assembly shit fascinating. don't know how useful it REALLY is though considering commands speed has NEVER really been a problem since dcmd imo. and the memory hacking always means it may not be compatible in the future...
Reply
#9

I'm curious about ****** and Kalcor's opinions (if either reads the thread obviously), but I'm really interested in this, so as soon as I can get an "expert" opinion (don't take it the wrong way), I'll be able to chose.

Anyway, really good job !
Reply
#10

People ever try to speed up commands run as it were the priority to gain CPU use or something. I liked your find but not your objective, it's almost deprecated at least for me.
Reply
#11

Wow nice job
Reply
#12

Fantastic
Reply
#13

Nice work!
Reply
#14

Nice job. i tested it's speed and i want to share the results :


Windows 7 Ultimate x64 :
Код:
[13:18:28] mcmd : 79 ms
[13:18:30] zcmd : 14 ms
[13:18:31] dcmd : 131 ms
[13:18:30] Normal command system (strcmp) : 127 ms
[13:18:33] Y_CMD : 11 ms
Reply
#15

Quote:
Originally Posted by iFarbod
Посмотреть сообщение
Nice job. i tested it's speed and i want to share the results :


Windows 7 Ultimate x64 :
Код:
[13:18:28] mcmd : 79 ms
[13:18:30] zcmd : 14 ms
[13:18:31] dcmd : 131 ms
[13:18:30] Normal command system (strcmp) : 127 ms
[13:18:33] Y_CMD : 11 ms
WOW, HOw did you test it?
Reply
#16

Quote:
Originally Posted by Whitetiger
Посмотреть сообщение
love the implementation, but i find all that assembly shit fascinating. don't know how useful it REALLY is though considering commands speed has NEVER really been a problem since dcmd imo. and the memory hacking always means it may not be compatible in the future...
As long as nothing changes regarding the command system mcmd should work with almost any version.


Quote:
Originally Posted by iFarbod
Посмотреть сообщение
Nice job. i tested it's speed and i want to share the results :


Windows 7 Ultimate x64 :
Код:
[13:18:28] mcmd : 79 ms
[13:18:30] zcmd : 14 ms
[13:18:31] dcmd : 131 ms
[13:18:30] Normal command system (strcmp) : 127 ms
[13:18:33] Y_CMD : 11 ms
You did it the wrong way. Counting speed is only possible by creating a pipe to it's internal functions, even then it's not 100% accurate.
Reply
#17

Ah, I always wanted to see some plugin based command processor. Really great work Mellnik.
Reply
#18

liked the idea, + rep
Reply
#19

Quote:
Originally Posted by Mellnik
Посмотреть сообщение
As long as nothing changes regarding the command system mcmd should work with almost any version.




You did it the wrong way. Counting speed is only possible by creating a pipe to it's internal functions, even then it's not 100% accurate.
No.. The speed must be measured by the run time it takes until pawn can call the next function.. and it seems it is slower than other command processors..
Reply
#20

Nice
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)