… | |
… | |
10 | |
10 | |
11 | =over 4 |
11 | =over 4 |
12 | |
12 | |
13 | =cut |
13 | =cut |
14 | |
14 | |
15 | package Deliantra::Client; # work around CPAN breakage |
|
|
16 | package App::Deliantra; # try to reserve namespace |
|
|
17 | package DC; |
15 | package DC; |
18 | |
16 | |
19 | use Carp (); |
17 | use Carp (); |
20 | |
18 | |
21 | our $VERSION; |
19 | our $VERSION; |
22 | |
20 | |
23 | BEGIN { |
21 | BEGIN { |
24 | $VERSION = '0.9975'; |
22 | $VERSION = '2.0'; |
25 | |
23 | |
26 | use XSLoader; |
24 | use XSLoader; |
27 | XSLoader::load "Deliantra::Client", $VERSION; |
25 | XSLoader::load "Deliantra::Client", $VERSION; |
28 | } |
26 | } |
29 | |
27 | |
… | |
… | |
70 | |
68 | |
71 | $_ |
69 | $_ |
72 | } |
70 | } |
73 | |
71 | |
74 | sub socketpipe() { |
72 | sub socketpipe() { |
75 | socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC |
73 | socketpair my $fh1, my $fh2, &Socket::AF_UNIX, &Socket::SOCK_STREAM, &Socket::PF_UNSPEC |
76 | or die "cannot establish bidirectional pipe: $!\n"; |
74 | or die "cannot establish bidirectional pipe: $!\n"; |
77 | |
75 | |
78 | ($fh1, $fh2) |
76 | ($fh1, $fh2) |
79 | } |
77 | } |
80 | |
78 | |
… | |
… | |
145 | print $msg, "\n"; |
143 | print $msg, "\n"; |
146 | } |
144 | } |
147 | |
145 | |
148 | package DC; |
146 | package DC; |
149 | |
147 | |
150 | our @RC_THEME = ("theme-blue", "."); |
148 | our $RC_THEME; |
|
|
149 | our %THEME; |
|
|
150 | our @RC_PATH; |
151 | our $RC_BASE; |
151 | our $RC_BASE; |
152 | |
152 | |
153 | for (grep !ref, @INC) { |
153 | for (grep !ref, @INC) { |
154 | $RC_BASE = "$_/Deliantra/Client/private/resources"; |
154 | $RC_BASE = "$_/Deliantra/Client/private/resources"; |
155 | last if -d $RC_BASE; |
155 | last if -d $RC_BASE; |
156 | } |
156 | } |
157 | |
157 | |
158 | sub find_rcfile($) { |
158 | sub find_rcfile($) { |
159 | my $path; |
159 | my $path; |
160 | |
160 | |
161 | for (@RC_THEME) { |
161 | for (@RC_PATH, "") { |
162 | $path = "$RC_BASE/$_/$_[0]"; |
162 | $path = "$RC_BASE/$_/$_[0]"; |
163 | return $path if -r $path; |
163 | return $path if -r $path; |
164 | } |
164 | } |
165 | |
165 | |
166 | die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; |
166 | die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; |
167 | } |
167 | } |
168 | |
168 | |
|
|
169 | sub load_json($) { |
|
|
170 | my ($file) = @_; |
|
|
171 | |
|
|
172 | open my $fh, $file |
|
|
173 | or return; |
|
|
174 | |
|
|
175 | local $/; |
|
|
176 | JSON::XS->new->utf8->relaxed->decode (<$fh>) |
|
|
177 | } |
|
|
178 | |
|
|
179 | sub set_theme($) { |
|
|
180 | return if $RC_THEME eq $_[0]; |
|
|
181 | $RC_THEME = $_[0]; |
|
|
182 | |
|
|
183 | # kind of hacky, find the main theme file, then load all theme files and merge them |
|
|
184 | |
|
|
185 | %THEME = (); |
|
|
186 | @RC_PATH = "theme-$RC_THEME"; |
|
|
187 | |
|
|
188 | my $theme = load_json find_rcfile "theme.json" |
|
|
189 | or die "FATAL: theme resource file not found"; |
|
|
190 | |
|
|
191 | @RC_PATH = @{ $theme->{path} } if $theme->{path}; |
|
|
192 | |
|
|
193 | for (@RC_PATH, "") { |
|
|
194 | my $theme = load_json "$RC_BASE/$_/theme.json" |
|
|
195 | or next; |
|
|
196 | |
|
|
197 | %THEME = ( %$theme, %THEME ); |
|
|
198 | } |
|
|
199 | } |
|
|
200 | |
169 | sub read_cfg { |
201 | sub read_cfg { |
170 | my ($file) = @_; |
202 | my ($file) = @_; |
171 | |
203 | |
172 | open my $fh, $file |
204 | $::CFG = load_json $file; |
173 | or return; |
|
|
174 | |
|
|
175 | local $/; |
|
|
176 | my $CFG = <$fh>; |
|
|
177 | |
|
|
178 | $::CFG = decode_json $CFG; |
|
|
179 | } |
205 | } |
180 | |
206 | |
181 | sub write_cfg { |
207 | sub write_cfg { |
182 | my $file = "$Deliantra::VARDIR/client.cf"; |
208 | my $file = "$Deliantra::VARDIR/client.cf"; |
183 | |
209 | |