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.112 by root, Sun Aug 13 03:20:53 2006 UTC vs.
Revision 1.122 by root, Sun Oct 1 14:48:50 2006 UTC

12 12
13=cut 13=cut
14 14
15package CFPlus; 15package CFPlus;
16 16
17use Carp ();
18
17BEGIN { 19BEGIN {
18 $VERSION = '0.2'; 20 $VERSION = '0.52';
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
69my %DB_SYNC; 79my %DB_SYNC;
70 80
71sub put($$$) { 81sub put($$$) {
72 my ($db, $key, $data) = @_; 82 my ($db, $key, $data) = @_;
73 83
84 my $hkey = $db + 0;
85 Scalar::Util::weaken $db;
74 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync }); 86 $DB_SYNC{$hkey} ||= AnyEvent->timer (after => 5, cb => sub {
87 delete $DB_SYNC{$hkey};
88 $db->db_sync if $db;
89 });
75 90
76 $db->db_put ($key => $data) 91 $db->db_put ($key => $data)
77} 92}
78 93
79package CFPlus; 94package CFPlus;
123 open my $fh, ">:utf8", $file 138 open my $fh, ">:utf8", $file
124 or return; 139 or return;
125 print $fh to_json $::CFG; 140 print $fh to_json $::CFG;
126} 141}
127 142
143sub http_proxy {
144 my @proxy = win32_proxy_info;
145
146 if (@proxy) {
147 "http://" . (@proxy < 2 ? "" : @proxy < 3 ? "$proxy[1]\@" : "$proxy[1]:$proxy[2]\@") . $proxy[0]
148 } elsif (exists $ENV{http_proxy}) {
149 $ENV{http_proxy}
150 } else {
151 ()
152 }
153}
154
155sub set_proxy {
156 my $proxy = http_proxy
157 or return;
158
159 $ENV{http_proxy} = $proxy;
160}
161
128our $DB_ENV; 162our $DB_ENV;
163our $DB_STATE;
164
165sub db_table($) {
166 my ($table) = @_;
167
168 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
169
170 new CFPlus::Database
171 -Env => $DB_ENV,
172 -Filename => $table,
173# -Filename => "database",
174# -Subname => $table,
175 -Property => DB_CHKSUM,
176 -Flags => DB_CREATE | DB_UPGRADE,
177 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
178}
129 179
130{ 180{
131 use strict; 181 use strict;
132 182
133 mkdir "$Crossfire::VARDIR/cfplus", 0777; 183 mkdir "$Crossfire::VARDIR/cfplus", 0777;
142# -ErrPrefix => "DATABASE", 192# -ErrPrefix => "DATABASE",
143 -Verbose => 1, 193 -Verbose => 1,
144 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, 194 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover,
145 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, 195 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE,
146 or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error"; 196 or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error";
147}
148 197
149sub db_table($) { 198 $DB_STATE = db_table "state";
150 my ($table) = @_;
151
152 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
153
154 new CFPlus::Database
155 -Env => $DB_ENV,
156 -Filename => $table,
157# -Filename => "database",
158# -Subname => $table,
159 -Property => DB_CHKSUM,
160 -Flags => DB_CREATE | DB_UPGRADE,
161 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
162} 199}
163 200
164package CFPlus::Layout; 201package CFPlus::Layout;
165 202
166$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub { 203$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub {
209} 246}
210 247
211sub do_n_dialog { 248sub do_n_dialog {
212 my ($cb) = @_; 249 my ($cb) = @_;
213 250
214 my $w = new CFPlus::UI::FancyFrame 251 my $w = new CFPlus::UI::Toplevel
215 on_delete => sub { $_[0]->destroy; 1 }, 252 on_delete => sub { $_[0]->destroy; 1 },
216 has_close_button => 1, 253 has_close_button => 1,
217 ; 254 ;
218 255
219 $w->add (my $vb = new CFPlus::UI::VBox x => "center", y => "center"); 256 $w->add (my $vb = new CFPlus::UI::VBox x => "center", y => "center");
281 &::open_string_query ("Text to inscribe", sub { 318 &::open_string_query ("Text to inscribe", sub {
282 my ($entry, $txt) = @_; 319 my ($entry, $txt) = @_;
283 $::CONN->send ("mark ". pack "N", $self->{tag}); 320 $::CONN->send ("mark ". pack "N", $self->{tag});
284 $::CONN->send ("command use_skill inscription $txt"); 321 $::CONN->send ("command use_skill inscription $txt");
285 }); 322 });
323 }
324 ],
325 ["rename", # first try of an easier use of flint&steel
326 sub {
327 &::open_string_query ("Rename item to:", sub {
328 my ($entry, $txt) = @_;
329 $::CONN->send ("mark ". pack "N", $self->{tag});
330 $::CONN->send ("command rename to <$txt>");
331 }, $self->{name},
332 "If you input no name or erase the current custom name, the custom name will be unset");
286 } 333 }
287 ], 334 ],
288 ["apply", sub { $::CONN->send ("apply $self->{tag}") }], 335 ["apply", sub { $::CONN->send ("apply $self->{tag}") }],
289 ( 336 (
290 $self->{flags} & F_LOCKED 337 $self->{flags} & F_LOCKED

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines