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.48 by root, Mon Jul 7 08:02:17 2008 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2
3{
4package Deliantra::Client; # work around CPAN breakage
5package App::Deliantra; # try to reserve namespace
6}
2 7
3if ($ENV{DELIANTRA_CORO_DEBUG}) { 8if ($ENV{DELIANTRA_CORO_DEBUG}) {
4 eval ' 9 eval '
5 use Coro; 10 use Coro;
6 use Coro::EV; 11 use Coro::EV;
97use List::Util qw(max min); 102use List::Util qw(max min);
98 103
99use Deliantra; 104use Deliantra;
100use Deliantra::Protocol::Constants; 105use Deliantra::Protocol::Constants;
101 106
107use AnyEvent::DNS;
108
102use Compress::LZF; 109use Compress::LZF;
103 110
111use DC;
104use DC; BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } 112BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } }
105use DC::OpenGL (); 113use DC::OpenGL ();
106use DC::Protocol; 114use DC::Protocol;
107use DC::DB; 115use DC::DB;
108use DC::UI; 116use DC::UI;
109use DC::UI::Canvas; 117use DC::UI::Canvas;
725 733
726 $vbox->add (@dialog); 734 $vbox->add (@dialog);
727 $dialog->show; 735 $dialog->show;
728} 736}
729 737
730sub start_game { 738sub dc_connect {
731 status "logging in..."; 739 my ($host, $port) = @_;
732
733 $LOGIN_BUTTON->set_text ("Logout");
734 $SETUP_DIALOG->hide;
735 740
736 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 741 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
737 742
738 my ($host, $port) = split /:/, $PROFILE->{host};
739
740 $MAP = new DC::Map;
741
742 $CONN = eval { 743 $CONN =
743 new DC::Protocol 744 new DC::Protocol
744 host => $host, 745 host => $host,
745 port => $port || 13327, 746 port => $port || 13327,
746 user => $PROFILE->{user}, 747 user => $PROFILE->{user},
747 pass => $PROFILE->{password}, 748 pass => $PROFILE->{password},
757 query => \&server_query, 758 query => \&server_query,
758 759
759 setup_req => { 760 setup_req => {
760 smoothing => $CFG->{map_smoothing}*1, 761 smoothing => $CFG->{map_smoothing}*1,
761 }, 762 },
762 };
763 763
764 if ($CONN) { 764 on_connect => sub {
765 if ($_[0]) {
765 DC::lowdelay fileno $CONN->{fh}; 766 DC::lowdelay fileno $CONN->{fh};
766 767
767 status "login successful"; 768 status "login successful";
769 } else {
770 undef $CONN;
771 status "unable to connect: $!";
772 stop_game();
773 }
774 },
775 ;
776}
777
778sub start_game {
779 status "logging in...";
780
781 $LOGIN_BUTTON->set_text ("Logout");
782 $SETUP_DIALOG->hide;
783
784 my ($host, $port) = split /:/, $PROFILE->{host};
785
786 $MAP = new DC::Map;
787
788 # hack to make SURE we find the IP address all right
789 # can be removed once AnyEvent::DNS is proven stable.
790 if ($host eq "gameserver.deliantra.net") {
791 AnyEvent::DNS::a "dnstest.deliantra.net", sub {
792 if ($_[0] ne "80.101.114.108") { # Perl
793 status "dns failure, using hardcoded address";
794 $host = "129.13.162.95";
795 }
796
797 dc_connect $host, $port;
798 };
768 } else { 799 } else {
769 warn $@; 800 dc_connect $host, $port;
770 status "unable to connect";
771 stop_game();
772 } 801 }
773} 802}
774 803
775sub stop_game { 804sub stop_game {
776 $LOGIN_BUTTON->set_text ("Login / Register"); 805 $LOGIN_BUTTON->set_text ("Login / Register");
1742 1771
1743 $r 1772 $r
1744} 1773}
1745 1774
1746my %SORT_ORDER = ( 1775my %SORT_ORDER = (
1747 type => undef, 1776 type => sub {
1777 sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_
1778 },
1748 mtime => sub { 1779 mtime => sub {
1749 my $NOW = time; 1780 my $NOW = time;
1750 sort { 1781 sort {
1751 my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6; 1782 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; 1783 my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6;
2480 pickup => 0, 2511 pickup => 0,
2481 inv_sort => "mtime", 2512 inv_sort => "mtime",
2482 default => "profile", # default profile 2513 default => "profile", # default profile
2483 show_tips => 1, 2514 show_tips => 1,
2484 logview_max_par => 1000, 2515 logview_max_par => 1000,
2516 shift_fire_stop => 0,
2485 ); 2517 );
2486 2518
2487 while (my ($k, $v) = each %DEF_CFG) { 2519 while (my ($k, $v) = each %DEF_CFG) {
2488 $CFG->{$k} = $v unless exists $CFG->{$k}; 2520 $CFG->{$k} = $v unless exists $CFG->{$k};
2489 } 2521 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines