… | |
… | |
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 | |
|
|
110 | use AnyEvent::Util (); |
109 | use AnyEvent::DNS; |
111 | use AnyEvent::DNS; |
110 | use AnyEvent::Socket (); |
112 | use AnyEvent::Socket (); |
111 | |
113 | |
112 | use Compress::LZF; |
114 | use Compress::LZF; |
|
|
115 | use JSON::XS; |
113 | |
116 | |
114 | use DC; |
117 | use DC; |
115 | BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$_[0]" unless $^S } } |
118 | |
|
|
119 | sub crash($;$) { |
|
|
120 | # nop during compiletime |
|
|
121 | } |
|
|
122 | |
|
|
123 | BEGIN { |
|
|
124 | $SIG{__DIE__} = sub { |
|
|
125 | return if $^S; |
|
|
126 | crash ("CRASH/DIE: $_[0]" => 1); |
|
|
127 | DC::fatal Carp::longmess "$_[0]"; |
|
|
128 | } |
|
|
129 | } |
|
|
130 | |
116 | use DC::OpenGL (); |
131 | use DC::OpenGL (); |
117 | use DC::Protocol; |
132 | use DC::Protocol; |
118 | use DC::DB; |
133 | use DC::DB; |
119 | use DC::UI; |
134 | use DC::UI; |
120 | use DC::UI::Canvas; |
135 | use DC::UI::Canvas; |
… | |
… | |
130 | |
145 | |
131 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
146 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
132 | $SIG{PIPE} = 'IGNORE'; |
147 | $SIG{PIPE} = 'IGNORE'; |
133 | |
148 | |
134 | $EV::DIED = sub { |
149 | $EV::DIED = sub { |
|
|
150 | crash ("CRASH/EV::DIED: $@" => 1); |
135 | DC::fatal Carp::longmess $@; |
151 | DC::fatal Carp::longmess $@; |
136 | }; |
152 | }; |
137 | |
153 | |
138 | my $MAX_FPS = 60; |
154 | my $MAX_FPS = 60; |
139 | |
155 | |
… | |
… | |
141 | |
157 | |
142 | our $LAST_REFRESH; |
158 | our $LAST_REFRESH; |
143 | our $NOW; |
159 | our $NOW; |
144 | |
160 | |
145 | our $CFG; |
161 | our $CFG; |
146 | our $CONN; |
|
|
147 | our $PROFILE; # current profile |
162 | our $PROFILE; # current profile |
148 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
163 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
149 | |
164 | |
150 | our $WANT_REFRESH; |
165 | our $WANT_REFRESH; |
151 | |
166 | |
… | |
… | |
159 | our $FULLSCREEN; |
174 | our $FULLSCREEN; |
160 | our $FONTSIZE; |
175 | our $FONTSIZE; |
161 | |
176 | |
162 | our $FONT_PROP; |
177 | our $FONT_PROP; |
163 | our $FONT_FIXED; |
178 | our $FONT_FIXED; |
|
|
179 | |
|
|
180 | our $CONN; |
164 | |
181 | |
165 | our $MAP; |
182 | our $MAP; |
166 | our $MAPMAP; |
183 | our $MAPMAP; |
167 | our $MAPWIDGET; |
184 | our $MAPWIDGET; |
168 | our $COMPLETER; |
185 | our $COMPLETER; |
… | |
… | |
210 | our $DEBUG_STATUS; |
227 | our $DEBUG_STATUS; |
211 | |
228 | |
212 | our $INV; |
229 | our $INV; |
213 | our $INVR; |
230 | our $INVR; |
214 | 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 | }; |
215 | |
260 | |
216 | ############################################################################# |
261 | ############################################################################# |
217 | |
262 | |
218 | sub status { |
263 | sub status { |
219 | $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]); |
… | |
… | |
806 | dc_connect $host, $port; |
851 | dc_connect $host, $port; |
807 | } |
852 | } |
808 | } |
853 | } |
809 | |
854 | |
810 | sub stop_game { |
855 | sub stop_game { |
|
|
856 | crash "stop_game"; |
|
|
857 | |
811 | $LOGIN_BUTTON->set_text ("Login / Register"); |
858 | $LOGIN_BUTTON->set_text ("Login / Register"); |
812 | $SETUP_NOTEBOOK->set_current_page ($SETUP_LOGIN); |
859 | $SETUP_NOTEBOOK->set_current_page ($SETUP_LOGIN); |
813 | $SETUP_DIALOG->show; |
860 | $SETUP_DIALOG->show; |
814 | $PL_WINDOW->hide; |
861 | $PL_WINDOW->hide; |
815 | $SPELL_LIST->clear_spells; |
862 | $SPELL_LIST->clear_spells; |
… | |
… | |
2132 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
2179 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
2133 | ); |
2180 | ); |
2134 | $hb->add (new DC::UI::Button |
2181 | $hb->add (new DC::UI::Button |
2135 | text => "Quit anyway", |
2182 | text => "Quit anyway", |
2136 | expand => 1, |
2183 | expand => 1, |
2137 | on_activate => sub { EV::unloop EV::UNLOOP_ALL }, |
2184 | on_activate => sub { |
|
|
2185 | crash "Quit anyway"; |
|
|
2186 | EV::unloop EV::UNLOOP_ALL; |
|
|
2187 | }, |
2138 | ); |
2188 | ); |
2139 | } |
2189 | } |
2140 | |
2190 | |
2141 | $QUIT_DIALOG->show; |
2191 | $QUIT_DIALOG->show; |
2142 | $QUIT_DIALOG->grab_focus; |
2192 | $QUIT_DIALOG->grab_focus; |
… | |
… | |
2480 | delete $animate_object{$widget}; |
2530 | delete $animate_object{$widget}; |
2481 | } |
2531 | } |
2482 | |
2532 | |
2483 | %SDL_CB = ( |
2533 | %SDL_CB = ( |
2484 | DC::SDL_QUIT => sub { |
2534 | DC::SDL_QUIT => sub { |
|
|
2535 | crash "SDL_QUIT"; |
2485 | EV::unloop EV::UNLOOP_ALL; |
2536 | EV::unloop EV::UNLOOP_ALL; |
2486 | }, |
2537 | }, |
2487 | DC::SDL_VIDEORESIZE => sub { |
2538 | DC::SDL_VIDEORESIZE => sub { |
2488 | }, |
2539 | }, |
2489 | DC::SDL_VIDEOEXPOSE => sub { |
2540 | DC::SDL_VIDEOEXPOSE => sub { |