… | |
… | |
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 | |
… | |
… | |
195 | AnyEvent::Util::fh_nonblocking $fh, 1; |
196 | AnyEvent::Util::fh_nonblocking $fh, 1; |
196 | |
197 | |
197 | $msg =~ s/\s+$//; |
198 | $msg =~ s/\s+$//; |
198 | |
199 | |
199 | # backtrace as second step, in case it crashes, too |
200 | # backtrace as second step, in case it crashes, too |
200 | 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" |
201 | if $backtrace; |
202 | if $backtrace; |
202 | }; |
203 | }; |
203 | |
204 | |
204 | sub clienterror($;$) { |
205 | sub clienterror($;$) { |
205 | my ($msg, $backtrace) = @_; |
206 | my ($msg, $backtrace) = @_; |
… | |
… | |
207 | warn $msg; |
208 | warn $msg; |
208 | |
209 | |
209 | return unless $CONN; |
210 | return unless $CONN; |
210 | |
211 | |
211 | $CONN->send_exti_msg (clientlog => $msg); |
212 | $CONN->send_exti_msg (clientlog => $msg); |
212 | $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; |
213 | } |
214 | } |
214 | |
215 | |
215 | ############################################################################# |
216 | ############################################################################# |
216 | |
217 | |
217 | sub status { |
218 | sub status { |
… | |
… | |
527 | } |
528 | } |
528 | |
529 | |
529 | ############################################################################# |
530 | ############################################################################# |
530 | # Over-the-air updates |
531 | # Over-the-air updates |
531 | |
532 | |
532 | sub ota_update_finish { |
|
|
533 | $MESSAGE_DIST->message ({ type => "ota_update", markup => $_[0] }); |
|
|
534 | } |
|
|
535 | |
|
|
536 | sub ota_update_status { |
|
|
537 | } |
|
|
538 | |
|
|
539 | sub ota_update { |
533 | sub ota_update { |
540 | my ($face, $size) = @_; |
534 | my ($face, $size, $md5) = @_; |
541 | |
535 | |
542 | my $coro = Coro::async_pool { |
536 | my $coro = Coro::async_pool { |
543 | my $override = "$Urlader::EXE_DIR/override"; |
537 | my $override = "$Urlader::EXE_DIR/override"; |
544 | |
538 | |
545 | $MESSAGE_DIST->add_channel ({ |
539 | $MESSAGE_DIST->add_channel ({ |
… | |
… | |
551 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." }); |
545 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." }); |
552 | |
546 | |
553 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777; |
547 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777; |
554 | |
548 | |
555 | unless ($fh) { |
549 | unless ($fh) { |
556 | ota_update_finish "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!"; |
550 | $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") }); |
557 | return; |
551 | return; |
558 | } |
552 | } |
559 | |
553 | |
560 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." }); |
554 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." }); |
561 | |
555 | |
562 | my $cv = AE::cv; |
556 | my $cv = AE::cv; |
563 | my $error; |
557 | my $error; |
564 | |
558 | |
565 | $cv->begin (Coro::rouse_cb); |
559 | $cv->begin (Coro::rouse_cb); |
566 | |
|
|
567 | $CONN->ask_face ( |
560 | $CONN->ask_face ( |
568 | $face, |
561 | $face, |
569 | -1000, |
562 | -1000, |
570 | sub { |
563 | sub { |
571 | $STATUSBOX->add ( |
564 | $STATUSBOX->add ( |
… | |
… | |
596 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." }); |
589 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." }); |
597 | Coro::AIO::aio_unlink "$override.tmp"; |
590 | Coro::AIO::aio_unlink "$override.tmp"; |
598 | return; |
591 | return; |
599 | } |
592 | } |
600 | |
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 | Coro::AIO::aio_readahead $fh, 0, $size; |
|
|
603 | |
|
|
604 | my $f_md5 = new Digest::MD5; |
|
|
605 | binmode $fh; # ugh :( |
|
|
606 | $f_md5->addfile ($fh); |
|
|
607 | $f_md5 = $f_md5->hexdigest; |
|
|
608 | $error ||= $md5 ne $f_md5; |
|
|
609 | } |
|
|
610 | } |
|
|
611 | |
|
|
612 | if ($error) { |
|
|
613 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "verification failed, update aborted." }); |
|
|
614 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
615 | return; |
|
|
616 | } |
|
|
617 | |
601 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." }); |
618 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." }); |
602 | |
619 | |
603 | if (Coro::AIO::aio_rename "$override.tmp", $override) { |
620 | if (Coro::AIO::aio_rename "$override.tmp", $override) { |
604 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." }); |
621 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." }); |
605 | Coro::AIO::aio_unlink "$override.tmp"; |
622 | Coro::AIO::aio_unlink "$override.tmp"; |
606 | } |
623 | } |
607 | |
624 | |
608 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "update successfull, changes become active at next start." }); |
625 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." }); |
609 | }; |
626 | }; |
610 | |
627 | |
611 | $CONN->{ota_update} = Guard::guard { |
628 | $CONN->{ota_update} = Guard::guard { |
612 | $coro->cancel; |
629 | $coro->cancel; |
613 | }; |
630 | }; |
614 | } |
631 | } |
615 | |
632 | |
616 | sub ota_update_ask { |
633 | sub ota_update_ask { |
617 | my ($ok, $face, $ver, $size, $changes) = @_; |
634 | my ($ok, $face, $ver, $size, $md5, $changes) = @_; |
618 | |
635 | |
619 | $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel |
636 | $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel |
620 | x => "center", |
637 | x => "center", |
621 | y => "center", |
638 | y => "center", |
|
|
639 | z => 55, |
622 | max_w => $::WIDTH * 0.7, |
640 | force_w => $::WIDTH * 0.7, |
623 | max_h => $::WIDTH * 0.7, |
641 | force_h => $::HEIGHT * 0.7, |
624 | title => "Software update available", |
642 | title => "Software update available", |
625 | child => my $vbox = new DC::UI::VBox, |
643 | child => my $vbox = new DC::UI::VBox, |
626 | ; |
644 | ; |
627 | |
645 | |
628 | $vbox->add (new DC::UI::Label |
646 | $vbox->add (new DC::UI::Label |
629 | ellipsise => 0, |
647 | ellipsise => 0, |
630 | text => "The server offers a software update, " |
648 | text => "The server offers a software update, " |
631 | . "do you want to start downloading this update in the background?", |
649 | . "do you want to start downloading this update in the background?", |
632 | ); |
650 | ); |
633 | |
651 | |
634 | $vbox->add (new DC::UI::FancyFrame |
652 | $vbox->add (new DC::UI::FancyFrame |
635 | expand => 1, |
653 | expand => 1, |
636 | label => "Changes", |
654 | label => "Details", |
637 | child => (new DC::UI::TextScroller |
655 | child => (new DC::UI::TextScroller |
638 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4, |
656 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4, |
639 | par => [{ |
657 | par => [{ |
640 | markup => "<tt>Old revision: $Urlader::EXE_VER\n" |
658 | markup => "<tt>Old revision: $Urlader::EXE_VER\n" |
641 | . "New revision: $ver\n" |
659 | . "New revision: $ver\n" |
642 | . "Download size: $size bytes</tt>\n\n" |
660 | . "Download size: $size bytes</tt>\n\n" |
|
|
661 | . "Changes:\n\n" |
643 | . DC::asxml $changes |
662 | . DC::asxml $changes |
644 | }], |
663 | }], |
645 | ), |
664 | ), |
646 | ); |
665 | ); |
647 | |
666 | |
… | |
… | |
658 | $hbox->add (new DC::UI::Button |
677 | $hbox->add (new DC::UI::Button |
659 | expand => 1, |
678 | expand => 1, |
660 | text => "Yes, start downloading", |
679 | text => "Yes, start downloading", |
661 | on_activate => sub { |
680 | on_activate => sub { |
662 | $dialog->destroy; |
681 | $dialog->destroy; |
663 | ota_update $face, $size; |
682 | ota_update $face, $size, $md5; |
664 | 0 |
683 | 0 |
665 | }, |
684 | }, |
666 | ); |
685 | ); |
667 | |
686 | |
668 | $dialog->show; |
687 | $dialog->show; |
… | |
… | |
672 | return unless defined $Urlader::EXE_ID; |
691 | return unless defined $Urlader::EXE_ID; |
673 | |
692 | |
674 | ::message { markup => "Checking for software update..." }; |
693 | ::message { markup => "Checking for software update..." }; |
675 | |
694 | |
676 | $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub { |
695 | $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub { |
677 | my ($ok, $face, $ver, $size, $changes) = @_; |
696 | my ($ok, $face, $ver, $size, $md5, $changes) = @_; |
678 | |
697 | |
679 | if ($ok) { |
698 | if ($ok) { |
680 | if (defined $ver) { |
699 | if (defined $ver) { |
681 | ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." }; |
700 | ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." }; |
682 | &ota_update_ask; |
701 | &ota_update_ask; |
… | |
… | |
946 | mapw => $mapw, |
965 | mapw => $mapw, |
947 | maph => $maph, |
966 | maph => $maph, |
948 | |
967 | |
949 | c_version => { |
968 | c_version => { |
950 | client => "deliantra", |
969 | client => "deliantra", |
951 | clientver => $DC::VERSION, |
970 | clientver => "$DC::VERSION$Urlader::EXE_VER", |
952 | gl_vendor => DC::OpenGL::gl_vendor, |
971 | gl_vendor => DC::OpenGL::gl_vendor, |
953 | gl_version => DC::OpenGL::gl_version, |
972 | gl_version => DC::OpenGL::gl_version, |
954 | }, |
973 | }, |
955 | |
974 | |
956 | map_widget => $MAPWIDGET, |
975 | map_widget => $MAPWIDGET, |
… | |
… | |
2453 | sub open_quit_dialog { |
2472 | sub open_quit_dialog { |
2454 | unless ($QUIT_DIALOG) { |
2473 | unless ($QUIT_DIALOG) { |
2455 | $QUIT_DIALOG = new DC::UI::Toplevel |
2474 | $QUIT_DIALOG = new DC::UI::Toplevel |
2456 | x => "center", |
2475 | x => "center", |
2457 | y => "center", |
2476 | y => "center", |
2458 | z => 50, |
2477 | z => 60, |
2459 | title => "Really Quit?", |
2478 | title => "Really Quit?", |
2460 | on_key_down => sub { |
2479 | on_key_down => sub { |
2461 | my ($dialog, $ev) = @_; |
2480 | my ($dialog, $ev) = @_; |
2462 | $ev->{sym} == 27 and $dialog->hide; |
2481 | $ev->{sym} == 27 and $dialog->hide; |
2463 | } |
2482 | } |
… | |
… | |
2679 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2698 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2680 | |
2699 | |
2681 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2700 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2682 | $FULLSCREEN = $CFG->{fullscreen}; |
2701 | $FULLSCREEN = $CFG->{fullscreen}; |
2683 | $FAST = $CFG->{fast}; |
2702 | $FAST = $CFG->{fast}; |
|
|
2703 | |
|
|
2704 | DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init |
2684 | |
2705 | |
2685 | # due to mac os x braindamage, we simply retry with !fullscreen in case of an error |
2706 | # due to mac os x braindamage, we simply retry with !fullscreen in case of an error |
2686 | DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN |
2707 | DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN |
2687 | or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN |
2708 | or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN |
2688 | or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; |
2709 | or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; |