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.6 by root, Sat Dec 31 04:23:42 2011 UTC vs.
Revision 1.13 by root, Sat Jan 7 19:43:46 2012 UTC

18} 18}
19 19
20use common::sense; 20use common::sense;
21use Carp 'verbose'; 21use Carp 'verbose';
22use Cwd (); 22use Cwd ();
23use Digest::MD5 ();
23use EV; 24use EV;
24BEGIN { *time = \&EV::time } 25BEGIN { *time = \&EV::time }
25 26
26use List::Util qw(max min); 27use 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
204sub clienterror($;$) { 205sub 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
217sub status { 218sub status {
522 523
523 DC::Mix_CloseAudio if $SDL_MIXER; 524 DC::Mix_CloseAudio if $SDL_MIXER;
524 undef $SDL_MIXER; 525 undef $SDL_MIXER;
525 526
526 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 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
618 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
619
620 if (Coro::AIO::aio_rename "$override.tmp", $override) {
621 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
622 Coro::AIO::aio_unlink "$override.tmp";
623 }
624
625 $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." });
626 };
627
628 $CONN->{ota_update} = Guard::guard {
629 $coro->cancel;
630 };
631}
632
633sub ota_update_ask {
634 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
635
636 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
637 x => "center",
638 y => "center",
639 z => 55,
640 force_w => $::WIDTH * 0.7,
641 force_h => $::HEIGHT * 0.7,
642 title => "Software update available",
643 child => my $vbox = new DC::UI::VBox,
644 ;
645
646 $vbox->add (new DC::UI::Label
647 ellipsise => 0,
648 text => "The server offers a software update, "
649 . "do you want to start downloading this update in the background?",
650 );
651
652 $vbox->add (new DC::UI::FancyFrame
653 expand => 1,
654 label => "Details",
655 child => (new DC::UI::TextScroller
656 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
657 par => [{
658 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
659 . "New revision: $ver\n"
660 . "Download size: $size bytes</tt>\n\n"
661 . "Changes:\n\n"
662 . DC::asxml $changes
663 }],
664 ),
665 );
666
667 $vbox->add (my $hbox = new DC::UI::HBox);
668
669 $hbox->add (new DC::UI::Button
670 expand => 1,
671 text => "Not now",
672 on_activate => sub {
673 $dialog->destroy;
674 0
675 }
676 );
677 $hbox->add (new DC::UI::Button
678 expand => 1,
679 text => "Yes, start downloading",
680 on_activate => sub {
681 $dialog->destroy;
682 ota_update $face, $size, $md5;
683 0
684 },
685 );
686
687 $dialog->show;
688}
689
690sub ota_update_check {
691 return unless defined $Urlader::EXE_ID;
692
693 ::message { markup => "Checking for software update..." };
694
695 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
696 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
697
698 if ($ok) {
699 if (defined $ver) {
700 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
701 &ota_update_ask;
702 } else {
703 ::message { markup => "Server has no newer version." };
704 }
705 } else {
706 ::message { markup => "Server does not support software update." };
707 }
708
709# $self->register_face_handler ($exp_table, sub {
710# my ($face) = @_;
711
712# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
713# $_->() for values %{ $self->{on_exp_update} || {} };
714# });
715
716 ()
717 });
527} 718}
528 719
529############################################################################# 720#############################################################################
530 721
531sub destroy_query_dialog { 722sub destroy_query_dialog {
774 mapw => $mapw, 965 mapw => $mapw,
775 maph => $maph, 966 maph => $maph,
776 967
777 c_version => { 968 c_version => {
778 client => "deliantra", 969 client => "deliantra",
779 clientver => $DC::VERSION, 970 clientver => "$DC::VERSION$Urlader::EXE_VER",
780 gl_vendor => DC::OpenGL::gl_vendor, 971 gl_vendor => DC::OpenGL::gl_vendor,
781 gl_version => DC::OpenGL::gl_version, 972 gl_version => DC::OpenGL::gl_version,
782 }, 973 },
783 974
784 map_widget => $MAPWIDGET, 975 map_widget => $MAPWIDGET,
792 }, 983 },
793 984
794 on_connect => sub { 985 on_connect => sub {
795 if ($_[0]) { 986 if ($_[0]) {
796 DC::lowdelay fileno $CONN->{fh}; 987 DC::lowdelay fileno $CONN->{fh};
988
989 ota_update_check;
797 990
798 status "successfully connected to the server"; 991 status "successfully connected to the server";
799 } else { 992 } else {
800 undef $CONN; 993 undef $CONN;
801 status "unable to connect: $!"; 994 status "unable to connect: $!";
1855 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); 2048 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
1856 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)"); 2049 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
1857 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => ""); 2050 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
1858 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); 2051 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
1859 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => ""); 2052 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
1860 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Version (Prebuilt)"); 2053 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
1861 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => ""); 2054 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
1862 } 2055 }
1863 2056
1864 $vbox 2057 $vbox
1865} 2058}
2057 my ($self) = @_; 2250 my ($self) = @_;
2058 2251
2059 delete $self->{updater}; 2252 delete $self->{updater};
2060 return unless $_[1]; 2253 return unless $_[1];
2061 2254
2062 $self->{updater} = AE::timer 0, 1, sub { 2255 $self->{updater} = AE::timer 0, 0.7, sub {
2063 $self->clear; 2256 $self->clear;
2064 2257
2065 return unless $CONN; 2258 return unless $CONN;
2066 2259
2067 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} }; 2260 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2261 return unless @nums;
2068 2262
2069 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face"); 2263 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2070 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total"); 2264 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2071 2265
2072 for my $row (0 .. $#nums) { 2266 for my $row (0 .. $#nums) {
2278sub open_quit_dialog { 2472sub open_quit_dialog {
2279 unless ($QUIT_DIALOG) { 2473 unless ($QUIT_DIALOG) {
2280 $QUIT_DIALOG = new DC::UI::Toplevel 2474 $QUIT_DIALOG = new DC::UI::Toplevel
2281 x => "center", 2475 x => "center",
2282 y => "center", 2476 y => "center",
2283 z => 50, 2477 z => 60,
2284 title => "Really Quit?", 2478 title => "Really Quit?",
2285 on_key_down => sub { 2479 on_key_down => sub {
2286 my ($dialog, $ev) = @_; 2480 my ($dialog, $ev) = @_;
2287 $ev->{sym} == 27 and $dialog->hide; 2481 $ev->{sym} == 27 and $dialog->hide;
2288 } 2482 }
2504 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2698 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2505 2699
2506 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2700 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2507 $FULLSCREEN = $CFG->{fullscreen}; 2701 $FULLSCREEN = $CFG->{fullscreen};
2508 $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
2509 2705
2510 # 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
2511 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2707 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2512 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2708 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2513 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2709 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines