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.127 by root, Thu Nov 16 19:42:44 2006 UTC vs.
Revision 1.135 by root, Thu Dec 7 15:57:13 2006 UTC

15package CFPlus; 15package CFPlus;
16 16
17use Carp (); 17use Carp ();
18 18
19BEGIN { 19BEGIN {
20 $VERSION = '0.95'; 20 $VERSION = '0.97';
21 21
22 use XSLoader; 22 use XSLoader;
23 XSLoader::load "CFPlus", $VERSION; 23 XSLoader::load "CFPlus", $VERSION;
24}
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} 24}
34 25
35use utf8; 26use utf8;
36 27
37use AnyEvent (); 28use AnyEvent ();
38use BerkeleyDB; 29use BerkeleyDB;
39use Pod::POM (); 30use Pod::POM ();
40use Scalar::Util (); 31use Scalar::Util ();
32use File::Path ();
41use Storable (); # finally 33use Storable (); # finally
42 34
43BEGIN { 35BEGIN {
44 use Crossfire::Protocol::Base (); 36 use Crossfire::Protocol::Base ();
45 *to_json = \&Crossfire::Protocol::Base::to_json; 37 *to_json = \&Crossfire::Protocol::Base::to_json;
56 bless \(my $cb = $_[0]), "CFPlus::Guard" 48 bless \(my $cb = $_[0]), "CFPlus::Guard"
57} 49}
58 50
59sub CFPlus::Guard::DESTROY { 51sub CFPlus::Guard::DESTROY {
60 ${$_[0]}->() 52 ${$_[0]}->()
53}
54
55=item shorten $string[, $maxlength]
56
57=cut
58
59sub shorten($;$) {
60 my ($str, $len) = @_;
61 substr $str, $len, (length $str), "..." if $len + 3 <= length $str;
62 $str
61} 63}
62 64
63sub asxml($) { 65sub asxml($) {
64 local $_ = $_[0]; 66 local $_ = $_[0];
65 67
271 -Property => DB_CHKSUM, 273 -Property => DB_CHKSUM,
272 -Flags => DB_CREATE | DB_UPGRADE, 274 -Flags => DB_CREATE | DB_UPGRADE,
273 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 275 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
274} 276}
275 277
276{ 278our $DB_HOME = "$Crossfire::VARDIR/cfplus";
279
280sub open_db {
277 use strict; 281 use strict;
278 282
279 mkdir "$Crossfire::VARDIR/cfplus", 0777; 283 mkdir $DB_HOME, 0777;
280 my $recover = $BerkeleyDB::db_version >= 4.4 284 my $recover = $BerkeleyDB::db_version >= 4.4
281 ? eval "DB_REGISTER | DB_RECOVER" 285 ? eval "DB_REGISTER | DB_RECOVER"
282 : 0; 286 : 0;
283 287
284 $DB_ENV = new BerkeleyDB::Env 288 $DB_ENV = new BerkeleyDB::Env
285 -Home => "$Crossfire::VARDIR/cfplus", 289 -Home => $DB_HOME,
286 -Cachesize => 1_000_000, 290 -Cachesize => 1_000_000,
287 -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt", 291 -ErrFile => "$DB_HOME/errorlog.txt",
288# -ErrPrefix => "DATABASE", 292# -ErrPrefix => "DATABASE",
289 -Verbose => 1, 293 -Verbose => 1,
290 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, 294 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover,
291 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, 295 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE,
292 or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error"; 296 or die "unable to create/open database home $DB_HOME: $BerkeleyDB::Error";
293 297
294 $DB_STATE = db_table "state"; 298 $DB_STATE = db_table "state";
299
300 1
301}
302
303unless (eval { open_db }) {
304 File::Path::rmtree $DB_HOME;
305 open_db;
295} 306}
296 307
297package CFPlus::Layout; 308package CFPlus::Layout;
298 309
299$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub { 310$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub {
397 } elsif ($ev->{button} == 3) { 408 } elsif ($ev->{button} == 3) {
398 my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop'; 409 my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop';
399 if ($self->{container} == $::CONN->{open_container}) { 410 if ($self->{container} == $::CONN->{open_container}) {
400 $move_prefix = "take"; 411 $move_prefix = "take";
401 } 412 }
413
414 my $shortname = CFPlus::shorten $self->{name}, 14;
402 415
403 my @menu_items = ( 416 my @menu_items = (
404 ["examine", sub { $::CONN->send ("examine $self->{tag}") }], 417 ["examine", sub { $::CONN->send ("examine $self->{tag}") }],
405 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 418 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
406 ["ignite/thaw", # first try of an easier use of flint&steel 419 ["ignite/thaw", # first try of an easier use of flint&steel
442 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") }) 455 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") })
443 } 456 }
444 ] 457 ]
445 ) 458 )
446 ), 459 ),
460 ["bind <i>apply $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["apply $self->{name}"]) }],
447 ); 461 );
448 462
449 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 463 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
450 } 464 }
451 465

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines