ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/bin/cfshell
Revision: 1.1
Committed: Fri Jul 21 10:37:00 2006 UTC (17 years, 10 months ago) by root
Branch: MAIN
Log Message:
simple perl-shell for crossfire - useless as of today

File Contents

# User Rev Content
1 root 1.1 #!/opt/bin/perl
2    
3     use AnyEvent;
4     use Storable;
5     use YAML;
6    
7     @ARGV == 5 or die "Usage: $0 host port login password dm-pass\n";
8    
9     use base Crossfire::Protocol::Base;
10    
11     sub refresh;
12    
13     sub logged_in {
14     my ($self) = @_;
15    
16     $self->send_command ("dmhide $ARGV[4]");
17     print "\nlogged in.\n";
18     refresh;
19     }
20    
21     sub eof {
22     my ($self) = @_;
23    
24     print "\nserver closed connection.\n";
25     readline::ResetTTY ();
26     exit;
27     }
28    
29     my $cf = new main
30     host => $ARGV[0],
31     port => $ARGV[1] || 13327,
32     user => $ARGV[2],
33     pass => $ARGV[3],
34     mapw => 1,
35     maph => 1;
36    
37     #===========================================================================#
38     # very hackish non-blocking readline.
39    
40     BEGIN { $ENV{PERL_RL} = "Perl o=0" }
41     use Term::ReadLine;
42    
43     sub refresh {
44     $readline::force_redraw = 1;
45     readline::redisplay ();
46     }
47    
48     my $stdin = AnyEvent->condvar;
49    
50     my $w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub { $stdin->broadcast });
51    
52     sub Term::ReadLine::Tk::Tk_loop {
53     $stdin->wait;
54     $stdin = AnyEvent->condvar;
55     }
56    
57     sub Tk::DoOneEvent { }
58     sub Term::ReadLine::Tk::register_Tk { }
59    
60     $rl = new Term::ReadLine "mpg123sh";
61     $rl->tkRunning(1);
62    
63     while (defined (my $cmd = $rl->readline ("$ARGV[0]> "))) {
64     $cf->send_ext_req (perl_eval => $cmd, sub {
65     my ($data) = @_;
66    
67     print "\n";
68    
69     my ($status, $result) = split / /, $data, 2;
70     print "status: $status\n";
71     if ($status eq "ok") {
72     print Dump Storable::thaw $result;
73     } else {
74     $result =~ s/\n$//;
75     print "$result\n";
76     }
77     refresh;
78     });
79     }
80    
81     #===========================================================================#
82