Merge pull request #96915 from Faless/mp/rpc_sort_custom

[MP] Fix broken RPCs after dictionary keys type change
This commit is contained in:
Rémi Verschelde 2024-09-13 11:21:29 +02:00
commit 5a56d11ad1
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 13 additions and 1 deletions

View File

@ -73,6 +73,16 @@ int get_packet_len(uint32_t p_node_target, int p_packet_len) {
}
}
bool SceneRPCInterface::_sort_rpc_names(const Variant &p_l, const Variant &p_r) {
if (likely(p_l.is_string() && p_r.is_string())) {
return p_l.operator String() < p_r.operator String();
}
bool valid = false;
Variant res;
Variant::evaluate(Variant::OP_LESS, p_l, p_r, res, valid);
return valid ? res.operator bool() : false;
}
void SceneRPCInterface::_parse_rpc_config(const Variant &p_config, bool p_for_node, RPCConfigCache &r_cache) {
if (p_config.get_type() == Variant::NIL) {
return;
@ -80,7 +90,7 @@ void SceneRPCInterface::_parse_rpc_config(const Variant &p_config, bool p_for_no
ERR_FAIL_COND(p_config.get_type() != Variant::DICTIONARY);
const Dictionary config = p_config;
Array names = config.keys();
names.sort(); // Ensure ID order
names.sort_custom(callable_mp_static(&SceneRPCInterface::_sort_rpc_names)); // Ensure ID order
for (int i = 0; i < names.size(); i++) {
ERR_CONTINUE(!names[i].is_string());
String name = names[i].operator String();

View File

@ -91,6 +91,8 @@ private:
#endif
protected:
static bool _sort_rpc_names(const Variant &p_l, const Variant &p_r);
void _process_rpc(Node *p_node, const uint16_t p_rpc_method_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset);
void _send_rpc(Node *p_from, int p_to, uint16_t p_rpc_id, const RPCConfig &p_config, const StringName &p_name, const Variant **p_arg, int p_argcount);