ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Main.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Main.pm (file contents):
Revision 1.2 by root, Tue Dec 27 09:17:27 2011 UTC vs.
Revision 1.10 by root, Fri Jan 6 05:02:39 2012 UTC

17 die if $@; 17 die if $@;
18} 18}
19 19
20use common::sense; 20use common::sense;
21use Carp 'verbose'; 21use Carp 'verbose';
22use Cwd ();
23use Digest::MD5 ();
22use EV; 24use EV;
23BEGIN { *time = \&EV::time } 25BEGIN { *time = \&EV::time }
24 26
25use List::Util qw(max min); 27use List::Util qw(max min);
26 28
40 # nop at compiletime 42 # nop at compiletime
41} 43}
42 44
43BEGIN { 45BEGIN {
44 $SIG{__DIE__} = sub { 46 $SIG{__DIE__} = sub {
45 return if $^S; 47 return if $^S; # quick reject
48
49 # return if there are any eval contexts in the csall stack
50 for my $i (0..999) {
51 my ($sub, $is_require) = (caller $i)[3, 7]
52 or last;
53 return if $sub eq "(eval)" && !$is_require;
54 }
55
46 crash "CRASH/DIE: $_[0]" => 1; 56 crash "CRASH/DIE: $_[0]" => 1;
47 DC::fatal Carp::longmess "$_[0]"; 57 DC::fatal Carp::longmess "$_[0]";
48 } 58 }
49} 59}
50 60
133our $PL_NOTEBOOK; 143our $PL_NOTEBOOK;
134our $PL_WINDOW; 144our $PL_WINDOW;
135 145
136our $MUSIC_PLAYING_WIDGET; 146our $MUSIC_PLAYING_WIDGET;
137our $LICENSE_WIDGET; 147our $LICENSE_WIDGET;
148our $DOWNLOADS_WIDGET;
138 149
139our $PICKUP_PAGE; 150our $PICKUP_PAGE;
140our $INVENTORY_PAGE; 151our $INVENTORY_PAGE;
141our $STATS_PAGE; 152our $STATS_PAGE;
142our $SKILL_PAGE; 153our $SKILL_PAGE;
185 AnyEvent::Util::fh_nonblocking $fh, 1; 196 AnyEvent::Util::fh_nonblocking $fh, 1;
186 197
187 $msg =~ s/\s+$//; 198 $msg =~ s/\s+$//;
188 199
189 # backtrace as second step, in case it crashes, too 200 # backtrace as second step, in case it crashes, too
190 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" 201 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated"
191 if $backtrace; 202 if $backtrace;
192}; 203};
193 204
194sub clienterror($;$) { 205sub clienterror($;$) {
195 my ($msg, $backtrace) = @_; 206 my ($msg, $backtrace) = @_;
197 warn $msg; 208 warn $msg;
198 209
199 return unless $CONN; 210 return unless $CONN;
200 211
201 $CONN->send_exti_msg (clientlog => $msg); 212 $CONN->send_exti_msg (clientlog => $msg);
202 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace; 213 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated") if $backtrace;
203} 214}
204 215
205############################################################################# 216#############################################################################
206 217
207sub status { 218sub status {
512 523
513 DC::Mix_CloseAudio if $SDL_MIXER; 524 DC::Mix_CloseAudio if $SDL_MIXER;
514 undef $SDL_MIXER; 525 undef $SDL_MIXER;
515 526
516 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; 527 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO;
528}
529
530#############################################################################
531# Over-the-air updates
532
533sub ota_update {
534 my ($face, $size, $md5) = @_;
535
536 my $coro = Coro::async_pool {
537 my $override = "$Urlader::EXE_DIR/override";
538
539 $MESSAGE_DIST->add_channel ({
540 id => "ota_update",
541 title => "Update",
542 tooltip => "<b>Software Update Log</b>",
543 });
544
545 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." });
546
547 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777;
548
549 unless ($fh) {
550 $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") });
551 return;
552 }
553
554 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." });
555
556 my $cv = AE::cv;
557 my $error;
558
559 $cv->begin (Coro::rouse_cb);
560 $CONN->ask_face (
561 $face,
562 -1000,
563 sub {
564 $STATUSBOX->add (
565 (sprintf "update download: %d/%d", $size - $_[1], $size),
566 pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1]
567 );
568
569 $cv->begin;
570 my $len = length $_[2];
571 IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub {
572 $error ||= $_[0] != $len;
573 $cv->end;
574 };
575 },
576 sub {
577 $cv->end;
578 },
579 );
580
581 Coro::rouse_wait;
582
583 $STATUSBOX->clr_group ("ota_update");
584
585 $error ||= Coro::AIO::aio_fsync $fh;
586 $error ||= Coro::AIO::aio_close $fh;
587
588 if ($error) {
589 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." });
590 Coro::AIO::aio_unlink "$override.tmp";
591 return;
592 }
593
594 {
595 $MESSAGE_DIST->message ({ type => "ota_update", markup => "verifying update file..." });
596
597 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0;
598
599 if ($fh) {
600 $error ||= Coro::AIO::aio_stat "$override.tmp";
601 $error ||= -s _ != $size;
602 $error ||= Coro::AIO::aio_readahead $fh, 0, $size;
603
604 my $f_md5 = new Digest::MD5;
605 $f_md5->addfile ($fh);
606 $f_md5 = $f_md5->hexdigest;
607 $error ||= $md5 ne $f_md5;
608 }
609 }
610
611 if ($error) {
612 $MESSAGE_DIST->message ({ type => "ota_update", markup => "verification failed, update aborted." });
613 Coro::AIO::aio_unlink "$override.tmp";
614 return;
615 }
616
617 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
618
619 if (Coro::AIO::aio_rename "$override.tmp", $override) {
620 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
621 Coro::AIO::aio_unlink "$override.tmp";
622 }
623
624 $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." });
625 };
626
627 $CONN->{ota_update} = Guard::guard {
628 $coro->cancel;
629 };
630}
631
632sub ota_update_ask {
633 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
634
635 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
636 x => "center",
637 y => "center",
638 z => 55,
639 force_w => $::WIDTH * 0.7,
640 force_h => $::HEIGHT * 0.7,
641 title => "Software update available",
642 child => my $vbox = new DC::UI::VBox,
643 ;
644
645 $vbox->add (new DC::UI::Label
646 ellipsise => 0,
647 text => "The server offers a software update, "
648 . "do you want to start downloading this update in the background?",
649 );
650
651 $vbox->add (new DC::UI::FancyFrame
652 expand => 1,
653 label => "Details",
654 child => (new DC::UI::TextScroller
655 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
656 par => [{
657 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
658 . "New revision: $ver\n"
659 . "Download size: $size bytes</tt>\n\n"
660 . "Changes:\n\n"
661 . DC::asxml $changes
662 }],
663 ),
664 );
665
666 $vbox->add (my $hbox = new DC::UI::HBox);
667
668 $hbox->add (new DC::UI::Button
669 expand => 1,
670 text => "Not now",
671 on_activate => sub {
672 $dialog->destroy;
673 0
674 }
675 );
676 $hbox->add (new DC::UI::Button
677 expand => 1,
678 text => "Yes, start downloading",
679 on_activate => sub {
680 $dialog->destroy;
681 ota_update $face, $size, $md5;
682 0
683 },
684 );
685
686 $dialog->show;
687}
688
689sub ota_update_check {
690 return unless defined $Urlader::EXE_ID;
691
692 ::message { markup => "Checking for software update..." };
693
694 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
695 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
696
697 if ($ok) {
698 if (defined $ver) {
699 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
700 &ota_update_ask;
701 } else {
702 ::message { markup => "Server has no newer version." };
703 }
704 } else {
705 ::message { markup => "Server does not support software update." };
706 }
707
708# $self->register_face_handler ($exp_table, sub {
709# my ($face) = @_;
710
711# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
712# $_->() for values %{ $self->{on_exp_update} || {} };
713# });
714
715 ()
716 });
517} 717}
518 718
519############################################################################# 719#############################################################################
520 720
521sub destroy_query_dialog { 721sub destroy_query_dialog {
764 mapw => $mapw, 964 mapw => $mapw,
765 maph => $maph, 965 maph => $maph,
766 966
767 c_version => { 967 c_version => {
768 client => "deliantra", 968 client => "deliantra",
769 clientver => $DC::VERSION, 969 clientver => "$DC::VERSION$Urlader::EXE_VER",
770 gl_vendor => DC::OpenGL::gl_vendor, 970 gl_vendor => DC::OpenGL::gl_vendor,
771 gl_version => DC::OpenGL::gl_version, 971 gl_version => DC::OpenGL::gl_version,
772 }, 972 },
773 973
774 map_widget => $MAPWIDGET, 974 map_widget => $MAPWIDGET,
782 }, 982 },
783 983
784 on_connect => sub { 984 on_connect => sub {
785 if ($_[0]) { 985 if ($_[0]) {
786 DC::lowdelay fileno $CONN->{fh}; 986 DC::lowdelay fileno $CONN->{fh};
987
988 ota_update_check;
787 989
788 status "successfully connected to the server"; 990 status "successfully connected to the server";
789 } else { 991 } else {
790 undef $CONN; 992 undef $CONN;
791 status "unable to connect: $!"; 993 status "unable to connect: $!";
1131 text => $CFG->{audio_driver}, 1333 text => $CFG->{audio_driver},
1132 template => "dsound1234", 1334 template => "dsound1234",
1133 tooltip => "You can override the audio driver to use here. Leaving it empty will result " 1335 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 " 1336 . "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> " 1337 . "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" 1338 . "or other system-specific drivers. Selecting the wrong driver here will simply result "
1137 . "in no sound.", 1339 . "in no sound.",
1138 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 } 1340 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 }
1139 ); 1341 );
1140 1342
1141 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects"); 1343 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects");
1841 2043
1842 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); 2044 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory");
1843 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => ""); 2045 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => "");
1844 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory"); 2046 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory");
1845 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); 2047 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
2048 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
2049 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
1846 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); 2050 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
1847 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_ID, tooltip => ""); 2051 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
1848 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Version (Prebuilt)"); 2052 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
1849 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_VER, tooltip => ""); 2053 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
1850 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Update (Prebuilt)");
1851 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::UPDPAR, tooltip => "");
1852 } 2054 }
1853 2055
1854 $vbox 2056 $vbox
1855} 2057}
1856 2058
2030 2232
2031sub media_window { 2233sub media_window {
2032 my $vb = new DC::UI::VBox; 2234 my $vb = new DC::UI::VBox;
2033 2235
2034 $vb->add (new DC::UI::FancyFrame 2236 $vb->add (new DC::UI::FancyFrame
2035 label => "Currently playing music", 2237 label => "Current background music",
2036 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2238 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
2037 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), 2239 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2038 ); 2240 );
2241
2242 $vb->add (new DC::UI::FancyFrame
2243 label => "Current downloads",
2244 child => ($DOWNLOADS_WIDGET = new DC::UI::Table
2245 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2246 );
2247
2248 $DOWNLOADS_WIDGET->connect (visibility_change => sub {
2249 my ($self) = @_;
2250
2251 delete $self->{updater};
2252 return unless $_[1];
2253
2254 $self->{updater} = AE::timer 0, 0.7, sub {
2255 $self->clear;
2256
2257 return unless $CONN;
2258
2259 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2260 return unless @nums;
2261
2262 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2263 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2264
2265 for my $row (0 .. $#nums) {
2266 my $num = $nums[$row];
2267
2268 my $total = length $CONN->{ix_recv_buf}{$num};
2269 my $got = $total - $CONN->{ix_recv_ofs}{$num};
2270
2271 $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => "");
2272 $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => "");
2273 }
2274 };
2275 });
2039 2276
2040 $vb->add (new DC::UI::FancyFrame 2277 $vb->add (new DC::UI::FancyFrame
2041 label => "Other media used in this session", 2278 label => "Other media used in this session",
2042 expand => 1, 2279 expand => 1,
2043 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2280 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2044 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2281 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2045 ); 2282 );
2046 2283
2047 $vb 2284 $vb
2048} 2285}
2049 2286
2234sub open_quit_dialog { 2471sub open_quit_dialog {
2235 unless ($QUIT_DIALOG) { 2472 unless ($QUIT_DIALOG) {
2236 $QUIT_DIALOG = new DC::UI::Toplevel 2473 $QUIT_DIALOG = new DC::UI::Toplevel
2237 x => "center", 2474 x => "center",
2238 y => "center", 2475 y => "center",
2239 z => 50, 2476 z => 60,
2240 title => "Really Quit?", 2477 title => "Really Quit?",
2241 on_key_down => sub { 2478 on_key_down => sub {
2242 my ($dialog, $ev) = @_; 2479 my ($dialog, $ev) = @_;
2243 $ev->{sym} == 27 and $dialog->hide; 2480 $ev->{sym} == 27 and $dialog->hide;
2244 } 2481 }
2838 }; 3075 };
2839 } 3076 }
2840 } 3077 }
2841 } 3078 }
2842 3079
3080 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3081 # these are ignored under windows, for some reason, and thus set in the loader
2843 $ENV{FONTCONFIG_FILE} = DC::find_rcfile "fonts/fonts.conf"; 3082 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2844 $ENV{FONTCONFIG_DIR} = DC::find_rcfile "fonts"; 3083 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3084 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2845 3085
2846 { 3086 {
2847 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3087 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2848 DejaVuSans.ttf 3088 DejaVuSans.ttf
2849 DejaVuSansMono.ttf 3089 DejaVuSansMono.ttf

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines