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.42 by root, Wed Apr 18 17:32:06 2007 UTC

2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
7 7use List::Util qw(min max);
8my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir;
9 8
10# paranoia function to overwrite a string-in-place 9# paranoia function to overwrite a string-in-place
11sub nuke_str { 10sub nuke_str {
12 substr $_[0], 0, (length $_[0]), "x" x length $_[0] 11 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
13} 12}
14 13
15sub query { 14sub query {
16 my ($ns, $flags, $text) = @_; 15 my ($ns, $flags, $text) = @_;
17 16
18 my $current = $Coro::current; 17 my $current = $Coro::current;
19 $ns->query ($flags, $text, sub { $current->ready; $current = $_[0]; }); 18 $ns->query ($flags, $text, sub { $current->ready; $current = $_[0] });
20 Coro::schedule while ref $current; 19 Coro::schedule while ref $current;
21 20
22 $current 21 $current
23} 22}
24 23
77 system "cd \Q$PLAYERDIR\E " 76 system "cd \Q$PLAYERDIR\E "
78 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 77 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null "
79 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 78 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)";
80} 79}
81 80
81sub send_capabilities {
82 my ($ns) = @_;
83
84 return unless $ns->extcmd;
85
86 $ns->ext_event (capabilities =>
87 # id, name, flags (1 == 2d), edge length
88 tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32]],
89 );
90}
91
92sub setup {
93 my ($ns, $args) = @_;
94
95 # run through the cmds of setup
96 # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
97 #
98 # we send the status of the cmd back, or a FALSE is the cmd is the server unknown
99 # The client then must sort this out
100
101 my %setup = split / +/, $args;
102 while (my ($k, $v) = each %setup) {
103 if ($k eq "sound") {
104 $ns->sound ($v);
105
106 } elsif ($k eq "exp64") {
107 $setup{$k} = 1;
108
109 } elsif ($k eq "spellmon") {
110 $ns->monitor_spells ($v);
111
112 } elsif ($k eq "darkness") {
113 $ns->darkness ($v);
114
115 } elsif ($k eq "map1cmd") {
116 $ns->mapmode (cf::Map1Cmd) if $v > 0;
117
118 } elsif ($k eq "map1acmd") {
119 $ns->mapmode (cf::Map1aCmd) if $v > 0;
120
121 } elsif ($k eq "map2cmd") {
122 # gcfclient bug, map1acmd is sent too late
123 $ns->mapmode (cf::Map1aCmd);
124 $setup{$k} = "FALSE";
125
126 } elsif ($k eq "newmapcmd") {
127 $ns->newmapcmd ($v);
128
129 } elsif ($k eq "mapinfocmd") {
130 $ns->mapinfocmd ($v);
131
132 } elsif ($k eq "extcmd") {
133 $ns->extcmd ($v > 0);
134 send_capabilities $ns;
135
136 } elsif ($k eq "extmap") {
137 $ns->extmap ($v);
138
139 } elsif ($k eq "facecache") {
140 if (!$v) {
141 $v = 1;
142 $setup{$k} = $v;
143 $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED);
144 }
145
146 $ns->facecache ($v);
147
148 } elsif ($k eq "faceset") {
149 $ns->faceset (0);
150 $setup{$k} = 0;
151 # $ns->image2 (1)
152
153 } elsif ($k eq "tileset") {
154 $setup{$k} = $ns->faceset ($v & 1);
155
156 } elsif ($k eq "itemcmd") {
157 # Version of the item protocol command to use. Currently,
158 # only supported versions are 1 and 2. Using a numeric
159 # value will make it very easy to extend this in the future.
160 $ns->itemcmd ($v) if $v >= 1 && $v <= 2;
161
162 $setup{$k} = $ns->itemcmd;
163
164 } elsif ($k eq "mapsize") {
165 my ($x, $y) = split /x/, $v;
166
167 $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1);
168 $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1);
169
170 $setup{$k} = "${x}x${y}";
171
172 } elsif ($k eq "extendedMapInfos") {
173 $ns->ext_mapinfos ($v);
174
175 } elsif ($k eq "extendedTextInfos") {
176 $ns->has_readable_type ($v);
177
178 } elsif ($k eq "smoothing") { # cfplus-style smoothing
179 $ns->smoothing ($v);
180
181 } elsif ($k eq "fxix") {
182 $ns->fxix ($v);
183
184 } else {
185 # other commands:
186 # sexp: no idea, probably for oudated servers
187 # tick: more stupidity, server should sned a tick per tick
188
189 $setup{$k} = "FALSE";
190 }
191 }
192
193 $ns->send_packet (join " ", setup => %setup);
194
195 cf::datalog setup =>
196 request => $args,
197 reply => \%setup,
198 client => $ns->version,
199 ;
200}
201
82sub addme { 202sub addme {
83 my ($ns) = @_; 203 my ($ns) = @_;
84 204
85 $ns->destroy if $ns->pl; 205 if (!$ns->facecache)
206 {
207 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
208
209
210***
211*** WARNING:
212*** Your client does not support face/image caching,
213*** or it has been disabled. Face caching is mandatory
214*** so please enable it or use a newer client.
215***
216*** Look at your client preferences:
217***
218*** CFPlus: all known versions automatically enable the facecache.
219*** cfclient: use the -cache commandline option.
220*** cfclient: map will not redraw automatically (bug).
221*** gcfclient: use -cache commandline option, or enable
222*** gcfclient: Client=>Configure=>Map & Image=>Cache Images.
223*** jcrossclient: your client is broken, use CFPlus or gcfclient.
224***
225***
226EOF
227 if ($ns->version =~ /jcrossclient/) {
228 # let them, for now
229 } else {
230 $ns->flush;
231 return $ns->destroy;
232 }
233
234 # $ns->facecache = true;
235 }
236
237 if ($ns->mapmode < cf::Map1aCmd) {
238 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
239
240
241***
242*** WARNING:
243*** Your client is too old. Please upgrade to a newer version.
244EOF
245
246 $ns->flush;
247 return $ns->destroy;
248 }
249
250 $ns->pl and return $ns->destroy;
86 251
87 $ns->async (sub { 252 $ns->async (sub {
88 my ($user, $pass); 253 my ($user, $pass);
89 254
90 $ns->send_packet ("addme_success"); 255 $ns->send_packet ("addme_success");
105 $ns->send_drawinfo ( 270 $ns->send_drawinfo (
106 "That username is currently used in another login session. " 271 "That username is currently used in another login session. "
107 . "Chose another, or wait till the other session has ended.", 272 . "Chose another, or wait till the other session has ended.",
108 cf::NDI_RED 273 cf::NDI_RED
109 ); 274 );
110 } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}$/) { 275 } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) {
111 last; 276 last;
112 } else { 277 } else {
113 $ns->send_drawinfo ( 278 $ns->send_drawinfo (
114 "Your username contains illegal characters " 279 "Your username contains illegal characters "
115 . "(only a-z, A-Z and 0-9 are allowed), " 280 . "(only a-z, A-Z and 0-9 are allowed), "
192 Coro::Timer::sleep 1; 357 Coro::Timer::sleep 1;
193 358
194 $ns->send_drawinfo ( 359 $ns->send_drawinfo (
195 "Wrong username or password. Please try again " 360 "Wrong username or password. Please try again "
196 . "(check for Numlock and other semi-obvious error sources).", 361 . "(check for Numlock and other semi-obvious error sources).",
362 cf::NDI_RED
363 );
364 next;
365 }
366 } else {
367 # unable to load the playerfile:
368 # check wether the player dir exists, which means the file is corrupted or
369 # something very similar.
370 if (!aio_stat cf::player::playerdir $user) {
371 $ns->send_drawinfo (
372 "Unable to retrieve this player. It might be a locked or broken account. "
373 . "If this is your account, ask a dungeon master for assistance. "
374 . "Otherwise choose a different login name.",
197 cf::NDI_RED 375 cf::NDI_RED
198 ); 376 );
199 next; 377 next;
200 } 378 }
201 } 379 }
283 } else { 461 } else {
284 $ob->reply (undef, 462 $ob->reply (undef,
285 "Ok, quitting, hope to see you again.", 463 "Ok, quitting, hope to see you again.",
286 cf::NDI_UNIQUE | cf::NDI_RED); 464 cf::NDI_UNIQUE | cf::NDI_RED);
287 $pl->ns->flush; 465 $pl->ns->flush;
288 $pl->quit_character; 466 cf::async { $pl->quit_character };
289 } 467 }
290 }); 468 });
291}; 469};
292 470
293cf::object->attach ( 471cf::object->attach (
340 }, 518 },
341); 519);
342 520
343cf::client->attach ( 521cf::client->attach (
344 on_addme => \&addme, 522 on_addme => \&addme,
523 on_setup => \&setup,
345); 524);
346 525
347############################################################################# 526#############################################################################
348 527
349our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 528our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs
364 or next; 543 or next;
365 $pl->valid or next; 544 $pl->valid or next;
366 545
367 eval { 546 eval {
368 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 547 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
369 $cf::WAIT_FOR_TICK_ONE->wait; 548 cf::wait_for_tick_begin;
370 $pl->save; 549 $pl->save;
371 550
372 unless ($pl->active) { 551 unless ($pl->active) {
373 # check refcounts, this is tricky and needs to be adjusted to fit server internals 552 # check refcounts, this is tricky and needs to be adjusted to fit server internals
374 my $ob = $pl->ob; 553 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines