ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/bin/cfshell
Revision: 1.4
Committed: Thu Aug 3 10:51:27 2006 UTC (17 years, 10 months ago) by root
Branch: MAIN
CVS Tags: rel-0_92, rel-0_91, rel-0_96, rel-0_97, rel-0_98, rel-0_99, rel-1_11, rel-1_13, rel-1_12, rel-2_2, rel-2_0, rel-2_1, rel-1_1, rel-1_0, rel-0_9
Changes since 1.3: +5 -7 lines
Log Message:
*** empty log message ***

File Contents

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