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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines