… | |
… | |
97 | use List::Util qw(max min); |
97 | use List::Util qw(max min); |
98 | |
98 | |
99 | use Deliantra; |
99 | use Deliantra; |
100 | use Deliantra::Protocol::Constants; |
100 | use Deliantra::Protocol::Constants; |
101 | |
101 | |
|
|
102 | use AnyEvent::DNS; |
|
|
103 | use AnyEvent::Socket (); |
|
|
104 | |
102 | use Compress::LZF; |
105 | use Compress::LZF; |
103 | |
106 | |
|
|
107 | use DC; |
104 | use DC; BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } |
108 | BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } |
105 | use DC::OpenGL (); |
109 | use DC::OpenGL (); |
106 | use DC::Protocol; |
110 | use DC::Protocol; |
107 | use DC::DB; |
111 | use DC::DB; |
108 | use DC::UI; |
112 | use DC::UI; |
109 | use DC::UI::Canvas; |
113 | use DC::UI::Canvas; |
… | |
… | |
725 | |
729 | |
726 | $vbox->add (@dialog); |
730 | $vbox->add (@dialog); |
727 | $dialog->show; |
731 | $dialog->show; |
728 | } |
732 | } |
729 | |
733 | |
730 | sub start_game { |
734 | sub 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 | |
|
|
774 | sub 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 | |
775 | sub stop_game { |
800 | sub 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 | |
1746 | my %SORT_ORDER = ( |
1771 | my %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; |
… | |
… | |
2242 | has_close_button => 1, |
2269 | has_close_button => 1, |
2243 | ; |
2270 | ; |
2244 | |
2271 | |
2245 | $METASERVER = metaserver_dialog; |
2272 | $METASERVER = metaserver_dialog; |
2246 | # the name is changed to not conflict with the older name as users could have hidden it |
2273 | # the name is changed to not conflict with the older name as users could have hidden it |
2247 | $MESSAGE_WINDOW = new DC::UI::Dockbar (name => "message_window2", title => 'Messages'); |
2274 | $MESSAGE_WINDOW = new DC::UI::Dockbar |
|
|
2275 | name => "message_window2", |
|
|
2276 | title => 'Messages', |
|
|
2277 | force_w => $::WIDTH * 0.6, |
|
|
2278 | force_h => $::HEIGHT * 0.25, |
|
|
2279 | ; |
|
|
2280 | |
2248 | $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; |
2281 | $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; |
2249 | |
2282 | |
2250 | $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, |
2283 | $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, |
2251 | filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1); |
2284 | filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1); |
2252 | |
2285 | |
… | |
… | |
2474 | pickup => 0, |
2507 | pickup => 0, |
2475 | inv_sort => "mtime", |
2508 | inv_sort => "mtime", |
2476 | default => "profile", # default profile |
2509 | default => "profile", # default profile |
2477 | show_tips => 1, |
2510 | show_tips => 1, |
2478 | logview_max_par => 1000, |
2511 | logview_max_par => 1000, |
|
|
2512 | shift_fire_stop => 0, |
2479 | ); |
2513 | ); |
2480 | |
2514 | |
2481 | while (my ($k, $v) = each %DEF_CFG) { |
2515 | while (my ($k, $v) = each %DEF_CFG) { |
2482 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2516 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2483 | } |
2517 | } |