ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.119 by root, Tue Sep 12 20:51:17 2006 UTC vs.
Revision 1.126 by root, Tue Nov 7 22:41:27 2006 UTC

12 12
13=cut 13=cut
14 14
15package CFPlus; 15package CFPlus;
16 16
17use Carp ();
18
17BEGIN { 19BEGIN {
18 $VERSION = '0.51'; 20 $VERSION = '0.95';
19 21
20 use XSLoader; 22 use XSLoader;
21 XSLoader::load "CFPlus", $VERSION; 23 XSLoader::load "CFPlus", $VERSION;
22} 24}
23 25
26BEGIN {
27 $SIG{__DIE__} = sub {
28 return if CFPlus::in_destruct;
29 #CFPlus::fatal $_[0];#d#
30 CFPlus::error Carp::longmess $_[0];#d#
31 die;#d#
32 };
33}
34
24use utf8; 35use utf8;
25 36
26use Carp ();
27use AnyEvent (); 37use AnyEvent ();
28use BerkeleyDB; 38use BerkeleyDB;
29use Pod::POM (); 39use Pod::POM ();
30use Scalar::Util (); 40use Scalar::Util ();
31use Storable (); # finally 41use Storable (); # finally
50 s/&/&/g; 60 s/&/&/g;
51 s/>/>/g; 61 s/>/>/g;
52 s/</&lt;/g; 62 s/</&lt;/g;
53 63
54 $_ 64 $_
65}
66
67sub socketpipe() {
68 socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC
69 or die "cannot establish bidiretcional pipe: $!\n";
70
71 ($fh1, $fh2)
72}
73
74sub background(&) {
75 my ($cb) = @_;
76
77 my ($fh_r, $fh_w) = CFPlus::socketpipe;
78
79 my $pid = fork;
80
81 if (defined $pid && !$pid) {
82 local $SIG{__DIE__};
83
84 open STDOUT, ">&", $fh_w;
85 open STDERR, ">&", $fh_w;
86 close $fh_r;
87 close $fh_w;
88
89 $| = 1;
90
91 eval { $cb->() };
92
93 if ($@) {
94 my $msg = $@;
95 $msg =~ s/\n+/\n/;
96 warn "FATAL: $msg";
97 CFPlus::_exit 1;
98 }
99
100 # win32 is fucked up, of course. exit will clean stuff up,
101 # which destroys our database etc. _exit will exit ALL
102 # forked processes, because of the dreaded fork emulation.
103 CFPlus::_exit 0;
104 }
105
106 close $fh_w;
107
108 my $buffer;
109
110 my $w; $w = AnyEvent->io (fh => $fh_r, poll => 'r', cb => sub {
111 unless (sysread $fh_r, $buffer, 4096, length $buffer) {
112 undef $w;
113 $buffer .= "done\n";
114 }
115
116 while ($buffer =~ s/^(.*)\n//) {
117 my $line = $1;
118 $line =~ s/\s+$//;
119 utf8::decode $line;
120 ::message ({
121 markup => "editor($pid): " . CFPlus::asxml $line,
122 });
123 }
124 });
55} 125}
56 126
57package CFPlus::Database; 127package CFPlus::Database;
58 128
59our @ISA = BerkeleyDB::Btree::; 129our @ISA = BerkeleyDB::Btree::;
128 open my $fh, ">:utf8", $file 198 open my $fh, ">:utf8", $file
129 or return; 199 or return;
130 print $fh to_json $::CFG; 200 print $fh to_json $::CFG;
131} 201}
132 202
203sub http_proxy {
204 my @proxy = win32_proxy_info;
205
206 if (@proxy) {
207 "http://" . (@proxy < 2 ? "" : @proxy < 3 ? "$proxy[1]\@" : "$proxy[1]:$proxy[2]\@") . $proxy[0]
208 } elsif (exists $ENV{http_proxy}) {
209 $ENV{http_proxy}
210 } else {
211 ()
212 }
213}
214
215sub set_proxy {
216 my $proxy = http_proxy
217 or return;
218
219 $ENV{http_proxy} = $proxy;
220}
221
133our $DB_ENV; 222our $DB_ENV;
223our $DB_STATE;
224
225sub db_table($) {
226 my ($table) = @_;
227
228 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
229
230 new CFPlus::Database
231 -Env => $DB_ENV,
232 -Filename => $table,
233# -Filename => "database",
234# -Subname => $table,
235 -Property => DB_CHKSUM,
236 -Flags => DB_CREATE | DB_UPGRADE,
237 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
238}
134 239
135{ 240{
136 use strict; 241 use strict;
137 242
138 mkdir "$Crossfire::VARDIR/cfplus", 0777; 243 mkdir "$Crossfire::VARDIR/cfplus", 0777;
147# -ErrPrefix => "DATABASE", 252# -ErrPrefix => "DATABASE",
148 -Verbose => 1, 253 -Verbose => 1,
149 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, 254 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover,
150 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, 255 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE,
151 or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error"; 256 or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error";
152}
153 257
154sub db_table($) { 258 $DB_STATE = db_table "state";
155 my ($table) = @_;
156
157 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
158
159 new CFPlus::Database
160 -Env => $DB_ENV,
161 -Filename => $table,
162# -Filename => "database",
163# -Subname => $table,
164 -Property => DB_CHKSUM,
165 -Flags => DB_CREATE | DB_UPGRADE,
166 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
167} 259}
168 260
169package CFPlus::Layout; 261package CFPlus::Layout;
170 262
171$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub { 263$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines