diff options
Diffstat (limited to 'src/input_common/drivers')
| -rw-r--r-- | src/input_common/drivers/udp_client.cpp | 10 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.h | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 192ab336b..7cab707da 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <random> | 5 | #include <random> |
| 6 | #include <boost/asio.hpp> | 6 | #include <boost/asio.hpp> |
| 7 | #include <fmt/format.h> | ||
| 7 | 8 | ||
| 8 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 9 | #include "common/param_package.h" | 10 | #include "common/param_package.h" |
| @@ -279,6 +280,7 @@ void UDPClient::StartCommunication(std::size_t client, const std::string& host, | |||
| 279 | [this](Response::PortInfo info) { OnPortInfo(info); }, | 280 | [this](Response::PortInfo info) { OnPortInfo(info); }, |
| 280 | [this, client](Response::PadData data) { OnPadData(data, client); }}; | 281 | [this, client](Response::PadData data) { OnPadData(data, client); }}; |
| 281 | LOG_INFO(Input, "Starting communication with UDP input server on {}:{}", host, port); | 282 | LOG_INFO(Input, "Starting communication with UDP input server on {}:{}", host, port); |
| 283 | clients[client].uuid = GetHostUUID(host); | ||
| 282 | clients[client].host = host; | 284 | clients[client].host = host; |
| 283 | clients[client].port = port; | 285 | clients[client].port = port; |
| 284 | clients[client].active = 0; | 286 | clients[client].active = 0; |
| @@ -293,12 +295,18 @@ void UDPClient::StartCommunication(std::size_t client, const std::string& host, | |||
| 293 | const PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { | 295 | const PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { |
| 294 | const std::size_t client = pad_index / PADS_PER_CLIENT; | 296 | const std::size_t client = pad_index / PADS_PER_CLIENT; |
| 295 | return { | 297 | return { |
| 296 | .guid = Common::UUID{clients[client].host}, | 298 | .guid = clients[client].uuid, |
| 297 | .port = static_cast<std::size_t>(clients[client].port), | 299 | .port = static_cast<std::size_t>(clients[client].port), |
| 298 | .pad = pad_index, | 300 | .pad = pad_index, |
| 299 | }; | 301 | }; |
| 300 | } | 302 | } |
| 301 | 303 | ||
| 304 | const Common::UUID UDPClient::GetHostUUID(const std::string host) const { | ||
| 305 | const auto ip = boost::asio::ip::address_v4::from_string(host); | ||
| 306 | const auto hex_host = fmt::format("{:06x}", ip.to_ulong()); | ||
| 307 | return Common::UUID{hex_host}; | ||
| 308 | } | ||
| 309 | |||
| 302 | void UDPClient::Reset() { | 310 | void UDPClient::Reset() { |
| 303 | for (auto& client : clients) { | 311 | for (auto& client : clients) { |
| 304 | if (client.thread.joinable()) { | 312 | if (client.thread.joinable()) { |
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h index 639325b17..1f02adba5 100644 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h | |||
| @@ -69,6 +69,7 @@ private: | |||
| 69 | struct ClientConnection { | 69 | struct ClientConnection { |
| 70 | ClientConnection(); | 70 | ClientConnection(); |
| 71 | ~ClientConnection(); | 71 | ~ClientConnection(); |
| 72 | Common::UUID uuid{"7F000001"}; | ||
| 72 | std::string host{"127.0.0.1"}; | 73 | std::string host{"127.0.0.1"}; |
| 73 | u16 port{26760}; | 74 | u16 port{26760}; |
| 74 | s8 active{-1}; | 75 | s8 active{-1}; |
| @@ -87,6 +88,7 @@ private: | |||
| 87 | void OnPadData(Response::PadData, std::size_t client); | 88 | void OnPadData(Response::PadData, std::size_t client); |
| 88 | void StartCommunication(std::size_t client, const std::string& host, u16 port); | 89 | void StartCommunication(std::size_t client, const std::string& host, u16 port); |
| 89 | const PadIdentifier GetPadIdentifier(std::size_t pad_index) const; | 90 | const PadIdentifier GetPadIdentifier(std::size_t pad_index) const; |
| 91 | const Common::UUID GetHostUUID(const std::string host) const; | ||
| 90 | 92 | ||
| 91 | // Allocate clients for 8 udp servers | 93 | // Allocate clients for 8 udp servers |
| 92 | static constexpr std::size_t MAX_UDP_CLIENTS = 8; | 94 | static constexpr std::size_t MAX_UDP_CLIENTS = 8; |