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.27 by root, Mon Jan 22 03:44:41 2007 UTC vs.
Revision 1.62 by root, Sat Jul 14 14:33:29 2007 UTC

1#! perl # MANDATORY 1#! perl # mandatory
2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
7
8my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir;
9 7
10# paranoia function to overwrite a string-in-place 8# paranoia function to overwrite a string-in-place
11sub nuke_str { 9sub nuke_str {
12 substr $_[0], 0, (length $_[0]), "x" x length $_[0] 10 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
13} 11}
14 12
15sub query { 13sub query {
16 my ($ns, $flags, $text) = @_; 14 my ($ns, $flags, $text) = @_;
17 15
18 my $current = $Coro::current; 16 my $current = $Coro::current;
19 $ns->query ($flags, $text, sub { $current->ready; $current = $_[0]; }); 17 $ns->query ($flags, $text, sub { $current->ready; $current = $_[0] });
20 Coro::schedule while ref $current; 18 Coro::schedule while ref $current;
21 19
22 $current 20 $current
23} 21}
24 22
40 return unless cf::player::find_active $user; 38 return unless cf::player::find_active $user;
41 39
42 $ns->send_drawinfo ( 40 $ns->send_drawinfo (
43 "That player is already logged in on this server. " 41 "That player is already logged in on this server. "
44 . "If you want to create a new player, choose another name. " 42 . "If you want to create a new player, choose another name. "
45 . "If you are already a registered player, make sure nobody " 43 . "If you have already a registered, make sure nobody "
46 . "else is using your account at this time. If you lost your conenction " 44 . "else is using your account at this time. If you lost your connection "
47 . "then the server will likely timeout within a minute. If you still " 45 . "then the server will likely timeout within a minute. If you still "
48 . "cannot log-in after a minute, you are still logged in. Make sure " 46 . "cannot log-in after a minute, you are still logged in. Make sure "
49 . "you do not have another client running. If you use windows, reboot, " 47 . "you do not have another client running. If you use windows, reboot, "
50 . "this will fix anything.", 48 . "this will fix anything.",
51 cf::NDI_RED 49 cf::NDI_RED
52 ); 50 );
53 51
54 1 52 1
55} 53}
56 54
57sub check_clean_save { 55sub enter_map {
58 my ($pl) = @_; 56 my ($pl) = @_;
59 57
58 my $ob = $pl->ob;
59
60 my ($map, $x, $y)
61 = $ob->{_link_pos}
62 ? @{delete $ob->{_link_pos}}
63 : ($pl->maplevel, $ob->x, $ob->y);
64
65 $ob->enter_link;
66
60 if (my $time = delete $pl->{unclean_save}) { 67 if (my $time = delete $pl->{unclean_save}) {
68 if (my $m = cf::map::find $map) {
69 if ($time < $m->{instantiate_time} || 1) {#d#
70 # the map was reset in the meantime
71 my $age = $cf::RUNTIME - $time;
72 warn $ob->name, " map reset after logout, logout age $age\n";#d#
73
74 # for now, just go back to savebed
75 ($map, $x, $y) = $pl->savebed;
76
61 $pl->ns->send_drawinfo ( 77 $pl->ns->send_drawinfo (
78 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
79 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
80 . "Better use a savebed next time, much worse things could have happened...",
81 cf::NDI_RED
82 );
83 } else {
84 $pl->ns->send_drawinfo (
62 "You didn't use a savebed to leave this realm. This is very dangerous, " 85 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
63 . "as lots of things could happen when you leave by other means, such as cave-ins, " 86 . "as lots of things could happen when you leave by other means, such as cave-ins, "
64 . "or monsters suddenly snapping your body. Better use a savebed next time.", 87 . "or monsters suddenly snapping your body. Better use a savebed next time.",
65 cf::NDI_RED 88 cf::NDI_RED
89 );
90 }
66 ); 91 }
67 #d#TODO
68 } 92 }
93
94 $ob->goto ($map, $x, $y);
69} 95}
70 96
71# delete a player directory, be non-blocking AND synchronous... 97# delete a player directory, be non-blocking AND synchronous...
72# (thats hard, so we crap out and fork). 98# (thats hard, so we crap out and fork).
73sub nuke_playerdir { 99sub nuke_playerdir {
77 system "cd \Q$PLAYERDIR\E " 103 system "cd \Q$PLAYERDIR\E "
78 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 104 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null "
79 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 105 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)";
80} 106}
81 107
82sub addme { 108cf::client->attach (on_addme => sub {
83 my ($ns) = @_; 109 my ($ns) = @_;
84 110
85 $ns->destroy if $ns->pl; 111 if (!$ns->facecache)
112 {
113 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
114
115
116***
117*** WARNING:
118*** Your client does not support face/image caching,
119*** or it has been disabled. Face caching is mandatory
120*** so please enable it or use a newer client.
121***
122*** Look at your client preferences:
123***
124*** CFPlus: all known versions automatically enable the facecache.
125*** cfclient: use the -cache commandline option.
126*** cfclient: map will not redraw automatically (bug).
127*** gcfclient: use -cache commandline option, or enable
128*** gcfclient: Client=>Configure=>Map & Image=>Cache Images.
129*** jcrossclient: your client is broken, use CFPlus or gcfclient.
130***
131***
132EOF
133 if ($ns->version =~ /jcrossclient/) {
134 # let them, for now
135 } else {
136 $ns->flush;
137 return $ns->destroy;
138 }
139
140 # $ns->facecache = true;
141 }
142
143 if ($ns->mapmode < cf::Map1aCmd) {
144 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
145
146
147***
148*** WARNING:
149*** Your client is too old. Please upgrade to a newer version.
150EOF
151
152 $ns->flush;
153 return $ns->destroy;
154 }
155
156 $ns->pl and return $ns->destroy;
86 157
87 $ns->async (sub { 158 $ns->async (sub {
88 my ($user, $pass); 159 my ($user, $pass);
89 160
90 $ns->send_packet ("addme_success"); 161 $ns->send_packet ("addme_success");
105 $ns->send_drawinfo ( 176 $ns->send_drawinfo (
106 "That username is currently used in another login session. " 177 "That username is currently used in another login session. "
107 . "Chose another, or wait till the other session has ended.", 178 . "Chose another, or wait till the other session has ended.",
108 cf::NDI_RED 179 cf::NDI_RED
109 ); 180 );
110 } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}$/) { 181 } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) {
111 last; 182 last;
112 } else { 183 } else {
113 $ns->send_drawinfo ( 184 $ns->send_drawinfo (
114 "Your username contains illegal characters " 185 "Your username contains illegal characters "
115 . "(only a-z, A-Z and 0-9 are allowed), " 186 . "(only a-z, A-Z and 0-9 are allowed), "
116 . "or is not between 3 and 18 characters in length.", 187 . "or is not between 3 and 18 characters in length.",
117 cf::NDI_RED 188 cf::NDI_RED
118 ); 189 );
119 } 190 }
191 Coro::Timer::sleep 0.4;
120 } 192 }
121 193
122 check_playing $ns, $user and next; 194 check_playing $ns, $user and next;
123 195
124 $ns->send_drawinfo ( 196 $ns->send_drawinfo (
135 $ns->send_drawinfo ( 207 $ns->send_drawinfo (
136 "Try to use at least three characters as your password please, " 208 "Try to use at least three characters as your password please, "
137 . "that cannot be too much to ask for :)", 209 . "that cannot be too much to ask for :)",
138 cf::NDI_RED 210 cf::NDI_RED
139 ); 211 );
212 Coro::Timer::sleep 0.4;
140 } 213 }
141 214
142 # lock this username for the remainder of this login session 215 # lock this username for the remainder of this login session
143 if ($cf::LOGIN_LOCK{$user}) { 216 if ($cf::LOGIN_LOCK{$user}) {
144 $ns->send_drawinfo ( 217 $ns->send_drawinfo (
161 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { 234 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) {
162 nuke_str $pass; 235 nuke_str $pass;
163 # password matches, wonderful 236 # password matches, wonderful
164 my $pl = cf::player::find $user or next; 237 my $pl = cf::player::find $user or next;
165 $pl->connect ($ns); 238 $pl->connect ($ns);
166 check_clean_save $pl; 239 enter_map $pl;
167 last; 240 last;
168 } elsif (can_cleanup $pl, $mtime) { 241 } elsif (can_cleanup $pl, $mtime) {
169 Coro::Timer::sleep 1; 242 Coro::Timer::sleep 1;
170 243
171 $ns->send_drawinfo ( 244 $ns->send_drawinfo (
196 . "(check for Numlock and other semi-obvious error sources).", 269 . "(check for Numlock and other semi-obvious error sources).",
197 cf::NDI_RED 270 cf::NDI_RED
198 ); 271 );
199 next; 272 next;
200 } 273 }
274 } else {
275 # unable to load the playerfile:
276 # check wether the player dir exists, which means the file is corrupted or
277 # something very similar.
278 if (!aio_stat cf::player::playerdir $user) {
279 $ns->send_drawinfo (
280 "Unable to retrieve this player. It might be a locked or broken account. "
281 . "If this is your account, ask a dungeon master for assistance. "
282 . "Otherwise choose a different login name.",
283 cf::NDI_RED
284 );
285 next;
286 }
201 } 287 }
202 288
203 # the rest of this function is character creation 289 # the rest of this function is character creation
204 290
205 # just to make sure nothing is left over 291 # just to make sure nothing is left over
212 nuke_str $pass2; 298 nuke_str $pass2;
213 $ns->send_drawinfo ( 299 $ns->send_drawinfo (
214 "The passwords do not match, please try again.", 300 "The passwords do not match, please try again.",
215 cf::NDI_RED 301 cf::NDI_RED
216 ); 302 );
303 Coro::Timer::sleep 0.5;
217 next; 304 next;
218 } 305 }
219 306
220 nuke_str $pass2; 307 nuke_str $pass2;
221 308
222 my $pl = cf::player::new $user; 309 my $pl = cf::player::new $user;
223 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); 310 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]);
224 nuke_str $pass; 311 nuke_str $pass;
225 $pl->connect ($ns); 312 $pl->connect ($ns);
226
227 my $ob = $pl->ob; 313 my $ob = $pl->ob;
314
315 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
228 316
229 while () { 317 while () {
230 $ob->update_stats; 318 $ob->update_stats;
231 $pl->save_stats; 319 $pl->save_stats;
232 320
242 $ob->swap_stats ($res - 1, $swap - 1); 330 $ob->swap_stats ($res - 1, $swap - 1);
243 } 331 }
244 } else { 332 } else {
245 $ob->roll_stats; 333 $ob->roll_stats;
246 } 334 }
335
336 Coro::Timer::sleep 0.2;
247 } 337 }
248 338
249 $ob->set_animation (2); 339 $ob->set_animation (2);
250 $ob->add_statbonus; 340 $ob->add_statbonus;
251 341
252 $ns->send_drawinfo ($ob->msg, cf::NDI_BLUE); 342 while () {
253 $ns->send_packet (sprintf "query %d %s", cf::CS_QUERY_SINGLECHAR, 343 $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title);
344 my $msg = $ob->msg;
345 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
346 $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg);
347
348 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
254 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 349 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
255 350
256 $ns->state (cf::ST_CHANGE_CLASS); 351 last if $res =~ /[dD]/;
352
353 $pl->chargen_race_next;
354 Coro::Timer::sleep 0.2;
355 }
356
357 $pl->chargen_race_done;
358
359 while () {
360 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
361 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
362
363 if ($res =~ /^[fF]/) {
364 $pl->gender (1);
365 last;
366 } elsif ($res =~ /^[mM]/) {
367 $pl->gender (0);
368 last;
369 }
370 Coro::Timer::sleep 0.2;
371 }
372
373 $ob->reply (undef, "Welcome to Crossfire!");
374
257 delete $pl->{deny_save};#d# too early 375 delete $pl->{deny_save};
258 376
259 last; 377 last;
260 } 378 }
261 }); 379 });
262} 380});
263 381
264cf::register_command quit => sub { 382cf::register_command quit => sub {
265 my ($ob, $arg) = @_; 383 my ($ob, $arg) = @_;
266 384
267 $ob->reply (undef, 385 $ob->reply (undef,
283 } else { 401 } else {
284 $ob->reply (undef, 402 $ob->reply (undef,
285 "Ok, quitting, hope to see you again.", 403 "Ok, quitting, hope to see you again.",
286 cf::NDI_UNIQUE | cf::NDI_RED); 404 cf::NDI_UNIQUE | cf::NDI_RED);
287 $pl->ns->flush; 405 $pl->ns->flush;
288 $pl->quit_character; 406 cf::async { $pl->quit_character };
289 } 407 }
290 }); 408 });
291}; 409};
292 410
293cf::object->attach ( 411cf::object->attach (
336 } else { 454 } else {
337 $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; 455 $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list;
338 $pl->{unclean_save} = $cf::RUNTIME; 456 $pl->{unclean_save} = $cf::RUNTIME;
339 } 457 }
340 }, 458 },
341);
342
343cf::client->attach (
344 on_addme => \&addme,
345); 459);
346 460
347############################################################################# 461#############################################################################
348 462
349our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 463our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs
364 or next; 478 or next;
365 $pl->valid or next; 479 $pl->valid or next;
366 480
367 eval { 481 eval {
368 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 482 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
369 $cf::WAIT_FOR_TICK_ONE->wait; 483 cf::wait_for_tick_begin;
370 $pl->save; 484 $pl->save;
371 485
372 unless ($pl->active) { 486 unless ($pl->active || $pl->ns) {
373 # check refcounts, this is tricky and needs to be adjusted to fit server internals 487 # check refcounts, this is tricky and needs to be adjusted to fit server internals
374 my $ob = $pl->ob; 488 my $ob = $pl->ob;
375 Scalar::Util::weaken $pl; 489
376 Scalar::Util::weaken $ob;
377 my $a_ = $pl->refcnt;#d#
378 my $b_ = $ob->refcnt;#d#
379 my $pl_ref = $pl->refcnt_cnt; 490 my $pl_ref = $pl->refcnt_cnt;
380 my $ob_ref = $ob->refcnt_cnt; 491 my $ob_ref = $ob->refcnt_cnt;
381 492
382 ## pl_ref == one from object + one from cf::PLAYER 493 ## pl_ref == $pl + ob->contr + %cf::PLAYER
383 ## ob_ref == one from simply being an object 494 ## ob_ref == $ob + pl->observe + simply being an object
384 if ($pl_ref == 2 && $ob_ref == 1) { 495 if ($pl_ref == 3 && $ob_ref == 3) {
385 warn "player-scheduler destroy ", $ob->name;#d# 496 warn "player-scheduler destroy ", $ob->name;#d#
386 497
387 # remove from sight and get fresh "copies" 498 # remove from sight and get fresh "copies"
388 $pl = delete $cf::PLAYER{$ob->name}; 499 $pl = delete $cf::PLAYER{$ob->name};
389 $ob = $pl->ob; 500 $ob = $pl->ob;
390 501
391 $ob->destroy;
392 $pl->destroy; 502 $pl->destroy; # destroys $ob
393 } else { 503 } else {
504 my $a_ = $pl->refcnt;#d#
505 my $b_ = $ob->refcnt;#d#
506
394 warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# 507 warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d#
395 } 508 }
396 } 509 }
397 } 510 }
398 }; 511 };
399 warn $@ if $@; 512 warn $@ if $@;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines