summaryrefslogtreecommitdiff
path: root/core/io/multiplayer_api.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/multiplayer_api.cpp')
-rw-r--r--core/io/multiplayer_api.cpp44
1 files changed, 0 insertions, 44 deletions
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 998bcfd3f3..b819725155 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -45,9 +45,7 @@
#endif
_FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_master, bool &r_skip_rpc) {
-
switch (mode) {
-
case MultiplayerAPI::RPC_MODE_DISABLED: {
// Do nothing.
} break;
@@ -78,7 +76,6 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
_FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, int p_remote_id) {
switch (mode) {
-
case MultiplayerAPI::RPC_MODE_DISABLED: {
return false;
} break;
@@ -100,7 +97,6 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i
}
void MultiplayerAPI::poll() {
-
if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED)
return;
@@ -110,7 +106,6 @@ void MultiplayerAPI::poll() {
return;
while (network_peer->get_available_packet_count()) {
-
int sender = network_peer->get_packet_peer();
const uint8_t *packet;
int len;
@@ -144,7 +139,6 @@ void MultiplayerAPI::set_root_node(Node *p_node) {
}
void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) {
-
if (p_peer == network_peer)
return; // Nothing to do
@@ -208,7 +202,6 @@ int get_packet_len(uint32_t p_node_target, int p_packet_len) {
}
void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {
-
ERR_FAIL_COND_MSG(root_node == nullptr, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it.");
ERR_FAIL_COND_MSG(p_packet_len < 1, "Invalid packet received. Size too small.");
@@ -220,20 +213,16 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
uint8_t packet_type = p_packet[0] & 7;
switch (packet_type) {
-
case NETWORK_COMMAND_SIMPLIFY_PATH: {
-
_process_simplify_path(p_from, p_packet, p_packet_len);
} break;
case NETWORK_COMMAND_CONFIRM_PATH: {
-
_process_confirm_path(p_from, p_packet, p_packet_len);
} break;
case NETWORK_COMMAND_REMOTE_CALL:
case NETWORK_COMMAND_REMOTE_SET: {
-
// Extract packet meta
int packet_min_size = 1;
int name_id_offset = 1;
@@ -304,25 +293,21 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
const int packet_len = get_packet_len(node_target, p_packet_len);
if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {
-
_process_rpc(node, name_id, p_from, p_packet, packet_len, packet_min_size);
} else {
-
_process_rset(node, name_id, p_from, p_packet, packet_len, packet_min_size);
}
} break;
case NETWORK_COMMAND_RAW: {
-
_process_raw(p_from, p_packet, p_packet_len);
} break;
}
}
Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) {
-
Node *node = nullptr;
if (p_node_target & 0x80000000) {
@@ -362,7 +347,6 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin
}
void MultiplayerAPI::_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) {
-
ERR_FAIL_COND_MSG(p_offset > p_packet_len, "Invalid packet received. Size too small.");
// Check that remote can call the RPC on this node.
@@ -415,7 +399,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id,
p_offset += len;
} else {
for (int i = 0; i < argc; i++) {
-
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
int vlen;
@@ -438,7 +421,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id,
}
void MultiplayerAPI::_process_rset(Node *p_node, const uint16_t p_rpc_property_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
-
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
// Check that remote can call the RSET on this node.
@@ -472,7 +454,6 @@ void MultiplayerAPI::_process_rset(Node *p_node, const uint16_t p_rpc_property_i
}
void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
-
ERR_FAIL_COND_MSG(p_packet_len < 38, "Invalid packet received. Size too small.");
int ofs = 1;
@@ -521,7 +502,6 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
}
void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
-
ERR_FAIL_COND_MSG(p_packet_len < 3, "Invalid packet received. Size too small.");
const bool valid_rpc_checksum = p_packet[1];
@@ -548,7 +528,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
List<int> peers_to_add; // If one is missing, take note to add it.
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
-
if (p_target < 0 && E->get() == -p_target)
continue; // Continue, excluded.
@@ -569,7 +548,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
}
if (peers_to_add.size() > 0) {
-
// Those that need to be added, send a message for this.
// Encode function name.
@@ -594,7 +572,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
ofs += encode_cstring(path.get_data(), &packet.write[ofs]);
for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
-
network_peer->set_target_peer(E->get()); // To all of you.
network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
network_peer->put_packet(packet.ptr(), packet.size());
@@ -619,7 +596,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
#define ENCODE_32 2 << 5
#define ENCODE_64 3 << 5
Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
-
// Unreachable because `VARIANT_MAX` == 27 and `ENCODE_VARIANT_MASK` == 31
CRASH_COND(p_variant.get_type() > VARIANT_META_TYPE_MASK);
@@ -693,7 +669,6 @@ Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uin
return OK;
}
Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len) {
-
const uint8_t *buf = p_buffer;
int len = p_len;
@@ -755,7 +730,6 @@ Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const u
}
void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) {
-
ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree.");
@@ -841,7 +815,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
}
if (p_set) {
-
// Take the rpc property ID
uint16_t property_id = p_from->get_node_rset_property_id(p_name);
if (property_id == UINT16_MAX && p_from->get_script_instance()) {
@@ -934,7 +907,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
if (has_all_peers) {
-
// They all have verified paths, so send fast.
network_peer->set_target_peer(p_to); // To all of you.
network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
@@ -951,7 +923,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
encode_cstring(pname.get_data(), &(packet_cache.write[ofs]));
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
-
if (p_to < 0 && E->get() == -p_to)
continue; // Continue, excluded.
@@ -998,22 +969,18 @@ void MultiplayerAPI::_del_peer(int p_id) {
}
void MultiplayerAPI::_connected_to_server() {
-
emit_signal("connected_to_server");
}
void MultiplayerAPI::_connection_failed() {
-
emit_signal("connection_failed");
}
void MultiplayerAPI::_server_disconnected() {
-
emit_signal("server_disconnected");
}
void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) {
-
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to call an RPC while no network peer is active.");
ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected.");
@@ -1040,7 +1007,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
if (!skip_rpc) {
-
#ifdef DEBUG_ENABLED
_profile_node_data("out_rpc", p_node->get_instance_id());
#endif
@@ -1081,7 +1047,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) {
-
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to RSET while no network peer is active.");
ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to RSET on a node which is not inside SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to send an RSET via a network peer which is not connected.");
@@ -1146,7 +1111,6 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
Error MultiplayerAPI::send_bytes(Vector<uint8_t> p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) {
-
ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet.");
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no network peer is active.");
ERR_FAIL_COND_V_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a network peer which is not connected.");
@@ -1163,7 +1127,6 @@ Error MultiplayerAPI::send_bytes(Vector<uint8_t> p_data, int p_to, NetworkedMult
}
void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) {
-
ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small.");
Vector<uint8_t> out;
@@ -1177,32 +1140,27 @@ void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_pac
}
int MultiplayerAPI::get_network_unique_id() const {
-
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), 0, "No network peer is assigned. Unable to get unique network ID.");
return network_peer->get_unique_id();
}
bool MultiplayerAPI::is_network_server() const {
-
// XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier?
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. I can't be a server.");
return network_peer->is_server();
}
void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) {
-
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "No network peer is assigned. Unable to set 'refuse_new_connections'.");
network_peer->set_refuse_new_connections(p_refuse);
}
bool MultiplayerAPI::is_refusing_new_network_connections() const {
-
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. Unable to get 'refuse_new_connections'.");
return network_peer->is_refusing_new_connections();
}
Vector<int> MultiplayerAPI::get_network_connected_peers() const {
-
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), Vector<int>(), "No network peer is assigned. Assume no peers are connected.");
Vector<int> ret;
@@ -1214,12 +1172,10 @@ Vector<int> MultiplayerAPI::get_network_connected_peers() const {
}
void MultiplayerAPI::set_allow_object_decoding(bool p_enable) {
-
allow_object_decoding = p_enable;
}
bool MultiplayerAPI::is_object_decoding_allowed() const {
-
return allow_object_decoding;
}