diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-07-16 00:43:49 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-07-29 10:40:03 +0200 |
commit | 1e8bf86379ca818bf7208de5f04f986be95dc102 (patch) | |
tree | 58e22020da59410beec75c4b07ef85dfd95f4c4f /modules/enet | |
parent | 4cfa9bc0f1ef1d584705f36d70ee7f4d37a02b8c (diff) |
[Net] Add generate_unique_id to MultiplayerPeer.
Used by ENetMultiplayerPeer and WebSocketServer to generate network IDs,
and exposed to the user for p2p networks (e.g. WebRTCMultiplayerPeer)
and custom MultiplayerPeer implementations.
Diffstat (limited to 'modules/enet')
-rw-r--r-- | modules/enet/enet_multiplayer_peer.cpp | 23 | ||||
-rw-r--r-- | modules/enet/enet_multiplayer_peer.h | 1 |
2 files changed, 1 insertions, 23 deletions
diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index b4ca93f4d9..14f9b3b1b9 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -179,7 +179,7 @@ Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, in #endif address.port = p_port; - unique_id = _gen_unique_id(); + unique_id = generate_unique_id(); // Initiate connection, allocating enough channels ENetPeer *peer = enet_host_connect(host, &address, channel_count, unique_id); @@ -608,27 +608,6 @@ MultiplayerPeer::ConnectionStatus ENetMultiplayerPeer::get_connection_status() c return connection_status; } -uint32_t ENetMultiplayerPeer::_gen_unique_id() const { - uint32_t hash = 0; - - while (hash == 0 || hash == 1) { - hash = hash_djb2_one_32( - (uint32_t)OS::get_singleton()->get_ticks_usec()); - hash = hash_djb2_one_32( - (uint32_t)OS::get_singleton()->get_unix_time(), hash); - hash = hash_djb2_one_32( - (uint32_t)OS::get_singleton()->get_user_data_dir().hash64(), hash); - hash = hash_djb2_one_32( - (uint32_t)((uint64_t)this), hash); // Rely on ASLR heap - hash = hash_djb2_one_32( - (uint32_t)((uint64_t)&hash), hash); // Rely on ASLR stack - - hash = hash & 0x7FFFFFFF; // Make it compatible with unsigned, since negative ID is used for exclusion - } - - return hash; -} - int ENetMultiplayerPeer::get_unique_id() const { ERR_FAIL_COND_V_MSG(!active, 0, "The multiplayer instance isn't currently active."); return unique_id; diff --git a/modules/enet/enet_multiplayer_peer.h b/modules/enet/enet_multiplayer_peer.h index 63f2ec5870..db80953414 100644 --- a/modules/enet/enet_multiplayer_peer.h +++ b/modules/enet/enet_multiplayer_peer.h @@ -96,7 +96,6 @@ private: Packet current_packet; - uint32_t _gen_unique_id() const; void _pop_current_packet(); Vector<uint8_t> src_compressor_mem; |