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.51 by root, Sun Jun 10 03:15:17 2007 UTC vs.
Revision 1.60 by root, Thu Jul 5 20:52:22 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,
474 $pl->chargen_race_next; 346 $pl->chargen_race_next;
475 } 347 }
476 348
477 $pl->chargen_race_done; 349 $pl->chargen_race_done;
478 350
351 while () {
352 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
353 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
354
355 if ($res =~ /^[fF]/) {
356 $pl->gender (1);
357 last;
358 } elsif ($res =~ /^[mM]/) {
359 $pl->gender (0);
360 last;
361 }
362 }
363
364 $ob->reply (undef, "Welcome to Crossfire!");
365
479 delete $pl->{deny_save}; 366 delete $pl->{deny_save};
480 367
481 last; 368 last;
482 } 369 }
483 }); 370 });
484} 371});
485 372
486cf::register_command quit => sub { 373cf::register_command quit => sub {
487 my ($ob, $arg) = @_; 374 my ($ob, $arg) = @_;
488 375
489 $ob->reply (undef, 376 $ob->reply (undef,
560 $pl->{unclean_save} = $cf::RUNTIME; 447 $pl->{unclean_save} = $cf::RUNTIME;
561 } 448 }
562 }, 449 },
563); 450);
564 451
565cf::client->attach (
566 on_addme => \&addme,
567 on_setup => \&setup,
568);
569
570############################################################################# 452#############################################################################
571 453
572our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 454our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs
573our $SAVE_TIMEOUT = 20; # save players every n seconds 455our $SAVE_TIMEOUT = 20; # save players every n seconds
574 456
606 488
607 # remove from sight and get fresh "copies" 489 # remove from sight and get fresh "copies"
608 $pl = delete $cf::PLAYER{$ob->name}; 490 $pl = delete $cf::PLAYER{$ob->name};
609 $ob = $pl->ob; 491 $ob = $pl->ob;
610 492
611 $ob->destroy;
612 $pl->destroy; 493 $pl->destroy; # destroys $ob
613 } else { 494 } else {
614 my $a_ = $pl->refcnt;#d# 495 my $a_ = $pl->refcnt;#d#
615 my $b_ = $ob->refcnt;#d# 496 my $b_ = $ob->refcnt;#d#
616 497
617 warn "player-scheduler refcnt ", $ob->name, " pp$pl_ref,pc$a_ op$ob_ref,oc$b_\n";#d# 498 warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d#
618 } 499 }
619 } 500 }
620 } 501 }
621 }; 502 };
622 warn $@ if $@; 503 warn $@ if $@;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines