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.2 by root, Tue Jan 9 15:36:18 2007 UTC vs.
Revision 1.5 by root, Wed Apr 18 14:24:09 2007 UTC

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 10
11 select $fh;
12
11 binmode $fh, ":raw:perlio:utf8"; 13 binmode $fh, ":raw:perlio:utf8";
12 14
13 my $buf; 15 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); 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);
15 my (%l, @l); # for use by shell users 17 my (%l, @l); # for use by shell users
16 18
17 print $fh "Welcome!\n", 19 print <<EOF;
18 "Remember that everything entered here will be executed as a sync_job in cf::!\n", 20Welcome!
21Remember 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"; 22You can freely use \$a .. \$z and \@l and \%l
20 print $fh "\n> ";
21 23
24Useful commands (note the '&'):
25
26reload_perl &
27reload_regions &
28reload_facedata &
29reload_treasures &
30reload_archetypes &
31ext::map_world::reload &
32EOF
33 print "\n> ";
34
22 Event->io (fd => $fh, poll => 'r', data => cf::WF_AUTOCANCEL, cb => sub { 35 Event->io (fd => $fh, poll => 'r', data => 0, cb => sub {
23 if (defined (my $cmd = <$fh>)) { 36 if (defined (my $cmd = <$fh>)) {
24 my $old_fh = select $fh; 37 $cmd =~ s/\s+$//;
25 38
26 if ($cmd =~ /^\s*exit\b/i) { 39 if ($cmd =~ /^\s*exit\b/i) {
27 print "will not exit() server.\n"; 40 print "will not exit() server.\n";
28 } else { 41 } else {
29 cf::sync_job { 42 my $sub = sub {
30 package cf; 43 package cf;
31 my @res = eval $cmd; 44 select $fh;
32 warn "tcpshell evaluation error: $@" if $@;
33 print $@ if $@;
34 45
46 # compile first, the execute, as Coro does not support switching in eval string
47 my $cb = eval "sub { $cmd }";
48
49 my $t1 = Time::HiRes::time;
50 my @res = $@ ? () : eval { $cb->() };
51 my $t2 = Time::HiRes::time;
52
53 print "\n",
54 "command: '$cmd'\n",
55 "execution time: ", $t2 - $t1, "\n";
56 warn "evaluation error: $@" if $@;
57 print "evaluation error: $@\n" if $@;
35 print cf::dumpval @res > 1 ? \@res : $res[0] if @res; 58 print "result:\n", cf::dumpval @res > 1 ? \@res : $res[0] if @res;
59 print "\n> ";
36 }; 60 };
61
62 if ($cmd =~ s/\s*&$//) {
63 Coro::async_pool { $sub->() };
64 } else {
65 $sub->();
66 }
37 } 67 }
38 68
39 print "\n> "; 69 print "\n> ";
40 select $old_fh;
41 } else { 70 } else {
42 $_[0]->w->cancel; 71 $_[0]->w->cancel;
43 } 72 }
44 }); 73 });
45} 74}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines