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.38 by root, Mon May 5 16:26:11 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;
725 732
726 $vbox->add (@dialog); 733 $vbox->add (@dialog);
727 $dialog->show; 734 $dialog->show;
728} 735}
729 736
730sub start_game { 737sub dc_connect {
731 status "logging in..."; 738 my ($host, $port) = @_;
732
733 $LOGIN_BUTTON->set_text ("Logout");
734 $SETUP_DIALOG->hide;
735 739
736 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;
737 741
738 my ($host, $port) = split /:/, $PROFILE->{host};
739
740 $MAP = new DC::Map;
741
742 $CONN = eval { 742 $CONN =
743 new DC::Protocol 743 new DC::Protocol
744 host => $host, 744 host => $host,
745 port => $port || 13327, 745 port => $port || 13327,
746 user => $PROFILE->{user}, 746 user => $PROFILE->{user},
747 pass => $PROFILE->{password}, 747 pass => $PROFILE->{password},
757 query => \&server_query, 757 query => \&server_query,
758 758
759 setup_req => { 759 setup_req => {
760 smoothing => $CFG->{map_smoothing}*1, 760 smoothing => $CFG->{map_smoothing}*1,
761 }, 761 },
762 };
763 762
764 if ($CONN) { 763 on_connect => sub {
764 if ($_[0]) {
765 DC::lowdelay fileno $CONN->{fh}; 765 DC::lowdelay fileno $CONN->{fh};
766 766
767 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 };
768 } else { 798 } else {
769 warn $@; 799 dc_connect $host, $port;
770 status "unable to connect";
771 stop_game();
772 } 800 }
773} 801}
774 802
775sub stop_game { 803sub stop_game {
776 $LOGIN_BUTTON->set_text ("Login / Register"); 804 $LOGIN_BUTTON->set_text ("Login / Register");
1742 1770
1743 $r 1771 $r
1744} 1772}
1745 1773
1746my %SORT_ORDER = ( 1774my %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;
2276 # the name is changed to not conflict with the older name as users could have hidden it
2246 $MESSAGE_WINDOW = new DC::UI::Dockbar (title => 'Messages'); 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, 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
2473 pickup => 0, 2510 pickup => 0,
2474 inv_sort => "mtime", 2511 inv_sort => "mtime",
2475 default => "profile", # default profile 2512 default => "profile", # default profile
2476 show_tips => 1, 2513 show_tips => 1,
2477 logview_max_par => 1000, 2514 logview_max_par => 1000,
2515 shift_fire_stop => 0,
2478 ); 2516 );
2479 2517
2480 while (my ($k, $v) = each %DEF_CFG) { 2518 while (my ($k, $v) = each %DEF_CFG) {
2481 $CFG->{$k} = $v unless exists $CFG->{$k}; 2519 $CFG->{$k} = $v unless exists $CFG->{$k};
2482 } 2520 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines