Show psadmin.pl syntax highlighted
#!/usr/bin/perl
BEGIN { use FindBin; use lib "$FindBin::Bin"; }
$| = 1; # do not buffer output on STDOUT
our $VERSION = '1.1';
use strict;
use warnings;
use util;
use LoadConfig;
use Getopt::Long;
use Data::Dumper;
use DBI;
our ($args, $conf, $db, $sth, $plr, $ident);
die usage() unless GetOptions(
'<>' => \&GetOptions_callback,
'config=s' => \$args->{config},
'username=s' => \$args->{username},
'steamid|worldid=s' => \$args->{worldid},
'playername|name=s' => \$args->{name},
'ipaddress=s' => \$args->{ipaddr},
'accesslevel|level|acl=i' => \$args->{accesslevel},
);
# include some common functionality that all of the ps*.pl utilities use
do 'psinc.inc' or die $@;
# makes sure we have a steamid, user, playername or ip address
validate_ident($args);
# default to ADMIN level if none was specified (0 is still valid though)
$args->{accesslevel} = 10 if !defined $args->{accesslevel};
$plr = find_player($args);
die "No matching players found!\n" unless $plr->{plrid};
print "Player \"$plr->{name}\" matched the $ident \"$args->{$ident}\". PLRID=$plr->{plrid} PFID=$plr->{plrprofileid}\n";
my $res = $db->do("UPDATE $conf->{mysql}{tableprefix}plr_profile SET accesslevel=$args->{accesslevel} WHERE plrprofileid=$plr->{plrprofileid}");
if ($res) {
print "Accesslevel updated to level \"$args->{accesslevel}\"\n";
} else {
print STDERR "An error occured while updating accesslevel: " . $db->errstr . "\n";
}
# ------------------------------------------------------
sub usage {
my $me = 'psadmin.pl';
print STDERR $_[0] if scalar @_;
print STDERR "USAGE:\n";
print STDERR "$me <identity> [accesslevel]\n";
print STDERR "$me -steamid <steamid> [-accesslevel <accesslevel>]\n";
print STDERR "$me -username <username> [-accesslevel <accesslevel>]\n";
print STDERR "$me -name <player name> [-accesslevel <accesslevel>]\n";
print STDERR "$me -ip <ipaddress> [-accesslevel <accesslevel>]\n";
print STDERR "$me -c <config> <identity> [accesslevel]\n";
print STDERR "\nIf no accesslevel is given ADMIN is the default.\n";
print STDERR "Valid access levels are:\n 1 = Normal User.\n 5 = Clan Admin.\n10 = ADMIN.\n";
return "\n";
}
sub GetOptions_callback {
my $value = shift;
$args->{args} = [] unless ref $args->{args} eq 'ARRAY';
push(@{$args->{args}}, $value);
if ($args->{worldid} or $args->{username} or $args->{name} or $args->{ipaddr}) {
$args->{accesslevel} = $value;
} else {
$args->{worldid} = $args->{username} = $args->{name} = $args->{ipaddr} = $value;
}
}
See more files for this project here