I run a few game servers and I'm trying to write a script to parse a log file into something more readable. Unfortunately it's turning into one big headache...
The format of the log is...
The only useful fields are the first and the last. They represent the player's GUID and player name.
So, player jim logged on three times using the same guid, and joe changed his name to joe2, and his guid remained the same as well. What I'd like to do is end up with an output like this...
Basically, rearranging the log into something useful - eliminating all extra instances where the guid and handle match, and rearranging by guid.
Every time I make a breakthrough it seems to get more complicated. If someone could look over this code it would be greatly appreciated. The first few full lines of the log above can be cut/paste into a pbalias.dat file if you'd like to test.
The format of the log is...
Code:
12eca1f19798ab7587255e682016003f 1 20040705 20040705 joe2
f17f39ddd593c46f9ce255eb20daac83 1 20040705 20040705 jim
f17f39ddd593c46f9ce255eb20daac83 1 20040705 20040705 jim
a1beb7c4ecd8cba7e7dddade70ecf445 1 20040705 20040705 sam
12eca1f19798ab7587255e682016003f 1 20040705 20040705 joe
f17f39ddd593c46f9ce255eb20daac83 1 20040705 20040705 jim
The only useful fields are the first and the last. They represent the player's GUID and player name.
So, player jim logged on three times using the same guid, and joe changed his name to joe2, and his guid remained the same as well. What I'd like to do is end up with an output like this...
Code:
f17f39ddd593c46f9ce255eb20daac83 jim
a1beb7c4ecd8cba7e7dddade70ecf445 sam
12eca1f19798ab7587255e682016003f joe
12eca1f19798ab7587255e682016003f joe2
Basically, rearranging the log into something useful - eliminating all extra instances where the guid and handle match, and rearranging by guid.
Every time I make a breakthrough it seems to get more complicated. If someone could look over this code it would be greatly appreciated. The first few full lines of the log above can be cut/paste into a pbalias.dat file if you'd like to test.
Code:
#/usr/bin/perl -w
#
use strict;
open LOG, "pbalias.dat" || die;
my @data=(); #intial data array for name/handle from log
my @guidarray=(); #used for checking duplicate guids
my @namearray=(); #used for checking duplicate names
my @finalarray=(); #used for final array to be output to file
my $hcheck=&handlecheck;
my $counter;
my @line2=();
while (<LOG>) {
my @line=split(/ /, $_); #take each line, split via whitespace
chomp $line[4];
my $hi=$line[0] . " " . $line[4] . "\n"; #take only guid and name, combine
push (@data, $hi); #push that into first array
}
close LOG;
for ($counter=0; $counter < scalar(@data); $counter++) {
my $lvar;
my $hvar;
@line2=split(/ /, @data[$counter]); #first split array element into guid/handle
push (@guidarray, $line2[0]); #put the guid into one array
push (@namearray, $line2[1]); #handle into another
&guidcheck($line2[0]); #send guid to subroutine to check if its already there
my $gcheck=guidcheck($ARGV[0]);
if ($gcheck) { #if the guid was found
&handlecheck($line2[1]); #send the handle to check if that is there
my $hcheck=handlecheck($ARGV[0]);
if ($hcheck) { #if handle is found
#do nothing
}
else {
push (@finalarray, @data[$counter]); #same guid,unique handle. throw it into final
}
}
else
{
push (@finalarray, @data[$counter]); #otherwise throw it into final
}
}
@finalarray=sort(@finalarray);
print @finalarray;
sub guidcheck {
foreach (0..$#guidarray) {
if ($_[0] eq $guidarray[$_]) {
return (1);
}
else {
return undef;
}
}
}
sub handlecheck {
foreach (0..$#namearray) {
if ($_[1] eq $namearray[$_]) {
return (1);
}
else {
return undef;
}
}
}