From dbcd40111f9037801627dfdb7b4f1ed9af9eb991 Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Thu, 29 May 2014 18:59:07 -0400 Subject: [PATCH] Add an option to kick players from netplay. --- Source/Core/Core/NetPlayServer.cpp | 12 ++++++++++++ Source/Core/Core/NetPlayServer.h | 2 ++ Source/Core/DolphinWX/NetWindow.cpp | 27 +++++++++++++++++++++++++++ Source/Core/DolphinWX/NetWindow.h | 3 +++ 4 files changed, 44 insertions(+) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index c7145079bf..af28565520 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -583,6 +583,18 @@ void NetPlayServer::SendToClients(sf::Packet& packet, const PlayerId skip_pid) } } +void NetPlayServer::KickPlayer(u8 player) +{ + for (auto& current_player : m_players) + { + if (current_player.second.pid == player) + { + current_player.second.socket.Close(); + return; + } + } +} + #ifdef USE_UPNP #include #include diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index ff81565653..b09df0f5be 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -41,6 +41,8 @@ public: void AdjustPadBufferSize(unsigned int size); + void KickPlayer(u8 player); + bool is_connected; #ifdef USE_UPNP diff --git a/Source/Core/DolphinWX/NetWindow.cpp b/Source/Core/DolphinWX/NetWindow.cpp index daefacb63e..da3947bdd0 100644 --- a/Source/Core/DolphinWX/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetWindow.cpp @@ -355,6 +355,12 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game // player list if (is_hosting) { + m_player_lbox->Bind(wxEVT_LISTBOX, &NetPlayDiag::OnPlayerSelect, this); + m_kick_btn = new wxButton(panel, wxID_ANY, _("Kick Player")); + m_kick_btn->Bind(wxEVT_BUTTON, &NetPlayDiag::OnKick, this); + player_szr->Add(m_kick_btn, 0, wxEXPAND | wxTOP, 5); + m_kick_btn->Disable(); + wxButton* const player_config_btn = new wxButton(panel, wxID_ANY, _("Configure Pads")); player_config_btn->Bind(wxEVT_BUTTON, &NetPlayDiag::OnConfigPads, this); player_szr->Add(player_config_btn, 0, wxEXPAND | wxTOP, 5); @@ -624,6 +630,27 @@ void NetPlayDiag::OnConfigPads(wxCommandEvent&) netplay_server->SetWiimoteMapping(wiimotemapping); } +void NetPlayDiag::OnKick(wxCommandEvent&) +{ + wxString selection = m_player_lbox->GetStringSelection(); + unsigned long player = 0; + selection.Mid(selection.find_last_of("[") + 1, selection.find_last_of("]")).ToULong(&player); + + netplay_server->KickPlayer((u8)player); + + m_player_lbox->SetSelection(wxNOT_FOUND); + wxCommandEvent event; + OnPlayerSelect(event); +} + +void NetPlayDiag::OnPlayerSelect(wxCommandEvent&) +{ + if (m_player_lbox->GetSelection() > 0) + m_kick_btn->Enable(); + else + m_kick_btn->Disable(); +} + bool NetPlayDiag::IsRecording() { return m_record_chkbox->GetValue(); diff --git a/Source/Core/DolphinWX/NetWindow.h b/Source/Core/DolphinWX/NetWindow.h index 8d3e6e58d4..a0ea37e47d 100644 --- a/Source/Core/DolphinWX/NetWindow.h +++ b/Source/Core/DolphinWX/NetWindow.h @@ -90,6 +90,8 @@ private: void OnChangeGame(wxCommandEvent& event); void OnAdjustBuffer(wxCommandEvent& event); void OnConfigPads(wxCommandEvent& event); + void OnKick(wxCommandEvent& event); + void OnPlayerSelect(wxCommandEvent& event); void GetNetSettings(NetSettings &settings); std::string FindGame(); @@ -102,6 +104,7 @@ private: std::string m_selected_game; wxButton* m_game_btn; wxButton* m_start_btn; + wxButton* m_kick_btn; std::vector m_playerids;