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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines