input_common: Fix UDP uuid

This commit is contained in:
german77 2021-10-25 12:53:14 -05:00 committed by Narr the Reg
parent 7348e205d9
commit 1d71d4b874
3 changed files with 16 additions and 2 deletions

View file

@ -4,6 +4,7 @@
#include <random>
#include <boost/asio.hpp>
#include <fmt/format.h>
#include "common/logging/log.h"
#include "common/param_package.h"
@ -279,6 +280,7 @@ void UDPClient::StartCommunication(std::size_t client, const std::string& host,
[this](Response::PortInfo info) { OnPortInfo(info); },
[this, client](Response::PadData data) { OnPadData(data, client); }};
LOG_INFO(Input, "Starting communication with UDP input server on {}:{}", host, port);
clients[client].uuid = GetHostUUID(host);
clients[client].host = host;
clients[client].port = port;
clients[client].active = 0;
@ -293,12 +295,18 @@ void UDPClient::StartCommunication(std::size_t client, const std::string& host,
const PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const {
const std::size_t client = pad_index / PADS_PER_CLIENT;
return {
.guid = Common::UUID{clients[client].host},
.guid = clients[client].uuid,
.port = static_cast<std::size_t>(clients[client].port),
.pad = pad_index,
};
}
const Common::UUID UDPClient::GetHostUUID(const std::string host) const {
const auto ip = boost::asio::ip::address_v4::from_string(host);
const auto hex_host = fmt::format("{:06x}", ip.to_ulong());
return Common::UUID{hex_host};
}
void UDPClient::Reset() {
for (auto& client : clients) {
if (client.thread.joinable()) {