Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/multiplayer/scene_rpc_interface.cpp
10277 views
1
/**************************************************************************/
2
/* scene_rpc_interface.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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
31
#include "scene_rpc_interface.h"
32
33
#include "scene_multiplayer.h"
34
35
#include "core/debugger/engine_debugger.h"
36
#include "core/io/marshalls.h"
37
#include "scene/main/multiplayer_api.h"
38
#include "scene/main/node.h"
39
#include "scene/main/window.h"
40
41
// The RPC meta is composed by a single byte that contains (starting from the least significant bit):
42
// - `NetworkCommands` in the first four bits.
43
// - `NetworkNodeIdCompression` in the next 2 bits.
44
// - `NetworkNameIdCompression` in the next 1 bit.
45
// - `byte_only_or_no_args` in the next 1 bit.
46
#define NODE_ID_COMPRESSION_SHIFT SceneMultiplayer::CMD_FLAG_0_SHIFT
47
#define NAME_ID_COMPRESSION_SHIFT SceneMultiplayer::CMD_FLAG_2_SHIFT
48
#define BYTE_ONLY_OR_NO_ARGS_SHIFT SceneMultiplayer::CMD_FLAG_3_SHIFT
49
50
#define NODE_ID_COMPRESSION_FLAG ((1 << NODE_ID_COMPRESSION_SHIFT) | (1 << (NODE_ID_COMPRESSION_SHIFT + 1)))
51
#define NAME_ID_COMPRESSION_FLAG (1 << NAME_ID_COMPRESSION_SHIFT)
52
#define BYTE_ONLY_OR_NO_ARGS_FLAG (1 << BYTE_ONLY_OR_NO_ARGS_SHIFT)
53
54
#ifdef DEBUG_ENABLED
55
_FORCE_INLINE_ void SceneRPCInterface::_profile_node_data(const String &p_what, ObjectID p_id, int p_size) {
56
if (EngineDebugger::is_profiling("multiplayer:rpc")) {
57
Array values = { p_what, p_id, p_size };
58
EngineDebugger::profiler_add_frame_data("multiplayer:rpc", values);
59
}
60
}
61
#endif
62
63
// Returns the packet size stripping the node path added when the node is not yet cached.
64
int get_packet_len(uint32_t p_node_target, int p_packet_len) {
65
if (p_node_target & 0x80000000) {
66
int ofs = p_node_target & 0x7FFFFFFF;
67
return p_packet_len - (p_packet_len - ofs);
68
} else {
69
return p_packet_len;
70
}
71
}
72
73
void SceneRPCInterface::_parse_rpc_config(const Variant &p_config, bool p_for_node, RPCConfigCache &r_cache) {
74
if (p_config.get_type() == Variant::NIL) {
75
return;
76
}
77
ERR_FAIL_COND(p_config.get_type() != Variant::DICTIONARY);
78
const Dictionary config = p_config;
79
Array names = config.keys();
80
names.sort_custom(callable_mp_static(&StringLikeVariantOrder::compare)); // Ensure ID order
81
for (int i = 0; i < names.size(); i++) {
82
ERR_CONTINUE(!names[i].is_string());
83
String name = names[i].operator String();
84
ERR_CONTINUE(config[name].get_type() != Variant::DICTIONARY);
85
ERR_CONTINUE(!config[name].operator Dictionary().has("rpc_mode"));
86
Dictionary dict = config[name];
87
RPCConfig cfg;
88
cfg.name = name;
89
cfg.rpc_mode = ((MultiplayerAPI::RPCMode)dict.get("rpc_mode", MultiplayerAPI::RPC_MODE_AUTHORITY).operator int());
90
cfg.transfer_mode = ((MultiplayerPeer::TransferMode)dict.get("transfer_mode", MultiplayerPeer::TRANSFER_MODE_RELIABLE).operator int());
91
cfg.call_local = dict.get("call_local", false).operator bool();
92
cfg.channel = dict.get("channel", 0).operator int();
93
uint16_t id = ((uint16_t)i);
94
if (p_for_node) {
95
id |= (1 << 15);
96
}
97
r_cache.configs[id] = cfg;
98
r_cache.ids[name] = id;
99
}
100
}
101
102
const SceneRPCInterface::RPCConfigCache &SceneRPCInterface::_get_node_config(const Node *p_node) {
103
const ObjectID oid = p_node->get_instance_id();
104
if (rpc_cache.has(oid)) {
105
return rpc_cache[oid];
106
}
107
RPCConfigCache cache;
108
_parse_rpc_config(p_node->get_node_rpc_config(), true, cache);
109
if (p_node->get_script_instance()) {
110
_parse_rpc_config(p_node->get_script_instance()->get_rpc_config(), false, cache);
111
}
112
rpc_cache[oid] = cache;
113
return rpc_cache[oid];
114
}
115
116
String SceneRPCInterface::get_rpc_md5(const Object *p_obj) {
117
const Node *node = Object::cast_to<Node>(p_obj);
118
ERR_FAIL_NULL_V(node, "");
119
const RPCConfigCache cache = _get_node_config(node);
120
String rpc_list;
121
for (const KeyValue<uint16_t, RPCConfig> &config : cache.configs) {
122
rpc_list += String(config.value.name);
123
}
124
return rpc_list.md5_text();
125
}
126
127
Node *SceneRPCInterface::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) {
128
Node *root_node = SceneTree::get_singleton()->get_root()->get_node(multiplayer->get_root_path());
129
ERR_FAIL_NULL_V(root_node, nullptr);
130
Node *node = nullptr;
131
132
if (p_node_target & 0x80000000) {
133
// Use full path (not cached yet).
134
int ofs = p_node_target & 0x7FFFFFFF;
135
136
ERR_FAIL_COND_V_MSG(ofs >= p_packet_len, nullptr, "Invalid packet received. Size smaller than declared.");
137
138
String paths = String::utf8((const char *)&p_packet[ofs], p_packet_len - ofs);
139
140
NodePath np = paths;
141
142
node = root_node->get_node(np);
143
144
if (!node) {
145
ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
146
}
147
return node;
148
} else {
149
// Use cached path.
150
return Object::cast_to<Node>(multiplayer_cache->get_cached_object(p_from, p_node_target));
151
}
152
}
153
154
void SceneRPCInterface::process_rpc(int p_from, const uint8_t *p_packet, int p_packet_len) {
155
// Extract packet meta
156
int packet_min_size = 1;
157
int name_id_offset = 1;
158
ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
159
// Compute the meta size, which depends on the compression level.
160
int node_id_compression = (p_packet[0] & NODE_ID_COMPRESSION_FLAG) >> NODE_ID_COMPRESSION_SHIFT;
161
int name_id_compression = (p_packet[0] & NAME_ID_COMPRESSION_FLAG) >> NAME_ID_COMPRESSION_SHIFT;
162
163
switch (node_id_compression) {
164
case NETWORK_NODE_ID_COMPRESSION_8:
165
packet_min_size += 1;
166
name_id_offset += 1;
167
break;
168
case NETWORK_NODE_ID_COMPRESSION_16:
169
packet_min_size += 2;
170
name_id_offset += 2;
171
break;
172
case NETWORK_NODE_ID_COMPRESSION_32:
173
packet_min_size += 4;
174
name_id_offset += 4;
175
break;
176
default:
177
ERR_FAIL_MSG("Was not possible to extract the node id compression mode.");
178
}
179
switch (name_id_compression) {
180
case NETWORK_NAME_ID_COMPRESSION_8:
181
packet_min_size += 1;
182
break;
183
case NETWORK_NAME_ID_COMPRESSION_16:
184
packet_min_size += 2;
185
break;
186
default:
187
ERR_FAIL_MSG("Was not possible to extract the name id compression mode.");
188
}
189
ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
190
191
uint32_t node_target = 0;
192
switch (node_id_compression) {
193
case NETWORK_NODE_ID_COMPRESSION_8:
194
node_target = p_packet[1];
195
break;
196
case NETWORK_NODE_ID_COMPRESSION_16:
197
node_target = decode_uint16(p_packet + 1);
198
break;
199
case NETWORK_NODE_ID_COMPRESSION_32:
200
node_target = decode_uint32(p_packet + 1);
201
break;
202
default:
203
// Unreachable, checked before.
204
CRASH_NOW();
205
}
206
207
Node *node = _process_get_node(p_from, p_packet, node_target, p_packet_len);
208
ERR_FAIL_NULL_MSG(node, "Invalid packet received. Requested node was not found.");
209
210
uint16_t name_id = 0;
211
switch (name_id_compression) {
212
case NETWORK_NAME_ID_COMPRESSION_8:
213
name_id = p_packet[name_id_offset];
214
break;
215
case NETWORK_NAME_ID_COMPRESSION_16:
216
name_id = decode_uint16(p_packet + name_id_offset);
217
break;
218
default:
219
// Unreachable, checked before.
220
CRASH_NOW();
221
}
222
223
const int packet_len = get_packet_len(node_target, p_packet_len);
224
_process_rpc(node, name_id, p_from, p_packet, packet_len, packet_min_size);
225
}
226
227
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) {
228
ERR_FAIL_COND_MSG(p_offset > p_packet_len, "Invalid packet received. Size too small.");
229
230
// Check that remote can call the RPC on this node.
231
const RPCConfigCache &cache_config = _get_node_config(p_node);
232
ERR_FAIL_COND(!cache_config.configs.has(p_rpc_method_id));
233
const RPCConfig &config = cache_config.configs[p_rpc_method_id];
234
235
bool can_call = false;
236
switch (config.rpc_mode) {
237
case MultiplayerAPI::RPC_MODE_DISABLED: {
238
can_call = false;
239
} break;
240
case MultiplayerAPI::RPC_MODE_ANY_PEER: {
241
can_call = true;
242
} break;
243
case MultiplayerAPI::RPC_MODE_AUTHORITY: {
244
can_call = p_from == p_node->get_multiplayer_authority();
245
} break;
246
}
247
248
ERR_FAIL_COND_MSG(!can_call, "RPC '" + String(config.name) + "' is not allowed on node " + String(p_node->get_path()) + " from: " + itos(p_from) + ". Mode is " + itos((int)config.rpc_mode) + ", authority is " + itos(p_node->get_multiplayer_authority()) + ".");
249
250
int argc = 0;
251
252
const bool byte_only_or_no_args = p_packet[0] & BYTE_ONLY_OR_NO_ARGS_FLAG;
253
if (byte_only_or_no_args) {
254
if (p_offset < p_packet_len) {
255
// This packet contains only bytes.
256
argc = 1;
257
}
258
} else {
259
// Normal variant, takes the argument count from the packet.
260
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
261
argc = p_packet[p_offset];
262
p_offset += 1;
263
}
264
265
Vector<Variant> args;
266
Vector<const Variant *> argp;
267
args.resize(argc);
268
argp.resize(argc);
269
270
#ifdef DEBUG_ENABLED
271
_profile_node_data("rpc_in", p_node->get_instance_id(), p_packet_len);
272
#endif
273
274
int out;
275
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());
276
for (int i = 0; i < argc; i++) {
277
argp.write[i] = &args[i];
278
}
279
280
Callable::CallError ce;
281
282
p_node->callp(config.name, (const Variant **)argp.ptr(), argc, ce);
283
if (ce.error != Callable::CallError::CALL_OK) {
284
String error = Variant::get_call_error_text(p_node, config.name, (const Variant **)argp.ptr(), argc, ce);
285
error = "RPC - " + error;
286
ERR_PRINT(error);
287
}
288
}
289
290
void SceneRPCInterface::_send_rpc(Node *p_node, int p_to, uint16_t p_rpc_id, const RPCConfig &p_config, const StringName &p_name, const Variant **p_arg, int p_argcount) {
291
Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer();
292
ERR_FAIL_COND_MSG(peer.is_null(), "Attempt to call RPC without active multiplayer peer.");
293
294
ERR_FAIL_COND_MSG(peer->get_connection_status() == MultiplayerPeer::CONNECTION_CONNECTING, "Attempt to call RPC while multiplayer peer is not connected yet.");
295
296
ERR_FAIL_COND_MSG(peer->get_connection_status() == MultiplayerPeer::CONNECTION_DISCONNECTED, "Attempt to call RPC while multiplayer peer is disconnected.");
297
298
ERR_FAIL_COND_MSG(p_argcount > 255, "Too many arguments (>255).");
299
300
if (p_to != 0 && !multiplayer->get_connected_peers().has(Math::abs(p_to))) {
301
ERR_FAIL_COND_MSG(p_to == multiplayer->get_unique_id(), "Attempt to call RPC on yourself! Peer unique ID: " + itos(multiplayer->get_unique_id()) + ".");
302
303
ERR_FAIL_MSG("Attempt to call RPC with unknown peer ID: " + itos(p_to) + ".");
304
}
305
306
// See if all peers have cached path (if so, call can be fast) while building the RPC target list.
307
HashSet<int> targets;
308
int psc_id = -1;
309
bool has_all_peers = true;
310
const ObjectID oid = p_node->get_instance_id();
311
if (p_to > 0) {
312
ERR_FAIL_COND_MSG(!multiplayer_replicator->is_rpc_visible(oid, p_to), "Attempt to call an RPC to a peer that cannot see this node. Peer ID: " + itos(p_to));
313
targets.insert(p_to);
314
has_all_peers = multiplayer_cache->send_object_cache(p_node, p_to, psc_id);
315
} else {
316
bool restricted = !multiplayer_replicator->is_rpc_visible(oid, 0);
317
for (const int &P : multiplayer->get_connected_peers()) {
318
if (p_to < 0 && P == -p_to) {
319
continue; // Excluded peer.
320
}
321
if (restricted && !multiplayer_replicator->is_rpc_visible(oid, P)) {
322
continue; // Not visible to this peer.
323
}
324
targets.insert(P);
325
bool has_peer = multiplayer_cache->send_object_cache(p_node, P, psc_id);
326
has_all_peers = has_all_peers && has_peer;
327
}
328
}
329
if (targets.is_empty()) {
330
return; // No one in sight.
331
}
332
333
// Create base packet, lots of hardcode because it must be tight.
334
int ofs = 0;
335
336
#define MAKE_ROOM(m_amount) \
337
if (packet_cache.size() < m_amount) \
338
packet_cache.resize(m_amount);
339
340
// Encode meta.
341
uint8_t command_type = SceneMultiplayer::NETWORK_COMMAND_REMOTE_CALL;
342
uint8_t node_id_compression = UINT8_MAX;
343
uint8_t name_id_compression = UINT8_MAX;
344
bool byte_only_or_no_args = false;
345
346
MAKE_ROOM(1);
347
// The meta is composed along the way, so just set 0 for now.
348
packet_cache.write[0] = 0;
349
ofs += 1;
350
351
// Encode Node ID.
352
if (has_all_peers) {
353
// Compress the node ID only if all the target peers already know it.
354
if (psc_id >= 0 && psc_id <= 255) {
355
// We can encode the id in 1 byte
356
node_id_compression = NETWORK_NODE_ID_COMPRESSION_8;
357
MAKE_ROOM(ofs + 1);
358
packet_cache.write[ofs] = static_cast<uint8_t>(psc_id);
359
ofs += 1;
360
} else if (psc_id >= 0 && psc_id <= 65535) {
361
// We can encode the id in 2 bytes
362
node_id_compression = NETWORK_NODE_ID_COMPRESSION_16;
363
MAKE_ROOM(ofs + 2);
364
encode_uint16(static_cast<uint16_t>(psc_id), &(packet_cache.write[ofs]));
365
ofs += 2;
366
} else {
367
// Too big, let's use 4 bytes.
368
node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
369
MAKE_ROOM(ofs + 4);
370
encode_uint32(psc_id, &(packet_cache.write[ofs]));
371
ofs += 4;
372
}
373
} else {
374
// The targets don't know the node yet, so we need to use 32 bits int.
375
node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
376
MAKE_ROOM(ofs + 4);
377
encode_uint32(psc_id, &(packet_cache.write[ofs]));
378
ofs += 4;
379
}
380
381
// Encode method ID
382
if (p_rpc_id <= UINT8_MAX) {
383
// The ID fits in 1 byte
384
name_id_compression = NETWORK_NAME_ID_COMPRESSION_8;
385
MAKE_ROOM(ofs + 1);
386
packet_cache.write[ofs] = static_cast<uint8_t>(p_rpc_id);
387
ofs += 1;
388
} else {
389
// The ID is larger, let's use 2 bytes
390
name_id_compression = NETWORK_NAME_ID_COMPRESSION_16;
391
MAKE_ROOM(ofs + 2);
392
encode_uint16(p_rpc_id, &(packet_cache.write[ofs]));
393
ofs += 2;
394
}
395
396
int len;
397
Error err = MultiplayerAPI::encode_and_compress_variants(p_arg, p_argcount, nullptr, len, &byte_only_or_no_args, multiplayer->is_object_decoding_allowed());
398
ERR_FAIL_COND_MSG(err != OK, "Unable to encode RPC arguments. THIS IS LIKELY A BUG IN THE ENGINE!");
399
if (byte_only_or_no_args) {
400
MAKE_ROOM(ofs + len);
401
} else {
402
MAKE_ROOM(ofs + 1 + len);
403
packet_cache.write[ofs] = p_argcount;
404
ofs += 1;
405
}
406
if (len) {
407
MultiplayerAPI::encode_and_compress_variants(p_arg, p_argcount, &packet_cache.write[ofs], len, &byte_only_or_no_args, multiplayer->is_object_decoding_allowed());
408
ofs += len;
409
}
410
411
ERR_FAIL_COND(command_type > 7);
412
ERR_FAIL_COND(node_id_compression > 3);
413
ERR_FAIL_COND(name_id_compression > 1);
414
415
#ifdef DEBUG_ENABLED
416
_profile_node_data("rpc_out", p_node->get_instance_id(), ofs);
417
#endif
418
419
// We can now set the meta
420
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);
421
422
// Take chance and set transfer mode, since all send methods will use it.
423
peer->set_transfer_channel(p_config.channel);
424
peer->set_transfer_mode(p_config.transfer_mode);
425
426
if (has_all_peers) {
427
for (const int P : targets) {
428
multiplayer->send_command(P, packet_cache.ptr(), ofs);
429
}
430
} else {
431
// Unreachable because the node ID is never compressed if the peers doesn't know it.
432
CRASH_COND(node_id_compression != NETWORK_NODE_ID_COMPRESSION_32);
433
434
// Not all verified path, so send one by one.
435
436
// Append path at the end, since we will need it for some packets.
437
CharString pname = String(multiplayer->get_root_path().rel_path_to(p_node->get_path())).utf8();
438
int path_len = encode_cstring(pname.get_data(), nullptr);
439
MAKE_ROOM(ofs + path_len);
440
encode_cstring(pname.get_data(), &(packet_cache.write[ofs]));
441
442
// Not all verified path, so check which needs the longer packet.
443
for (const int P : targets) {
444
bool confirmed = multiplayer_cache->is_cache_confirmed(p_node, P);
445
if (confirmed) {
446
// This one confirmed path, so use id.
447
encode_uint32(psc_id, &(packet_cache.write[1]));
448
multiplayer->send_command(P, packet_cache.ptr(), ofs);
449
} else {
450
// This one did not confirm path yet, so use entire path (sorry!).
451
encode_uint32(0x80000000 | ofs, &(packet_cache.write[1])); // Offset to path and flag.
452
multiplayer->send_command(P, packet_cache.ptr(), ofs + path_len);
453
}
454
}
455
}
456
}
457
458
Error SceneRPCInterface::rpcp(Object *p_obj, int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount) {
459
Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer();
460
ERR_FAIL_COND_V_MSG(peer.is_null(), ERR_UNCONFIGURED, "Trying to call an RPC while no multiplayer peer is active.");
461
Node *node = Object::cast_to<Node>(p_obj);
462
ERR_FAIL_COND_V_MSG(!node || !node->is_inside_tree(), ERR_INVALID_PARAMETER, "The object must be a valid Node inside the SceneTree");
463
ERR_FAIL_COND_V_MSG(peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, ERR_CONNECTION_ERROR, "Trying to call an RPC via a multiplayer peer which is not connected.");
464
465
int caller_id = multiplayer->get_unique_id();
466
bool call_local_native = false;
467
bool call_local_script = false;
468
const RPCConfigCache &config_cache = _get_node_config(node);
469
uint16_t rpc_id = config_cache.ids.has(p_method) ? config_cache.ids[p_method] : UINT16_MAX;
470
ERR_FAIL_COND_V_MSG(rpc_id == UINT16_MAX, ERR_INVALID_PARAMETER,
471
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()));
472
const RPCConfig &config = config_cache.configs[rpc_id];
473
474
ERR_FAIL_COND_V_MSG(p_peer_id == caller_id && !config.call_local, ERR_INVALID_PARAMETER, "RPC '" + p_method + "' on yourself is not allowed by selected mode.");
475
476
if (p_peer_id == 0 || p_peer_id == caller_id || (p_peer_id < 0 && p_peer_id != -caller_id)) {
477
if (rpc_id & (1 << 15)) {
478
call_local_native = config.call_local;
479
} else {
480
call_local_script = config.call_local;
481
}
482
}
483
484
if (p_peer_id != caller_id) {
485
_send_rpc(node, p_peer_id, rpc_id, config, p_method, p_arg, p_argcount);
486
}
487
488
if (call_local_native) {
489
Callable::CallError ce;
490
491
multiplayer->set_remote_sender_override(multiplayer->get_unique_id());
492
node->callp(p_method, p_arg, p_argcount, ce);
493
multiplayer->set_remote_sender_override(0);
494
495
if (ce.error != Callable::CallError::CALL_OK) {
496
String error = Variant::get_call_error_text(node, p_method, p_arg, p_argcount, ce);
497
error = "rpc() aborted in local call: - " + error + ".";
498
ERR_PRINT(error);
499
return FAILED;
500
}
501
}
502
503
if (call_local_script) {
504
Callable::CallError ce;
505
ce.error = Callable::CallError::CALL_OK;
506
507
multiplayer->set_remote_sender_override(multiplayer->get_unique_id());
508
node->get_script_instance()->callp(p_method, p_arg, p_argcount, ce);
509
multiplayer->set_remote_sender_override(0);
510
511
if (ce.error != Callable::CallError::CALL_OK) {
512
String error = Variant::get_call_error_text(node, p_method, p_arg, p_argcount, ce);
513
error = "rpc() aborted in script local call: - " + error + ".";
514
ERR_PRINT(error);
515
return FAILED;
516
}
517
}
518
return OK;
519
}
520
521