rpc_manager.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*************************************************************************/
  2. /* rpc_manager.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 "core/multiplayer/rpc_manager.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. #ifdef DEBUG_ENABLED
  36. _FORCE_INLINE_ void RPCManager::_profile_node_data(const String &p_what, ObjectID p_id) {
  37. if (EngineDebugger::is_profiling("multiplayer")) {
  38. Array values;
  39. values.push_back("node");
  40. values.push_back(p_id);
  41. values.push_back(p_what);
  42. EngineDebugger::profiler_add_frame_data("multiplayer", values);
  43. }
  44. }
  45. #else
  46. _FORCE_INLINE_ void RPCManager::_profile_node_data(const String &p_what, ObjectID p_id) {}
  47. #endif
  48. // Returns the packet size stripping the node path added when the node is not yet cached.
  49. int get_packet_len(uint32_t p_node_target, int p_packet_len) {
  50. if (p_node_target & 0x80000000) {
  51. int ofs = p_node_target & 0x7FFFFFFF;
  52. return p_packet_len - (p_packet_len - ofs);
  53. } else {
  54. return p_packet_len;
  55. }
  56. }
  57. const Multiplayer::RPCConfig _get_rpc_config(const Node *p_node, const StringName &p_method, uint16_t &r_id) {
  58. const Vector<Multiplayer::RPCConfig> node_config = p_node->get_node_rpc_methods();
  59. for (int i = 0; i < node_config.size(); i++) {
  60. if (node_config[i].name == p_method) {
  61. r_id = ((uint16_t)i) | (1 << 15);
  62. return node_config[i];
  63. }
  64. }
  65. if (p_node->get_script_instance()) {
  66. const Vector<Multiplayer::RPCConfig> script_config = p_node->get_script_instance()->get_rpc_methods();
  67. for (int i = 0; i < script_config.size(); i++) {
  68. if (script_config[i].name == p_method) {
  69. r_id = (uint16_t)i;
  70. return script_config[i];
  71. }
  72. }
  73. }
  74. return Multiplayer::RPCConfig();
  75. }
  76. const Multiplayer::RPCConfig _get_rpc_config_by_id(Node *p_node, uint16_t p_id) {
  77. Vector<Multiplayer::RPCConfig> config;
  78. uint16_t id = p_id;
  79. if (id & (1 << 15)) {
  80. id = id & ~(1 << 15);
  81. config = p_node->get_node_rpc_methods();
  82. } else if (p_node->get_script_instance()) {
  83. config = p_node->get_script_instance()->get_rpc_methods();
  84. }
  85. if (id < config.size()) {
  86. return config[id];
  87. }
  88. return Multiplayer::RPCConfig();
  89. }
  90. _FORCE_INLINE_ bool _can_call_mode(Node *p_node, Multiplayer::RPCMode mode, int p_remote_id) {
  91. switch (mode) {
  92. case Multiplayer::RPC_MODE_DISABLED: {
  93. return false;
  94. } break;
  95. case Multiplayer::RPC_MODE_ANY: {
  96. return true;
  97. } break;
  98. case Multiplayer::RPC_MODE_AUTHORITY: {
  99. return !p_node->is_network_authority() && p_remote_id == p_node->get_network_authority();
  100. } break;
  101. }
  102. return false;
  103. }
  104. String RPCManager::get_rpc_md5(const Node *p_node) {
  105. String rpc_list;
  106. const Vector<Multiplayer::RPCConfig> node_config = p_node->get_node_rpc_methods();
  107. for (int i = 0; i < node_config.size(); i++) {
  108. rpc_list += String(node_config[i].name);
  109. }
  110. if (p_node->get_script_instance()) {
  111. const Vector<Multiplayer::RPCConfig> script_config = p_node->get_script_instance()->get_rpc_methods();
  112. for (int i = 0; i < script_config.size(); i++) {
  113. rpc_list += String(script_config[i].name);
  114. }
  115. }
  116. return rpc_list.md5_text();
  117. }
  118. Node *RPCManager::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) {
  119. Node *node = nullptr;
  120. if (p_node_target & 0x80000000) {
  121. // Use full path (not cached yet).
  122. int ofs = p_node_target & 0x7FFFFFFF;
  123. ERR_FAIL_COND_V_MSG(ofs >= p_packet_len, nullptr, "Invalid packet received. Size smaller than declared.");
  124. String paths;
  125. paths.parse_utf8((const char *)&p_packet[ofs], p_packet_len - ofs);
  126. NodePath np = paths;
  127. node = multiplayer->get_root_node()->get_node(np);
  128. if (!node) {
  129. ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
  130. }
  131. return node;
  132. } else {
  133. // Use cached path.
  134. return multiplayer->get_cached_node(p_from, p_node_target);
  135. }
  136. }
  137. void RPCManager::process_rpc(int p_from, const uint8_t *p_packet, int p_packet_len) {
  138. // Extract packet meta
  139. int packet_min_size = 1;
  140. int name_id_offset = 1;
  141. ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
  142. // Compute the meta size, which depends on the compression level.
  143. int node_id_compression = (p_packet[0] & NODE_ID_COMPRESSION_FLAG) >> NODE_ID_COMPRESSION_SHIFT;
  144. int name_id_compression = (p_packet[0] & NAME_ID_COMPRESSION_FLAG) >> NAME_ID_COMPRESSION_SHIFT;
  145. switch (node_id_compression) {
  146. case NETWORK_NODE_ID_COMPRESSION_8:
  147. packet_min_size += 1;
  148. name_id_offset += 1;
  149. break;
  150. case NETWORK_NODE_ID_COMPRESSION_16:
  151. packet_min_size += 2;
  152. name_id_offset += 2;
  153. break;
  154. case NETWORK_NODE_ID_COMPRESSION_32:
  155. packet_min_size += 4;
  156. name_id_offset += 4;
  157. break;
  158. default:
  159. ERR_FAIL_MSG("Was not possible to extract the node id compression mode.");
  160. }
  161. switch (name_id_compression) {
  162. case NETWORK_NAME_ID_COMPRESSION_8:
  163. packet_min_size += 1;
  164. break;
  165. case NETWORK_NAME_ID_COMPRESSION_16:
  166. packet_min_size += 2;
  167. break;
  168. default:
  169. ERR_FAIL_MSG("Was not possible to extract the name id compression mode.");
  170. }
  171. ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
  172. uint32_t node_target = 0;
  173. switch (node_id_compression) {
  174. case NETWORK_NODE_ID_COMPRESSION_8:
  175. node_target = p_packet[1];
  176. break;
  177. case NETWORK_NODE_ID_COMPRESSION_16:
  178. node_target = decode_uint16(p_packet + 1);
  179. break;
  180. case NETWORK_NODE_ID_COMPRESSION_32:
  181. node_target = decode_uint32(p_packet + 1);
  182. break;
  183. default:
  184. // Unreachable, checked before.
  185. CRASH_NOW();
  186. }
  187. Node *node = _process_get_node(p_from, p_packet, node_target, p_packet_len);
  188. ERR_FAIL_COND_MSG(node == nullptr, "Invalid packet received. Requested node was not found.");
  189. uint16_t name_id = 0;
  190. switch (name_id_compression) {
  191. case NETWORK_NAME_ID_COMPRESSION_8:
  192. name_id = p_packet[name_id_offset];
  193. break;
  194. case NETWORK_NAME_ID_COMPRESSION_16:
  195. name_id = decode_uint16(p_packet + name_id_offset);
  196. break;
  197. default:
  198. // Unreachable, checked before.
  199. CRASH_NOW();
  200. }
  201. const int packet_len = get_packet_len(node_target, p_packet_len);
  202. _process_rpc(node, name_id, p_from, p_packet, packet_len, packet_min_size);
  203. }
  204. void RPCManager::_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) {
  205. ERR_FAIL_COND_MSG(p_offset > p_packet_len, "Invalid packet received. Size too small.");
  206. // Check that remote can call the RPC on this node.
  207. const Multiplayer::RPCConfig config = _get_rpc_config_by_id(p_node, p_rpc_method_id);
  208. ERR_FAIL_COND(config.name == StringName());
  209. bool can_call = _can_call_mode(p_node, config.rpc_mode, p_from);
  210. 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_network_authority()) + ".");
  211. int argc = 0;
  212. bool byte_only = false;
  213. const bool byte_only_or_no_args = p_packet[0] & BYTE_ONLY_OR_NO_ARGS_FLAG;
  214. if (byte_only_or_no_args) {
  215. if (p_offset < p_packet_len) {
  216. // This packet contains only bytes.
  217. argc = 1;
  218. byte_only = true;
  219. } else {
  220. // This rpc calls a method without parameters.
  221. }
  222. } else {
  223. // Normal variant, takes the argument count from the packet.
  224. ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
  225. argc = p_packet[p_offset];
  226. p_offset += 1;
  227. }
  228. Vector<Variant> args;
  229. Vector<const Variant *> argp;
  230. args.resize(argc);
  231. argp.resize(argc);
  232. #ifdef DEBUG_ENABLED
  233. _profile_node_data("in_rpc", p_node->get_instance_id());
  234. #endif
  235. if (byte_only) {
  236. Vector<uint8_t> pure_data;
  237. const int len = p_packet_len - p_offset;
  238. pure_data.resize(len);
  239. memcpy(pure_data.ptrw(), &p_packet[p_offset], len);
  240. args.write[0] = pure_data;
  241. argp.write[0] = &args[0];
  242. p_offset += len;
  243. } else {
  244. for (int i = 0; i < argc; i++) {
  245. ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
  246. int vlen;
  247. Error err = multiplayer->decode_and_decompress_variant(args.write[i], &p_packet[p_offset], p_packet_len - p_offset, &vlen);
  248. ERR_FAIL_COND_MSG(err != OK, "Invalid packet received. Unable to decode RPC argument.");
  249. argp.write[i] = &args[i];
  250. p_offset += vlen;
  251. }
  252. }
  253. Callable::CallError ce;
  254. p_node->call(config.name, (const Variant **)argp.ptr(), argc, ce);
  255. if (ce.error != Callable::CallError::CALL_OK) {
  256. String error = Variant::get_call_error_text(p_node, config.name, (const Variant **)argp.ptr(), argc, ce);
  257. error = "RPC - " + error;
  258. ERR_PRINT(error);
  259. }
  260. }
  261. void RPCManager::_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) {
  262. Ref<MultiplayerPeer> network_peer = multiplayer->get_network_peer();
  263. ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree.");
  264. ERR_FAIL_COND_MSG(network_peer->get_connection_status() == MultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree.");
  265. ERR_FAIL_COND_MSG(network_peer->get_connection_status() == MultiplayerPeer::CONNECTION_DISCONNECTED, "Attempt to remote call/set when networking is disconnected.");
  266. ERR_FAIL_COND_MSG(p_argcount > 255, "Too many arguments >255.");
  267. if (p_to != 0 && !multiplayer->get_network_connected_peers().has(ABS(p_to))) {
  268. ERR_FAIL_COND_MSG(p_to == network_peer->get_unique_id(), "Attempt to remote call/set yourself! unique ID: " + itos(network_peer->get_unique_id()) + ".");
  269. ERR_FAIL_MSG("Attempt to remote call unexisting ID: " + itos(p_to) + ".");
  270. }
  271. NodePath from_path = (multiplayer->get_root_node()->get_path()).rel_path_to(p_from->get_path());
  272. ERR_FAIL_COND_MSG(from_path.is_empty(), "Unable to send RPC. Relative path is empty. THIS IS LIKELY A BUG IN THE ENGINE!");
  273. // See if all peers have cached path (if so, call can be fast).
  274. int psc_id;
  275. const bool has_all_peers = multiplayer->send_confirm_path(p_from, from_path, p_to, psc_id);
  276. // Create base packet, lots of hardcode because it must be tight.
  277. int ofs = 0;
  278. #define MAKE_ROOM(m_amount) \
  279. if (packet_cache.size() < m_amount) \
  280. packet_cache.resize(m_amount);
  281. // Encode meta.
  282. uint8_t command_type = MultiplayerAPI::NETWORK_COMMAND_REMOTE_CALL;
  283. uint8_t node_id_compression = UINT8_MAX;
  284. uint8_t name_id_compression = UINT8_MAX;
  285. bool byte_only_or_no_args = false;
  286. MAKE_ROOM(1);
  287. // The meta is composed along the way, so just set 0 for now.
  288. packet_cache.write[0] = 0;
  289. ofs += 1;
  290. // Encode Node ID.
  291. if (has_all_peers) {
  292. // Compress the node ID only if all the target peers already know it.
  293. if (psc_id >= 0 && psc_id <= 255) {
  294. // We can encode the id in 1 byte
  295. node_id_compression = NETWORK_NODE_ID_COMPRESSION_8;
  296. MAKE_ROOM(ofs + 1);
  297. packet_cache.write[ofs] = static_cast<uint8_t>(psc_id);
  298. ofs += 1;
  299. } else if (psc_id >= 0 && psc_id <= 65535) {
  300. // We can encode the id in 2 bytes
  301. node_id_compression = NETWORK_NODE_ID_COMPRESSION_16;
  302. MAKE_ROOM(ofs + 2);
  303. encode_uint16(static_cast<uint16_t>(psc_id), &(packet_cache.write[ofs]));
  304. ofs += 2;
  305. } else {
  306. // Too big, let's use 4 bytes.
  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. } else {
  313. // The targets don't know the node yet, so we need to use 32 bits int.
  314. node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
  315. MAKE_ROOM(ofs + 4);
  316. encode_uint32(psc_id, &(packet_cache.write[ofs]));
  317. ofs += 4;
  318. }
  319. // Encode method ID
  320. if (p_rpc_id <= UINT8_MAX) {
  321. // The ID fits in 1 byte
  322. name_id_compression = NETWORK_NAME_ID_COMPRESSION_8;
  323. MAKE_ROOM(ofs + 1);
  324. packet_cache.write[ofs] = static_cast<uint8_t>(p_rpc_id);
  325. ofs += 1;
  326. } else {
  327. // The ID is larger, let's use 2 bytes
  328. name_id_compression = NETWORK_NAME_ID_COMPRESSION_16;
  329. MAKE_ROOM(ofs + 2);
  330. encode_uint16(p_rpc_id, &(packet_cache.write[ofs]));
  331. ofs += 2;
  332. }
  333. if (p_argcount == 0) {
  334. byte_only_or_no_args = true;
  335. } else if (p_argcount == 1 && p_arg[0]->get_type() == Variant::PACKED_BYTE_ARRAY) {
  336. byte_only_or_no_args = true;
  337. // Special optimization when only the byte vector is sent.
  338. const Vector<uint8_t> data = *p_arg[0];
  339. MAKE_ROOM(ofs + data.size());
  340. memcpy(&(packet_cache.write[ofs]), data.ptr(), sizeof(uint8_t) * data.size());
  341. ofs += data.size();
  342. } else {
  343. // Arguments
  344. MAKE_ROOM(ofs + 1);
  345. packet_cache.write[ofs] = p_argcount;
  346. ofs += 1;
  347. for (int i = 0; i < p_argcount; i++) {
  348. int len(0);
  349. Error err = multiplayer->encode_and_compress_variant(*p_arg[i], nullptr, len);
  350. ERR_FAIL_COND_MSG(err != OK, "Unable to encode RPC argument. THIS IS LIKELY A BUG IN THE ENGINE!");
  351. MAKE_ROOM(ofs + len);
  352. multiplayer->encode_and_compress_variant(*p_arg[i], &(packet_cache.write[ofs]), len);
  353. ofs += len;
  354. }
  355. }
  356. ERR_FAIL_COND(command_type > 7);
  357. ERR_FAIL_COND(node_id_compression > 3);
  358. ERR_FAIL_COND(name_id_compression > 1);
  359. // We can now set the meta
  360. 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);
  361. #ifdef DEBUG_ENABLED
  362. multiplayer->profile_bandwidth("out", ofs);
  363. #endif
  364. // Take chance and set transfer mode, since all send methods will use it.
  365. network_peer->set_transfer_channel(p_config.channel);
  366. network_peer->set_transfer_mode(p_config.transfer_mode);
  367. if (has_all_peers) {
  368. // They all have verified paths, so send fast.
  369. network_peer->set_target_peer(p_to); // To all of you.
  370. network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
  371. } else {
  372. // Unreachable because the node ID is never compressed if the peers doesn't know it.
  373. CRASH_COND(node_id_compression != NETWORK_NODE_ID_COMPRESSION_32);
  374. // Not all verified path, so send one by one.
  375. // Append path at the end, since we will need it for some packets.
  376. CharString pname = String(from_path).utf8();
  377. int path_len = encode_cstring(pname.get_data(), nullptr);
  378. MAKE_ROOM(ofs + path_len);
  379. encode_cstring(pname.get_data(), &(packet_cache.write[ofs]));
  380. for (const int &P : multiplayer->get_connected_peers()) {
  381. if (p_to < 0 && P == -p_to) {
  382. continue; // Continue, excluded.
  383. }
  384. if (p_to > 0 && P != p_to) {
  385. continue; // Continue, not for this peer.
  386. }
  387. bool confirmed = multiplayer->is_cache_confirmed(from_path, P);
  388. network_peer->set_target_peer(P); // To this one specifically.
  389. if (confirmed) {
  390. // This one confirmed path, so use id.
  391. encode_uint32(psc_id, &(packet_cache.write[1]));
  392. network_peer->put_packet(packet_cache.ptr(), ofs);
  393. } else {
  394. // This one did not confirm path yet, so use entire path (sorry!).
  395. encode_uint32(0x80000000 | ofs, &(packet_cache.write[1])); // Offset to path and flag.
  396. network_peer->put_packet(packet_cache.ptr(), ofs + path_len);
  397. }
  398. }
  399. }
  400. }
  401. void RPCManager::rpcp(Node *p_node, int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount) {
  402. Ref<MultiplayerPeer> network_peer = multiplayer->get_network_peer();
  403. ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to call an RPC while no network peer is active.");
  404. ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree.");
  405. ERR_FAIL_COND_MSG(network_peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected.");
  406. int node_id = network_peer->get_unique_id();
  407. bool call_local_native = false;
  408. bool call_local_script = false;
  409. uint16_t rpc_id = UINT16_MAX;
  410. const Multiplayer::RPCConfig config = _get_rpc_config(p_node, p_method, rpc_id);
  411. ERR_FAIL_COND_MSG(config.name == StringName(),
  412. vformat("Unable to get the RPC configuration for the function \"%s\" at path: \"%s\". This happens when the method is not marked for RPCs.", p_method, p_node->get_path()));
  413. if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
  414. if (rpc_id & (1 << 15)) {
  415. call_local_native = config.sync;
  416. } else {
  417. call_local_script = config.sync;
  418. }
  419. }
  420. if (p_peer_id != node_id) {
  421. #ifdef DEBUG_ENABLED
  422. _profile_node_data("out_rpc", p_node->get_instance_id());
  423. #endif
  424. _send_rpc(p_node, p_peer_id, rpc_id, config, p_method, p_arg, p_argcount);
  425. }
  426. if (call_local_native) {
  427. Callable::CallError ce;
  428. multiplayer->set_remote_sender_override(network_peer->get_unique_id());
  429. p_node->call(p_method, p_arg, p_argcount, ce);
  430. multiplayer->set_remote_sender_override(0);
  431. if (ce.error != Callable::CallError::CALL_OK) {
  432. String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce);
  433. error = "rpc() aborted in local call: - " + error + ".";
  434. ERR_PRINT(error);
  435. return;
  436. }
  437. }
  438. if (call_local_script) {
  439. Callable::CallError ce;
  440. ce.error = Callable::CallError::CALL_OK;
  441. multiplayer->set_remote_sender_override(network_peer->get_unique_id());
  442. p_node->get_script_instance()->call(p_method, p_arg, p_argcount, ce);
  443. multiplayer->set_remote_sender_override(0);
  444. if (ce.error != Callable::CallError::CALL_OK) {
  445. String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce);
  446. error = "rpc() aborted in script local call: - " + error + ".";
  447. ERR_PRINT(error);
  448. return;
  449. }
  450. }
  451. ERR_FAIL_COND_MSG(p_peer_id == node_id && !config.sync, "RPC '" + p_method + "' on yourself is not allowed by selected mode.");
  452. }