summaryrefslogtreecommitdiff
path: root/modules/multiplayer/scene_multiplayer.h
diff options
context:
space:
mode:
Diffstat (limited to 'modules/multiplayer/scene_multiplayer.h')
-rw-r--r--modules/multiplayer/scene_multiplayer.h44
1 files changed, 41 insertions, 3 deletions
diff --git a/modules/multiplayer/scene_multiplayer.h b/modules/multiplayer/scene_multiplayer.h
index a99cca7b21..b0ecc48f8c 100644
--- a/modules/multiplayer/scene_multiplayer.h
+++ b/modules/multiplayer/scene_multiplayer.h
@@ -49,6 +49,18 @@ public:
NETWORK_COMMAND_SPAWN,
NETWORK_COMMAND_DESPAWN,
NETWORK_COMMAND_SYNC,
+ NETWORK_COMMAND_SYS,
+ };
+
+ enum SysCommands {
+ SYS_COMMAND_AUTH,
+ SYS_COMMAND_ADD_PEER,
+ SYS_COMMAND_DEL_PEER,
+ SYS_COMMAND_RELAY,
+ };
+
+ enum {
+ SYS_CMD_SIZE = 6, // Command + sys command + peer_id (+ optional payload).
};
// For each command, the 4 MSB can contain custom flags, as defined by subsystems.
@@ -65,7 +77,17 @@ public:
};
private:
+ struct PendingPeer {
+ bool local = false;
+ bool remote = false;
+ uint64_t time = 0;
+ };
+
Ref<MultiplayerPeer> multiplayer_peer;
+ MultiplayerPeer::ConnectionStatus last_connection_status = MultiplayerPeer::CONNECTION_DISCONNECTED;
+ HashMap<int, PendingPeer> pending_peers; // true if locally finalized.
+ Callable auth_callback;
+ uint64_t auth_timeout = 3000;
HashSet<int> connected_peers;
int remote_sender_id = 0;
int remote_sender_override = 0;
@@ -74,6 +96,8 @@ private:
NodePath root_path;
bool allow_object_decoding = false;
+ bool server_relay = true;
+ Ref<StreamPeerBuffer> relay_buffer;
Ref<SceneCacheInterface> cache;
Ref<SceneReplicationInterface> replicator;
@@ -84,12 +108,12 @@ protected:
void _process_packet(int p_from, const uint8_t *p_packet, int p_packet_len);
void _process_raw(int p_from, const uint8_t *p_packet, int p_packet_len);
+ void _process_sys(int p_from, const uint8_t *p_packet, int p_packet_len, MultiplayerPeer::TransferMode p_mode, int p_channel);
void _add_peer(int p_id);
+ void _admit_peer(int p_id);
void _del_peer(int p_id);
- void _connected_to_server();
- void _connection_failed();
- void _server_disconnected();
+ void _update_status();
public:
virtual void set_multiplayer_peer(const Ref<MultiplayerPeer> &p_peer) override;
@@ -111,6 +135,17 @@ public:
void set_root_path(const NodePath &p_path);
NodePath get_root_path() const;
+ void disconnect_peer(int p_id);
+
+ Error send_auth(int p_to, Vector<uint8_t> p_bytes);
+ Error complete_auth(int p_peer);
+ void set_auth_callback(Callable p_callback);
+ Callable get_auth_callback() const;
+ void set_auth_timeout(double p_timeout);
+ double get_auth_timeout() const;
+ Vector<int> get_authenticating_peer_ids();
+
+ Error send_command(int p_to, const uint8_t *p_packet, int p_packet_len); // Used internally to relay packets when needed.
Error send_bytes(Vector<uint8_t> p_data, int p_to = MultiplayerPeer::TARGET_PEER_BROADCAST, MultiplayerPeer::TransferMode p_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE, int p_channel = 0);
String get_rpc_md5(const Object *p_obj);
@@ -123,6 +158,9 @@ public:
void set_allow_object_decoding(bool p_enable);
bool is_object_decoding_allowed() const;
+ void set_server_relay_enabled(bool p_enabled);
+ bool is_server_relay_enabled() const;
+
Ref<SceneCacheInterface> get_path_cache() { return cache; }
#ifdef DEBUG_ENABLED