ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/dm-support.ext
(Generate patch)

Comparing deliantra/server/ext/dm-support.ext (file contents):
Revision 1.9 by root, Thu Sep 13 08:35:24 2007 UTC vs.
Revision 1.35 by root, Tue Nov 6 23:33:15 2012 UTC

1#! perl 1#! perl
2 2
3use Coro::Debug;
3use IO::Socket; 4use IO::Socket;
4use Storable qw/nfreeze thaw/;
5 5
6my %global; # for use by eval'ed commands 6my %global; # for use by eval'ed commands
7 7
8sub tcp_serve($) { 8sub tcp_serve($) {
9 my ($fh) = @_; 9 my ($fh) = @_;
10
11 select $fh;
12 10
13 binmode $fh, ":raw:perlio:utf8"; 11 binmode $fh, ":raw:perlio:utf8";
14 12
15 my $buf; 13 my $buf;
16 my ($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s, $t, $u, $v, $w, $x, $y, $z); 14 my ($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s, $t, $u, $v, $w, $x, $y, $z);
17 my (%l, @l); # for use by shell users 15 my (%l, @l); # for use by shell users
18 16
19 print <<EOF; 17 print $fh <<EOF;
20Welcome! 18Welcome!
21Remember that everything entered here will be in the main coro context within cf::! 19Remember that everything entered here will be in the main coro context within cf::!
22You can freely use \$a .. \$z and \@l and \%l 20You can freely use \$a .. \$z and \@l and \%l
23 21
24Useful commands (note the '&'): 22Useful commands (note the '&'):
25 23
24reload_pod &
26reload_perl & 25reload_perl &
26reload_sound &
27reload_config & 27reload_config &
28reload_regions & 28reload_regions &
29reload_facedata & 29reload_facedata &
30reload_exp_table &
31reload_materials &
30reload_treasures & 32reload_treasures &
33reload_resources &
31reload_archetypes & 34reload_archetypes &
32ext::help::reload & 35ext::help::reload &
33ext::books::reload & 36ext::books::reload &
34ext::map_tags::reload & 37ext::map_tags::reload &
35ext::map_world::reload & 38ext::map_world::reload &
39ext::player_env::reload &
40ext::map_scheduler::reload &
41# ext::map_scheduler::loadall & # debugging only!
42until (Coro::AnyEvent::readable \$fh, 1) { Coro::Debug::command "ps" } &
43({mallinfo})
44({objinfo})
36EOF 45EOF
37 print "\n> "; 46 print $fh "\n> ";
38 47
39 Event->io (fd => $fh, poll => 'r', data => 0, cb => sub { 48 my $iow; $iow = AE::io $fh, 0, sub {
40 if (defined (my $cmd = <$fh>)) { 49 if (defined (my $cmd = <$fh>)) {
41 $cmd =~ s/\s+$//; 50 $cmd =~ s/\s+$//;
42 51
43 if ($cmd =~ /^\s*exit\b/i) { 52 if ($cmd =~ /^\s*exit\b/i) {
44 print "will not exit() server.\n"; 53 print $fh "will not exit() server.\n";
54 } elsif ($cmd =~ s/^coro\s+// or $cmd =~ /^(?:ps|bt\s)/) {
55 select $fh;
56 Coro::Debug::command $cmd;
57 select STDOUT;
45 } else { 58 } else {
46 my $sub = sub { 59 my $sub = sub {
47 package cf; 60 package cf;
48 select $fh; 61 select $fh;
49 62
50 # compile first, the execute, as Coro does not support switching in eval string 63 # compile first, then execute, as Coro does not support switching in eval string
51 my $cb = eval "sub { $cmd }"; 64 my $cb = eval "sub { $cmd \n}";
52 65
53 my $t1 = Time::HiRes::time; 66 my $t1 = Time::HiRes::time;
54 my @res = $@ ? () : eval { $cb->() }; 67 my @res = $@ ? () : eval { $cb->() };
55 my $t2 = Time::HiRes::time; 68 my $t2 = Time::HiRes::time;
56 69
57 print "\n", 70 print "\n",
58 "command: '$cmd'\n", 71 "command: '$cmd'\n",
59 "execution time: ", $t2 - $t1, "\n"; 72 "execution time: ", $t2 - $t1, "\n";
60 warn "evaluation error: $@" if $@;
61 print "evaluation error: $@\n" if $@; 73 print "evaluation error: $@\n" if $@;
62 print "result:\n", cf::dumpval @res > 1 ? \@res : $res[0] if @res; 74 print "result:\n", cf::dumpval @res > 1 ? \@res : $res[0] if @res;
63 print "\n> "; 75 print "\n> ";
76
77 select STDOUT;
64 }; 78 };
65 79
66 if ($cmd =~ s/\s*&$//) { 80 if ($cmd =~ s/\s*&$//) {
67 Coro::async { $sub->() }; 81 cf::async {
82 $Coro::current->desc ($cmd);
83 $sub->()
84 };
68 } else { 85 } else {
69 $sub->(); 86 $sub->();
70 } 87 }
71 } 88 }
72 89
73 print "\n> "; 90 print $fh "\n> ";
74 } else { 91 } else {
75 $_[0]->w->cancel; 92 undef $iow;
76 } 93 }
77 }); 94 };
78} 95}
96
97our $LISTENER;
79 98
80# now a shell listening on a tcp-port - let the firewall decide access rights 99# now a shell listening on a tcp-port - let the firewall decide access rights
81if ($cf::CFG{perl_shell}) { 100if ($cf::CFG{perl_shell}) {
82 if (my $listen = new IO::Socket::INET LocalAddr => $cf::CFG{perl_shell}, Listen => 1, ReuseAddr => 1) { 101 if (my $listen = new IO::Socket::INET LocalAddr => $cf::CFG{perl_shell}, Listen => 1, ReuseAddr => 1, Blocking => 0) {
83 Event->io (fd => $listen, poll => 'r', data => cf::WF_AUTOCANCEL, cb => sub { tcp_serve $listen->accept }); 102 $LISTENER = AE::io $listen, 0, sub { tcp_serve $listen->accept };
84 } 103 }
85} 104}
105

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines