summaryrefslogtreecommitdiff
path: root/modules/websocket/websocket_multiplayer_peer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/websocket/websocket_multiplayer_peer.cpp')
-rw-r--r--modules/websocket/websocket_multiplayer_peer.cpp50
1 files changed, 19 insertions, 31 deletions
diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp
index fa0ef7060f..7464cf2bf5 100644
--- a/modules/websocket/websocket_multiplayer_peer.cpp
+++ b/modules/websocket/websocket_multiplayer_peer.cpp
@@ -39,35 +39,15 @@ WebSocketMultiplayerPeer::~WebSocketMultiplayerPeer() {
_clear();
}
-int WebSocketMultiplayerPeer::_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_data_path().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;
-}
-
void WebSocketMultiplayerPeer::_clear() {
_peer_map.clear();
if (_current_packet.data != nullptr) {
memfree(_current_packet.data);
}
- for (List<Packet>::Element *E = _incoming_packets.front(); E; E = E->next()) {
- memfree(E->get().data);
- E->get().data = nullptr;
+ for (Packet &E : _incoming_packets) {
+ memfree(E.data);
+ E.data = nullptr;
}
_incoming_packets.clear();
@@ -123,15 +103,23 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer
}
//
-// NetworkedMultiplayerPeer
+// MultiplayerPeer
//
-void WebSocketMultiplayerPeer::set_transfer_mode(TransferMode p_mode) {
+void WebSocketMultiplayerPeer::set_transfer_channel(int p_channel) {
+ // Websocket does not have channels.
+}
+
+int WebSocketMultiplayerPeer::get_transfer_channel() const {
+ return 0;
+}
+
+void WebSocketMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) {
// Websocket uses TCP, reliable
}
-NetworkedMultiplayerPeer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const {
+Multiplayer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const {
// Websocket uses TCP, reliable
- return TRANSFER_MODE_RELIABLE;
+ return Multiplayer::TRANSFER_MODE_RELIABLE;
}
void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) {
@@ -215,7 +203,7 @@ void WebSocketMultiplayerPeer::_store_pkt(int32_t p_source, int32_t p_dest, cons
packet.destination = p_dest;
memcpy(packet.data, &p_data[PROTO_SIZE], p_data_size);
_incoming_packets.push_back(packet);
- emit_signal("peer_packet", p_source);
+ emit_signal(SNAME("peer_packet"), p_source);
}
Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, const uint8_t *p_buffer, uint32_t p_buffer_size) {
@@ -306,15 +294,15 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u
switch (type) {
case SYS_ADD: // Add peer
_peer_map[id] = Ref<WebSocketPeer>();
- emit_signal("peer_connected", id);
+ emit_signal(SNAME("peer_connected"), id);
if (id == 1) { // We just connected to the server
- emit_signal("connection_succeeded");
+ emit_signal(SNAME("connection_succeeded"));
}
break;
case SYS_DEL: // Remove peer
_peer_map.erase(id);
- emit_signal("peer_disconnected", id);
+ emit_signal(SNAME("peer_disconnected"), id);
break;
case SYS_ID: // Hello, server assigned ID
_peer_id = id;