… | |
… | |
25 | BEGIN { *time = \&EV::time } |
25 | BEGIN { *time = \&EV::time } |
26 | |
26 | |
27 | use List::Util qw(max min); |
27 | use List::Util qw(max min); |
28 | |
28 | |
29 | use Deliantra; |
29 | use Deliantra; |
|
|
30 | use Deliantra::Util; |
30 | use Deliantra::Protocol::Constants; |
31 | use Deliantra::Protocol::Constants; |
31 | |
32 | |
32 | use AnyEvent::Util (); |
33 | use AnyEvent::Util (); |
33 | use AnyEvent::Socket (); |
34 | use AnyEvent::Socket (); |
34 | use AnyEvent::DNS (); |
35 | use AnyEvent::DNS (); |
… | |
… | |
128 | our $MENUBAR; # the hbox at the top |
129 | our $MENUBAR; # the hbox at the top |
129 | our $MENUPOPUP; |
130 | our $MENUPOPUP; |
130 | our $BUTTONBAR; # the menu buttons |
131 | our $BUTTONBAR; # the menu buttons |
131 | our $METASERVER; |
132 | our $METASERVER; |
132 | our $LOGIN_BUTTON; |
133 | our $LOGIN_BUTTON; |
|
|
134 | our $LOGIN_ERROR; |
133 | our $QUIT_DIALOG; |
135 | our $QUIT_DIALOG; |
134 | our $HOST_ENTRY; |
136 | our $HOST_ENTRY; |
135 | our $FULLSCREEN_ENABLE; |
137 | our $FULLSCREEN_ENABLE; |
136 | our $PICKUP_ENABLE; |
138 | our $PICKUP_ENABLE; |
137 | our $SERVER_INFO; |
139 | our $SERVER_INFO; |
… | |
… | |
251 | : "[<span foreground='#888'>num</span>]"; |
253 | : "[<span foreground='#888'>num</span>]"; |
252 | |
254 | |
253 | # <tt> around next statement works around some bug that keeps the |
255 | # <tt> around next statement works around some bug that keeps the |
254 | # "font =>" from being used on windows |
256 | # "font =>" from being used on windows |
255 | $MODBOX->set_markup ("<tt>$markup</tt>"); |
257 | $MODBOX->set_markup ("<tt>$markup</tt>"); |
|
|
258 | } |
|
|
259 | |
|
|
260 | sub errorbox { |
|
|
261 | my ($msg) = @_; |
|
|
262 | |
|
|
263 | status $msg; |
|
|
264 | |
|
|
265 | my $dialog = new DC::UI::Toplevel |
|
|
266 | x => "center", |
|
|
267 | y => "center", |
|
|
268 | z => 200, |
|
|
269 | title => "Error", |
|
|
270 | child => my $vbox = new DC::UI::VBox, |
|
|
271 | has_close_button => 1, |
|
|
272 | on_delete => sub { |
|
|
273 | $_[0]->destroy; |
|
|
274 | }, |
|
|
275 | ; |
|
|
276 | |
|
|
277 | add $vbox new DC::UI::Label |
|
|
278 | align => 0.5, |
|
|
279 | ellipsise => 0, |
|
|
280 | text => $msg; |
|
|
281 | |
|
|
282 | add $vbox new DC::UI::Button |
|
|
283 | expand => 1, |
|
|
284 | text => "OK", |
|
|
285 | on_activate => sub { |
|
|
286 | $dialog->destroy; |
|
|
287 | 0 |
|
|
288 | } |
|
|
289 | ; |
|
|
290 | |
|
|
291 | $dialog->show; |
256 | } |
292 | } |
257 | |
293 | |
258 | ############################################################################# |
294 | ############################################################################# |
259 | #TODO: maybe move into own audio module... |
295 | #TODO: maybe move into own audio module... |
260 | |
296 | |
… | |
… | |
689 | ::message { markup => "Server has no newer version." }; |
725 | ::message { markup => "Server has no newer version." }; |
690 | } |
726 | } |
691 | } else { |
727 | } else { |
692 | ::message { markup => "Server does not support software update." }; |
728 | ::message { markup => "Server does not support software update." }; |
693 | } |
729 | } |
694 | |
|
|
695 | # $self->register_face_handler ($exp_table, sub { |
|
|
696 | # my ($face) = @_; |
|
|
697 | |
|
|
698 | # $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
699 | # $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
700 | # }); |
|
|
701 | |
730 | |
702 | () |
731 | () |
703 | }); |
732 | }); |
704 | } |
733 | } |
705 | |
734 | |
… | |
… | |
935 | $vbox->add (@dialog); |
964 | $vbox->add (@dialog); |
936 | $dialog->show; |
965 | $dialog->show; |
937 | } |
966 | } |
938 | |
967 | |
939 | sub dc_connect { |
968 | sub dc_connect { |
940 | my ($host, $port) = @_; |
969 | my ($host, $port, $create) = @_; |
941 | |
970 | |
942 | my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
971 | my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
943 | my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
972 | my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
944 | |
973 | |
945 | $CONN = |
974 | $CONN = |
946 | new DC::Protocol |
975 | new DC::Protocol |
947 | host => $host, |
976 | host => $host, |
948 | port => $port, |
977 | port => $port, |
|
|
978 | create_login => $create, |
949 | user => $PROFILE->{user}, |
979 | user => $PROFILE->{user}, |
950 | pass => $PROFILE->{password}, |
980 | pass => (pack "H*", $PROFILE->{password}), |
951 | mapw => $mapw, |
981 | mapw => $mapw, |
952 | maph => $maph, |
982 | maph => $maph, |
953 | |
983 | |
954 | c_version => { |
984 | c_version => { |
955 | client => "deliantra", |
985 | client => "deliantra", |
… | |
… | |
975 | ota_update_check; |
1005 | ota_update_check; |
976 | |
1006 | |
977 | status "successfully connected to the server"; |
1007 | status "successfully connected to the server"; |
978 | } else { |
1008 | } else { |
979 | undef $CONN; |
1009 | undef $CONN; |
980 | status "unable to connect: $!"; |
1010 | $LOGIN_ERROR->{fg} = [1, 0, 0]; |
|
|
1011 | $LOGIN_ERROR->set_text ("Unable to connect to server: $!"); |
981 | stop_game(); |
1012 | stop_game(); |
982 | } |
1013 | } |
983 | }, |
1014 | }, |
|
|
1015 | |
|
|
1016 | on_addme => sub { |
|
|
1017 | my ($ok, $msg) = @_; |
|
|
1018 | |
|
|
1019 | $LOGIN_ERROR->{fg} = $ok ? [0, 1, 0] : [1, 0, 0]; |
|
|
1020 | $LOGIN_ERROR->set_text ($msg); |
|
|
1021 | }, |
984 | ; |
1022 | ; |
985 | } |
1023 | } |
986 | |
1024 | |
987 | sub start_game { |
1025 | sub start_game($) { |
|
|
1026 | my ($create) = @_; |
|
|
1027 | |
988 | status "logging in..."; |
1028 | status "logging in..."; |
989 | |
1029 | |
990 | my $server = $PROFILE->{host} || $DEFAULT_SERVER; |
1030 | my $server = $PROFILE->{host} || $DEFAULT_SERVER; |
991 | my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" |
1031 | my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" |
992 | or return status "$server: unable to parse server address, try an empty field."; |
1032 | or return status "$server: unable to parse server address, try an empty field."; |
… | |
… | |
1007 | status "dns failure, using hardcoded address"; |
1047 | status "dns failure, using hardcoded address"; |
1008 | $host = "194.126.175.154"; |
1048 | $host = "194.126.175.154"; |
1009 | } |
1049 | } |
1010 | } |
1050 | } |
1011 | |
1051 | |
1012 | dc_connect $host, $port; |
1052 | dc_connect $host, $port, $create; |
1013 | }; |
1053 | }; |
1014 | } else { |
1054 | } else { |
1015 | dc_connect $host, $port; |
1055 | dc_connect $host, $port, $create; |
1016 | } |
1056 | } |
1017 | } |
1057 | } |
1018 | |
1058 | |
1019 | sub stop_game { |
1059 | sub stop_game { |
1020 | crash "stop_game"; |
1060 | crash "stop_game"; |
… | |
… | |
1853 | $vbox->add (new DC::UI::FancyFrame |
1893 | $vbox->add (new DC::UI::FancyFrame |
1854 | label => "Login Settings", |
1894 | label => "Login Settings", |
1855 | child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), |
1895 | child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), |
1856 | ); |
1896 | ); |
1857 | |
1897 | |
|
|
1898 | my $nullpw = "\x00" x 16; |
|
|
1899 | |
1858 | $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username"); |
1900 | $table->add_at (0, 0, new DC::UI::Label align => 1, text => "Username"); |
1859 | $table->add_at (1, 4, new DC::UI::Entry |
1901 | $table->add_at (1, 0, new DC::UI::Entry |
1860 | text => $PROFILE->{user}, |
1902 | text => $PROFILE->{user}, |
1861 | tooltip => "The name of your character on the server. The name is case-sensitive!", |
1903 | tooltip => "The name of your character on the server. The name is case-sensitive!", |
1862 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } |
1904 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } |
1863 | ); |
1905 | ); |
1864 | |
1906 | |
1865 | $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password"); |
1907 | $table->add_at (0, 1, new DC::UI::Label align => 1, text => "Password"); |
1866 | $table->add_at (1, 5, new DC::UI::Entry |
1908 | $table->add_at (1, 1, my $pw1 = new DC::UI::Entry |
1867 | text => $PROFILE->{password}, |
1909 | text => $PROFILE->{password} ? $nullpw : "", |
1868 | hidden => 1, |
1910 | hidden => 1, |
1869 | tooltip => "The password for your character.", |
1911 | tooltip => "The password for your character.", |
1870 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{password} = $value; 1 } |
1912 | on_focus_in => sub { |
|
|
1913 | my ($self) = @_; |
|
|
1914 | $self->set_text ("") |
|
|
1915 | if $self->{text} eq $nullpw; |
|
|
1916 | 0 |
|
|
1917 | }, |
|
|
1918 | on_changed => sub { |
|
|
1919 | my ($self, $value) = @_; |
|
|
1920 | $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $value |
|
|
1921 | if length $value && $value ne $nullpw; |
|
|
1922 | 1 |
|
|
1923 | }, |
1871 | ); |
1924 | ); |
1872 | |
1925 | |
1873 | $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button |
1926 | $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button |
1874 | expand => 1, |
1927 | expand => 1, |
1875 | text => "Login / Register", |
1928 | text => "Login to Existing Account", |
1876 | tooltip => "This button will either login to the account configured above or register a new account.", |
1929 | tooltip => "This button will login to the account given by the <b>Username</b> and <b>Password</b> fields above.", |
1877 | on_activate => sub { |
1930 | on_activate => sub { |
1878 | $CONN ? stop_game |
1931 | $CONN ? stop_game |
1879 | : start_game; |
1932 | : start_game 0; |
1880 | 1 |
1933 | 1 |
1881 | }, |
1934 | }, |
1882 | ); |
1935 | ); |
1883 | |
1936 | |
|
|
1937 | $table->add_at (0, 3, new DC::UI::Label align => 1, text => "Password"); |
|
|
1938 | $table->add_at (1, 3, my $pw2 = new DC::UI::Entry |
|
|
1939 | hidden => 1, |
|
|
1940 | tooltip => "The new password for your character", |
|
|
1941 | ); |
|
|
1942 | |
|
|
1943 | $table->add_at (1, 4, new DC::UI::Button |
|
|
1944 | expand => 1, |
|
|
1945 | text => "Create New Account", |
|
|
1946 | tooltip => "This button will try to create a new account - you need to fill out the <b>Username</b> and the two <b>Password</b> fields above, using the same password for both <b>Password</b> fields.", |
|
|
1947 | on_activate => sub { |
|
|
1948 | if ($pw1->{text} ne $pw2->{text}) { |
|
|
1949 | $LOGIN_ERROR->{fg} = [1, 0, 0]; |
|
|
1950 | $LOGIN_ERROR->set_text ("The passwords do not match - try to enter them again."); |
|
|
1951 | } else { |
|
|
1952 | $CONN or start_game 1; |
|
|
1953 | } |
|
|
1954 | 1 |
|
|
1955 | }, |
|
|
1956 | ); |
|
|
1957 | |
|
|
1958 | $vbox->add (new DC::UI::FancyFrame |
|
|
1959 | label => "Server Message", |
|
|
1960 | tooltip => "The last message, or error, form the server.", |
|
|
1961 | child => ($LOGIN_ERROR = new DC::UI::Label valign => 0, ellipsise => 0), |
|
|
1962 | ); |
|
|
1963 | |
1884 | $vbox->add (new DC::UI::FancyFrame |
1964 | $vbox->add (new DC::UI::FancyFrame |
1885 | label => "How to Play", |
1965 | label => "How to Play", |
1886 | min_h => 240, |
1966 | min_h => 240,#d# should not be necessary - widget bug |
1887 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1967 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1888 | markup => |
1968 | markup => |
1889 | "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" |
1969 | "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" |
1890 | . "Then register a new account (or use an existing one if you have one). " |
1970 | . "Then create a new account (or use an existing one if you have one).\n\n" |
1891 | . "To register an account, choose a username that hasn't been taken yet (just guess) and " |
1971 | . "To create an account, choose a username that hasn't been taken yet (just guess) and " |
1892 | . "try to log-in. Follow the instructions in the Log tab in the message window.", |
1972 | . "fill out the top two <b>Password</b> fields using the same password, then press <b>Create New Account</b>.", |
1893 | ), |
1973 | ), |
1894 | ); |
1974 | ); |
1895 | |
1975 | |
1896 | $vbox |
1976 | $vbox |
1897 | } |
1977 | } |
… | |
… | |
2661 | DC::set_theme $CFG->{uitheme}; |
2741 | DC::set_theme $CFG->{uitheme}; |
2662 | |
2742 | |
2663 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2743 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2664 | $SDL_REINIT = 0; |
2744 | $SDL_REINIT = 0; |
2665 | |
2745 | |
2666 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2746 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2; |
2667 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2747 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2668 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2748 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2669 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2749 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2670 | |
2750 | |
2671 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
2751 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
… | |
… | |
3000 | |
3080 | |
3001 | $CFG->{profile}{$profile} ||= {}; |
3081 | $CFG->{profile}{$profile} ||= {}; |
3002 | $PROFILE = $CFG->{profile}{$profile}; |
3082 | $PROFILE = $CFG->{profile}{$profile}; |
3003 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
3083 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
3004 | |
3084 | |
3005 | $PROFILE->{host} = $args[0] if @args > 0; |
3085 | $PROFILE->{host} = $args[0] if @args > 0; |
3006 | $PROFILE->{user} = $args[1] if @args > 1; |
3086 | $PROFILE->{user} = $args[1] if @args > 1; |
3007 | $PROFILE->{password} = $args[2] if @args > 2; |
3087 | $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $args[2] if @args > 2; |
3008 | |
3088 | |
3009 | # convert old bindings (only default profile matters) |
3089 | # convert old bindings (only default profile matters) |
3010 | if (my $bindings = delete $PROFILE->{bindings}) { |
3090 | if (my $bindings = delete $PROFILE->{bindings}) { |
3011 | while (my ($mod, $syms) = each %$bindings) { |
3091 | while (my ($mod, $syms) = each %$bindings) { |
3012 | while (my ($sym, $cmds) = each %$syms) { |
3092 | while (my ($sym, $cmds) = each %$syms) { |