NetPlay: Limit nickname length
Ridiculously long nicknames cause UI silliness, so 30 characters seems like a reasonable limit, as it's the same as the forum.
This commit is contained in:
parent
92812d0b0b
commit
037aa2192f
|
@ -412,6 +412,12 @@ void StringPopBackIf(std::string* s, char c)
|
||||||
s->pop_back();
|
s->pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t StringUTF8CodePointCount(const std::string& str)
|
||||||
|
{
|
||||||
|
return str.size() -
|
||||||
|
std::count_if(str.begin(), str.end(), [](char c) -> bool { return (c & 0xC0) == 0x80; });
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
std::wstring CPToUTF16(u32 code_page, std::string_view input)
|
std::wstring CPToUTF16(u32 code_page, std::string_view input)
|
||||||
|
|
|
@ -167,6 +167,7 @@ void BuildCompleteFilename(std::string& complete_filename, std::string_view path
|
||||||
bool StringBeginsWith(std::string_view str, std::string_view begin);
|
bool StringBeginsWith(std::string_view str, std::string_view begin);
|
||||||
bool StringEndsWith(std::string_view str, std::string_view end);
|
bool StringEndsWith(std::string_view str, std::string_view end);
|
||||||
void StringPopBackIf(std::string* s, char c);
|
void StringPopBackIf(std::string* s, char c);
|
||||||
|
size_t StringUTF8CodePointCount(const std::string& str);
|
||||||
|
|
||||||
std::string CP1252ToUTF8(std::string_view str);
|
std::string CP1252ToUTF8(std::string_view str);
|
||||||
std::string SHIFTJISToUTF8(std::string_view str);
|
std::string SHIFTJISToUTF8(std::string_view str);
|
||||||
|
|
|
@ -252,6 +252,9 @@ bool NetPlayClient::Connect()
|
||||||
case CON_ERR_GAME_RUNNING:
|
case CON_ERR_GAME_RUNNING:
|
||||||
m_dialog->OnConnectionError(_trans("The game is currently running."));
|
m_dialog->OnConnectionError(_trans("The game is currently running."));
|
||||||
break;
|
break;
|
||||||
|
case CON_ERR_NAME_TOO_LONG:
|
||||||
|
m_dialog->OnConnectionError(_trans("Nickname is too long."));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
m_dialog->OnConnectionError(_trans("The server sent an unknown error message."));
|
m_dialog->OnConnectionError(_trans("The server sent an unknown error message."));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -171,7 +171,8 @@ enum
|
||||||
{
|
{
|
||||||
CON_ERR_SERVER_FULL = 1,
|
CON_ERR_SERVER_FULL = 1,
|
||||||
CON_ERR_GAME_RUNNING = 2,
|
CON_ERR_GAME_RUNNING = 2,
|
||||||
CON_ERR_VERSION_MISMATCH = 3
|
CON_ERR_VERSION_MISMATCH = 3,
|
||||||
|
CON_ERR_NAME_TOO_LONG = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -197,6 +198,7 @@ enum
|
||||||
|
|
||||||
constexpr u32 NETPLAY_LZO_IN_LEN = 1024 * 64;
|
constexpr u32 NETPLAY_LZO_IN_LEN = 1024 * 64;
|
||||||
constexpr u32 NETPLAY_LZO_OUT_LEN = NETPLAY_LZO_IN_LEN + (NETPLAY_LZO_IN_LEN / 16) + 64 + 3;
|
constexpr u32 NETPLAY_LZO_OUT_LEN = NETPLAY_LZO_IN_LEN + (NETPLAY_LZO_IN_LEN / 16) + 64 + 3;
|
||||||
|
constexpr u32 MAX_NAME_LENGTH = 30;
|
||||||
constexpr size_t CHUNKED_DATA_UNIT_SIZE = 16384;
|
constexpr size_t CHUNKED_DATA_UNIT_SIZE = 16384;
|
||||||
constexpr u8 CHANNEL_COUNT = 2;
|
constexpr u8 CHANNEL_COUNT = 2;
|
||||||
constexpr u8 DEFAULT_CHANNEL = 0;
|
constexpr u8 DEFAULT_CHANNEL = 0;
|
||||||
|
|
|
@ -377,9 +377,6 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
|
||||||
if (m_players.size() >= 255)
|
if (m_players.size() >= 255)
|
||||||
return CON_ERR_SERVER_FULL;
|
return CON_ERR_SERVER_FULL;
|
||||||
|
|
||||||
// cause pings to be updated
|
|
||||||
m_update_pings = true;
|
|
||||||
|
|
||||||
Client player;
|
Client player;
|
||||||
player.pid = pid;
|
player.pid = pid;
|
||||||
player.socket = socket;
|
player.socket = socket;
|
||||||
|
@ -387,6 +384,12 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
|
||||||
rpac >> player.revision;
|
rpac >> player.revision;
|
||||||
rpac >> player.name;
|
rpac >> player.name;
|
||||||
|
|
||||||
|
if (StringUTF8CodePointCount(player.name) > MAX_NAME_LENGTH)
|
||||||
|
return CON_ERR_NAME_TOO_LONG;
|
||||||
|
|
||||||
|
// cause pings to be updated
|
||||||
|
m_update_pings = true;
|
||||||
|
|
||||||
// try to automatically assign new user a pad
|
// try to automatically assign new user a pad
|
||||||
for (PlayerId& mapping : m_pad_map)
|
for (PlayerId& mapping : m_pad_map)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
|
|
||||||
#include "Core/Config/NetplaySettings.h"
|
#include "Core/Config/NetplaySettings.h"
|
||||||
|
#include "Core/NetPlayProto.h"
|
||||||
|
|
||||||
#include "DolphinQt/GameList/GameListModel.h"
|
#include "DolphinQt/GameList/GameListModel.h"
|
||||||
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
||||||
|
#include "DolphinQt/QtUtils/UTF8CodePointCountValidator.h"
|
||||||
#include "DolphinQt/Settings.h"
|
#include "DolphinQt/Settings.h"
|
||||||
|
|
||||||
#include "UICommon/NetPlayIndex.h"
|
#include "UICommon/NetPlayIndex.h"
|
||||||
|
@ -87,6 +89,9 @@ void NetPlaySetupDialog::CreateMainLayout()
|
||||||
m_reset_traversal_button = new QPushButton(tr("Reset Traversal Settings"));
|
m_reset_traversal_button = new QPushButton(tr("Reset Traversal Settings"));
|
||||||
m_tab_widget = new QTabWidget;
|
m_tab_widget = new QTabWidget;
|
||||||
|
|
||||||
|
m_nickname_edit->setValidator(
|
||||||
|
new UTF8CodePointCountValidator(NetPlay::MAX_NAME_LENGTH, m_nickname_edit));
|
||||||
|
|
||||||
// Connection widget
|
// Connection widget
|
||||||
auto* connection_widget = new QWidget;
|
auto* connection_widget = new QWidget;
|
||||||
auto* connection_layout = new QGridLayout;
|
auto* connection_layout = new QGridLayout;
|
||||||
|
|
Loading…
Reference in New Issue