[INACTIVE][ADMIN/DEV] TCP interface for Bukkit - v1.2 [617]

Discussion in 'Inactive/Unsupported Plugins' started by DerpinLlama, Jan 16, 2011.

     
  1. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I AM NO LONGER DEVELOPING THIS PLUGIN.
    Anyone who wants to continue are obviously allowed to use my code and start a new thread. Don't forget to give me credit though. :p


    BukkitTcpServer:
    Version: v1.2

    Hai guis.

    I've been working on an interface to connect to Bukkit via things like PuTTY (http://www.chiark.greenend.org.uk/~sgtatham/putty/).
    As hey0 pointed out in another topic, this could theoretically allow any language with a socket API to be used for Bukkit.

    At the moment, clients that are authenticated with the server will receive messages about players chatting, players joining, and players quitting. (Post requests here if you want moar.)

    Place the BukkitTcpServer.jar file into your plugins folder and the properties file into your server's folder. (Remember to change the default password to something else!)
    Then you can download something like PuTTY, connect to your server (port is in the properties file), and type 'pass ' then your password. :)

    Current commands:
    • currenttime <world name>
    • eventtoggle <chat/join/quit>
    • getplayers
    • invadd <player name> <block type> <amount>
    • invprobe <player name>
    • invremove <player name> <slot> <type> <amount>
    • invset <player name> <slot>
    • json [on|off]
    • kick <playername>
    • maxplayers
    • msg <message>
    • pid
    • playercount
    • pm <player name> <message>
    • port
    • quit
    • time <world name> <time - as a string that can be converted to long>
    This plugin was compiled on CraftBukkit build 617 - be careful when using it on other versions.

    You can send donations via Bitcoin to 1CTKB67Cs9mZ6vpDJeanH5Dp8MnEkBrCNp. :)

    Feedback/comments would be nice. :)

    Remember that you're sending your password over plain text with no encryption please.

    Features:
    • My plugin makes cake
    • And eats it
    Jar

    Sauce

    Changelog:
    Version 1.2:
    • Some code for the invset and invadd commands cleaned up, thanks to cyberbobjr.
    • Added command event.
    • Compiled against CraftBukkit #449 (1.1 was against #297)
    • Edit: Now compiled again against #617.
    Version 1.1
    • Currenttime and time commands fixed so they take world name parameters.
    • GPL license applied.
    • Fixed PM command.
    • Updated support for drdanick's Remote Toolkit.
    • Probably some other stuff that I forgot about.
    Version 1.0
    • Now writing to the socket with writeBytes instead of writeUTF. Programs that remove the first two bytes will need to be fixed.
    • Added JSON functionality. The getplayers and invprobe commands will always output JSON info, while the others will need to be changed to JSON outputs using 'json on'.
    • Config file now has options for turning chat/join/quit events on/off.
    Version 0.9
    • Begun changelog because I finally got around to it.
    • Added option to bind to localhost.
    cyberbobjr and MonsieurApple like this.
  2.  
  3. Offline

    Lologarithm

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I had a few suggestions.

    1. When building a response string (like invprobe for example) use StringBuilder (or StringBuffer if you need thread synchronization on a single string) because it will greatly decrease memory and cpu usage. Doing 8 string concats is slow!

    2. I know it is a lot of work but try looking at Java's NIO package for doing the networking. Again, a much more performant implementation of networking - also if you are going to do this, you should do some reading on IOCP.

    3. If you want to allow for easier programming against this and better performance you should try to first queue up all string data and do one send instead of sending a whole bunch of lines - you should also consider sending the data in a standard format, like JSON... for example when 'getplayers' is requested you generate an array that is easy to parse rather than sending a ton of lines of "player name=". Parhaps something like " Players = { Joe, Frank, Bill, Susie } "
  4. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    1. I don't see how that would decrease RAM or CPU usage at all.

    2. I'll take a look.

    3. I do agree on buffering things like the getplayers and invprobe command outputs then sending it all in one go. As for JSON, I can't find Java's equivalent of PHP's json_encode function.
  5. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    playercount, port and maxplayers commands added.
    You do not need to be authenticated to use those commands.
    getplayers changed so you do not need to be authenticated.
    Note that using a wrong command while not authenticated still causes a disconnect.
    Removed the "Plugin enabled" on startup.
  6. Offline

    cyberbobjr

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hi,
    very nice feature ! i have try it with a php script and it's work !
    I can now work on a PHP web admin :)
    It is possible to add server commands (like reload ? etc.)
    Thank you very much
    Regards
  7. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I've looked into the possibility of things like that and as far as I can see, that's not possible without making the server create a new socket to drdanick's Server Remote Toolkit.
  8. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Fixed invadd command, added eventtoggle command.
  9. Offline

    Reil

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Cool, got this running on my server.

    Feature request: Can you echo commands made over TCP onto the console? It would help testing things, and also make sure that no one's using the TCP without being known/detected. :3
  10. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I did comment out the line which was doing that (was using it for debug), but I'll add it back in next version for ya.

    I'm just waiting for drdanick's permission to add support for his Remote Toolkit's restart and forcerestart commands.
  11. Offline

    Lologarithm

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hey DerpinLlama,
    Just a follow up to your comment about string concat vs builder:
    http://kaioa.com/node/59

    The take away is this:
    Code:
    When to use StringBuilder and StringBuffer
    This one is easy to remember: use 'em whenever you assemble a String in a loop. 
  12. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    So I should use this:
    Code:
    					StringBuffer output = new StringBuffer("");
    					for(int i = 0; i <= 35; i++){
    						output.append("inventory_item player=").append(split[1]).append(" slot=").append(i).append(" type=").append(items[i].getTypeId()).append(" amount=").append(items[i].getAmount()).append("\r\n");
    					}
    					sendText(output.toString().trim());
    Instead of this:
    Code:
    					String output = "";
    					for(int i = 0; i <= 35; i++){
    						output += "inventory_item player=" + split[1] + " slot=" + i + " type=" + items[i].getTypeId() + " amount=" + items[i].getAmount() + "\r\n";
    					}
    					sendText(output.trim());
    ?
  13. Offline

    Lologarithm

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Exactly :)

    Edit:
    I am not trying to be a jerk or anything, I honestly want to help people out! I hope you don't take offense to any of my comments.

    I especially like this project because I think it could be a really cool way of creating an interface for any language you want to use - or write an Android app, or whatever. And because this could have multiple connections at once I think performance is pretty important.
  14. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Nono, I understand completely. You want to help and I'm grateful for that.
  15. Offline

    The_REGs_Group

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Gotta question, you say to type ( pass <password> ) but i wasn't sure where so i tried putty and, well no text shows up and then i tried my MC server console and it isn't read as a valid command. I need some help so if some could come up with like an idiot proof tutorial on what to do or just answer me that would be fantastic. Thx for your time.[IMG]
  16. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    That does not sound like a bug I can reproduce.
  17. Offline

    MonsieurApple

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    As part of my new project, BukkitAdmin, there will be a PHP server wrapper to interact with this plugin.

    You can checkout the progress here -> https://github.com/BukkitAdmin/BukkitAdmin/blob/master/minelink.php
    --- merged: Jan 29, 2011 4:55 AM ---
    Hi!

    Testing it out some more. Had a few little requests.

    1. Could you possibly add more options for like enable/disable it sending chat back to you and such
    2. JSON would be awesome for all returned data
  18. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    1. Use the eventtoggle command.
    2. I was looking into that but I couldn't find a method that encodes a variable as a JSON string.
  19. Offline

    MonsieurApple

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Ah didn't see eventtoggle. Thanks.

    As for JSON in java, is this of help? http://www.json.org/java/

    You could also cheat and just return stuff like the JSON would be, but not actually use JSON if you get what im saying.
  20. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You mean generate the JSON myself? Yeah, that's what I've decided I'd do.
  21. Offline

    MonsieurApple

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hey I've made a JSON version and added other improvments (new pid command) and such.

    Source and JAR attached.
  22. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Uhm yeah. I have no intention to add in JSON where not necessary. Only the things that can return more than 2 lines will be getting JSON added. Still good work though.

    Edit: I think I'm gonna have invprobe output something like this:
    Code:
    {"inventory_items": {
    	"name": "DerpinLlama",
    	"slots": [
    		{"num": 0, "type": 0, "amount": 0}
    		{"num": 1, "type": 0, "amount": 0}
    		{"num": 2, "type": 0, "amount": 0}
    		{"num": 3, "type": 0, "amount": 0}
    		{"num": 4, "type": 0, "amount": 0}
    		{"num": 5, "type": 0, "amount": 0}
    	]
    }}
    Ok?

    2nd edit:
    PHP:
                    else if(line.length() >= && line.substring(09).equals("invprobe ")){
                        
    String[] split line.split(" ");
                        if(
    plugin.getServer().getPlayer(split[1]) == null){
                            
    sendText("ERR Player not online.");
                            continue;
                        }
                        
    PlayerInventory playerInventory plugin.getServer().getPlayer(split[1]).getInventory();
                        
    ItemStack[] items playerInventory.getContents();
                        
    StringBuffer output = new StringBuffer("{\"inventory_items\":{\"name\":\"");
                        
    output.append(split[1]);
                        
    output.append("\",\"slots\":[");
                        for(
    int i 0<= 35i++){
                            
    output.append("{\"num\": ").append(i).append(", \"type\": ").append(items[i].getTypeId()).append(", \"amount\": ").append(items[i].getAmount()).append("}}");
                        }
                        
    output.append("]}}");
                        
    sendText(output.toString().trim());
                        
    sendText("OK");
                    }
  23. Offline

    MonsieurApple

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Nice!

    Can we have an option for all JSON though please? Every result I get back I run through json_decode().

    Also, maybe options for default event on/off? Thanks alot :D
  24. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You want an option for JSON to be used for all outputs?

    What do you mean by your last line? >_<
  25. Offline

    MonsieurApple

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    By the last line, I mean like in the properties file, you can set the events join, chat, quit on/off by default.
  26. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I see. I'll add that in I guess.
    --- merged: Jan 30, 2011 11:04 PM ---
    What do you think of changing the sending method to do this:
    Code:
    			if(sendAllJson){
    				if(text.substring(0, 3).equals("ERR")){
    					text = "{\"error\":true,\"message\":\"" + text + "\"}";
    				}
    				else if(text.equals("Welcome to Bukkit, please authenticate.")){
    					text = "{\"ready_for_auth\":true}";
    				}
    				else if(text.equals("OK")){
    					text = "{\"ok\":true}";
    				}
    				else{
    					text = "{\"message\":\"" + text + "\"}";
    				}
    			}
    ???
  27. Offline

    MonsieurApple

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Awesome! :D

    Also, maybe an event toggle? (eventtoggle json on/off)

    However, still have it like chat/quit/join where you can set a default.

    Thanks :)
  28. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Version 1.0:

    Configs will now look a bit like this:
  29. Offline

    MonsieurApple

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    *hugs DerpinLlama profusely*
  30. Offline

    Pezmantbh

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Does this work with build 168+ ?

    If so, I am gonna use this to make a program for my server. Cheers :)
  31. Offline

    DerpinLlama

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Should do. I'm not aware of it breaking at that build. Test it if you like. :)
  32. Offline

    Pezmantbh

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    The reason I ask, is because 168 changed the way commands are handled which broke many plugins... Just wondered if it broke this too. I will try it shortly, and post back my findings :)


    EDIT:
    Putty is giving me this error:
    "Network Error: Connection Refused"

    I am not entirely sure why...
    CB #166

Share This Page