1 | #!/usr/bin/perl -w
|
---|
2 | # idlerpg-adv (11-22-2003) by daxxar (http://mental.mine.nu)
|
---|
3 | # Usage: ./idlerpg-adv.pl [playernames]
|
---|
4 | #
|
---|
5 | # Call this script from the command line, or your login profile.
|
---|
6 | use strict;
|
---|
7 | use LWP::Simple;
|
---|
8 |
|
---|
9 | # Use cookies:
|
---|
10 | # %user - username, %class - class, %level - level,
|
---|
11 | # %next - time to next level, %status - online status,
|
---|
12 | # %uhost - nick!ident@host, %ca - created at,
|
---|
13 | # %llo - last logged on, %ti - total idletime,
|
---|
14 | # %items - list of items, %penalties - list of penalties (special; multiline)
|
---|
15 | #
|
---|
16 | # Each comma-separated element is printed with a newline at the end :)
|
---|
17 |
|
---|
18 | my @string = (
|
---|
19 | '[User] %user', '[Class] %class', '[Level] %level', '[Next level] %next',
|
---|
20 | '[Status] %status', '[User@host] %uhost', '[Created at] %ca',
|
---|
21 | '[Last logged on] %llo', '[Total idle] %ti', '[Items] %items',
|
---|
22 | '[Penalties] %penalties'
|
---|
23 | );
|
---|
24 |
|
---|
25 | ### No need to change below ###
|
---|
26 | # For printing things in a columnized view
|
---|
27 | # print_col(\@list_of_entries, \@value_of_entries, $number_per_line)
|
---|
28 | sub make_col {
|
---|
29 | my $entryname = shift;
|
---|
30 | my $entryvalue = shift;
|
---|
31 | my $count = shift;
|
---|
32 | my @len;
|
---|
33 | my $ret;
|
---|
34 | # Find maximum length for each of the $count columns
|
---|
35 | for my $x (0 .. $#{$entryvalue}) {
|
---|
36 | my $col = $x % $count;
|
---|
37 | if (!defined($len[$col]) || $len[$col] < length($entryvalue->[$x] . $entryname->[$x])) {
|
---|
38 | $len[$col] = length("$entryvalue->[$x]"."$entryname->[$x]");
|
---|
39 | }
|
---|
40 | }
|
---|
41 | for my $t (0 .. $#$entryvalue) {
|
---|
42 | if (!($t % $count)) { $ret .= "\n "; }
|
---|
43 | $ret .= "$entryname->[$t]\($entryvalue->[$t]\)";
|
---|
44 | $ret .= ' ' x ($len[$t % $count] - length($entryname->[$t] . $entryvalue->[$t]) + 1);
|
---|
45 | }
|
---|
46 | return $ret;
|
---|
47 | }
|
---|
48 | sub time_to {
|
---|
49 | my @timeunits = ('yr', 'month', 'week', 'day', 'hr', 'min', 'sec');
|
---|
50 | my @timecalc = (31104000, 2592000, 604800, 86400, 3600, 60, 1);
|
---|
51 | my $seconds = shift; my $output;
|
---|
52 | if ($seconds == 0) { return "0 seconds"; }
|
---|
53 | for my $x (0 .. $#timecalc) {
|
---|
54 | my $y = int($seconds / $timecalc[$x]);
|
---|
55 | if ($y != 0 && $seconds != 0 && $seconds >= $timecalc[$x]) {
|
---|
56 | $seconds = ($seconds % $timecalc[$x]);
|
---|
57 | $output .= "$y $timeunits[$x]";
|
---|
58 | $output .= 's' unless $y == 1;
|
---|
59 | if ($seconds == 0) { last; }
|
---|
60 | $output .= ', ' if $x < $#timecalc - 1 && ($seconds % $timecalc[$x+1]) && $seconds != 0;
|
---|
61 | $output .= ' and ' if !($seconds % $timecalc[$x+1]);
|
---|
62 | }
|
---|
63 | }
|
---|
64 | return $output;
|
---|
65 | }
|
---|
66 | sub time_from {
|
---|
67 | my $seconds = shift;
|
---|
68 | my ($sec, $min, $hr, $day, $mo, $yr, $wday) = localtime($seconds);
|
---|
69 | $mo = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Oct', 'Sep', 'Nov', 'Dec')[$mo];
|
---|
70 | $wday = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')[$wday];
|
---|
71 | $yr += 1900;
|
---|
72 | if ($hr < 10) { $hr = "0$hr"; }
|
---|
73 | if ($min < 10) { $min = "0$min"; }
|
---|
74 | if ($sec < 10) { $sec = "0$sec"; }
|
---|
75 | if ($day < 10) { $day .= ' '; }
|
---|
76 | return "$wday $mo $day $hr:$min:$sec $yr";
|
---|
77 | }
|
---|
78 | die "Usage: $0 <playernames>\n" .
|
---|
79 | "Example: $0 daxxar cyb\n" if @ARGV == 0;
|
---|
80 |
|
---|
81 | start:
|
---|
82 | my $username = shift(@ARGV);
|
---|
83 | my $page = get "http://jotun.ultrazone.org/g7/dump.php?player=$username";
|
---|
84 |
|
---|
85 | # Only line is commented if there is no such user
|
---|
86 | if ($page =~ /^#[^\n]+$/) { print "$username: no such user\n"; exit 1; }
|
---|
87 | ($page) = ($page =~ /\n([^#].*)/); # Remove the comment
|
---|
88 |
|
---|
89 | # @ent = entries on page, \t separated.
|
---|
90 | my @ent = split(/\t/, $page);
|
---|
91 |
|
---|
92 | # Assign each tab-separated entry to its hash-key
|
---|
93 | my %values = (
|
---|
94 | 'user' => $ent[0], 'level' => $ent[1],
|
---|
95 | 'class' => $ent[2], 'next' => $ent[3],
|
---|
96 | 'host' => $ent[4], 'status' => $ent[5],
|
---|
97 | 'totalidle'=> $ent[6], 'created'=> $ent[14],
|
---|
98 | 'lastlog' => $ent[15],
|
---|
99 | 'penaltynames' => [ qw(msg nick part kick quit quest logout) ],
|
---|
100 | 'penaltytimes' => [ @ent[7 .. 13] ],
|
---|
101 | 'itemnames' => [ qw(amulet charm helm boots gloves ring leggings shield tunic weapon sum) ],
|
---|
102 | 'itemlvls' => [ @ent[16 .. 25] ]
|
---|
103 | );
|
---|
104 | $values{'next'} = time_to ($values{'next'});
|
---|
105 | $values{'totalidle'} = time_to ($values{'totalidle'});
|
---|
106 | $values{'lastlog'} = time_from($values{'lastlog'});
|
---|
107 | $values{'created'} = time_from($values{'created'});
|
---|
108 | if ($values{'status'}) {$values{'status'} = 'Online'}
|
---|
109 | else {$values{'status'} = 'Offline'}
|
---|
110 |
|
---|
111 | foreach my $str (@{[ @string ]}) {
|
---|
112 | $str =~ s/%user/$values{'user'}/g;
|
---|
113 | $str =~ s/%class/$values{'class'}/g;
|
---|
114 | $str =~ s/%level/$values{'level'}/g;
|
---|
115 | $str =~ s/%next/$values{'next'}/g;
|
---|
116 | $str =~ s/%status/$values{'status'}/g;
|
---|
117 | $str =~ s/%uhost/$values{'host'}/g;
|
---|
118 | $str =~ s/%ca/$values{'created'}/g;
|
---|
119 | $str =~ s/%llo/$values{'lastlog'}/g;
|
---|
120 | $str =~ s/%ti/$values{'totalidle'}/g;
|
---|
121 | if ($str =~ /%penalties/) {
|
---|
122 | my @penaltyname = qw(msg nick part kick quit quest logout);
|
---|
123 | my @penaltytime = @ent[7 .. 13];
|
---|
124 | for my $t (0 .. $#penaltytime) { $penaltytime[$t] = time_to($penaltytime[$t]); }
|
---|
125 | my $cols = make_col(\@penaltyname, \@penaltytime, 3);
|
---|
126 | $str =~ s/%penalties/$cols/g;
|
---|
127 | }
|
---|
128 | if ($str =~ /%items/) {
|
---|
129 | my @itemname = qw(amulet charm helm boots gloves ring leggings shield tunic weapon sum);
|
---|
130 | my @itemlvls = @ent[16 .. 25];
|
---|
131 | # Yay, lets get a nice sum(sum) in output! :D
|
---|
132 | my $sum; map($sum += $_, @itemlvls);
|
---|
133 | my $cols = make_col(\@itemname, [ @itemlvls, $sum ], 3);
|
---|
134 | $str =~ s/%items/$cols/g;
|
---|
135 | }
|
---|
136 | $str =~ s///g;
|
---|
137 | $str =~ s///g;
|
---|
138 | print "$str\n";
|
---|
139 | }
|
---|
140 |
|
---|
141 | print "\n" if @ARGV != 0;
|
---|
142 | goto start if @ARGV != 0;
|
---|