# get_player_info(): # intention: Get a listing of all the players in the server # and place that info into a global array. Return # the number of players on the server. sub player_stat() { my $funcName = (caller(0))[3]; my $raw_data = &send(1,"status"); my $watch = 0; my $pass = 0; my $num_players; my $player_name; my %player_info; my $player_nickname; my $player_userid; my $key; my $ipaddr; my @status; # Wow, I am actually starting to get this stuff # I wrote the following without asking anyone # about how to do it. Whats this do you ask? # It takes several lines of data in a single element # of an array and splits each line up into seperate # elements in the array. map { push (@status, $_) } map { split(/\n/,$_) } $raw_data; for ( @status ) { chomp; # eliminate that nasty terminator! :) $_ =~ s/\0//; # Ignore the stuff that comes from this # command for now. Maybe later I will # use this information for something but # I will wait until a more mature release # of this code. if ( $watch ) { # # name userid frags # address rate ping drop # ------------------ ---- ---- ----- # player name userid frags # IPaddr rate ping drop <- record 1 # player name userid frags # IPaddr rate ping drop <- record 2 # # This parses out just the name,userid and IP per record # so that the array is now propagated with # player_name,userid,IPaddr <- from reocrd 1 # player_name,userid,IPaddr <- from record 2 # etc. if ( $_ ne "" ) { if ( $pass == 0 ) { $pass = 1; } if ( $pass == 1 ) { $_ =~ s/\Q( .*)\E\s+([0-9]+)\s+.*//; $player_nickname = $1; $player_userid = $2; $pass = 2; } elsif ( $pass == 2 ) { ($key = $_ ) =~ /((?:\d+\.){3}\d+)/; $player_info{$1} = [ qw($value1 $value2) ]; $pass = 1; } } } # start counting after we see the "-"'s $watch = 1 if ( /-/ ); }