| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
$| = 1; |
| 4 |
|
| 5 |
use DBI; |
| 6 |
|
| 7 |
&header; |
| 8 |
|
| 9 |
if (scalar(@ARGV) < 5) { |
| 10 |
&usage; |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
$levelxpfile = shift; |
| 15 |
$dbhost = shift; |
| 16 |
$dbname = shift; |
| 17 |
$dbuser = shift; |
| 18 |
$dbpass = shift; |
| 19 |
|
| 20 |
open LEVELFD, $levelxpfile or die "Could not open XP level file ($levelxpfile)"; |
| 21 |
|
| 22 |
print "Reading from XP file ...\n"; |
| 23 |
while($line = <LEVELFD>) { |
| 24 |
$line =~ s/#.*//; |
| 25 |
if ($line !~ m/^\s*$/) { |
| 26 |
($level, $startxp, $neededxp, $lossfactor, $mingames) = split(/\s+/,$line); |
| 27 |
print "level: $level startxp: $startxp neededxp: $neededxp lossfactor: $lossfactor mingames: $mingames\n"; |
| 28 |
$xplevel[$level]->{startxp} = $startxp; |
| 29 |
$xplevel[$level]->{neededxp} = $neededxp; |
| 30 |
$xplevel[$level]->{lossfactor} = $lossfactor; |
| 31 |
$xplevel[$level]->{mingames} = $mingames; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
close LEVELFD; |
| 36 |
print "...done\n\nConnecting to db..."; |
| 37 |
|
| 38 |
$dbh = DBI->connect("dbi:mysql:$dbname;host=$dbhost", $dbuser, $dbpass) or die "Could not connect to db (mysql, db: $dbname, host: $dbhost, user: $dbuser, pass: $dbpass)"; |
| 39 |
$sth = $dbh->prepare("SELECT uid, solo_xp, solo_level FROM Record WHERE uid > 0") or die "Error preparing query!"; |
| 40 |
|
| 41 |
$sth->execute() or die "Error executing query!"; |
| 42 |
|
| 43 |
while($row = $sth->fetchrow_hashref) { |
| 44 |
$level = $row->{solo_level}; |
| 45 |
$xp = $row->{solo_xp}; |
| 46 |
if ($level eq "" or $xp eq "" or $level < 1) { next; } |
| 47 |
for($i = $level; $i < 50 ; $i++) { |
| 48 |
if ($xplevel[$i]->{startxp} > $xp) { $i--; last; } |
| 49 |
} |
| 50 |
$level = $i; |
| 51 |
|
| 52 |
for($i = $level; $i > 1; $i++) { |
| 53 |
if ($xplevel[$i]->{needed_xp} <= $xp) { last; } |
| 54 |
} |
| 55 |
$level = $i; |
| 56 |
|
| 57 |
if ($level < 1) {$level = 1;} |
| 58 |
|
| 59 |
if ($level != $row->{solo_level}) { |
| 60 |
print "Repaired $uid from (level: " , $row->{solo_level}, " xp: $xp) to (level: $level xp: $xp)\n"; |
| 61 |
$dbh->do("UPDATE profile SET solo_level = '$level' WHERE uid = '".$row->{uid}."'"); |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
$sth->finish(); |
| 68 |
$dbh->disconnect(); |
| 69 |
|
| 70 |
sub header { |
| 71 |
print "Account db accounts XP levels repair tool.\n"; |
| 72 |
print " Copyright (C) 2002 Dizzy (dizzy\@roedu.net)\n"; |
| 73 |
print " People Versus People Gaming Network (www.pvpgn.org)\n\n"; |
| 74 |
} |
| 75 |
|
| 76 |
sub usage { |
| 77 |
print "Usage:\n\nrepairlevels.pl <xplevelfile> <dbhost> <dbname> <dbuser> <dbpass>\n\n"; |
| 78 |
print " <xplevelfile>\t: path/name of the file with the XP level data (ex. bnxplevel.txt)\n"; |
| 79 |
print " <dbhost>\t: the database host\n"; |
| 80 |
print " <dbname>\t: the database name\n"; |
| 81 |
print " <dbuser>\t: the database user\n"; |
| 82 |
print " <dbpass>\t: the database password\n"; |
| 83 |
} |