1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
|
|
2 | |
|
|
3 | { |
|
|
4 | package Deliantra::Client; # work around CPAN breakage |
|
|
5 | } |
2 | |
6 | |
3 | if ($ENV{DELIANTRA_CORO_DEBUG}) { |
7 | if ($ENV{DELIANTRA_CORO_DEBUG}) { |
4 | eval ' |
8 | eval ' |
5 | use Coro; |
9 | use Coro; |
6 | use Coro::EV; |
10 | use Coro::EV; |
… | |
… | |
97 | use List::Util qw(max min); |
101 | use List::Util qw(max min); |
98 | |
102 | |
99 | use Deliantra; |
103 | use Deliantra; |
100 | use Deliantra::Protocol::Constants; |
104 | use Deliantra::Protocol::Constants; |
101 | |
105 | |
|
|
106 | use AnyEvent::DNS; |
|
|
107 | |
102 | use Compress::LZF; |
108 | use Compress::LZF; |
103 | |
109 | |
104 | use DC; |
110 | use DC; |
|
|
111 | BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } |
105 | use DC::OpenGL (); |
112 | use DC::OpenGL (); |
106 | use DC::Protocol; |
113 | use DC::Protocol; |
107 | use DC::DB; |
114 | use DC::DB; |
108 | use DC::UI; |
115 | use DC::UI; |
109 | use DC::UI::Canvas; |
116 | use DC::UI::Canvas; |
… | |
… | |
664 | # right: accept |
671 | # right: accept |
665 | $table->add_at (4, 0, new DC::UI::Button |
672 | $table->add_at (4, 0, new DC::UI::Button |
666 | text => "Accept", |
673 | text => "Accept", |
667 | on_activate => sub { |
674 | on_activate => sub { |
668 | $conn->send ("reply n"); |
675 | $conn->send ("reply n"); |
669 | $STATS_PAGE->hide; |
|
|
670 | destroy_query_dialog $conn; |
676 | destroy_query_dialog $conn; |
671 | 0 |
677 | 0 |
672 | }, |
678 | }, |
673 | ); |
679 | ); |
674 | |
680 | |
… | |
… | |
726 | |
732 | |
727 | $vbox->add (@dialog); |
733 | $vbox->add (@dialog); |
728 | $dialog->show; |
734 | $dialog->show; |
729 | } |
735 | } |
730 | |
736 | |
731 | sub start_game { |
737 | sub dc_connect { |
732 | status "logging in..."; |
738 | my ($host, $port) = @_; |
733 | |
|
|
734 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
735 | $SETUP_DIALOG->hide; |
|
|
736 | |
739 | |
737 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
740 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
738 | |
741 | |
739 | my ($host, $port) = split /:/, $PROFILE->{host}; |
|
|
740 | |
|
|
741 | $MAP = new DC::Map; |
|
|
742 | |
|
|
743 | $CONN = eval { |
742 | $CONN = |
744 | new DC::Protocol |
743 | new DC::Protocol |
745 | host => $host, |
744 | host => $host, |
746 | port => $port || 13327, |
745 | port => $port || 13327, |
747 | user => $PROFILE->{user}, |
746 | user => $PROFILE->{user}, |
748 | pass => $PROFILE->{password}, |
747 | pass => $PROFILE->{password}, |
… | |
… | |
758 | query => \&server_query, |
757 | query => \&server_query, |
759 | |
758 | |
760 | setup_req => { |
759 | setup_req => { |
761 | smoothing => $CFG->{map_smoothing}*1, |
760 | smoothing => $CFG->{map_smoothing}*1, |
762 | }, |
761 | }, |
763 | }; |
|
|
764 | |
762 | |
765 | if ($CONN) { |
763 | on_connect => sub { |
|
|
764 | if ($_[0]) { |
766 | DC::lowdelay fileno $CONN->{fh}; |
765 | DC::lowdelay fileno $CONN->{fh}; |
767 | |
766 | |
768 | status "login successful"; |
767 | status "login successful"; |
|
|
768 | } else { |
|
|
769 | undef $CONN; |
|
|
770 | status "unable to connect: $!"; |
|
|
771 | stop_game(); |
|
|
772 | } |
|
|
773 | }, |
|
|
774 | ; |
|
|
775 | } |
|
|
776 | |
|
|
777 | sub start_game { |
|
|
778 | status "logging in..."; |
|
|
779 | |
|
|
780 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
781 | $SETUP_DIALOG->hide; |
|
|
782 | |
|
|
783 | my ($host, $port) = split /:/, $PROFILE->{host}; |
|
|
784 | |
|
|
785 | $MAP = new DC::Map; |
|
|
786 | |
|
|
787 | # hack to make SURE we find the IP address all right |
|
|
788 | # can be removed once AnyEvent::DNS is proven stable. |
|
|
789 | if ($host eq "gameserver.deliantra.net") { |
|
|
790 | AnyEvent::DNS::a "dnstest.deliantra.net", sub { |
|
|
791 | if ($_[0] ne "80.101.114.108") { # Perl |
|
|
792 | status "dns failure, using hardcoded address"; |
|
|
793 | $host = "129.13.162.95"; |
|
|
794 | } |
|
|
795 | |
|
|
796 | dc_connect $host, $port; |
|
|
797 | }; |
769 | } else { |
798 | } else { |
770 | status "unable to connect"; |
799 | dc_connect $host, $port; |
771 | stop_game(); |
|
|
772 | } |
800 | } |
773 | } |
801 | } |
774 | |
802 | |
775 | sub stop_game { |
803 | sub stop_game { |
776 | $LOGIN_BUTTON->set_text ("Login / Register"); |
804 | $LOGIN_BUTTON->set_text ("Login / Register"); |
… | |
… | |
1620 | $CFG->{show_tips} = $value; |
1648 | $CFG->{show_tips} = $value; |
1621 | 0 |
1649 | 0 |
1622 | } |
1650 | } |
1623 | ); |
1651 | ); |
1624 | |
1652 | |
1625 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Messages Window Size"); |
1653 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size"); |
1626 | $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry |
1654 | $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry |
1627 | text => $CFG->{logview_max_par}, |
1655 | text => $CFG->{logview_max_par}, |
1628 | tooltip => "This is maximum number of messages remembered in the <b>Messages</b> window. If the server " |
1656 | tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server " |
1629 | . "sends more messages than this number, older messages get removed to save memory and " |
1657 | . "sends more messages than this number, older messages get removed to save memory and " |
1630 | . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", |
1658 | . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", |
1631 | on_changed => sub { |
1659 | on_changed => sub { |
1632 | my ($self, $value) = @_; |
1660 | my ($self, $value) = @_; |
1633 | $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); |
1661 | $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); |
… | |
… | |
1742 | |
1770 | |
1743 | $r |
1771 | $r |
1744 | } |
1772 | } |
1745 | |
1773 | |
1746 | my %SORT_ORDER = ( |
1774 | my %SORT_ORDER = ( |
1747 | type => undef, |
1775 | type => sub { |
|
|
1776 | sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_ |
|
|
1777 | }, |
1748 | mtime => sub { |
1778 | mtime => sub { |
1749 | my $NOW = time; |
1779 | my $NOW = time; |
1750 | sort { |
1780 | sort { |
1751 | my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6; |
1781 | my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6; |
1752 | my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6; |
1782 | my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6; |
… | |
… | |
2241 | force_h => $::HEIGHT * 0.6, |
2271 | force_h => $::HEIGHT * 0.6, |
2242 | has_close_button => 1, |
2272 | has_close_button => 1, |
2243 | ; |
2273 | ; |
2244 | |
2274 | |
2245 | $METASERVER = metaserver_dialog; |
2275 | $METASERVER = metaserver_dialog; |
2246 | $MESSAGE_WINDOW = new DC::UI::Dockbar (name => 'message_window', title => 'Messages'); |
2276 | # the name is changed to not conflict with the older name as users could have hidden it |
|
|
2277 | $MESSAGE_WINDOW = new DC::UI::Dockbar |
|
|
2278 | name => "message_window2", |
|
|
2279 | title => 'Messages', |
|
|
2280 | force_w => $::WIDTH * 0.6, |
|
|
2281 | force_h => $::HEIGHT * 0.25, |
|
|
2282 | ; |
|
|
2283 | |
2247 | $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; |
2284 | $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; |
2248 | |
2285 | |
2249 | $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, debug => 1, |
2286 | $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, |
2250 | filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1); |
2287 | filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1); |
2251 | |
2288 | |
2252 | $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup, |
2289 | $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup, |
2253 | "Configure the server to play on, your username and password."); |
2290 | "Configure the server to play on, your username and password."); |
2254 | $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup, |
2291 | $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup, |
… | |
… | |
2272 | $BUTTONBAR = new DC::UI::Buttonbar x => 0, y => 0, z => 200; # put on top |
2309 | $BUTTONBAR = new DC::UI::Buttonbar x => 0, y => 0, z => 200; # put on top |
2273 | |
2310 | |
2274 | $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG, |
2311 | $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG, |
2275 | tooltip => "Toggles a dialog where you can configure all aspects of this client."); |
2312 | tooltip => "Toggles a dialog where you can configure all aspects of this client."); |
2276 | |
2313 | |
2277 | $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW, |
2314 | # $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW, |
2278 | tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server."); |
2315 | # tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server."); |
2279 | |
2316 | |
2280 | 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 |
2317 | 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 |
2281 | |
2318 | |
2282 | $BUTTONBAR->add (new DC::UI::Flopper text => "Playerbook", other => player_window, |
2319 | $BUTTONBAR->add (new DC::UI::Flopper text => "Playerbook", other => player_window, |
2283 | tooltip => "Toggles the player view, where you can manage Inventory, Spells, Skills and see your Stats."); |
2320 | tooltip => "Toggles the player view, where you can manage Inventory, Spells, Skills and see your Stats."); |
… | |
… | |
2285 | $BUTTONBAR->add (new DC::UI::Button |
2322 | $BUTTONBAR->add (new DC::UI::Button |
2286 | text => "Save Config", |
2323 | text => "Save Config", |
2287 | tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.", |
2324 | tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.", |
2288 | on_activate => sub { |
2325 | on_activate => sub { |
2289 | $::CFG->{layout} = DC::UI::get_layout; |
2326 | $::CFG->{layout} = DC::UI::get_layout; |
2290 | DC::write_cfg "$Deliantra::VARDIR/client.cf"; |
2327 | DC::write_cfg; |
2291 | status "Configuration Saved"; |
2328 | status "Configuration Saved"; |
2292 | 0 |
2329 | 0 |
2293 | }, |
2330 | }, |
2294 | ); |
2331 | ); |
2295 | |
2332 | |
2296 | $BUTTONBAR->add (new DC::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window, |
2333 | $BUTTONBAR->add (new DC::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window, |
2297 | tooltip => "View Documentation"); |
2334 | tooltip => "View Documentation"); |
2298 | |
|
|
2299 | |
2335 | |
2300 | $BUTTONBAR->add (new DC::UI::Button |
2336 | $BUTTONBAR->add (new DC::UI::Button |
2301 | text => "Quit", |
2337 | text => "Quit", |
2302 | tooltip => "Terminates the program", |
2338 | tooltip => "Terminates the program", |
2303 | on_activate => sub { |
2339 | on_activate => sub { |
… | |
… | |
2420 | EV::unloop; |
2456 | EV::unloop; |
2421 | #d# TODO calling exit here hangs the process in some futex |
2457 | #d# TODO calling exit here hangs the process in some futex |
2422 | }; |
2458 | }; |
2423 | |
2459 | |
2424 | { |
2460 | { |
|
|
2461 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
|
|
2462 | |
2425 | if (-e "$Deliantra::VARDIR/client.cf") { |
2463 | if (-e "$Deliantra::VARDIR/client.cf") { |
2426 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
2464 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
2427 | } else { |
2465 | } else { |
2428 | #TODO: compatibility cruft |
2466 | #TODO: compatibility cruft |
2429 | DC::read_cfg "$Deliantra::OLDDIR/cfplusrc"; |
2467 | DC::read_cfg "$Deliantra::OLDDIR/cfplusrc"; |
2430 | print STDERR "INFO: used old configuration file\n"; |
2468 | print STDERR "INFO: used old configuration file\n"; |
2431 | } |
2469 | } |
2432 | |
2470 | |
2433 | DC::DB::Server::run; |
2471 | DC::DB::Server::run; |
|
|
2472 | |
|
|
2473 | if ($CFG->{db_schema} < 1) { |
|
|
2474 | warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; |
|
|
2475 | DC::DB::nuke_db; |
|
|
2476 | $CFG->{db_schema} = 1; |
|
|
2477 | DC::write_cfg; |
|
|
2478 | } |
|
|
2479 | |
|
|
2480 | DC::DB::open_db; |
2434 | |
2481 | |
2435 | DC::UI::set_layout ($::CFG->{layout}); |
2482 | DC::UI::set_layout ($::CFG->{layout}); |
2436 | |
2483 | |
2437 | my %DEF_CFG = ( |
2484 | my %DEF_CFG = ( |
2438 | sdl_mode => 0, |
2485 | sdl_mode => 0, |
… | |
… | |
2463 | pickup => 0, |
2510 | pickup => 0, |
2464 | inv_sort => "mtime", |
2511 | inv_sort => "mtime", |
2465 | default => "profile", # default profile |
2512 | default => "profile", # default profile |
2466 | show_tips => 1, |
2513 | show_tips => 1, |
2467 | logview_max_par => 1000, |
2514 | logview_max_par => 1000, |
|
|
2515 | shift_fire_stop => 0, |
2468 | ); |
2516 | ); |
2469 | |
2517 | |
2470 | while (my ($k, $v) = each %DEF_CFG) { |
2518 | while (my ($k, $v) = each %DEF_CFG) { |
2471 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2519 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2472 | } |
2520 | } |
… | |
… | |
2540 | our $STARTUP_CANCEL = EV::idle sub { |
2588 | our $STARTUP_CANCEL = EV::idle sub { |
2541 | undef $::STARTUP_CANCEL; |
2589 | undef $::STARTUP_CANCEL; |
2542 | $startup_done->(); |
2590 | $startup_done->(); |
2543 | }; |
2591 | }; |
2544 | |
2592 | |
|
|
2593 | delete $SIG{__DIE__}; |
2545 | EV::loop; |
2594 | EV::loop; |
2546 | |
2595 | |
2547 | #video_shutdown; |
2596 | #video_shutdown; |
2548 | #audio_shutdown; |
2597 | #audio_shutdown; |
2549 | DC::OpenGL::quit; |
2598 | DC::OpenGL::quit; |