barneygale / mark2

minecraft server wrapper, written in python with twisted
Other
105 stars 27 forks source link

Allow mark2 send (or new command) to return data #110

Open LadyCailin opened 10 years ago

LadyCailin commented 10 years ago

I don't know how trivial this would be, but it would be nice is there were a way to get any data sent to the CommandSender via sendMessage to be returned as part of the command's stdout. This would allow shell scripts to more easily integrate to get data from the server without having to somehow modify a plugin's output to write to an external file or whatever other means of communication is kludged together. For instance, "mark2 send -c server list | sed 's/hidden moderator//g'" could be used by a shell script to get the list of players from the server, and then perform more complicated transformations on the data.

It would even suffice for my purposes if the command were required to message the data in some specified format that mark2 knew how to respond to, and properly intercept.

barneygale commented 10 years ago

You sort of already have this. Check out mark2 help send, specifically --wait and --only.

The minecraft server sticks all console commands into an async list processed by a thread, so unfortunately there's no guarantee that the next thing you'll see on console will be your command's output. This means that sending something like `\ncommand\n\n" to try to wrap the output in two "Unknown command."s (something I've previously considered) won't work.

In short: you can't get a command's output unless you know what you're looking for, and for that you can use --wait and --only

barneygale commented 10 years ago

I also think if you're trying to solve something with a combination of CH and mark2, you should just bite the bullet and write a bukkit plugin :P

LadyCailin commented 10 years ago

Yeah, I may end up doing that, this is a bit kludgy. However, if the infrastructure is in place and works, it works.

Anyways, I tried --wait and --only, and while that would work for what I'm trying to do, it would be more trouble than it's worth, I think, so I may just figure out how to do this without mark2. (Either bukkit plugin or otherwise.) Anyways, feel free to close this ticket if you don't want to add this feature, but what I'm suggesting is different than your suggestion, but may not be as useful as I think.

To elaborate: what i'm suggesting is that when you send mark2 request -n server command, then mark2 sends command -id<some random request identifier> which then expects the plugin to respond by echoing to console: {{MARK2(<the same random request id provided by the command>): The response to the actual command}} (or some other well defined format, perhaps xml) which mark2 could then positively identify as the response to its request, at which point it would return The response to the actual command to the process. This would require plugins to know about mark2, but it would still abstract away from bukkit, as mark2 would be the abstraction layer that connects external processes to whatever the server is, bukkit or otherwise. Granted, this would require writing a custom plugin, but with things like CH (or with any plugin that wanted to be aware of mark2), that would be trivial to do, and this seems like the perfect companion to mark2 send. Does my idea make sense?