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.31 by root, Sat Feb 17 23:54:35 2007 UTC vs.
Revision 1.43 by root, Mon Apr 23 18:09:57 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 } elsif ($k eq "msg") {
185 $ns->{setup}{msg} = $v;
186
187 } else {
188 # other commands:
189 # sexp: no idea, probably for oudated servers
190 # tick: more stupidity, server should sned a tick per tick
191
192 $setup{$k} = "FALSE";
193 }
194 }
195
196 $ns->send_packet (join " ", setup => %setup);
197
198 cf::datalog setup =>
199 request => $args,
200 reply => \%setup,
201 client => $ns->version,
202 ;
203}
204
82sub addme { 205sub addme {
83 my ($ns) = @_; 206 my ($ns) = @_;
84 207
85 $ns->destroy if $ns->pl; 208 if (!$ns->facecache)
209 {
210 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
211
212
213***
214*** WARNING:
215*** Your client does not support face/image caching,
216*** or it has been disabled. Face caching is mandatory
217*** so please enable it or use a newer client.
218***
219*** Look at your client preferences:
220***
221*** CFPlus: all known versions automatically enable the facecache.
222*** cfclient: use the -cache commandline option.
223*** cfclient: map will not redraw automatically (bug).
224*** gcfclient: use -cache commandline option, or enable
225*** gcfclient: Client=>Configure=>Map & Image=>Cache Images.
226*** jcrossclient: your client is broken, use CFPlus or gcfclient.
227***
228***
229EOF
230 if ($ns->version =~ /jcrossclient/) {
231 # let them, for now
232 } else {
233 $ns->flush;
234 return $ns->destroy;
235 }
236
237 # $ns->facecache = true;
238 }
239
240 if ($ns->mapmode < cf::Map1aCmd) {
241 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
242
243
244***
245*** WARNING:
246*** Your client is too old. Please upgrade to a newer version.
247EOF
248
249 $ns->flush;
250 return $ns->destroy;
251 }
252
253 $ns->pl and return $ns->destroy;
86 254
87 $ns->async (sub { 255 $ns->async (sub {
88 my ($user, $pass); 256 my ($user, $pass);
89 257
90 $ns->send_packet ("addme_success"); 258 $ns->send_packet ("addme_success");
196 . "(check for Numlock and other semi-obvious error sources).", 364 . "(check for Numlock and other semi-obvious error sources).",
197 cf::NDI_RED 365 cf::NDI_RED
198 ); 366 );
199 next; 367 next;
200 } 368 }
369 } else {
370 # unable to load the playerfile:
371 # check wether the player dir exists, which means the file is corrupted or
372 # something very similar.
373 if (!aio_stat cf::player::playerdir $user) {
374 $ns->send_drawinfo (
375 "Unable to retrieve this player. It might be a locked or broken account. "
376 . "If this is your account, ask a dungeon master for assistance. "
377 . "Otherwise choose a different login name.",
378 cf::NDI_RED
379 );
380 next;
381 }
201 } 382 }
202 383
203 # the rest of this function is character creation 384 # the rest of this function is character creation
204 385
205 # just to make sure nothing is left over 386 # just to make sure nothing is left over
340 }, 521 },
341); 522);
342 523
343cf::client->attach ( 524cf::client->attach (
344 on_addme => \&addme, 525 on_addme => \&addme,
526 on_setup => \&setup,
345); 527);
346 528
347############################################################################# 529#############################################################################
348 530
349our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 531our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs
364 or next; 546 or next;
365 $pl->valid or next; 547 $pl->valid or next;
366 548
367 eval { 549 eval {
368 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 550 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
369 $cf::WAIT_FOR_TICK_ONE->wait; 551 cf::wait_for_tick_begin;
370 $pl->save; 552 $pl->save;
371 553
372 unless ($pl->active) { 554 unless ($pl->active) {
373 # check refcounts, this is tricky and needs to be adjusted to fit server internals 555 # check refcounts, this is tricky and needs to be adjusted to fit server internals
374 my $ob = $pl->ob; 556 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines