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.59 by root, Tue Jul 3 01:04:43 2007 UTC vs.
Revision 1.64 by root, Sat Jul 14 19:27:59 2007 UTC

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
9our %EXT_SETUP; 8our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600;
10 9
11# paranoia function to overwrite a string-in-place 10# paranoia function to overwrite a string-in-place
12sub nuke_str { 11sub nuke_str {
13 substr $_[0], 0, (length $_[0]), "x" x length $_[0] 12 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
14} 13}
56} 55}
57 56
58sub enter_map { 57sub enter_map {
59 my ($pl) = @_; 58 my ($pl) = @_;
60 59
60 my $ob = $pl->ob;
61
61 my ($map, $x, $y) 62 my ($map, $x, $y)
62 = $pl->ob->{_link_pos} 63 = $ob->{_link_pos}
63 ? @{delete $pl->ob->{_link_pos}} 64 ? @{delete $ob->{_link_pos}}
64 : ($pl->maplevel, $pl->ob->x, $pl->ob->y); 65 : ($pl->maplevel, $ob->x, $ob->y);
65 66
66 $pl->ob->enter_link; 67 $ob->enter_link;
67 68
68 if (my $time = delete $pl->{unclean_save}) { 69 if (my $time = delete $pl->{unclean_save}) {
69 if (my $m = cf::map::find $map) { 70 if (my $m = cf::map::find $map) {
70 if ($time < $m->{instantiate_time}) { 71 if ($time < $m->{instantiate_time}) {
71 # the map was reset in the meantime 72 # the map was reset in the meantime
72 my $age = $cf::RUNTIME - $time; 73 my $age = $cf::RUNTIME - $time;
74
73 warn $pl->ob->name, " map reset after logout, logout age $age\n";#d# 75 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
74 76
75 # for now, just go back to savebed 77 # for now, just go back to savebed
76 ($map, $x, $y) = $pl->savebed; 78 ($map, $x, $y) = $pl->savebed;
77 79
78 $pl->ns->send_drawinfo ( 80 if ($age >= $MAX_DISCONNECT_TIME) {
81 $ob->message (
79 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " 82 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
83 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. "
84 . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... "
85 . "H<You disconnected too long without having used a savebed.>",
86 cf::NDI_RED
87 );
88 # kill them.
89 # reminds me of the famous badness 10000 syndrome...
90 $ob->stats->hp (-10000); #] if they survive this they deserved to live
91 } else {
92 $ob->message (
93 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
80 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " 94 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
81 . "Better use a savebed next time, much worse things could have happened...", 95 . "Better use a savebed next time, much worse things could have happened... "
96 . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>",
97 cf::NDI_RED
98 );
99 }
100 } else {
101 $ob->message (
102 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
103 . "as lots of things could happen when you leave by other means, such as cave-ins, "
104 . "or monsters suddenly snapping your body. Better use a savebed next time. "
105 . "H<Always apply a bed of reality to disconnect from the server.>",
82 cf::NDI_RED 106 cf::NDI_RED
83 ); 107 );
84 } else {
85 $pl->ns->send_drawinfo (
86 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
87 . "as lots of things could happen when you leave by other means, such as cave-ins, "
88 . "or monsters suddenly snapping your body. Better use a savebed next time.",
89 cf::NDI_RED
90 );
91 } 108 }
92 } 109 }
93 } 110 }
94 111
95 $pl->ob->goto ($map, $x, $y); 112 $ob->goto ($map, $x, $y);
96} 113}
97 114
98# delete a player directory, be non-blocking AND synchronous... 115# delete a player directory, be non-blocking AND synchronous...
99# (thats hard, so we crap out and fork). 116# (thats hard, so we crap out and fork).
100sub nuke_playerdir { 117sub nuke_playerdir {
104 system "cd \Q$PLAYERDIR\E " 121 system "cd \Q$PLAYERDIR\E "
105 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 122 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null "
106 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 123 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)";
107} 124}
108 125
109sub send_capabilities { 126cf::client->attach (on_addme => sub {
110 my ($ns) = @_; 127 my ($ns) = @_;
111 128
112 return unless $ns->extcmd;
113
114 $ns->ext_event (capabilities =>
115 # id, name, flags (1 == 2d), edge length
116 tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32]],
117 );
118}
119
120sub setup {
121 my ($ns, $args) = @_;
122
123 # run through the cmds of setup
124 # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
125 #
126 # we send the status of the cmd back, or a FALSE is the cmd is the server unknown
127 # The client then must sort this out
128
129 my %setup = split / +/, $args;
130 while (my ($k, $v) = each %setup) {
131 if ($k eq "sound") {
132 $ns->sound ($v);
133
134 } elsif ($k eq "exp64") {
135 $setup{$k} = 1;
136
137 } elsif ($k eq "spellmon") {
138 $ns->monitor_spells ($v);
139
140 } elsif ($k eq "darkness") {
141 $ns->darkness ($v);
142
143 } elsif ($k eq "map1cmd") {
144 $ns->mapmode (cf::Map1Cmd) if $v > 0;
145
146 } elsif ($k eq "map1acmd") {
147 $ns->mapmode (cf::Map1aCmd) if $v > 0;
148
149 } elsif ($k eq "map2cmd") {
150 # gcfclient bug, map1acmd is sent too late
151 $ns->mapmode (cf::Map1aCmd);
152 $setup{$k} = "FALSE";
153
154 } elsif ($k eq "newmapcmd") {
155 $ns->newmapcmd ($v);
156
157 } elsif ($k eq "mapinfocmd") {
158 $ns->mapinfocmd ($v);
159
160 } elsif ($k eq "extcmd") {
161 $ns->extcmd ($v > 0);
162 send_capabilities $ns;
163
164 } elsif ($k eq "extmap") {
165 $ns->extmap ($v);
166
167 } elsif ($k eq "facecache") {
168 if (!$v) {
169 $v = 1;
170 $setup{$k} = $v;
171 $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED);
172 }
173
174 $ns->facecache ($v);
175
176 } elsif ($k eq "faceset") {
177 $ns->faceset (0);
178 $setup{$k} = 0;
179 # $ns->image2 (1)
180
181 } elsif ($k eq "tileset") {
182 $setup{$k} = $ns->faceset ($v & 1);
183
184 } elsif ($k eq "itemcmd") {
185 # Version of the item protocol command to use. Currently,
186 # only supported versions are 1 and 2. Using a numeric
187 # value will make it very easy to extend this in the future.
188 $ns->itemcmd ($v) if $v >= 1 && $v <= 2;
189
190 $setup{$k} = $ns->itemcmd;
191
192 } elsif ($k eq "mapsize") {
193 my ($x, $y) = split /x/, $v;
194
195 $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1);
196 $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1);
197
198 $setup{$k} = "${x}x${y}";
199
200 } elsif ($k eq "extendedMapInfos") {
201 $ns->ext_mapinfos ($v);
202
203 } elsif ($k eq "extendedTextInfos") {
204 $ns->has_readable_type ($v);
205
206 } elsif ($k eq "smoothing") { # cfplus-style smoothing
207 $ns->smoothing ($v);
208
209 } elsif ($k eq "fxix") {
210 $v = 2 if $v > 2;
211 $ns->fxix ($v);
212 $setup{$k} = $v;
213
214 } elsif ($k eq "msg") {
215 $v = 2 if $v > 2;
216 $ns->can_msg ($v >= 2);
217 $setup{$k} = $v;
218
219 } elsif ($k eq "xwidget") {
220 # eXperimental server-side widgets
221 $ns->{can_widget} = 1;
222
223 } elsif ($k eq "excmd") {
224 # we support it
225
226 } else {
227 # other commands:
228 # sexp: no idea, probably for oudated servers
229 # tick: more stupidity, server should send a tick per tick
230
231 $setup{$k} = "FALSE";
232 }
233 }
234
235 $ns->send_packet (join " ", setup => %setup);
236
237 cf::datalog setup =>
238 request => $args,
239 reply => \%setup,
240 client => $ns->version,
241 ;
242}
243
244sub addme {
245 my ($ns) = @_;
246
247 if (!$ns->facecache) 129 if (!$ns->facecache)
248 { 130 {
249 $ns->send_drawinfo (<<EOF, cf::NDI_RED); 131 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
250 132
251 133
252*** 134***
253*** WARNING: 135*** WARNING:
254*** Your client does not support face/image caching, 136*** Your client does not support face/image caching,
322 . "(only a-z, A-Z and 0-9 are allowed), " 204 . "(only a-z, A-Z and 0-9 are allowed), "
323 . "or is not between 3 and 18 characters in length.", 205 . "or is not between 3 and 18 characters in length.",
324 cf::NDI_RED 206 cf::NDI_RED
325 ); 207 );
326 } 208 }
209 Coro::Timer::sleep 0.4;
327 } 210 }
328 211
329 check_playing $ns, $user and next; 212 check_playing $ns, $user and next;
330 213
331 $ns->send_drawinfo ( 214 $ns->send_drawinfo (
342 $ns->send_drawinfo ( 225 $ns->send_drawinfo (
343 "Try to use at least three characters as your password please, " 226 "Try to use at least three characters as your password please, "
344 . "that cannot be too much to ask for :)", 227 . "that cannot be too much to ask for :)",
345 cf::NDI_RED 228 cf::NDI_RED
346 ); 229 );
230 Coro::Timer::sleep 0.4;
347 } 231 }
348 232
349 # lock this username for the remainder of this login session 233 # lock this username for the remainder of this login session
350 if ($cf::LOGIN_LOCK{$user}) { 234 if ($cf::LOGIN_LOCK{$user}) {
351 $ns->send_drawinfo ( 235 $ns->send_drawinfo (
432 nuke_str $pass2; 316 nuke_str $pass2;
433 $ns->send_drawinfo ( 317 $ns->send_drawinfo (
434 "The passwords do not match, please try again.", 318 "The passwords do not match, please try again.",
435 cf::NDI_RED 319 cf::NDI_RED
436 ); 320 );
321 Coro::Timer::sleep 0.5;
437 next; 322 next;
438 } 323 }
439 324
440 nuke_str $pass2; 325 nuke_str $pass2;
441 326
463 $ob->swap_stats ($res - 1, $swap - 1); 348 $ob->swap_stats ($res - 1, $swap - 1);
464 } 349 }
465 } else { 350 } else {
466 $ob->roll_stats; 351 $ob->roll_stats;
467 } 352 }
353
354 Coro::Timer::sleep 0.2;
468 } 355 }
469 356
470 $ob->set_animation (2); 357 $ob->set_animation (2);
471 $ob->add_statbonus; 358 $ob->add_statbonus;
472 359
480 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; 367 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
481 368
482 last if $res =~ /[dD]/; 369 last if $res =~ /[dD]/;
483 370
484 $pl->chargen_race_next; 371 $pl->chargen_race_next;
372 Coro::Timer::sleep 0.2;
485 } 373 }
486 374
487 $pl->chargen_race_done; 375 $pl->chargen_race_done;
488 376
489 while () { 377 while () {
495 last; 383 last;
496 } elsif ($res =~ /^[mM]/) { 384 } elsif ($res =~ /^[mM]/) {
497 $pl->gender (0); 385 $pl->gender (0);
498 last; 386 last;
499 } 387 }
388 Coro::Timer::sleep 0.2;
500 } 389 }
501 390
502 $ob->reply (undef, "Welcome to Crossfire!"); 391 $ob->reply (undef, "Welcome to Crossfire!");
503 392
504 delete $pl->{deny_save}; 393 delete $pl->{deny_save};
505 394
506 last; 395 last;
507 } 396 }
508 }); 397 });
509} 398});
510 399
511cf::register_command quit => sub { 400cf::register_command quit => sub {
512 my ($ob, $arg) = @_; 401 my ($ob, $arg) = @_;
513 402
514 $ob->reply (undef, 403 $ob->reply (undef,
585 $pl->{unclean_save} = $cf::RUNTIME; 474 $pl->{unclean_save} = $cf::RUNTIME;
586 } 475 }
587 }, 476 },
588); 477);
589 478
590cf::client->attach (
591 on_addme => \&addme,
592 on_setup => \&setup,
593);
594
595############################################################################# 479#############################################################################
596 480
597our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 481our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs
598our $SAVE_TIMEOUT = 20; # save players every n seconds 482our $SAVE_TIMEOUT = 20; # save players every n seconds
599 483

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines