From d1441d803951294386e7ce13a4a74f5eac202ac4 Mon Sep 17 00:00:00 2001 From: Jamie Meyer <45072324+HeatXD@users.noreply.github.com> Date: Wed, 17 May 2023 02:31:03 +0200 Subject: [PATCH 1/3] Neplay: Session password. --- src/core/netplay.cpp | 16 +++++++++++++--- src/core/netplay_packets.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/core/netplay.cpp b/src/core/netplay.cpp index b5953ecad..b1345d892 100644 --- a/src/core/netplay.cpp +++ b/src/core/netplay.cpp @@ -161,6 +161,7 @@ static Common::Timer s_last_host_connection_attempt; /// GGPO static std::string s_local_nickname; +static std::string s_session_password; static GGPOPlayerHandle s_local_handle = GGPO_INVALID_HANDLE; static s32 s_local_delay = 0; static GGPONetworkStats s_last_net_stats{}; @@ -954,6 +955,7 @@ void Netplay::SendConnectRequest() std::memset(pkt->nickname, 0, sizeof(pkt->nickname)); std::memset(pkt->session_password, 0, sizeof(pkt->session_password)); StringUtil::Strlcpy(pkt->nickname, s_local_nickname, std::size(pkt->nickname)); + StringUtil::Strlcpy(pkt->session_password, s_session_password, std::size(pkt->session_password)); SendControlPacket(s_peers[s_host_player_id].peer, pkt); } @@ -1001,6 +1003,14 @@ void Netplay::HandleMessageFromNewPeer(ENetPeer* peer, const ENetPacket* pkt) PacketWrapper response = NewControlPacket(); response->player_id = -1; + // Gatekeep using the session password. + if (msg->GetSessionPassword() != s_session_password) + { + response->result = JoinResponseMessage::Result::InvalidPassword; + SendControlPacket(peer, response); + return; + } + // TODO: Spectators shouldn't get assigned a real player ID, they should go into a separate peer list. if (msg->mode != JoinRequestMessage::Mode::Player) { @@ -1861,7 +1871,7 @@ void Netplay::SetInputs(Netplay::Input inputs[2]) bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std::string password) { - // TODO: Password + s_session_password = password; // TODO: This is going to blow away our memory cards, because for sync purposes we want all clients // to have the same data, and we don't want to trash their local memcards. We should therefore load @@ -1885,8 +1895,8 @@ bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std bool Netplay::JoinSession(std::string nickname, const std::string& hostname, s32 port, std::string password) { - // TODO: Password - + s_session_password = password; + // TODO: input delay. GGPO Should support changing it on the fly. const s32 input_delay = 1; if (!Netplay::Start(false, std::move(nickname), hostname, port, input_delay)) diff --git a/src/core/netplay_packets.h b/src/core/netplay_packets.h index 5d8261687..9dd098658 100644 --- a/src/core/netplay_packets.h +++ b/src/core/netplay_packets.h @@ -161,6 +161,7 @@ struct JoinResponseMessage ServerFull, PlayerIDInUse, SessionClosed, + InvalidPassword, }; ControlMessageHeader header; From 6092011d97712bf72a6eb667c3ed5fef52e03276 Mon Sep 17 00:00:00 2001 From: Jamie Meyer <45072324+HeatXD@users.noreply.github.com> Date: Wed, 17 May 2023 02:46:37 +0200 Subject: [PATCH 2/3] Netplay: Session password - be more descriptive --- src/core/netplay.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/netplay.cpp b/src/core/netplay.cpp index b1345d892..fe5291861 100644 --- a/src/core/netplay.cpp +++ b/src/core/netplay.cpp @@ -161,7 +161,7 @@ static Common::Timer s_last_host_connection_attempt; /// GGPO static std::string s_local_nickname; -static std::string s_session_password; +static std::string s_local_session_password; static GGPOPlayerHandle s_local_handle = GGPO_INVALID_HANDLE; static s32 s_local_delay = 0; static GGPONetworkStats s_last_net_stats{}; @@ -955,7 +955,7 @@ void Netplay::SendConnectRequest() std::memset(pkt->nickname, 0, sizeof(pkt->nickname)); std::memset(pkt->session_password, 0, sizeof(pkt->session_password)); StringUtil::Strlcpy(pkt->nickname, s_local_nickname, std::size(pkt->nickname)); - StringUtil::Strlcpy(pkt->session_password, s_session_password, std::size(pkt->session_password)); + StringUtil::Strlcpy(pkt->session_password, s_local_session_password, std::size(pkt->session_password)); SendControlPacket(s_peers[s_host_player_id].peer, pkt); } @@ -1004,7 +1004,7 @@ void Netplay::HandleMessageFromNewPeer(ENetPeer* peer, const ENetPacket* pkt) response->player_id = -1; // Gatekeep using the session password. - if (msg->GetSessionPassword() != s_session_password) + if (msg->GetSessionPassword() != s_local_session_password) { response->result = JoinResponseMessage::Result::InvalidPassword; SendControlPacket(peer, response); @@ -1871,12 +1871,13 @@ void Netplay::SetInputs(Netplay::Input inputs[2]) bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std::string password) { - s_session_password = password; + s_local_session_password = password; // TODO: This is going to blow away our memory cards, because for sync purposes we want all clients // to have the same data, and we don't want to trash their local memcards. We should therefore load // the memory cards for this game (based on game/global settings), and copy that to the temp card. - + + // TODO: input delay. GGPO Should support changing it on the fly. const s32 input_delay = 1; if (!Netplay::Start(true, std::move(nickname), std::string(), port, input_delay)) @@ -1895,7 +1896,7 @@ bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std bool Netplay::JoinSession(std::string nickname, const std::string& hostname, s32 port, std::string password) { - s_session_password = password; + s_local_session_password = password; // TODO: input delay. GGPO Should support changing it on the fly. const s32 input_delay = 1; From ee813c4a542178b05fcfed78ade4fe1841dcf2e9 Mon Sep 17 00:00:00 2001 From: Jamie Meyer <45072324+HeatXD@users.noreply.github.com> Date: Wed, 17 May 2023 14:44:02 +0200 Subject: [PATCH 3/3] Netplay: Move password string instead of copying. --- src/core/netplay.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/netplay.cpp b/src/core/netplay.cpp index fe5291861..44e1c9ee2 100644 --- a/src/core/netplay.cpp +++ b/src/core/netplay.cpp @@ -1871,7 +1871,7 @@ void Netplay::SetInputs(Netplay::Input inputs[2]) bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std::string password) { - s_local_session_password = password; + s_local_session_password = std::move(password); // TODO: This is going to blow away our memory cards, because for sync purposes we want all clients // to have the same data, and we don't want to trash their local memcards. We should therefore load @@ -1896,7 +1896,8 @@ bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std bool Netplay::JoinSession(std::string nickname, const std::string& hostname, s32 port, std::string password) { - s_local_session_password = password; + s_local_session_password = std::move(password); + // TODO: input delay. GGPO Should support changing it on the fly. const s32 input_delay = 1;