… | |
… | |
373 | and return; |
373 | and return; |
374 | |
374 | |
375 | 1 |
375 | 1 |
376 | } |
376 | } |
377 | |
377 | |
|
|
378 | =item cf::datalog type => key => value, ... |
|
|
379 | |
|
|
380 | Log a datalog packet of the given type with the given key-value pairs. |
|
|
381 | |
|
|
382 | =cut |
|
|
383 | |
|
|
384 | sub datalog($@) { |
|
|
385 | my ($type, %kv) = @_; |
|
|
386 | warn "DATALOG ", JSON::XS->new->ascii->encode ({ %kv, type => $type }); |
|
|
387 | } |
|
|
388 | |
378 | =back |
389 | =back |
379 | |
390 | |
380 | =cut |
391 | =cut |
381 | |
392 | |
382 | ############################################################################# |
393 | ############################################################################# |
… | |
… | |
1113 | } |
1124 | } |
1114 | |
1125 | |
1115 | \@paths |
1126 | \@paths |
1116 | } |
1127 | } |
1117 | |
1128 | |
1118 | =item $player->ext_reply ($msgid, $msgtype, %msg) |
1129 | =item $player->ext_reply ($msgid, %msg) |
1119 | |
1130 | |
1120 | Sends an ext reply to the player. |
1131 | Sends an ext reply to the player. |
1121 | |
1132 | |
1122 | =cut |
1133 | =cut |
1123 | |
1134 | |
1124 | sub ext_reply($$$%) { |
1135 | sub ext_reply($$%) { |
1125 | my ($self, $id, %msg) = @_; |
1136 | my ($self, $id, %msg) = @_; |
1126 | |
1137 | |
1127 | $msg{msgid} = $id; |
1138 | $msg{msgid} = $id; |
|
|
1139 | |
|
|
1140 | $self->send ("ext " . cf::to_json \%msg); |
|
|
1141 | } |
|
|
1142 | |
|
|
1143 | =item $player->ext_event ($type, %msg) |
|
|
1144 | |
|
|
1145 | Sends an ext event to the client. |
|
|
1146 | |
|
|
1147 | =cut |
|
|
1148 | |
|
|
1149 | sub ext_event($$%) { |
|
|
1150 | my ($self, $type, %msg) = @_; |
|
|
1151 | |
|
|
1152 | delete $msg{msgid}; |
|
|
1153 | $msg{msgtype} = "event"; |
|
|
1154 | $msg{eventtype} = $type; |
1128 | |
1155 | |
1129 | $self->send ("ext " . cf::to_json \%msg); |
1156 | $self->send ("ext " . cf::to_json \%msg); |
1130 | } |
1157 | } |
1131 | |
1158 | |
1132 | package cf; |
1159 | package cf; |
… | |
… | |
2093 | |
2120 | |
2094 | # here we export the classes and methods available to script code |
2121 | # here we export the classes and methods available to script code |
2095 | |
2122 | |
2096 | =pod |
2123 | =pod |
2097 | |
2124 | |
2098 | The following fucntions and emthods are available within a safe environment: |
2125 | The following functions and methods are available within a safe environment: |
2099 | |
2126 | |
2100 | cf::object contr pay_amount pay_player map |
2127 | cf::object contr pay_amount pay_player map |
2101 | cf::object::player player |
2128 | cf::object::player player |
2102 | cf::player peaceful |
2129 | cf::player peaceful |
2103 | cf::map trigger |
2130 | cf::map trigger |
… | |
… | |
2258 | } |
2285 | } |
2259 | |
2286 | |
2260 | ############################################################################# |
2287 | ############################################################################# |
2261 | # the server's init and main functions |
2288 | # the server's init and main functions |
2262 | |
2289 | |
2263 | sub load_faces { |
2290 | sub load_facedata { |
2264 | my $path = sprintf "%s/faces", cf::datadir; |
2291 | my $path = sprintf "%s/facedata", cf::datadir; |
2265 | |
2292 | |
2266 | warn "loading faces from $path\n"; |
2293 | warn "loading facedata from $path\n"; |
2267 | |
2294 | |
2268 | my $faces; |
2295 | my $faces; |
2269 | 0 < aio_load $path, $faces |
2296 | 0 < aio_load $path, $faces |
2270 | or die "$path: $!"; |
2297 | or die "$path: $!"; |
2271 | |
2298 | |
… | |
… | |
2279 | |
2306 | |
2280 | while (my ($face, $info) = each %$faces) { |
2307 | while (my ($face, $info) = each %$faces) { |
2281 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2308 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2282 | cf::face::set $idx, $info->{visibility}, $info->{magicmap}; |
2309 | cf::face::set $idx, $info->{visibility}, $info->{magicmap}; |
2283 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
2310 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
|
|
2311 | cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; |
2284 | Coro::cede; |
2312 | Coro::cede; |
2285 | } |
2313 | } |
2286 | |
2314 | |
2287 | while (my ($face, $info) = each %$faces) { |
2315 | while (my ($face, $info) = each %$faces) { |
2288 | next unless $info->{smooth}; |
2316 | next unless $info->{smooth}; |
… | |
… | |
2300 | } |
2328 | } |
2301 | |
2329 | |
2302 | sub reload_resources { |
2330 | sub reload_resources { |
2303 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2331 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2304 | or die "unable to load regions file\n";#d# |
2332 | or die "unable to load regions file\n";#d# |
2305 | load_faces |
2333 | load_facedata |
2306 | or die "unable to load faces\n";#d# |
2334 | or die "unable to load facedata\n";#d# |
2307 | } |
2335 | } |
2308 | |
2336 | |
2309 | sub init { |
2337 | sub init { |
2310 | reload_resources; |
2338 | reload_resources; |
2311 | } |
2339 | } |