… | |
… | |
17 | die if $@; |
17 | die if $@; |
18 | } |
18 | } |
19 | |
19 | |
20 | use common::sense; |
20 | use common::sense; |
21 | use Carp 'verbose'; |
21 | use Carp 'verbose'; |
|
|
22 | use Cwd (); |
|
|
23 | use Digest::MD5 (); |
22 | use EV; |
24 | use EV; |
23 | BEGIN { *time = \&EV::time } |
25 | BEGIN { *time = \&EV::time } |
24 | |
26 | |
25 | use List::Util qw(max min); |
27 | use List::Util qw(max min); |
26 | |
28 | |
27 | use Deliantra; |
29 | use Deliantra; |
|
|
30 | use Deliantra::Util; |
28 | use Deliantra::Protocol::Constants; |
31 | use Deliantra::Protocol::Constants; |
29 | |
32 | |
30 | use AnyEvent::Util (); |
33 | use AnyEvent::Util (); |
31 | use AnyEvent::Socket (); |
34 | use AnyEvent::Socket (); |
32 | use AnyEvent::DNS (); |
35 | use AnyEvent::DNS (); |
33 | |
36 | |
34 | use Compress::LZF; |
37 | use Compress::LZF; |
35 | use JSON::XS; |
38 | use JSON::XS; |
|
|
39 | use Urlader; |
36 | |
40 | |
37 | use DC; |
41 | use DC; |
38 | |
42 | |
39 | sub crash($;$) { |
43 | sub crash($;$) { |
40 | # nop at compiletime |
44 | # nop at compiletime |
41 | } |
45 | } |
42 | |
46 | |
43 | BEGIN { |
47 | BEGIN { |
44 | $SIG{__DIE__} = sub { |
48 | $SIG{__DIE__} = sub { |
45 | return if $^S; |
49 | return if $^S; # quick reject |
|
|
50 | |
|
|
51 | # return if there are any eval contexts in the call stack |
|
|
52 | for my $i (0..999) { |
|
|
53 | my ($sub, $is_require) = (caller $i)[3, 7] |
|
|
54 | or last; |
|
|
55 | return if $sub eq "(eval)" && !$is_require; |
|
|
56 | } |
|
|
57 | |
46 | crash "CRASH/DIE: $_[0]" => 1; |
58 | crash "CRASH/DIE: $_[0]" => 1; |
47 | DC::fatal Carp::longmess "$_[0]"; |
59 | DC::fatal Carp::longmess "$_[0]"; |
48 | } |
60 | } |
49 | } |
61 | } |
50 | |
62 | |
51 | use DC::OpenGL (); |
63 | use DC::OpenGL (); |
|
|
64 | use DC::Audio (); |
52 | use DC::Protocol; |
65 | use DC::Protocol; |
53 | use DC::DB; |
66 | use DC::DB; |
54 | use DC::UI; |
67 | use DC::UI; |
55 | use DC::UI::Canvas; |
68 | use DC::UI::Canvas; |
56 | use DC::UI::Inventory; |
69 | use DC::UI::Inventory; |
… | |
… | |
116 | our $MENUBAR; # the hbox at the top |
129 | our $MENUBAR; # the hbox at the top |
117 | our $MENUPOPUP; |
130 | our $MENUPOPUP; |
118 | our $BUTTONBAR; # the menu buttons |
131 | our $BUTTONBAR; # the menu buttons |
119 | our $METASERVER; |
132 | our $METASERVER; |
120 | our $LOGIN_BUTTON; |
133 | our $LOGIN_BUTTON; |
|
|
134 | our $LOGIN_ERROR; |
121 | our $QUIT_DIALOG; |
135 | our $QUIT_DIALOG; |
122 | our $HOST_ENTRY; |
136 | our $HOST_ENTRY; |
123 | our $FULLSCREEN_ENABLE; |
137 | our $FULLSCREEN_ENABLE; |
124 | our $PICKUP_ENABLE; |
138 | our $PICKUP_ENABLE; |
125 | our $SERVER_INFO; |
139 | our $SERVER_INFO; |
… | |
… | |
133 | our $PL_NOTEBOOK; |
147 | our $PL_NOTEBOOK; |
134 | our $PL_WINDOW; |
148 | our $PL_WINDOW; |
135 | |
149 | |
136 | our $MUSIC_PLAYING_WIDGET; |
150 | our $MUSIC_PLAYING_WIDGET; |
137 | our $LICENSE_WIDGET; |
151 | our $LICENSE_WIDGET; |
|
|
152 | our $DOWNLOADS_WIDGET; |
138 | |
153 | |
139 | our $PICKUP_PAGE; |
154 | our $PICKUP_PAGE; |
140 | our $INVENTORY_PAGE; |
155 | our $INVENTORY_PAGE; |
141 | our $STATS_PAGE; |
156 | our $STATS_PAGE; |
142 | our $SKILL_PAGE; |
157 | our $SKILL_PAGE; |
… | |
… | |
185 | AnyEvent::Util::fh_nonblocking $fh, 1; |
200 | AnyEvent::Util::fh_nonblocking $fh, 1; |
186 | |
201 | |
187 | $msg =~ s/\s+$//; |
202 | $msg =~ s/\s+$//; |
188 | |
203 | |
189 | # backtrace as second step, in case it crashes, too |
204 | # backtrace as second step, in case it crashes, too |
190 | crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" |
205 | crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated" |
191 | if $backtrace; |
206 | if $backtrace; |
192 | }; |
207 | }; |
193 | |
208 | |
194 | sub clienterror($;$) { |
209 | sub clienterror($;$) { |
195 | my ($msg, $backtrace) = @_; |
210 | my ($msg, $backtrace) = @_; |
… | |
… | |
197 | warn $msg; |
212 | warn $msg; |
198 | |
213 | |
199 | return unless $CONN; |
214 | return unless $CONN; |
200 | |
215 | |
201 | $CONN->send_exti_msg (clientlog => $msg); |
216 | $CONN->send_exti_msg (clientlog => $msg); |
202 | $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace; |
217 | $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated") if $backtrace; |
203 | } |
218 | } |
204 | |
219 | |
205 | ############################################################################# |
220 | ############################################################################# |
206 | |
221 | |
207 | sub status { |
222 | sub status { |
… | |
… | |
238 | : "[<span foreground='#888'>num</span>]"; |
253 | : "[<span foreground='#888'>num</span>]"; |
239 | |
254 | |
240 | # <tt> around next statement works around some bug that keeps the |
255 | # <tt> around next statement works around some bug that keeps the |
241 | # "font =>" from being used on windows |
256 | # "font =>" from being used on windows |
242 | $MODBOX->set_markup ("<tt>$markup</tt>"); |
257 | $MODBOX->set_markup ("<tt>$markup</tt>"); |
|
|
258 | } |
|
|
259 | |
|
|
260 | sub errorbox { |
|
|
261 | my ($msg) = @_; |
|
|
262 | |
|
|
263 | status $msg; |
|
|
264 | |
|
|
265 | my $dialog = new DC::UI::Toplevel |
|
|
266 | x => "center", |
|
|
267 | y => "center", |
|
|
268 | z => 200, |
|
|
269 | title => "Error", |
|
|
270 | child => my $vbox = new DC::UI::VBox, |
|
|
271 | has_close_button => 1, |
|
|
272 | on_delete => sub { |
|
|
273 | $_[0]->destroy; |
|
|
274 | }, |
|
|
275 | ; |
|
|
276 | |
|
|
277 | add $vbox new DC::UI::Label |
|
|
278 | align => 0.5, |
|
|
279 | ellipsise => 0, |
|
|
280 | text => $msg; |
|
|
281 | |
|
|
282 | add $vbox new DC::UI::Button |
|
|
283 | expand => 1, |
|
|
284 | text => "OK", |
|
|
285 | on_activate => sub { |
|
|
286 | $dialog->destroy; |
|
|
287 | 0 |
|
|
288 | } |
|
|
289 | ; |
|
|
290 | |
|
|
291 | $dialog->show; |
243 | } |
292 | } |
244 | |
293 | |
245 | ############################################################################# |
294 | ############################################################################# |
246 | #TODO: maybe move into own audio module... |
295 | #TODO: maybe move into own audio module... |
247 | |
296 | |
… | |
… | |
462 | audio_music_push; |
511 | audio_music_push; |
463 | } |
512 | } |
464 | |
513 | |
465 | sub audio_init { |
514 | sub audio_init { |
466 | if ($CFG->{audio_enable}) { |
515 | if ($CFG->{audio_enable}) { |
467 | if (length $CFG->{audio_driver}) { |
516 | DC::Audio::init $CFG->{audio_driver}; |
468 | local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver}; |
|
|
469 | DC::SDL_Init DC::SDL_INIT_AUDIO |
|
|
470 | and die "SDL::Init failed!\n"; |
|
|
471 | } else { |
|
|
472 | DC::SDL_Init DC::SDL_INIT_AUDIO |
|
|
473 | and die "SDL::Init failed!\n"; |
|
|
474 | } |
|
|
475 | |
|
|
476 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
|
|
477 | $SDL_MIXER = !DC::Mix_OpenAudio |
|
|
478 | $CFG->{audio_hw_frequency}, |
|
|
479 | DC::MIX_DEFAULT_FORMAT, |
|
|
480 | $CFG->{audio_hw_channels}, |
|
|
481 | $CFG->{audio_hw_chunksize}; |
|
|
482 | |
517 | |
483 | if ($SDL_MIXER) { |
518 | if ($SDL_MIXER) { |
484 | DC::Mix_AllocateChannels $CFG->{audio_mix_channels}; |
|
|
485 | |
|
|
486 | audio_music_finished; |
519 | audio_music_finished; |
487 | } else { |
520 | } else { |
488 | status "Unable to open sound device: there will be no sound"; |
521 | status "Unable to open sound device: there will be no sound"; |
489 | } |
522 | } |
490 | } else { |
523 | } else { |
… | |
… | |
512 | |
545 | |
513 | DC::Mix_CloseAudio if $SDL_MIXER; |
546 | DC::Mix_CloseAudio if $SDL_MIXER; |
514 | undef $SDL_MIXER; |
547 | undef $SDL_MIXER; |
515 | |
548 | |
516 | DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; |
549 | DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; |
|
|
550 | } |
|
|
551 | |
|
|
552 | ############################################################################# |
|
|
553 | # Over-the-air updates |
|
|
554 | |
|
|
555 | sub ota_update { |
|
|
556 | my ($face, $size, $md5) = @_; |
|
|
557 | |
|
|
558 | my $coro = Coro::async_pool { |
|
|
559 | my $override = "$Urlader::EXE_DIR/override"; |
|
|
560 | |
|
|
561 | $MESSAGE_DIST->add_channel ({ |
|
|
562 | id => "ota_update", |
|
|
563 | title => "Update", |
|
|
564 | tooltip => "<b>Software Update Log</b>", |
|
|
565 | }); |
|
|
566 | |
|
|
567 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." }); |
|
|
568 | |
|
|
569 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777; |
|
|
570 | |
|
|
571 | unless ($fh) { |
|
|
572 | $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") }); |
|
|
573 | return; |
|
|
574 | } |
|
|
575 | |
|
|
576 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." }); |
|
|
577 | |
|
|
578 | my $cv = AE::cv; |
|
|
579 | my $error; |
|
|
580 | |
|
|
581 | $cv->begin (Coro::rouse_cb); |
|
|
582 | $CONN->ask_face ( |
|
|
583 | $face, |
|
|
584 | -1000, |
|
|
585 | sub { |
|
|
586 | $STATUSBOX->add ( |
|
|
587 | (sprintf "update download: %d/%d", $size - $_[1], $size), |
|
|
588 | pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1] |
|
|
589 | ); |
|
|
590 | |
|
|
591 | $cv->begin; |
|
|
592 | my $len = length $_[2]; |
|
|
593 | IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub { |
|
|
594 | $error ||= $_[0] != $len; |
|
|
595 | $cv->end; |
|
|
596 | }; |
|
|
597 | }, |
|
|
598 | sub { |
|
|
599 | $cv->end; |
|
|
600 | }, |
|
|
601 | ); |
|
|
602 | |
|
|
603 | Coro::rouse_wait; |
|
|
604 | |
|
|
605 | $STATUSBOX->clr_group ("ota_update"); |
|
|
606 | |
|
|
607 | $error ||= Coro::AIO::aio_fsync $fh; |
|
|
608 | $error ||= Coro::AIO::aio_close $fh; |
|
|
609 | |
|
|
610 | if ($error) { |
|
|
611 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." }); |
|
|
612 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
613 | return; |
|
|
614 | } |
|
|
615 | |
|
|
616 | { |
|
|
617 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "verifying update file..." }); |
|
|
618 | |
|
|
619 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0; |
|
|
620 | |
|
|
621 | if ($fh) { |
|
|
622 | $error ||= Coro::AIO::aio_stat "$override.tmp"; |
|
|
623 | $error ||= -s _ != $size; |
|
|
624 | Coro::AIO::aio_readahead $fh, 0, $size; |
|
|
625 | |
|
|
626 | my $f_md5 = new Digest::MD5; |
|
|
627 | binmode $fh; # ugh :( |
|
|
628 | $f_md5->addfile ($fh); |
|
|
629 | $f_md5 = $f_md5->hexdigest; |
|
|
630 | $error ||= $md5 ne $f_md5; |
|
|
631 | } |
|
|
632 | } |
|
|
633 | |
|
|
634 | if ($error) { |
|
|
635 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "verification failed, update aborted." }); |
|
|
636 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
637 | return; |
|
|
638 | } |
|
|
639 | |
|
|
640 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." }); |
|
|
641 | |
|
|
642 | if (Coro::AIO::aio_rename "$override.tmp", $override) { |
|
|
643 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." }); |
|
|
644 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
645 | } |
|
|
646 | |
|
|
647 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." }); |
|
|
648 | }; |
|
|
649 | |
|
|
650 | $CONN->{ota_update} = Guard::guard { |
|
|
651 | $coro->cancel; |
|
|
652 | }; |
|
|
653 | } |
|
|
654 | |
|
|
655 | sub ota_update_ask { |
|
|
656 | my ($ok, $face, $ver, $size, $md5, $changes) = @_; |
|
|
657 | |
|
|
658 | $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel |
|
|
659 | x => "center", |
|
|
660 | y => "center", |
|
|
661 | z => 55, |
|
|
662 | force_w => $::WIDTH * 0.7, |
|
|
663 | force_h => $::HEIGHT * 0.7, |
|
|
664 | title => "Software update available", |
|
|
665 | child => my $vbox = new DC::UI::VBox, |
|
|
666 | ; |
|
|
667 | |
|
|
668 | $vbox->add (new DC::UI::Label |
|
|
669 | ellipsise => 0, |
|
|
670 | text => "The server offers a software update, " |
|
|
671 | . "do you want to start downloading this update in the background?", |
|
|
672 | ); |
|
|
673 | |
|
|
674 | $vbox->add (new DC::UI::FancyFrame |
|
|
675 | expand => 1, |
|
|
676 | label => "Details", |
|
|
677 | child => (new DC::UI::TextScroller |
|
|
678 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4, |
|
|
679 | par => [{ |
|
|
680 | markup => "<tt>Old revision: $Urlader::EXE_VER\n" |
|
|
681 | . "New revision: $ver\n" |
|
|
682 | . "Download size: $size bytes</tt>\n\n" |
|
|
683 | . "Changes:\n\n" |
|
|
684 | . DC::asxml $changes |
|
|
685 | }], |
|
|
686 | ), |
|
|
687 | ); |
|
|
688 | |
|
|
689 | $vbox->add (my $hbox = new DC::UI::HBox); |
|
|
690 | |
|
|
691 | $hbox->add (new DC::UI::Button |
|
|
692 | expand => 1, |
|
|
693 | text => "Not now", |
|
|
694 | on_activate => sub { |
|
|
695 | $dialog->destroy; |
|
|
696 | 0 |
|
|
697 | } |
|
|
698 | ); |
|
|
699 | $hbox->add (new DC::UI::Button |
|
|
700 | expand => 1, |
|
|
701 | text => "Yes, start downloading", |
|
|
702 | on_activate => sub { |
|
|
703 | $dialog->destroy; |
|
|
704 | ota_update $face, $size, $md5; |
|
|
705 | 0 |
|
|
706 | }, |
|
|
707 | ); |
|
|
708 | |
|
|
709 | $dialog->show; |
|
|
710 | } |
|
|
711 | |
|
|
712 | sub ota_update_check { |
|
|
713 | return unless defined $Urlader::EXE_ID; |
|
|
714 | |
|
|
715 | ::message { markup => "Checking for software update..." }; |
|
|
716 | |
|
|
717 | $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub { |
|
|
718 | my ($ok, $face, $ver, $size, $md5, $changes) = @_; |
|
|
719 | |
|
|
720 | if ($ok) { |
|
|
721 | if (defined $ver) { |
|
|
722 | ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." }; |
|
|
723 | &ota_update_ask; |
|
|
724 | } else { |
|
|
725 | ::message { markup => "Server has no newer version." }; |
|
|
726 | } |
|
|
727 | } else { |
|
|
728 | ::message { markup => "Server does not support software update." }; |
|
|
729 | } |
|
|
730 | |
|
|
731 | () |
|
|
732 | }); |
517 | } |
733 | } |
518 | |
734 | |
519 | ############################################################################# |
735 | ############################################################################# |
520 | |
736 | |
521 | sub destroy_query_dialog { |
737 | sub destroy_query_dialog { |
… | |
… | |
748 | $vbox->add (@dialog); |
964 | $vbox->add (@dialog); |
749 | $dialog->show; |
965 | $dialog->show; |
750 | } |
966 | } |
751 | |
967 | |
752 | sub dc_connect { |
968 | sub dc_connect { |
753 | my ($host, $port) = @_; |
969 | my ($host, $port, $create) = @_; |
754 | |
970 | |
755 | my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
971 | my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
756 | my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
972 | my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
757 | |
973 | |
758 | $CONN = |
974 | $CONN = |
759 | new DC::Protocol |
975 | new DC::Protocol |
760 | host => $host, |
976 | host => $host, |
761 | port => $port, |
977 | port => $port, |
|
|
978 | create_login => $create, |
762 | user => $PROFILE->{user}, |
979 | user => $PROFILE->{user}, |
763 | pass => $PROFILE->{password}, |
980 | pass => (pack "H*", $PROFILE->{password}), |
764 | mapw => $mapw, |
981 | mapw => $mapw, |
765 | maph => $maph, |
982 | maph => $maph, |
766 | |
983 | |
767 | c_version => { |
984 | c_version => { |
768 | client => "deliantra", |
985 | client => "deliantra", |
769 | clientver => $DC::VERSION, |
986 | clientver => "$DC::VERSION$Urlader::EXE_VER", |
770 | gl_vendor => DC::OpenGL::gl_vendor, |
987 | gl_vendor => DC::OpenGL::gl_vendor, |
771 | gl_version => DC::OpenGL::gl_version, |
988 | gl_version => DC::OpenGL::gl_version, |
772 | }, |
989 | }, |
773 | |
990 | |
774 | map_widget => $MAPWIDGET, |
991 | map_widget => $MAPWIDGET, |
… | |
… | |
783 | |
1000 | |
784 | on_connect => sub { |
1001 | on_connect => sub { |
785 | if ($_[0]) { |
1002 | if ($_[0]) { |
786 | DC::lowdelay fileno $CONN->{fh}; |
1003 | DC::lowdelay fileno $CONN->{fh}; |
787 | |
1004 | |
|
|
1005 | ota_update_check; |
|
|
1006 | |
788 | status "successfully connected to the server"; |
1007 | status "successfully connected to the server"; |
789 | } else { |
1008 | } else { |
790 | undef $CONN; |
1009 | undef $CONN; |
791 | status "unable to connect: $!"; |
1010 | $LOGIN_ERROR->{fg} = [1, 0, 0]; |
|
|
1011 | $LOGIN_ERROR->set_text ("Unable to connect to server: $!"); |
792 | stop_game(); |
1012 | stop_game(); |
793 | } |
1013 | } |
794 | }, |
1014 | }, |
|
|
1015 | |
|
|
1016 | on_addme => sub { |
|
|
1017 | my ($ok, $msg) = @_; |
|
|
1018 | |
|
|
1019 | $LOGIN_ERROR->{fg} = $ok ? [0, 1, 0] : [1, 0, 0]; |
|
|
1020 | $LOGIN_ERROR->set_text ($msg); |
|
|
1021 | }, |
795 | ; |
1022 | ; |
796 | } |
1023 | } |
797 | |
1024 | |
798 | sub start_game { |
1025 | sub start_game($) { |
|
|
1026 | my ($create) = @_; |
|
|
1027 | |
799 | status "logging in..."; |
1028 | status "logging in..."; |
800 | |
1029 | |
801 | my $server = $PROFILE->{host} || $DEFAULT_SERVER; |
1030 | my $server = $PROFILE->{host} || $DEFAULT_SERVER; |
802 | my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" |
1031 | my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" |
803 | or return status "$server: unable to parse server address, try an empty field."; |
1032 | or return status "$server: unable to parse server address, try an empty field."; |
… | |
… | |
818 | status "dns failure, using hardcoded address"; |
1047 | status "dns failure, using hardcoded address"; |
819 | $host = "194.126.175.154"; |
1048 | $host = "194.126.175.154"; |
820 | } |
1049 | } |
821 | } |
1050 | } |
822 | |
1051 | |
823 | dc_connect $host, $port; |
1052 | dc_connect $host, $port, $create; |
824 | }; |
1053 | }; |
825 | } else { |
1054 | } else { |
826 | dc_connect $host, $port; |
1055 | dc_connect $host, $port, $create; |
827 | } |
1056 | } |
828 | } |
1057 | } |
829 | |
1058 | |
830 | sub stop_game { |
1059 | sub stop_game { |
831 | crash "stop_game"; |
1060 | crash "stop_game"; |
… | |
… | |
1131 | text => $CFG->{audio_driver}, |
1360 | text => $CFG->{audio_driver}, |
1132 | template => "dsound1234", |
1361 | template => "dsound1234", |
1133 | tooltip => "You can override the audio driver to use here. Leaving it empty will result " |
1362 | tooltip => "You can override the audio driver to use here. Leaving it empty will result " |
1134 | . "in Deliantra picking one automatically. GNU/Linux users often prefer specific " |
1363 | . "in Deliantra picking one automatically. GNU/Linux users often prefer specific " |
1135 | . "drivers though, and can experiment with <b>alsa</b>, <b>dsp</b>, <b>esd</b>, <b>pulse</b>, <b>arts</b>, <b>nas</b> " |
1364 | . "drivers though, and can experiment with <b>alsa</b>, <b>dsp</b>, <b>esd</b>, <b>pulse</b>, <b>arts</b>, <b>nas</b> " |
1136 | . "or other system-specific drivers. Selecting the wrong driver here will simply result" |
1365 | . "or other system-specific drivers. Selecting the wrong driver here will simply result " |
1137 | . "in no sound.", |
1366 | . "in no sound.", |
1138 | on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 } |
1367 | on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 } |
1139 | ); |
1368 | ); |
1140 | |
1369 | |
1141 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects"); |
1370 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects"); |
… | |
… | |
1664 | $vbox->add (new DC::UI::FancyFrame |
1893 | $vbox->add (new DC::UI::FancyFrame |
1665 | label => "Login Settings", |
1894 | label => "Login Settings", |
1666 | child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), |
1895 | child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), |
1667 | ); |
1896 | ); |
1668 | |
1897 | |
|
|
1898 | my $nullpw = "\x00" x 16; |
|
|
1899 | |
1669 | $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username"); |
1900 | $table->add_at (0, 0, new DC::UI::Label align => 1, text => "Username"); |
1670 | $table->add_at (1, 4, new DC::UI::Entry |
1901 | $table->add_at (1, 0, new DC::UI::Entry |
1671 | text => $PROFILE->{user}, |
1902 | text => $PROFILE->{user}, |
1672 | tooltip => "The name of your character on the server. The name is case-sensitive!", |
1903 | tooltip => "The name of your character on the server. The name is case-sensitive!", |
1673 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } |
1904 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } |
1674 | ); |
1905 | ); |
1675 | |
1906 | |
1676 | $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password"); |
1907 | $table->add_at (0, 1, new DC::UI::Label align => 1, text => "Password"); |
1677 | $table->add_at (1, 5, new DC::UI::Entry |
1908 | $table->add_at (1, 1, my $pw1 = new DC::UI::Entry |
1678 | text => $PROFILE->{password}, |
1909 | text => $PROFILE->{password} ? $nullpw : "", |
1679 | hidden => 1, |
1910 | hidden => 1, |
1680 | tooltip => "The password for your character.", |
1911 | tooltip => "The password for your character.", |
1681 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{password} = $value; 1 } |
1912 | on_focus_in => sub { |
|
|
1913 | my ($self) = @_; |
|
|
1914 | $self->set_text ("") |
|
|
1915 | if $self->{text} eq $nullpw; |
|
|
1916 | 0 |
|
|
1917 | }, |
|
|
1918 | on_changed => sub { |
|
|
1919 | my ($self, $value) = @_; |
|
|
1920 | $PROFILE->{password} = pack "H*", Deliantra::Util::hash_pw $value |
|
|
1921 | if length $value && $value ne $nullpw; |
|
|
1922 | 1 |
|
|
1923 | }, |
1682 | ); |
1924 | ); |
1683 | |
1925 | |
1684 | $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button |
1926 | $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button |
1685 | expand => 1, |
1927 | expand => 1, |
1686 | text => "Login / Register", |
1928 | text => "Login to Existing Account", |
1687 | tooltip => "This button will either login to the account configured above or register a new account.", |
1929 | tooltip => "This button will login to the account given by the <b>Username</b> and <b>Password</b> fields above.", |
1688 | on_activate => sub { |
1930 | on_activate => sub { |
1689 | $CONN ? stop_game |
1931 | $CONN ? stop_game |
1690 | : start_game; |
1932 | : start_game 0; |
1691 | 1 |
1933 | 1 |
1692 | }, |
1934 | }, |
1693 | ); |
1935 | ); |
1694 | |
1936 | |
|
|
1937 | $table->add_at (0, 3, new DC::UI::Label align => 1, text => "Password"); |
|
|
1938 | $table->add_at (1, 3, my $pw2 = new DC::UI::Entry |
|
|
1939 | hidden => 1, |
|
|
1940 | tooltip => "The new password for your character", |
|
|
1941 | ); |
|
|
1942 | |
|
|
1943 | $table->add_at (1, 4, new DC::UI::Button |
|
|
1944 | expand => 1, |
|
|
1945 | text => "Create New Account", |
|
|
1946 | tooltip => "This button will try to create a new account - you need to fill out the <b>Username</b> and the two <b>Password</b> fields above, using the same password for both <b>Password</b> fields.", |
|
|
1947 | on_activate => sub { |
|
|
1948 | if ($pw1->{text} ne $pw2->{text}) { |
|
|
1949 | $LOGIN_ERROR->{fg} = [1, 0, 0]; |
|
|
1950 | $LOGIN_ERROR->set_text ("The passwords do not match - try to enter them again."); |
|
|
1951 | } else { |
|
|
1952 | $CONN or start_game 1; |
|
|
1953 | } |
|
|
1954 | 1 |
|
|
1955 | }, |
|
|
1956 | ); |
|
|
1957 | |
|
|
1958 | $vbox->add (new DC::UI::FancyFrame |
|
|
1959 | label => "Server Message", |
|
|
1960 | tooltip => "The last message, or error, form the server.", |
|
|
1961 | child => ($LOGIN_ERROR = new DC::UI::Label valign => 0, ellipsise => 0), |
|
|
1962 | ); |
|
|
1963 | |
1695 | $vbox->add (new DC::UI::FancyFrame |
1964 | $vbox->add (new DC::UI::FancyFrame |
1696 | label => "How to Play", |
1965 | label => "How to Play", |
1697 | min_h => 240, |
1966 | min_h => 240,#d# should not be necessary - widget bug |
1698 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1967 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1699 | markup => |
1968 | markup => |
1700 | "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" |
1969 | "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" |
1701 | . "Then register a new account (or use an existing one if you have one). " |
1970 | . "Then create a new account (or use an existing one if you have one).\n\n" |
1702 | . "To register an account, choose a username that hasn't been taken yet (just guess) and " |
1971 | . "To create an account, choose a username that hasn't been taken yet (just guess) and " |
1703 | . "try to log-in. Follow the instructions in the Log tab in the message window.", |
1972 | . "fill out the top two <b>Password</b> fields using the same password, then press <b>Create New Account</b>.", |
1704 | ), |
1973 | ), |
1705 | ); |
1974 | ); |
1706 | |
1975 | |
1707 | $vbox |
1976 | $vbox |
1708 | } |
1977 | } |
… | |
… | |
1773 | |
2042 | |
1774 | $vbox |
2043 | $vbox |
1775 | } |
2044 | } |
1776 | |
2045 | |
1777 | sub client_setup { |
2046 | sub client_setup { |
|
|
2047 | my $vbox = new DC::UI::VBox; |
|
|
2048 | |
|
|
2049 | $vbox->add (my $top = new DC::UI::FancyFrame expand => 1, label => "Client Settings"); |
|
|
2050 | $vbox->add (my $bot = new DC::UI::FancyFrame expand => 1, label => "Client Info"); |
|
|
2051 | |
|
|
2052 | { |
1778 | my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]; |
2053 | $top->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]); |
1779 | |
2054 | |
1780 | my $row = 0; |
2055 | my $row = 0; |
1781 | |
2056 | |
1782 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day"); |
2057 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day"); |
1783 | $table->add_at (1, $row++, new DC::UI::CheckBox |
2058 | $table->add_at (1, $row++, new DC::UI::CheckBox |
1784 | c_colspan => 2, |
2059 | c_colspan => 2, |
1785 | state => $CFG->{show_tips}, |
2060 | state => $CFG->{show_tips}, |
1786 | tooltip => "Show the <b>Tip of the day</b> window at startup?", |
2061 | tooltip => "Show the <b>Tip of the day</b> window at startup?", |
1787 | on_changed => sub { |
2062 | on_changed => sub { |
1788 | my ($self, $value) = @_; |
2063 | my ($self, $value) = @_; |
1789 | $CFG->{show_tips} = $value; |
2064 | $CFG->{show_tips} = $value; |
|
|
2065 | 0 |
1790 | 0 |
2066 | } |
1791 | } |
2067 | ); |
1792 | ); |
|
|
1793 | |
2068 | |
1794 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size"); |
2069 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size"); |
1795 | $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry |
2070 | $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry |
1796 | c_colspan => 2, |
2071 | c_colspan => 2, |
1797 | text => $CFG->{logview_max_par}, |
2072 | text => $CFG->{logview_max_par}, |
1798 | tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server " |
2073 | tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server " |
1799 | . "sends more messages than this number, older messages get removed to save memory and " |
2074 | . "sends more messages than this number, older messages get removed to save memory and " |
1800 | . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", |
2075 | . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", |
1801 | on_changed => sub { |
2076 | on_changed => sub { |
1802 | my ($self, $value) = @_; |
2077 | my ($self, $value) = @_; |
1803 | $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); |
2078 | $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); |
1804 | 0 |
2079 | 0 |
1805 | }, |
2080 | }, |
1806 | ); |
2081 | ); |
1807 | |
2082 | |
1808 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Config Autosave"); |
2083 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Config Autosave"); |
1809 | $table->add_at (1, $row, new DC::UI::CheckBox |
2084 | $table->add_at (1, $row, new DC::UI::CheckBox |
1810 | state => $CFG->{config_autosave}, |
2085 | state => $CFG->{config_autosave}, |
1811 | tooltip => "Normally, configuration settings and the user interface layout " |
2086 | tooltip => "Normally, configuration settings and the user interface layout " |
1812 | . "are saved on client exit. You can disable this behaviour by " |
2087 | . "are saved on client exit. You can disable this behaviour by " |
1813 | . "unchecking this checkbox.", |
2088 | . "unchecking this checkbox.", |
1814 | on_changed => sub { |
2089 | on_changed => sub { |
1815 | my ($self, $value) = @_; |
2090 | my ($self, $value) = @_; |
1816 | $CFG->{config_autosave} = $value; |
2091 | $CFG->{config_autosave} = $value; |
|
|
2092 | 0 |
1817 | 0 |
2093 | } |
1818 | } |
2094 | ); |
1819 | ); |
|
|
1820 | $table->add_at (2, $row++, new DC::UI::Button |
2095 | $table->add_at (2, $row++, new DC::UI::Button |
1821 | text => "Save Now", |
2096 | text => "Save Now", |
1822 | tooltip => "Use this to manually save configuration and UI layout when " |
2097 | tooltip => "Use this to manually save configuration and UI layout when " |
1823 | . "autosave is disabled.", |
2098 | . "autosave is disabled.", |
1824 | on_activate => sub { |
2099 | on_activate => sub { |
1825 | DC::write_cfg; |
2100 | DC::save_cfg; |
|
|
2101 | 0 |
1826 | 0 |
2102 | } |
1827 | } |
2103 | ); |
1828 | ); |
2104 | } |
1829 | |
2105 | |
1830 | $table |
2106 | { |
|
|
2107 | $bot->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
2108 | |
|
|
2109 | my $row = 0; |
|
|
2110 | |
|
|
2111 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); |
|
|
2112 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => ""); |
|
|
2113 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory"); |
|
|
2114 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); |
|
|
2115 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)"); |
|
|
2116 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => ""); |
|
|
2117 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); |
|
|
2118 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => ""); |
|
|
2119 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)"); |
|
|
2120 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => ""); |
|
|
2121 | } |
|
|
2122 | |
|
|
2123 | $vbox |
1831 | } |
2124 | } |
1832 | |
2125 | |
1833 | sub autopickup_setup { |
2126 | sub autopickup_setup { |
1834 | my $r = new DC::UI::ScrolledWindow ( |
2127 | my $r = new DC::UI::ScrolledWindow ( |
1835 | expand => 1, |
2128 | expand => 1, |
… | |
… | |
2006 | |
2299 | |
2007 | sub media_window { |
2300 | sub media_window { |
2008 | my $vb = new DC::UI::VBox; |
2301 | my $vb = new DC::UI::VBox; |
2009 | |
2302 | |
2010 | $vb->add (new DC::UI::FancyFrame |
2303 | $vb->add (new DC::UI::FancyFrame |
2011 | label => "Currently playing music", |
2304 | label => "Current background music", |
2012 | child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, |
2305 | child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, |
2013 | child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), |
2306 | child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), |
2014 | ); |
2307 | ); |
|
|
2308 | |
|
|
2309 | $vb->add (new DC::UI::FancyFrame |
|
|
2310 | label => "Current downloads", |
|
|
2311 | child => ($DOWNLOADS_WIDGET = new DC::UI::Table |
|
|
2312 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
|
|
2313 | ); |
|
|
2314 | |
|
|
2315 | $DOWNLOADS_WIDGET->connect (visibility_change => sub { |
|
|
2316 | my ($self) = @_; |
|
|
2317 | |
|
|
2318 | delete $self->{updater}; |
|
|
2319 | return unless $_[1]; |
|
|
2320 | |
|
|
2321 | $self->{updater} = AE::timer 0, 0.7, sub { |
|
|
2322 | $self->clear; |
|
|
2323 | |
|
|
2324 | return unless $CONN; |
|
|
2325 | |
|
|
2326 | my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} }; |
|
|
2327 | return unless @nums; |
|
|
2328 | |
|
|
2329 | $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face"); |
|
|
2330 | $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total"); |
|
|
2331 | |
|
|
2332 | for my $row (0 .. $#nums) { |
|
|
2333 | my $num = $nums[$row]; |
|
|
2334 | |
|
|
2335 | my $total = length $CONN->{ix_recv_buf}{$num}; |
|
|
2336 | my $got = $total - $CONN->{ix_recv_ofs}{$num}; |
|
|
2337 | |
|
|
2338 | $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => ""); |
|
|
2339 | $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => ""); |
|
|
2340 | } |
|
|
2341 | }; |
|
|
2342 | }); |
2015 | |
2343 | |
2016 | $vb->add (new DC::UI::FancyFrame |
2344 | $vb->add (new DC::UI::FancyFrame |
2017 | label => "Other media used in this session", |
2345 | label => "Other media used in this session", |
2018 | expand => 1, |
2346 | expand => 1, |
2019 | child => ($LICENSE_WIDGET = new DC::UI::TextScroller |
2347 | child => ($LICENSE_WIDGET = new DC::UI::TextScroller |
2020 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
2348 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
2021 | ); |
2349 | ); |
2022 | |
2350 | |
2023 | $vb |
2351 | $vb |
2024 | } |
2352 | } |
2025 | |
2353 | |
… | |
… | |
2210 | sub open_quit_dialog { |
2538 | sub open_quit_dialog { |
2211 | unless ($QUIT_DIALOG) { |
2539 | unless ($QUIT_DIALOG) { |
2212 | $QUIT_DIALOG = new DC::UI::Toplevel |
2540 | $QUIT_DIALOG = new DC::UI::Toplevel |
2213 | x => "center", |
2541 | x => "center", |
2214 | y => "center", |
2542 | y => "center", |
2215 | z => 50, |
2543 | z => 60, |
2216 | title => "Really Quit?", |
2544 | title => "Really Quit?", |
2217 | on_key_down => sub { |
2545 | on_key_down => sub { |
2218 | my ($dialog, $ev) = @_; |
2546 | my ($dialog, $ev) = @_; |
2219 | $ev->{sym} == 27 and $dialog->hide; |
2547 | $ev->{sym} == 27 and $dialog->hide; |
2220 | } |
2548 | } |
… | |
… | |
2413 | DC::set_theme $CFG->{uitheme}; |
2741 | DC::set_theme $CFG->{uitheme}; |
2414 | |
2742 | |
2415 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2743 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2416 | $SDL_REINIT = 0; |
2744 | $SDL_REINIT = 0; |
2417 | |
2745 | |
2418 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2746 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2; |
2419 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2747 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2420 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2748 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2421 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2749 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2422 | |
2750 | |
2423 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
2751 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
… | |
… | |
2436 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2764 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2437 | |
2765 | |
2438 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2766 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2439 | $FULLSCREEN = $CFG->{fullscreen}; |
2767 | $FULLSCREEN = $CFG->{fullscreen}; |
2440 | $FAST = $CFG->{fast}; |
2768 | $FAST = $CFG->{fast}; |
|
|
2769 | |
|
|
2770 | DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init |
2441 | |
2771 | |
2442 | # due to mac os x braindamage, we simply retry with !fullscreen in case of an error |
2772 | # due to mac os x braindamage, we simply retry with !fullscreen in case of an error |
2443 | DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN |
2773 | DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN |
2444 | or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN |
2774 | or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN |
2445 | or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; |
2775 | or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; |
… | |
… | |
2632 | |
2962 | |
2633 | our $INPUT_WATCHER = EV::periodic 0, 1 / $MAX_FPS, undef, sub { |
2963 | our $INPUT_WATCHER = EV::periodic 0, 1 / $MAX_FPS, undef, sub { |
2634 | $NOW = EV::now; |
2964 | $NOW = EV::now; |
2635 | |
2965 | |
2636 | ($SDL_CB[$_->{type}] || sub { warn "unhandled event $_->{type}" })->($_) |
2966 | ($SDL_CB[$_->{type}] || sub { warn "unhandled event $_->{type}" })->($_) |
2637 | for DC::poll_events; |
2967 | for DC::peep_events; |
2638 | |
2968 | |
2639 | if (%animate_object) { |
2969 | if (%animate_object) { |
2640 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2970 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2641 | $WANT_REFRESH = 1; |
2971 | $WANT_REFRESH = 1; |
2642 | } |
2972 | } |
… | |
… | |
2703 | EV::unloop; |
3033 | EV::unloop; |
2704 | #d# TODO calling exit here hangs the process in some futex |
3034 | #d# TODO calling exit here hangs the process in some futex |
2705 | }; |
3035 | }; |
2706 | |
3036 | |
2707 | # due to mac os x + sdl combined braindamage, we need this contortion |
3037 | # due to mac os x + sdl combined braindamage, we need this contortion |
2708 | sub DC::Main::main { |
3038 | sub DC::Main::run { |
2709 | { |
3039 | DC::SDL_main_hack { |
|
|
3040 | { |
2710 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
3041 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
2711 | |
3042 | |
2712 | if (-e "$Deliantra::VARDIR/client.cf") { |
3043 | DC::load_cfg; |
2713 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
3044 | DC::upgrade_cfg; |
2714 | } else { |
|
|
2715 | #TODO: compatibility cruft |
|
|
2716 | DC::read_cfg "$Deliantra::OLDDIR/cfplusrc"; |
|
|
2717 | print STDERR "INFO: used old configuration file\n"; |
|
|
2718 | } |
|
|
2719 | |
3045 | |
|
|
3046 | DC::Audio::probe; |
|
|
3047 | |
2720 | DC::DB::Server::run; |
3048 | DC::DB::Server::run; |
2721 | |
3049 | |
2722 | if ($CFG->{db_schema} < 1) { |
3050 | if ($CFG->{db_schema} < 1) { |
2723 | warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; |
3051 | warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; |
2724 | DC::DB::nuke_db; |
3052 | DC::DB::nuke_db; |
2725 | $CFG->{db_schema} = 1; |
3053 | $CFG->{db_schema} = 1; |
2726 | DC::write_cfg; |
3054 | DC::save_cfg; |
2727 | } |
|
|
2728 | |
|
|
2729 | DC::DB::open_db; |
|
|
2730 | |
|
|
2731 | DC::UI::set_layout ($::CFG->{layout}); |
|
|
2732 | |
|
|
2733 | my %DEF_CFG = ( |
|
|
2734 | config_autosave => 1, |
|
|
2735 | sdl_mode => undef, |
|
|
2736 | fullscreen => 1, |
|
|
2737 | fast => 0, |
|
|
2738 | force_opengl11 => undef, |
|
|
2739 | disable_alpha => 0, |
|
|
2740 | smooth_movement => 1, |
|
|
2741 | smooth_transitions => 1, |
|
|
2742 | texture_compression => 1, |
|
|
2743 | map_scale => 1, |
|
|
2744 | fow_enable => 1, |
|
|
2745 | fow_intensity => 0, |
|
|
2746 | fow_texture => 0, |
|
|
2747 | map_smoothing => 1, |
|
|
2748 | gui_fontsize => 1, |
|
|
2749 | log_fontsize => 0.7, |
|
|
2750 | gauge_fontsize => 1, |
|
|
2751 | gauge_size => 0.35, |
|
|
2752 | stat_fontsize => 0.7, |
|
|
2753 | mapsize => 100, |
|
|
2754 | audio_enable => 1, |
|
|
2755 | audio_hw_channels => 0, |
|
|
2756 | audio_hw_frequency => 0, |
|
|
2757 | audio_hw_chunksize => 0, |
|
|
2758 | audio_mix_channels => 8, |
|
|
2759 | effects_enable => 1, |
|
|
2760 | effects_volume => 1, |
|
|
2761 | bgm_enable => 1, |
|
|
2762 | bgm_volume => 0.5, |
|
|
2763 | output_rate => "", |
|
|
2764 | pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES, |
|
|
2765 | inv_sort => "mtime", |
|
|
2766 | default => "profile", # default profile |
|
|
2767 | show_tips => 1, |
|
|
2768 | logview_max_par => 1000, |
|
|
2769 | shift_fire_stop => 0, |
|
|
2770 | uitheme => "wood", |
|
|
2771 | map_shift_x => -24, # arbitrary |
|
|
2772 | map_shift_y => +24, # arbitrary |
|
|
2773 | ); |
|
|
2774 | |
|
|
2775 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
2776 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
2777 | } |
|
|
2778 | |
|
|
2779 | my @args = @ARGV; |
|
|
2780 | |
|
|
2781 | # OS X passes some process serial number of other shit. they |
|
|
2782 | # could have used an env var or any other sane mechanism. but |
|
|
2783 | # would it be os x then? no... |
|
|
2784 | shift @args if $args[0] =~ /^-psn_/; |
|
|
2785 | |
|
|
2786 | my $profile = 'default'; |
|
|
2787 | |
|
|
2788 | for (my $i = 0; $i < @args; $i++) { |
|
|
2789 | if ($args[$i] =~ /^--?profile$/) { |
|
|
2790 | $profile = $args[$i + 1]; |
|
|
2791 | splice @args, $i, 2, (); |
|
|
2792 | $i = 0; |
|
|
2793 | } elsif ($args[$i] =~ /^--?h/) { |
|
|
2794 | print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n"; |
|
|
2795 | exit 0; |
|
|
2796 | } |
3055 | } |
2797 | } |
|
|
2798 | |
3056 | |
2799 | $CFG->{profile}{$profile} ||= {}; |
3057 | DC::DB::open_db; |
2800 | $PROFILE = $CFG->{profile}{$profile}; |
|
|
2801 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
|
|
2802 | |
3058 | |
2803 | $PROFILE->{host} = $args[0] if @args > 0; |
3059 | DC::UI::set_layout ($::CFG->{layout}); |
2804 | $PROFILE->{user} = $args[1] if @args > 1; |
|
|
2805 | $PROFILE->{password} = $args[2] if @args > 2; |
|
|
2806 | |
3060 | |
2807 | # convert old bindings (only default profile matters) |
3061 | my @args = @ARGV; |
2808 | if (my $bindings = delete $PROFILE->{bindings}) { |
3062 | |
2809 | while (my ($mod, $syms) = each %$bindings) { |
3063 | # OS X passes some process serial number of other shit. they |
2810 | while (my ($sym, $cmds) = each %$syms) { |
3064 | # could have used an env var or any other sane mechanism. but |
2811 | push @{ $PROFILE->{macro} }, { |
3065 | # would it be os x then? no... |
2812 | accelkey => [$mod*1, $sym*1], |
3066 | shift @args if $args[0] =~ /^-psn_/; |
2813 | action => $cmds, |
3067 | |
|
|
3068 | my $profile = 'default'; |
|
|
3069 | |
|
|
3070 | for (my $i = 0; $i < @args; $i++) { |
|
|
3071 | if ($args[$i] =~ /^--?profile$/) { |
|
|
3072 | $profile = $args[$i + 1]; |
|
|
3073 | splice @args, $i, 2, (); |
2814 | }; |
3074 | $i = 0; |
|
|
3075 | } elsif ($args[$i] =~ /^--?h/) { |
|
|
3076 | print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n"; |
|
|
3077 | exit 0; |
2815 | } |
3078 | } |
2816 | } |
3079 | } |
|
|
3080 | |
|
|
3081 | $CFG->{profile}{$profile} ||= {}; |
|
|
3082 | $PROFILE = $CFG->{profile}{$profile}; |
|
|
3083 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
|
|
3084 | |
|
|
3085 | $PROFILE->{host} = $args[0] if @args > 0; |
|
|
3086 | $PROFILE->{user} = $args[1] if @args > 1; |
|
|
3087 | $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $args[2] if @args > 2; |
|
|
3088 | |
|
|
3089 | # convert old bindings (only default profile matters) |
|
|
3090 | if (my $bindings = delete $PROFILE->{bindings}) { |
|
|
3091 | while (my ($mod, $syms) = each %$bindings) { |
|
|
3092 | while (my ($sym, $cmds) = each %$syms) { |
|
|
3093 | push @{ $PROFILE->{macro} }, { |
|
|
3094 | accelkey => [$mod*1, $sym*1], |
|
|
3095 | action => $cmds, |
|
|
3096 | }; |
|
|
3097 | } |
|
|
3098 | } |
2817 | } |
3099 | } |
2818 | |
3100 | |
|
|
3101 | # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed |
|
|
3102 | # these are ignored under windows, for some reason, and thus set in the loader |
2819 | $ENV{FONTCONFIG_FILE} = DC::find_rcfile "fonts/fonts.conf"; |
3103 | $ENV{FONTCONFIG_FILE} = "fonts.conf"; |
2820 | $ENV{FONTCONFIG_DIR} = DC::find_rcfile "fonts"; |
3104 | $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; |
|
|
3105 | $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions |
2821 | |
3106 | |
2822 | { |
3107 | { |
2823 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
3108 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
2824 | DejaVuSans.ttf |
3109 | DejaVuSans.ttf |
2825 | DejaVuSansMono.ttf |
3110 | DejaVuSansMono.ttf |
2826 | DejaVuSans-Bold.ttf |
3111 | DejaVuSans-Bold.ttf |
2827 | DejaVuSansMono-Bold.ttf |
3112 | DejaVuSansMono-Bold.ttf |
2828 | DejaVuSans-Oblique.ttf |
3113 | DejaVuSans-Oblique.ttf |
2829 | DejaVuSansMono-Oblique.ttf |
3114 | DejaVuSansMono-Oblique.ttf |
2830 | DejaVuSans-BoldOblique.ttf |
3115 | DejaVuSans-BoldOblique.ttf |
2831 | DejaVuSansMono-BoldOblique.ttf |
3116 | DejaVuSansMono-BoldOblique.ttf |
2832 | mona.ttf |
3117 | mona.ttf |
2833 | ); |
3118 | ); |
2834 | |
3119 | |
2835 | DC::add_font $_ for @fonts; |
3120 | DC::add_font $_ for @fonts; |
2836 | |
3121 | |
2837 | $FONT_PROP = new_from_file DC::Font $fonts[0]; |
3122 | $FONT_PROP = new_from_file DC::Font $fonts[0]; |
2838 | $FONT_FIXED = new_from_file DC::Font $fonts[1]; |
3123 | $FONT_FIXED = new_from_file DC::Font $fonts[1]; |
2839 | |
3124 | |
2840 | $FONT_PROP->make_default; |
3125 | $FONT_PROP->make_default; |
2841 | |
3126 | |
2842 | DC::pango_init; |
3127 | DC::pango_init; |
2843 | } |
3128 | } |
2844 | |
3129 | |
2845 | # compare mono (ft) vs. rgba (cairo) |
3130 | # compare mono (ft) vs. rgba (cairo) |
2846 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
3131 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
2847 | # for my $rgba (0..1) { |
3132 | # for my $rgba (0..1) { |
2848 | # my $t1 = Time::HiRes::time; |
3133 | # my $t1 = Time::HiRes::time; |
… | |
… | |
2853 | # } |
3138 | # } |
2854 | # my $t2 = Time::HiRes::time; |
3139 | # my $t2 = Time::HiRes::time; |
2855 | # warn $t2-$t1; |
3140 | # warn $t2-$t1; |
2856 | # } |
3141 | # } |
2857 | |
3142 | |
|
|
3143 | } |
|
|
3144 | |
|
|
3145 | DC::SDL_Init 0; |
2858 | DC::IMG_Init; video_init; |
3146 | DC::IMG_Init; video_init; |
2859 | DC::Mix_Init; audio_init; |
3147 | DC::Mix_Init; audio_init; |
2860 | } |
|
|
2861 | |
3148 | |
2862 | show_tip_of_the_day if $CFG->{show_tips}; |
3149 | show_tip_of_the_day if $CFG->{show_tips}; |
2863 | |
3150 | |
2864 | my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { |
3151 | my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { |
2865 | undef $STARTUP_CANCEL; |
3152 | undef $STARTUP_CANCEL; |
2866 | (pop @::STARTUP_DONE)->() |
3153 | (pop @::STARTUP_DONE)->() |
2867 | while @::STARTUP_DONE; |
3154 | while @::STARTUP_DONE; |
|
|
3155 | }; |
|
|
3156 | |
|
|
3157 | debug_toggle 0; |
|
|
3158 | |
|
|
3159 | delete $SIG{__DIE__}; |
|
|
3160 | EV::loop; |
|
|
3161 | |
|
|
3162 | DC::save_cfg if $CFG->{config_autosave}; |
|
|
3163 | |
|
|
3164 | #video_shutdown; |
|
|
3165 | #audio_shutdown; |
|
|
3166 | |
|
|
3167 | DC::OpenGL::quit; |
|
|
3168 | DC::SDL_Quit; |
|
|
3169 | DC::DB::Server::stop; |
2868 | }; |
3170 | }; |
2869 | |
|
|
2870 | debug_toggle 0; |
|
|
2871 | |
|
|
2872 | delete $SIG{__DIE__}; |
|
|
2873 | EV::loop; |
|
|
2874 | |
|
|
2875 | DC::write_cfg if $CFG->{config_autosave}; |
|
|
2876 | |
|
|
2877 | #video_shutdown; |
|
|
2878 | #audio_shutdown; |
|
|
2879 | |
|
|
2880 | DC::OpenGL::quit; |
|
|
2881 | DC::SDL_Quit; |
|
|
2882 | DC::DB::Server::stop; |
|
|
2883 | } |
3171 | } |
2884 | |
|
|
2885 | *DC::Main::run = \&DC::SDL_braino; # see sub above |
|
|
2886 | |
3172 | |
2887 | 1 |
3173 | 1 |