[Net] MultiplayerPeer cleanup, defaults.
This commit is contained in:
parent
7c81ce43ec
commit
25226329be
@ -53,6 +53,30 @@ uint32_t MultiplayerPeer::generate_unique_id() const {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MultiplayerPeer::set_transfer_channel(int p_channel) {
|
||||||
|
transfer_channel = p_channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MultiplayerPeer::get_transfer_channel() const {
|
||||||
|
return transfer_channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) {
|
||||||
|
transfer_mode = p_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Multiplayer::TransferMode MultiplayerPeer::get_transfer_mode() const {
|
||||||
|
return transfer_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiplayerPeer::set_refuse_new_connections(bool p_enable) {
|
||||||
|
refuse_connections = p_enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MultiplayerPeer::is_refusing_new_connections() const {
|
||||||
|
return refuse_connections;
|
||||||
|
}
|
||||||
|
|
||||||
void MultiplayerPeer::_bind_methods() {
|
void MultiplayerPeer::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_transfer_channel", "channel"), &MultiplayerPeer::set_transfer_channel);
|
ClassDB::bind_method(D_METHOD("set_transfer_channel", "channel"), &MultiplayerPeer::set_transfer_channel);
|
||||||
ClassDB::bind_method(D_METHOD("get_transfer_channel"), &MultiplayerPeer::get_transfer_channel);
|
ClassDB::bind_method(D_METHOD("get_transfer_channel"), &MultiplayerPeer::get_transfer_channel);
|
||||||
@ -131,7 +155,7 @@ void MultiplayerPeerExtension::set_transfer_channel(int p_channel) {
|
|||||||
if (GDVIRTUAL_CALL(_set_transfer_channel, p_channel)) {
|
if (GDVIRTUAL_CALL(_set_transfer_channel, p_channel)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WARN_PRINT_ONCE("MultiplayerPeerExtension::_set_transfer_channel is unimplemented!");
|
MultiplayerPeer::set_transfer_channel(p_channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MultiplayerPeerExtension::get_transfer_channel() const {
|
int MultiplayerPeerExtension::get_transfer_channel() const {
|
||||||
@ -139,15 +163,14 @@ int MultiplayerPeerExtension::get_transfer_channel() const {
|
|||||||
if (GDVIRTUAL_CALL(_get_transfer_channel, channel)) {
|
if (GDVIRTUAL_CALL(_get_transfer_channel, channel)) {
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
WARN_PRINT_ONCE("MultiplayerPeerExtension::_get_transfer_channel is unimplemented!");
|
return MultiplayerPeer::get_transfer_channel();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerPeerExtension::set_transfer_mode(Multiplayer::TransferMode p_mode) {
|
void MultiplayerPeerExtension::set_transfer_mode(Multiplayer::TransferMode p_mode) {
|
||||||
if (GDVIRTUAL_CALL(_set_transfer_mode, p_mode)) {
|
if (GDVIRTUAL_CALL(_set_transfer_mode, p_mode)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WARN_PRINT_ONCE("MultiplayerPeerExtension::_set_transfer_mode is unimplemented!");
|
MultiplayerPeer::set_transfer_mode(p_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
Multiplayer::TransferMode MultiplayerPeerExtension::get_transfer_mode() const {
|
Multiplayer::TransferMode MultiplayerPeerExtension::get_transfer_mode() const {
|
||||||
@ -155,8 +178,7 @@ Multiplayer::TransferMode MultiplayerPeerExtension::get_transfer_mode() const {
|
|||||||
if (GDVIRTUAL_CALL(_get_transfer_mode, mode)) {
|
if (GDVIRTUAL_CALL(_get_transfer_mode, mode)) {
|
||||||
return (Multiplayer::TransferMode)mode;
|
return (Multiplayer::TransferMode)mode;
|
||||||
}
|
}
|
||||||
WARN_PRINT_ONCE("MultiplayerPeerExtension::_get_transfer_mode is unimplemented!");
|
return MultiplayerPeer::get_transfer_mode();
|
||||||
return Multiplayer::TRANSFER_MODE_UNRELIABLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerPeerExtension::set_target_peer(int p_peer_id) {
|
void MultiplayerPeerExtension::set_target_peer(int p_peer_id) {
|
||||||
@ -205,7 +227,7 @@ void MultiplayerPeerExtension::set_refuse_new_connections(bool p_enable) {
|
|||||||
if (GDVIRTUAL_CALL(_set_refuse_new_connections, p_enable)) {
|
if (GDVIRTUAL_CALL(_set_refuse_new_connections, p_enable)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WARN_PRINT_ONCE("MultiplayerPeerExtension::_set_refuse_new_connections is unimplemented!");
|
MultiplayerPeer::set_refuse_new_connections(p_enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MultiplayerPeerExtension::is_refusing_new_connections() const {
|
bool MultiplayerPeerExtension::is_refusing_new_connections() const {
|
||||||
@ -213,8 +235,7 @@ bool MultiplayerPeerExtension::is_refusing_new_connections() const {
|
|||||||
if (GDVIRTUAL_CALL(_is_refusing_new_connections, refusing)) {
|
if (GDVIRTUAL_CALL(_is_refusing_new_connections, refusing)) {
|
||||||
return refusing;
|
return refusing;
|
||||||
}
|
}
|
||||||
WARN_PRINT_ONCE("MultiplayerPeerExtension::_is_refusing_new_connections is unimplemented!");
|
return MultiplayerPeer::is_refusing_new_connections();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiplayerPeer::ConnectionStatus MultiplayerPeerExtension::get_connection_status() const {
|
MultiplayerPeer::ConnectionStatus MultiplayerPeerExtension::get_connection_status() const {
|
||||||
|
@ -44,6 +44,11 @@ class MultiplayerPeer : public PacketPeer {
|
|||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int transfer_channel = 0;
|
||||||
|
Multiplayer::TransferMode transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE;
|
||||||
|
bool refuse_connections = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum {
|
enum {
|
||||||
TARGET_PEER_BROADCAST = 0,
|
TARGET_PEER_BROADCAST = 0,
|
||||||
@ -56,10 +61,13 @@ public:
|
|||||||
CONNECTION_CONNECTED,
|
CONNECTION_CONNECTED,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void set_transfer_channel(int p_channel) = 0;
|
virtual void set_transfer_channel(int p_channel);
|
||||||
virtual int get_transfer_channel() const = 0;
|
virtual int get_transfer_channel() const;
|
||||||
virtual void set_transfer_mode(Multiplayer::TransferMode p_mode) = 0;
|
virtual void set_transfer_mode(Multiplayer::TransferMode p_mode);
|
||||||
virtual Multiplayer::TransferMode get_transfer_mode() const = 0;
|
virtual Multiplayer::TransferMode get_transfer_mode() const;
|
||||||
|
virtual void set_refuse_new_connections(bool p_enable);
|
||||||
|
virtual bool is_refusing_new_connections() const;
|
||||||
|
|
||||||
virtual void set_target_peer(int p_peer_id) = 0;
|
virtual void set_target_peer(int p_peer_id) = 0;
|
||||||
|
|
||||||
virtual int get_packet_peer() const = 0;
|
virtual int get_packet_peer() const = 0;
|
||||||
@ -70,9 +78,6 @@ public:
|
|||||||
|
|
||||||
virtual int get_unique_id() const = 0;
|
virtual int get_unique_id() const = 0;
|
||||||
|
|
||||||
virtual void set_refuse_new_connections(bool p_enable) = 0;
|
|
||||||
virtual bool is_refusing_new_connections() const = 0;
|
|
||||||
|
|
||||||
virtual ConnectionStatus get_connection_status() const = 0;
|
virtual ConnectionStatus get_connection_status() const = 0;
|
||||||
|
|
||||||
uint32_t generate_unique_id() const;
|
uint32_t generate_unique_id() const;
|
||||||
|
@ -33,22 +33,6 @@
|
|||||||
#include "core/io/marshalls.h"
|
#include "core/io/marshalls.h"
|
||||||
#include "core/os/os.h"
|
#include "core/os/os.h"
|
||||||
|
|
||||||
void ENetMultiplayerPeer::set_transfer_channel(int p_channel) {
|
|
||||||
transfer_channel = p_channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ENetMultiplayerPeer::get_transfer_channel() const {
|
|
||||||
return transfer_channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ENetMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) {
|
|
||||||
transfer_mode = p_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
Multiplayer::TransferMode ENetMultiplayerPeer::get_transfer_mode() const {
|
|
||||||
return transfer_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ENetMultiplayerPeer::set_target_peer(int p_peer) {
|
void ENetMultiplayerPeer::set_target_peer(int p_peer) {
|
||||||
target_peer = p_peer;
|
target_peer = p_peer;
|
||||||
}
|
}
|
||||||
@ -62,6 +46,7 @@ int ENetMultiplayerPeer::get_packet_peer() const {
|
|||||||
|
|
||||||
Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) {
|
Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) {
|
||||||
ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
|
ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
|
||||||
|
set_refuse_new_connections(false);
|
||||||
Ref<ENetConnection> host;
|
Ref<ENetConnection> host;
|
||||||
host.instantiate();
|
host.instantiate();
|
||||||
Error err = host->create_host_bound(bind_ip, p_port, p_max_clients, 0, p_max_channels > 0 ? p_max_channels + SYSCH_MAX : 0, p_out_bandwidth);
|
Error err = host->create_host_bound(bind_ip, p_port, p_max_clients, 0, p_max_channels > 0 ? p_max_channels + SYSCH_MAX : 0, p_out_bandwidth);
|
||||||
@ -70,7 +55,6 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
active_mode = MODE_SERVER;
|
active_mode = MODE_SERVER;
|
||||||
refuse_connections = false;
|
|
||||||
unique_id = 1;
|
unique_id = 1;
|
||||||
connection_status = CONNECTION_CONNECTED;
|
connection_status = CONNECTION_CONNECTED;
|
||||||
hosts[0] = host;
|
hosts[0] = host;
|
||||||
@ -79,6 +63,7 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma
|
|||||||
|
|
||||||
Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_channel_count, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) {
|
Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_channel_count, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) {
|
||||||
ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
|
ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
|
||||||
|
set_refuse_new_connections(false);
|
||||||
Ref<ENetConnection> host;
|
Ref<ENetConnection> host;
|
||||||
host.instantiate();
|
host.instantiate();
|
||||||
Error err;
|
Error err;
|
||||||
@ -102,7 +87,6 @@ Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, in
|
|||||||
// Need to wait for CONNECT event.
|
// Need to wait for CONNECT event.
|
||||||
connection_status = CONNECTION_CONNECTING;
|
connection_status = CONNECTION_CONNECTING;
|
||||||
active_mode = MODE_CLIENT;
|
active_mode = MODE_CLIENT;
|
||||||
refuse_connections = false;
|
|
||||||
peers[1] = peer;
|
peers[1] = peer;
|
||||||
hosts[0] = host;
|
hosts[0] = host;
|
||||||
|
|
||||||
@ -113,7 +97,6 @@ Error ENetMultiplayerPeer::create_mesh(int p_id) {
|
|||||||
ERR_FAIL_COND_V_MSG(p_id <= 0, ERR_INVALID_PARAMETER, "The unique ID must be greater then 0");
|
ERR_FAIL_COND_V_MSG(p_id <= 0, ERR_INVALID_PARAMETER, "The unique ID must be greater then 0");
|
||||||
ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
|
ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
|
||||||
active_mode = MODE_MESH;
|
active_mode = MODE_MESH;
|
||||||
refuse_connections = false;
|
|
||||||
unique_id = p_id;
|
unique_id = p_id;
|
||||||
connection_status = CONNECTION_CONNECTED;
|
connection_status = CONNECTION_CONNECTED;
|
||||||
return OK;
|
return OK;
|
||||||
@ -145,7 +128,7 @@ bool ENetMultiplayerPeer::_poll_server() {
|
|||||||
}
|
}
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case ENetConnection::EVENT_CONNECT: {
|
case ENetConnection::EVENT_CONNECT: {
|
||||||
if (refuse_connections) {
|
if (is_refusing_new_connections()) {
|
||||||
event.peer->reset();
|
event.peer->reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -423,6 +406,7 @@ void ENetMultiplayerPeer::close_connection(uint32_t wait_usec) {
|
|||||||
hosts.clear();
|
hosts.clear();
|
||||||
unique_id = 0;
|
unique_id = 0;
|
||||||
connection_status = CONNECTION_DISCONNECTED;
|
connection_status = CONNECTION_DISCONNECTED;
|
||||||
|
set_refuse_new_connections(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ENetMultiplayerPeer::get_available_packet_count() const {
|
int ENetMultiplayerPeer::get_available_packet_count() const {
|
||||||
@ -451,10 +435,11 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size
|
|||||||
|
|
||||||
int packet_flags = 0;
|
int packet_flags = 0;
|
||||||
int channel = SYSCH_RELIABLE;
|
int channel = SYSCH_RELIABLE;
|
||||||
|
int transfer_channel = get_transfer_channel();
|
||||||
if (transfer_channel > 0) {
|
if (transfer_channel > 0) {
|
||||||
channel = SYSCH_MAX + transfer_channel - 1;
|
channel = SYSCH_MAX + transfer_channel - 1;
|
||||||
} else {
|
} else {
|
||||||
switch (transfer_mode) {
|
switch (get_transfer_mode()) {
|
||||||
case Multiplayer::TRANSFER_MODE_UNRELIABLE: {
|
case Multiplayer::TRANSFER_MODE_UNRELIABLE: {
|
||||||
packet_flags = ENET_PACKET_FLAG_UNSEQUENCED;
|
packet_flags = ENET_PACKET_FLAG_UNSEQUENCED;
|
||||||
channel = SYSCH_UNRELIABLE;
|
channel = SYSCH_UNRELIABLE;
|
||||||
@ -545,19 +530,15 @@ int ENetMultiplayerPeer::get_unique_id() const {
|
|||||||
return unique_id;
|
return unique_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enable) {
|
void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enabled) {
|
||||||
refuse_connections = p_enable;
|
|
||||||
#ifdef GODOT_ENET
|
#ifdef GODOT_ENET
|
||||||
if (_is_active()) {
|
if (_is_active()) {
|
||||||
for (KeyValue<int, Ref<ENetConnection>> &E : hosts) {
|
for (KeyValue<int, Ref<ENetConnection>> &E : hosts) {
|
||||||
E.value->refuse_new_connections(p_enable);
|
E.value->refuse_new_connections(p_enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
MultiplayerPeer::set_refuse_new_connections(p_enabled);
|
||||||
|
|
||||||
bool ENetMultiplayerPeer::is_refusing_new_connections() const {
|
|
||||||
return refuse_connections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) {
|
void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) {
|
||||||
|
@ -65,10 +65,7 @@ private:
|
|||||||
uint32_t unique_id = 0;
|
uint32_t unique_id = 0;
|
||||||
|
|
||||||
int target_peer = 0;
|
int target_peer = 0;
|
||||||
int transfer_channel = 0;
|
|
||||||
Multiplayer::TransferMode transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE;
|
|
||||||
|
|
||||||
bool refuse_connections = false;
|
|
||||||
bool server_relay = true;
|
bool server_relay = true;
|
||||||
|
|
||||||
ConnectionStatus connection_status = CONNECTION_DISCONNECTED;
|
ConnectionStatus connection_status = CONNECTION_DISCONNECTED;
|
||||||
@ -101,15 +98,23 @@ protected:
|
|||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void set_transfer_channel(int p_channel) override;
|
|
||||||
virtual int get_transfer_channel() const override;
|
|
||||||
|
|
||||||
virtual void set_transfer_mode(Multiplayer::TransferMode p_mode) override;
|
|
||||||
virtual Multiplayer::TransferMode get_transfer_mode() const override;
|
|
||||||
virtual void set_target_peer(int p_peer) override;
|
virtual void set_target_peer(int p_peer) override;
|
||||||
|
|
||||||
virtual int get_packet_peer() const override;
|
virtual int get_packet_peer() const override;
|
||||||
|
|
||||||
|
virtual void poll() override;
|
||||||
|
virtual bool is_server() const override;
|
||||||
|
// Overriden so we can instrument the DTLSServer when needed.
|
||||||
|
virtual void set_refuse_new_connections(bool p_enabled) override;
|
||||||
|
|
||||||
|
virtual ConnectionStatus get_connection_status() const override;
|
||||||
|
|
||||||
|
virtual int get_unique_id() const override;
|
||||||
|
|
||||||
|
virtual int get_max_packet_size() const override;
|
||||||
|
virtual int get_available_packet_count() const override;
|
||||||
|
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override;
|
||||||
|
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override;
|
||||||
|
|
||||||
Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0);
|
Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0);
|
||||||
Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0);
|
Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0);
|
||||||
Error create_mesh(int p_id);
|
Error create_mesh(int p_id);
|
||||||
@ -119,23 +124,6 @@ public:
|
|||||||
|
|
||||||
void disconnect_peer(int p_peer, bool now = false);
|
void disconnect_peer(int p_peer, bool now = false);
|
||||||
|
|
||||||
virtual void poll() override;
|
|
||||||
|
|
||||||
virtual bool is_server() const override;
|
|
||||||
|
|
||||||
virtual int get_available_packet_count() const override;
|
|
||||||
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet
|
|
||||||
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override;
|
|
||||||
|
|
||||||
virtual int get_max_packet_size() const override;
|
|
||||||
|
|
||||||
virtual ConnectionStatus get_connection_status() const override;
|
|
||||||
|
|
||||||
virtual void set_refuse_new_connections(bool p_enable) override;
|
|
||||||
virtual bool is_refusing_new_connections() const override;
|
|
||||||
|
|
||||||
virtual int get_unique_id() const override;
|
|
||||||
|
|
||||||
void set_bind_ip(const IPAddress &p_ip);
|
void set_bind_ip(const IPAddress &p_ip);
|
||||||
void set_server_relay_enabled(bool p_enabled);
|
void set_server_relay_enabled(bool p_enabled);
|
||||||
bool is_server_relay_enabled() const;
|
bool is_server_relay_enabled() const;
|
||||||
|
@ -43,22 +43,6 @@ void WebRTCMultiplayerPeer::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayerPeer::close);
|
ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayerPeer::close);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRTCMultiplayerPeer::set_transfer_channel(int p_channel) {
|
|
||||||
transfer_channel = p_channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebRTCMultiplayerPeer::get_transfer_channel() const {
|
|
||||||
return transfer_channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebRTCMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) {
|
|
||||||
transfer_mode = p_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
Multiplayer::TransferMode WebRTCMultiplayerPeer::get_transfer_mode() const {
|
|
||||||
return transfer_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebRTCMultiplayerPeer::set_target_peer(int p_peer_id) {
|
void WebRTCMultiplayerPeer::set_target_peer(int p_peer_id) {
|
||||||
target_peer = p_peer_id;
|
target_peer = p_peer_id;
|
||||||
}
|
}
|
||||||
@ -188,14 +172,6 @@ void WebRTCMultiplayerPeer::_find_next_peer() {
|
|||||||
next_packet_peer = 0;
|
next_packet_peer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRTCMultiplayerPeer::set_refuse_new_connections(bool p_enable) {
|
|
||||||
refuse_connections = p_enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WebRTCMultiplayerPeer::is_refusing_new_connections() const {
|
|
||||||
return refuse_connections;
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiplayerPeer::ConnectionStatus WebRTCMultiplayerPeer::get_connection_status() const {
|
MultiplayerPeer::ConnectionStatus WebRTCMultiplayerPeer::get_connection_status() const {
|
||||||
return connection_status;
|
return connection_status;
|
||||||
}
|
}
|
||||||
@ -279,7 +255,7 @@ Dictionary WebRTCMultiplayerPeer::get_peers() {
|
|||||||
Error WebRTCMultiplayerPeer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime) {
|
Error WebRTCMultiplayerPeer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime) {
|
||||||
ERR_FAIL_COND_V(p_peer_id < 0 || p_peer_id > ~(1 << 31), ERR_INVALID_PARAMETER);
|
ERR_FAIL_COND_V(p_peer_id < 0 || p_peer_id > ~(1 << 31), ERR_INVALID_PARAMETER);
|
||||||
ERR_FAIL_COND_V(p_unreliable_lifetime < 0, ERR_INVALID_PARAMETER);
|
ERR_FAIL_COND_V(p_unreliable_lifetime < 0, ERR_INVALID_PARAMETER);
|
||||||
ERR_FAIL_COND_V(refuse_connections, ERR_UNAUTHORIZED);
|
ERR_FAIL_COND_V(is_refusing_new_connections(), ERR_UNAUTHORIZED);
|
||||||
// Peer must be valid, and in new state (to create data channels)
|
// Peer must be valid, and in new state (to create data channels)
|
||||||
ERR_FAIL_COND_V(!p_peer.is_valid(), ERR_INVALID_PARAMETER);
|
ERR_FAIL_COND_V(!p_peer.is_valid(), ERR_INVALID_PARAMETER);
|
||||||
ERR_FAIL_COND_V(p_peer->get_connection_state() != WebRTCPeerConnection::STATE_NEW, ERR_INVALID_PARAMETER);
|
ERR_FAIL_COND_V(p_peer->get_connection_state() != WebRTCPeerConnection::STATE_NEW, ERR_INVALID_PARAMETER);
|
||||||
@ -352,9 +328,9 @@ Error WebRTCMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_
|
|||||||
Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
|
Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
|
||||||
ERR_FAIL_COND_V(connection_status == CONNECTION_DISCONNECTED, ERR_UNCONFIGURED);
|
ERR_FAIL_COND_V(connection_status == CONNECTION_DISCONNECTED, ERR_UNCONFIGURED);
|
||||||
|
|
||||||
int ch = transfer_channel;
|
int ch = get_transfer_channel();
|
||||||
if (ch == 0) {
|
if (ch == 0) {
|
||||||
switch (transfer_mode) {
|
switch (get_transfer_mode()) {
|
||||||
case Multiplayer::TRANSFER_MODE_RELIABLE:
|
case Multiplayer::TRANSFER_MODE_RELIABLE:
|
||||||
ch = CH_RELIABLE;
|
ch = CH_RELIABLE;
|
||||||
break;
|
break;
|
||||||
|
@ -65,10 +65,7 @@ private:
|
|||||||
uint32_t unique_id = 0;
|
uint32_t unique_id = 0;
|
||||||
int target_peer = 0;
|
int target_peer = 0;
|
||||||
int client_count = 0;
|
int client_count = 0;
|
||||||
bool refuse_connections = false;
|
|
||||||
ConnectionStatus connection_status = CONNECTION_DISCONNECTED;
|
ConnectionStatus connection_status = CONNECTION_DISCONNECTED;
|
||||||
int transfer_channel = 0;
|
|
||||||
Multiplayer::TransferMode transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE;
|
|
||||||
int next_packet_peer = 0;
|
int next_packet_peer = 0;
|
||||||
bool server_compat = false;
|
bool server_compat = false;
|
||||||
|
|
||||||
@ -97,10 +94,6 @@ public:
|
|||||||
int get_max_packet_size() const override;
|
int get_max_packet_size() const override;
|
||||||
|
|
||||||
// MultiplayerPeer
|
// MultiplayerPeer
|
||||||
void set_transfer_channel(int p_channel) override;
|
|
||||||
int get_transfer_channel() const override;
|
|
||||||
void set_transfer_mode(Multiplayer::TransferMode p_mode) override;
|
|
||||||
Multiplayer::TransferMode get_transfer_mode() const override;
|
|
||||||
void set_target_peer(int p_peer_id) override;
|
void set_target_peer(int p_peer_id) override;
|
||||||
|
|
||||||
int get_unique_id() const override;
|
int get_unique_id() const override;
|
||||||
@ -110,9 +103,6 @@ public:
|
|||||||
|
|
||||||
void poll() override;
|
void poll() override;
|
||||||
|
|
||||||
void set_refuse_new_connections(bool p_enable) override;
|
|
||||||
bool is_refusing_new_connections() const override;
|
|
||||||
|
|
||||||
ConnectionStatus get_connection_status() const override;
|
ConnectionStatus get_connection_status() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -105,23 +105,6 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer
|
|||||||
//
|
//
|
||||||
// MultiplayerPeer
|
// MultiplayerPeer
|
||||||
//
|
//
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
Multiplayer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const {
|
|
||||||
// Websocket uses TCP, reliable
|
|
||||||
return Multiplayer::TRANSFER_MODE_RELIABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) {
|
void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) {
|
||||||
_target_peer = p_target_peer;
|
_target_peer = p_target_peer;
|
||||||
}
|
}
|
||||||
@ -137,14 +120,6 @@ int WebSocketMultiplayerPeer::get_unique_id() const {
|
|||||||
return _peer_id;
|
return _peer_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketMultiplayerPeer::set_refuse_new_connections(bool p_enable) {
|
|
||||||
_refusing = p_enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WebSocketMultiplayerPeer::is_refusing_new_connections() const {
|
|
||||||
return _refusing;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_type, int32_t p_peer_id) {
|
void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_type, int32_t p_peer_id) {
|
||||||
ERR_FAIL_COND(!p_peer.is_valid());
|
ERR_FAIL_COND(!p_peer.is_valid());
|
||||||
ERR_FAIL_COND(!p_peer->is_connected_to_host());
|
ERR_FAIL_COND(!p_peer->is_connected_to_host());
|
||||||
|
@ -68,7 +68,6 @@ protected:
|
|||||||
bool _is_multiplayer = false;
|
bool _is_multiplayer = false;
|
||||||
int _target_peer = 0;
|
int _target_peer = 0;
|
||||||
int _peer_id = 0;
|
int _peer_id = 0;
|
||||||
int _refusing = false;
|
|
||||||
|
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
@ -78,15 +77,9 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/* MultiplayerPeer */
|
/* MultiplayerPeer */
|
||||||
void set_transfer_channel(int p_channel) override;
|
|
||||||
int get_transfer_channel() const override;
|
|
||||||
void set_transfer_mode(Multiplayer::TransferMode p_mode) override;
|
|
||||||
Multiplayer::TransferMode get_transfer_mode() const override;
|
|
||||||
void set_target_peer(int p_target_peer) override;
|
void set_target_peer(int p_target_peer) override;
|
||||||
int get_packet_peer() const override;
|
int get_packet_peer() const override;
|
||||||
int get_unique_id() const override;
|
int get_unique_id() const override;
|
||||||
void set_refuse_new_connections(bool p_enable) override;
|
|
||||||
bool is_refusing_new_connections() const override;
|
|
||||||
|
|
||||||
/* PacketPeer */
|
/* PacketPeer */
|
||||||
virtual int get_available_packet_count() const override;
|
virtual int get_available_packet_count() const override;
|
||||||
|
Loading…
Reference in New Issue
Block a user