ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/dm-support.ext
Revision: 1.8
Committed: Tue Aug 28 19:30:09 2007 UTC (16 years, 9 months ago) by root
Branch: MAIN
CVS Tags: rel-2_2
Changes since 1.7: +1 -0 lines
Log Message:
lock map_data in addition to map_load when loading a map, possibly avoids the crash seen today

File Contents

# Content
1 #! perl
2
3 use IO::Socket;
4 use Storable qw/nfreeze thaw/;
5
6 my %global; # for use by eval'ed commands
7
8 sub tcp_serve($) {
9 my ($fh) = @_;
10
11 select $fh;
12
13 binmode $fh, ":raw:perlio:utf8";
14
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);
17 my (%l, @l); # for use by shell users
18
19 print <<EOF;
20 Welcome!
21 Remember that everything entered here will be in the main coro context within cf::!
22 You can freely use \$a .. \$z and \@l and \%l
23
24 Useful commands (note the '&'):
25
26 reload_perl &
27 reload_config &
28 reload_regions &
29 reload_facedata &
30 reload_treasures &
31 reload_archetypes &
32 ext::help::reload &
33 ext::books::reload &
34 ext::map_world::reload &
35 EOF
36 print "\n> ";
37
38 Event->io (fd => $fh, poll => 'r', data => 0, cb => sub {
39 if (defined (my $cmd = <$fh>)) {
40 $cmd =~ s/\s+$//;
41
42 if ($cmd =~ /^\s*exit\b/i) {
43 print "will not exit() server.\n";
44 } else {
45 my $sub = sub {
46 package cf;
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->();
69 }
70 }
71
72 print "\n> ";
73 } else {
74 $_[0]->w->cancel;
75 }
76 });
77 }
78
79 # now a shell listening on a tcp-port - let the firewall decide access rights
80 if ($cf::CFG{perl_shell}) {
81 if (my $listen = new IO::Socket::INET LocalAddr => $cf::CFG{perl_shell}, Listen => 1, ReuseAddr => 1) {
82 Event->io (fd => $listen, poll => 'r', data => cf::WF_AUTOCANCEL, cb => sub { tcp_serve $listen->accept });
83 }
84 }