--- deliantra/Deliantra-Client/DC/Main.pm 2012/01/18 15:31:51 1.18
+++ deliantra/Deliantra-Client/DC/Main.pm 2017/01/29 00:11:23 1.30
@@ -27,6 +27,7 @@
use List::Util qw(max min);
use Deliantra;
+use Deliantra::Util;
use Deliantra::Protocol::Constants;
use AnyEvent::Util ();
@@ -35,6 +36,7 @@
use Compress::LZF;
use JSON::XS;
+use Urlader;
use DC;
@@ -46,7 +48,7 @@
$SIG{__DIE__} = sub {
return if $^S; # quick reject
- # return if there are any eval contexts in the csall stack
+ # return if there are any eval contexts in the call stack
for my $i (0..999) {
my ($sub, $is_require) = (caller $i)[3, 7]
or last;
@@ -129,6 +131,7 @@
our $BUTTONBAR; # the menu buttons
our $METASERVER;
our $LOGIN_BUTTON;
+our $LOGIN_ERROR;
our $QUIT_DIALOG;
our $HOST_ENTRY;
our $FULLSCREEN_ENABLE;
@@ -254,6 +257,40 @@
$MODBOX->set_markup ("$markup");
}
+sub errorbox {
+ my ($msg) = @_;
+
+ status $msg;
+
+ my $dialog = new DC::UI::Toplevel
+ x => "center",
+ y => "center",
+ z => 200,
+ title => "Error",
+ child => my $vbox = new DC::UI::VBox,
+ has_close_button => 1,
+ on_delete => sub {
+ $_[0]->destroy;
+ },
+ ;
+
+ add $vbox new DC::UI::Label
+ align => 0.5,
+ ellipsise => 0,
+ text => $msg;
+
+ add $vbox new DC::UI::Button
+ expand => 1,
+ text => "OK",
+ on_activate => sub {
+ $dialog->destroy;
+ 0
+ }
+ ;
+
+ $dialog->show;
+}
+
#############################################################################
#TODO: maybe move into own audio module...
@@ -476,7 +513,7 @@
sub audio_init {
if ($CFG->{audio_enable}) {
- DC::Audio::init $CFG->{audio_driver};
+ DC::Audio::init;
if ($SDL_MIXER) {
audio_music_finished;
@@ -691,13 +728,6 @@
::message { markup => "Server does not support software update." };
}
-# $self->register_face_handler ($exp_table, sub {
-# my ($face) = @_;
-
-# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
-# $_->() for values %{ $self->{on_exp_update} || {} };
-# });
-
()
});
}
@@ -936,17 +966,18 @@
}
sub dc_connect {
- my ($host, $port) = @_;
+ my ($host, $port, $create) = @_;
my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32;
my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
- $CONN =
+ $CONN =
new DC::Protocol
host => $host,
port => $port,
+ create_login => $create,
user => $PROFILE->{user},
- pass => $PROFILE->{password},
+ pass => (pack "H*", $PROFILE->{password}),
mapw => $mapw,
maph => $maph,
@@ -976,14 +1007,24 @@
status "successfully connected to the server";
} else {
undef $CONN;
- status "unable to connect: $!";
+ $LOGIN_ERROR->{fg} = [1, 0, 0];
+ $LOGIN_ERROR->set_text ("Unable to connect to server: $!");
stop_game();
}
},
+
+ on_addme => sub {
+ my ($ok, $msg) = @_;
+
+ $LOGIN_ERROR->{fg} = $ok ? [0, 1, 0] : [1, 0, 0];
+ $LOGIN_ERROR->set_text ($msg);
+ },
;
}
-sub start_game {
+sub start_game($) {
+ my ($create) = @_;
+
status "logging in...";
my $server = $PROFILE->{host} || $DEFAULT_SERVER;
@@ -1008,10 +1049,10 @@
}
}
- dc_connect $host, $port;
+ dc_connect $host, $port, $create;
};
} else {
- dc_connect $host, $port;
+ dc_connect $host, $port, $create;
}
}
@@ -1139,7 +1180,7 @@
state => $CFG->{texture_compression},
tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
. "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). "
- . "The compression algorithm can differ form card to card, so your mileage may vary. This setting is ignored in "
+ . "The compression algorithm can differ from card to card, so your mileage may vary. This setting is ignored in "
. "forced OpenGL 1.1 mode and when using the Apple renderer.",
on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
);
@@ -1501,7 +1542,7 @@
if ($DELIANTRA_DEBUG & 16) {
$BW_WATCHER = EV::periodic 0, 1, 0, sub {
return unless $CONN;
- debug sprintf "%8.2gKB/s", $CONN->{octets_in} / 1e3;
+ debug sprintf "%8.2gkB/s", $CONN->{octets_in} / 1e3;
$CONN->{octets_in} = 0;
};
} else {
@@ -1854,41 +1895,81 @@
child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]),
);
- $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username");
- $table->add_at (1, 4, new DC::UI::Entry
+ my $nullpw = "\x00" x 16;
+
+ $table->add_at (0, 0, new DC::UI::Label align => 1, text => "Username");
+ $table->add_at (1, 0, new DC::UI::Entry
text => $PROFILE->{user},
tooltip => "The name of your character on the server. The name is case-sensitive!",
on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 }
);
- $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password");
- $table->add_at (1, 5, new DC::UI::Entry
- text => $PROFILE->{password},
+ $table->add_at (0, 1, new DC::UI::Label align => 1, text => "Password");
+ $table->add_at (1, 1, my $pw1 = new DC::UI::Entry
+ text => $PROFILE->{password} ? $nullpw : "",
hidden => 1,
tooltip => "The password for your character.",
- on_changed => sub { my ($self, $value) = @_; $PROFILE->{password} = $value; 1 }
+ on_focus_in => sub {
+ my ($self) = @_;
+ $self->set_text ("")
+ if $self->{text} eq $nullpw;
+ 0
+ },
+ on_changed => sub {
+ my ($self, $value) = @_;
+ $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $value
+ if length $value && $value ne $nullpw;
+ 1
+ },
);
- $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button
+ $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button
expand => 1,
- text => "Login / Register",
- tooltip => "This button will either login to the account configured above or register a new account.",
+ text => "Login to Existing Account",
+ tooltip => "This button will login to the account given by the Username and Password fields above.",
on_activate => sub {
$CONN ? stop_game
- : start_game;
+ : start_game 0;
1
},
);
+ $table->add_at (0, 3, new DC::UI::Label align => 1, text => "Password");
+ $table->add_at (1, 3, my $pw2 = new DC::UI::Entry
+ hidden => 1,
+ tooltip => "The new password for your character",
+ );
+
+ $table->add_at (1, 4, new DC::UI::Button
+ expand => 1,
+ text => "Create New Account",
+ tooltip => "This button will try to create a new account - you need to fill out the Username and the two Password fields above, using the same password for both Password fields.",
+ on_activate => sub {
+ if ($pw1->{text} ne $pw2->{text}) {
+ $LOGIN_ERROR->{fg} = [1, 0, 0];
+ $LOGIN_ERROR->set_text ("The passwords do not match - try to enter them again.");
+ } else {
+ $CONN or start_game 1;
+ }
+ 1
+ },
+ );
+
+ $vbox->add (new DC::UI::FancyFrame
+ label => "Server Message",
+ tooltip => "The last message, or error, from the server.",
+ child => ($LOGIN_ERROR = new DC::UI::Label valign => 0, ellipsise => 0),
+ );
+
$vbox->add (new DC::UI::FancyFrame
label => "How to Play",
- min_h => 240,
+ min_h => 240,#d# should not be necessary - widget bug
child => (new DC::UI::Label valign => 0, ellipsise => 0,
markup =>
"First select a suitable video resolution in the Graphics tab, above.\n\n"
- . "Then register a new account (or use an existing one if you have one). "
- . "To register an account, choose a username that hasn't been taken yet (just guess) and "
- . "try to log-in. Follow the instructions in the Log tab in the message window.",
+ . "Then create a new account (or use an existing one if you have one).\n\n"
+ . "To create an account, choose a username that hasn't been taken yet (just guess) and "
+ . "fill out the top two Password fields using the same password, then press Create New Account.",
),
);
@@ -1949,7 +2030,7 @@
text => $CFG->{output_rate},
tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
. "when sending data. When 0 or unset, the server "
- . "default will be used, which is usually around 100kb/s. Most servers will "
+ . "default will be used, which is usually around 100kB/s. Most servers will "
. "dynamically find an optimal rate, so adjust this only when necessary.",
on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
);
@@ -2516,8 +2597,8 @@
$MENUPOPUP = DC::UI::Menu->new (items => [
["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }],
["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }],
- ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }],
- ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }],
+ ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }],
+ ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }],
["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }],
["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }],
["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }],
@@ -2525,7 +2606,7 @@
if ($CONN) {
open_quit_dialog;
} else {
- EV::unloop EV::UNLOOP_ALL;
+ EV::break EV::BREAK_ALL;
}
}],
]);
@@ -2662,7 +2743,7 @@
DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
$SDL_REINIT = 0;
- @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8;
+ @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
@SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
@SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
@SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
@@ -2906,7 +2987,7 @@
$SDL_CB[DC::SDL_QUIT] = sub {
crash "SDL_QUIT";
- EV::unloop EV::UNLOOP_ALL;
+ EV::break EV::BREAK_ALL;
};
$SDL_CB[DC::SDL_VIDEORESIZE] = sub { };
$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub {
@@ -2949,7 +3030,7 @@
#############################################################################
$SIG{INT} = $SIG{TERM} = sub {
- EV::unloop;
+ EV::break;
#d# TODO calling exit here hangs the process in some futex
};
@@ -3001,9 +3082,9 @@
$PROFILE = $CFG->{profile}{$profile};
$PROFILE->{host} ||= "gameserver.deliantra.net";
- $PROFILE->{host} = $args[0] if @args > 0;
- $PROFILE->{user} = $args[1] if @args > 1;
- $PROFILE->{password} = $args[2] if @args > 2;
+ $PROFILE->{host} = $args[0] if @args > 0;
+ $PROFILE->{user} = $args[1] if @args > 1;
+ $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $args[2] if @args > 2;
# convert old bindings (only default profile matters)
if (my $bindings = delete $PROFILE->{bindings}) {
@@ -3076,7 +3157,7 @@
debug_toggle 0;
delete $SIG{__DIE__};
- EV::loop;
+ EV::run;
DC::save_cfg if $CFG->{config_autosave};