--- deliantra/Deliantra-Client/DC.pm 2009/09/15 18:49:55 1.207 +++ deliantra/Deliantra-Client/DC.pm 2012/11/21 13:23:10 1.217 @@ -19,7 +19,7 @@ our $VERSION; BEGIN { - $VERSION = '2.05'; + $VERSION = '3.0'; use XSLoader; XSLoader::load "Deliantra::Client", $VERSION; @@ -38,6 +38,15 @@ use JSON::XS qw(encode_json decode_json); use Guard qw(guard); +# modules to support other DC::* packages +use List::Util (); +use IO::AIO (); +use Coro::AIO (); +use AnyEvent::AIO (); + +use Deliantra::Util (); +use Deliantra::Protocol::Constants (); + =item shorten $string[, $maxlength] =cut @@ -58,6 +67,27 @@ $_ } +sub sanitise_cfxml($) { + local $_ = shift; + + # we now weed out all tags we do not support + s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>) + }{ + "<" + }gex; + + # now all entities + s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; + + # handle some elements + s/(.*?)<\/fg>/$2<\/span>/gs; + s/(.*?)<\/fg>/$2<\/span>/gs; + + s/\s+$//; + + $_ +} + sub background(&;&) { my ($bg, $cb) = @_; @@ -181,13 +211,13 @@ } } -sub read_cfg { +sub read_cfg($) { my ($file) = @_; $::CFG = (load_json $file) || (load_json "$file.bak"); } -sub write_cfg { +sub write_cfg($) { my $file = "$Deliantra::VARDIR/client.cf"; $::CFG->{VERSION} = $::VERSION; @@ -202,6 +232,75 @@ rename "$file~", $file; } +sub load_cfg() { + if (-e "$Deliantra::VARDIR/client.cf") { + DC::read_cfg "$Deliantra::VARDIR/client.cf"; + } else { + $::CFG = { cfg_schema => 1, db_schema => 1 }; + } +} + +sub save_cfg() { + write_cfg "$Deliantra::VARDIR/client.cf"; +} + +sub upgrade_cfg() { + my %DEF_CFG = ( + config_autosave => 1, + sdl_mode => undef, + fullscreen => 1, + fast => 0, + force_opengl11 => undef, + disable_alpha => 0, + smooth_movement => 1, + smooth_transitions => 1, + texture_compression => 1, + map_scale => 1, + fow_enable => 1, + fow_intensity => 0, + fow_texture => 0, + map_smoothing => 1, + gui_fontsize => 1, + log_fontsize => 0.7, + gauge_fontsize => 1, + gauge_size => 0.35, + stat_fontsize => 0.7, + mapsize => 100, + audio_enable => 1, + audio_hw_channels => 0, + audio_hw_frequency => 0, + audio_hw_chunksize => 0, + audio_mix_channels => 8, + effects_enable => 1, + effects_volume => 1, + bgm_enable => 1, + bgm_volume => 0.5, + output_rate => "", + pickup => Deliantra::Protocol::Constants::PICKUP_SPELLBOOK + | Deliantra::Protocol::Constants::PICKUP_SKILLSCROLL + | Deliantra::Protocol::Constants::PICKUP_VALUABLES, + inv_sort => "mtime", + default => "profile", # default profile + show_tips => 1, + logview_max_par => 1000, + shift_fire_stop => 0, + uitheme => "wood", + map_shift_x => -24, # arbitrary + map_shift_y => +24, # arbitrary + ); + + while (my ($k, $v) = each %DEF_CFG) { + $::CFG->{$k} = $v unless exists $::CFG->{$k}; + } + + if ($::CFG->{cfg_schema} < 1) { + for my $profile (values %{ $::CFG->{profile} }) { + $profile->{password} = unpack "H*", Deliantra::Util::hash_pw $profile->{password}; + } + $::CFG->{cfg_schema} = 1; + } +} + sub http_proxy { my @proxy = win32_proxy_info;