Skip to content

Commit

Permalink
SceneRPCInterface: Sort rpc names using StringLikeVariantOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
rune-scape committed Oct 23, 2024
1 parent b3bcb2d commit cec3553
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
13 changes: 2 additions & 11 deletions modules/multiplayer/scene_rpc_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "scene_rpc_interface.h"

#include "core/variant/variant.h"
#include "scene_multiplayer.h"

#include "core/debugger/engine_debugger.h"
Expand Down Expand Up @@ -73,24 +74,14 @@ 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;
}
ERR_FAIL_COND(p_config.get_type() != Variant::DICTIONARY);
const Dictionary config = p_config;
Array names = config.keys();
names.sort_custom(callable_mp_static(&SceneRPCInterface::_sort_rpc_names)); // Ensure ID order
names.sort_custom(callable_mp_static(&StringLikeVariantOrder::compare)); // Ensure ID order
for (int i = 0; i < names.size(); i++) {
ERR_CONTINUE(!names[i].is_string());
String name = names[i].operator String();
Expand Down
2 changes: 0 additions & 2 deletions modules/multiplayer/scene_rpc_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ class SceneRPCInterface : public RefCounted {
#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);
Expand Down

0 comments on commit cec3553

Please sign in to comment.