ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/deliantra
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/deliantra (file contents):
Revision 1.29 by root, Mon Mar 24 00:24:47 2008 UTC vs.
Revision 1.50 by root, Thu Jul 17 13:07:01 2008 UTC

97use List::Util qw(max min); 97use List::Util qw(max min);
98 98
99use Deliantra; 99use Deliantra;
100use Deliantra::Protocol::Constants; 100use Deliantra::Protocol::Constants;
101 101
102use AnyEvent::DNS;
103
102use Compress::LZF; 104use Compress::LZF;
103 105
104use DC; 106use DC;
107BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } }
105use DC::OpenGL (); 108use DC::OpenGL ();
106use DC::Protocol; 109use DC::Protocol;
107use DC::DB; 110use DC::DB;
108use DC::UI; 111use DC::UI;
109use DC::UI::Canvas; 112use DC::UI::Canvas;
232 235
233 $markup .= $mod & DC::KMOD_NUM 236 $markup .= $mod & DC::KMOD_NUM
234 ? "[NUM]" 237 ? "[NUM]"
235 : "[<span foreground='#888'>num</span>]"; 238 : "[<span foreground='#888'>num</span>]";
236 239
240 # <tt> around next statement works around some bug that keeps the
241 # "font =>" from being used on windows
237 $MODBOX->set_markup ($markup); 242 $MODBOX->set_markup ("<tt>$markup</tt>");
238} 243}
239 244
240############################################################################# 245#############################################################################
241#TODO: maybe move into own audio module... 246#TODO: maybe move into own audio module...
242 247
662 # right: accept 667 # right: accept
663 $table->add_at (4, 0, new DC::UI::Button 668 $table->add_at (4, 0, new DC::UI::Button
664 text => "Accept", 669 text => "Accept",
665 on_activate => sub { 670 on_activate => sub {
666 $conn->send ("reply n"); 671 $conn->send ("reply n");
667 $STATS_PAGE->hide;
668 destroy_query_dialog $conn; 672 destroy_query_dialog $conn;
669 0 673 0
670 }, 674 },
671 ); 675 );
672 676
724 728
725 $vbox->add (@dialog); 729 $vbox->add (@dialog);
726 $dialog->show; 730 $dialog->show;
727} 731}
728 732
729sub start_game { 733sub dc_connect {
730 status "logging in..."; 734 my ($host, $port) = @_;
731
732 $LOGIN_BUTTON->set_text ("Logout");
733 $SETUP_DIALOG->hide;
734 735
735 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 736 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
736 737
737 my ($host, $port) = split /:/, $PROFILE->{host};
738
739 $MAP = new DC::Map;
740
741 $CONN = eval { 738 $CONN =
742 new DC::Protocol 739 new DC::Protocol
743 host => $host, 740 host => $host,
744 port => $port || 13327, 741 port => $port || "deliantra=13327",
745 user => $PROFILE->{user}, 742 user => $PROFILE->{user},
746 pass => $PROFILE->{password}, 743 pass => $PROFILE->{password},
747 mapw => $mapsize, 744 mapw => $mapsize,
748 maph => $mapsize, 745 maph => $mapsize,
749 746
756 query => \&server_query, 753 query => \&server_query,
757 754
758 setup_req => { 755 setup_req => {
759 smoothing => $CFG->{map_smoothing}*1, 756 smoothing => $CFG->{map_smoothing}*1,
760 }, 757 },
761 };
762 758
763 if ($CONN) { 759 on_connect => sub {
760 if ($_[0]) {
764 DC::lowdelay fileno $CONN->{fh}; 761 DC::lowdelay fileno $CONN->{fh};
765 762
766 status "login successful"; 763 status "login successful";
764 } else {
765 undef $CONN;
766 status "unable to connect: $!";
767 stop_game();
768 }
769 },
770 ;
771}
772
773sub start_game {
774 status "logging in...";
775
776 $LOGIN_BUTTON->set_text ("Logout");
777 $SETUP_DIALOG->hide;
778
779 my ($host, $port) = split /:/, $PROFILE->{host};
780
781 $MAP = new DC::Map;
782
783 # hack to make SURE we find the IP address all right
784 # can be removed once AnyEvent::DNS is proven stable.
785 if ($host eq "gameserver.deliantra.net") {
786 AnyEvent::DNS::a "dnstest.deliantra.net", sub {
787 if ($_[0] ne "80.101.114.108") { # Perl
788 status "dns failure, using hardcoded address";
789 $host = "129.13.162.95";
790 }
791
792 dc_connect $host, $port;
793 };
767 } else { 794 } else {
768 status "unable to connect"; 795 dc_connect $host, $port;
769 stop_game();
770 } 796 }
771} 797}
772 798
773sub stop_game { 799sub stop_game {
774 $LOGIN_BUTTON->set_text ("Login / Register"); 800 $LOGIN_BUTTON->set_text ("Login / Register");
1618 $CFG->{show_tips} = $value; 1644 $CFG->{show_tips} = $value;
1619 0 1645 0
1620 } 1646 }
1621 ); 1647 );
1622 1648
1623 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Messages Window Size"); 1649 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size");
1624 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry 1650 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry
1625 text => $CFG->{logview_max_par}, 1651 text => $CFG->{logview_max_par},
1626 tooltip => "This is maximum number of messages remembered in the <b>Messages</b> window. If the server " 1652 tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server "
1627 . "sends more messages than this number, older messages get removed to save memory and " 1653 . "sends more messages than this number, older messages get removed to save memory and "
1628 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", 1654 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.",
1629 on_changed => sub { 1655 on_changed => sub {
1630 my ($self, $value) = @_; 1656 my ($self, $value) = @_;
1631 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); 1657 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1);
1740 1766
1741 $r 1767 $r
1742} 1768}
1743 1769
1744my %SORT_ORDER = ( 1770my %SORT_ORDER = (
1745 type => undef, 1771 type => sub {
1772 sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_
1773 },
1746 mtime => sub { 1774 mtime => sub {
1747 my $NOW = time; 1775 my $NOW = time;
1748 sort { 1776 sort {
1749 my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6; 1777 my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6;
1750 my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6; 1778 my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6;
1972 my @path = DC::Pod::full_path_of $node; 2000 my @path = DC::Pod::full_path_of $node;
1973 pop @path; # drop current node 2001 pop @path; # drop current node
1974 2002
1975 for my $node (@path) { 2003 for my $node (@path) {
1976 $buttons->add (new DC::UI::Button 2004 $buttons->add (new DC::UI::Button
1977 text => $node->{kw}[0], 2005 text => $node->[DC::Pod::N_KW][0],
1978 tooltip => "go to <i>" . (DC::asxml DC::Pod::full_path $node) . "</i>", 2006 tooltip => "go to <i>" . (DC::asxml DC::Pod::full_path $node) . "</i>",
1979 on_activate => sub { 2007 on_activate => sub {
1980 push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = (); 2008 push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
1981 $load_node->($node); 2009 $load_node->($node);
1982 }, 2010 },
1983 ); 2011 );
1984 $buttons->add (new DC::UI::Label text => "/"); 2012 $buttons->add (new DC::UI::Label text => "/");
1985 } 2013 }
1986 2014
1987 $buttons->add (new DC::UI::Label text => $node->{kw}[0], padding_x => 4, padding_y => 4); 2015 $buttons->add (new DC::UI::Label text => $node->[DC::Pod::N_KW][0], padding_x => 4, padding_y => 4);
1988 2016
1989 $curnode = $node; 2017 $curnode = $node;
1990 2018
1991 $viewer->clear; 2019 $viewer->clear;
1992 $viewer->add_paragraph (DC::Pod::as_paragraphs DC::Pod::section_of $curnode); 2020 $viewer->add_paragraph (DC::Pod::as_paragraphs DC::Pod::section_of $curnode);
2178 can_events => 1, 2206 can_events => 1,
2179 can_hover => 1, 2207 can_hover => 1,
2180 markup => "", 2208 markup => "",
2181 align => 0, 2209 align => 0,
2182 font => $FONT_FIXED, 2210 font => $FONT_FIXED,
2183 tooltip => "#modifier_box"; 2211 tooltip => "#modifier_box",
2212 tooltip_width => 0.67,
2213 ;
2184 2214
2185 update_modbox; 2215 update_modbox;
2186 2216
2187 (new DC::UI::Frame 2217 (new DC::UI::Frame
2188 bg => [0, 0, 0, 0.4], 2218 bg => [0, 0, 0, 0.4],
2237 force_h => $::HEIGHT * 0.6, 2267 force_h => $::HEIGHT * 0.6,
2238 has_close_button => 1, 2268 has_close_button => 1,
2239 ; 2269 ;
2240 2270
2241 $METASERVER = metaserver_dialog; 2271 $METASERVER = metaserver_dialog;
2242 $MESSAGE_WINDOW = new DC::UI::Dockbar (name => 'message_window', title => 'Messages'); 2272 # the name is changed to not conflict with the older name as users could have hidden it
2273 $MESSAGE_WINDOW = new DC::UI::Dockbar
2274 name => "message_window2",
2275 title => 'Messages',
2276 force_w => $::WIDTH * 0.6,
2277 force_h => $::HEIGHT * 0.25,
2278 ;
2279
2243 $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; 2280 $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW;
2244 2281
2245 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, debug => 1, 2282 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1,
2246 filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1); 2283 filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1);
2247 2284
2248 $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup, 2285 $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup,
2249 "Configure the server to play on, your username and password."); 2286 "Configure the server to play on, your username and password.");
2250 $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup, 2287 $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup,
2268 $BUTTONBAR = new DC::UI::Buttonbar x => 0, y => 0, z => 200; # put on top 2305 $BUTTONBAR = new DC::UI::Buttonbar x => 0, y => 0, z => 200; # put on top
2269 2306
2270 $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG, 2307 $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG,
2271 tooltip => "Toggles a dialog where you can configure all aspects of this client."); 2308 tooltip => "Toggles a dialog where you can configure all aspects of this client.");
2272 2309
2273 $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW, 2310# $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW,
2274 tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server."); 2311# tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server.");
2275 2312
2276 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D 2313 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
2277 2314
2278 $BUTTONBAR->add (new DC::UI::Flopper text => "Playerbook", other => player_window, 2315 $BUTTONBAR->add (new DC::UI::Flopper text => "Playerbook", other => player_window,
2279 tooltip => "Toggles the player view, where you can manage Inventory, Spells, Skills and see your Stats."); 2316 tooltip => "Toggles the player view, where you can manage Inventory, Spells, Skills and see your Stats.");
2281 $BUTTONBAR->add (new DC::UI::Button 2318 $BUTTONBAR->add (new DC::UI::Button
2282 text => "Save Config", 2319 text => "Save Config",
2283 tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.", 2320 tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.",
2284 on_activate => sub { 2321 on_activate => sub {
2285 $::CFG->{layout} = DC::UI::get_layout; 2322 $::CFG->{layout} = DC::UI::get_layout;
2286 DC::write_cfg "$Deliantra::VARDIR/client.cf"; 2323 DC::write_cfg;
2287 status "Configuration Saved"; 2324 status "Configuration Saved";
2288 0 2325 0
2289 }, 2326 },
2290 ); 2327 );
2291 2328
2292 $BUTTONBAR->add (new DC::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window, 2329 $BUTTONBAR->add (new DC::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window,
2293 tooltip => "View Documentation"); 2330 tooltip => "View Documentation");
2294
2295 2331
2296 $BUTTONBAR->add (new DC::UI::Button 2332 $BUTTONBAR->add (new DC::UI::Button
2297 text => "Quit", 2333 text => "Quit",
2298 tooltip => "Terminates the program", 2334 tooltip => "Terminates the program",
2299 on_activate => sub { 2335 on_activate => sub {
2416 EV::unloop; 2452 EV::unloop;
2417 #d# TODO calling exit here hangs the process in some futex 2453 #d# TODO calling exit here hangs the process in some futex
2418}; 2454};
2419 2455
2420{ 2456{
2457 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2458
2421 if (-e "$Deliantra::VARDIR/client.cf") { 2459 if (-e "$Deliantra::VARDIR/client.cf") {
2422 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2460 DC::read_cfg "$Deliantra::VARDIR/client.cf";
2423 } else { 2461 } else {
2424 #TODO: compatibility cruft 2462 #TODO: compatibility cruft
2425 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc"; 2463 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2426 print STDERR "INFO: used old configuration file\n"; 2464 print STDERR "INFO: used old configuration file\n";
2427 } 2465 }
2428 2466
2429 DC::DB::Server::run; 2467 DC::DB::Server::run;
2468
2469 if ($CFG->{db_schema} < 1) {
2470 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2471 DC::DB::nuke_db;
2472 $CFG->{db_schema} = 1;
2473 DC::write_cfg;
2474 }
2475
2476 DC::DB::open_db;
2430 2477
2431 DC::UI::set_layout ($::CFG->{layout}); 2478 DC::UI::set_layout ($::CFG->{layout});
2432 2479
2433 my %DEF_CFG = ( 2480 my %DEF_CFG = (
2434 sdl_mode => 0, 2481 sdl_mode => 0,
2459 pickup => 0, 2506 pickup => 0,
2460 inv_sort => "mtime", 2507 inv_sort => "mtime",
2461 default => "profile", # default profile 2508 default => "profile", # default profile
2462 show_tips => 1, 2509 show_tips => 1,
2463 logview_max_par => 1000, 2510 logview_max_par => 1000,
2511 shift_fire_stop => 0,
2464 ); 2512 );
2465 2513
2466 while (my ($k, $v) = each %DEF_CFG) { 2514 while (my ($k, $v) = each %DEF_CFG) {
2467 $CFG->{$k} = $v unless exists $CFG->{$k}; 2515 $CFG->{$k} = $v unless exists $CFG->{$k};
2468 } 2516 }
2504 DejaVuSansMono-BoldOblique.ttf 2552 DejaVuSansMono-BoldOblique.ttf
2505 ); 2553 );
2506 2554
2507 DC::add_font $_ for @fonts; 2555 DC::add_font $_ for @fonts;
2508 2556
2509 DC::pango_init;
2510
2511 $FONT_PROP = new_from_file DC::Font $fonts[0]; 2557 $FONT_PROP = new_from_file DC::Font $fonts[0];
2512 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 2558 $FONT_FIXED = new_from_file DC::Font $fonts[1];
2513 2559
2514 $FONT_PROP->make_default; 2560 $FONT_PROP->make_default;
2561
2562 DC::pango_init;
2515 } 2563 }
2516 2564
2517# compare mono (ft) vs. rgba (cairo) 2565# compare mono (ft) vs. rgba (cairo)
2518# ft - 1.8s, cairo 3s, even in alpha-only mode 2566# ft - 1.8s, cairo 3s, even in alpha-only mode
2519# for my $rgba (0..1) { 2567# for my $rgba (0..1) {
2536our $STARTUP_CANCEL = EV::idle sub { 2584our $STARTUP_CANCEL = EV::idle sub {
2537 undef $::STARTUP_CANCEL; 2585 undef $::STARTUP_CANCEL;
2538 $startup_done->(); 2586 $startup_done->();
2539}; 2587};
2540 2588
2589delete $SIG{__DIE__};
2541EV::loop; 2590EV::loop;
2542 2591
2543#video_shutdown; 2592#video_shutdown;
2544#audio_shutdown; 2593#audio_shutdown;
2545DC::OpenGL::quit; 2594DC::OpenGL::quit;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines