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.8 by root, Wed Jan 4 11:23:23 2012 UTC vs.
Revision 1.25 by root, Mon Nov 19 02:03:56 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
28use Deliantra; 29use Deliantra;
30use Deliantra::Util;
29use Deliantra::Protocol::Constants; 31use Deliantra::Protocol::Constants;
30 32
31use AnyEvent::Util (); 33use AnyEvent::Util ();
32use AnyEvent::Socket (); 34use AnyEvent::Socket ();
33use AnyEvent::DNS (); 35use AnyEvent::DNS ();
34 36
35use Compress::LZF; 37use Compress::LZF;
36use JSON::XS; 38use JSON::XS;
39use Urlader;
37 40
38use DC; 41use DC;
39 42
40sub crash($;$) { 43sub crash($;$) {
41 # nop at compiletime 44 # nop at compiletime
43 46
44BEGIN { 47BEGIN {
45 $SIG{__DIE__} = sub { 48 $SIG{__DIE__} = sub {
46 return if $^S; # quick reject 49 return if $^S; # quick reject
47 50
48 # return if there are any eval contexts in the csall stack 51 # return if there are any eval contexts in the call stack
49 for my $i (0..999) { 52 for my $i (0..999) {
50 my ($sub, $is_require) = (caller $i)[3, 7] 53 my ($sub, $is_require) = (caller $i)[3, 7]
51 or last; 54 or last;
52 return if $sub eq "(eval)" && !$is_require; 55 return if $sub eq "(eval)" && !$is_require;
53 } 56 }
56 DC::fatal Carp::longmess "$_[0]"; 59 DC::fatal Carp::longmess "$_[0]";
57 } 60 }
58} 61}
59 62
60use DC::OpenGL (); 63use DC::OpenGL ();
64use DC::Audio ();
61use DC::Protocol; 65use DC::Protocol;
62use DC::DB; 66use DC::DB;
63use DC::UI; 67use DC::UI;
64use DC::UI::Canvas; 68use DC::UI::Canvas;
65use DC::UI::Inventory; 69use DC::UI::Inventory;
125our $MENUBAR; # the hbox at the top 129our $MENUBAR; # the hbox at the top
126our $MENUPOPUP; 130our $MENUPOPUP;
127our $BUTTONBAR; # the menu buttons 131our $BUTTONBAR; # the menu buttons
128our $METASERVER; 132our $METASERVER;
129our $LOGIN_BUTTON; 133our $LOGIN_BUTTON;
134our $LOGIN_ERROR;
130our $QUIT_DIALOG; 135our $QUIT_DIALOG;
131our $HOST_ENTRY; 136our $HOST_ENTRY;
132our $FULLSCREEN_ENABLE; 137our $FULLSCREEN_ENABLE;
133our $PICKUP_ENABLE; 138our $PICKUP_ENABLE;
134our $SERVER_INFO; 139our $SERVER_INFO;
195 AnyEvent::Util::fh_nonblocking $fh, 1; 200 AnyEvent::Util::fh_nonblocking $fh, 1;
196 201
197 $msg =~ s/\s+$//; 202 $msg =~ s/\s+$//;
198 203
199 # backtrace as second step, in case it crashes, too 204 # backtrace as second step, in case it crashes, too
200 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"
201 if $backtrace; 206 if $backtrace;
202}; 207};
203 208
204sub clienterror($;$) { 209sub clienterror($;$) {
205 my ($msg, $backtrace) = @_; 210 my ($msg, $backtrace) = @_;
207 warn $msg; 212 warn $msg;
208 213
209 return unless $CONN; 214 return unless $CONN;
210 215
211 $CONN->send_exti_msg (clientlog => $msg); 216 $CONN->send_exti_msg (clientlog => $msg);
212 $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;
213} 218}
214 219
215############################################################################# 220#############################################################################
216 221
217sub status { 222sub status {
248 : "[<span foreground='#888'>num</span>]"; 253 : "[<span foreground='#888'>num</span>]";
249 254
250 # <tt> around next statement works around some bug that keeps the 255 # <tt> around next statement works around some bug that keeps the
251 # "font =>" from being used on windows 256 # "font =>" from being used on windows
252 $MODBOX->set_markup ("<tt>$markup</tt>"); 257 $MODBOX->set_markup ("<tt>$markup</tt>");
258}
259
260sub 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;
253} 292}
254 293
255############################################################################# 294#############################################################################
256#TODO: maybe move into own audio module... 295#TODO: maybe move into own audio module...
257 296
472 audio_music_push; 511 audio_music_push;
473} 512}
474 513
475sub audio_init { 514sub audio_init {
476 if ($CFG->{audio_enable}) { 515 if ($CFG->{audio_enable}) {
477 if (length $CFG->{audio_driver}) { 516 DC::Audio::init $CFG->{audio_driver};
478 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
479 DC::SDL_Init DC::SDL_INIT_AUDIO
480 and die "SDL::Init failed!\n";
481 } else {
482 DC::SDL_Init DC::SDL_INIT_AUDIO
483 and die "SDL::Init failed!\n";
484 }
485
486 $ENV{MIX_EFFECTSMAXSPEED} = 1;
487 $SDL_MIXER = !DC::Mix_OpenAudio
488 $CFG->{audio_hw_frequency},
489 DC::MIX_DEFAULT_FORMAT,
490 $CFG->{audio_hw_channels},
491 $CFG->{audio_hw_chunksize};
492 517
493 if ($SDL_MIXER) { 518 if ($SDL_MIXER) {
494 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
495
496 audio_music_finished; 519 audio_music_finished;
497 } else { 520 } else {
498 status "Unable to open sound device: there will be no sound"; 521 status "Unable to open sound device: there will be no sound";
499 } 522 }
500 } else { 523 } else {
527} 550}
528 551
529############################################################################# 552#############################################################################
530# Over-the-air updates 553# Over-the-air updates
531 554
532sub ota_update_finish {
533 $MESSAGE_DIST->message ({ type => "ota_update", markup => $_[0] });
534}
535
536sub ota_update_status {
537}
538
539sub ota_update { 555sub ota_update {
540 my ($face, $size) = @_; 556 my ($face, $size, $md5) = @_;
541 557
542 my $coro = Coro::async_pool { 558 my $coro = Coro::async_pool {
543 my $override = "$Urlader::EXE_DIR/override"; 559 my $override = "$Urlader::EXE_DIR/override";
544 560
545 $MESSAGE_DIST->add_channel ({ 561 $MESSAGE_DIST->add_channel ({
551 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." }); 567 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." });
552 568
553 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777; 569 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777;
554 570
555 unless ($fh) { 571 unless ($fh) {
556 ota_update_finish "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!"; 572 $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") });
557 return; 573 return;
558 } 574 }
559 575
560 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." }); 576 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." });
561 577
562 my $cv = AE::cv; 578 my $cv = AE::cv;
563 my $error; 579 my $error;
564 580
565 $cv->begin (Coro::rouse_cb); 581 $cv->begin (Coro::rouse_cb);
566
567 $CONN->ask_face ( 582 $CONN->ask_face (
568 $face, 583 $face,
569 -1000, 584 -1000,
570 sub { 585 sub {
571 $STATUSBOX->add ( 586 $STATUSBOX->add (
596 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." }); 611 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." });
597 Coro::AIO::aio_unlink "$override.tmp"; 612 Coro::AIO::aio_unlink "$override.tmp";
598 return; 613 return;
599 } 614 }
600 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
601 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." }); 640 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
602 641
603 if (Coro::AIO::aio_rename "$override.tmp", $override) { 642 if (Coro::AIO::aio_rename "$override.tmp", $override) {
604 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." }); 643 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
605 Coro::AIO::aio_unlink "$override.tmp"; 644 Coro::AIO::aio_unlink "$override.tmp";
606 } 645 }
607 646
608 $MESSAGE_DIST->message ({ type => "ota_update", markup => "update successfull, changes become active at next start." }); 647 $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." });
609 }; 648 };
610 649
611 $CONN->{ota_update} = Guard::guard { 650 $CONN->{ota_update} = Guard::guard {
612 $coro->cancel; 651 $coro->cancel;
613 }; 652 };
614} 653}
615 654
616sub ota_update_ask { 655sub ota_update_ask {
617 my ($ok, $face, $ver, $size, $changes) = @_; 656 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
618 657
619 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel 658 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
620 x => "center", 659 x => "center",
621 y => "center", 660 y => "center",
661 z => 55,
622 max_w => $::WIDTH * 0.7, 662 force_w => $::WIDTH * 0.7,
623 max_h => $::WIDTH * 0.7, 663 force_h => $::HEIGHT * 0.7,
624 title => "Software update available", 664 title => "Software update available",
625 child => my $vbox = new DC::UI::VBox, 665 child => my $vbox = new DC::UI::VBox,
626 ; 666 ;
627 667
628 $vbox->add (new DC::UI::Label 668 $vbox->add (new DC::UI::Label
629 ellipsise => 0, 669 ellipsise => 0,
630 text => "The server offers a software update, " 670 text => "The server offers a software update, "
631 . "do you want to start downloading this update in the background?", 671 . "do you want to start downloading this update in the background?",
632 ); 672 );
633 673
634 $vbox->add (new DC::UI::FancyFrame 674 $vbox->add (new DC::UI::FancyFrame
635 expand => 1, 675 expand => 1,
636 label => "Changes", 676 label => "Details",
637 child => (new DC::UI::TextScroller 677 child => (new DC::UI::TextScroller
638 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4, 678 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
639 par => [{ 679 par => [{
640 markup => "<tt>Old revision: $Urlader::EXE_VER\n" 680 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
641 . "New revision: $ver\n" 681 . "New revision: $ver\n"
642 . "Download size: $size bytes</tt>\n\n" 682 . "Download size: $size bytes</tt>\n\n"
683 . "Changes:\n\n"
643 . DC::asxml $changes 684 . DC::asxml $changes
644 }], 685 }],
645 ), 686 ),
646 ); 687 );
647 688
658 $hbox->add (new DC::UI::Button 699 $hbox->add (new DC::UI::Button
659 expand => 1, 700 expand => 1,
660 text => "Yes, start downloading", 701 text => "Yes, start downloading",
661 on_activate => sub { 702 on_activate => sub {
662 $dialog->destroy; 703 $dialog->destroy;
663 ota_update $face, $size; 704 ota_update $face, $size, $md5;
664 0 705 0
665 }, 706 },
666 ); 707 );
667 708
668 $dialog->show; 709 $dialog->show;
672 return unless defined $Urlader::EXE_ID; 713 return unless defined $Urlader::EXE_ID;
673 714
674 ::message { markup => "Checking for software update..." }; 715 ::message { markup => "Checking for software update..." };
675 716
676 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub { 717 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
677 my ($ok, $face, $ver, $size, $changes) = @_; 718 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
678 719
679 if ($ok) { 720 if ($ok) {
680 if (defined $ver) { 721 if (defined $ver) {
681 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." }; 722 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
682 &ota_update_ask; 723 &ota_update_ask;
684 ::message { markup => "Server has no newer version." }; 725 ::message { markup => "Server has no newer version." };
685 } 726 }
686 } else { 727 } else {
687 ::message { markup => "Server does not support software update." }; 728 ::message { markup => "Server does not support software update." };
688 } 729 }
689
690# $self->register_face_handler ($exp_table, sub {
691# my ($face) = @_;
692
693# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
694# $_->() for values %{ $self->{on_exp_update} || {} };
695# });
696 730
697 () 731 ()
698 }); 732 });
699} 733}
700 734
930 $vbox->add (@dialog); 964 $vbox->add (@dialog);
931 $dialog->show; 965 $dialog->show;
932} 966}
933 967
934sub dc_connect { 968sub dc_connect {
935 my ($host, $port) = @_; 969 my ($host, $port, $create) = @_;
936 970
937 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;
938 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;
939 973
940 $CONN = 974 $CONN =
941 new DC::Protocol 975 new DC::Protocol
942 host => $host, 976 host => $host,
943 port => $port, 977 port => $port,
978 create_login => $create,
944 user => $PROFILE->{user}, 979 user => $PROFILE->{user},
945 pass => $PROFILE->{password}, 980 pass => (pack "H*", $PROFILE->{password}),
946 mapw => $mapw, 981 mapw => $mapw,
947 maph => $maph, 982 maph => $maph,
948 983
949 c_version => { 984 c_version => {
950 client => "deliantra", 985 client => "deliantra",
951 clientver => $DC::VERSION, 986 clientver => "$DC::VERSION$Urlader::EXE_VER",
952 gl_vendor => DC::OpenGL::gl_vendor, 987 gl_vendor => DC::OpenGL::gl_vendor,
953 gl_version => DC::OpenGL::gl_version, 988 gl_version => DC::OpenGL::gl_version,
954 }, 989 },
955 990
956 map_widget => $MAPWIDGET, 991 map_widget => $MAPWIDGET,
970 ota_update_check; 1005 ota_update_check;
971 1006
972 status "successfully connected to the server"; 1007 status "successfully connected to the server";
973 } else { 1008 } else {
974 undef $CONN; 1009 undef $CONN;
975 status "unable to connect: $!"; 1010 $LOGIN_ERROR->{fg} = [1, 0, 0];
1011 $LOGIN_ERROR->set_text ("Unable to connect to server: $!");
976 stop_game(); 1012 stop_game();
977 } 1013 }
978 }, 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 },
979 ; 1022 ;
980} 1023}
981 1024
982sub start_game { 1025sub start_game($) {
1026 my ($create) = @_;
1027
983 status "logging in..."; 1028 status "logging in...";
984 1029
985 my $server = $PROFILE->{host} || $DEFAULT_SERVER; 1030 my $server = $PROFILE->{host} || $DEFAULT_SERVER;
986 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" 1031 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327"
987 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.";
1002 status "dns failure, using hardcoded address"; 1047 status "dns failure, using hardcoded address";
1003 $host = "194.126.175.154"; 1048 $host = "194.126.175.154";
1004 } 1049 }
1005 } 1050 }
1006 1051
1007 dc_connect $host, $port; 1052 dc_connect $host, $port, $create;
1008 }; 1053 };
1009 } else { 1054 } else {
1010 dc_connect $host, $port; 1055 dc_connect $host, $port, $create;
1011 } 1056 }
1012} 1057}
1013 1058
1014sub stop_game { 1059sub stop_game {
1015 crash "stop_game"; 1060 crash "stop_game";
1848 $vbox->add (new DC::UI::FancyFrame 1893 $vbox->add (new DC::UI::FancyFrame
1849 label => "Login Settings", 1894 label => "Login Settings",
1850 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]),
1851 ); 1896 );
1852 1897
1898 my $nullpw = "\x00" x 16;
1899
1853 $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");
1854 $table->add_at (1, 4, new DC::UI::Entry 1901 $table->add_at (1, 0, new DC::UI::Entry
1855 text => $PROFILE->{user}, 1902 text => $PROFILE->{user},
1856 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!",
1857 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } 1904 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 }
1858 ); 1905 );
1859 1906
1860 $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");
1861 $table->add_at (1, 5, new DC::UI::Entry 1908 $table->add_at (1, 1, my $pw1 = new DC::UI::Entry
1862 text => $PROFILE->{password}, 1909 text => $PROFILE->{password} ? $nullpw : "",
1863 hidden => 1, 1910 hidden => 1,
1864 tooltip => "The password for your character.", 1911 tooltip => "The password for your character.",
1865 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} = unpack "H*", Deliantra::Util::hash_pw $value
1921 if length $value && $value ne $nullpw;
1922 1
1923 },
1866 ); 1924 );
1867 1925
1868 $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button 1926 $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button
1869 expand => 1, 1927 expand => 1,
1870 text => "Login / Register", 1928 text => "Login to Existing Account",
1871 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.",
1872 on_activate => sub { 1930 on_activate => sub {
1873 $CONN ? stop_game 1931 $CONN ? stop_game
1874 : start_game; 1932 : start_game 0;
1875 1 1933 1
1876 }, 1934 },
1877 ); 1935 );
1878 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
1879 $vbox->add (new DC::UI::FancyFrame 1964 $vbox->add (new DC::UI::FancyFrame
1880 label => "How to Play", 1965 label => "How to Play",
1881 min_h => 240, 1966 min_h => 240,#d# should not be necessary - widget bug
1882 child => (new DC::UI::Label valign => 0, ellipsise => 0, 1967 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1883 markup => 1968 markup =>
1884 "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"
1885 . "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"
1886 . "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 "
1887 . "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>.",
1888 ), 1973 ),
1889 ); 1974 );
1890 1975
1891 $vbox 1976 $vbox
1892} 1977}
2010 $table->add_at (2, $row++, new DC::UI::Button 2095 $table->add_at (2, $row++, new DC::UI::Button
2011 text => "Save Now", 2096 text => "Save Now",
2012 tooltip => "Use this to manually save configuration and UI layout when " 2097 tooltip => "Use this to manually save configuration and UI layout when "
2013 . "autosave is disabled.", 2098 . "autosave is disabled.",
2014 on_activate => sub { 2099 on_activate => sub {
2015 DC::write_cfg; 2100 DC::save_cfg;
2016 0 2101 0
2017 } 2102 }
2018 ); 2103 );
2019 } 2104 }
2020 2105
2453sub open_quit_dialog { 2538sub open_quit_dialog {
2454 unless ($QUIT_DIALOG) { 2539 unless ($QUIT_DIALOG) {
2455 $QUIT_DIALOG = new DC::UI::Toplevel 2540 $QUIT_DIALOG = new DC::UI::Toplevel
2456 x => "center", 2541 x => "center",
2457 y => "center", 2542 y => "center",
2458 z => 50, 2543 z => 60,
2459 title => "Really Quit?", 2544 title => "Really Quit?",
2460 on_key_down => sub { 2545 on_key_down => sub {
2461 my ($dialog, $ev) = @_; 2546 my ($dialog, $ev) = @_;
2462 $ev->{sym} == 27 and $dialog->hide; 2547 $ev->{sym} == 27 and $dialog->hide;
2463 } 2548 }
2656 DC::set_theme $CFG->{uitheme}; 2741 DC::set_theme $CFG->{uitheme};
2657 2742
2658 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2743 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2659 $SDL_REINIT = 0; 2744 $SDL_REINIT = 0;
2660 2745
2661 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2746 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2662 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2747 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2663 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2748 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2664 @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)";
2665 2750
2666 @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;
2679 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2764 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2680 2765
2681 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2766 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2682 $FULLSCREEN = $CFG->{fullscreen}; 2767 $FULLSCREEN = $CFG->{fullscreen};
2683 $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
2684 2771
2685 # 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
2686 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2773 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2687 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2774 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2688 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2775 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2946 EV::unloop; 3033 EV::unloop;
2947 #d# TODO calling exit here hangs the process in some futex 3034 #d# TODO calling exit here hangs the process in some futex
2948}; 3035};
2949 3036
2950# 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
2951sub DC::Main::main { 3038sub DC::Main::run {
2952 { 3039 DC::SDL_main_hack {
3040 {
2953 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 3041 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2954 3042
2955 if (-e "$Deliantra::VARDIR/client.cf") { 3043 DC::load_cfg;
2956 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 3044 DC::upgrade_cfg;
2957 } else {
2958 #TODO: compatibility cruft
2959 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2960 print STDERR "INFO: used old configuration file\n";
2961 }
2962 3045
3046 DC::Audio::probe;
3047
2963 DC::DB::Server::run; 3048 DC::DB::Server::run;
2964 3049
2965 if ($CFG->{db_schema} < 1) { 3050 if ($CFG->{db_schema} < 1) {
2966 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";
2967 DC::DB::nuke_db; 3052 DC::DB::nuke_db;
2968 $CFG->{db_schema} = 1; 3053 $CFG->{db_schema} = 1;
2969 DC::write_cfg; 3054 DC::save_cfg;
2970 }
2971
2972 DC::DB::open_db;
2973
2974 DC::UI::set_layout ($::CFG->{layout});
2975
2976 my %DEF_CFG = (
2977 config_autosave => 1,
2978 sdl_mode => undef,
2979 fullscreen => 1,
2980 fast => 0,
2981 force_opengl11 => undef,
2982 disable_alpha => 0,
2983 smooth_movement => 1,
2984 smooth_transitions => 1,
2985 texture_compression => 1,
2986 map_scale => 1,
2987 fow_enable => 1,
2988 fow_intensity => 0,
2989 fow_texture => 0,
2990 map_smoothing => 1,
2991 gui_fontsize => 1,
2992 log_fontsize => 0.7,
2993 gauge_fontsize => 1,
2994 gauge_size => 0.35,
2995 stat_fontsize => 0.7,
2996 mapsize => 100,
2997 audio_enable => 1,
2998 audio_hw_channels => 0,
2999 audio_hw_frequency => 0,
3000 audio_hw_chunksize => 0,
3001 audio_mix_channels => 8,
3002 effects_enable => 1,
3003 effects_volume => 1,
3004 bgm_enable => 1,
3005 bgm_volume => 0.5,
3006 output_rate => "",
3007 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
3008 inv_sort => "mtime",
3009 default => "profile", # default profile
3010 show_tips => 1,
3011 logview_max_par => 1000,
3012 shift_fire_stop => 0,
3013 uitheme => "wood",
3014 map_shift_x => -24, # arbitrary
3015 map_shift_y => +24, # arbitrary
3016 );
3017
3018 while (my ($k, $v) = each %DEF_CFG) {
3019 $CFG->{$k} = $v unless exists $CFG->{$k};
3020 }
3021
3022 my @args = @ARGV;
3023
3024 # OS X passes some process serial number of other shit. they
3025 # could have used an env var or any other sane mechanism. but
3026 # would it be os x then? no...
3027 shift @args if $args[0] =~ /^-psn_/;
3028
3029 my $profile = 'default';
3030
3031 for (my $i = 0; $i < @args; $i++) {
3032 if ($args[$i] =~ /^--?profile$/) {
3033 $profile = $args[$i + 1];
3034 splice @args, $i, 2, ();
3035 $i = 0;
3036 } elsif ($args[$i] =~ /^--?h/) {
3037 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3038 exit 0;
3039 } 3055 }
3040 }
3041 3056
3042 $CFG->{profile}{$profile} ||= {}; 3057 DC::DB::open_db;
3043 $PROFILE = $CFG->{profile}{$profile};
3044 $PROFILE->{host} ||= "gameserver.deliantra.net";
3045 3058
3046 $PROFILE->{host} = $args[0] if @args > 0; 3059 DC::UI::set_layout ($::CFG->{layout});
3047 $PROFILE->{user} = $args[1] if @args > 1;
3048 $PROFILE->{password} = $args[2] if @args > 2;
3049 3060
3050 # convert old bindings (only default profile matters) 3061 my @args = @ARGV;
3051 if (my $bindings = delete $PROFILE->{bindings}) { 3062
3052 while (my ($mod, $syms) = each %$bindings) { 3063 # OS X passes some process serial number of other shit. they
3053 while (my ($sym, $cmds) = each %$syms) { 3064 # could have used an env var or any other sane mechanism. but
3054 push @{ $PROFILE->{macro} }, { 3065 # would it be os x then? no...
3055 accelkey => [$mod*1, $sym*1], 3066 shift @args if $args[0] =~ /^-psn_/;
3056 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, ();
3057 }; 3074 $i = 0;
3075 } elsif ($args[$i] =~ /^--?h/) {
3076 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3077 exit 0;
3058 } 3078 }
3059 } 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 }
3060 } 3099 }
3061 3100
3062 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed 3101 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3063 # these are ignored under windows, for some reason, and thus set in the loader 3102 # these are ignored under windows, for some reason, and thus set in the loader
3064 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3103 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3065 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3104 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3066 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3105 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3067 3106
3068 { 3107 {
3069 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3108 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3070 DejaVuSans.ttf 3109 DejaVuSans.ttf
3071 DejaVuSansMono.ttf 3110 DejaVuSansMono.ttf
3072 DejaVuSans-Bold.ttf 3111 DejaVuSans-Bold.ttf
3073 DejaVuSansMono-Bold.ttf 3112 DejaVuSansMono-Bold.ttf
3074 DejaVuSans-Oblique.ttf 3113 DejaVuSans-Oblique.ttf
3075 DejaVuSansMono-Oblique.ttf 3114 DejaVuSansMono-Oblique.ttf
3076 DejaVuSans-BoldOblique.ttf 3115 DejaVuSans-BoldOblique.ttf
3077 DejaVuSansMono-BoldOblique.ttf 3116 DejaVuSansMono-BoldOblique.ttf
3078 mona.ttf 3117 mona.ttf
3079 ); 3118 );
3080 3119
3081 DC::add_font $_ for @fonts; 3120 DC::add_font $_ for @fonts;
3082 3121
3083 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3122 $FONT_PROP = new_from_file DC::Font $fonts[0];
3084 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3123 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3085 3124
3086 $FONT_PROP->make_default; 3125 $FONT_PROP->make_default;
3087 3126
3088 DC::pango_init; 3127 DC::pango_init;
3089 } 3128 }
3090 3129
3091# compare mono (ft) vs. rgba (cairo) 3130# compare mono (ft) vs. rgba (cairo)
3092# ft - 1.8s, cairo 3s, even in alpha-only mode 3131# ft - 1.8s, cairo 3s, even in alpha-only mode
3093# for my $rgba (0..1) { 3132# for my $rgba (0..1) {
3094# my $t1 = Time::HiRes::time; 3133# my $t1 = Time::HiRes::time;
3099# } 3138# }
3100# my $t2 = Time::HiRes::time; 3139# my $t2 = Time::HiRes::time;
3101# warn $t2-$t1; 3140# warn $t2-$t1;
3102# } 3141# }
3103 3142
3143 }
3144
3145 DC::SDL_Init 0;
3104 DC::IMG_Init; video_init; 3146 DC::IMG_Init; video_init;
3105 DC::Mix_Init; audio_init; 3147 DC::Mix_Init; audio_init;
3106 }
3107 3148
3108 show_tip_of_the_day if $CFG->{show_tips}; 3149 show_tip_of_the_day if $CFG->{show_tips};
3109 3150
3110 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3151 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3111 undef $STARTUP_CANCEL; 3152 undef $STARTUP_CANCEL;
3112 (pop @::STARTUP_DONE)->() 3153 (pop @::STARTUP_DONE)->()
3113 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;
3114 }; 3170 };
3115
3116 debug_toggle 0;
3117
3118 delete $SIG{__DIE__};
3119 EV::loop;
3120
3121 DC::write_cfg if $CFG->{config_autosave};
3122
3123 #video_shutdown;
3124 #audio_shutdown;
3125
3126 DC::OpenGL::quit;
3127 DC::SDL_Quit;
3128 DC::DB::Server::stop;
3129} 3171}
3130
3131*DC::Main::run = \&DC::SDL_braino; # see sub above
3132 3172
31331 31731

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines