Add kicking player for server owner
This commit is contained in:
parent
3bbec8aa27
commit
95208967cf
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "config/player_manager.hpp"
|
#include "config/player_manager.hpp"
|
||||||
#include "karts/kart_properties_manager.hpp"
|
#include "karts/kart_properties_manager.hpp"
|
||||||
|
#include "guiengine/modaldialog.hpp"
|
||||||
#include "guiengine/message_queue.hpp"
|
#include "guiengine/message_queue.hpp"
|
||||||
#include "modes/world_with_rank.hpp"
|
#include "modes/world_with_rank.hpp"
|
||||||
#include "network/event.hpp"
|
#include "network/event.hpp"
|
||||||
@ -369,6 +370,8 @@ void ClientLobby::update(float dt)
|
|||||||
break;
|
break;
|
||||||
case KART_SELECTION:
|
case KART_SELECTION:
|
||||||
{
|
{
|
||||||
|
// In case the user opened a user info dialog
|
||||||
|
GUIEngine::ModalDialog::dismiss();
|
||||||
NetworkKartSelectionScreen* screen =
|
NetworkKartSelectionScreen* screen =
|
||||||
NetworkKartSelectionScreen::getInstance();
|
NetworkKartSelectionScreen::getInstance();
|
||||||
screen->setAvailableKartsFromServer(m_available_karts);
|
screen->setAvailableKartsFromServer(m_available_karts);
|
||||||
|
@ -62,7 +62,8 @@ public:
|
|||||||
LE_VOTE_LAPS, // vote number of laps
|
LE_VOTE_LAPS, // vote number of laps
|
||||||
LE_CHAT,
|
LE_CHAT,
|
||||||
LE_FINAL_PLAYER_LIST,
|
LE_FINAL_PLAYER_LIST,
|
||||||
LE_AUTHORISED
|
LE_AUTHORISED,
|
||||||
|
LE_KICK_HOST
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RejectReason : uint8_t
|
enum RejectReason : uint8_t
|
||||||
|
@ -160,7 +160,20 @@ bool ServerLobby::notifyEvent(Event* event)
|
|||||||
} // notifyEvent
|
} // notifyEvent
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
void ServerLobby::kickHost(Event* event)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m_connection_mutex);
|
||||||
|
if (m_server_owner.lock() != event->getPeerSP())
|
||||||
|
return;
|
||||||
|
lock.unlock();
|
||||||
|
NetworkString& data = event->data();
|
||||||
|
uint32_t host_id = data.getUInt32();
|
||||||
|
std::shared_ptr<STKPeer> peer = STKHost::get()->findPeerByHostId(host_id);
|
||||||
|
if (peer)
|
||||||
|
peer->kick();
|
||||||
|
} // kickHost
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
bool ServerLobby::notifyEventAsynchronous(Event* event)
|
bool ServerLobby::notifyEventAsynchronous(Event* event)
|
||||||
{
|
{
|
||||||
assert(m_game_setup); // assert that the setup exists
|
assert(m_game_setup); // assert that the setup exists
|
||||||
@ -185,6 +198,8 @@ bool ServerLobby::notifyEventAsynchronous(Event* event)
|
|||||||
case LE_VOTE_REVERSE: playerReversedVote(event); break;
|
case LE_VOTE_REVERSE: playerReversedVote(event); break;
|
||||||
case LE_VOTE_LAPS: playerLapsVote(event); break;
|
case LE_VOTE_LAPS: playerLapsVote(event); break;
|
||||||
case LE_RACE_FINISHED_ACK: playerFinishedResult(event); break;
|
case LE_RACE_FINISHED_ACK: playerFinishedResult(event); break;
|
||||||
|
case LE_KICK_HOST: kickHost(event); break;
|
||||||
|
default: break;
|
||||||
} // switch
|
} // switch
|
||||||
} // if (event->getType() == EVENT_TYPE_MESSAGE)
|
} // if (event->getType() == EVENT_TYPE_MESSAGE)
|
||||||
else if (event->getType() == EVENT_TYPE_DISCONNECTED)
|
else if (event->getType() == EVENT_TYPE_DISCONNECTED)
|
||||||
|
@ -95,6 +95,7 @@ private:
|
|||||||
void registerServer();
|
void registerServer();
|
||||||
void finishedLoadingWorldClient(Event *event);
|
void finishedLoadingWorldClient(Event *event);
|
||||||
void startedRaceOnClient(Event *event);
|
void startedRaceOnClient(Event *event);
|
||||||
|
void kickHost(Event* event);
|
||||||
void unregisterServer();
|
void unregisterServer();
|
||||||
void createServerIdFile();
|
void createServerIdFile();
|
||||||
void updatePlayerList();
|
void updatePlayerList();
|
||||||
|
99
src/states_screens/dialogs/network_user_dialog.cpp
Normal file
99
src/states_screens/dialogs/network_user_dialog.cpp
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
// Copyright (C) 2018 SuperTuxKart-Team
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation; either version 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
#include "states_screens/dialogs/network_user_dialog.hpp"
|
||||||
|
|
||||||
|
#include "config/player_manager.hpp"
|
||||||
|
#include "guiengine/dialog_queue.hpp"
|
||||||
|
#include "guiengine/engine.hpp"
|
||||||
|
#include "online/online_profile.hpp"
|
||||||
|
#include "network/protocols/lobby_protocol.hpp"
|
||||||
|
#include "network/stk_host.hpp"
|
||||||
|
#include "states_screens/state_manager.hpp"
|
||||||
|
#include "utils/translation.hpp"
|
||||||
|
|
||||||
|
#include <IGUIEnvironment.h>
|
||||||
|
|
||||||
|
using namespace GUIEngine;
|
||||||
|
using namespace irr;
|
||||||
|
using namespace irr::gui;
|
||||||
|
using namespace Online;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
void NetworkUserDialog::beforeAddingWidgets()
|
||||||
|
{
|
||||||
|
m_options_widget = getWidget<RibbonWidget>("options");
|
||||||
|
assert(m_options_widget != NULL);
|
||||||
|
m_name_widget = getWidget<LabelWidget>("name");
|
||||||
|
assert(m_name_widget != NULL);
|
||||||
|
m_name_widget->setText(m_name, false);
|
||||||
|
|
||||||
|
m_options_widget = getWidget<RibbonWidget>("options");
|
||||||
|
assert(m_options_widget != NULL);
|
||||||
|
|
||||||
|
m_friend_widget = getWidget<IconButtonWidget>("friend");
|
||||||
|
assert(m_friend_widget != NULL);
|
||||||
|
m_kick_widget = getWidget<IconButtonWidget>("decline");
|
||||||
|
assert(m_kick_widget != NULL);
|
||||||
|
|
||||||
|
//I18N: In the network user dialog
|
||||||
|
m_kick_widget->setText(_("Kick"));
|
||||||
|
m_kick_widget->setVisible(STKHost::get()->isAuthorisedToControl());
|
||||||
|
|
||||||
|
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
|
||||||
|
assert(m_cancel_widget != NULL);
|
||||||
|
m_cancel_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||||
|
|
||||||
|
getWidget<IconButtonWidget>("accept")->setVisible(false);
|
||||||
|
getWidget<IconButtonWidget>("remove")->setVisible(false);
|
||||||
|
getWidget<IconButtonWidget>("enter")->setVisible(false);
|
||||||
|
getWidget<LabelWidget>("info")->setVisible(false);
|
||||||
|
} // beforeAddingWidgets
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
GUIEngine::EventPropagation
|
||||||
|
NetworkUserDialog::processEvent(const std::string& source)
|
||||||
|
{
|
||||||
|
if (source == m_options_widget->m_properties[PROP_ID])
|
||||||
|
{
|
||||||
|
const std::string& selection = m_options_widget
|
||||||
|
->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||||
|
if (selection == m_cancel_widget->m_properties[PROP_ID])
|
||||||
|
{
|
||||||
|
m_self_destroy = true;
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
|
else if(selection == m_friend_widget->m_properties[PROP_ID])
|
||||||
|
{
|
||||||
|
XMLRequest *request = new XMLRequest();
|
||||||
|
PlayerManager::setUserDetails(request, "friend-request");
|
||||||
|
request->addParameter("friendid", m_online_id);
|
||||||
|
request->queue();
|
||||||
|
m_self_destroy = true;
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
|
else if(selection == m_kick_widget->m_properties[PROP_ID])
|
||||||
|
{
|
||||||
|
NetworkString kick(PROTOCOL_LOBBY_ROOM);
|
||||||
|
kick.addUInt8(LobbyProtocol::LE_KICK_HOST).addUInt32(m_host_id);
|
||||||
|
STKHost::get()->sendToServer(&kick, true/*reliable*/);
|
||||||
|
m_self_destroy = true;
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GUIEngine::EVENT_LET;
|
||||||
|
} // processEvent
|
93
src/states_screens/dialogs/network_user_dialog.hpp
Normal file
93
src/states_screens/dialogs/network_user_dialog.hpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
// Copyright (C) 2018 SuperTuxKart-Team
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation; either version 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef HEADER_USER_INFO_DIALOG_HPP
|
||||||
|
#define HEADER_USER_INFO_DIALOG_HPP
|
||||||
|
|
||||||
|
#include "guiengine/modaldialog.hpp"
|
||||||
|
#include "guiengine/widgets.hpp"
|
||||||
|
#include "utils/types.hpp"
|
||||||
|
|
||||||
|
#include <irrString.h>
|
||||||
|
|
||||||
|
namespace Online
|
||||||
|
{
|
||||||
|
class OnlineProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Dialog that handle user in network lobby
|
||||||
|
* \ingroup states_screens
|
||||||
|
*/
|
||||||
|
class NetworkUserDialog : public GUIEngine::ModalDialog
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const uint32_t m_host_id;
|
||||||
|
|
||||||
|
const uint32_t m_online_id;
|
||||||
|
|
||||||
|
const core::stringw m_name;
|
||||||
|
|
||||||
|
bool m_self_destroy;
|
||||||
|
|
||||||
|
GUIEngine::RibbonWidget * m_options_widget;
|
||||||
|
|
||||||
|
GUIEngine::LabelWidget * m_name_widget;
|
||||||
|
|
||||||
|
GUIEngine::IconButtonWidget * m_friend_widget;
|
||||||
|
|
||||||
|
GUIEngine::IconButtonWidget * m_kick_widget;
|
||||||
|
|
||||||
|
GUIEngine::IconButtonWidget * m_cancel_widget;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NetworkUserDialog(uint32_t host_id, uint32_t online_id,
|
||||||
|
const core::stringw& name)
|
||||||
|
: ModalDialog(0.8f,0.8f), m_host_id(host_id), m_online_id(online_id),
|
||||||
|
m_name(name), m_self_destroy(false)
|
||||||
|
{
|
||||||
|
loadFromFile("online/user_info_dialog.stkgui");
|
||||||
|
}
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
~NetworkUserDialog() {}
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
virtual void beforeAddingWidgets();
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
void onEnterPressedInternal() { m_self_destroy = true; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
GUIEngine::EventPropagation processEvent(const std::string& source);
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
virtual bool onEscapePressed()
|
||||||
|
{
|
||||||
|
if (m_cancel_widget->isActivated())
|
||||||
|
m_self_destroy = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
virtual void onUpdate(float dt)
|
||||||
|
{
|
||||||
|
// It's unsafe to delete from inside the event handler so we do it here
|
||||||
|
if (m_self_destroy)
|
||||||
|
{
|
||||||
|
ModalDialog::dismiss();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -39,7 +39,7 @@
|
|||||||
#include "network/server.hpp"
|
#include "network/server.hpp"
|
||||||
#include "network/stk_host.hpp"
|
#include "network/stk_host.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "states_screens/dialogs/message_dialog.hpp"
|
#include "states_screens/dialogs/network_user_dialog.hpp"
|
||||||
#include "utils/translation.hpp"
|
#include "utils/translation.hpp"
|
||||||
|
|
||||||
using namespace Online;
|
using namespace Online;
|
||||||
@ -101,7 +101,6 @@ void NetworkingLobby::beforeAddingWidget()
|
|||||||
void NetworkingLobby::init()
|
void NetworkingLobby::init()
|
||||||
{
|
{
|
||||||
Screen::init();
|
Screen::init();
|
||||||
setInitialFocus();
|
|
||||||
m_start_button->setVisible(false);
|
m_start_button->setVisible(false);
|
||||||
|
|
||||||
// For now create the active player and bind it to the right
|
// For now create the active player and bind it to the right
|
||||||
@ -201,6 +200,18 @@ void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
|
|||||||
StateManager::get()->escapePressed();
|
StateManager::get()->escapePressed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (name == m_player_list->m_properties[GUIEngine::PROP_ID])
|
||||||
|
{
|
||||||
|
auto host_online_ids = StringUtils::splitToUInt
|
||||||
|
(m_player_list->getSelectionInternalName(), '_');
|
||||||
|
if (host_online_ids.size() != 2 ||
|
||||||
|
STKHost::get()->getMyHostId() == host_online_ids[0])
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new NetworkUserDialog(host_online_ids[0], host_online_ids[1],
|
||||||
|
m_player_list->getSelectionLabel());
|
||||||
|
} // click on replay file
|
||||||
|
|
||||||
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
|
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
|
||||||
if (ribbon == NULL) return;
|
if (ribbon == NULL) return;
|
||||||
@ -227,6 +238,7 @@ void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
|
|||||||
STKHost::get()->sendToServer(&start, true);
|
STKHost::get()->sendToServer(&start, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // eventCallback
|
} // eventCallback
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -243,23 +255,6 @@ bool NetworkingLobby::onEscapePressed()
|
|||||||
return true; // close the screen
|
return true; // close the screen
|
||||||
} // onEscapePressed
|
} // onEscapePressed
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void NetworkingLobby::onDisabledItemClicked(const std::string& item)
|
|
||||||
{
|
|
||||||
|
|
||||||
} // onDisabledItemClicked
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void NetworkingLobby::setInitialFocus()
|
|
||||||
{
|
|
||||||
} // setInitialFocus
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void NetworkingLobby::onDialogClose()
|
|
||||||
{
|
|
||||||
setInitialFocus();
|
|
||||||
} // onDialogClose()
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void NetworkingLobby::addPlayer(const std::tuple<uint32_t, uint32_t,
|
void NetworkingLobby::addPlayer(const std::tuple<uint32_t, uint32_t,
|
||||||
core::stringw, bool>& p)
|
core::stringw, bool>& p)
|
||||||
@ -273,7 +268,7 @@ void NetworkingLobby::addPlayer(const std::tuple<uint32_t, uint32_t,
|
|||||||
StringUtils::toString(std::get<1>(p));
|
StringUtils::toString(std::get<1>(p));
|
||||||
m_player_list->addItem(internal_name, std::get<2>(p));
|
m_player_list->addItem(internal_name, std::get<2>(p));
|
||||||
if (std::get<3>(p))
|
if (std::get<3>(p))
|
||||||
m_player_list->markItemRed(internal_name, true);
|
m_player_list->markItemBlue(internal_name, true);
|
||||||
}
|
}
|
||||||
} // addPlayer
|
} // addPlayer
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ namespace GUIEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Handles the main menu
|
* \brief Handles the networking lobby
|
||||||
* \ingroup states_screens
|
* \ingroup states_screens
|
||||||
*/
|
*/
|
||||||
class NetworkingLobby : public GUIEngine::Screen,
|
class NetworkingLobby : public GUIEngine::Screen,
|
||||||
@ -55,9 +55,6 @@ private:
|
|||||||
GUIEngine::ListWidget *m_player_list;
|
GUIEngine::ListWidget *m_player_list;
|
||||||
GUIEngine::TextBoxWidget* m_chat_box;
|
GUIEngine::TextBoxWidget* m_chat_box;
|
||||||
|
|
||||||
/** \brief Sets which widget has to be focused. Depends on the user state. */
|
|
||||||
void setInitialFocus();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void onUpdate(float delta) OVERRIDE;
|
virtual void onUpdate(float delta) OVERRIDE;
|
||||||
@ -81,12 +78,6 @@ public:
|
|||||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||||
virtual bool onEscapePressed() OVERRIDE;
|
virtual bool onEscapePressed() OVERRIDE;
|
||||||
|
|
||||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
|
||||||
virtual void onDisabledItemClicked(const std::string& item) OVERRIDE;
|
|
||||||
|
|
||||||
/** \brief Implements the callback when a dialog gets closed. */
|
|
||||||
virtual void onDialogClose() OVERRIDE;
|
|
||||||
|
|
||||||
/** Used to insert each client chat message (reserved). */
|
/** Used to insert each client chat message (reserved). */
|
||||||
void addMoreServerInfo(const core::stringw& info);
|
void addMoreServerInfo(const core::stringw& info);
|
||||||
void setJoinedServer(std::shared_ptr<Server> server);
|
void setJoinedServer(std::shared_ptr<Server> server);
|
||||||
|
Loading…
Reference in New Issue
Block a user