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.129 by root, Mon Nov 20 16:41:46 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.96'; 20 $VERSION = '0.97';
21 21
22 use XSLoader; 22 use XSLoader;
23 XSLoader::load "CFPlus", $VERSION; 23 XSLoader::load "CFPlus", $VERSION;
24} 24}
25 25
27 27
28use AnyEvent (); 28use AnyEvent ();
29use BerkeleyDB; 29use BerkeleyDB;
30use Pod::POM (); 30use Pod::POM ();
31use Scalar::Util (); 31use Scalar::Util ();
32use File::Path ();
32use Storable (); # finally 33use Storable (); # finally
33 34
34BEGIN { 35BEGIN {
35 use Crossfire::Protocol::Base (); 36 use Crossfire::Protocol::Base ();
36 *to_json = \&Crossfire::Protocol::Base::to_json; 37 *to_json = \&Crossfire::Protocol::Base::to_json;
47 bless \(my $cb = $_[0]), "CFPlus::Guard" 48 bless \(my $cb = $_[0]), "CFPlus::Guard"
48} 49}
49 50
50sub CFPlus::Guard::DESTROY { 51sub CFPlus::Guard::DESTROY {
51 ${$_[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
52} 63}
53 64
54sub asxml($) { 65sub asxml($) {
55 local $_ = $_[0]; 66 local $_ = $_[0];
56 67
262 -Property => DB_CHKSUM, 273 -Property => DB_CHKSUM,
263 -Flags => DB_CREATE | DB_UPGRADE, 274 -Flags => DB_CREATE | DB_UPGRADE,
264 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 275 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
265} 276}
266 277
267{ 278our $DB_HOME = "$Crossfire::VARDIR/cfplus";
279
280sub open_db {
268 use strict; 281 use strict;
269 282
270 mkdir "$Crossfire::VARDIR/cfplus", 0777; 283 mkdir $DB_HOME, 0777;
271 my $recover = $BerkeleyDB::db_version >= 4.4 284 my $recover = $BerkeleyDB::db_version >= 4.4
272 ? eval "DB_REGISTER | DB_RECOVER" 285 ? eval "DB_REGISTER | DB_RECOVER"
273 : 0; 286 : 0;
274 287
275 $DB_ENV = new BerkeleyDB::Env 288 $DB_ENV = new BerkeleyDB::Env
276 -Home => "$Crossfire::VARDIR/cfplus", 289 -Home => $DB_HOME,
277 -Cachesize => 1_000_000, 290 -Cachesize => 1_000_000,
278 -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt", 291 -ErrFile => "$DB_HOME/errorlog.txt",
279# -ErrPrefix => "DATABASE", 292# -ErrPrefix => "DATABASE",
280 -Verbose => 1, 293 -Verbose => 1,
281 -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,
282 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, 295 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE,
283 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";
284 297
285 $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;
286} 306}
287 307
288package CFPlus::Layout; 308package CFPlus::Layout;
289 309
290$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub { 310$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub {
388 } elsif ($ev->{button} == 3) { 408 } elsif ($ev->{button} == 3) {
389 my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop'; 409 my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop';
390 if ($self->{container} == $::CONN->{open_container}) { 410 if ($self->{container} == $::CONN->{open_container}) {
391 $move_prefix = "take"; 411 $move_prefix = "take";
392 } 412 }
413
414 my $shortname = CFPlus::shorten $self->{name}, 14;
393 415
394 my @menu_items = ( 416 my @menu_items = (
395 ["examine", sub { $::CONN->send ("examine $self->{tag}") }], 417 ["examine", sub { $::CONN->send ("examine $self->{tag}") }],
396 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 418 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
397 ["ignite/thaw", # first try of an easier use of flint&steel 419 ["ignite/thaw", # first try of an easier use of flint&steel
433 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") }) 455 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") })
434 } 456 }
435 ] 457 ]
436 ) 458 )
437 ), 459 ),
460 ["bind <i>apply $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["apply $self->{name}"]) }],
438 ); 461 );
439 462
440 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 463 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
441 } 464 }
442 465

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines