Created
August 11, 2012 18:10
-
-
Save azatoth/3326072 to your computer and use it in GitHub Desktop.
convert Minecraft Bukkit PermissionEX PEX SQL to flat file format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use DBI; | |
use YAML::Tiny; | |
my $permissions = { | |
'users' => {}, | |
'groups' => {} | |
}; | |
# aka username, password | |
my $dbh = DBI->connect("DBI:mysql:eclipsecraft;mysql_read_default_file=$ENV{HOME}/.my.cnf") || die "Could not connect to database: $DBI::errstr"; | |
my $in_permissions = $dbh->selectall_hashref("SELECT * from permissions", 'id'); | |
my $in_permissions_inheritance = $dbh->selectall_hashref("SELECT * from permissions_inheritance", 'id'); | |
my $in_permissions_entity = $dbh->selectall_hashref("SELECT * from permissions_entity", 'id'); | |
$dbh->disconnect; | |
foreach my $i(values %$in_permissions) { | |
my $type = $i->{type} == 0 ? 'groups' : 'users'; | |
my $name = $i->{name}; | |
my $permission = $i->{permission}; | |
my $world = $i->{world}; | |
my $value = $i->{value}; | |
if( $world ) { | |
if( $value ) { | |
$permissions->{$type}->{$name}->{worlds}->{$world}->{$permission} = $value; | |
} else { | |
push @{$permissions->{$type}->{$name}->{worlds}->{$world}->{permissions}}, $permission; | |
} | |
} else { | |
if( $value ) { | |
$permissions->{$type}->{$name}->{$permission} = $value; | |
} else { | |
push @{$permissions->{$type}->{$name}->{permissions}}, $permission; | |
} | |
} | |
} | |
my $default_group = ""; | |
foreach my $i(values %$in_permissions_entity) { | |
my $name = $i->{name}; | |
my $type = $i->{type} == 0 ? 'groups' : 'users'; | |
my $suffix = $i->{suffix}; | |
my $prefix = $i->{prefix}; | |
my $default = $i->{default}; | |
if($prefix) { | |
$permissions->{$type}->{$name}->{prefix} = $prefix; | |
} | |
if($suffix) { | |
$permissions->{$type}->{$name}->{suffix} = $suffix; | |
} | |
if($default) { | |
$default_group = $name; | |
$permissions->{$type}->{$name}->{default} = 1; | |
} | |
} | |
foreach my $i(values %$in_permissions_inheritance) { | |
my $child = $i->{child}; | |
my $parent = $i->{parent}; | |
my $type = $i->{type}; | |
if( $type == 0) { | |
push @{$permissions->{groups}->{$child}->{inheritance}}, $parent; | |
} elsif( $parent ne $default_group ) { | |
push @{$permissions->{users}->{$child}->{groups}}, $parent; | |
} | |
} | |
my $res = YAML::Tiny->new; | |
$res->[0] = $permissions; | |
$res->write("new_permissions.yml"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment