ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/login.ext
(Generate patch)

Comparing deliantra/server/ext/login.ext (file contents):
Revision 1.115 by root, Sun Jan 23 23:37:55 2011 UTC vs.
Revision 1.120 by root, Thu Nov 15 06:00:16 2012 UTC

2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
7use Deliantra::Util ();
7 8
8our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600; 9CONF MAX_DISCONNECT_TIME = 3600;
9
10# paranoia function to overwrite a string-in-place
11sub nuke_str {
12 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
13}
14 10
15sub query { 11sub query {
16 my ($ns, $flags, $text) = @_; 12 my ($ns, $flags, $text) = @_;
17 13
18 $ns->query ($flags, $text, Coro::rouse_cb); 14 $ns->query ($flags, $text, Coro::rouse_cb);
60 or return; 56 or return;
61 my $x = $ob->x; 57 my $x = $ob->x;
62 my $y = $ob->y; 58 my $y = $ob->y;
63 59
64 # never happens normally, but helps when shell users make mistakes 60 # never happens normally, but helps when shell users make mistakes
65 $m->in_memory == cf::MAP_ACTIVE 61 $m->linkable
66 or return 1; 62 or return 1;
67 63
68# return 0;#d# 64# return 0;#d#
69# warn join ":", $m->at ($x, $y);#d# 65# warn join ":", $m->at ($x, $y);#d#
70# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; 66# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n";
131 127
132 $ob->goto ($map, $x, $y); 128 $ob->goto ($map, $x, $y);
133} 129}
134 130
135sub encode_password($) { 131sub encode_password($) {
136# crypt $_[0],
137# join '',
138# ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]
139 "!" . unpack "H*", $_[0] 132 "!" . unpack "H*", $_[0]
140} 133}
141 134
142sub compare_password($$) { 135sub compare_password($$) {
143 my ($pass, $token) = @_; 136 my ($pass, $token) = @_;
144 137
145 if ($token =~ /\!(.*)/) { 138 if ($token =~ /!!(.*)/) {
139 return +(substr $pass, 0, 8) eq pack "H*", $1;
140 } elsif ($token =~ /!(.*)/) {
146 return $pass eq pack "H*", $1; 141 return $pass eq pack "H*", $1;
147 } else { 142 } else {
148 return $token eq crypt $pass, $token; 143 return $token eq crypt $pass, $token;
149 } 144 }
150} 145}
156 my $lock = cf::lock_acquire "ext::login::nuke_playerdir"; 151 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
157 152
158 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 153 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
159 aio_rename "$PLAYERDIR/$user", $temp; 154 aio_rename "$PLAYERDIR/$user", $temp;
160 IO::AIO::aio_rmtree $temp; 155 IO::AIO::aio_rmtree $temp;
156}
157
158sub login_done {
159 my ($pl) = @_;
160
161 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) {
162 $pl->ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR);
163 }
164}
165
166sub chargen {
167 my ($ns, $user, $pass) = @_;
168
169 # the rest of this function is character creation
170 $Coro::current->{desc} = "addme($user) chargen";
171
172 # just to make sure nothing is left over
173 # normally, nothing is there.
174 nuke_playerdir $user;
175
176 my $pl = cf::player::new $user;
177 $pl->password (encode_password $pass);
178 $pl->connect ($ns);
179 my $ob = $pl->ob;
180
181 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
182
183 while () {
184 $ob->update_stats;
185 $pl->save_stats;
186
187 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
188 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)?";
189
190 if ($res =~ /^[Nn]/) {
191 last;
192 } elsif ($res > 0 && $res <= 7) {
193 my $swap = query $ns, cf::CS_QUERY_SINGLECHAR, "Swap stat with (will not roll new stats) [1-7]?";
194
195 if ($swap > 0 && $swap <= 7) {
196 $ob->swap_stats ($res - 1, $swap - 1);
197 }
198 } else {
199 $ob->roll_stats;
200 }
201
202 Coro::Timer::sleep 0.05;
203 }
204
205 $ob->set_animation (2);
206 $ob->add_statbonus;
207
208 while () {
209 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
210 my $msg = $ob->msg;
211 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
212 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
213
214 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
215 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
216
217 last if $res =~ /[dD]/;
218
219 $pl->chargen_race_next;
220 Coro::Timer::sleep 0.05;
221 }
222
223 # create the playerdir, if necessary, as chargen_race_done did it before
224 # presumably because of unique maps
225 aio_mkdir playerdir $pl, 0770;
226 $pl->chargen_race_done;
227
228 while () {
229 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
230 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
231
232 if ($res =~ /^[fF]/) {
233 $pl->gender (1);
234 last;
235 } elsif ($res =~ /^[mM]/) {
236 $pl->gender (0);
237 last;
238 }
239 Coro::Timer::sleep 0.05;
240 }
241
242 $ob->reply (undef, "Welcome to Deliantra!");
243
244 # XXX: Workaround for delayed client ext protocol handshake
245 $pl->esrv_new_player;
246
247 delete $pl->{deny_save};
161} 248}
162 249
163cf::client->attach (on_addme => sub { 250cf::client->attach (on_addme => sub {
164 my ($ns) = @_; 251 my ($ns) = @_;
165 252
246 aio_stat $pl->path and next; 333 aio_stat $pl->path and next;
247 my $mtime = (stat _)[9]; 334 my $mtime = (stat _)[9];
248 my $token = $pl->password; 335 my $token = $pl->password;
249 336
250 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { 337 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) {
338 # player exists and passwords match - we can proceed
339
251 $pl->password (encode_password $pass); # make sure we store the new encoding #d# 340 $pl->password (encode_password $pass); # make sure we store the new encoding #d#
252 nuke_str $pass;
253 # password matches, wonderful 341 # password matches, wonderful
254 my $pl = cf::player::find $user or next; 342 my $pl = cf::player::find $user or next;
255 $pl->connect ($ns); 343 $pl->connect ($ns);
256 enter_map $pl; 344 enter_map $pl;
345 login_done $pl;
257 last; 346 return;
258 } elsif (can_cleanup $pl, $mtime) { 347 } elsif (can_cleanup $pl, $mtime) {
259 Coro::Timer::sleep 1; 348 Coro::Timer::sleep 1;
260 349
261 $ns->send_drawinfo ( 350 $ns->send_drawinfo (
262 "Player exists, but password does not match. If this is your account, " 351 "Player exists, but password does not match. If this is your account, "
263 . "please try again. If not, you can now decide to take over this account " 352 . "please try again. If not, you can now decide to take over this account "
264 . "because it has not been in-use for some time.", 353 . "because it has not been in-use for some time.",
265 cf::NDI_RED 354 cf::NDI_RED
266 ); 355 );
267 356
268 #TODO: nuke_str
269 (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ 357 (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/
270 or next; 358 or next;
271 359
272 # check if the file hasn't changed 360 # check if the file hasn't changed
273 aio_stat cf::player::path $user and next; 361 aio_stat cf::player::path $user and next;
275 363
276 $pl->quit_character; 364 $pl->quit_character;
277 365
278 # fall through to creation 366 # fall through to creation
279 } else { 367 } else {
280 nuke_str $pass;
281
282 Coro::Timer::sleep 1; 368 Coro::Timer::sleep 1;
283 369
284 $ns->send_drawinfo ( 370 $ns->send_drawinfo (
285 "Wrong username or password. Please try again " 371 "Wrong username or password. Please try again "
286 . "(check for Numlock and other semi-obvious error sources).", 372 . "(check for Numlock and other semi-obvious error sources).",
301 ); 387 );
302 next; 388 next;
303 } 389 }
304 } 390 }
305 391
306 # the rest of this function is character creation
307 $Coro::current->{desc} = "addme($user) chargen";
308
309 # just to make sure nothing is left over
310 # normally, nothing is there.
311 nuke_playerdir $user;
312
313 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 392 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
314 393
315 if ($pass2 ne $pass) { 394 if ($pass2 ne $pass) {
316 nuke_str $pass;
317 nuke_str $pass2;
318 $ns->send_drawinfo ( 395 $ns->send_drawinfo (
319 "The passwords do not match, please try again.", 396 "The passwords do not match, please try again.",
320 cf::NDI_RED 397 cf::NDI_RED
321 ); 398 );
322 Coro::Timer::sleep 0.5; 399 Coro::Timer::sleep 0.5;
323 next; 400 next;
324 } 401 }
325 402
326 nuke_str $pass2;
327
328 my $pl = cf::player::new $user;
329 $pl->password (encode_password $pass);
330 nuke_str $pass;
331 $pl->connect ($ns);
332 my $ob = $pl->ob;
333
334 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
335
336 while () {
337 $ob->update_stats;
338 $pl->save_stats;
339
340 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
341 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)?";
342
343 if ($res =~ /^[Nn]/) {
344 last;
345 } elsif ($res > 0 && $res <= 7) {
346 my $swap = query $ns, cf::CS_QUERY_SINGLECHAR, "Swap stat with (will not roll new stats) [1-7]?";
347
348 if ($swap > 0 && $swap <= 7) {
349 $ob->swap_stats ($res - 1, $swap - 1);
350 }
351 } else {
352 $ob->roll_stats;
353 }
354
355 Coro::Timer::sleep 0.05;
356 }
357
358 $ob->set_animation (2);
359 $ob->add_statbonus;
360
361 while () {
362 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
363 my $msg = $ob->msg;
364 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
365 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
366
367 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
368 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
369
370 last if $res =~ /[dD]/;
371
372 $pl->chargen_race_next;
373 Coro::Timer::sleep 0.05;
374 }
375
376 # create the playerdir, if necessary, as chargen_race_done did it before
377 # presumably because of unique maps
378 aio_mkdir playerdir $pl, 0770;
379 $pl->chargen_race_done;
380
381 while () {
382 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
383 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
384
385 if ($res =~ /^[fF]/) {
386 $pl->gender (1);
387 last;
388 } elsif ($res =~ /^[mM]/) {
389 $pl->gender (0);
390 last;
391 }
392 Coro::Timer::sleep 0.05;
393 }
394
395 $ob->reply (undef, "Welcome to Deliantra!");
396
397 # XXX: Workaround for delayed client ext protocol handshake
398 $pl->esrv_new_player;
399
400 delete $pl->{deny_save};
401
402 last; 403 last;
403 } 404 }
404 405
405 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { 406 # lock again, too layz to make this nicer
406 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); 407 local $cf::LOGIN_LOCK{$user} = 1;
407 } 408
409 chargen $ns, $user, $pass;
410 login_done $ns->pl;
408 }); 411 });
409}); 412});
410 413
411cf::register_command password => sub { 414cf::register_command password => sub {
412 my ($pl, $arg) = @_; 415 my ($pl, $arg) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines