| 1 | package BBS::UserInfo::Maple3itoc; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Expect; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | BBS::UserInfo::Maple3itoc - Get user information of Maple3itoc-style BBS | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | 1 | our $VERSION = '0.01'; | |||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | use BBS::UserInfo::Maple3itoc; | ||||||||||
| 20 | |||||||||||
| 21 | my $foo = BBS::UserInfo::Maple3itoc->new( | ||||||||||
| 22 | 'debug' => 1, | ||||||||||
| 23 | 'port' => 23, | ||||||||||
| 24 | 'server' => 'kulu.twbbs.org', | ||||||||||
| 25 | 'telnet' => '/usr/bin/telnet', | ||||||||||
| 26 | 'timeout' => 10 | ||||||||||
| 27 | ); | ||||||||||
| 28 | |||||||||||
| 29 | # connect to the server | ||||||||||
| 30 | $bot->connect() or die('Unable to connect BBS'); | ||||||||||
| 31 | |||||||||||
| 32 | my $userdata = $bot->query('username'); | ||||||||||
| 33 | |||||||||||
| 34 | # print some data | ||||||||||
| 35 | print($userdata->{'logintimes'}); | ||||||||||
| 36 | |||||||||||
| 37 | =head1 FUNCTIONS | ||||||||||
| 38 | |||||||||||
| 39 | =head2 new() | ||||||||||
| 40 | |||||||||||
| 41 | Create a BBS::UserInfo::Maple3itoc object, there are some parameters | ||||||||||
| 42 | that you can define: | ||||||||||
| 43 | |||||||||||
| 44 | server => 'kulu.twbbs.org' # Necessary, server name | ||||||||||
| 45 | port => 23 # Optional, server port | ||||||||||
| 46 | telnet => 'telnet' # Optional, telnet program | ||||||||||
| 47 | timeout => 10 # Optional, Expect timeout | ||||||||||
| 48 | debug => 1 # Optional, print debug information | ||||||||||
| 49 | |||||||||||
| 50 | =cut | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 53 | 0 | my ($class, %params) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 0 | my %self = ( | |||||||||
| 56 | 'debug' => 0, | ||||||||||
| 57 | 'password' => '', # incomplete function | ||||||||||
| 58 | 'port' => 23, | ||||||||||
| 59 | 'server' => undef, | ||||||||||
| 60 | 'telnet' => 'telnet', | ||||||||||
| 61 | 'timeout' => 10, | ||||||||||
| 62 | 'username' => 'guest' # incomplete function | ||||||||||
| 63 | ); | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | while (my ($k, $v) = each(%params)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | ▶ | $self{$k} = $v if (exists $self{$k}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | return bless(\%self, $class); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | =head2 connect() | ||||||||||
| 73 | |||||||||||
| 74 | Connect to the BBS server. | ||||||||||
| 75 | |||||||||||
| 76 | =cut | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub connect { | ||||||||
|
Subroutine
connect: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 79 | 0 | my $self = shift(); | |||||||||
| 80 | |||||||||||
| 81 | $self->{'expect'} = Expect->spawn($self->{'telnet'}, $self->{'server'}, | ||||||||||
| 82 | 0 | $self->{'port'}); | |||||||||
| 83 | 0 | $self->{'expect'}->log_stdout(0); | |||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | return undef unless (defined($self->_login($self))); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | |||||||||||
| 87 | 0 | return $self->{'expect'}; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | sub _login { | ||||||||
|
Subroutine
_login: not called CC=3 SCAR=24.8
| |||||||||||
| 91 | 0 | my $self = shift(); | |||||||||
| 92 | |||||||||||
| 93 | 0 | my $bot = $self->{'expect'}; | |||||||||
| 94 | 0 | my $debug = $self->{'debug'}; | |||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | print("Waiting for login\n") if ($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | $bot->expect($self->{'timeout'}, '-re', '±zªº±b¸¹'); | |||||||||
| 98 | 0 | ▶ | return undef if ($bot->error()); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | |||||||||||
| 100 | 0 | $bot->send($self->{'username'}, "\n[D[D[D[D"); | |||||||||
| 101 | 0 | return 1; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | =head2 query() | ||||||||||
| 105 | |||||||||||
| 106 | Query user information and return a hash reference with: | ||||||||||
| 107 | |||||||||||
| 108 | =over 4 | ||||||||||
| 109 | |||||||||||
| 110 | =item * nickname | ||||||||||
| 111 | |||||||||||
| 112 | =item * logintimes | ||||||||||
| 113 | |||||||||||
| 114 | =item * posttimes | ||||||||||
| 115 | |||||||||||
| 116 | =item * lastlogintime | ||||||||||
| 117 | |||||||||||
| 118 | =item * lastloginip | ||||||||||
| 119 | |||||||||||
| 120 | =back | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||
| 123 | |||||||||||
| 124 | 0 | ▶ | sub query { | ||||||||
|
Subroutine
query: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||
| 125 | 0 | my ($self, $user) = @_; | |||||||||
| 126 | |||||||||||
| 127 | 0 | my $bot = $self->{'expect'}; | |||||||||
| 128 | 0 | my $debug = $self->{'debug'}; | |||||||||
| 129 | 0 | my $timeout = $self->{'timeout'}; | |||||||||
| 130 | |||||||||||
| 131 | 0 | $bot->send("[D[Dt\nq\n", $user, "\n"); | |||||||||
| 132 | |||||||||||
| 133 | 0 | my %h; | |||||||||
| 134 | |||||||||||
| 135 | 0 | ▶ | print("Waiting for nickname, logintimes, and posttimes\n") if ($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 0 | $bot->expect($timeout, '-re', '\[¼ÊºÙ\]\s(.+?)\s+\[¤W¯¸\]\s*(\d+)\s*¦¸\s*\[¤å³¹\]\s*?(\d+)\s*½g'); | |||||||||
| 137 | 0 | $h{'nickname'} = ($bot->matchlist)[0]; | |||||||||
| 138 | 0 | $h{'logintimes'} = ($bot->matchlist)[1]; | |||||||||
| 139 | 0 | $h{'posttimes'} = ($bot->matchlist)[2]; | |||||||||
| 140 | 0 | ▶ | printf("nickname = %s\n", $h{'nickname'}) if ($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 0 | ▶ | printf("logintimes = %s\n", $h{'logintimes'}) if ($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | 0 | ▶ | printf("posttimes = %s\n", $h{'posttimes'}) if ($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | 0 | ▶ | return undef if ($bot->error()); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | |||||||||||
| 145 | 0 | ▶ | print("Waiting for lastelogintime and lastloginip\n") if ($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | 0 | $bot->expect($timeout, '-re', '\[¨Ó·½\]\s\((.+)\)\s([^ ]+)'); | |||||||||
| 147 | 0 | $h{'lastlogintime'} = ($bot->matchlist)[0]; | |||||||||
| 148 | 0 | $h{'lastloginip'} = ($bot->matchlist)[1]; | |||||||||
| 149 | 0 | ▶ | printf("lastlogintime = %s\n", $h{'lastlogintime'}) if ($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 150 | 0 | ▶ | printf("lastloginip = %s\n", $h{'lastloginip'}) if ($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 151 | 0 | ▶ | return undef if ($bot->error()); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | |||||||||||
| 153 | 0 | return \%h; | |||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | =head1 AUTHOR | ||||||||||
| 157 | |||||||||||
| 158 | Gea-Suan Lin, C<< <gslin at gslin.org> >> | ||||||||||
| 159 | |||||||||||
| 160 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 161 | |||||||||||
| 162 | Copyright 2006 Gea-Suan Lin, all rights reserved. | ||||||||||
| 163 | |||||||||||
| 164 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 165 | under the same terms as Perl itself. | ||||||||||
| 166 | |||||||||||
| 167 | =cut | ||||||||||
| 168 | |||||||||||
| 169 | 1 | 1; # End of BBS::UserInfo::Maple3itoc | |||||||||