… | |
… | |
18 | } |
18 | } |
19 | |
19 | |
20 | use common::sense; |
20 | use common::sense; |
21 | use Carp 'verbose'; |
21 | use Carp 'verbose'; |
22 | use Cwd (); |
22 | use Cwd (); |
|
|
23 | use Digest::MD5 (); |
23 | use EV; |
24 | use EV; |
24 | BEGIN { *time = \&EV::time } |
25 | BEGIN { *time = \&EV::time } |
25 | |
26 | |
26 | use List::Util qw(max min); |
27 | use List::Util qw(max min); |
27 | |
28 | |
28 | use Deliantra; |
29 | use Deliantra; |
|
|
30 | use Deliantra::Util; |
29 | use Deliantra::Protocol::Constants; |
31 | use Deliantra::Protocol::Constants; |
30 | |
32 | |
31 | use AnyEvent::Util (); |
33 | use AnyEvent::Util (); |
32 | use AnyEvent::Socket (); |
34 | use AnyEvent::Socket (); |
33 | use AnyEvent::DNS (); |
35 | use AnyEvent::DNS (); |
34 | |
36 | |
35 | use Compress::LZF; |
37 | use Compress::LZF; |
36 | use JSON::XS; |
38 | use JSON::XS; |
|
|
39 | use Urlader; |
37 | |
40 | |
38 | use DC; |
41 | use DC; |
39 | |
42 | |
40 | sub crash($;$) { |
43 | sub crash($;$) { |
41 | # nop at compiletime |
44 | # nop at compiletime |
42 | } |
45 | } |
43 | |
46 | |
44 | BEGIN { |
47 | BEGIN { |
45 | $SIG{__DIE__} = sub { |
48 | $SIG{__DIE__} = sub { |
46 | 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 | |
47 | crash "CRASH/DIE: $_[0]" => 1; |
58 | crash "CRASH/DIE: $_[0]" => 1; |
48 | DC::fatal Carp::longmess "$_[0]"; |
59 | DC::fatal Carp::longmess "$_[0]"; |
49 | } |
60 | } |
50 | } |
61 | } |
51 | |
62 | |
52 | use DC::OpenGL (); |
63 | use DC::OpenGL (); |
|
|
64 | use DC::Audio (); |
53 | use DC::Protocol; |
65 | use DC::Protocol; |
54 | use DC::DB; |
66 | use DC::DB; |
55 | use DC::UI; |
67 | use DC::UI; |
56 | use DC::UI::Canvas; |
68 | use DC::UI::Canvas; |
57 | use DC::UI::Inventory; |
69 | use DC::UI::Inventory; |
… | |
… | |
62 | use DC::MessageDistributor; |
74 | use DC::MessageDistributor; |
63 | use DC::Pod; |
75 | use DC::Pod; |
64 | use DC::MapWidget; |
76 | use DC::MapWidget; |
65 | use DC::Macro; |
77 | use DC::Macro; |
66 | |
78 | |
|
|
79 | # printf "%5d %5d %5d %5d\n", $_, DC::minpot $_, DC::ld32 $_, 2 << ((DC::ld32 $_ - 1)); |
|
|
80 | |
67 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
81 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
68 | $SIG{PIPE} = 'IGNORE'; |
82 | $SIG{PIPE} = 'IGNORE'; |
69 | |
83 | |
70 | $EV::DIED = sub { |
84 | $EV::DIED = sub { |
71 | crash "CRASH/EV::DIED: $@" => 0; |
85 | crash "CRASH/EV::DIED: $@" => 0; |
… | |
… | |
117 | our $MENUBAR; # the hbox at the top |
131 | our $MENUBAR; # the hbox at the top |
118 | our $MENUPOPUP; |
132 | our $MENUPOPUP; |
119 | our $BUTTONBAR; # the menu buttons |
133 | our $BUTTONBAR; # the menu buttons |
120 | our $METASERVER; |
134 | our $METASERVER; |
121 | our $LOGIN_BUTTON; |
135 | our $LOGIN_BUTTON; |
|
|
136 | our $LOGIN_ERROR; |
122 | our $QUIT_DIALOG; |
137 | our $QUIT_DIALOG; |
123 | our $HOST_ENTRY; |
138 | our $HOST_ENTRY; |
124 | our $FULLSCREEN_ENABLE; |
139 | our $FULLSCREEN_ENABLE; |
125 | our $PICKUP_ENABLE; |
140 | our $PICKUP_ENABLE; |
126 | our $SERVER_INFO; |
141 | our $SERVER_INFO; |
… | |
… | |
134 | our $PL_NOTEBOOK; |
149 | our $PL_NOTEBOOK; |
135 | our $PL_WINDOW; |
150 | our $PL_WINDOW; |
136 | |
151 | |
137 | our $MUSIC_PLAYING_WIDGET; |
152 | our $MUSIC_PLAYING_WIDGET; |
138 | our $LICENSE_WIDGET; |
153 | our $LICENSE_WIDGET; |
|
|
154 | our $DOWNLOADS_WIDGET; |
139 | |
155 | |
140 | our $PICKUP_PAGE; |
156 | our $PICKUP_PAGE; |
141 | our $INVENTORY_PAGE; |
157 | our $INVENTORY_PAGE; |
142 | our $STATS_PAGE; |
158 | our $STATS_PAGE; |
143 | our $SKILL_PAGE; |
159 | our $SKILL_PAGE; |
… | |
… | |
186 | AnyEvent::Util::fh_nonblocking $fh, 1; |
202 | AnyEvent::Util::fh_nonblocking $fh, 1; |
187 | |
203 | |
188 | $msg =~ s/\s+$//; |
204 | $msg =~ s/\s+$//; |
189 | |
205 | |
190 | # backtrace as second step, in case it crashes, too |
206 | # backtrace as second step, in case it crashes, too |
191 | crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" |
207 | crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated" |
192 | if $backtrace; |
208 | if $backtrace; |
193 | }; |
209 | }; |
194 | |
210 | |
195 | sub clienterror($;$) { |
211 | sub clienterror($;$) { |
196 | my ($msg, $backtrace) = @_; |
212 | my ($msg, $backtrace) = @_; |
… | |
… | |
198 | warn $msg; |
214 | warn $msg; |
199 | |
215 | |
200 | return unless $CONN; |
216 | return unless $CONN; |
201 | |
217 | |
202 | $CONN->send_exti_msg (clientlog => $msg); |
218 | $CONN->send_exti_msg (clientlog => $msg); |
203 | $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace; |
219 | $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated") if $backtrace; |
204 | } |
220 | } |
205 | |
221 | |
206 | ############################################################################# |
222 | ############################################################################# |
207 | |
223 | |
208 | sub status { |
224 | sub status { |
… | |
… | |
239 | : "[<span foreground='#888'>num</span>]"; |
255 | : "[<span foreground='#888'>num</span>]"; |
240 | |
256 | |
241 | # <tt> around next statement works around some bug that keeps the |
257 | # <tt> around next statement works around some bug that keeps the |
242 | # "font =>" from being used on windows |
258 | # "font =>" from being used on windows |
243 | $MODBOX->set_markup ("<tt>$markup</tt>"); |
259 | $MODBOX->set_markup ("<tt>$markup</tt>"); |
|
|
260 | } |
|
|
261 | |
|
|
262 | sub errorbox { |
|
|
263 | my ($msg) = @_; |
|
|
264 | |
|
|
265 | status $msg; |
|
|
266 | |
|
|
267 | my $dialog = new DC::UI::Toplevel |
|
|
268 | x => "center", |
|
|
269 | y => "center", |
|
|
270 | z => 200, |
|
|
271 | title => "Error", |
|
|
272 | child => my $vbox = new DC::UI::VBox, |
|
|
273 | has_close_button => 1, |
|
|
274 | on_delete => sub { |
|
|
275 | $_[0]->destroy; |
|
|
276 | }, |
|
|
277 | ; |
|
|
278 | |
|
|
279 | add $vbox new DC::UI::Label |
|
|
280 | align => 0.5, |
|
|
281 | ellipsise => 0, |
|
|
282 | text => $msg; |
|
|
283 | |
|
|
284 | add $vbox new DC::UI::Button |
|
|
285 | expand => 1, |
|
|
286 | text => "OK", |
|
|
287 | on_activate => sub { |
|
|
288 | $dialog->destroy; |
|
|
289 | 0 |
|
|
290 | } |
|
|
291 | ; |
|
|
292 | |
|
|
293 | $dialog->show; |
244 | } |
294 | } |
245 | |
295 | |
246 | ############################################################################# |
296 | ############################################################################# |
247 | #TODO: maybe move into own audio module... |
297 | #TODO: maybe move into own audio module... |
248 | |
298 | |
… | |
… | |
463 | audio_music_push; |
513 | audio_music_push; |
464 | } |
514 | } |
465 | |
515 | |
466 | sub audio_init { |
516 | sub audio_init { |
467 | if ($CFG->{audio_enable}) { |
517 | if ($CFG->{audio_enable}) { |
468 | if (length $CFG->{audio_driver}) { |
518 | DC::Audio::init; |
469 | local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver}; |
|
|
470 | DC::SDL_Init DC::SDL_INIT_AUDIO |
|
|
471 | and die "SDL::Init failed!\n"; |
|
|
472 | } else { |
|
|
473 | DC::SDL_Init DC::SDL_INIT_AUDIO |
|
|
474 | and die "SDL::Init failed!\n"; |
|
|
475 | } |
|
|
476 | |
|
|
477 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
|
|
478 | $SDL_MIXER = !DC::Mix_OpenAudio |
|
|
479 | $CFG->{audio_hw_frequency}, |
|
|
480 | DC::MIX_DEFAULT_FORMAT, |
|
|
481 | $CFG->{audio_hw_channels}, |
|
|
482 | $CFG->{audio_hw_chunksize}; |
|
|
483 | |
519 | |
484 | if ($SDL_MIXER) { |
520 | if ($SDL_MIXER) { |
485 | DC::Mix_AllocateChannels $CFG->{audio_mix_channels}; |
|
|
486 | |
|
|
487 | audio_music_finished; |
521 | audio_music_finished; |
488 | } else { |
522 | } else { |
489 | status "Unable to open sound device: there will be no sound"; |
523 | status "Unable to open sound device: there will be no sound"; |
490 | } |
524 | } |
491 | } else { |
525 | } else { |
… | |
… | |
513 | |
547 | |
514 | DC::Mix_CloseAudio if $SDL_MIXER; |
548 | DC::Mix_CloseAudio if $SDL_MIXER; |
515 | undef $SDL_MIXER; |
549 | undef $SDL_MIXER; |
516 | |
550 | |
517 | DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; |
551 | DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; |
|
|
552 | } |
|
|
553 | |
|
|
554 | ############################################################################# |
|
|
555 | # Over-the-air updates |
|
|
556 | |
|
|
557 | sub ota_update { |
|
|
558 | my ($face, $size, $md5) = @_; |
|
|
559 | |
|
|
560 | my $coro = Coro::async_pool { |
|
|
561 | my $override = "$Urlader::EXE_DIR/override"; |
|
|
562 | |
|
|
563 | $MESSAGE_DIST->add_channel ({ |
|
|
564 | id => "ota_update", |
|
|
565 | title => "Update", |
|
|
566 | tooltip => "<b>Software Update Log</b>", |
|
|
567 | }); |
|
|
568 | |
|
|
569 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." }); |
|
|
570 | |
|
|
571 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777; |
|
|
572 | |
|
|
573 | unless ($fh) { |
|
|
574 | $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") }); |
|
|
575 | return; |
|
|
576 | } |
|
|
577 | |
|
|
578 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." }); |
|
|
579 | |
|
|
580 | my $cv = AE::cv; |
|
|
581 | my $error; |
|
|
582 | |
|
|
583 | $cv->begin (Coro::rouse_cb); |
|
|
584 | $CONN->ask_face ( |
|
|
585 | $face, |
|
|
586 | -1000, |
|
|
587 | sub { |
|
|
588 | $STATUSBOX->add ( |
|
|
589 | (sprintf "update download: %d/%d", $size - $_[1], $size), |
|
|
590 | pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1] |
|
|
591 | ); |
|
|
592 | |
|
|
593 | $cv->begin; |
|
|
594 | my $len = length $_[2]; |
|
|
595 | IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub { |
|
|
596 | $error ||= $_[0] != $len; |
|
|
597 | $cv->end; |
|
|
598 | }; |
|
|
599 | }, |
|
|
600 | sub { |
|
|
601 | $cv->end; |
|
|
602 | }, |
|
|
603 | ); |
|
|
604 | |
|
|
605 | Coro::rouse_wait; |
|
|
606 | |
|
|
607 | $STATUSBOX->clr_group ("ota_update"); |
|
|
608 | |
|
|
609 | $error ||= Coro::AIO::aio_fsync $fh; |
|
|
610 | $error ||= Coro::AIO::aio_close $fh; |
|
|
611 | |
|
|
612 | if ($error) { |
|
|
613 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." }); |
|
|
614 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
615 | return; |
|
|
616 | } |
|
|
617 | |
|
|
618 | { |
|
|
619 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "verifying update file..." }); |
|
|
620 | |
|
|
621 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0; |
|
|
622 | |
|
|
623 | if ($fh) { |
|
|
624 | $error ||= Coro::AIO::aio_stat "$override.tmp"; |
|
|
625 | $error ||= -s _ != $size; |
|
|
626 | Coro::AIO::aio_readahead $fh, 0, $size; |
|
|
627 | |
|
|
628 | my $f_md5 = new Digest::MD5; |
|
|
629 | binmode $fh; # ugh :( |
|
|
630 | $f_md5->addfile ($fh); |
|
|
631 | $f_md5 = $f_md5->hexdigest; |
|
|
632 | $error ||= $md5 ne $f_md5; |
|
|
633 | } |
|
|
634 | } |
|
|
635 | |
|
|
636 | if ($error) { |
|
|
637 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "verification failed, update aborted." }); |
|
|
638 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
639 | return; |
|
|
640 | } |
|
|
641 | |
|
|
642 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." }); |
|
|
643 | |
|
|
644 | if (Coro::AIO::aio_rename "$override.tmp", $override) { |
|
|
645 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." }); |
|
|
646 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
647 | } |
|
|
648 | |
|
|
649 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." }); |
|
|
650 | }; |
|
|
651 | |
|
|
652 | $CONN->{ota_update} = Guard::guard { |
|
|
653 | $coro->cancel; |
|
|
654 | }; |
|
|
655 | } |
|
|
656 | |
|
|
657 | sub ota_update_ask { |
|
|
658 | my ($ok, $face, $ver, $size, $md5, $changes) = @_; |
|
|
659 | |
|
|
660 | $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel |
|
|
661 | x => "center", |
|
|
662 | y => "center", |
|
|
663 | z => 55, |
|
|
664 | force_w => $::WIDTH * 0.7, |
|
|
665 | force_h => $::HEIGHT * 0.7, |
|
|
666 | title => "Software update available", |
|
|
667 | child => my $vbox = new DC::UI::VBox, |
|
|
668 | ; |
|
|
669 | |
|
|
670 | $vbox->add (new DC::UI::Label |
|
|
671 | ellipsise => 0, |
|
|
672 | text => "The server offers a software update, " |
|
|
673 | . "do you want to start downloading this update in the background?", |
|
|
674 | ); |
|
|
675 | |
|
|
676 | $vbox->add (new DC::UI::FancyFrame |
|
|
677 | expand => 1, |
|
|
678 | label => "Details", |
|
|
679 | child => (new DC::UI::TextScroller |
|
|
680 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4, |
|
|
681 | par => [{ |
|
|
682 | markup => "<tt>Old revision: $Urlader::EXE_VER\n" |
|
|
683 | . "New revision: $ver\n" |
|
|
684 | . "Download size: $size bytes</tt>\n\n" |
|
|
685 | . "Changes:\n\n" |
|
|
686 | . DC::asxml $changes |
|
|
687 | }], |
|
|
688 | ), |
|
|
689 | ); |
|
|
690 | |
|
|
691 | $vbox->add (my $hbox = new DC::UI::HBox); |
|
|
692 | |
|
|
693 | $hbox->add (new DC::UI::Button |
|
|
694 | expand => 1, |
|
|
695 | text => "Not now", |
|
|
696 | on_activate => sub { |
|
|
697 | $dialog->destroy; |
|
|
698 | 0 |
|
|
699 | } |
|
|
700 | ); |
|
|
701 | $hbox->add (new DC::UI::Button |
|
|
702 | expand => 1, |
|
|
703 | text => "Yes, start downloading", |
|
|
704 | on_activate => sub { |
|
|
705 | $dialog->destroy; |
|
|
706 | ota_update $face, $size, $md5; |
|
|
707 | 0 |
|
|
708 | }, |
|
|
709 | ); |
|
|
710 | |
|
|
711 | $dialog->show; |
|
|
712 | } |
|
|
713 | |
|
|
714 | sub ota_update_check { |
|
|
715 | return unless defined $Urlader::EXE_ID; |
|
|
716 | |
|
|
717 | ::message { markup => "Checking for software update..." }; |
|
|
718 | |
|
|
719 | $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub { |
|
|
720 | my ($ok, $face, $ver, $size, $md5, $changes) = @_; |
|
|
721 | |
|
|
722 | if ($ok) { |
|
|
723 | if (defined $ver) { |
|
|
724 | ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." }; |
|
|
725 | &ota_update_ask; |
|
|
726 | } else { |
|
|
727 | ::message { markup => "Server has no newer version." }; |
|
|
728 | } |
|
|
729 | } else { |
|
|
730 | ::message { markup => "Server does not support software update." }; |
|
|
731 | } |
|
|
732 | |
|
|
733 | () |
|
|
734 | }); |
518 | } |
735 | } |
519 | |
736 | |
520 | ############################################################################# |
737 | ############################################################################# |
521 | |
738 | |
522 | sub destroy_query_dialog { |
739 | sub destroy_query_dialog { |
… | |
… | |
749 | $vbox->add (@dialog); |
966 | $vbox->add (@dialog); |
750 | $dialog->show; |
967 | $dialog->show; |
751 | } |
968 | } |
752 | |
969 | |
753 | sub dc_connect { |
970 | sub dc_connect { |
754 | my ($host, $port) = @_; |
971 | my ($host, $port, $create) = @_; |
755 | |
972 | |
756 | my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
973 | my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
757 | my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
974 | my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
758 | |
975 | |
759 | $CONN = |
976 | $CONN = |
760 | new DC::Protocol |
977 | new DC::Protocol |
761 | host => $host, |
978 | host => $host, |
762 | port => $port, |
979 | port => $port, |
|
|
980 | create_login => $create, |
763 | user => $PROFILE->{user}, |
981 | user => $PROFILE->{user}, |
764 | pass => $PROFILE->{password}, |
982 | pass => (pack "H*", $PROFILE->{password}), |
765 | mapw => $mapw, |
983 | mapw => $mapw, |
766 | maph => $maph, |
984 | maph => $maph, |
767 | |
985 | |
768 | c_version => { |
986 | c_version => { |
769 | client => "deliantra", |
987 | client => "deliantra", |
770 | clientver => $DC::VERSION, |
988 | clientver => "$DC::VERSION$Urlader::EXE_VER", |
771 | gl_vendor => DC::OpenGL::gl_vendor, |
989 | gl_vendor => DC::OpenGL::gl_vendor, |
772 | gl_version => DC::OpenGL::gl_version, |
990 | gl_version => DC::OpenGL::gl_version, |
773 | }, |
991 | }, |
774 | |
992 | |
775 | map_widget => $MAPWIDGET, |
993 | map_widget => $MAPWIDGET, |
… | |
… | |
784 | |
1002 | |
785 | on_connect => sub { |
1003 | on_connect => sub { |
786 | if ($_[0]) { |
1004 | if ($_[0]) { |
787 | DC::lowdelay fileno $CONN->{fh}; |
1005 | DC::lowdelay fileno $CONN->{fh}; |
788 | |
1006 | |
|
|
1007 | ota_update_check; |
|
|
1008 | |
789 | status "successfully connected to the server"; |
1009 | status "successfully connected to the server"; |
790 | } else { |
1010 | } else { |
791 | undef $CONN; |
1011 | undef $CONN; |
792 | status "unable to connect: $!"; |
1012 | $LOGIN_ERROR->{fg} = [1, 0, 0]; |
|
|
1013 | $LOGIN_ERROR->set_text ("Unable to connect to server: $!"); |
793 | stop_game(); |
1014 | stop_game(); |
794 | } |
1015 | } |
795 | }, |
1016 | }, |
|
|
1017 | |
|
|
1018 | on_addme => sub { |
|
|
1019 | my ($ok, $msg) = @_; |
|
|
1020 | |
|
|
1021 | $LOGIN_ERROR->{fg} = $ok ? [0, 1, 0] : [1, 0, 0]; |
|
|
1022 | $LOGIN_ERROR->set_text ($msg); |
|
|
1023 | }, |
796 | ; |
1024 | ; |
797 | } |
1025 | } |
798 | |
1026 | |
799 | sub start_game { |
1027 | sub start_game($) { |
|
|
1028 | my ($create) = @_; |
|
|
1029 | |
800 | status "logging in..."; |
1030 | status "logging in..."; |
801 | |
1031 | |
802 | my $server = $PROFILE->{host} || $DEFAULT_SERVER; |
1032 | my $server = $PROFILE->{host} || $DEFAULT_SERVER; |
803 | my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" |
1033 | my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" |
804 | or return status "$server: unable to parse server address, try an empty field."; |
1034 | or return status "$server: unable to parse server address, try an empty field."; |
… | |
… | |
819 | status "dns failure, using hardcoded address"; |
1049 | status "dns failure, using hardcoded address"; |
820 | $host = "194.126.175.154"; |
1050 | $host = "194.126.175.154"; |
821 | } |
1051 | } |
822 | } |
1052 | } |
823 | |
1053 | |
824 | dc_connect $host, $port; |
1054 | dc_connect $host, $port, $create; |
825 | }; |
1055 | }; |
826 | } else { |
1056 | } else { |
827 | dc_connect $host, $port; |
1057 | dc_connect $host, $port, $create; |
828 | } |
1058 | } |
829 | } |
1059 | } |
830 | |
1060 | |
831 | sub stop_game { |
1061 | sub stop_game { |
832 | crash "stop_game"; |
1062 | crash "stop_game"; |
… | |
… | |
950 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); |
1180 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); |
951 | $table->add_at (1, $row++, new DC::UI::CheckBox |
1181 | $table->add_at (1, $row++, new DC::UI::CheckBox |
952 | state => $CFG->{texture_compression}, |
1182 | state => $CFG->{texture_compression}, |
953 | tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " |
1183 | tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " |
954 | . "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). " |
1184 | . "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). " |
955 | . "The compression algorithm can differ form card to card, so your mileage may vary. This setting is ignored in " |
1185 | . "The compression algorithm can differ from card to card, so your mileage may vary. This setting is ignored in " |
956 | . "forced OpenGL 1.1 mode and when using the Apple renderer.", |
1186 | . "forced OpenGL 1.1 mode and when using the Apple renderer.", |
957 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
1187 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
958 | ); |
1188 | ); |
959 | |
1189 | |
960 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly"); |
1190 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly"); |
… | |
… | |
1312 | $DELIANTRA_DEBUG ^= $_[0]; |
1542 | $DELIANTRA_DEBUG ^= $_[0]; |
1313 | |
1543 | |
1314 | if ($DELIANTRA_DEBUG & 16) { |
1544 | if ($DELIANTRA_DEBUG & 16) { |
1315 | $BW_WATCHER = EV::periodic 0, 1, 0, sub { |
1545 | $BW_WATCHER = EV::periodic 0, 1, 0, sub { |
1316 | return unless $CONN; |
1546 | return unless $CONN; |
1317 | debug sprintf "%8.2gKB/s", $CONN->{octets_in} / 1e3; |
1547 | debug sprintf "%8.2gkB/s", $CONN->{octets_in} / 1e3; |
1318 | $CONN->{octets_in} = 0; |
1548 | $CONN->{octets_in} = 0; |
1319 | }; |
1549 | }; |
1320 | } else { |
1550 | } else { |
1321 | undef $BW_WATCHER; |
1551 | undef $BW_WATCHER; |
1322 | } |
1552 | } |
… | |
… | |
1665 | $vbox->add (new DC::UI::FancyFrame |
1895 | $vbox->add (new DC::UI::FancyFrame |
1666 | label => "Login Settings", |
1896 | label => "Login Settings", |
1667 | child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), |
1897 | child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), |
1668 | ); |
1898 | ); |
1669 | |
1899 | |
|
|
1900 | my $nullpw = "\x00" x 16; |
|
|
1901 | |
1670 | $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username"); |
1902 | $table->add_at (0, 0, new DC::UI::Label align => 1, text => "Username"); |
1671 | $table->add_at (1, 4, new DC::UI::Entry |
1903 | $table->add_at (1, 0, new DC::UI::Entry |
1672 | text => $PROFILE->{user}, |
1904 | text => $PROFILE->{user}, |
1673 | tooltip => "The name of your character on the server. The name is case-sensitive!", |
1905 | tooltip => "The name of your character on the server. The name is case-sensitive!", |
1674 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } |
1906 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } |
1675 | ); |
1907 | ); |
1676 | |
1908 | |
1677 | $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password"); |
1909 | $table->add_at (0, 1, new DC::UI::Label align => 1, text => "Password"); |
1678 | $table->add_at (1, 5, new DC::UI::Entry |
1910 | $table->add_at (1, 1, my $pw1 = new DC::UI::Entry |
1679 | text => $PROFILE->{password}, |
1911 | text => $PROFILE->{password} ? $nullpw : "", |
1680 | hidden => 1, |
1912 | hidden => 1, |
1681 | tooltip => "The password for your character.", |
1913 | tooltip => "The password for your character.", |
1682 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{password} = $value; 1 } |
1914 | on_focus_in => sub { |
|
|
1915 | my ($self) = @_; |
|
|
1916 | $self->set_text ("") |
|
|
1917 | if $self->{text} eq $nullpw; |
|
|
1918 | 0 |
|
|
1919 | }, |
|
|
1920 | on_changed => sub { |
|
|
1921 | my ($self, $value) = @_; |
|
|
1922 | $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $value |
|
|
1923 | if length $value && $value ne $nullpw; |
|
|
1924 | 1 |
|
|
1925 | }, |
1683 | ); |
1926 | ); |
1684 | |
1927 | |
1685 | $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button |
1928 | $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button |
1686 | expand => 1, |
1929 | expand => 1, |
1687 | text => "Login / Register", |
1930 | text => "Login to Existing Account", |
1688 | tooltip => "This button will either login to the account configured above or register a new account.", |
1931 | tooltip => "This button will login to the account given by the <b>Username</b> and <b>Password</b> fields above.", |
1689 | on_activate => sub { |
1932 | on_activate => sub { |
1690 | $CONN ? stop_game |
1933 | $CONN ? stop_game |
1691 | : start_game; |
1934 | : start_game 0; |
1692 | 1 |
1935 | 1 |
1693 | }, |
1936 | }, |
1694 | ); |
1937 | ); |
1695 | |
1938 | |
|
|
1939 | $table->add_at (0, 3, new DC::UI::Label align => 1, text => "Password"); |
|
|
1940 | $table->add_at (1, 3, my $pw2 = new DC::UI::Entry |
|
|
1941 | hidden => 1, |
|
|
1942 | tooltip => "The new password for your character", |
|
|
1943 | ); |
|
|
1944 | |
|
|
1945 | $table->add_at (1, 4, new DC::UI::Button |
|
|
1946 | expand => 1, |
|
|
1947 | text => "Create New Account", |
|
|
1948 | 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.", |
|
|
1949 | on_activate => sub { |
|
|
1950 | if ($pw1->{text} ne $pw2->{text}) { |
|
|
1951 | $LOGIN_ERROR->{fg} = [1, 0, 0]; |
|
|
1952 | $LOGIN_ERROR->set_text ("The passwords do not match - try to enter them again."); |
|
|
1953 | } else { |
|
|
1954 | $CONN or start_game 1; |
|
|
1955 | } |
|
|
1956 | 1 |
|
|
1957 | }, |
|
|
1958 | ); |
|
|
1959 | |
|
|
1960 | $vbox->add (new DC::UI::FancyFrame |
|
|
1961 | label => "Server Message", |
|
|
1962 | tooltip => "The last message, or error, from the server.", |
|
|
1963 | child => ($LOGIN_ERROR = new DC::UI::Label valign => 0, ellipsise => 0), |
|
|
1964 | ); |
|
|
1965 | |
1696 | $vbox->add (new DC::UI::FancyFrame |
1966 | $vbox->add (new DC::UI::FancyFrame |
1697 | label => "How to Play", |
1967 | label => "How to Play", |
1698 | min_h => 240, |
1968 | min_h => 240,#d# should not be necessary - widget bug |
1699 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1969 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1700 | markup => |
1970 | markup => |
1701 | "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" |
1971 | "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" |
1702 | . "Then register a new account (or use an existing one if you have one). " |
1972 | . "Then create a new account (or use an existing one if you have one).\n\n" |
1703 | . "To register an account, choose a username that hasn't been taken yet (just guess) and " |
1973 | . "To create an account, choose a username that hasn't been taken yet (just guess) and " |
1704 | . "try to log-in. Follow the instructions in the Log tab in the message window.", |
1974 | . "fill out the top two <b>Password</b> fields using the same password, then press <b>Create New Account</b>.", |
1705 | ), |
1975 | ), |
1706 | ); |
1976 | ); |
1707 | |
1977 | |
1708 | $vbox |
1978 | $vbox |
1709 | } |
1979 | } |
… | |
… | |
1760 | $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Output-Rate"); |
2030 | $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Output-Rate"); |
1761 | $table->add_at (1, $row, new DC::UI::Entry |
2031 | $table->add_at (1, $row, new DC::UI::Entry |
1762 | text => $CFG->{output_rate}, |
2032 | text => $CFG->{output_rate}, |
1763 | tooltip => "The maximum bandwidth in bytes per second that the server should not exceed " |
2033 | tooltip => "The maximum bandwidth in bytes per second that the server should not exceed " |
1764 | . "when sending data. When 0 or unset, the server " |
2034 | . "when sending data. When 0 or unset, the server " |
1765 | . "default will be used, which is usually around 100kb/s. Most servers will " |
2035 | . "default will be used, which is usually around 100kB/s. Most servers will " |
1766 | . "dynamically find an optimal rate, so adjust this only when necessary.", |
2036 | . "dynamically find an optimal rate, so adjust this only when necessary.", |
1767 | on_changed => sub { $CFG->{output_rate} = $_[1]; 1 }, |
2037 | on_changed => sub { $CFG->{output_rate} = $_[1]; 1 }, |
1768 | ); |
2038 | ); |
1769 | |
2039 | |
1770 | $vbox->add (new DC::UI::FancyFrame |
2040 | $vbox->add (new DC::UI::FancyFrame |
… | |
… | |
1827 | $table->add_at (2, $row++, new DC::UI::Button |
2097 | $table->add_at (2, $row++, new DC::UI::Button |
1828 | text => "Save Now", |
2098 | text => "Save Now", |
1829 | tooltip => "Use this to manually save configuration and UI layout when " |
2099 | tooltip => "Use this to manually save configuration and UI layout when " |
1830 | . "autosave is disabled.", |
2100 | . "autosave is disabled.", |
1831 | on_activate => sub { |
2101 | on_activate => sub { |
1832 | DC::write_cfg; |
2102 | DC::save_cfg; |
1833 | 0 |
2103 | 0 |
1834 | } |
2104 | } |
1835 | ); |
2105 | ); |
1836 | } |
2106 | } |
1837 | |
2107 | |
… | |
… | |
1842 | |
2112 | |
1843 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); |
2113 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); |
1844 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => ""); |
2114 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => ""); |
1845 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory"); |
2115 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory"); |
1846 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); |
2116 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); |
|
|
2117 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)"); |
|
|
2118 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => ""); |
1847 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); |
2119 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); |
1848 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_ID, tooltip => ""); |
2120 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => ""); |
1849 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Version (Prebuilt)"); |
2121 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)"); |
1850 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_VER, tooltip => ""); |
2122 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => ""); |
1851 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Update (Prebuilt)"); |
|
|
1852 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::UPDPAR, tooltip => ""); |
|
|
1853 | } |
2123 | } |
1854 | |
2124 | |
1855 | $vbox |
2125 | $vbox |
1856 | } |
2126 | } |
1857 | |
2127 | |
… | |
… | |
2031 | |
2301 | |
2032 | sub media_window { |
2302 | sub media_window { |
2033 | my $vb = new DC::UI::VBox; |
2303 | my $vb = new DC::UI::VBox; |
2034 | |
2304 | |
2035 | $vb->add (new DC::UI::FancyFrame |
2305 | $vb->add (new DC::UI::FancyFrame |
2036 | label => "Currently playing music", |
2306 | label => "Current background music", |
2037 | child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, |
2307 | child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, |
2038 | child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), |
2308 | child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), |
2039 | ); |
2309 | ); |
|
|
2310 | |
|
|
2311 | $vb->add (new DC::UI::FancyFrame |
|
|
2312 | label => "Current downloads", |
|
|
2313 | child => ($DOWNLOADS_WIDGET = new DC::UI::Table |
|
|
2314 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
|
|
2315 | ); |
|
|
2316 | |
|
|
2317 | $DOWNLOADS_WIDGET->connect (visibility_change => sub { |
|
|
2318 | my ($self) = @_; |
|
|
2319 | |
|
|
2320 | delete $self->{updater}; |
|
|
2321 | return unless $_[1]; |
|
|
2322 | |
|
|
2323 | $self->{updater} = AE::timer 0, 0.7, sub { |
|
|
2324 | $self->clear; |
|
|
2325 | |
|
|
2326 | return unless $CONN; |
|
|
2327 | |
|
|
2328 | my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} }; |
|
|
2329 | return unless @nums; |
|
|
2330 | |
|
|
2331 | $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face"); |
|
|
2332 | $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total"); |
|
|
2333 | |
|
|
2334 | for my $row (0 .. $#nums) { |
|
|
2335 | my $num = $nums[$row]; |
|
|
2336 | |
|
|
2337 | my $total = length $CONN->{ix_recv_buf}{$num}; |
|
|
2338 | my $got = $total - $CONN->{ix_recv_ofs}{$num}; |
|
|
2339 | |
|
|
2340 | $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => ""); |
|
|
2341 | $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => ""); |
|
|
2342 | } |
|
|
2343 | }; |
|
|
2344 | }); |
2040 | |
2345 | |
2041 | $vb->add (new DC::UI::FancyFrame |
2346 | $vb->add (new DC::UI::FancyFrame |
2042 | label => "Other media used in this session", |
2347 | label => "Other media used in this session", |
2043 | expand => 1, |
2348 | expand => 1, |
2044 | child => ($LICENSE_WIDGET = new DC::UI::TextScroller |
2349 | child => ($LICENSE_WIDGET = new DC::UI::TextScroller |
2045 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
2350 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
2046 | ); |
2351 | ); |
2047 | |
2352 | |
2048 | $vb |
2353 | $vb |
2049 | } |
2354 | } |
2050 | |
2355 | |
… | |
… | |
2235 | sub open_quit_dialog { |
2540 | sub open_quit_dialog { |
2236 | unless ($QUIT_DIALOG) { |
2541 | unless ($QUIT_DIALOG) { |
2237 | $QUIT_DIALOG = new DC::UI::Toplevel |
2542 | $QUIT_DIALOG = new DC::UI::Toplevel |
2238 | x => "center", |
2543 | x => "center", |
2239 | y => "center", |
2544 | y => "center", |
2240 | z => 50, |
2545 | z => 60, |
2241 | title => "Really Quit?", |
2546 | title => "Really Quit?", |
2242 | on_key_down => sub { |
2547 | on_key_down => sub { |
2243 | my ($dialog, $ev) = @_; |
2548 | my ($dialog, $ev) = @_; |
2244 | $ev->{sym} == 27 and $dialog->hide; |
2549 | $ev->{sym} == 27 and $dialog->hide; |
2245 | } |
2550 | } |
… | |
… | |
2292 | make_playerbook; |
2597 | make_playerbook; |
2293 | |
2598 | |
2294 | $MENUPOPUP = DC::UI::Menu->new (items => [ |
2599 | $MENUPOPUP = DC::UI::Menu->new (items => [ |
2295 | ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }], |
2600 | ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }], |
2296 | ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }], |
2601 | ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }], |
2297 | ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }], |
2602 | ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }], |
2298 | ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }], |
2603 | ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }], |
2299 | ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }], |
2604 | ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }], |
2300 | ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }], |
2605 | ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }], |
2301 | ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }], |
2606 | ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }], |
2302 | ["Quit…" , sub { |
2607 | ["Quit…" , sub { |
2303 | if ($CONN) { |
2608 | if ($CONN) { |
2304 | open_quit_dialog; |
2609 | open_quit_dialog; |
2305 | } else { |
2610 | } else { |
2306 | EV::unloop EV::UNLOOP_ALL; |
2611 | EV::break EV::BREAK_ALL; |
2307 | } |
2612 | } |
2308 | }], |
2613 | }], |
2309 | ]); |
2614 | ]); |
2310 | |
2615 | |
2311 | $BUTTONBAR->add (new DC::UI::Button text => "Menu…", |
2616 | $BUTTONBAR->add (new DC::UI::Button text => "Menu…", |
… | |
… | |
2438 | DC::set_theme $CFG->{uitheme}; |
2743 | DC::set_theme $CFG->{uitheme}; |
2439 | |
2744 | |
2440 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2745 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2441 | $SDL_REINIT = 0; |
2746 | $SDL_REINIT = 0; |
2442 | |
2747 | |
2443 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2748 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2; |
2444 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2749 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2445 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2750 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2446 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2751 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2447 | |
2752 | |
2448 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
2753 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
… | |
… | |
2461 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2766 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2462 | |
2767 | |
2463 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2768 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2464 | $FULLSCREEN = $CFG->{fullscreen}; |
2769 | $FULLSCREEN = $CFG->{fullscreen}; |
2465 | $FAST = $CFG->{fast}; |
2770 | $FAST = $CFG->{fast}; |
|
|
2771 | |
|
|
2772 | DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init |
2466 | |
2773 | |
2467 | # due to mac os x braindamage, we simply retry with !fullscreen in case of an error |
2774 | # due to mac os x braindamage, we simply retry with !fullscreen in case of an error |
2468 | DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN |
2775 | DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN |
2469 | or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN |
2776 | or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN |
2470 | or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; |
2777 | or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; |
… | |
… | |
2680 | delete $animate_object{$widget}; |
2987 | delete $animate_object{$widget}; |
2681 | } |
2988 | } |
2682 | |
2989 | |
2683 | $SDL_CB[DC::SDL_QUIT] = sub { |
2990 | $SDL_CB[DC::SDL_QUIT] = sub { |
2684 | crash "SDL_QUIT"; |
2991 | crash "SDL_QUIT"; |
2685 | EV::unloop EV::UNLOOP_ALL; |
2992 | EV::break EV::BREAK_ALL; |
2686 | }; |
2993 | }; |
2687 | $SDL_CB[DC::SDL_VIDEORESIZE] = sub { }; |
2994 | $SDL_CB[DC::SDL_VIDEORESIZE] = sub { }; |
2688 | $SDL_CB[DC::SDL_VIDEOEXPOSE] = sub { |
2995 | $SDL_CB[DC::SDL_VIDEOEXPOSE] = sub { |
2689 | DC::UI::full_refresh; |
2996 | DC::UI::full_refresh; |
2690 | }; |
2997 | }; |
… | |
… | |
2723 | }; |
3030 | }; |
2724 | |
3031 | |
2725 | ############################################################################# |
3032 | ############################################################################# |
2726 | |
3033 | |
2727 | $SIG{INT} = $SIG{TERM} = sub { |
3034 | $SIG{INT} = $SIG{TERM} = sub { |
2728 | EV::unloop; |
3035 | EV::break; |
2729 | #d# TODO calling exit here hangs the process in some futex |
3036 | #d# TODO calling exit here hangs the process in some futex |
2730 | }; |
3037 | }; |
2731 | |
3038 | |
2732 | # due to mac os x + sdl combined braindamage, we need this contortion |
3039 | # due to mac os x + sdl combined braindamage, we need this contortion |
2733 | sub DC::Main::main { |
3040 | sub DC::Main::run { |
2734 | { |
3041 | DC::SDL_main_hack { |
|
|
3042 | { |
2735 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
3043 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
2736 | |
3044 | |
2737 | if (-e "$Deliantra::VARDIR/client.cf") { |
3045 | DC::load_cfg; |
2738 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
3046 | DC::upgrade_cfg; |
2739 | } else { |
|
|
2740 | #TODO: compatibility cruft |
|
|
2741 | DC::read_cfg "$Deliantra::OLDDIR/cfplusrc"; |
|
|
2742 | print STDERR "INFO: used old configuration file\n"; |
|
|
2743 | } |
|
|
2744 | |
3047 | |
|
|
3048 | DC::Audio::probe; |
|
|
3049 | |
2745 | DC::DB::Server::run; |
3050 | DC::DB::Server::run; |
2746 | |
3051 | |
2747 | if ($CFG->{db_schema} < 1) { |
3052 | if ($CFG->{db_schema} < 1) { |
2748 | warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; |
3053 | warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; |
2749 | DC::DB::nuke_db; |
3054 | DC::DB::nuke_db; |
2750 | $CFG->{db_schema} = 1; |
3055 | $CFG->{db_schema} = 1; |
2751 | DC::write_cfg; |
3056 | DC::save_cfg; |
2752 | } |
|
|
2753 | |
|
|
2754 | DC::DB::open_db; |
|
|
2755 | |
|
|
2756 | DC::UI::set_layout ($::CFG->{layout}); |
|
|
2757 | |
|
|
2758 | my %DEF_CFG = ( |
|
|
2759 | config_autosave => 1, |
|
|
2760 | sdl_mode => undef, |
|
|
2761 | fullscreen => 1, |
|
|
2762 | fast => 0, |
|
|
2763 | force_opengl11 => undef, |
|
|
2764 | disable_alpha => 0, |
|
|
2765 | smooth_movement => 1, |
|
|
2766 | smooth_transitions => 1, |
|
|
2767 | texture_compression => 1, |
|
|
2768 | map_scale => 1, |
|
|
2769 | fow_enable => 1, |
|
|
2770 | fow_intensity => 0, |
|
|
2771 | fow_texture => 0, |
|
|
2772 | map_smoothing => 1, |
|
|
2773 | gui_fontsize => 1, |
|
|
2774 | log_fontsize => 0.7, |
|
|
2775 | gauge_fontsize => 1, |
|
|
2776 | gauge_size => 0.35, |
|
|
2777 | stat_fontsize => 0.7, |
|
|
2778 | mapsize => 100, |
|
|
2779 | audio_enable => 1, |
|
|
2780 | audio_hw_channels => 0, |
|
|
2781 | audio_hw_frequency => 0, |
|
|
2782 | audio_hw_chunksize => 0, |
|
|
2783 | audio_mix_channels => 8, |
|
|
2784 | effects_enable => 1, |
|
|
2785 | effects_volume => 1, |
|
|
2786 | bgm_enable => 1, |
|
|
2787 | bgm_volume => 0.5, |
|
|
2788 | output_rate => "", |
|
|
2789 | pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES, |
|
|
2790 | inv_sort => "mtime", |
|
|
2791 | default => "profile", # default profile |
|
|
2792 | show_tips => 1, |
|
|
2793 | logview_max_par => 1000, |
|
|
2794 | shift_fire_stop => 0, |
|
|
2795 | uitheme => "wood", |
|
|
2796 | map_shift_x => -24, # arbitrary |
|
|
2797 | map_shift_y => +24, # arbitrary |
|
|
2798 | ); |
|
|
2799 | |
|
|
2800 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
2801 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
2802 | } |
|
|
2803 | |
|
|
2804 | my @args = @ARGV; |
|
|
2805 | |
|
|
2806 | # OS X passes some process serial number of other shit. they |
|
|
2807 | # could have used an env var or any other sane mechanism. but |
|
|
2808 | # would it be os x then? no... |
|
|
2809 | shift @args if $args[0] =~ /^-psn_/; |
|
|
2810 | |
|
|
2811 | my $profile = 'default'; |
|
|
2812 | |
|
|
2813 | for (my $i = 0; $i < @args; $i++) { |
|
|
2814 | if ($args[$i] =~ /^--?profile$/) { |
|
|
2815 | $profile = $args[$i + 1]; |
|
|
2816 | splice @args, $i, 2, (); |
|
|
2817 | $i = 0; |
|
|
2818 | } elsif ($args[$i] =~ /^--?h/) { |
|
|
2819 | print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n"; |
|
|
2820 | exit 0; |
|
|
2821 | } |
3057 | } |
2822 | } |
|
|
2823 | |
3058 | |
2824 | $CFG->{profile}{$profile} ||= {}; |
3059 | DC::DB::open_db; |
2825 | $PROFILE = $CFG->{profile}{$profile}; |
|
|
2826 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
|
|
2827 | |
3060 | |
2828 | $PROFILE->{host} = $args[0] if @args > 0; |
3061 | DC::UI::set_layout ($::CFG->{layout}); |
2829 | $PROFILE->{user} = $args[1] if @args > 1; |
|
|
2830 | $PROFILE->{password} = $args[2] if @args > 2; |
|
|
2831 | |
3062 | |
2832 | # convert old bindings (only default profile matters) |
3063 | my @args = @ARGV; |
2833 | if (my $bindings = delete $PROFILE->{bindings}) { |
3064 | |
2834 | while (my ($mod, $syms) = each %$bindings) { |
3065 | # OS X passes some process serial number of other shit. they |
2835 | while (my ($sym, $cmds) = each %$syms) { |
3066 | # could have used an env var or any other sane mechanism. but |
2836 | push @{ $PROFILE->{macro} }, { |
3067 | # would it be os x then? no... |
2837 | accelkey => [$mod*1, $sym*1], |
3068 | shift @args if $args[0] =~ /^-psn_/; |
2838 | action => $cmds, |
3069 | |
|
|
3070 | my $profile = 'default'; |
|
|
3071 | |
|
|
3072 | for (my $i = 0; $i < @args; $i++) { |
|
|
3073 | if ($args[$i] =~ /^--?profile$/) { |
|
|
3074 | $profile = $args[$i + 1]; |
|
|
3075 | splice @args, $i, 2, (); |
2839 | }; |
3076 | $i = 0; |
|
|
3077 | } elsif ($args[$i] =~ /^--?h/) { |
|
|
3078 | print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n"; |
|
|
3079 | exit 0; |
2840 | } |
3080 | } |
2841 | } |
3081 | } |
|
|
3082 | |
|
|
3083 | $CFG->{profile}{$profile} ||= {}; |
|
|
3084 | $PROFILE = $CFG->{profile}{$profile}; |
|
|
3085 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
|
|
3086 | |
|
|
3087 | $PROFILE->{host} = $args[0] if @args > 0; |
|
|
3088 | $PROFILE->{user} = $args[1] if @args > 1; |
|
|
3089 | $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $args[2] if @args > 2; |
|
|
3090 | |
|
|
3091 | # convert old bindings (only default profile matters) |
|
|
3092 | if (my $bindings = delete $PROFILE->{bindings}) { |
|
|
3093 | while (my ($mod, $syms) = each %$bindings) { |
|
|
3094 | while (my ($sym, $cmds) = each %$syms) { |
|
|
3095 | push @{ $PROFILE->{macro} }, { |
|
|
3096 | accelkey => [$mod*1, $sym*1], |
|
|
3097 | action => $cmds, |
|
|
3098 | }; |
|
|
3099 | } |
|
|
3100 | } |
2842 | } |
3101 | } |
2843 | |
3102 | |
2844 | # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed |
3103 | # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed |
|
|
3104 | # these are ignored under windows, for some reason, and thus set in the loader |
2845 | $ENV{FONTCONFIG_FILE} = "fonts.conf"; |
3105 | $ENV{FONTCONFIG_FILE} = "fonts.conf"; |
2846 | $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; |
3106 | $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; |
2847 | $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; |
3107 | $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions |
2848 | |
3108 | |
2849 | { |
3109 | { |
2850 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
3110 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
2851 | DejaVuSans.ttf |
3111 | DejaVuSans.ttf |
2852 | DejaVuSansMono.ttf |
3112 | DejaVuSansMono.ttf |
2853 | DejaVuSans-Bold.ttf |
3113 | DejaVuSans-Bold.ttf |
2854 | DejaVuSansMono-Bold.ttf |
3114 | DejaVuSansMono-Bold.ttf |
2855 | DejaVuSans-Oblique.ttf |
3115 | DejaVuSans-Oblique.ttf |
2856 | DejaVuSansMono-Oblique.ttf |
3116 | DejaVuSansMono-Oblique.ttf |
2857 | DejaVuSans-BoldOblique.ttf |
3117 | DejaVuSans-BoldOblique.ttf |
2858 | DejaVuSansMono-BoldOblique.ttf |
3118 | DejaVuSansMono-BoldOblique.ttf |
2859 | mona.ttf |
3119 | mona.ttf |
2860 | ); |
3120 | ); |
2861 | |
3121 | |
2862 | DC::add_font $_ for @fonts; |
3122 | DC::add_font $_ for @fonts; |
2863 | |
3123 | |
2864 | $FONT_PROP = new_from_file DC::Font $fonts[0]; |
3124 | $FONT_PROP = new_from_file DC::Font $fonts[0]; |
2865 | $FONT_FIXED = new_from_file DC::Font $fonts[1]; |
3125 | $FONT_FIXED = new_from_file DC::Font $fonts[1]; |
2866 | |
3126 | |
2867 | $FONT_PROP->make_default; |
3127 | $FONT_PROP->make_default; |
2868 | |
3128 | |
2869 | DC::pango_init; |
3129 | DC::pango_init; |
2870 | } |
3130 | } |
2871 | |
3131 | |
2872 | # compare mono (ft) vs. rgba (cairo) |
3132 | # compare mono (ft) vs. rgba (cairo) |
2873 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
3133 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
2874 | # for my $rgba (0..1) { |
3134 | # for my $rgba (0..1) { |
2875 | # my $t1 = Time::HiRes::time; |
3135 | # my $t1 = Time::HiRes::time; |
… | |
… | |
2880 | # } |
3140 | # } |
2881 | # my $t2 = Time::HiRes::time; |
3141 | # my $t2 = Time::HiRes::time; |
2882 | # warn $t2-$t1; |
3142 | # warn $t2-$t1; |
2883 | # } |
3143 | # } |
2884 | |
3144 | |
|
|
3145 | } |
|
|
3146 | |
|
|
3147 | DC::SDL_Init 0; |
2885 | DC::IMG_Init; video_init; |
3148 | DC::IMG_Init; video_init; |
2886 | DC::Mix_Init; audio_init; |
3149 | DC::Mix_Init; audio_init; |
2887 | } |
|
|
2888 | |
3150 | |
2889 | show_tip_of_the_day if $CFG->{show_tips}; |
3151 | show_tip_of_the_day if $CFG->{show_tips}; |
2890 | |
3152 | |
2891 | my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { |
3153 | my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { |
2892 | undef $STARTUP_CANCEL; |
3154 | undef $STARTUP_CANCEL; |
2893 | (pop @::STARTUP_DONE)->() |
3155 | (pop @::STARTUP_DONE)->() |
2894 | while @::STARTUP_DONE; |
3156 | while @::STARTUP_DONE; |
|
|
3157 | }; |
|
|
3158 | |
|
|
3159 | debug_toggle 0; |
|
|
3160 | |
|
|
3161 | delete $SIG{__DIE__}; |
|
|
3162 | EV::run; |
|
|
3163 | |
|
|
3164 | DC::save_cfg if $CFG->{config_autosave}; |
|
|
3165 | |
|
|
3166 | #video_shutdown; |
|
|
3167 | #audio_shutdown; |
|
|
3168 | |
|
|
3169 | DC::OpenGL::quit; |
|
|
3170 | DC::SDL_Quit; |
|
|
3171 | DC::DB::Server::stop; |
2895 | }; |
3172 | }; |
2896 | |
|
|
2897 | debug_toggle 0; |
|
|
2898 | |
|
|
2899 | delete $SIG{__DIE__}; |
|
|
2900 | EV::loop; |
|
|
2901 | |
|
|
2902 | DC::write_cfg if $CFG->{config_autosave}; |
|
|
2903 | |
|
|
2904 | #video_shutdown; |
|
|
2905 | #audio_shutdown; |
|
|
2906 | |
|
|
2907 | DC::OpenGL::quit; |
|
|
2908 | DC::SDL_Quit; |
|
|
2909 | DC::DB::Server::stop; |
|
|
2910 | } |
3173 | } |
2911 | |
|
|
2912 | *DC::Main::run = \&DC::SDL_braino; # see sub above |
|
|
2913 | |
3174 | |
2914 | 1 |
3175 | 1 |