maniaplanet / manialive

PHP controller for the ManiaPlanet Dedicated Server
GNU Lesser General Public License v3.0
9 stars 4 forks source link

registerChatCommand should have option to output all parameters to one variable #1

Closed magnetik closed 10 years ago

magnetik commented 10 years ago

From petri.ja...@gmail.com on December 29, 2010 23:32:25

I'm porting google translate plugin to manialive... there is just no way to do it with current api, and same goes with if developers want to do chatcommands like /gg /thx or /msg --> personal messages, etc..

Original issue: http://code.google.com/p/manialive/issues/detail?id=1

magnetik commented 10 years ago

From petri.ja...@gmail.com on December 29, 2010 15:04:59

and people on real world doesn't care much about caps lock or case sensitivity, so the commands entered in trackmania chat should be translated to whatever case to class functions.

and issue 3 with chatcommands is maybe fixed if all parameters can be send to one variable... at the current state, you get nasty error message that command doesn't exist if you enter mismatch number of variables, atleast user should get warning, parameter count mismatch with plugin. or similar.

magnetik commented 10 years ago

From melot.philippe on December 29, 2010 22:21:11

Can you give us more details about your difficulty you have to use the current ChatCommand Api ?

magnetik commented 10 years ago

From petri.ja...@gmail.com on December 29, 2010 23:12:25

sure, here's the essential parts of code:

function onReady() {
$this->registerChatCommand("admin", "admin", 2, true);
}

function admin($login, $command, $param = NULL) {
Connection::GetInstance()->chatSendServerMessage("$login --> $command --> $param");
}

on chat i enter /Admin help it says command Admin doesn't exist.

on chat i enter /admin help it says command Admin doesn't exist.

on chat i enter /admin help this reaby -> help -> this


so in this case, i can't implement a admin command with help and / or one / multiple parameters.

i tried to hook the onPlayerChat do trigger admin command and register admin chatcommand with 0 parameters, but still i get too much error messages.

another example, personal messages to players

function onReady() {
$this->registerChatCommand("pm", "pm", 50, true);
}

well it's obvious that when there is miscount of parametres in chat command, it just says command pm doesn't exist.

magnetik commented 10 years ago

From petri.ja...@gmail.com on December 29, 2010 23:15:53

so my suggestion is to make something like this

function onReady() { $this->registerChatCommand("pm", "pm", false, true); }

function pm($login, $param) { Connection::GetInstance()->chatSendServerMessage("$login -> $param"); }

where i can "manually" parse the parameters. or send the parameters as chat to when ever i want to.

magnetik commented 10 years ago

From melot.philippe on December 30, 2010 01:10:55

ok, there is several things about your problem. First, in your admin method you don't have to use Connection::getInstance if you extend the Plugin class. You have a direct access to the Connection object with $this->connection . Then, on each Command you can attribute a list of login allowed to use it. The method registerChatCommand will return you the Command object. If you get this object you will be able to edit it and add allowed players. You can also use the full signature of the registerChatCommand method: registerChatCommand($command_name, $callback_method, $parameter_count = 0, $add_login = false, $authorizedLogin = array()) Here you can see that the last parameter is an array you can fill with authorized Login. Like this every player using /help will see only commands visible and available to him. Finally, your callback command could be used with 1 or 2 parameters, so you just have to register it twice with 1 and 2 parameters. $this->registerChatCommand("admin", "admin", 1, true); $this->registerChatCommand("admin", "admin", 2, true);

magnetik commented 10 years ago

From melot.philippe on December 30, 2010 09:10:20

A new package is available with some improvements in the Chat Command API, I hope you will enjoy them ;)

Status: Fixed

magnetik commented 10 years ago

From petri.ja...@gmail.com on January 02, 2011 11:16:46

would you provide me an example how to get all chat to one parameter, i tried, but i can't figure out how to do it.

magnetik commented 10 years ago

From melot.philippe on January 03, 2011 01:00:41

Here is a sample:

$this->registerChatCommand('myCommand','myCallback',1,false,array('login1','login2',...));

Like this you create a command avaible to login1, login2, etc. If you want to add some help for the user who use the command 'man', you have to do like the following sample

$command = $this->registerChatCommand('myCommand','myCallback',1,false,array('login1','login2',...)); $command->help = 'My Help Sentence';

Hope it will help you

magnetik commented 10 years ago

From petri.ja...@gmail.com on January 03, 2011 03:12:14

I still have problem with the api, using latest version from svn.

code: function onLoad() { $command = $this->registerChatCommand('pm','sendPersonalMessage',1,false,array('reaby')); $command->help = 'Sends a personal messages'; $command = $this->registerChatCommand('r','sendReply',1,false); $command->help = 'Sends a reply to personal message'; }

function sendPersonalMessage($login, $params) {
$this->connection->chatSendServerMessage("yet public, but a really personal message:" .$params);
}

outputcome: (image will be removed in some time) http://labs.dura.fi/p/reaby/c5cd.png --------- also for personal messages and google translate i would need public commands with no login restriction :)

Could there be a additional parameter to be passed to command.. or something, my vision would be like this:

$command = $this->registerChatCommand('pm','sendPersonalMessage',2,true); $command->help = 'Sends a personal messages'; $command->routeAll = 2; // this defines everything else is spitted out to second variable

function pm ($login, $targetlogin, $chat) { // do the login to player assign here.. $this->connection->chatSendServerMessage($login."-->".$chat, $targetlogin); }

in trackmania chat: /pm philippe just sending a personal message, this uses damn a lot of params if using the normal system. could you fix it for me ?

and you could then just type: /r yeah, i'll fix it to next release.

magnetik commented 10 years ago

From melot.philippe on January 03, 2011 03:41:16

ok, I now see what you mean, it's preatty easy to solve, and I have no change to do ;) The exemple you give me should be use like this: /pm targetLogin "You message with as many space that you want"

/r "Yeah, I can send a message with a lot of space by using doubl quotes"