ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/dm-support.ext
Revision: 1.7
Committed: Mon Oct 2 16:55:35 2006 UTC (17 years, 7 months ago) by root
Branch: MAIN
Changes since 1.6: +4 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 #! perl
2    
3 root 1.5 use IO::Socket;
4 root 1.2 use Storable qw/nfreeze thaw/;
5 elmex 1.1
6 root 1.2 my %global; # for use by eval'ed commands
7    
8 root 1.5 sub tcp_serve($) {
9     my ($fh) = @_;
10 root 1.2
11 root 1.5 binmode $fh, ":raw:perlio:utf8";
12 root 1.2
13 root 1.5 my $buf;
14     my ($a,$b,$c,$d,%l,@l); # for use by shell users
15 root 1.2
16 root 1.5 print $fh "Welcome\n> ";
17    
18     Event->io (fd => $fh, poll => 'r', cb => sub {
19     if (defined (my $cmd = <$fh>)) {
20     my $old_fh = select $fh;
21    
22     if ($cmd =~ /^\s*exit\b/i) {
23     print "will not exit() server.\n";
24     } else {
25     {
26     package cf;
27     eval $cmd;
28     }
29     print $@ if $@;
30     }
31    
32 root 1.6 print "> ";
33 root 1.5 select $old_fh;
34     } else {
35     $_[0]->w->cancel;
36     }
37     });
38     }
39    
40     # now a shell listening on a tcp-port - let the firewall decide access rights
41 root 1.7 if ($cf::CFG{perl_shell}) {
42     if (my $listen = new IO::Socket::INET LocalAddr => $cf::CFG{perl_shell}, Listen => 1, ReuseAddr => 1) {
43     Event->io (fd => $listen, poll => 'r', cb => sub { tcp_serve $listen->accept });
44     }
45 root 1.5 }