… | |
… | |
42 | use List::Util (); |
42 | use List::Util (); |
43 | use IO::AIO (); |
43 | use IO::AIO (); |
44 | use Coro::AIO (); |
44 | use Coro::AIO (); |
45 | use AnyEvent::AIO (); |
45 | use AnyEvent::AIO (); |
46 | |
46 | |
|
|
47 | use Deliantra::Util (); |
47 | use Deliantra::Protocol::Constants (); |
48 | use Deliantra::Protocol::Constants (); |
48 | |
49 | |
49 | =item shorten $string[, $maxlength] |
50 | =item shorten $string[, $maxlength] |
50 | |
51 | |
51 | =cut |
52 | =cut |
… | |
… | |
187 | |
188 | |
188 | %THEME = ( %$theme, %THEME ); |
189 | %THEME = ( %$theme, %THEME ); |
189 | } |
190 | } |
190 | } |
191 | } |
191 | |
192 | |
192 | sub read_cfg { |
193 | sub read_cfg($) { |
193 | my ($file) = @_; |
194 | my ($file) = @_; |
194 | |
195 | |
195 | $::CFG = (load_json $file) || (load_json "$file.bak"); |
196 | $::CFG = (load_json $file) || (load_json "$file.bak"); |
196 | } |
197 | } |
197 | |
198 | |
198 | sub write_cfg { |
199 | sub write_cfg($) { |
199 | my $file = "$Deliantra::VARDIR/client.cf"; |
200 | my $file = "$Deliantra::VARDIR/client.cf"; |
200 | |
201 | |
201 | $::CFG->{VERSION} = $::VERSION; |
202 | $::CFG->{VERSION} = $::VERSION; |
202 | $::CFG->{layout} = DC::UI::get_layout (); |
203 | $::CFG->{layout} = DC::UI::get_layout (); |
203 | |
204 | |
… | |
… | |
206 | print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); |
207 | print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); |
207 | close $fh; |
208 | close $fh; |
208 | |
209 | |
209 | rename $file, "$file.bak"; |
210 | rename $file, "$file.bak"; |
210 | rename "$file~", $file; |
211 | rename "$file~", $file; |
|
|
212 | } |
|
|
213 | |
|
|
214 | sub load_cfg() { |
|
|
215 | if (-e "$Deliantra::VARDIR/client.cf") { |
|
|
216 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
|
|
217 | } else { |
|
|
218 | $::CFG = { cfg_schema => 1, db_schema => 1 }; |
|
|
219 | } |
|
|
220 | } |
|
|
221 | |
|
|
222 | sub save_cfg() { |
|
|
223 | write_cfg "$Deliantra::VARDIR/client.cf"; |
211 | } |
224 | } |
212 | |
225 | |
213 | sub upgrade_cfg() { |
226 | sub upgrade_cfg() { |
214 | my %DEF_CFG = ( |
227 | my %DEF_CFG = ( |
215 | config_autosave => 1, |
228 | config_autosave => 1, |
… | |
… | |
251 | logview_max_par => 1000, |
264 | logview_max_par => 1000, |
252 | shift_fire_stop => 0, |
265 | shift_fire_stop => 0, |
253 | uitheme => "wood", |
266 | uitheme => "wood", |
254 | map_shift_x => -24, # arbitrary |
267 | map_shift_x => -24, # arbitrary |
255 | map_shift_y => +24, # arbitrary |
268 | map_shift_y => +24, # arbitrary |
256 | #db_schema => 0, |
|
|
257 | ); |
269 | ); |
258 | |
270 | |
259 | while (my ($k, $v) = each %DEF_CFG) { |
271 | while (my ($k, $v) = each %DEF_CFG) { |
260 | $::CFG->{$k} = $v unless exists $::CFG->{$k}; |
272 | $::CFG->{$k} = $v unless exists $::CFG->{$k}; |
|
|
273 | } |
|
|
274 | |
|
|
275 | if ($::CFG->{cfg_schema} < 1) { |
|
|
276 | for my $profile (values %{ $::CFG->{profile} }) { |
|
|
277 | $profile->{password} = unpack "H*", Deliantra::Util::hash_pw $profile->{password}; |
|
|
278 | } |
|
|
279 | $::CFG->{cfg_schema} = 1; |
261 | } |
280 | } |
262 | } |
281 | } |
263 | |
282 | |
264 | sub http_proxy { |
283 | sub http_proxy { |
265 | my @proxy = win32_proxy_info; |
284 | my @proxy = win32_proxy_info; |