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.23 by root, Tue Jan 9 15:36:18 2007 UTC vs.
Revision 1.30 by root, Sun Feb 11 17:47:22 2007 UTC

1#! perl 1#! perl # MANDATORY
2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
55} 55}
56 56
57sub check_clean_save { 57sub check_clean_save {
58 my ($pl) = @_; 58 my ($pl) = @_;
59 59
60 unless (delete $pl->{clean_save}) { 60 if (my $time = delete $pl->{unclean_save}) {
61 $pl->ns->send_drawinfo (
62 "You didn't use a savebed 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, "
64 . "or monsters suddenly snapping your body. Better use a savebed next time.",
65 cf::NDI_RED
66 );
61 #d#TODO 67 #d#TODO
62 } 68 }
63} 69}
64 70
65# delete a player directory, be non-blocking AND synchronous... 71# delete a player directory, be non-blocking AND synchronous...
99 $ns->send_drawinfo ( 105 $ns->send_drawinfo (
100 "That username is currently used in another login session. " 106 "That username is currently used in another login session. "
101 . "Chose another, or wait till the other session has ended.", 107 . "Chose another, or wait till the other session has ended.",
102 cf::NDI_RED 108 cf::NDI_RED
103 ); 109 );
104 } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}$/) { 110 } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) {
105 last; 111 last;
106 } else { 112 } else {
107 $ns->send_drawinfo ( 113 $ns->send_drawinfo (
108 "Your username contains illegal characters " 114 "Your username contains illegal characters "
109 . "(only a-z, A-Z and 0-9 are allowed), " 115 . "(only a-z, A-Z and 0-9 are allowed), "
156 nuke_str $pass; 162 nuke_str $pass;
157 # password matches, wonderful 163 # password matches, wonderful
158 my $pl = cf::player::find $user or next; 164 my $pl = cf::player::find $user or next;
159 $pl->connect ($ns); 165 $pl->connect ($ns);
160 check_clean_save $pl; 166 check_clean_save $pl;
161 $pl->{clean_save} = 1;
162 last; 167 last;
163 } elsif (can_cleanup $pl, $mtime) { 168 } elsif (can_cleanup $pl, $mtime) {
164 Coro::Timer::sleep 1; 169 Coro::Timer::sleep 1;
165 170
166 $ns->send_drawinfo ( 171 $ns->send_drawinfo (
328 333
329 if ($cleanly) { 334 if ($cleanly) {
330 $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; 335 $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list;
331 } else { 336 } else {
332 $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; 337 $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list;
333 delete $pl->{clean_save}; 338 $pl->{unclean_save} = $cf::RUNTIME;
334 } 339 }
335 }, 340 },
336); 341);
337 342
338cf::client->attach ( 343cf::client->attach (
341 346
342############################################################################# 347#############################################################################
343 348
344our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 349our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs
345our $SAVE_TIMEOUT = 20; # save players every n seconds 350our $SAVE_TIMEOUT = 20; # save players every n seconds
346our $SAVE_INTERVAL = 0.5; # save at max. one player every $SAVE_INTERVAL
347 351
348our $SCHEDULER = cf::async_ext { 352our $SCHEDULER = cf::async_ext {
353 my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL);
349 while () { 354 while () {
350 Coro::Timer::sleep $SCHEDULE_INTERVAL; 355 $schedule_interval->next;
351 356
352 # this weird form of iteration over values is used because 357 # this weird form of iteration over values is used because
353 # the hash changes underneath us frequently, and for 358 # the hash changes underneath us frequently, and for
354 # keeps a direct reference to the value without (in 5.8 perls) 359 # keeps a direct reference to the value without (in 5.8 perls)
355 # keeping a reference, so this is prone to crashes or worse. 360 # keeping a reference, so this is prone to crashes or worse.
359 or next; 364 or next;
360 $pl->valid or next; 365 $pl->valid or next;
361 366
362 eval { 367 eval {
363 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 368 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
369 $cf::WAIT_FOR_TICK_ONE->wait;
364 $pl->save; 370 $pl->save;
365 371
366 unless ($pl->active) { 372 unless ($pl->active) {
367 # check refcounts, this is tricky and needs to be adjusted to fit server internals 373 # check refcounts, this is tricky and needs to be adjusted to fit server internals
368 my $ob = $pl->ob; 374 my $ob = $pl->ob;
386 $pl->destroy; 392 $pl->destroy;
387 } else { 393 } else {
388 warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# 394 warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d#
389 } 395 }
390 } 396 }
391 Coro::Timer::sleep $SAVE_INTERVAL;
392 } 397 }
393 }; 398 };
394 warn $@ if $@; 399 warn $@ if $@;
395 Coro::cede; 400 Coro::cede;
396 }; 401 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines