scene_rpc_interface.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /*************************************************************************/
  2. /* scene_rpc_interface.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "scene/multiplayer/scene_rpc_interface.h"
  31. #include "core/debugger/engine_debugger.h"
  32. #include "core/io/marshalls.h"
  33. #include "core/multiplayer/multiplayer_api.h"
  34. #include "scene/main/node.h"
  35. #include "scene/main/window.h"
  36. MultiplayerRPCInterface *SceneRPCInterface::_create(MultiplayerAPI *p_multiplayer) {
  37. return memnew(SceneRPCInterface(p_multiplayer));
  38. }
  39. void SceneRPCInterface::make_default() {
  40. MultiplayerAPI::create_default_rpc_interface = _create;
  41. }
  42. #ifdef DEBUG_ENABLED
  43. _FORCE_INLINE_ void SceneRPCInterface::_profile_node_data(const String &p_what, ObjectID p_id) {
  44. if (EngineDebugger::is_profiling("rpc")) {
  45. Array values;
  46. values.push_back(p_id);
  47. values.push_back(p_what);
  48. EngineDebugger::profiler_add_frame_data("rpc", values);
  49. }
  50. }
  51. #else
  52. _FORCE_INLINE_ void SceneRPCInterface::_profile_node_data(const String &p_what, ObjectID p_id) {}
  53. #endif
  54. // Returns the packet size stripping the node path added when the node is not yet cached.
  55. int get_packet_len(uint32_t p_node_target, int p_packet_len) {
  56. if (p_node_target & 0x80000000) {
  57. int ofs = p_node_target & 0x7FFFFFFF;
  58. return p_packet_len - (p_packet_len - ofs);
  59. } else {
  60. return p_packet_len;
  61. }
  62. }
  63. const Multiplayer::RPCConfig _get_rpc_config(const Node *p_node, const StringName &p_method, uint16_t &r_id) {
  64. const Vector<Multiplayer::RPCConfig> node_config = p_node->get_node_rpc_methods();
  65. for (int i = 0; i < node_config.size(); i++) {
  66. if (node_config[i].name == p_method) {
  67. r_id = ((uint16_t)i) | (1 << 15);
  68. return node_config[i];
  69. }
  70. }
  71. if (p_node->get_script_instance()) {
  72. const Vector<Multiplayer::RPCConfig> script_config = p_node->get_script_instance()->get_rpc_methods();
  73. for (int i = 0; i < script_config.size(); i++) {
  74. if (script_config[i].name == p_method) {
  75. r_id = (uint16_t)i;
  76. return script_config[i];
  77. }
  78. }
  79. }
  80. return Multiplayer::RPCConfig();
  81. }
  82. const Multiplayer::RPCConfig _get_rpc_config_by_id(Node *p_node, uint16_t p_id) {
  83. Vector<Multiplayer::RPCConfig> config;
  84. uint16_t id = p_id;
  85. if (id & (1 << 15)) {
  86. id = id & ~(1 << 15);
  87. config = p_node->get_node_rpc_methods();
  88. } else if (p_node->get_script_instance()) {
  89. config = p_node->get_script_instance()->get_rpc_methods();
  90. }
  91. if (id < config.size()) {
  92. return config[id];
  93. }
  94. return Multiplayer::RPCConfig();
  95. }
  96. _FORCE_INLINE_ bool _can_call_mode(Node *p_node, Multiplayer::RPCMode mode, int p_remote_id) {
  97. switch (mode) {
  98. case Multiplayer::RPC_MODE_DISABLED: {
  99. return false;
  100. } break;
  101. case Multiplayer::RPC_MODE_ANY_PEER: {
  102. return true;
  103. } break;
  104. case Multiplayer::RPC_MODE_AUTHORITY: {
  105. return !p_node->is_multiplayer_authority() && p_remote_id == p_node->get_multiplayer_authority();
  106. } break;
  107. }
  108. return false;
  109. }
  110. String SceneRPCInterface::get_rpc_md5(const Object *p_obj) const {
  111. const Node *node = Object::cast_to<Node>(p_obj);
  112. ERR_FAIL_COND_V(!node, "");
  113. String rpc_list;
  114. const Vector<Multiplayer::RPCConfig> node_config = node->get_node_rpc_methods();
  115. for (int i = 0; i < node_config.size(); i++) {
  116. rpc_list += String(node_config[i].name);
  117. }
  118. if (node->get_script_instance()) {
  119. const Vector<Multiplayer::RPCConfig> script_config = node->get_script_instance()->get_rpc_methods();
  120. for (int i = 0; i < script_config.size(); i++) {
  121. rpc_list += String(script_config[i].name);
  122. }
  123. }
  124. return rpc_list.md5_text();
  125. }
  126. Node *SceneRPCInterface::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) {
  127. Node *root_node = SceneTree::get_singleton()->get_root()->get_node(multiplayer->get_root_path());
  128. ERR_FAIL_COND_V(!root_node, nullptr);
  129. Node *node = nullptr;
  130. if (p_node_target & 0x80000000) {
  131. // Use full path (not cached yet).
  132. int ofs = p_node_target & 0x7FFFFFFF;
  133. ERR_FAIL_COND_V_MSG(ofs >= p_packet_len, nullptr, "Invalid packet received. Size smaller than declared.");
  134. String paths;
  135. paths.parse_utf8((const char *)&p_packet[ofs], p_packet_len - ofs);
  136. NodePath np = paths;
  137. node = root_node->get_node(np);
  138. if (!node) {
  139. ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
  140. }
  141. return node;
  142. } else {
  143. // Use cached path.
  144. return Object::cast_to<Node>(multiplayer->get_cached_object(p_from, p_node_target));
  145. }
  146. }
  147. void SceneRPCInterface::process_rpc(int p_from, const uint8_t *p_packet, int p_packet_len) {
  148. // Extract packet meta
  149. int packet_min_size = 1;
  150. int name_id_offset = 1;
  151. ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
  152. // Compute the meta size, which depends on the compression level.
  153. int node_id_compression = (p_packet[0] & NODE_ID_COMPRESSION_FLAG) >> NODE_ID_COMPRESSION_SHIFT;
  154. int name_id_compression = (p_packet[0] & NAME_ID_COMPRESSION_FLAG) >> NAME_ID_COMPRESSION_SHIFT;
  155. switch (node_id_compression) {
  156. case NETWORK_NODE_ID_COMPRESSION_8:
  157. packet_min_size += 1;
  158. name_id_offset += 1;
  159. break;
  160. case NETWORK_NODE_ID_COMPRESSION_16:
  161. packet_min_size += 2;
  162. name_id_offset += 2;
  163. break;
  164. case NETWORK_NODE_ID_COMPRESSION_32:
  165. packet_min_size += 4;
  166. name_id_offset += 4;
  167. break;
  168. default:
  169. ERR_FAIL_MSG("Was not possible to extract the node id compression mode.");
  170. }
  171. switch (name_id_compression) {
  172. case NETWORK_NAME_ID_COMPRESSION_8:
  173. packet_min_size += 1;
  174. break;
  175. case NETWORK_NAME_ID_COMPRESSION_16:
  176. packet_min_size += 2;
  177. break;
  178. default:
  179. ERR_FAIL_MSG("Was not possible to extract the name id compression mode.");
  180. }
  181. ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
  182. uint32_t node_target = 0;
  183. switch (node_id_compression) {
  184. case NETWORK_NODE_ID_COMPRESSION_8:
  185. node_target = p_packet[1];
  186. break;
  187. case NETWORK_NODE_ID_COMPRESSION_16:
  188. node_target = decode_uint16(p_packet + 1);
  189. break;
  190. case NETWORK_NODE_ID_COMPRESSION_32:
  191. node_target = decode_uint32(p_packet + 1);
  192. break;
  193. default:
  194. // Unreachable, checked before.
  195. CRASH_NOW();
  196. }
  197. Node *node = _process_get_node(p_from, p_packet, node_target, p_packet_len);
  198. ERR_FAIL_COND_MSG(node == nullptr, "Invalid packet received. Requested node was not found.");
  199. uint16_t name_id = 0;
  200. switch (name_id_compression) {
  201. case NETWORK_NAME_ID_COMPRESSION_8:
  202. name_id = p_packet[name_id_offset];
  203. break;
  204. case NETWORK_NAME_ID_COMPRESSION_16:
  205. name_id = decode_uint16(p_packet + name_id_offset);
  206. break;
  207. default:
  208. // Unreachable, checked before.
  209. CRASH_NOW();
  210. }
  211. const int packet_len = get_packet_len(node_target, p_packet_len);
  212. _process_rpc(node, name_id, p_from, p_packet, packet_len, packet_min_size);
  213. }
  214. void SceneRPCInterface::_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) {
  215. ERR_FAIL_COND_MSG(p_offset > p_packet_len, "Invalid packet received. Size too small.");
  216. // Check that remote can call the RPC on this node.
  217. const Multiplayer::RPCConfig config = _get_rpc_config_by_id(p_node, p_rpc_method_id);
  218. ERR_FAIL_COND(config.name == StringName());
  219. bool can_call = _can_call_mode(p_node, config.rpc_mode, p_from);
  220. ERR_FAIL_COND_MSG(!can_call, "RPC '" + String(config.name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)config.rpc_mode) + ", authority is " + itos(p_node->get_multiplayer_authority()) + ".");
  221. int argc = 0;
  222. const bool byte_only_or_no_args = p_packet[0] & BYTE_ONLY_OR_NO_ARGS_FLAG;
  223. if (byte_only_or_no_args) {
  224. if (p_offset < p_packet_len) {
  225. // This packet contains only bytes.
  226. argc = 1;
  227. }
  228. } else {
  229. // Normal variant, takes the argument count from the packet.
  230. ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
  231. argc = p_packet[p_offset];
  232. p_offset += 1;
  233. }
  234. Vector<Variant> args;
  235. Vector<const Variant *> argp;
  236. args.resize(argc);
  237. argp.resize(argc);
  238. #ifdef DEBUG_ENABLED
  239. _profile_node_data("rpc_in", p_node->get_instance_id());
  240. #endif
  241. int out;
  242. MultiplayerAPI::decode_and_decompress_variants(args, &p_packet[p_offset], p_packet_len - p_offset, out, byte_only_or_no_args, multiplayer->is_object_decoding_allowed());
  243. for (int i = 0; i < argc; i++) {
  244. argp.write[i] = &args[i];
  245. }
  246. Callable::CallError ce;
  247. p_node->callp(config.name, (const Variant **)argp.ptr(), argc, ce);
  248. if (ce.error != Callable::CallError::CALL_OK) {
  249. String error = Variant::get_call_error_text(p_node, config.name, (const Variant **)argp.ptr(), argc, ce);
  250. error = "RPC - " + error;
  251. ERR_PRINT(error);
  252. }
  253. }
  254. void SceneRPCInterface::_send_rpc(Node *p_from, int p_to, uint16_t p_rpc_id, const Multiplayer::RPCConfig &p_config, const StringName &p_name, const Variant **p_arg, int p_argcount) {
  255. Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer();
  256. ERR_FAIL_COND_MSG(peer.is_null(), "Attempt to call RPC without active multiplayer peer.");
  257. ERR_FAIL_COND_MSG(peer->get_connection_status() == MultiplayerPeer::CONNECTION_CONNECTING, "Attempt to call RPC while multiplayer peer is not connected yet.");
  258. ERR_FAIL_COND_MSG(peer->get_connection_status() == MultiplayerPeer::CONNECTION_DISCONNECTED, "Attempt to call RPC while multiplayer peer is disconnected.");
  259. ERR_FAIL_COND_MSG(p_argcount > 255, "Too many arguments (>255).");
  260. if (p_to != 0 && !multiplayer->get_connected_peers().has(ABS(p_to))) {
  261. ERR_FAIL_COND_MSG(p_to == peer->get_unique_id(), "Attempt to call RPC on yourself! Peer unique ID: " + itos(peer->get_unique_id()) + ".");
  262. ERR_FAIL_MSG("Attempt to call RPC with unknown peer ID: " + itos(p_to) + ".");
  263. }
  264. NodePath from_path = multiplayer->get_root_path().rel_path_to(p_from->get_path());
  265. ERR_FAIL_COND_MSG(from_path.is_empty(), "Unable to send RPC. Relative path is empty. THIS IS LIKELY A BUG IN THE ENGINE!");
  266. // See if all peers have cached path (if so, call can be fast).
  267. int psc_id;
  268. const bool has_all_peers = multiplayer->send_object_cache(p_from, from_path, p_to, psc_id);
  269. // Create base packet, lots of hardcode because it must be tight.
  270. int ofs = 0;
  271. #define MAKE_ROOM(m_amount) \
  272. if (packet_cache.size() < m_amount) \
  273. packet_cache.resize(m_amount);
  274. // Encode meta.
  275. uint8_t command_type = MultiplayerAPI::NETWORK_COMMAND_REMOTE_CALL;
  276. uint8_t node_id_compression = UINT8_MAX;
  277. uint8_t name_id_compression = UINT8_MAX;
  278. bool byte_only_or_no_args = false;
  279. MAKE_ROOM(1);
  280. // The meta is composed along the way, so just set 0 for now.
  281. packet_cache.write[0] = 0;
  282. ofs += 1;
  283. // Encode Node ID.
  284. if (has_all_peers) {
  285. // Compress the node ID only if all the target peers already know it.
  286. if (psc_id >= 0 && psc_id <= 255) {
  287. // We can encode the id in 1 byte
  288. node_id_compression = NETWORK_NODE_ID_COMPRESSION_8;
  289. MAKE_ROOM(ofs + 1);
  290. packet_cache.write[ofs] = static_cast<uint8_t>(psc_id);
  291. ofs += 1;
  292. } else if (psc_id >= 0 && psc_id <= 65535) {
  293. // We can encode the id in 2 bytes
  294. node_id_compression = NETWORK_NODE_ID_COMPRESSION_16;
  295. MAKE_ROOM(ofs + 2);
  296. encode_uint16(static_cast<uint16_t>(psc_id), &(packet_cache.write[ofs]));
  297. ofs += 2;
  298. } else {
  299. // Too big, let's use 4 bytes.
  300. node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
  301. MAKE_ROOM(ofs + 4);
  302. encode_uint32(psc_id, &(packet_cache.write[ofs]));
  303. ofs += 4;
  304. }
  305. } else {
  306. // The targets don't know the node yet, so we need to use 32 bits int.
  307. node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
  308. MAKE_ROOM(ofs + 4);
  309. encode_uint32(psc_id, &(packet_cache.write[ofs]));
  310. ofs += 4;
  311. }
  312. // Encode method ID
  313. if (p_rpc_id <= UINT8_MAX) {
  314. // The ID fits in 1 byte
  315. name_id_compression = NETWORK_NAME_ID_COMPRESSION_8;
  316. MAKE_ROOM(ofs + 1);
  317. packet_cache.write[ofs] = static_cast<uint8_t>(p_rpc_id);
  318. ofs += 1;
  319. } else {
  320. // The ID is larger, let's use 2 bytes
  321. name_id_compression = NETWORK_NAME_ID_COMPRESSION_16;
  322. MAKE_ROOM(ofs + 2);
  323. encode_uint16(p_rpc_id, &(packet_cache.write[ofs]));
  324. ofs += 2;
  325. }
  326. int len;
  327. Error err = MultiplayerAPI::encode_and_compress_variants(p_arg, p_argcount, nullptr, len, &byte_only_or_no_args, multiplayer->is_object_decoding_allowed());
  328. ERR_FAIL_COND_MSG(err != OK, "Unable to encode RPC arguments. THIS IS LIKELY A BUG IN THE ENGINE!");
  329. if (byte_only_or_no_args) {
  330. MAKE_ROOM(ofs + len);
  331. } else {
  332. MAKE_ROOM(ofs + 1 + len);
  333. packet_cache.write[ofs] = p_argcount;
  334. ofs += 1;
  335. }
  336. if (len) {
  337. MultiplayerAPI::encode_and_compress_variants(p_arg, p_argcount, &packet_cache.write[ofs], len, &byte_only_or_no_args, multiplayer->is_object_decoding_allowed());
  338. ofs += len;
  339. }
  340. ERR_FAIL_COND(command_type > 7);
  341. ERR_FAIL_COND(node_id_compression > 3);
  342. ERR_FAIL_COND(name_id_compression > 1);
  343. // We can now set the meta
  344. packet_cache.write[0] = command_type + (node_id_compression << NODE_ID_COMPRESSION_SHIFT) + (name_id_compression << NAME_ID_COMPRESSION_SHIFT) + (byte_only_or_no_args ? BYTE_ONLY_OR_NO_ARGS_FLAG : 0);
  345. #ifdef DEBUG_ENABLED
  346. multiplayer->profile_bandwidth("out", ofs);
  347. #endif
  348. // Take chance and set transfer mode, since all send methods will use it.
  349. peer->set_transfer_channel(p_config.channel);
  350. peer->set_transfer_mode(p_config.transfer_mode);
  351. if (has_all_peers) {
  352. // They all have verified paths, so send fast.
  353. peer->set_target_peer(p_to); // To all of you.
  354. peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
  355. } else {
  356. // Unreachable because the node ID is never compressed if the peers doesn't know it.
  357. CRASH_COND(node_id_compression != NETWORK_NODE_ID_COMPRESSION_32);
  358. // Not all verified path, so send one by one.
  359. // Append path at the end, since we will need it for some packets.
  360. CharString pname = String(from_path).utf8();
  361. int path_len = encode_cstring(pname.get_data(), nullptr);
  362. MAKE_ROOM(ofs + path_len);
  363. encode_cstring(pname.get_data(), &(packet_cache.write[ofs]));
  364. for (const int &P : multiplayer->get_connected_peers()) {
  365. if (p_to < 0 && P == -p_to) {
  366. continue; // Continue, excluded.
  367. }
  368. if (p_to > 0 && P != p_to) {
  369. continue; // Continue, not for this peer.
  370. }
  371. bool confirmed = multiplayer->is_cache_confirmed(from_path, P);
  372. peer->set_target_peer(P); // To this one specifically.
  373. if (confirmed) {
  374. // This one confirmed path, so use id.
  375. encode_uint32(psc_id, &(packet_cache.write[1]));
  376. peer->put_packet(packet_cache.ptr(), ofs);
  377. } else {
  378. // This one did not confirm path yet, so use entire path (sorry!).
  379. encode_uint32(0x80000000 | ofs, &(packet_cache.write[1])); // Offset to path and flag.
  380. peer->put_packet(packet_cache.ptr(), ofs + path_len);
  381. }
  382. }
  383. }
  384. }
  385. void SceneRPCInterface::rpcp(Object *p_obj, int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount) {
  386. Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer();
  387. ERR_FAIL_COND_MSG(!peer.is_valid(), "Trying to call an RPC while no multiplayer peer is active.");
  388. Node *node = Object::cast_to<Node>(p_obj);
  389. ERR_FAIL_COND(!node);
  390. ERR_FAIL_COND_MSG(!node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree.");
  391. ERR_FAIL_COND_MSG(peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a multiplayer peer which is not connected.");
  392. int node_id = peer->get_unique_id();
  393. bool call_local_native = false;
  394. bool call_local_script = false;
  395. uint16_t rpc_id = UINT16_MAX;
  396. const Multiplayer::RPCConfig config = _get_rpc_config(node, p_method, rpc_id);
  397. ERR_FAIL_COND_MSG(config.name == StringName(),
  398. vformat("Unable to get the RPC configuration for the function \"%s\" at path: \"%s\". This happens when the method is missing or not marked for RPCs in the local script.", p_method, node->get_path()));
  399. if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
  400. if (rpc_id & (1 << 15)) {
  401. call_local_native = config.call_local;
  402. } else {
  403. call_local_script = config.call_local;
  404. }
  405. }
  406. if (p_peer_id != node_id) {
  407. #ifdef DEBUG_ENABLED
  408. _profile_node_data("rpc_out", node->get_instance_id());
  409. #endif
  410. _send_rpc(node, p_peer_id, rpc_id, config, p_method, p_arg, p_argcount);
  411. }
  412. if (call_local_native) {
  413. Callable::CallError ce;
  414. multiplayer->set_remote_sender_override(peer->get_unique_id());
  415. node->callp(p_method, p_arg, p_argcount, ce);
  416. multiplayer->set_remote_sender_override(0);
  417. if (ce.error != Callable::CallError::CALL_OK) {
  418. String error = Variant::get_call_error_text(node, p_method, p_arg, p_argcount, ce);
  419. error = "rpc() aborted in local call: - " + error + ".";
  420. ERR_PRINT(error);
  421. return;
  422. }
  423. }
  424. if (call_local_script) {
  425. Callable::CallError ce;
  426. ce.error = Callable::CallError::CALL_OK;
  427. multiplayer->set_remote_sender_override(peer->get_unique_id());
  428. node->get_script_instance()->callp(p_method, p_arg, p_argcount, ce);
  429. multiplayer->set_remote_sender_override(0);
  430. if (ce.error != Callable::CallError::CALL_OK) {
  431. String error = Variant::get_call_error_text(node, p_method, p_arg, p_argcount, ce);
  432. error = "rpc() aborted in script local call: - " + error + ".";
  433. ERR_PRINT(error);
  434. return;
  435. }
  436. }
  437. ERR_FAIL_COND_MSG(p_peer_id == node_id && !config.call_local, "RPC '" + p_method + "' on yourself is not allowed by selected mode.");
  438. }