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.49 by root, Sun Jun 10 03:11:16 2007 UTC vs.
Revision 1.61 by root, Tue Jul 10 06:12:13 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;
7use List::Util qw(min max);
8 7
9# paranoia function to overwrite a string-in-place 8# paranoia function to overwrite a string-in-place
10sub nuke_str { 9sub nuke_str {
11 substr $_[0], 0, (length $_[0]), "x" x length $_[0] 10 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
12} 11}
39 return unless cf::player::find_active $user; 38 return unless cf::player::find_active $user;
40 39
41 $ns->send_drawinfo ( 40 $ns->send_drawinfo (
42 "That player is already logged in on this server. " 41 "That player is already logged in on this server. "
43 . "If you want to create a new player, choose another name. " 42 . "If you want to create a new player, choose another name. "
44 . "If you are already a registered player, make sure nobody " 43 . "If you have already a registered, make sure nobody "
45 . "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 "
46 . "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 "
47 . "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 "
48 . "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, "
49 . "this will fix anything.", 48 . "this will fix anything.",
50 cf::NDI_RED 49 cf::NDI_RED
102 system "cd \Q$PLAYERDIR\E " 101 system "cd \Q$PLAYERDIR\E "
103 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 102 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null "
104 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 103 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)";
105} 104}
106 105
107sub send_capabilities { 106cf::client->attach (on_addme => sub {
108 my ($ns) = @_; 107 my ($ns) = @_;
109 108
110 return unless $ns->extcmd;
111
112 $ns->ext_event (capabilities =>
113 # id, name, flags (1 == 2d), edge length
114 tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32]],
115 );
116}
117
118sub setup {
119 my ($ns, $args) = @_;
120
121 # run through the cmds of setup
122 # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
123 #
124 # we send the status of the cmd back, or a FALSE is the cmd is the server unknown
125 # The client then must sort this out
126
127 my %setup = split / +/, $args;
128 while (my ($k, $v) = each %setup) {
129 if ($k eq "sound") {
130 $ns->sound ($v);
131
132 } elsif ($k eq "exp64") {
133 $setup{$k} = 1;
134
135 } elsif ($k eq "spellmon") {
136 $ns->monitor_spells ($v);
137
138 } elsif ($k eq "darkness") {
139 $ns->darkness ($v);
140
141 } elsif ($k eq "map1cmd") {
142 $ns->mapmode (cf::Map1Cmd) if $v > 0;
143
144 } elsif ($k eq "map1acmd") {
145 $ns->mapmode (cf::Map1aCmd) if $v > 0;
146
147 } elsif ($k eq "map2cmd") {
148 # gcfclient bug, map1acmd is sent too late
149 $ns->mapmode (cf::Map1aCmd);
150 $setup{$k} = "FALSE";
151
152 } elsif ($k eq "newmapcmd") {
153 $ns->newmapcmd ($v);
154
155 } elsif ($k eq "mapinfocmd") {
156 $ns->mapinfocmd ($v);
157
158 } elsif ($k eq "extcmd") {
159 $ns->extcmd ($v > 0);
160 send_capabilities $ns;
161
162 } elsif ($k eq "extmap") {
163 $ns->extmap ($v);
164
165 } elsif ($k eq "facecache") {
166 if (!$v) {
167 $v = 1;
168 $setup{$k} = $v;
169 $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED);
170 }
171
172 $ns->facecache ($v);
173
174 } elsif ($k eq "faceset") {
175 $ns->faceset (0);
176 $setup{$k} = 0;
177 # $ns->image2 (1)
178
179 } elsif ($k eq "tileset") {
180 $setup{$k} = $ns->faceset ($v & 1);
181
182 } elsif ($k eq "itemcmd") {
183 # Version of the item protocol command to use. Currently,
184 # only supported versions are 1 and 2. Using a numeric
185 # value will make it very easy to extend this in the future.
186 $ns->itemcmd ($v) if $v >= 1 && $v <= 2;
187
188 $setup{$k} = $ns->itemcmd;
189
190 } elsif ($k eq "mapsize") {
191 my ($x, $y) = split /x/, $v;
192
193 $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1);
194 $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1);
195
196 $setup{$k} = "${x}x${y}";
197
198 } elsif ($k eq "extendedMapInfos") {
199 $ns->ext_mapinfos ($v);
200
201 } elsif ($k eq "extendedTextInfos") {
202 $ns->has_readable_type ($v);
203
204 } elsif ($k eq "smoothing") { # cfplus-style smoothing
205 $ns->smoothing ($v);
206
207 } elsif ($k eq "fxix") {
208 $ns->fxix ($v);
209
210 } elsif ($k eq "msg") {
211 $ns->can_msg ($v);
212
213 } elsif ($k eq "excmd") {
214 # we support it
215
216 } else {
217 # other commands:
218 # sexp: no idea, probably for oudated servers
219 # tick: more stupidity, server should send a tick per tick
220
221 $setup{$k} = "FALSE";
222 }
223 }
224
225 $ns->send_packet (join " ", setup => %setup);
226
227 cf::datalog setup =>
228 request => $args,
229 reply => \%setup,
230 client => $ns->version,
231 ;
232}
233
234sub addme {
235 my ($ns) = @_;
236
237 if (!$ns->facecache) 109 if (!$ns->facecache)
238 { 110 {
239 $ns->send_drawinfo (<<EOF, cf::NDI_RED); 111 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
240 112
241 113
242*** 114***
243*** WARNING: 115*** WARNING:
244*** Your client does not support face/image caching, 116*** Your client does not support face/image caching,
312 . "(only a-z, A-Z and 0-9 are allowed), " 184 . "(only a-z, A-Z and 0-9 are allowed), "
313 . "or is not between 3 and 18 characters in length.", 185 . "or is not between 3 and 18 characters in length.",
314 cf::NDI_RED 186 cf::NDI_RED
315 ); 187 );
316 } 188 }
189 Coro::Timer::sleep 0.4;
317 } 190 }
318 191
319 check_playing $ns, $user and next; 192 check_playing $ns, $user and next;
320 193
321 $ns->send_drawinfo ( 194 $ns->send_drawinfo (
332 $ns->send_drawinfo ( 205 $ns->send_drawinfo (
333 "Try to use at least three characters as your password please, " 206 "Try to use at least three characters as your password please, "
334 . "that cannot be too much to ask for :)", 207 . "that cannot be too much to ask for :)",
335 cf::NDI_RED 208 cf::NDI_RED
336 ); 209 );
210 Coro::Timer::sleep 0.4;
337 } 211 }
338 212
339 # lock this username for the remainder of this login session 213 # lock this username for the remainder of this login session
340 if ($cf::LOGIN_LOCK{$user}) { 214 if ($cf::LOGIN_LOCK{$user}) {
341 $ns->send_drawinfo ( 215 $ns->send_drawinfo (
422 nuke_str $pass2; 296 nuke_str $pass2;
423 $ns->send_drawinfo ( 297 $ns->send_drawinfo (
424 "The passwords do not match, please try again.", 298 "The passwords do not match, please try again.",
425 cf::NDI_RED 299 cf::NDI_RED
426 ); 300 );
301 Coro::Timer::sleep 0.5;
427 next; 302 next;
428 } 303 }
429 304
430 nuke_str $pass2; 305 nuke_str $pass2;
431 306
453 $ob->swap_stats ($res - 1, $swap - 1); 328 $ob->swap_stats ($res - 1, $swap - 1);
454 } 329 }
455 } else { 330 } else {
456 $ob->roll_stats; 331 $ob->roll_stats;
457 } 332 }
333
334 Coro::Timer::sleep 0.2;
458 } 335 }
459 336
460 $ob->set_animation (2); 337 $ob->set_animation (2);
461 $ob->add_statbonus; 338 $ob->add_statbonus;
462 339
470 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; 347 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
471 348
472 last if $res =~ /[dD]/; 349 last if $res =~ /[dD]/;
473 350
474 $pl->chargen_race_next; 351 $pl->chargen_race_next;
352 Coro::Timer::sleep 0.2;
475 } 353 }
476 354
477 $pl->chargen_race_done; 355 $pl->chargen_race_done;
356
357 while () {
358 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
359 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
360
361 if ($res =~ /^[fF]/) {
362 $pl->gender (1);
363 last;
364 } elsif ($res =~ /^[mM]/) {
365 $pl->gender (0);
366 last;
367 }
368 Coro::Timer::sleep 0.2;
369 }
370
371 $ob->reply (undef, "Welcome to Crossfire!");
478 372
479 delete $pl->{deny_save}; 373 delete $pl->{deny_save};
480 374
481 last; 375 last;
482 } 376 }
483 }); 377 });
484} 378});
485 379
486cf::register_command quit => sub { 380cf::register_command quit => sub {
487 my ($ob, $arg) = @_; 381 my ($ob, $arg) = @_;
488 382
489 $ob->reply (undef, 383 $ob->reply (undef,
560 $pl->{unclean_save} = $cf::RUNTIME; 454 $pl->{unclean_save} = $cf::RUNTIME;
561 } 455 }
562 }, 456 },
563); 457);
564 458
565cf::client->attach (
566 on_addme => \&addme,
567 on_setup => \&setup,
568);
569
570############################################################################# 459#############################################################################
571 460
572our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 461our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs
573our $SAVE_TIMEOUT = 20; # save players every n seconds 462our $SAVE_TIMEOUT = 20; # save players every n seconds
574 463
593 $pl->save; 482 $pl->save;
594 483
595 unless ($pl->active || $pl->ns) { 484 unless ($pl->active || $pl->ns) {
596 # check refcounts, this is tricky and needs to be adjusted to fit server internals 485 # check refcounts, this is tricky and needs to be adjusted to fit server internals
597 my $ob = $pl->ob; 486 my $ob = $pl->ob;
598 Scalar::Util::weaken $pl; 487
599 Scalar::Util::weaken $ob;
600 my $a_ = $pl->refcnt;#d#
601 my $b_ = $ob->refcnt;#d#
602 my $pl_ref = $pl->refcnt_cnt; 488 my $pl_ref = $pl->refcnt_cnt;
603 my $ob_ref = $ob->refcnt_cnt; 489 my $ob_ref = $ob->refcnt_cnt;
604 490
605 ## pl_ref == one from object + one from cf::PLAYER 491 ## pl_ref == $pl + ob->contr + %cf::PLAYER
606 ## ob_ref == one from simply being an object + one from pl->observe 492 ## ob_ref == $ob + pl->observe + simply being an object
607 if ($pl_ref == 2 && $ob_ref == 2) { 493 if ($pl_ref == 3 && $ob_ref == 3) {
608 warn "player-scheduler destroy ", $ob->name;#d# 494 warn "player-scheduler destroy ", $ob->name;#d#
609 495
610 # remove from sight and get fresh "copies" 496 # remove from sight and get fresh "copies"
611 $pl = delete $cf::PLAYER{$ob->name}; 497 $pl = delete $cf::PLAYER{$ob->name};
612 $ob = $pl->ob; 498 $ob = $pl->ob;
613 499
614 $ob->destroy;
615 $pl->destroy; 500 $pl->destroy; # destroys $ob
616 } else { 501 } else {
502 my $a_ = $pl->refcnt;#d#
503 my $b_ = $ob->refcnt;#d#
504
617 warn "player-scheduler refcnt ", $ob->name, " pp$pl_ref,pc$a_ op$ob_ref,oc$b_\n";#d# 505 warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d#
618 } 506 }
619 } 507 }
620 } 508 }
621 }; 509 };
622 warn $@ if $@; 510 warn $@ if $@;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines