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.212 by root, Wed Jan 4 11:23:23 2012 UTC vs.
Revision 1.217 by root, Wed Nov 21 13:23:10 2012 UTC

17use Carp (); 17use Carp ();
18 18
19our $VERSION; 19our $VERSION;
20 20
21BEGIN { 21BEGIN {
22 $VERSION = '2.11'; 22 $VERSION = '3.0';
23 23
24 use XSLoader; 24 use XSLoader;
25 XSLoader::load "Deliantra::Client", $VERSION; 25 XSLoader::load "Deliantra::Client", $VERSION;
26} 26}
27 27
42use List::Util (); 42use List::Util ();
43use IO::AIO (); 43use IO::AIO ();
44use Coro::AIO (); 44use Coro::AIO ();
45use AnyEvent::AIO (); 45use AnyEvent::AIO ();
46 46
47use Deliantra::Util ();
48use Deliantra::Protocol::Constants ();
49
47=item shorten $string[, $maxlength] 50=item shorten $string[, $maxlength]
48 51
49=cut 52=cut
50 53
51sub shorten($;$) { 54sub shorten($;$) {
58 local $_ = $_[0]; 61 local $_ = $_[0];
59 62
60 s/&/&/g; 63 s/&/&/g;
61 s/>/>/g; 64 s/>/>/g;
62 s/</&lt;/g; 65 s/</&lt;/g;
66
67 $_
68}
69
70sub sanitise_cfxml($) {
71 local $_ = shift;
72
73 # we now weed out all tags we do not support
74 s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>)
75 }{
76 "&lt;"
77 }gex;
78
79 # now all entities
80 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
81
82 # handle some elements
83 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
84 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
85
86 s/\s+$//;
63 87
64 $_ 88 $_
65} 89}
66 90
67sub background(&;&) { 91sub background(&;&) {
185 209
186 %THEME = ( %$theme, %THEME ); 210 %THEME = ( %$theme, %THEME );
187 } 211 }
188} 212}
189 213
190sub read_cfg { 214sub read_cfg($) {
191 my ($file) = @_; 215 my ($file) = @_;
192 216
193 $::CFG = (load_json $file) || (load_json "$file.bak"); 217 $::CFG = (load_json $file) || (load_json "$file.bak");
194} 218}
195 219
196sub write_cfg { 220sub write_cfg($) {
197 my $file = "$Deliantra::VARDIR/client.cf"; 221 my $file = "$Deliantra::VARDIR/client.cf";
198 222
199 $::CFG->{VERSION} = $::VERSION; 223 $::CFG->{VERSION} = $::VERSION;
200 $::CFG->{layout} = DC::UI::get_layout (); 224 $::CFG->{layout} = DC::UI::get_layout ();
201 225
204 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); 228 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG);
205 close $fh; 229 close $fh;
206 230
207 rename $file, "$file.bak"; 231 rename $file, "$file.bak";
208 rename "$file~", $file; 232 rename "$file~", $file;
233}
234
235sub load_cfg() {
236 if (-e "$Deliantra::VARDIR/client.cf") {
237 DC::read_cfg "$Deliantra::VARDIR/client.cf";
238 } else {
239 $::CFG = { cfg_schema => 1, db_schema => 1 };
240 }
241}
242
243sub save_cfg() {
244 write_cfg "$Deliantra::VARDIR/client.cf";
245}
246
247sub upgrade_cfg() {
248 my %DEF_CFG = (
249 config_autosave => 1,
250 sdl_mode => undef,
251 fullscreen => 1,
252 fast => 0,
253 force_opengl11 => undef,
254 disable_alpha => 0,
255 smooth_movement => 1,
256 smooth_transitions => 1,
257 texture_compression => 1,
258 map_scale => 1,
259 fow_enable => 1,
260 fow_intensity => 0,
261 fow_texture => 0,
262 map_smoothing => 1,
263 gui_fontsize => 1,
264 log_fontsize => 0.7,
265 gauge_fontsize => 1,
266 gauge_size => 0.35,
267 stat_fontsize => 0.7,
268 mapsize => 100,
269 audio_enable => 1,
270 audio_hw_channels => 0,
271 audio_hw_frequency => 0,
272 audio_hw_chunksize => 0,
273 audio_mix_channels => 8,
274 effects_enable => 1,
275 effects_volume => 1,
276 bgm_enable => 1,
277 bgm_volume => 0.5,
278 output_rate => "",
279 pickup => Deliantra::Protocol::Constants::PICKUP_SPELLBOOK
280 | Deliantra::Protocol::Constants::PICKUP_SKILLSCROLL
281 | Deliantra::Protocol::Constants::PICKUP_VALUABLES,
282 inv_sort => "mtime",
283 default => "profile", # default profile
284 show_tips => 1,
285 logview_max_par => 1000,
286 shift_fire_stop => 0,
287 uitheme => "wood",
288 map_shift_x => -24, # arbitrary
289 map_shift_y => +24, # arbitrary
290 );
291
292 while (my ($k, $v) = each %DEF_CFG) {
293 $::CFG->{$k} = $v unless exists $::CFG->{$k};
294 }
295
296 if ($::CFG->{cfg_schema} < 1) {
297 for my $profile (values %{ $::CFG->{profile} }) {
298 $profile->{password} = unpack "H*", Deliantra::Util::hash_pw $profile->{password};
299 }
300 $::CFG->{cfg_schema} = 1;
301 }
209} 302}
210 303
211sub http_proxy { 304sub http_proxy {
212 my @proxy = win32_proxy_info; 305 my @proxy = win32_proxy_info;
213 306

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines