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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines