mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Separate ephemeral from client caching in core.dynamic_add_media()
This commit is contained in:
parent
0b66465f33
commit
5672b93007
5 changed files with 9 additions and 4 deletions
|
@ -7375,8 +7375,10 @@ Server
|
||||||
* `filedata`: the data of the file to be sent [*]
|
* `filedata`: the data of the file to be sent [*]
|
||||||
* `to_player`: name of the player the media should be sent to instead of
|
* `to_player`: name of the player the media should be sent to instead of
|
||||||
all players (optional)
|
all players (optional)
|
||||||
* `ephemeral`: boolean that marks the media as ephemeral,
|
* `ephemeral`: if true the server will create a copy of the file and
|
||||||
it will not be cached on the client (optional, default false)
|
forget about it once delivered (optional boolean, default false)
|
||||||
|
* `client_cache`: hint whether the client should save the media in its cache
|
||||||
|
(optional boolean, default `!ephemeral`, added in 5.14.0)
|
||||||
* Exactly one of the parameters marked [*] must be specified.
|
* Exactly one of the parameters marked [*] must be specified.
|
||||||
* `callback`: function with arguments `name`, which is a player name
|
* `callback`: function with arguments `name`, which is a player name
|
||||||
* Pushes the specified media file to client(s) as detailed below.
|
* Pushes the specified media file to client(s) as detailed below.
|
||||||
|
|
|
@ -52,6 +52,7 @@ local function test_dynamic_media(cb, player)
|
||||||
local ok = core.dynamic_add_media({
|
local ok = core.dynamic_add_media({
|
||||||
filepath = path,
|
filepath = path,
|
||||||
to_player = player:get_player_name(),
|
to_player = player:get_player_name(),
|
||||||
|
client_cache = false,
|
||||||
}, function(name)
|
}, function(name)
|
||||||
if not call_ok then
|
if not call_ok then
|
||||||
return cb("impossible condition")
|
return cb("impossible condition")
|
||||||
|
|
|
@ -551,6 +551,7 @@ int ModApiServer::l_dynamic_add_media(lua_State *L)
|
||||||
args.data.reset();
|
args.data.reset();
|
||||||
getstringfield(L, 1, "to_player", args.to_player);
|
getstringfield(L, 1, "to_player", args.to_player);
|
||||||
getboolfield(L, 1, "ephemeral", args.ephemeral);
|
getboolfield(L, 1, "ephemeral", args.ephemeral);
|
||||||
|
args.client_cache = getboolfield_default(L, 1, "client_cache", !args.ephemeral);
|
||||||
} else {
|
} else {
|
||||||
tmp = readParam<std::string>(L, 1);
|
tmp = readParam<std::string>(L, 1);
|
||||||
args.filepath = tmp;
|
args.filepath = tmp;
|
||||||
|
|
|
@ -3782,10 +3782,10 @@ bool Server::dynamicAddMedia(const DynamicMediaArgs &a)
|
||||||
if (m_env) {
|
if (m_env) {
|
||||||
NetworkPacket pkt(TOCLIENT_MEDIA_PUSH, 0);
|
NetworkPacket pkt(TOCLIENT_MEDIA_PUSH, 0);
|
||||||
pkt << raw_hash << filename;
|
pkt << raw_hash << filename;
|
||||||
// NOTE: the meaning of a.ephemeral was accidentally inverted between proto 39 and 40,
|
// NOTE: the meaning of this bit was accidentally inverted between proto 39 and 40,
|
||||||
// when dynamic_add_media v2 was added. As of 5.12.0 the server sends it correctly again.
|
// when dynamic_add_media v2 was added. As of 5.12.0 the server sends it correctly again.
|
||||||
// Compatibility code on the client-side was not added.
|
// Compatibility code on the client-side was not added.
|
||||||
pkt << static_cast<bool>(!a.ephemeral);
|
pkt << static_cast<bool>(a.client_cache);
|
||||||
|
|
||||||
NetworkPacket legacy_pkt = pkt;
|
NetworkPacket legacy_pkt = pkt;
|
||||||
|
|
||||||
|
|
|
@ -302,6 +302,7 @@ public:
|
||||||
u32 token;
|
u32 token;
|
||||||
std::string to_player;
|
std::string to_player;
|
||||||
bool ephemeral = false;
|
bool ephemeral = false;
|
||||||
|
bool client_cache = true;
|
||||||
};
|
};
|
||||||
bool dynamicAddMedia(const DynamicMediaArgs &args);
|
bool dynamicAddMedia(const DynamicMediaArgs &args);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue