mtasa-blue
mtasa-blue copied to clipboard
onClientCommand event before trigger onPlayerCommand server side
Is your feature request related to a problem? Please describe.
I'm trying to handle the situation when the player enters some invalid command, e.g. (/givemoney) so i do expect to receive the command and try to run this command client side to show some error or warning ('Command /givemoney not found') before any try to execute the command server side.
I don't like the current way this is handled by MTA at all. Even invalid commands are sent to the server and as far i know we can't define the bandwidth for this event. But just to be clear my problem here is not performance, but usability.
Describe the solution you'd like
A client side event 'onClientCommand' could be very useful for my problem. If i cancel this event i do expect the command not being sent to the server (via onPlayerCommand). This would allow me to change the way invalid commands/arguments are handled effectively.
Describe alternatives you've considered
I considered to create a .xml with valid commands / arguments but anyway the command would be sent to the server and on busy servers this could hurt.
Additional context
My goal is (pseudocode):
Client side
addEventHandler("onClientCommand", root, ...
cancelEvent()
if not executeCommandHandler ...
send the command to server ...
Server side
addEventHandler("onPlayerCommand, root ...
cancelEvent()
if not executeCommandHandler ...
(send fail feedback to client)
Security Policy
- [X] I have read and understood the Security Policy and this issue is not about a cheat or security vulnerability.
Why is it bad for client to send an invalid command to MTA server?
The issue with your solution being the server would need to tell the client of all existing commands (server) in order to filter them. I doubt the server owner would want the client to know all available commands given some could be restricted to certain people like staff or debugging.
i think that issue is completly different: because of mta implementing own command system, it's hard to do any changes to do not mess up other scripts. If instead there would be a resource that implements command, there you can customize it per server without worry of breaking anything.
Even current behaviour seems incorrect, fixing it will break someone else script. Adding condition to enable/disable old behaviour may be a solution, but it can just move problem to different area
Why is it bad for client to send an invalid command to MTA server?
It is not necessarily bad, but redundant if the command is client side. Any way to avoid triggering server events are valid in my view.
Did you already tried to assert commands or check if they exists? At least I had a lot of problems doing that. IIRC it is not even possible to cancel client side command events (except from inside the function passed in 'addCommandHandler' with if statements).
I already created a custom chat that supports commands, but it don't works for MTA commands like 'reconnect, quit, etc.' and it would annoy players used to this, so i dropped the idea (still have the resource). But in the custom chat i was able to reproduce the thing I am suggesting here smoothly.
The issue with your solution being the server would need to tell the client of all existing commands (server) in order to filter them
Also not necessarily. e.g. If the player sends a command 'givevehicle' (from admin resource) to the server, the command will not be executed via 'executeCommandHandler' because the command is added just for admins, hence an 'Unknown command' message would be sent to the player that executed the command. The 'issue' you mentioned would be just a bad usage of 'addCommandHandler'.
It is not necessary to have a xml with all commands to check if they exists or not, that is the point of my suggestion. You could use a xml just to assert the commands.
If the resource owner wish to use 'addCommandHandler' in a bad way and use the suggested event in the same server to send the invalid commands, then it is his blame (my opinion). A warning in the API could be sufficient to avoid mistakes.
I have no more arguments, so if these are not sufficient I will understand.
Another thing: commands may not impact your server performance so much as other scripts may do. Consider what cause highest cpu usage, maybe checking commands against permissions is responsible for tiny fraction of cpu usage?
As i said, changing behaviour is risky. If you really want to cancel command clientside and not send to server - use "onClientConsole". It gets triggered only clientside and give you entire string of command including arguments
i think that issue is completly different: because of mta implementing own command system, it's hard to do any changes to do not mess up other scripts. If instead there would be a resource that implements command, there you can customize it per server without worry of breaking anything.
It is not possible to trigger the 'onClientCommand' event before send it to the server (if the event is not cancelled)? I guess this can't break other scripts unintentionally, but i don't know how MTA works internally.
[Command have no impact on performance]
As I said, performance is not the problem, I am just having trouble to implement a custom behavioror...
Anyway, I am not here to just give work for people. I understand if this can not be achieved in a good way. 🙂
Thanks in advance!
@CrosRoad95 , because you suggested to use 'onClientConsole' I will try that (not sure if works for commands typed in chat), but this reminded me I can also not cancel the client send message event. I mean, if I could cancel the send message if I detect a command client side, I could also implement the feature I need (execute command "manually"). So maybe a cancellable 'onClientMessageSend' event could be useful and I would just cancel 'onPlayerCommand' and client side effects (if possible) to remap it for my custom event.
The thing I don't understand is why is not possible to cancel this client actions before send it to the server 🤔
Edit: Other thing i could try is to cancel the effect of the button that sends the message to the chat and search for a command in the message. But no way to get the text that is being typed in the chat :/ Every workaround seems to not work here. The text can be changed by Up/down arrows, backspaces, etc. and if the cursor is implemented in the future. Do you think a function like 'getChatBoxMessageBeingTyped' could be implemented?
This could be exploited for example if cmd == "admin" then cancelEvent() or quit or reconnect....etc