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.40 by root, Mon May 5 20:22:03 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
107use DC;
104use DC; BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } 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;
725 729
726 $vbox->add (@dialog); 730 $vbox->add (@dialog);
727 $dialog->show; 731 $dialog->show;
728} 732}
729 733
730sub start_game { 734sub dc_connect {
731 status "logging in..."; 735 my ($host, $port) = @_;
732
733 $LOGIN_BUTTON->set_text ("Logout");
734 $SETUP_DIALOG->hide;
735 736
736 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;
737 738
738 my ($host, $port) = split /:/, $PROFILE->{host};
739
740 $MAP = new DC::Map;
741
742 $CONN = eval { 739 $CONN =
743 new DC::Protocol 740 new DC::Protocol
744 host => $host, 741 host => $host,
745 port => $port || 13327, 742 port => $port,
746 user => $PROFILE->{user}, 743 user => $PROFILE->{user},
747 pass => $PROFILE->{password}, 744 pass => $PROFILE->{password},
748 mapw => $mapsize, 745 mapw => $mapsize,
749 maph => $mapsize, 746 maph => $mapsize,
750 747
757 query => \&server_query, 754 query => \&server_query,
758 755
759 setup_req => { 756 setup_req => {
760 smoothing => $CFG->{map_smoothing}*1, 757 smoothing => $CFG->{map_smoothing}*1,
761 }, 758 },
762 };
763 759
764 if ($CONN) { 760 on_connect => sub {
761 if ($_[0]) {
765 DC::lowdelay fileno $CONN->{fh}; 762 DC::lowdelay fileno $CONN->{fh};
766 763
767 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 };
768 } else { 795 } else {
769 warn $@; 796 dc_connect $host, $port;
770 status "unable to connect";
771 stop_game();
772 } 797 }
773} 798}
774 799
775sub stop_game { 800sub stop_game {
776 $LOGIN_BUTTON->set_text ("Login / Register"); 801 $LOGIN_BUTTON->set_text ("Login / Register");
1742 1767
1743 $r 1768 $r
1744} 1769}
1745 1770
1746my %SORT_ORDER = ( 1771my %SORT_ORDER = (
1747 type => undef, 1772 type => sub {
1773 sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_
1774 },
1748 mtime => sub { 1775 mtime => sub {
1749 my $NOW = time; 1776 my $NOW = time;
1750 sort { 1777 sort {
1751 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;
1752 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;
2480 pickup => 0, 2507 pickup => 0,
2481 inv_sort => "mtime", 2508 inv_sort => "mtime",
2482 default => "profile", # default profile 2509 default => "profile", # default profile
2483 show_tips => 1, 2510 show_tips => 1,
2484 logview_max_par => 1000, 2511 logview_max_par => 1000,
2512 shift_fire_stop => 0,
2485 ); 2513 );
2486 2514
2487 while (my ($k, $v) = each %DEF_CFG) { 2515 while (my ($k, $v) = each %DEF_CFG) {
2488 $CFG->{$k} = $v unless exists $CFG->{$k}; 2516 $CFG->{$k} = $v unless exists $CFG->{$k};
2489 } 2517 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines