[PHP][WEB] Permissions manager v1.1 + Permissions Converter v1.0 !! + Get data from player.dat !

Discussion in 'Bukkit Tools' started by Pr4w, Aug 21, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Pr4w

    Hey,

    Being useless at Java, I thougt I'd try to put the coding knowledge at use, so I've started writing a few scripts that work alongside PermissionsBukkit to enable/ease the creation of control panels.
    The functions are pretty basic, but get the job done ! :)

    I've got two read so far, I'm curious as to know if anyone would be interested in more, and if you have any suggestions to improve/modify the scripts I've currently written. It may not all be pretty, but it works !

    Please note, all these scripts require the Spyc YAML Parser, download it from here.
    For the moment, these work only with PermissionsBukkit. I can make them work with P2/P3 if people want me to. :)


    Available scripts :
    - permissions.class.php - All in one PHP Permissions managing script, gives you access to several useful functions, including addUser(), addGroup(), setGroup(), addPermissions() and display() ! REQUIRES Spyc.php Yaml Parser - Download it here


    - permissionsConverter.php - Converts permissions files, from Permissions 2, Permissions 3 and PermissionsBukkit ! REQUIRES Spyc.php Yaml Parser - Download it here


    - getPlayerInfo - Gets all the useful information from player.dat, and stores it in an array (position, health, and even inventory !) REQUIRES Nbt.Parser.php - Download it here

    Permissions.Class.Php - How to ?
    So far, the permissions.class.php file allows you to easily handle PermissionsBukkit with several functions.
    To call the script, you need to :
    PHP:
    require('permissions.class.php');
    $do = new permissions();
    $do->setYaml("Location/of/your/config.yml");
    From then on, you get several functions :
    Show Spoiler
    PHP:
    addUser($user$group$rawpermissions);
    /*
    Replace $user with the user's username
    Replace $group with the group you want to add him to
    Replace $rawpermissions with the permissions you want to give him, using the following format :
    "permission.node1: true, permission.node2: false, permission.node3: true"
    You can leave $rawpermissions blank if you don't want to give the user additional permissions, it's optional
    */
    PHP:
    addGroup($group$rawpermissions$inheritance);
    /*
    Replace $group with the name of the group you want to create
    Replace $rawpermissions with the permissions you want for that group, using the following format :
    "permission.node1: true, permission.node2: false, permission.node3: true"
    Replace $inheritance with the groups you want it to inherit, using this syntax :
    "Group1, Group2, Group3"
    */
    PHP:
    setGroup($target$group);
    /*
    Replace $target with the user's username
    Replace $group with the group you want to set that user to
    */
    PHP:
    addPermissions($target$type$rawpermissions);
    /*
    Replace $target with the target : User's username, or group's name
    Replace $type with "users" or "groups", depending on what/to who you want to add permission nodes
    Replace $rawpermissions with the permissions you want for that group, using the following format :
    "permission.node1: true, permission.node2: false, permission.node3: true"
    */
    PHP:
    display($file);
    /*
    If you already ran setYaml("config.yml");, you can leave $file blank, or you can use it to display a different permission.yml file
    */
    PHP:
    remove($target$type);
    /* (Removes a user/group from permissions file)
    Replace $target with the username/group name
    Replace $type with "groups" or "users"
    */
    PHP:
    removePermissions($target$type$rawpermissions);
    /*
    Replace $target with the username/groupname
    Replace $type with "groups" or "users"
    Replace $rawpermissions with the permissions you want for that group, using the following format :
    "permission.node1: true, permission.node2: false, permission.node3: true"
    */



    getPlayerInfo.php - How to ?

    This script is fairly easy to use :
    PHP:
    require("getPlayerInfo.php");
    // Syntax is : getPlayerInfo("Username", "Path/to/world/players");
    $Pr4wInfo getPlayerInfo("Pr4w""/opt/mc/world1/players/");

    Older, deprecated scripts :
    Show Spoiler
    - setGroup - Change a user's group, comes with full error checking
    (Or view on Pastebin)
    - addGroup - Create a group, with permissions and inheritance
    (Or view on Pastebin)


    Future updates/scripts :
    - ???
    - Add more functionnality to permissions.class.php


    Changelog :
    Show Spoiler
    Permissions.class.php :
    v1.1 - Added remove() and removePermissions()
    v1.0.1 - Fixed error on addUser(), inproper indentation
    v1.0 - First release


    Suggestions ? Ideas ? Improvements ? Feel free to share :)
     
  2. Offline

    ichingpow

    Interesting idea. Can't wait to see the results.
     
  3. Offline

    sfxworks

    Got one that gets a players last known position?
     
  4. Offline

    Pr4w

    @ichingpow Thanks :)
    @sfworks Well the problem is I don't know how the player.dat file is formatted, can't seem to find any guide on it. I'll give it a try nonetheless. If you find a guide on how it's formatted, tell me :)

    Writing permissionsAdd(), will have it as one function for both a single user, and a group, because having permAddToGroup() and permAddToUser() seems a bit overkill.

    If you have any script requests, I'd be glad to give it a try :)


    edit : Gave it a try, wasn't really a success... xD
    [​IMG]

    Anyone know an easy way to open it in PHP?
     
  5. Offline

    ichingpow

    You'll need a NBT parser.
     
  6. Offline

    Pr4w

    I found one, looks pretty decent, but the issue I'm having is it requires an additionnal library added to PHP, meaning people would have to recompile if they haven't got it installed.. This isn't ideal tbh, do you know of any other parsers ?
    *edit* : Found one that uses BCMath, which is already available in PHP, I'll give this a try :)

    And... Done ! @sfxworks

    getPlayerInfo freshly served up. Works with PHP 4.1.4 and up, because of the BCMath library. This outputs an array $playerInfo['nickname'] that has position, health, and even the user's inventory, this could come in extremely handy ! :)
    Alternative Pastebin link, if you want !

    [​IMG]


    Edit : This is actually really interesting, because this potentially means a PHP script could write to the .dat file and edit it's contents.

    Edit again : I've started writing an all-in-one permissions() class, so far I have all the base functions down, and addPermissions(target, permissions).
    This works with groups and users :)

    PHP:
    $perm = new permissions();
    $perm->yaml "config.yml";
    $perm->type "users"// Can be users/groups. It's "users" by default
    $perm->addPermissions("Pr4w""superpermbridge.*: true, worldedit.superpickaxe: true");
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  7. Offline

    sfxworks

    Oh wow nice. And if ya needed an nbt decoder you could of just asked. I used this one a while back to make this schem to bo2 converter. It works with php 5 too.

    Hmm....I never though of that.
    Very interesting actually. So given that...how hard would it be to pre-set a players location? For example, player registers on website. Then a php script pre-generates his data file and gives it a random x y z coordinate in the world OR a preset coordinate. For example, if the user chose spawn 1, his values would be set to spawn 1. If spawn 2, then spawn 2. If random, then random.

    Actually...I think ill play with this a little myself .

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  8. Offline

    Pr4w

    Hahaha, yeah when I was looking for that NBT parser, I came across a topic of yours on some Actionscript3.0 forums, looking for a way to send data from PHP to Flash.. :p

    I'm guessing it wouldn't be too hard actually, you just need to create an array with the exact same formatting as the one player.dat uses, then convert it to NBT, and write to the file.
    This could actually be really fun, you could write a module for your website, on the user control panel, where you can pay to be teleported to a certain location. The script would deduct a fee from iConomy, then alter your coordinates on your player.dat. You'd have to check if the user is online or not before, but that shouldn't be too hard, given a list of online players.

    From then on, you can do a lot :
    - Online trading system between users (both users would need to be offline though, unless you use fputs alongside MCTelnet and a plugin that takes from one user and gives to another)
    - Online teleporting
    - Online item buying
    - Online healing ?
    - ???


    If you want to have a look at what I'm writing, I've done quite a lot this morning, and am quite happy at how it is turning out, considering I have properly coded PHP in a looooong time !
    http://pastebin.com/5VxNgT7q
     
  9. Offline

    sfxworks

    Wait...Is the player.dat live? Meaning as soon as its rewritten the player is effected?
     
  10. Offline

    Pr4w

    That would be great, but I don't think so :/
    It would be interesting to try it, though
     
  11. Offline

    sfxworks

    OH come to think of it..I can mod the level.dat files.....
    o
    m
    G

    Oh :(
    Well either way its a great breakthrough. You just opened an entirely new window for me.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  12. Offline

    Pr4w

    Yeah, I was realizing at the same time, while writing, how many possibilities this offers *-*
    (Btw, if you have any fixes/improvements for what I've written so far, I'd be happy to hear them :) )

    Wait, would it be possible for a plugin to, on-command, use the information from the player.dat ?
    That way, a user could be online, go to the website, use the teleporting panel, then go back to his Minecraft page, and be instantly teleported ? This would require a bit of work for all the glitches I can think of, such as him being healed/lose health, or his inventory being changed as well, but it would be amazing !

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  13. Offline

    sfxworks

    Depends. You have to take into account how many times and when the server writes and reads from the player.dat file. I'm going to do some testing with that soon after I get my map up.
     
  14. Offline

    Pr4w

    Keep me posted !

    permissions.class.php v1.0 released ! Get it here !
    Gives you access to several easy to use functions such as :
    - display() -> Displays all users and groups
    - addPermissions() -> Add permissions to a user or group
    - setGroup() -> Change a user's group
    - addGroup() -> Create a new group, with permissions and inheritance
    - addUser() -> Add a new user to a group, with optional permissions


    Edit : Uploaded v1.0.1, fixed an error in addUser() :)
    Edit : Uploaded v1.1 - Added remove() to remove a user/group, and removePermissions() to remove permissions from a user/group !

    Releasing a PHP Permissions converter !

    permissionsConverter() - For the moment, converts Permissions 2.7.x to Permissions 3.x. Will add support for PermissionsBukkit very soon ! :)
    I'll create a web page for it when I get a bit more time, so that people can convert their permissions files online. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  15. Offline

    zecheesy

    Whoa! It works! It's very good for lazy people who don't want to change the files manually (me).
    It's the best converters I've seen!!!! Get it now!
     
  16. Offline

    Chuck67322

    Sorry if I sound like an idiot, but how the heck can I use the converter? I have no experience with PHP, and I really need to convert my old permissions to the new PermissionsBukkit. I don't feel like manually changing each permissions node to the new format.
    I'm running on Mac by the way (though I have access to Windows).
     
  17. Offline

    ichingpow

    This is for web developers, not nooblets. I suggest you get bPermissions and use it's built in converter for Permissions to bPermissions.
     
  18. Offline

    Chuck67322

    I looked through the PermissionsBukkit OP and it said "Automatic converters for Permissions 2.7 and 3.x are on their way, but in the meantime you can still convert your configurations manually."
    Also, what is the point of posting these scripts on the forums? Why isn't it on a website already?
     
  19. Offline

    ichingpow

    I said bPermissions, not PermissionsBukkit.
     
  20. Offline

    Chuck67322

    Sorry, I assumed they were the same thing for some reason. Thanks for telling me about it.
     
  21. Offline

    Pr4w

    It will be, but I have a lot of work. You could host it yourself. ;)
    This is for devs who want to have custom server-side scripts for handling their users. ;)
     
  22. Offline

    sfxworks

    FINALLY found this thread. OKAY.
     
  23. Offline

    edocsyl

    I dont know but his dont work.... maby i make some mystakes..

    My files. I copied.
    permissions.class.php
    users.yml
    spyc.php

    PHP:
    /*
    setGroup.php
    */
    <?php

    $target 
    "Edocsyl";
    $group "Owner";

    require(
    'permissions.class.php');
    $do = new permissions();
    $do->setYaml("users.yml");

    setGroup($target$group);

    ?>

    Fatal error: Call to undefined function setGroup() in /var/www/setGroup/setGroup.php on line 11

    http://www.file-upload.net/download-3886194/setGroup.rar.html
     
  24. Offline

    Pr4w

    Try $do->setGroup($target, $group); :)

    Script is deeply flawed, I'll try and write up a better and fully working version when I've got time. :)
     
  25. Offline

    edocsyl

    Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /var/www/setGroup/permissions.class.php on line 155
    Group Owner does not exist !

    where i must inclue the group.yml?
     
  26. Offline

    codename_B

    Why not use the bPermissions API and interface directly with sockets and json arrays?

    http://dev.bukkit.org/server-mods/bpermissionswebgui/

    bPermissionsWebGUI opens up a socket read/write based system that you could use (if you knew how - bPermissionsWebGUI uses it) to interface directly with the bPermissions api, making file changes instant, rather than relying on caching from sql etcetera.

    It might be worth at least looking at.
     
  27. Offline

    Pr4w


    This was useful before GUI permission managers existed :p
    I'll be re-writing it completely, I actually have a better version... Just never uploaded it, not many people seemed to use the scripts.
    It's actually quite handy if you need some sort of Cron Jobs for VIP member expiring, etc. :)
     
  28. Offline

    Antariano

    This could be very useful for SpaceBukkit. May I take a look?
     
  29. Offline

    Pr4w

    Of course !
    Keep in mind it is glitched (doesn't like consecutive operations), but some of the stuff is actually quite good (handling the arrays, parsing and fixing the Yaml, checks, etc) :)
     
  30. Offline

    edocsyl

    is there a guid, how to user this bPermissions API ? I cant find


    2011-11-16 22:31:03 [SEVERE] Error occurred while enabling bPermissionsWebGUI v1.2 (Is it up to date?): com/arandomappdev/bukkitstats/CallHome
    java.lang.NoClassDefFoundError: com/arandomappdev/bukkitstats/Call
     
Thread Status:
Not open for further replies.

Share This Page