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.36 by root, Thu Apr 17 02:42:27 2008 UTC vs.
Revision 1.47 by root, Mon Jul 7 05:02:03 2008 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2
3{
4package Deliantra::Client; # work around CPAN breakage
5}
2 6
3if ($ENV{DELIANTRA_CORO_DEBUG}) { 7if ($ENV{DELIANTRA_CORO_DEBUG}) {
4 eval ' 8 eval '
5 use Coro; 9 use Coro;
6 use Coro::EV; 10 use Coro::EV;
97use List::Util qw(max min); 101use List::Util qw(max min);
98 102
99use Deliantra; 103use Deliantra;
100use Deliantra::Protocol::Constants; 104use Deliantra::Protocol::Constants;
101 105
106use AnyEvent::DNS;
107
102use Compress::LZF; 108use Compress::LZF;
103 109
110use DC;
104use DC; BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } 111BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } }
105use DC::OpenGL (); 112use DC::OpenGL ();
106use DC::Protocol; 113use DC::Protocol;
107use DC::DB; 114use DC::DB;
108use DC::UI; 115use DC::UI;
109use DC::UI::Canvas; 116use 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
731sub start_game { 737sub 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
777sub 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 warn $@; 799 dc_connect $host, $port;
771 status "unable to connect";
772 stop_game();
773 } 800 }
774} 801}
775 802
776sub stop_game { 803sub stop_game {
777 $LOGIN_BUTTON->set_text ("Login / Register"); 804 $LOGIN_BUTTON->set_text ("Login / Register");
1621 $CFG->{show_tips} = $value; 1648 $CFG->{show_tips} = $value;
1622 0 1649 0
1623 } 1650 }
1624 ); 1651 );
1625 1652
1626 $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");
1627 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry 1654 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry
1628 text => $CFG->{logview_max_par}, 1655 text => $CFG->{logview_max_par},
1629 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 "
1630 . "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 "
1631 . "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.",
1632 on_changed => sub { 1659 on_changed => sub {
1633 my ($self, $value) = @_; 1660 my ($self, $value) = @_;
1634 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); 1661 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1);
1743 1770
1744 $r 1771 $r
1745} 1772}
1746 1773
1747my %SORT_ORDER = ( 1774my %SORT_ORDER = (
1748 type => undef, 1775 type => sub {
1776 sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_
1777 },
1749 mtime => sub { 1778 mtime => sub {
1750 my $NOW = time; 1779 my $NOW = time;
1751 sort { 1780 sort {
1752 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;
1753 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;
2242 force_h => $::HEIGHT * 0.6, 2271 force_h => $::HEIGHT * 0.6,
2243 has_close_button => 1, 2272 has_close_button => 1,
2244 ; 2273 ;
2245 2274
2246 $METASERVER = metaserver_dialog; 2275 $METASERVER = metaserver_dialog;
2247 $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
2248 $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; 2284 $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW;
2249 2285
2250 $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,
2251 filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1); 2287 filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1);
2252 2288
2253 $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup, 2289 $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup,
2254 "Configure the server to play on, your username and password."); 2290 "Configure the server to play on, your username and password.");
2255 $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup, 2291 $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup,
2273 $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
2274 2310
2275 $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG, 2311 $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG,
2276 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.");
2277 2313
2278 $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,
2279 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.");
2280 2316
2281 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
2282 2318
2283 $BUTTONBAR->add (new DC::UI::Flopper text => "Playerbook", other => player_window, 2319 $BUTTONBAR->add (new DC::UI::Flopper text => "Playerbook", other => player_window,
2284 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.");
2294 }, 2330 },
2295 ); 2331 );
2296 2332
2297 $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,
2298 tooltip => "View Documentation"); 2334 tooltip => "View Documentation");
2299
2300 2335
2301 $BUTTONBAR->add (new DC::UI::Button 2336 $BUTTONBAR->add (new DC::UI::Button
2302 text => "Quit", 2337 text => "Quit",
2303 tooltip => "Terminates the program", 2338 tooltip => "Terminates the program",
2304 on_activate => sub { 2339 on_activate => sub {
2475 pickup => 0, 2510 pickup => 0,
2476 inv_sort => "mtime", 2511 inv_sort => "mtime",
2477 default => "profile", # default profile 2512 default => "profile", # default profile
2478 show_tips => 1, 2513 show_tips => 1,
2479 logview_max_par => 1000, 2514 logview_max_par => 1000,
2515 shift_fire_stop => 0,
2480 ); 2516 );
2481 2517
2482 while (my ($k, $v) = each %DEF_CFG) { 2518 while (my ($k, $v) = each %DEF_CFG) {
2483 $CFG->{$k} = $v unless exists $CFG->{$k}; 2519 $CFG->{$k} = $v unless exists $CFG->{$k};
2484 } 2520 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines