… | |
… | |
97 | |
97 | |
98 | # need to do it again because that pile of garbage called PAR nukes it before main |
98 | # need to do it again because that pile of garbage called PAR nukes it before main |
99 | unshift @INC, $ENV{PAR_TEMP} |
99 | unshift @INC, $ENV{PAR_TEMP} |
100 | if %PAR::LibCache; |
100 | if %PAR::LibCache; |
101 | |
101 | |
102 | use Time::HiRes 'time'; |
|
|
103 | use EV; |
102 | use EV; |
|
|
103 | BEGIN { *time = \&EV::time } |
|
|
104 | |
104 | use List::Util qw(max min); |
105 | use List::Util qw(max min); |
105 | |
106 | |
106 | use Deliantra; |
107 | use Deliantra; |
107 | use Deliantra::Protocol::Constants; |
108 | use Deliantra::Protocol::Constants; |
108 | |
109 | |
… | |
… | |
113 | use Compress::LZF; |
114 | use Compress::LZF; |
114 | use JSON::XS; |
115 | use JSON::XS; |
115 | |
116 | |
116 | use DC; |
117 | use DC; |
117 | |
118 | |
118 | ############################################################################# |
|
|
119 | |
|
|
120 | our $CONN; |
|
|
121 | |
|
|
122 | # write a crash message blockingly to the socket, if possible |
|
|
123 | # this is a bit too complicated for my tastes, but it was easy. |
|
|
124 | sub crash($;$) { |
119 | sub crash($;$) { |
125 | my ($msg, $backtrace) = @_; |
120 | # nop during compiletime |
126 | |
|
|
127 | return unless $CONN; |
|
|
128 | |
|
|
129 | my $fh = $CONN->{fh} |
|
|
130 | or return; |
|
|
131 | |
|
|
132 | my $buf = delete $CONN->{wbuf}; |
|
|
133 | |
|
|
134 | $buf .= pack "n/a*", "exti " . JSON::XS::encode_json [clientlog => undef, substr $msg, 0, 8000]; |
|
|
135 | |
|
|
136 | AnyEvent::Util::fh_nonblocking $fh, 0; |
|
|
137 | |
|
|
138 | syswrite $fh, $buf; |
|
|
139 | AnyEvent::Util::fh_nonblocking $fh, 1; |
|
|
140 | |
|
|
141 | $msg =~ s/\s+$//; |
|
|
142 | |
|
|
143 | # backtrace as second step, in case it crashes, too |
|
|
144 | crash (Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") |
|
|
145 | if $backtrace; |
|
|
146 | } |
121 | } |
147 | |
|
|
148 | ############################################################################# |
|
|
149 | |
122 | |
150 | BEGIN { |
123 | BEGIN { |
151 | $SIG{__DIE__} = sub { |
124 | $SIG{__DIE__} = sub { |
152 | return if $^S; |
125 | return if $^S; |
153 | crash ("CRASH/DIE: $_[0]" => 1); |
126 | crash ("CRASH/DIE: $_[0]" => 1); |
… | |
… | |
202 | our $FONTSIZE; |
175 | our $FONTSIZE; |
203 | |
176 | |
204 | our $FONT_PROP; |
177 | our $FONT_PROP; |
205 | our $FONT_FIXED; |
178 | our $FONT_FIXED; |
206 | |
179 | |
|
|
180 | our $CONN; |
|
|
181 | |
207 | our $MAP; |
182 | our $MAP; |
208 | our $MAPMAP; |
183 | our $MAPMAP; |
209 | our $MAPWIDGET; |
184 | our $MAPWIDGET; |
210 | our $COMPLETER; |
185 | our $COMPLETER; |
211 | our $BUTTONBAR; |
186 | our $BUTTONBAR; |
… | |
… | |
252 | our $DEBUG_STATUS; |
227 | our $DEBUG_STATUS; |
253 | |
228 | |
254 | our $INV; |
229 | our $INV; |
255 | our $INVR; |
230 | our $INVR; |
256 | our $INVR_HB; |
231 | our $INVR_HB; |
|
|
232 | |
|
|
233 | ############################################################################# |
|
|
234 | |
|
|
235 | # write a crash message blockingly to the socket, if possible |
|
|
236 | # this is a bit too complicated for my tastes, but it was easy. |
|
|
237 | *crash = sub($;$) { |
|
|
238 | my ($msg, $backtrace) = @_; |
|
|
239 | |
|
|
240 | return unless $CONN; |
|
|
241 | |
|
|
242 | my $fh = $CONN->{fh} |
|
|
243 | or return; |
|
|
244 | |
|
|
245 | my $buf = delete $CONN->{wbuf}; |
|
|
246 | |
|
|
247 | $buf .= pack "n/a*", "exti " . JSON::XS::encode_json [clientlog => undef, substr $msg, 0, 8000]; |
|
|
248 | |
|
|
249 | AnyEvent::Util::fh_nonblocking $fh, 0; |
|
|
250 | |
|
|
251 | syswrite $fh, $buf; |
|
|
252 | AnyEvent::Util::fh_nonblocking $fh, 1; |
|
|
253 | |
|
|
254 | $msg =~ s/\s+$//; |
|
|
255 | |
|
|
256 | # backtrace as second step, in case it crashes, too |
|
|
257 | crash (Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") |
|
|
258 | if $backtrace; |
|
|
259 | }; |
257 | |
260 | |
258 | ############################################################################# |
261 | ############################################################################# |
259 | |
262 | |
260 | sub status { |
263 | sub status { |
261 | $STATUSBOX->add (DC::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
264 | $STATUSBOX->add (DC::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |