summaryrefslogtreecommitdiff
path: root/modules/enet
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2017-01-22 06:00:59 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2017-03-24 02:30:05 +0100
commit38d457170a15fd9eb902cecc8c5dc401646cd0b8 (patch)
treee43ccf541b01664b49ed24572e289139f00fdb74 /modules/enet
parent5bdbc0f762bf3a7cc38ebda0757de234c45b5f65 (diff)
Update ENet module to support custom ENet lib
Keep compatibility with upstream enet libraries
Diffstat (limited to 'modules/enet')
-rw-r--r--modules/enet/SCsub4
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp34
-rw-r--r--modules/enet/networked_multiplayer_enet.h2
3 files changed, 31 insertions, 9 deletions
diff --git a/modules/enet/SCsub b/modules/enet/SCsub
index fb22d1cff0..42a933a66d 100644
--- a/modules/enet/SCsub
+++ b/modules/enet/SCsub
@@ -10,6 +10,7 @@ env_enet = env_modules.Clone()
if (env['builtin_enet'] != 'no'):
thirdparty_dir = "#thirdparty/enet/"
thirdparty_sources = [
+ "godot.cpp",
"callbacks.c",
"compress.c",
"host.c",
@@ -17,12 +18,11 @@ if (env['builtin_enet'] != 'no'):
"packet.c",
"peer.c",
"protocol.c",
- "unix.c",
- "win32.c",
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env_enet.add_source_files(env.modules_sources, thirdparty_sources)
env_enet.Append(CPPPATH=[thirdparty_dir])
+ env_enet.Append(CPPFLAGS=["-DGODOT_ENET"])
env_enet.add_source_files(env.modules_sources, "*.cpp")
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index 2dfb0b4a6a..9e6a171d7f 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -53,8 +53,21 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int
ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE);
ENetAddress address;
- address.host = bind_ip;
+#ifdef GODOT_ENET
+ if (bind_ip.is_wildcard()) {
+ address.wildcard = 1;
+ } else {
+ enet_address_set_ip(&address, bind_ip.get_ipv6(), 16);
+ }
+#else
+ if (bind_ip.is_wildcard()) {
+ address.host = 0;
+ } else {
+ ERR_FAIL_COND_V(!bind_ip.is_ipv4(), ERR_INVALID_PARAMETER);
+ address.host = *(uint32_t *)bind_ip.get_ipv4();
+ }
+#endif
address.port = p_port;
host = enet_host_create(&address /* the address to bind the server host to */,
@@ -76,7 +89,6 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int
Error NetworkedMultiplayerENet::create_client(const IP_Address &p_ip, int p_port, int p_in_bandwidth, int p_out_bandwidth) {
ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE);
- ERR_FAIL_COND_V(!p_ip.is_ipv4(), ERR_INVALID_PARAMETER);
host = enet_host_create(NULL /* create a client host */,
1 /* only allow 1 outgoing connection */,
@@ -89,7 +101,12 @@ Error NetworkedMultiplayerENet::create_client(const IP_Address &p_ip, int p_port
_setup_compressor();
ENetAddress address;
- address.host = *((uint32_t *)p_ip.get_ipv4());
+#ifdef GODOT_ENET
+ enet_address_set_ip(&address, p_ip.get_ipv6(), 16);
+#else
+ ERR_FAIL_COND_V(!p_ip.is_ipv4(), ERR_INVALID_PARAMETER);
+ address.host = *(uint32_t *)p_ip.get_ipv4();
+#endif
address.port = p_port;
//enet_address_set_host (& address, "localhost");
@@ -147,7 +164,11 @@ void NetworkedMultiplayerENet::poll() {
}
IP_Address ip;
+#ifdef GODOT_ENET
+ ip.set_ipv6((uint8_t *)&(event.peer->address.host));
+#else
ip.set_ipv4((uint8_t *)&(event.peer->address.host));
+#endif
int *new_id = memnew(int);
*new_id = event.data;
@@ -657,7 +678,7 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet() {
enet_compressor.decompress = enet_decompress;
enet_compressor.destroy = enet_compressor_destroy;
- bind_ip = ENET_HOST_ANY;
+ bind_ip = IP_Address("*");
}
NetworkedMultiplayerENet::~NetworkedMultiplayerENet() {
@@ -668,6 +689,7 @@ NetworkedMultiplayerENet::~NetworkedMultiplayerENet() {
// sets IP for ENet to bind when using create_server
// if no IP is set, then ENet bind to ENET_HOST_ANY
void NetworkedMultiplayerENet::set_bind_ip(const IP_Address &p_ip) {
- ERR_FAIL_COND(!p_ip.is_ipv4());
- bind_ip = *(uint32_t *)p_ip.get_ipv4();
+ ERR_FAIL_COND(!p_ip.is_valid() && !p_ip.is_wildcard());
+
+ bind_ip = p_ip;
}
diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h
index 4b632adcc5..deddf4ecc7 100644
--- a/modules/enet/networked_multiplayer_enet.h
+++ b/modules/enet/networked_multiplayer_enet.h
@@ -100,7 +100,7 @@ private:
static void enet_compressor_destroy(void *context);
void _setup_compressor();
- enet_uint32 bind_ip;
+ IP_Address bind_ip;
protected:
static void _bind_methods();