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.118 by root, Thu Nov 8 00:16:07 2012 UTC vs.
Revision 1.119 by root, Thu Nov 15 05:54:02 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines