DolphinQt / InputCommon - add DSU string validator to avoid crashes, limited backwards compatibility support
This commit is contained in:
parent
58aa0150e1
commit
97c9cf3e21
|
@ -63,6 +63,8 @@ add_executable(dolphin-emu
|
||||||
Config/ControllerInterface/DualShockUDPClientWidget.h
|
Config/ControllerInterface/DualShockUDPClientWidget.h
|
||||||
Config/ControllerInterface/ControllerInterfaceWindow.cpp
|
Config/ControllerInterface/ControllerInterfaceWindow.cpp
|
||||||
Config/ControllerInterface/ControllerInterfaceWindow.h
|
Config/ControllerInterface/ControllerInterfaceWindow.h
|
||||||
|
Config/ControllerInterface/ServerStringValidator.cpp
|
||||||
|
Config/ControllerInterface/ServerStringValidator.h
|
||||||
Config/ControllersWindow.cpp
|
Config/ControllersWindow.cpp
|
||||||
Config/ControllersWindow.h
|
Config/ControllersWindow.h
|
||||||
Config/FilesystemWidget.cpp
|
Config/FilesystemWidget.cpp
|
||||||
|
|
|
@ -14,9 +14,11 @@
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
#include <QString>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "Common/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
|
#include "DolphinQt/Config/ControllerInterface/ServerStringValidator.h"
|
||||||
#include "InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.h"
|
#include "InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.h"
|
||||||
|
|
||||||
DualShockUDPClientAddServerDialog::DualShockUDPClientAddServerDialog(QWidget* parent)
|
DualShockUDPClientAddServerDialog::DualShockUDPClientAddServerDialog(QWidget* parent)
|
||||||
|
@ -35,9 +37,11 @@ void DualShockUDPClientAddServerDialog::CreateWidgets()
|
||||||
|
|
||||||
m_description = new QLineEdit();
|
m_description = new QLineEdit();
|
||||||
m_description->setPlaceholderText(tr("BetterJoy, DS4Windows, etc"));
|
m_description->setPlaceholderText(tr("BetterJoy, DS4Windows, etc"));
|
||||||
|
m_description->setValidator(new ServerStringValidator(m_description));
|
||||||
|
|
||||||
m_server_address =
|
m_server_address =
|
||||||
new QLineEdit(QString::fromStdString(ciface::DualShockUDPClient::DEFAULT_SERVER_ADDRESS));
|
new QLineEdit(QString::fromStdString(ciface::DualShockUDPClient::DEFAULT_SERVER_ADDRESS));
|
||||||
|
m_server_address->setValidator(new ServerStringValidator(m_server_address));
|
||||||
|
|
||||||
m_server_port = new QSpinBox();
|
m_server_port = new QSpinBox();
|
||||||
m_server_port->setMaximum(65535);
|
m_server_port->setMaximum(65535);
|
||||||
|
|
|
@ -75,6 +75,22 @@ void DualShockUDPClientWidget::RefreshServerList()
|
||||||
{
|
{
|
||||||
m_server_list->clear();
|
m_server_list->clear();
|
||||||
|
|
||||||
|
const auto server_address_setting =
|
||||||
|
Config::Get(ciface::DualShockUDPClient::Settings::SERVER_ADDRESS);
|
||||||
|
const auto server_port_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVER_PORT);
|
||||||
|
|
||||||
|
// Update our servers setting if the user is using old configuration
|
||||||
|
if (!server_address_setting.empty() && server_port_setting != 0)
|
||||||
|
{
|
||||||
|
const auto& servers_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVERS);
|
||||||
|
Config::SetBaseOrCurrent(ciface::DualShockUDPClient::Settings::SERVERS,
|
||||||
|
servers_setting + fmt::format("{}:{}:{};", "DS4",
|
||||||
|
server_address_setting,
|
||||||
|
server_port_setting));
|
||||||
|
Config::SetBase(ciface::DualShockUDPClient::Settings::SERVER_ADDRESS, "");
|
||||||
|
Config::SetBase(ciface::DualShockUDPClient::Settings::SERVER_PORT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
const auto& servers_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVERS);
|
const auto& servers_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVERS);
|
||||||
const auto server_details = SplitString(servers_setting, ';');
|
const auto server_details = SplitString(servers_setting, ';');
|
||||||
for (const std::string& server_detail : server_details)
|
for (const std::string& server_detail : server_details)
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright 2020 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2+
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "DolphinQt/Config/ControllerInterface/ServerStringValidator.h"
|
||||||
|
|
||||||
|
ServerStringValidator::ServerStringValidator(QObject* parent) : QValidator(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QValidator::State ServerStringValidator::validate(QString& input, int& pos) const
|
||||||
|
{
|
||||||
|
if (input.isEmpty())
|
||||||
|
return Invalid;
|
||||||
|
|
||||||
|
if (input.contains(QStringLiteral(":")))
|
||||||
|
return Invalid;
|
||||||
|
|
||||||
|
if (input.contains(QStringLiteral(";")))
|
||||||
|
return Invalid;
|
||||||
|
|
||||||
|
return Acceptable;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright 2020 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2+
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QValidator>
|
||||||
|
|
||||||
|
class ServerStringValidator : public QValidator
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ServerStringValidator(QObject* parent);
|
||||||
|
|
||||||
|
State validate(QString& input, int& pos) const override;
|
||||||
|
};
|
|
@ -127,6 +127,7 @@
|
||||||
<QtMoc Include="Config\ControllerInterface\DualShockUDPClientAddServerDialog.h" />
|
<QtMoc Include="Config\ControllerInterface\DualShockUDPClientAddServerDialog.h" />
|
||||||
<QtMoc Include="Config\ControllerInterface\DualShockUDPClientWidget.h" />
|
<QtMoc Include="Config\ControllerInterface\DualShockUDPClientWidget.h" />
|
||||||
<QtMoc Include="Config\ControllerInterface\ControllerInterfaceWindow.h" />
|
<QtMoc Include="Config\ControllerInterface\ControllerInterfaceWindow.h" />
|
||||||
|
<QtMoc Include="Config\ControllerInterface\ServerStringValidator.h" />
|
||||||
<QtMoc Include="Config\InfoWidget.h" />
|
<QtMoc Include="Config\InfoWidget.h" />
|
||||||
<QtMoc Include="Config\PatchesWidget.h" />
|
<QtMoc Include="Config\PatchesWidget.h" />
|
||||||
<QtMoc Include="Config\PropertiesDialog.h" />
|
<QtMoc Include="Config\PropertiesDialog.h" />
|
||||||
|
@ -216,6 +217,7 @@
|
||||||
<ClCompile Include="$(QtMocOutPrefix)DualShockUDPClientAddServerDialog.cpp" />
|
<ClCompile Include="$(QtMocOutPrefix)DualShockUDPClientAddServerDialog.cpp" />
|
||||||
<ClCompile Include="$(QtMocOutPrefix)DualShockUDPClientWidget.cpp" />
|
<ClCompile Include="$(QtMocOutPrefix)DualShockUDPClientWidget.cpp" />
|
||||||
<ClCompile Include="$(QtMocOutPrefix)ControllerInterfaceWindow.cpp" />
|
<ClCompile Include="$(QtMocOutPrefix)ControllerInterfaceWindow.cpp" />
|
||||||
|
<ClCompile Include="$(QtMocOutPrefix)ServerStringValidator.cpp" />
|
||||||
<ClCompile Include="$(QtMocOutPrefix)ControllersWindow.cpp" />
|
<ClCompile Include="$(QtMocOutPrefix)ControllersWindow.cpp" />
|
||||||
<ClCompile Include="$(QtMocOutPrefix)ConvertDialog.cpp" />
|
<ClCompile Include="$(QtMocOutPrefix)ConvertDialog.cpp" />
|
||||||
<ClCompile Include="$(QtMocOutPrefix)DiscordHandler.cpp" />
|
<ClCompile Include="$(QtMocOutPrefix)DiscordHandler.cpp" />
|
||||||
|
@ -330,6 +332,7 @@
|
||||||
<ClCompile Include="Config\ControllerInterface\DualShockUDPClientAddServerDialog.cpp" />
|
<ClCompile Include="Config\ControllerInterface\DualShockUDPClientAddServerDialog.cpp" />
|
||||||
<ClCompile Include="Config\ControllerInterface\DualShockUDPClientWidget.cpp" />
|
<ClCompile Include="Config\ControllerInterface\DualShockUDPClientWidget.cpp" />
|
||||||
<ClCompile Include="Config\ControllerInterface\ControllerInterfaceWindow.cpp" />
|
<ClCompile Include="Config\ControllerInterface\ControllerInterfaceWindow.cpp" />
|
||||||
|
<ClCompile Include="Config\ControllerInterface\ServerStringValidator.cpp" />
|
||||||
<ClCompile Include="Config\ControllersWindow.cpp" />
|
<ClCompile Include="Config\ControllersWindow.cpp" />
|
||||||
<ClCompile Include="Config\FilesystemWidget.cpp" />
|
<ClCompile Include="Config\FilesystemWidget.cpp" />
|
||||||
<ClCompile Include="Config\GameConfigEdit.cpp" />
|
<ClCompile Include="Config\GameConfigEdit.cpp" />
|
||||||
|
|
|
@ -30,6 +30,9 @@ namespace ciface::DualShockUDPClient
|
||||||
{
|
{
|
||||||
namespace Settings
|
namespace Settings
|
||||||
{
|
{
|
||||||
|
const Config::Info<std::string> SERVER_ADDRESS{
|
||||||
|
{Config::System::DualShockUDPClient, "Server", "IPAddress"}, ""};
|
||||||
|
const Config::Info<int> SERVER_PORT{{Config::System::DualShockUDPClient, "Server", "Port"}, 0};
|
||||||
const Config::Info<std::string> SERVERS{{Config::System::DualShockUDPClient, "Server", "Entries"},
|
const Config::Info<std::string> SERVERS{{Config::System::DualShockUDPClient, "Server", "Entries"},
|
||||||
""};
|
""};
|
||||||
const Config::Info<bool> SERVERS_ENABLED{{Config::System::DualShockUDPClient, "Server", "Enabled"},
|
const Config::Info<bool> SERVERS_ENABLED{{Config::System::DualShockUDPClient, "Server", "Enabled"},
|
||||||
|
@ -361,6 +364,21 @@ static void ConfigChanged()
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
|
// The following is added for backwards compatibility
|
||||||
|
const auto server_address_setting = Config::Get(Settings::SERVER_ADDRESS);
|
||||||
|
const auto server_port_setting = Config::Get(Settings::SERVER_PORT);
|
||||||
|
|
||||||
|
if (!server_address_setting.empty() && server_port_setting != 0)
|
||||||
|
{
|
||||||
|
const auto& servers_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVERS);
|
||||||
|
Config::SetBaseOrCurrent(ciface::DualShockUDPClient::Settings::SERVERS,
|
||||||
|
servers_setting + fmt::format("{}:{}:{};", "DS4",
|
||||||
|
server_address_setting,
|
||||||
|
server_port_setting));
|
||||||
|
Config::SetBase(Settings::SERVER_ADDRESS, "");
|
||||||
|
Config::SetBase(Settings::SERVER_PORT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
Config::AddConfigChangedCallback(ConfigChanged);
|
Config::AddConfigChangedCallback(ConfigChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@ constexpr u16 DEFAULT_SERVER_PORT = 26760;
|
||||||
|
|
||||||
namespace Settings
|
namespace Settings
|
||||||
{
|
{
|
||||||
|
// These two kept for backwards compatibility
|
||||||
|
extern const Config::Info<std::string> SERVER_ADDRESS;
|
||||||
|
extern const Config::Info<int> SERVER_PORT;
|
||||||
|
|
||||||
extern const Config::Info<std::string> SERVERS;
|
extern const Config::Info<std::string> SERVERS;
|
||||||
extern const Config::Info<bool> SERVERS_ENABLED;
|
extern const Config::Info<bool> SERVERS_ENABLED;
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
Loading…
Reference in New Issue