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.31 by root, Mon Nov 19 00:56:08 2018 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
27use Deliantra; 29use Deliantra;
30use Deliantra::Util;
28use Deliantra::Protocol::Constants; 31use Deliantra::Protocol::Constants;
29 32
30use AnyEvent::Util (); 33use AnyEvent::Util ();
31use AnyEvent::Socket (); 34use AnyEvent::Socket ();
32use AnyEvent::DNS (); 35use AnyEvent::DNS ();
33 36
34use Compress::LZF; 37use Compress::LZF;
35use JSON::XS; 38use JSON::XS;
39use Urlader;
36 40
37use DC; 41use DC;
38 42
39sub crash($;$) { 43sub crash($;$) {
40 # nop at compiletime 44 # nop at compiletime
41} 45}
42 46
43BEGIN { 47BEGIN {
44 $SIG{__DIE__} = sub { 48 $SIG{__DIE__} = sub {
45 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
46 crash "CRASH/DIE: $_[0]" => 1; 58 crash "CRASH/DIE: $_[0]" => 1;
47 DC::fatal Carp::longmess "$_[0]"; 59 DC::fatal Carp::longmess "$_[0]";
48 } 60 }
49} 61}
50 62
51use DC::OpenGL (); 63use DC::OpenGL ();
64use DC::Audio ();
52use DC::Protocol; 65use DC::Protocol;
53use DC::DB; 66use DC::DB;
54use DC::UI; 67use DC::UI;
55use DC::UI::Canvas; 68use DC::UI::Canvas;
56use DC::UI::Inventory; 69use DC::UI::Inventory;
61use DC::MessageDistributor; 74use DC::MessageDistributor;
62use DC::Pod; 75use DC::Pod;
63use DC::MapWidget; 76use DC::MapWidget;
64use DC::Macro; 77use DC::Macro;
65 78
79# printf "%5d %5d %5d %5d\n", $_, DC::minpot $_, DC::ld32 $_, 2 << ((DC::ld32 $_ - 1));
80
66$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 81$SIG{QUIT} = sub { Carp::cluck "QUIT" };
67$SIG{PIPE} = 'IGNORE'; 82$SIG{PIPE} = 'IGNORE';
68 83
69$EV::DIED = sub { 84$EV::DIED = sub {
70 crash "CRASH/EV::DIED: $@" => 0; 85 crash "CRASH/EV::DIED: $@" => 0;
116our $MENUBAR; # the hbox at the top 131our $MENUBAR; # the hbox at the top
117our $MENUPOPUP; 132our $MENUPOPUP;
118our $BUTTONBAR; # the menu buttons 133our $BUTTONBAR; # the menu buttons
119our $METASERVER; 134our $METASERVER;
120our $LOGIN_BUTTON; 135our $LOGIN_BUTTON;
136our $LOGIN_ERROR;
121our $QUIT_DIALOG; 137our $QUIT_DIALOG;
122our $HOST_ENTRY; 138our $HOST_ENTRY;
123our $FULLSCREEN_ENABLE; 139our $FULLSCREEN_ENABLE;
124our $PICKUP_ENABLE; 140our $PICKUP_ENABLE;
125our $SERVER_INFO; 141our $SERVER_INFO;
133our $PL_NOTEBOOK; 149our $PL_NOTEBOOK;
134our $PL_WINDOW; 150our $PL_WINDOW;
135 151
136our $MUSIC_PLAYING_WIDGET; 152our $MUSIC_PLAYING_WIDGET;
137our $LICENSE_WIDGET; 153our $LICENSE_WIDGET;
154our $DOWNLOADS_WIDGET;
138 155
139our $PICKUP_PAGE; 156our $PICKUP_PAGE;
140our $INVENTORY_PAGE; 157our $INVENTORY_PAGE;
141our $STATS_PAGE; 158our $STATS_PAGE;
142our $SKILL_PAGE; 159our $SKILL_PAGE;
185 AnyEvent::Util::fh_nonblocking $fh, 1; 202 AnyEvent::Util::fh_nonblocking $fh, 1;
186 203
187 $msg =~ s/\s+$//; 204 $msg =~ s/\s+$//;
188 205
189 # backtrace as second step, in case it crashes, too 206 # backtrace as second step, in case it crashes, too
190 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"
191 if $backtrace; 208 if $backtrace;
192}; 209};
193 210
194sub clienterror($;$) { 211sub clienterror($;$) {
195 my ($msg, $backtrace) = @_; 212 my ($msg, $backtrace) = @_;
197 warn $msg; 214 warn $msg;
198 215
199 return unless $CONN; 216 return unless $CONN;
200 217
201 $CONN->send_exti_msg (clientlog => $msg); 218 $CONN->send_exti_msg (clientlog => $msg);
202 $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;
203} 220}
204 221
205############################################################################# 222#############################################################################
206 223
207sub status { 224sub status {
238 : "[<span foreground='#888'>num</span>]"; 255 : "[<span foreground='#888'>num</span>]";
239 256
240 # <tt> around next statement works around some bug that keeps the 257 # <tt> around next statement works around some bug that keeps the
241 # "font =>" from being used on windows 258 # "font =>" from being used on windows
242 $MODBOX->set_markup ("<tt>$markup</tt>"); 259 $MODBOX->set_markup ("<tt>$markup</tt>");
260}
261
262sub 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;
243} 294}
244 295
245############################################################################# 296#############################################################################
246#TODO: maybe move into own audio module... 297#TODO: maybe move into own audio module...
247 298
462 audio_music_push; 513 audio_music_push;
463} 514}
464 515
465sub audio_init { 516sub audio_init {
466 if ($CFG->{audio_enable}) { 517 if ($CFG->{audio_enable}) {
467 if (length $CFG->{audio_driver}) { 518 DC::Audio::init;
468 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
469 DC::SDL_Init DC::SDL_INIT_AUDIO
470 and die "SDL::Init failed!\n";
471 } else {
472 DC::SDL_Init DC::SDL_INIT_AUDIO
473 and die "SDL::Init failed!\n";
474 }
475
476 $ENV{MIX_EFFECTSMAXSPEED} = 1;
477 $SDL_MIXER = !DC::Mix_OpenAudio
478 $CFG->{audio_hw_frequency},
479 DC::MIX_DEFAULT_FORMAT,
480 $CFG->{audio_hw_channels},
481 $CFG->{audio_hw_chunksize};
482 519
483 if ($SDL_MIXER) { 520 if ($SDL_MIXER) {
484 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
485
486 audio_music_finished; 521 audio_music_finished;
487 } else { 522 } else {
488 status "Unable to open sound device: there will be no sound"; 523 status "Unable to open sound device: there will be no sound";
489 } 524 }
490 } else { 525 } else {
512 547
513 DC::Mix_CloseAudio if $SDL_MIXER; 548 DC::Mix_CloseAudio if $SDL_MIXER;
514 undef $SDL_MIXER; 549 undef $SDL_MIXER;
515 550
516 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; 551 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO;
552}
553
554#############################################################################
555# Over-the-air updates
556
557sub 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
657sub 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
714sub 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 });
517} 735}
518 736
519############################################################################# 737#############################################################################
520 738
521sub destroy_query_dialog { 739sub destroy_query_dialog {
748 $vbox->add (@dialog); 966 $vbox->add (@dialog);
749 $dialog->show; 967 $dialog->show;
750} 968}
751 969
752sub dc_connect { 970sub dc_connect {
753 my ($host, $port) = @_; 971 my ($host, $port, $create) = @_;
754 972
755 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;
756 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;
757 975
758 $CONN = 976 $CONN =
759 new DC::Protocol 977 new DC::Protocol
760 host => $host, 978 host => $host,
761 port => $port, 979 port => $port,
980 create_login => $create,
762 user => $PROFILE->{user}, 981 user => $PROFILE->{user},
763 pass => $PROFILE->{password}, 982 pass => (pack "H*", $PROFILE->{password}),
764 mapw => $mapw, 983 mapw => $mapw,
765 maph => $maph, 984 maph => $maph,
766 985
767 c_version => { 986 c_version => {
768 client => "deliantra", 987 client => "deliantra",
769 clientver => $DC::VERSION, 988 clientver => "$DC::VERSION$Urlader::EXE_VER",
770 gl_vendor => DC::OpenGL::gl_vendor, 989 gl_vendor => DC::OpenGL::gl_vendor,
771 gl_version => DC::OpenGL::gl_version, 990 gl_version => DC::OpenGL::gl_version,
772 }, 991 },
773 992
774 map_widget => $MAPWIDGET, 993 map_widget => $MAPWIDGET,
783 1002
784 on_connect => sub { 1003 on_connect => sub {
785 if ($_[0]) { 1004 if ($_[0]) {
786 DC::lowdelay fileno $CONN->{fh}; 1005 DC::lowdelay fileno $CONN->{fh};
787 1006
1007 ota_update_check;
1008
788 status "successfully connected to the server"; 1009 status "successfully connected to the server";
789 } else { 1010 } else {
790 undef $CONN; 1011 undef $CONN;
791 status "unable to connect: $!"; 1012 $LOGIN_ERROR->{fg} = [1, 0, 0];
1013 $LOGIN_ERROR->set_text ("Unable to connect to server: $!");
792 stop_game(); 1014 stop_game();
793 } 1015 }
794 }, 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 },
795 ; 1024 ;
796} 1025}
797 1026
798sub start_game { 1027sub start_game($) {
1028 my ($create) = @_;
1029
799 status "logging in..."; 1030 status "logging in...";
800 1031
801 my $server = $PROFILE->{host} || $DEFAULT_SERVER; 1032 my $server = $PROFILE->{host} || $DEFAULT_SERVER;
802 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" 1033 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327"
803 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.";
818 status "dns failure, using hardcoded address"; 1049 status "dns failure, using hardcoded address";
819 $host = "194.126.175.154"; 1050 $host = "194.126.175.154";
820 } 1051 }
821 } 1052 }
822 1053
823 dc_connect $host, $port; 1054 dc_connect $host, $port, $create;
824 }; 1055 };
825 } else { 1056 } else {
826 dc_connect $host, $port; 1057 dc_connect $host, $port, $create;
827 } 1058 }
828} 1059}
829 1060
830sub stop_game { 1061sub stop_game {
831 crash "stop_game"; 1062 crash "stop_game";
949 $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");
950 $table->add_at (1, $row++, new DC::UI::CheckBox 1181 $table->add_at (1, $row++, new DC::UI::CheckBox
951 state => $CFG->{texture_compression}, 1182 state => $CFG->{texture_compression},
952 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 "
953 . "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). "
954 . "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 "
955 . "forced OpenGL 1.1 mode and when using the Apple renderer.", 1186 . "forced OpenGL 1.1 mode and when using the Apple renderer.",
956 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } 1187 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
957 ); 1188 );
958 1189
959 $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");
1131 text => $CFG->{audio_driver}, 1362 text => $CFG->{audio_driver},
1132 template => "dsound1234", 1363 template => "dsound1234",
1133 tooltip => "You can override the audio driver to use here. Leaving it empty will result " 1364 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 " 1365 . "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> " 1366 . "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" 1367 . "or other system-specific drivers. Selecting the wrong driver here will simply result "
1137 . "in no sound.", 1368 . "in no sound.",
1138 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 } 1369 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 }
1139 ); 1370 );
1140 1371
1141 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects"); 1372 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects");
1311 $DELIANTRA_DEBUG ^= $_[0]; 1542 $DELIANTRA_DEBUG ^= $_[0];
1312 1543
1313 if ($DELIANTRA_DEBUG & 16) { 1544 if ($DELIANTRA_DEBUG & 16) {
1314 $BW_WATCHER = EV::periodic 0, 1, 0, sub { 1545 $BW_WATCHER = EV::periodic 0, 1, 0, sub {
1315 return unless $CONN; 1546 return unless $CONN;
1316 debug sprintf "%8.2gKB/s", $CONN->{octets_in} / 1e3; 1547 debug sprintf "%8.2gkB/s", $CONN->{octets_in} / 1e3;
1317 $CONN->{octets_in} = 0; 1548 $CONN->{octets_in} = 0;
1318 }; 1549 };
1319 } else { 1550 } else {
1320 undef $BW_WATCHER; 1551 undef $BW_WATCHER;
1321 } 1552 }
1664 $vbox->add (new DC::UI::FancyFrame 1895 $vbox->add (new DC::UI::FancyFrame
1665 label => "Login Settings", 1896 label => "Login Settings",
1666 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]),
1667 ); 1898 );
1668 1899
1900 my $nullpw = "\x00" x 16;
1901
1669 $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");
1670 $table->add_at (1, 4, new DC::UI::Entry 1903 $table->add_at (1, 0, new DC::UI::Entry
1671 text => $PROFILE->{user}, 1904 text => $PROFILE->{user},
1672 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!",
1673 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } 1906 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 }
1674 ); 1907 );
1675 1908
1676 $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");
1677 $table->add_at (1, 5, new DC::UI::Entry 1910 $table->add_at (1, 1, my $pw1 = new DC::UI::Entry
1678 text => $PROFILE->{password}, 1911 text => $PROFILE->{password} ? $nullpw : "",
1679 hidden => 1, 1912 hidden => 1,
1680 tooltip => "The password for your character.", 1913 tooltip => "The password for your character.",
1681 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 },
1682 ); 1926 );
1683 1927
1684 $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button 1928 $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button
1685 expand => 1, 1929 expand => 1,
1686 text => "Login / Register", 1930 text => "Login to Existing Account",
1687 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.",
1688 on_activate => sub { 1932 on_activate => sub {
1689 $CONN ? stop_game 1933 $CONN ? stop_game
1690 : start_game; 1934 : start_game 0;
1691 1 1935 1
1692 }, 1936 },
1693 ); 1937 );
1694 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
1695 $vbox->add (new DC::UI::FancyFrame 1966 $vbox->add (new DC::UI::FancyFrame
1696 label => "How to Play", 1967 label => "How to Play",
1697 min_h => 240, 1968 min_h => 240,#d# should not be necessary - widget bug
1698 child => (new DC::UI::Label valign => 0, ellipsise => 0, 1969 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1699 markup => 1970 markup =>
1700 "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"
1701 . "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"
1702 . "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 "
1703 . "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>.",
1704 ), 1975 ),
1705 ); 1976 );
1706 1977
1707 $vbox 1978 $vbox
1708} 1979}
1759 $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");
1760 $table->add_at (1, $row, new DC::UI::Entry 2031 $table->add_at (1, $row, new DC::UI::Entry
1761 text => $CFG->{output_rate}, 2032 text => $CFG->{output_rate},
1762 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 "
1763 . "when sending data. When 0 or unset, the server " 2034 . "when sending data. When 0 or unset, the server "
1764 . "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 "
1765 . "dynamically find an optimal rate, so adjust this only when necessary.", 2036 . "dynamically find an optimal rate, so adjust this only when necessary.",
1766 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 }, 2037 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1767 ); 2038 );
1768 2039
1769 $vbox->add (new DC::UI::FancyFrame 2040 $vbox->add (new DC::UI::FancyFrame
1826 $table->add_at (2, $row++, new DC::UI::Button 2097 $table->add_at (2, $row++, new DC::UI::Button
1827 text => "Save Now", 2098 text => "Save Now",
1828 tooltip => "Use this to manually save configuration and UI layout when " 2099 tooltip => "Use this to manually save configuration and UI layout when "
1829 . "autosave is disabled.", 2100 . "autosave is disabled.",
1830 on_activate => sub { 2101 on_activate => sub {
1831 DC::write_cfg; 2102 DC::save_cfg;
1832 0 2103 0
1833 } 2104 }
1834 ); 2105 );
1835 } 2106 }
1836 2107
1841 2112
1842 $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");
1843 $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 => "");
1844 $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");
1845 $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 => "");
1846 $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)");
1847 $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 => "");
1848 $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)");
1849 $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 => "");
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 } 2123 }
1853 2124
1854 $vbox 2125 $vbox
1855} 2126}
1856 2127
2030 2301
2031sub media_window { 2302sub media_window {
2032 my $vb = new DC::UI::VBox; 2303 my $vb = new DC::UI::VBox;
2033 2304
2034 $vb->add (new DC::UI::FancyFrame 2305 $vb->add (new DC::UI::FancyFrame
2035 label => "Currently playing music", 2306 label => "Current background music",
2036 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2307 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), 2308 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2038 ); 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 });
2039 2345
2040 $vb->add (new DC::UI::FancyFrame 2346 $vb->add (new DC::UI::FancyFrame
2041 label => "Other media used in this session", 2347 label => "Other media used in this session",
2042 expand => 1, 2348 expand => 1,
2043 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2349 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2044 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2350 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2045 ); 2351 );
2046 2352
2047 $vb 2353 $vb
2048} 2354}
2049 2355
2234sub open_quit_dialog { 2540sub open_quit_dialog {
2235 unless ($QUIT_DIALOG) { 2541 unless ($QUIT_DIALOG) {
2236 $QUIT_DIALOG = new DC::UI::Toplevel 2542 $QUIT_DIALOG = new DC::UI::Toplevel
2237 x => "center", 2543 x => "center",
2238 y => "center", 2544 y => "center",
2239 z => 50, 2545 z => 60,
2240 title => "Really Quit?", 2546 title => "Really Quit?",
2241 on_key_down => sub { 2547 on_key_down => sub {
2242 my ($dialog, $ev) = @_; 2548 my ($dialog, $ev) = @_;
2243 $ev->{sym} == 27 and $dialog->hide; 2549 $ev->{sym} == 27 and $dialog->hide;
2244 } 2550 }
2291 make_playerbook; 2597 make_playerbook;
2292 2598
2293 $MENUPOPUP = DC::UI::Menu->new (items => [ 2599 $MENUPOPUP = DC::UI::Menu->new (items => [
2294 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }], 2600 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }],
2295 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }], 2601 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }],
2296 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }], 2602 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }],
2297 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }], 2603 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }],
2298 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }], 2604 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }],
2299 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }], 2605 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }],
2300 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }], 2606 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }],
2301 ["Quit…" , sub { 2607 ["Quit…" , sub {
2302 if ($CONN) { 2608 if ($CONN) {
2303 open_quit_dialog; 2609 open_quit_dialog;
2304 } else { 2610 } else {
2305 EV::unloop EV::UNLOOP_ALL; 2611 EV::break EV::BREAK_ALL;
2306 } 2612 }
2307 }], 2613 }],
2308 ]); 2614 ]);
2309 2615
2310 $BUTTONBAR->add (new DC::UI::Button text => "Menu…", 2616 $BUTTONBAR->add (new DC::UI::Button text => "Menu…",
2437 DC::set_theme $CFG->{uitheme}; 2743 DC::set_theme $CFG->{uitheme};
2438 2744
2439 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2745 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2440 $SDL_REINIT = 0; 2746 $SDL_REINIT = 0;
2441 2747
2442 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2748 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2443 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2749 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2444 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2750 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2445 @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)";
2446 2752
2447 @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;
2460 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2766 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2461 2767
2462 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2768 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2463 $FULLSCREEN = $CFG->{fullscreen}; 2769 $FULLSCREEN = $CFG->{fullscreen};
2464 $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
2465 2773
2466 # 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
2467 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2775 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2468 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2776 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2469 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2777 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2679 delete $animate_object{$widget}; 2987 delete $animate_object{$widget};
2680} 2988}
2681 2989
2682$SDL_CB[DC::SDL_QUIT] = sub { 2990$SDL_CB[DC::SDL_QUIT] = sub {
2683 crash "SDL_QUIT"; 2991 crash "SDL_QUIT";
2684 EV::unloop EV::UNLOOP_ALL; 2992 EV::break EV::BREAK_ALL;
2685}; 2993};
2686$SDL_CB[DC::SDL_VIDEORESIZE] = sub { }; 2994$SDL_CB[DC::SDL_VIDEORESIZE] = sub { };
2687$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub { 2995$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub {
2688 DC::UI::full_refresh; 2996 DC::UI::full_refresh;
2689}; 2997};
2722}; 3030};
2723 3031
2724############################################################################# 3032#############################################################################
2725 3033
2726$SIG{INT} = $SIG{TERM} = sub { 3034$SIG{INT} = $SIG{TERM} = sub {
2727 EV::unloop; 3035 EV::break;
2728 #d# TODO calling exit here hangs the process in some futex 3036 #d# TODO calling exit here hangs the process in some futex
2729}; 3037};
2730 3038
2731# 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
2732sub DC::Main::main { 3040sub DC::Main::run {
2733 { 3041 DC::SDL_main_hack {
3042 {
2734 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 3043 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2735 3044
2736 if (-e "$Deliantra::VARDIR/client.cf") { 3045 DC::load_cfg;
2737 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 3046 DC::upgrade_cfg;
2738 } else {
2739 #TODO: compatibility cruft
2740 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2741 print STDERR "INFO: used old configuration file\n";
2742 }
2743 3047
3048 DC::Audio::probe;
3049
2744 DC::DB::Server::run; 3050 DC::DB::Server::run;
2745 3051
2746 if ($CFG->{db_schema} < 1) { 3052 if ($CFG->{db_schema} < 1) {
2747 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";
2748 DC::DB::nuke_db; 3054 DC::DB::nuke_db;
2749 $CFG->{db_schema} = 1; 3055 $CFG->{db_schema} = 1;
2750 DC::write_cfg; 3056 DC::save_cfg;
2751 }
2752
2753 DC::DB::open_db;
2754
2755 DC::UI::set_layout ($::CFG->{layout});
2756
2757 my %DEF_CFG = (
2758 config_autosave => 1,
2759 sdl_mode => undef,
2760 fullscreen => 1,
2761 fast => 0,
2762 force_opengl11 => undef,
2763 disable_alpha => 0,
2764 smooth_movement => 1,
2765 smooth_transitions => 1,
2766 texture_compression => 1,
2767 map_scale => 1,
2768 fow_enable => 1,
2769 fow_intensity => 0,
2770 fow_texture => 0,
2771 map_smoothing => 1,
2772 gui_fontsize => 1,
2773 log_fontsize => 0.7,
2774 gauge_fontsize => 1,
2775 gauge_size => 0.35,
2776 stat_fontsize => 0.7,
2777 mapsize => 100,
2778 audio_enable => 1,
2779 audio_hw_channels => 0,
2780 audio_hw_frequency => 0,
2781 audio_hw_chunksize => 0,
2782 audio_mix_channels => 8,
2783 effects_enable => 1,
2784 effects_volume => 1,
2785 bgm_enable => 1,
2786 bgm_volume => 0.5,
2787 output_rate => "",
2788 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
2789 inv_sort => "mtime",
2790 default => "profile", # default profile
2791 show_tips => 1,
2792 logview_max_par => 1000,
2793 shift_fire_stop => 0,
2794 uitheme => "wood",
2795 map_shift_x => -24, # arbitrary
2796 map_shift_y => +24, # arbitrary
2797 );
2798
2799 while (my ($k, $v) = each %DEF_CFG) {
2800 $CFG->{$k} = $v unless exists $CFG->{$k};
2801 }
2802
2803 my @args = @ARGV;
2804
2805 # OS X passes some process serial number of other shit. they
2806 # could have used an env var or any other sane mechanism. but
2807 # would it be os x then? no...
2808 shift @args if $args[0] =~ /^-psn_/;
2809
2810 my $profile = 'default';
2811
2812 for (my $i = 0; $i < @args; $i++) {
2813 if ($args[$i] =~ /^--?profile$/) {
2814 $profile = $args[$i + 1];
2815 splice @args, $i, 2, ();
2816 $i = 0;
2817 } elsif ($args[$i] =~ /^--?h/) {
2818 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2819 exit 0;
2820 } 3057 }
2821 }
2822 3058
2823 $CFG->{profile}{$profile} ||= {}; 3059 DC::DB::open_db;
2824 $PROFILE = $CFG->{profile}{$profile};
2825 $PROFILE->{host} ||= "gameserver.deliantra.net";
2826 3060
2827 $PROFILE->{host} = $args[0] if @args > 0; 3061 DC::UI::set_layout ($::CFG->{layout});
2828 $PROFILE->{user} = $args[1] if @args > 1;
2829 $PROFILE->{password} = $args[2] if @args > 2;
2830 3062
2831 # convert old bindings (only default profile matters) 3063 my @args = @ARGV;
2832 if (my $bindings = delete $PROFILE->{bindings}) { 3064
2833 while (my ($mod, $syms) = each %$bindings) { 3065 # OS X passes some process serial number of other shit. they
2834 while (my ($sym, $cmds) = each %$syms) { 3066 # could have used an env var or any other sane mechanism. but
2835 push @{ $PROFILE->{macro} }, { 3067 # would it be os x then? no...
2836 accelkey => [$mod*1, $sym*1], 3068 shift @args if $args[0] =~ /^-psn_/;
2837 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, ();
2838 }; 3076 $i = 0;
3077 } elsif ($args[$i] =~ /^--?h/) {
3078 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3079 exit 0;
2839 } 3080 }
2840 } 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 }
2841 } 3101 }
2842 3102
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
2843 $ENV{FONTCONFIG_FILE} = DC::find_rcfile "fonts/fonts.conf"; 3105 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2844 $ENV{FONTCONFIG_DIR} = DC::find_rcfile "fonts"; 3106 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3107 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2845 3108
2846 { 3109 {
2847 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3110 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2848 DejaVuSans.ttf 3111 DejaVuSans.ttf
2849 DejaVuSansMono.ttf 3112 DejaVuSansMono.ttf
2850 DejaVuSans-Bold.ttf 3113 DejaVuSans-Bold.ttf
2851 DejaVuSansMono-Bold.ttf 3114 DejaVuSansMono-Bold.ttf
2852 DejaVuSans-Oblique.ttf 3115 DejaVuSans-Oblique.ttf
2853 DejaVuSansMono-Oblique.ttf 3116 DejaVuSansMono-Oblique.ttf
2854 DejaVuSans-BoldOblique.ttf 3117 DejaVuSans-BoldOblique.ttf
2855 DejaVuSansMono-BoldOblique.ttf 3118 DejaVuSansMono-BoldOblique.ttf
2856 mona.ttf 3119 mona.ttf
2857 ); 3120 );
2858 3121
2859 DC::add_font $_ for @fonts; 3122 DC::add_font $_ for @fonts;
2860 3123
2861 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3124 $FONT_PROP = new_from_file DC::Font $fonts[0];
2862 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3125 $FONT_FIXED = new_from_file DC::Font $fonts[1];
2863 3126
2864 $FONT_PROP->make_default; 3127 $FONT_PROP->make_default;
2865 3128
2866 DC::pango_init; 3129 DC::pango_init;
2867 } 3130 }
2868 3131
2869# compare mono (ft) vs. rgba (cairo) 3132# compare mono (ft) vs. rgba (cairo)
2870# ft - 1.8s, cairo 3s, even in alpha-only mode 3133# ft - 1.8s, cairo 3s, even in alpha-only mode
2871# for my $rgba (0..1) { 3134# for my $rgba (0..1) {
2872# my $t1 = Time::HiRes::time; 3135# my $t1 = Time::HiRes::time;
2877# } 3140# }
2878# my $t2 = Time::HiRes::time; 3141# my $t2 = Time::HiRes::time;
2879# warn $t2-$t1; 3142# warn $t2-$t1;
2880# } 3143# }
2881 3144
3145 }
3146
3147 DC::SDL_Init 0;
2882 DC::IMG_Init; video_init; 3148 DC::IMG_Init; video_init;
2883 DC::Mix_Init; audio_init; 3149 DC::Mix_Init; audio_init;
2884 }
2885 3150
2886 show_tip_of_the_day if $CFG->{show_tips}; 3151 show_tip_of_the_day if $CFG->{show_tips};
2887 3152
2888 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3153 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
2889 undef $STARTUP_CANCEL; 3154 undef $STARTUP_CANCEL;
2890 (pop @::STARTUP_DONE)->() 3155 (pop @::STARTUP_DONE)->()
2891 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;
2892 }; 3172 };
2893
2894 debug_toggle 0;
2895
2896 delete $SIG{__DIE__};
2897 EV::loop;
2898
2899 DC::write_cfg if $CFG->{config_autosave};
2900
2901 #video_shutdown;
2902 #audio_shutdown;
2903
2904 DC::OpenGL::quit;
2905 DC::SDL_Quit;
2906 DC::DB::Server::stop;
2907} 3173}
2908
2909*DC::Main::run = \&DC::SDL_braino; # see sub above
2910 3174
29111 31751

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines