summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient
diff options
context:
space:
mode:
authorFilippo Tarpini <filippotarpini@hotmail.it>2021-01-02 19:32:53 +0200
committerFiloppi <filippotarpini@hotmail.it>2021-01-03 21:06:06 +0200
commit1e4a1bee4399f161f43d7b338698ae3343cf2c98 (patch)
tree252aa227fda5e0fd0fbdfd37840cc9b32eaedf79 /Source/Core/InputCommon/ControllerInterface/DualShockUDPClient
parentf06e9c55c802f20ad144d936c597f2d532f6b048 (diff)
Fix DualShockUDP not adding/removing devices correctly
-If adding 2 devices with the same name, they their unique id wouldn't be increased, causing a conflict. -Removing a device wouldn't actually remove it from the internal devices list because the list of devices had already been updated when going through it. -It was possible to remove devices belonging to other sources by adding a device with the same name and then removing it.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/DualShockUDPClient')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp
index 200b904b17..61ac7b1318 100644
--- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp
@@ -28,6 +28,8 @@
namespace ciface::DualShockUDPClient
{
+constexpr std::string_view DUALSHOCKUDP_SOURCE_NAME = "DSUClient";
+
namespace Settings
{
const Config::Info<std::string> SERVER_ADDRESS{
@@ -317,7 +319,7 @@ static void Restart()
}
}
- PopulateDevices(); // remove devices
+ PopulateDevices(); // Only removes devices
if (s_servers_enabled && !s_servers.empty())
StartHotplugThread();
@@ -386,11 +388,14 @@ void PopulateDevices()
{
INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient PopulateDevices");
+ // s_servers has already been updated so we can't use it to know which devices we removed,
+ // also it's good to remove all of them before adding new ones so that their id will be set
+ // correctly if they have the same name
+ g_controller_interface.RemoveDevice(
+ [](const auto* dev) { return dev->GetSource() == DUALSHOCKUDP_SOURCE_NAME; });
+
for (auto& server : s_servers)
{
- g_controller_interface.RemoveDevice(
- [&server](const auto* dev) { return dev->GetName() == server.m_description; });
-
std::lock_guard lock{server.m_port_info_mutex};
for (size_t port_index = 0; port_index < server.m_port_info.size(); port_index++)
{
@@ -478,7 +483,7 @@ std::string Device::GetName() const
std::string Device::GetSource() const
{
- return "DSUClient";
+ return std::string(DUALSHOCKUDP_SOURCE_NAME);
}
void Device::UpdateInput()