SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 28/06/2014, 10:44 PM   #1
Mellnik
Gangsta
 
Mellnik's Avatar
 
Join Date: Dec 2011
Location: Paradise Falls, CAℕADA
Posts: 768
Reputation: 373
Default mcmd Command Engine - Plugin based command processing

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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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

Last edited by Mellnik; 01/05/2016 at 11:16 AM.
Mellnik is offline   Reply With Quote
Old 28/06/2014, 10:48 PM   #2
Kathleen
Big Clucker
 
Kathleen's Avatar
 
Join Date: May 2012
Location: Netherlands
Posts: 191
Reputation: 31
Default Re: mcmd Command Engine - Plugin based command processing - first of it's kind

First time i see a Command Processor inside a plugin :P
Anyway Good Job, Keep it up
Kathleen is offline   Reply With Quote
Old 28/06/2014, 10:49 PM   #3
Snipa
Banned
 
Join Date: May 2010
Posts: 807
Reputation: 115
Default Re: mcmd Command Engine - Plugin based command processing - first of it's kind

Great job, fantastic times.
Snipa is offline   Reply With Quote
Old 28/06/2014, 11:08 PM   #4
Jessyy
Huge Clucker
 
Join Date: May 2009
Posts: 248
Reputation: 91
Default Re: mcmd Command Engine - Plugin based command processing - first of it's kind

try the second not first - http://forum.sa-mp.com/showthread.php?t=423815
__________________
Always have your stuff when you need it with Dropbox. 2GB account is free! https://db.tt/dgsaOztP
Works at loading... Please wait ███████████████]99.9%
Jessyy is offline   Reply With Quote
Old 28/06/2014, 11:12 PM   #5
Mellnik
Gangsta
 
Mellnik's Avatar
 
Join Date: Dec 2011
Location: Paradise Falls, CAℕADA
Posts: 768
Reputation: 373
Default AW: Re: mcmd Command Engine - Plugin based command processing - first of it's kind

Quote:
Originally Posted by Jessyy View Post
Read the thread.
Mellnik is offline   Reply With Quote
Old 28/06/2014, 11:14 PM   #6
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,892
Reputation: 1321
Default Re: mcmd Command Engine - Plugin based command processing - first of it's kind

It will be interesting to see what ****** says about this but your not after speed so I predict leniency.
Pottus is offline   Reply With Quote
Old 28/06/2014, 11:22 PM   #7
PT
Godfather
 
PT's Avatar
 
Join Date: Nov 2012
Location: Europe
Posts: 7,174
Reputation: 803
Default Re: mcmd Command Engine - Plugin based command processing - first of it's kind

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.
PT is online now   Reply With Quote
Old 28/06/2014, 11:30 PM   #8
Whitetiger
Huge Clucker
 
Whitetiger's Avatar
 
Join Date: Nov 2007
Posts: 403
Reputation: 156
Default Re: mcmd Command Engine - Plugin based command processing - first of it's kind

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...
__________________
GitHub

Author of SA-MP AC


Last edited by Whitetiger; 29/06/2014 at 05:31 AM.
Whitetiger is offline   Reply With Quote
Old 28/06/2014, 11:39 PM   #9
S4t3K
Gangsta
 
S4t3K's Avatar
 
Join Date: Jan 2013
Posts: 864
Reputation: 165
Default Re : mcmd Command Engine - Plugin based command processing - first of it's kind

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 !
__________________
S4t3K is offline   Reply With Quote
Old 28/06/2014, 11:40 PM   #10
CyNiC
High-roller
 
Join Date: Jan 2009
Location: Brazil
Posts: 1,409
Reputation: 203
Default Re: mcmd Command Engine - Plugin based command processing - first of it's kind

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.
__________________
My scripts
Brazucas'Server
CyNiC is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stops processing after the 2nd debug (house command) Beckett Scripting Help 5 11/12/2014 05:04 PM
Need help with MySQL-based command BlackID Scripting Help 3 03/08/2012 12:31 PM
[Include] mcmd - Command processor! MrDeath537 Includes 37 05/03/2011 12:07 PM
Id 0 Command Processing Blade_Cervetti Help Archive 9 01/01/2011 04:42 PM
Name based command Ov3rl0rd Help Archive 4 09/09/2009 01:39 AM


All times are GMT. The time now is 07:33 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.