ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.219 by root, Sat Feb 17 03:19:44 2007 UTC vs.
Revision 1.223 by root, Sun Mar 11 02:12:44 2007 UTC

43our @EXTS = (); # list of extension package names 43our @EXTS = (); # list of extension package names
44our %EXTCMD = (); 44our %EXTCMD = ();
45our %EXT_CORO = (); # coroutines bound to extensions 45our %EXT_CORO = (); # coroutines bound to extensions
46our %EXT_MAP = (); # pluggable maps 46our %EXT_MAP = (); # pluggable maps
47 47
48our $RELOAD; # number of reloads so far
48our @EVENT; 49our @EVENT;
49our $LIBDIR = datadir . "/ext"; 50our $LIBDIR = datadir . "/ext";
50 51
51our $TICK = MAX_TIME * 1e-6; 52our $TICK = MAX_TIME * 1e-6;
52our $TICK_WATCHER; 53our $TICK_WATCHER;
1030=cut 1031=cut
1031 1032
1032sub quit_character { 1033sub quit_character {
1033 my ($pl) = @_; 1034 my ($pl) = @_;
1034 1035
1036 my $name = $pl->ob->name;
1037
1035 $pl->{deny_save} = 1; 1038 $pl->{deny_save} = 1;
1036 $pl->password ("*"); # this should lock out the player until we nuked the dir 1039 $pl->password ("*"); # this should lock out the player until we nuked the dir
1037 1040
1038 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; 1041 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active;
1039 $pl->deactivate; 1042 $pl->deactivate;
1043 my $path = playerdir $pl; 1046 my $path = playerdir $pl;
1044 my $temp = "$path~$cf::RUNTIME~deleting~"; 1047 my $temp = "$path~$cf::RUNTIME~deleting~";
1045 aio_rename $path, $temp; 1048 aio_rename $path, $temp;
1046 delete $cf::PLAYER{$pl->ob->name}; 1049 delete $cf::PLAYER{$pl->ob->name};
1047 $pl->destroy; 1050 $pl->destroy;
1051
1052 my $prefix = qr<^~\Q$name\E/>;
1053
1054 # nuke player maps
1055 $cf::MAP{$_}->nuke for grep /$prefix/, keys %cf::MAP;
1056
1048 IO::AIO::aio_rmtree $temp; 1057 IO::AIO::aio_rmtree $temp;
1058}
1059
1060=item $pl->kick
1061
1062Kicks a player out of the game. This destroys the connection.
1063
1064=cut
1065
1066sub kick {
1067 my ($pl, $kicker) = @_;
1068
1069 $pl->invoke (cf::EVENT_PLAYER_KICK, $kicker);
1070 $pl->killer ("kicked");
1071 $pl->ns->destroy;
1049} 1072}
1050 1073
1051=item cf::player::list_logins 1074=item cf::player::list_logins
1052 1075
1053Returns am arrayref of all valid playernames in the system, can take a 1076Returns am arrayref of all valid playernames in the system, can take a
2244} 2267}
2245 2268
2246############################################################################# 2269#############################################################################
2247# the server's init and main functions 2270# the server's init and main functions
2248 2271
2272sub load_faces {
2273 my $path = sprintf "%s/faces", cf::datadir;
2274
2275 warn "loading faces from $path\n";
2276
2277 my $faces;
2278 0 < aio_load $path, $faces
2279 or die "$path: $!";
2280
2281 Coro::cede;
2282 $faces = Storable::thaw $faces;
2283 Coro::cede;
2284
2285 while (my ($face, $info) = each %$faces) {
2286 my $idx = (cf::face::find $face) || cf::face::alloc $face;
2287 cf::face::set $idx, $info->{visibility}, $info->{magicmap};
2288 cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32};
2289 Coro::cede;
2290 }
2291
2292 1
2293}
2294
2249sub init_resources { 2295sub reload_resources {
2250 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir 2296 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir
2251 or die "unable to load regions file\n";#d# 2297 or die "unable to load regions file\n";#d#
2298 load_faces
2299 or die "unable to load faces\n";#d#
2300}
2301
2302sub init {
2303 reload_resources;
2252} 2304}
2253 2305
2254sub cfg_load { 2306sub cfg_load {
2255 open my $fh, "<:utf8", cf::confdir . "/config" 2307 open my $fh, "<:utf8", cf::confdir . "/config"
2256 or return; 2308 or return;
2268 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" 2320 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()"
2269 and die "WARNING: m(un)lockall failed: $!\n"; 2321 and die "WARNING: m(un)lockall failed: $!\n";
2270 }; 2322 };
2271 warn $@ if $@; 2323 warn $@ if $@;
2272 } 2324 }
2273}
2274
2275sub init {
2276 init_resources;
2277} 2325}
2278 2326
2279sub main { 2327sub main {
2280 # we must not ever block the main coroutine 2328 # we must not ever block the main coroutine
2281 local $Coro::idle = sub { 2329 local $Coro::idle = sub {
2384 Coro::cede; 2432 Coro::cede;
2385 last unless IO::AIO::nreqs || BDB::nreqs; 2433 last unless IO::AIO::nreqs || BDB::nreqs;
2386 warn "iterate..."; 2434 warn "iterate...";
2387 } 2435 }
2388 2436
2437 ++$RELOAD;
2438
2389 warn "cancelling all extension coros"; 2439 warn "cancelling all extension coros";
2390 $_->cancel for values %EXT_CORO; 2440 $_->cancel for values %EXT_CORO;
2391 %EXT_CORO = (); 2441 %EXT_CORO = ();
2392 2442
2393 warn "removing commands"; 2443 warn "removing commands";
2450 2500
2451 warn "loading extensions"; 2501 warn "loading extensions";
2452 cf::load_extensions; 2502 cf::load_extensions;
2453 2503
2454 warn "reattaching attachments to objects/players"; 2504 warn "reattaching attachments to objects/players";
2455 _global_reattach; 2505 _global_reattach; # objects, sockets
2456 warn "reattaching attachments to maps"; 2506 warn "reattaching attachments to maps";
2457 reattach $_ for values %MAP; 2507 reattach $_ for values %MAP;
2508 warn "reattaching attachments to players";
2509 reattach $_ for values %PLAYER;
2458 2510
2459 warn "loading reloadable resources"; 2511 warn "loading reloadable resources";
2460 init_resources; 2512 reload_resources;
2461 2513
2462 warn "leaving sync_job"; 2514 warn "leaving sync_job";
2463 2515
2464 1 2516 1
2465 } or do { 2517 } or do {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines