Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix `ENetMultiplayerPeer.create_server()` using channel count as incoming bandwidth

Nachiket Suryawanshibc5baf46fc1f
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index ebf9be49e5b..4edb39e408e 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -225,6 +225,7 @@
/modules/enet/**/*.py @godotengine/network @godotengine/buildsystem
/modules/enet/**/SCsub @godotengine/network @godotengine/buildsystem
/modules/enet/doc_classes/ @godotengine/network @godotengine/documentation
+/modules/enet/tests/ @godotengine/network @godotengine/tests
/modules/mbedtls/ @godotengine/network
/modules/mbedtls/**/*.py @godotengine/network @godotengine/buildsystem
/modules/mbedtls/**/SCsub @godotengine/network @godotengine/buildsystem
diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp
index baba00d5f88..2c176b5d913 100644
--- a/modules/enet/enet_multiplayer_peer.cpp
+++ b/modules/enet/enet_multiplayer_peer.cpp
@@ -64,7 +64,7 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma
set_refuse_new_connections(false);
Ref<ENetConnection> host;
host.instantiate();
- RETURN_IF_ERROR(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));
+ RETURN_IF_ERROR(host->create_host_bound(bind_ip, p_port, p_max_clients, p_max_channels > 0 ? p_max_channels + SYSCH_MAX : 0, p_in_bandwidth, p_out_bandwidth));
active_mode = MODE_SERVER;
unique_id = 1;
diff --git a/modules/enet/tests/test_enet_multiplayer_peer.h b/modules/enet/tests/test_enet_multiplayer_peer.h
new file mode 100644
index 00000000000..f70ff0396d8
--- /dev/null
+++ b/modules/enet/tests/test_enet_multiplayer_peer.h
@@ -0,0 +1,61 @@
+/**************************************************************************/
+/* test_enet_multiplayer_peer.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#pragma once
+
+#include "core/object/class_db.h"
+#include "scene/main/multiplayer_peer.h"
+#include "tests/test_macros.h"
+
+namespace TestENetMultiplayerPeer {
+
+// Uses ClassDB so the test doesn't need the ENet headers, which are only on the module's include path.
+TEST_CASE("[ENetMultiplayerPeer] create_server sets the host channel limit") {
+ Ref<MultiplayerPeer> peer = Object::cast_to<MultiplayerPeer>(ClassDB::instantiate("ENetMultiplayerPeer"));
+ REQUIRE(peer.is_valid());
+
+ SUBCASE("Default channels") {
+ REQUIRE_EQ(int(peer->call("create_server", 0, 4)), OK);
+ // 0 means the ENet maximum of 255.
+ Object *host = peer->call("get_host");
+ CHECK_EQ(int(host->call("get_max_channels")), 255);
+ }
+
+ SUBCASE("Custom channels") {
+ REQUIRE_EQ(int(peer->call("create_server", 0, 4, 3)), OK);
+ // 3 user channels plus the 2 reserved system channels.
+ Object *host = peer->call("get_host");
+ CHECK_EQ(int(host->call("get_max_channels")), 5);
+ }
+
+ peer->close();
+}
+
+} // namespace TestENetMultiplayerPeer