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.17 by root, Wed Jan 18 13:42:19 2012 UTC vs.
Revision 1.30 by root, Sun Jan 29 00:11:23 2017 UTC

25BEGIN { *time = \&EV::time } 25BEGIN { *time = \&EV::time }
26 26
27use List::Util qw(max min); 27use List::Util qw(max min);
28 28
29use Deliantra; 29use Deliantra;
30use Deliantra::Util;
30use Deliantra::Protocol::Constants; 31use Deliantra::Protocol::Constants;
31 32
32use AnyEvent::Util (); 33use AnyEvent::Util ();
33use AnyEvent::Socket (); 34use AnyEvent::Socket ();
34use AnyEvent::DNS (); 35use AnyEvent::DNS ();
35 36
36use Compress::LZF; 37use Compress::LZF;
37use JSON::XS; 38use JSON::XS;
39use Urlader;
38 40
39use DC; 41use DC;
40 42
41sub crash($;$) { 43sub crash($;$) {
42 # nop at compiletime 44 # nop at compiletime
44 46
45BEGIN { 47BEGIN {
46 $SIG{__DIE__} = sub { 48 $SIG{__DIE__} = sub {
47 return if $^S; # quick reject 49 return if $^S; # quick reject
48 50
49 # return if there are any eval contexts in the csall stack 51 # return if there are any eval contexts in the call stack
50 for my $i (0..999) { 52 for my $i (0..999) {
51 my ($sub, $is_require) = (caller $i)[3, 7] 53 my ($sub, $is_require) = (caller $i)[3, 7]
52 or last; 54 or last;
53 return if $sub eq "(eval)" && !$is_require; 55 return if $sub eq "(eval)" && !$is_require;
54 } 56 }
127our $MENUBAR; # the hbox at the top 129our $MENUBAR; # the hbox at the top
128our $MENUPOPUP; 130our $MENUPOPUP;
129our $BUTTONBAR; # the menu buttons 131our $BUTTONBAR; # the menu buttons
130our $METASERVER; 132our $METASERVER;
131our $LOGIN_BUTTON; 133our $LOGIN_BUTTON;
134our $LOGIN_ERROR;
132our $QUIT_DIALOG; 135our $QUIT_DIALOG;
133our $HOST_ENTRY; 136our $HOST_ENTRY;
134our $FULLSCREEN_ENABLE; 137our $FULLSCREEN_ENABLE;
135our $PICKUP_ENABLE; 138our $PICKUP_ENABLE;
136our $SERVER_INFO; 139our $SERVER_INFO;
250 : "[<span foreground='#888'>num</span>]"; 253 : "[<span foreground='#888'>num</span>]";
251 254
252 # <tt> around next statement works around some bug that keeps the 255 # <tt> around next statement works around some bug that keeps the
253 # "font =>" from being used on windows 256 # "font =>" from being used on windows
254 $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;
255} 292}
256 293
257############################################################################# 294#############################################################################
258#TODO: maybe move into own audio module... 295#TODO: maybe move into own audio module...
259 296
474 audio_music_push; 511 audio_music_push;
475} 512}
476 513
477sub audio_init { 514sub audio_init {
478 if ($CFG->{audio_enable}) { 515 if ($CFG->{audio_enable}) {
479 DC::Audio::init $CFG->{audio_driver}; 516 DC::Audio::init;
480 517
481 if ($SDL_MIXER) { 518 if ($SDL_MIXER) {
482 audio_music_finished; 519 audio_music_finished;
483 } else { 520 } else {
484 status "Unable to open sound device: there will be no sound"; 521 status "Unable to open sound device: there will be no sound";
688 ::message { markup => "Server has no newer version." }; 725 ::message { markup => "Server has no newer version." };
689 } 726 }
690 } else { 727 } else {
691 ::message { markup => "Server does not support software update." }; 728 ::message { markup => "Server does not support software update." };
692 } 729 }
693
694# $self->register_face_handler ($exp_table, sub {
695# my ($face) = @_;
696
697# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
698# $_->() for values %{ $self->{on_exp_update} || {} };
699# });
700 730
701 () 731 ()
702 }); 732 });
703} 733}
704 734
934 $vbox->add (@dialog); 964 $vbox->add (@dialog);
935 $dialog->show; 965 $dialog->show;
936} 966}
937 967
938sub dc_connect { 968sub dc_connect {
939 my ($host, $port) = @_; 969 my ($host, $port, $create) = @_;
940 970
941 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;
942 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;
943 973
944 $CONN = 974 $CONN =
945 new DC::Protocol 975 new DC::Protocol
946 host => $host, 976 host => $host,
947 port => $port, 977 port => $port,
978 create_login => $create,
948 user => $PROFILE->{user}, 979 user => $PROFILE->{user},
949 pass => $PROFILE->{password}, 980 pass => (pack "H*", $PROFILE->{password}),
950 mapw => $mapw, 981 mapw => $mapw,
951 maph => $maph, 982 maph => $maph,
952 983
953 c_version => { 984 c_version => {
954 client => "deliantra", 985 client => "deliantra",
974 ota_update_check; 1005 ota_update_check;
975 1006
976 status "successfully connected to the server"; 1007 status "successfully connected to the server";
977 } else { 1008 } else {
978 undef $CONN; 1009 undef $CONN;
979 status "unable to connect: $!"; 1010 $LOGIN_ERROR->{fg} = [1, 0, 0];
1011 $LOGIN_ERROR->set_text ("Unable to connect to server: $!");
980 stop_game(); 1012 stop_game();
981 } 1013 }
982 }, 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 },
983 ; 1022 ;
984} 1023}
985 1024
986sub start_game { 1025sub start_game($) {
1026 my ($create) = @_;
1027
987 status "logging in..."; 1028 status "logging in...";
988 1029
989 my $server = $PROFILE->{host} || $DEFAULT_SERVER; 1030 my $server = $PROFILE->{host} || $DEFAULT_SERVER;
990 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" 1031 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327"
991 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.";
1006 status "dns failure, using hardcoded address"; 1047 status "dns failure, using hardcoded address";
1007 $host = "194.126.175.154"; 1048 $host = "194.126.175.154";
1008 } 1049 }
1009 } 1050 }
1010 1051
1011 dc_connect $host, $port; 1052 dc_connect $host, $port, $create;
1012 }; 1053 };
1013 } else { 1054 } else {
1014 dc_connect $host, $port; 1055 dc_connect $host, $port, $create;
1015 } 1056 }
1016} 1057}
1017 1058
1018sub stop_game { 1059sub stop_game {
1019 crash "stop_game"; 1060 crash "stop_game";
1137 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); 1178 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures");
1138 $table->add_at (1, $row++, new DC::UI::CheckBox 1179 $table->add_at (1, $row++, new DC::UI::CheckBox
1139 state => $CFG->{texture_compression}, 1180 state => $CFG->{texture_compression},
1140 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " 1181 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
1141 . "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). " 1182 . "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). "
1142 . "The compression algorithm can differ form card to card, so your mileage may vary. This setting is ignored in " 1183 . "The compression algorithm can differ from card to card, so your mileage may vary. This setting is ignored in "
1143 . "forced OpenGL 1.1 mode and when using the Apple renderer.", 1184 . "forced OpenGL 1.1 mode and when using the Apple renderer.",
1144 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } 1185 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
1145 ); 1186 );
1146 1187
1147 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly"); 1188 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly");
1499 $DELIANTRA_DEBUG ^= $_[0]; 1540 $DELIANTRA_DEBUG ^= $_[0];
1500 1541
1501 if ($DELIANTRA_DEBUG & 16) { 1542 if ($DELIANTRA_DEBUG & 16) {
1502 $BW_WATCHER = EV::periodic 0, 1, 0, sub { 1543 $BW_WATCHER = EV::periodic 0, 1, 0, sub {
1503 return unless $CONN; 1544 return unless $CONN;
1504 debug sprintf "%8.2gKB/s", $CONN->{octets_in} / 1e3; 1545 debug sprintf "%8.2gkB/s", $CONN->{octets_in} / 1e3;
1505 $CONN->{octets_in} = 0; 1546 $CONN->{octets_in} = 0;
1506 }; 1547 };
1507 } else { 1548 } else {
1508 undef $BW_WATCHER; 1549 undef $BW_WATCHER;
1509 } 1550 }
1852 $vbox->add (new DC::UI::FancyFrame 1893 $vbox->add (new DC::UI::FancyFrame
1853 label => "Login Settings", 1894 label => "Login Settings",
1854 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]),
1855 ); 1896 );
1856 1897
1898 my $nullpw = "\x00" x 16;
1899
1857 $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");
1858 $table->add_at (1, 4, new DC::UI::Entry 1901 $table->add_at (1, 0, new DC::UI::Entry
1859 text => $PROFILE->{user}, 1902 text => $PROFILE->{user},
1860 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!",
1861 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } 1904 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 }
1862 ); 1905 );
1863 1906
1864 $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");
1865 $table->add_at (1, 5, new DC::UI::Entry 1908 $table->add_at (1, 1, my $pw1 = new DC::UI::Entry
1866 text => $PROFILE->{password}, 1909 text => $PROFILE->{password} ? $nullpw : "",
1867 hidden => 1, 1910 hidden => 1,
1868 tooltip => "The password for your character.", 1911 tooltip => "The password for your character.",
1869 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 },
1870 ); 1924 );
1871 1925
1872 $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button 1926 $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button
1873 expand => 1, 1927 expand => 1,
1874 text => "Login / Register", 1928 text => "Login to Existing Account",
1875 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.",
1876 on_activate => sub { 1930 on_activate => sub {
1877 $CONN ? stop_game 1931 $CONN ? stop_game
1878 : start_game; 1932 : start_game 0;
1879 1 1933 1
1880 }, 1934 },
1881 ); 1935 );
1882 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, from the server.",
1961 child => ($LOGIN_ERROR = new DC::UI::Label valign => 0, ellipsise => 0),
1962 );
1963
1883 $vbox->add (new DC::UI::FancyFrame 1964 $vbox->add (new DC::UI::FancyFrame
1884 label => "How to Play", 1965 label => "How to Play",
1885 min_h => 240, 1966 min_h => 240,#d# should not be necessary - widget bug
1886 child => (new DC::UI::Label valign => 0, ellipsise => 0, 1967 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1887 markup => 1968 markup =>
1888 "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"
1889 . "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"
1890 . "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 "
1891 . "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>.",
1892 ), 1973 ),
1893 ); 1974 );
1894 1975
1895 $vbox 1976 $vbox
1896} 1977}
1947 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Output-Rate"); 2028 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Output-Rate");
1948 $table->add_at (1, $row, new DC::UI::Entry 2029 $table->add_at (1, $row, new DC::UI::Entry
1949 text => $CFG->{output_rate}, 2030 text => $CFG->{output_rate},
1950 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed " 2031 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
1951 . "when sending data. When 0 or unset, the server " 2032 . "when sending data. When 0 or unset, the server "
1952 . "default will be used, which is usually around 100kb/s. Most servers will " 2033 . "default will be used, which is usually around 100kB/s. Most servers will "
1953 . "dynamically find an optimal rate, so adjust this only when necessary.", 2034 . "dynamically find an optimal rate, so adjust this only when necessary.",
1954 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 }, 2035 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1955 ); 2036 );
1956 2037
1957 $vbox->add (new DC::UI::FancyFrame 2038 $vbox->add (new DC::UI::FancyFrame
2514 make_playerbook; 2595 make_playerbook;
2515 2596
2516 $MENUPOPUP = DC::UI::Menu->new (items => [ 2597 $MENUPOPUP = DC::UI::Menu->new (items => [
2517 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }], 2598 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }],
2518 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }], 2599 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }],
2519 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }], 2600 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }],
2520 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }], 2601 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }],
2521 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }], 2602 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }],
2522 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }], 2603 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }],
2523 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }], 2604 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }],
2524 ["Quit…" , sub { 2605 ["Quit…" , sub {
2525 if ($CONN) { 2606 if ($CONN) {
2526 open_quit_dialog; 2607 open_quit_dialog;
2527 } else { 2608 } else {
2528 EV::unloop EV::UNLOOP_ALL; 2609 EV::break EV::BREAK_ALL;
2529 } 2610 }
2530 }], 2611 }],
2531 ]); 2612 ]);
2532 2613
2533 $BUTTONBAR->add (new DC::UI::Button text => "Menu…", 2614 $BUTTONBAR->add (new DC::UI::Button text => "Menu…",
2660 DC::set_theme $CFG->{uitheme}; 2741 DC::set_theme $CFG->{uitheme};
2661 2742
2662 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2743 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2663 $SDL_REINIT = 0; 2744 $SDL_REINIT = 0;
2664 2745
2665 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2746 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2666 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2747 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2667 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2748 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2668 @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)";
2669 2750
2670 @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;
2904 delete $animate_object{$widget}; 2985 delete $animate_object{$widget};
2905} 2986}
2906 2987
2907$SDL_CB[DC::SDL_QUIT] = sub { 2988$SDL_CB[DC::SDL_QUIT] = sub {
2908 crash "SDL_QUIT"; 2989 crash "SDL_QUIT";
2909 EV::unloop EV::UNLOOP_ALL; 2990 EV::break EV::BREAK_ALL;
2910}; 2991};
2911$SDL_CB[DC::SDL_VIDEORESIZE] = sub { }; 2992$SDL_CB[DC::SDL_VIDEORESIZE] = sub { };
2912$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub { 2993$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub {
2913 DC::UI::full_refresh; 2994 DC::UI::full_refresh;
2914}; 2995};
2947}; 3028};
2948 3029
2949############################################################################# 3030#############################################################################
2950 3031
2951$SIG{INT} = $SIG{TERM} = sub { 3032$SIG{INT} = $SIG{TERM} = sub {
2952 EV::unloop; 3033 EV::break;
2953 #d# TODO calling exit here hangs the process in some futex 3034 #d# TODO calling exit here hangs the process in some futex
2954}; 3035};
2955 3036
2956# 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
2957sub DC::Main::main { 3038sub DC::Main::run {
2958 { 3039 DC::SDL_main_hack {
3040 {
2959 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 3041 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2960 3042
2961 DC::load_cfg; 3043 DC::load_cfg;
3044 DC::upgrade_cfg;
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::save_cfg; 3054 DC::save_cfg;
2970 }
2971
2972 DC::upgrade_cfg;
2973
2974 DC::DB::open_db;
2975
2976 DC::UI::set_layout ($::CFG->{layout});
2977
2978 my @args = @ARGV;
2979
2980 # OS X passes some process serial number of other shit. they
2981 # could have used an env var or any other sane mechanism. but
2982 # would it be os x then? no...
2983 shift @args if $args[0] =~ /^-psn_/;
2984
2985 my $profile = 'default';
2986
2987 for (my $i = 0; $i < @args; $i++) {
2988 if ($args[$i] =~ /^--?profile$/) {
2989 $profile = $args[$i + 1];
2990 splice @args, $i, 2, ();
2991 $i = 0;
2992 } elsif ($args[$i] =~ /^--?h/) {
2993 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2994 exit 0;
2995 } 3055 }
2996 }
2997 3056
2998 $CFG->{profile}{$profile} ||= {}; 3057 DC::DB::open_db;
2999 $PROFILE = $CFG->{profile}{$profile};
3000 $PROFILE->{host} ||= "gameserver.deliantra.net";
3001 3058
3002 $PROFILE->{host} = $args[0] if @args > 0; 3059 DC::UI::set_layout ($::CFG->{layout});
3003 $PROFILE->{user} = $args[1] if @args > 1;
3004 $PROFILE->{password} = $args[2] if @args > 2;
3005 3060
3006 # convert old bindings (only default profile matters) 3061 my @args = @ARGV;
3007 if (my $bindings = delete $PROFILE->{bindings}) { 3062
3008 while (my ($mod, $syms) = each %$bindings) { 3063 # OS X passes some process serial number of other shit. they
3009 while (my ($sym, $cmds) = each %$syms) { 3064 # could have used an env var or any other sane mechanism. but
3010 push @{ $PROFILE->{macro} }, { 3065 # would it be os x then? no...
3011 accelkey => [$mod*1, $sym*1], 3066 shift @args if $args[0] =~ /^-psn_/;
3012 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, ();
3013 }; 3074 $i = 0;
3075 } elsif ($args[$i] =~ /^--?h/) {
3076 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3077 exit 0;
3014 } 3078 }
3015 } 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 }
3016 } 3099 }
3017 3100
3018 # 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
3019 # 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
3020 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3103 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3021 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3104 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3022 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3105 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3023 3106
3024 { 3107 {
3025 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3108 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3026 DejaVuSans.ttf 3109 DejaVuSans.ttf
3027 DejaVuSansMono.ttf 3110 DejaVuSansMono.ttf
3028 DejaVuSans-Bold.ttf 3111 DejaVuSans-Bold.ttf
3029 DejaVuSansMono-Bold.ttf 3112 DejaVuSansMono-Bold.ttf
3030 DejaVuSans-Oblique.ttf 3113 DejaVuSans-Oblique.ttf
3031 DejaVuSansMono-Oblique.ttf 3114 DejaVuSansMono-Oblique.ttf
3032 DejaVuSans-BoldOblique.ttf 3115 DejaVuSans-BoldOblique.ttf
3033 DejaVuSansMono-BoldOblique.ttf 3116 DejaVuSansMono-BoldOblique.ttf
3034 mona.ttf 3117 mona.ttf
3035 ); 3118 );
3036 3119
3037 DC::add_font $_ for @fonts; 3120 DC::add_font $_ for @fonts;
3038 3121
3039 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3122 $FONT_PROP = new_from_file DC::Font $fonts[0];
3040 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3123 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3041 3124
3042 $FONT_PROP->make_default; 3125 $FONT_PROP->make_default;
3043 3126
3044 DC::pango_init; 3127 DC::pango_init;
3045 } 3128 }
3046 3129
3047# compare mono (ft) vs. rgba (cairo) 3130# compare mono (ft) vs. rgba (cairo)
3048# ft - 1.8s, cairo 3s, even in alpha-only mode 3131# ft - 1.8s, cairo 3s, even in alpha-only mode
3049# for my $rgba (0..1) { 3132# for my $rgba (0..1) {
3050# my $t1 = Time::HiRes::time; 3133# my $t1 = Time::HiRes::time;
3055# } 3138# }
3056# my $t2 = Time::HiRes::time; 3139# my $t2 = Time::HiRes::time;
3057# warn $t2-$t1; 3140# warn $t2-$t1;
3058# } 3141# }
3059 3142
3143 }
3144
3145 DC::SDL_Init 0;
3060 DC::IMG_Init; video_init; 3146 DC::IMG_Init; video_init;
3061 DC::Mix_Init; audio_init; 3147 DC::Mix_Init; audio_init;
3062 }
3063 3148
3064 show_tip_of_the_day if $CFG->{show_tips}; 3149 show_tip_of_the_day if $CFG->{show_tips};
3065 3150
3066 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3151 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3067 undef $STARTUP_CANCEL; 3152 undef $STARTUP_CANCEL;
3068 (pop @::STARTUP_DONE)->() 3153 (pop @::STARTUP_DONE)->()
3069 while @::STARTUP_DONE; 3154 while @::STARTUP_DONE;
3155 };
3156
3157 debug_toggle 0;
3158
3159 delete $SIG{__DIE__};
3160 EV::run;
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;
3070 }; 3170 };
3071
3072 debug_toggle 0;
3073
3074 delete $SIG{__DIE__};
3075 EV::loop;
3076
3077 DC::save_cfg if $CFG->{config_autosave};
3078
3079 #video_shutdown;
3080 #audio_shutdown;
3081
3082 DC::OpenGL::quit;
3083 DC::SDL_Quit;
3084 DC::DB::Server::stop;
3085} 3171}
3086
3087*DC::Main::run = \&DC::SDL_braino; # see sub above
3088 3172
30891 31731

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines