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.379 by root, Thu Oct 4 23:59:07 2007 UTC vs.
Revision 1.385 by root, Fri Oct 12 19:13:26 2007 UTC

4use strict; 4use strict;
5 5
6use Symbol; 6use Symbol;
7use List::Util; 7use List::Util;
8use Socket; 8use Socket;
9use Storable;
10use Event; 9use Event;
11use Opcode; 10use Opcode;
12use Safe; 11use Safe;
13use Safe::Hole; 12use Safe::Hole;
13use Storable ();
14 14
15use Coro 3.64 (); 15use Coro 4.1 ();
16use Coro::State; 16use Coro::State;
17use Coro::Handle; 17use Coro::Handle;
18use Coro::Event; 18use Coro::Event;
19use Coro::Timer; 19use Coro::Timer;
20use Coro::Signal; 20use Coro::Signal;
27use BDB (); 27use BDB ();
28use Data::Dumper; 28use Data::Dumper;
29use Digest::MD5; 29use Digest::MD5;
30use Fcntl; 30use Fcntl;
31use YAML::Syck (); 31use YAML::Syck ();
32use IO::AIO 2.32 (); 32use IO::AIO 2.51 ();
33use Time::HiRes; 33use Time::HiRes;
34use Compress::LZF; 34use Compress::LZF;
35use Digest::MD5 (); 35use Digest::MD5 ();
36 36
37# configure various modules to our taste 37# configure various modules to our taste
373 } 373 }
374 } 374 }
375 } 375 }
376 376
377 if (@SLOT_QUEUE) { 377 if (@SLOT_QUEUE) {
378 # we do not use wait_For_tick() as it returns immediately when tick is inactive 378 # we do not use wait_for_tick() as it returns immediately when tick is inactive
379 push @cf::WAIT_FOR_TICK, $signal; 379 push @cf::WAIT_FOR_TICK, $signal;
380 $signal->wait; 380 $signal->wait;
381 } else { 381 } else {
382 Coro::schedule; 382 Coro::schedule;
383 } 383 }
427 my $time = Event::time; 427 my $time = Event::time;
428 428
429 # this is the main coro, too bad, we have to block 429 # this is the main coro, too bad, we have to block
430 # till the operation succeeds, freezing the server :/ 430 # till the operation succeeds, freezing the server :/
431 431
432 LOG llevError | logBacktrace, Carp::longmess "sync job";#d# 432 LOG llevError, Carp::longmess "sync job";#d#
433 433
434 # TODO: use suspend/resume instead 434 # TODO: use suspend/resume instead
435 # (but this is cancel-safe) 435 # (but this is cancel-safe)
436 my $freeze_guard = freeze_mainloop; 436 my $freeze_guard = freeze_mainloop;
437 437
971# 971#
972 972
973sub _can_merge { 973sub _can_merge {
974 my ($ob1, $ob2) = @_; 974 my ($ob1, $ob2) = @_;
975 975
976 return 1;#d#
977
978 #todo#d# kill yourself and do some recursive checking manually without storable
979 sync_job {
980 my $guard = Coro::Storable::guard;
976 local $Storable::canonical = 1; 981 local $Storable::canonical = 1;
977 my $fob1 = Storable::freeze $ob1; 982 my $fob1 = Storable::freeze $ob1;
978 my $fob2 = Storable::freeze $ob2; 983 my $fob2 = Storable::freeze $ob2;
979
980 $fob1 eq $fob2 984 $fob1 eq $fob2
985 }
981} 986}
982 987
983sub reattach { 988sub reattach {
984 # basically do the same as instantiate, without calling instantiate 989 # basically do the same as instantiate, without calling instantiate
985 my ($obj) = @_; 990 my ($obj) = @_;
1046 close $fh; 1051 close $fh;
1047 1052
1048 if (@$objs) { 1053 if (@$objs) {
1049 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { 1054 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) {
1050 chmod SAVE_MODE, $fh; 1055 chmod SAVE_MODE, $fh;
1051 my $data = Storable::nfreeze { version => 1, objs => $objs }; 1056 my $data = Coro::Storable::blocking_nfreeze { version => 1, objs => $objs };
1052 aio_write $fh, 0, (length $data), $data, 0; 1057 aio_write $fh, 0, (length $data), $data, 0;
1053 aio_fsync $fh if $cf::USE_FSYNC; 1058 aio_fsync $fh if $cf::USE_FSYNC;
1054 close $fh; 1059 close $fh;
1055 aio_rename "$filename.pst~", "$filename.pst"; 1060 aio_rename "$filename.pst~", "$filename.pst";
1056 } 1061 }
1087 1092
1088 unless (aio_stat "$filename.pst") { 1093 unless (aio_stat "$filename.pst") {
1089 (aio_load "$filename.pst", $av) >= 0 1094 (aio_load "$filename.pst", $av) >= 0
1090 or return; 1095 or return;
1091 1096
1092 $av = eval { (Storable::thaw $av)->{objs} }; 1097 my $st = eval { Coro::Storable::thaw $av }
1098 || eval { my $guard = Coro::Storable::guard; Storable::thaw $av }; #d# compatibility, remove
1099 $av = $st->{objs};
1093 } 1100 }
1094 1101
1095 utf8::decode (my $decname = $filename); 1102 utf8::decode (my $decname = $filename);
1096 warn sprintf "loading %s (%d,%d)\n", 1103 warn sprintf "loading %s (%d,%d)\n",
1097 $decname, length $data, scalar @{$av || []}; 1104 $decname, length $data, scalar @{$av || []};
2894=pod 2901=pod
2895 2902
2896The following functions and methods are available within a safe environment: 2903The following functions and methods are available within a safe environment:
2897 2904
2898 cf::object 2905 cf::object
2899 contr pay_amount pay_player map x y force_find force_add 2906 contr pay_amount pay_player map x y force_find force_add destroy
2900 insert remove name archname title slaying race decrease_ob_nr 2907 insert remove name archname title slaying race decrease_ob_nr
2901 2908
2902 cf::object::player 2909 cf::object::player
2903 player 2910 player
2904 2911
2911=cut 2918=cut
2912 2919
2913for ( 2920for (
2914 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y 2921 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y
2915 insert remove inv name archname title slaying race 2922 insert remove inv name archname title slaying race
2916 decrease_ob_nr)], 2923 decrease_ob_nr destroy)],
2917 ["cf::object::player" => qw(player)], 2924 ["cf::object::player" => qw(player)],
2918 ["cf::player" => qw(peaceful)], 2925 ["cf::player" => qw(peaceful)],
2919 ["cf::map" => qw(trigger)], 2926 ["cf::map" => qw(trigger)],
2920) { 2927) {
2921 no strict 'refs'; 2928 no strict 'refs';
3278 # and maps saved/destroyed asynchronously. 3285 # and maps saved/destroyed asynchronously.
3279 warn "begin emergency player save\n"; 3286 warn "begin emergency player save\n";
3280 for my $login (keys %cf::PLAYER) { 3287 for my $login (keys %cf::PLAYER) {
3281 my $pl = $cf::PLAYER{$login} or next; 3288 my $pl = $cf::PLAYER{$login} or next;
3282 $pl->valid or next; 3289 $pl->valid or next;
3290 delete $pl->{unclean_save}; # not strictly necessary, but cannot hurt
3283 $pl->save; 3291 $pl->save;
3284 } 3292 }
3285 warn "end emergency player save\n"; 3293 warn "end emergency player save\n";
3286 3294
3287 warn "begin emergency map save\n"; 3295 warn "begin emergency map save\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines