1 |
#!/opt/bin/perl |
2 |
|
3 |
BEGIN { $ENV{PERL_RL} = "gnu" } use Term::ReadLine; # this suxx |
4 |
|
5 |
use AnyEvent; |
6 |
use Storable; |
7 |
use YAML; |
8 |
|
9 |
@ARGV == 5 or die "Usage: $0 host port login password dm-pass\n"; |
10 |
|
11 |
use base Deliantra::Protocol::Base; |
12 |
|
13 |
my $login = AnyEvent->condvar; |
14 |
my $quit = AnyEvent->condvar; |
15 |
my $rl = new Term::ReadLine "cfshell"; |
16 |
|
17 |
sub logged_in { |
18 |
my ($self) = @_; |
19 |
|
20 |
$login->broadcast; |
21 |
|
22 |
$self->send_command ("dmhide $ARGV[4]"); |
23 |
print "\nlogged in.\n"; |
24 |
} |
25 |
|
26 |
sub fatal { |
27 |
$rl->crlf; |
28 |
$rl->deprep_terminal; |
29 |
print "$_[0]\n"; |
30 |
exit 1; |
31 |
} |
32 |
|
33 |
sub eof { |
34 |
my ($self) = @_; |
35 |
|
36 |
fatal "server closed connection."; |
37 |
} |
38 |
|
39 |
sub query { |
40 |
my ($self, $flags, $prompt) = @_; |
41 |
fatal "unexpected prompt: $prompt"; |
42 |
} |
43 |
|
44 |
sub drawinfo { |
45 |
my ($self, $flags, $text) = @_; |
46 |
|
47 |
$rl->crlf; |
48 |
print "$text\n"; |
49 |
$rl->forced_update_display; |
50 |
} |
51 |
|
52 |
my $cf = new main |
53 |
host => $ARGV[0], |
54 |
port => $ARGV[1] || 13327, |
55 |
user => $ARGV[2], |
56 |
pass => $ARGV[3], |
57 |
mapw => 1, |
58 |
maph => 1; |
59 |
|
60 |
$login->wait; |
61 |
|
62 |
my $w = AnyEvent->io (fh => $rl->IN, poll => 'r', cb => sub { $rl->callback_read_char }); |
63 |
|
64 |
$rl->callback_handler_install ("$ARGV[0]> ", sub { |
65 |
$rl->add_history ($_[0]); |
66 |
$cf->send_ext_req (perl_eval => code => $_[0], sub { |
67 |
my ($msg) = @_; |
68 |
|
69 |
$rl->crlf; |
70 |
|
71 |
my ($status, $result) = split / /, $data, 2; |
72 |
if (exists $msg->{error}) { |
73 |
print "$msg->{error}\n"; |
74 |
} else { |
75 |
print Dump Storable::thaw $msg->{result}; |
76 |
} |
77 |
|
78 |
$rl->forced_update_display; |
79 |
}); |
80 |
}); |
81 |
|
82 |
$quit->wait; |
83 |
$rl->callback_handler_remove; |
84 |
|