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.132 by root, Wed Dec 6 00:04:13 2006 UTC vs.
Revision 1.135 by root, Thu Dec 7 15:57:13 2006 UTC

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 my $HOME = "$Crossfire::VARDIR/cfplus-$BerkeleyDB::db_version";
271
272 mkdir $HOME, 0777; 283 mkdir $DB_HOME, 0777;
273 my $recover = $BerkeleyDB::db_version >= 4.4 284 my $recover = $BerkeleyDB::db_version >= 4.4
274 ? eval "DB_REGISTER | DB_RECOVER" 285 ? eval "DB_REGISTER | DB_RECOVER"
275 : 0; 286 : 0;
276 287
277 $DB_ENV = new BerkeleyDB::Env 288 $DB_ENV = new BerkeleyDB::Env
278 -Home => $HOME, 289 -Home => $DB_HOME,
279 -Cachesize => 1_000_000, 290 -Cachesize => 1_000_000,
280 -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt", 291 -ErrFile => "$DB_HOME/errorlog.txt",
281# -ErrPrefix => "DATABASE", 292# -ErrPrefix => "DATABASE",
282 -Verbose => 1, 293 -Verbose => 1,
283 -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,
284 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, 295 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE,
285 or die "unable to create/open database home $HOME: $BerkeleyDB::Error"; 296 or die "unable to create/open database home $DB_HOME: $BerkeleyDB::Error";
286 297
287 $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;
288} 306}
289 307
290package CFPlus::Layout; 308package CFPlus::Layout;
291 309
292$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub { 310$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub {
390 } elsif ($ev->{button} == 3) { 408 } elsif ($ev->{button} == 3) {
391 my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop'; 409 my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop';
392 if ($self->{container} == $::CONN->{open_container}) { 410 if ($self->{container} == $::CONN->{open_container}) {
393 $move_prefix = "take"; 411 $move_prefix = "take";
394 } 412 }
413
414 my $shortname = CFPlus::shorten $self->{name}, 14;
395 415
396 my @menu_items = ( 416 my @menu_items = (
397 ["examine", sub { $::CONN->send ("examine $self->{tag}") }], 417 ["examine", sub { $::CONN->send ("examine $self->{tag}") }],
398 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 418 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
399 ["ignite/thaw", # first try of an easier use of flint&steel 419 ["ignite/thaw", # first try of an easier use of flint&steel
435 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") }) 455 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") })
436 } 456 }
437 ] 457 ]
438 ) 458 )
439 ), 459 ),
440 ["bind <i>apply $self->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["apply $self->{name}"]) }], 460 ["bind <i>apply $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["apply $self->{name}"]) }],
441 ); 461 );
442 462
443 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 463 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
444 } 464 }
445 465

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines