… | |
… | |
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 | ############################################################################# |
… | |
… | |
952 | } |
963 | } |
953 | |
964 | |
954 | sub path($) { |
965 | sub path($) { |
955 | my $login = ref $_[0] ? $_[0]->ob->name : $_[0]; |
966 | my $login = ref $_[0] ? $_[0]->ob->name : $_[0]; |
956 | |
967 | |
957 | (playerdir $login) . "/$login.pl" |
968 | (playerdir $login) . "/playerdata" |
958 | } |
969 | } |
959 | |
970 | |
960 | sub find_active($) { |
971 | sub find_active($) { |
961 | $cf::PLAYER{$_[0]} |
972 | $cf::PLAYER{$_[0]} |
962 | and $cf::PLAYER{$_[0]}->active |
973 | and $cf::PLAYER{$_[0]}->active |
… | |
… | |
975 | my $login = $_[0]; |
986 | my $login = $_[0]; |
976 | |
987 | |
977 | my $guard = cf::lock_acquire "user_find:$login"; |
988 | my $guard = cf::lock_acquire "user_find:$login"; |
978 | |
989 | |
979 | $cf::PLAYER{$_[0]} || do { |
990 | $cf::PLAYER{$_[0]} || do { |
|
|
991 | # rename old playerfiles to new ones |
|
|
992 | #TODO: remove when no longer required |
|
|
993 | aio_link +(playerdir $login) . "/$login.pl.pst", (playerdir $login) . "/playerdata.pst"; |
|
|
994 | aio_link +(playerdir $login) . "/$login.pl" , (playerdir $login) . "/playerdata"; |
|
|
995 | aio_unlink +(playerdir $login) . "/$login.pl.pst"; |
|
|
996 | aio_unlink +(playerdir $login) . "/$login.pl"; |
|
|
997 | |
980 | my $pl = load_pl path $login |
998 | my $pl = load_pl path $login |
981 | or return; |
999 | or return; |
982 | $cf::PLAYER{$login} = $pl |
1000 | $cf::PLAYER{$login} = $pl |
983 | } |
1001 | } |
984 | } |
1002 | } |
… | |
… | |
1113 | } |
1131 | } |
1114 | |
1132 | |
1115 | \@paths |
1133 | \@paths |
1116 | } |
1134 | } |
1117 | |
1135 | |
1118 | =item $player->ext_reply ($msgid, $msgtype, %msg) |
1136 | =item $player->ext_reply ($msgid, %msg) |
1119 | |
1137 | |
1120 | Sends an ext reply to the player. |
1138 | Sends an ext reply to the player. |
1121 | |
1139 | |
1122 | =cut |
1140 | =cut |
1123 | |
1141 | |
1124 | sub ext_reply($$$%) { |
1142 | sub ext_reply($$%) { |
1125 | my ($self, $id, %msg) = @_; |
1143 | my ($self, $id, %msg) = @_; |
1126 | |
1144 | |
1127 | $msg{msgid} = $id; |
1145 | $msg{msgid} = $id; |
1128 | |
1146 | |
1129 | $self->send ("ext " . cf::to_json \%msg); |
1147 | $self->send ("ext " . cf::to_json \%msg); |
|
|
1148 | } |
|
|
1149 | |
|
|
1150 | =item $player->ext_event ($type, %msg) |
|
|
1151 | |
|
|
1152 | Sends an ext event to the client. |
|
|
1153 | |
|
|
1154 | =cut |
|
|
1155 | |
|
|
1156 | sub ext_event($$%) { |
|
|
1157 | my ($self, $type, %msg) = @_; |
|
|
1158 | |
|
|
1159 | $self->ns->ext_event ($type, %msg); |
1130 | } |
1160 | } |
1131 | |
1161 | |
1132 | package cf; |
1162 | package cf; |
1133 | |
1163 | |
1134 | =back |
1164 | =back |
… | |
… | |
1942 | |
1972 | |
1943 | return unless $self->type == cf::PLAYER; |
1973 | return unless $self->type == cf::PLAYER; |
1944 | |
1974 | |
1945 | if ($exit->slaying eq "/!") { |
1975 | if ($exit->slaying eq "/!") { |
1946 | #TODO: this should de-fi-ni-te-ly not be a sync-job |
1976 | #TODO: this should de-fi-ni-te-ly not be a sync-job |
|
|
1977 | # the problem is that $exit might not survive long enough |
|
|
1978 | # so it needs to be done right now, right here |
1947 | cf::sync_job { prepare_random_map $exit }; |
1979 | cf::sync_job { prepare_random_map $exit }; |
1948 | } |
1980 | } |
1949 | |
1981 | |
1950 | my $slaying = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; |
1982 | my $slaying = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; |
1951 | my $hp = $exit->stats->hp; |
1983 | my $hp = $exit->stats->hp; |
… | |
… | |
1959 | $self->goto ($slaying, $hp, $sp); |
1991 | $self->goto ($slaying, $hp, $sp); |
1960 | |
1992 | |
1961 | 1; |
1993 | 1; |
1962 | }) { |
1994 | }) { |
1963 | $self->message ("Something went wrong deep within the crossfire server. " |
1995 | $self->message ("Something went wrong deep within the crossfire server. " |
1964 | . "I'll try to bring you back to the map you were before. " |
1996 | . "I'll try to bring you back to the map you were before. " |
1965 | . "Please report this to the dungeon master!", |
1997 | . "Please report this to the dungeon master!", |
1966 | cf::NDI_UNIQUE | cf::NDI_RED); |
1998 | cf::NDI_UNIQUE | cf::NDI_RED); |
1967 | |
1999 | |
1968 | warn "ERROR in enter_exit: $@"; |
2000 | warn "ERROR in enter_exit: $@"; |
1969 | $self->leave_link; |
2001 | $self->leave_link; |
1970 | } |
2002 | } |
1971 | })->prio (1); |
2003 | })->prio (1); |
… | |
… | |
1987 | |
2019 | |
1988 | utf8::encode $text; |
2020 | utf8::encode $text; |
1989 | $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); |
2021 | $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); |
1990 | } |
2022 | } |
1991 | |
2023 | |
|
|
2024 | =item $client->ext_event ($type, %msg) |
|
|
2025 | |
|
|
2026 | Sends an exti event to the client. |
|
|
2027 | |
|
|
2028 | =cut |
|
|
2029 | |
|
|
2030 | sub cf::client::ext_event($$%) { |
|
|
2031 | my ($self, $type, %msg) = @_; |
|
|
2032 | |
|
|
2033 | $msg{msgtype} = "event_$type"; |
|
|
2034 | $self->send_packet ("ext " . cf::to_json \%msg); |
|
|
2035 | } |
1992 | |
2036 | |
1993 | =item $success = $client->query ($flags, "text", \&cb) |
2037 | =item $success = $client->query ($flags, "text", \&cb) |
1994 | |
2038 | |
1995 | Queues a query to the client, calling the given callback with |
2039 | Queues a query to the client, calling the given callback with |
1996 | the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>, |
2040 | the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>, |
… | |
… | |
2093 | |
2137 | |
2094 | # here we export the classes and methods available to script code |
2138 | # here we export the classes and methods available to script code |
2095 | |
2139 | |
2096 | =pod |
2140 | =pod |
2097 | |
2141 | |
2098 | The following fucntions and emthods are available within a safe environment: |
2142 | The following functions and methods are available within a safe environment: |
2099 | |
2143 | |
2100 | cf::object contr pay_amount pay_player map |
2144 | cf::object contr pay_amount pay_player map |
2101 | cf::object::player player |
2145 | cf::object::player player |
2102 | cf::player peaceful |
2146 | cf::player peaceful |
2103 | cf::map trigger |
2147 | cf::map trigger |
… | |
… | |
2258 | } |
2302 | } |
2259 | |
2303 | |
2260 | ############################################################################# |
2304 | ############################################################################# |
2261 | # the server's init and main functions |
2305 | # the server's init and main functions |
2262 | |
2306 | |
2263 | sub load_faces { |
2307 | sub load_facedata { |
2264 | my $path = sprintf "%s/faces", cf::datadir; |
2308 | my $path = sprintf "%s/facedata", cf::datadir; |
2265 | |
2309 | |
2266 | warn "loading faces from $path\n"; |
2310 | warn "loading facedata from $path\n"; |
2267 | |
2311 | |
2268 | my $faces; |
2312 | my $faces; |
2269 | 0 < aio_load $path, $faces |
2313 | 0 < aio_load $path, $faces |
2270 | or die "$path: $!"; |
2314 | or die "$path: $!"; |
2271 | |
2315 | |
… | |
… | |
2279 | |
2323 | |
2280 | while (my ($face, $info) = each %$faces) { |
2324 | while (my ($face, $info) = each %$faces) { |
2281 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2325 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2282 | cf::face::set $idx, $info->{visibility}, $info->{magicmap}; |
2326 | cf::face::set $idx, $info->{visibility}, $info->{magicmap}; |
2283 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
2327 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
|
|
2328 | cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; |
2284 | Coro::cede; |
2329 | Coro::cede; |
2285 | } |
2330 | } |
2286 | |
2331 | |
2287 | while (my ($face, $info) = each %$faces) { |
2332 | while (my ($face, $info) = each %$faces) { |
2288 | next unless $info->{smooth}; |
2333 | next unless $info->{smooth}; |
… | |
… | |
2300 | } |
2345 | } |
2301 | |
2346 | |
2302 | sub reload_resources { |
2347 | sub reload_resources { |
2303 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2348 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2304 | or die "unable to load regions file\n";#d# |
2349 | or die "unable to load regions file\n";#d# |
2305 | load_faces |
2350 | load_facedata |
2306 | or die "unable to load faces\n";#d# |
2351 | or die "unable to load facedata\n";#d# |
2307 | } |
2352 | } |
2308 | |
2353 | |
2309 | sub init { |
2354 | sub init { |
2310 | reload_resources; |
2355 | reload_resources; |
2311 | } |
2356 | } |