An 'authorised' client can now tell the server to select karts.

This commit is contained in:
hiker 2015-11-23 08:08:23 +11:00
parent 0f38d6fb8a
commit da2671c6ee
6 changed files with 66 additions and 37 deletions

View File

@ -25,7 +25,11 @@
</box>
<spacer width="20" height="20"/>
<box id="actions" proportion="1" height="100%" layout="vertical-row">
<label I18N="In networking lobby" word_wrap="true" text="actions" align="center" text-align="center"/>
<!-- <label I18N="In networking lobby" word_wrap="true" text="actions" align="center" text-align="center"/>
-->
<icon-button id="start" width="64" height="64" icon="gui/green_check.png"
I18N="In the network lobby" text="Start Race"/>
</box>
</div>
</div>

View File

@ -32,32 +32,34 @@
*/
class LobbyRoomProtocol : public Protocol
{
protected:
/** The game setup. */
GameSetup* m_setup;
public:
/** Lists all lobby events (LE). */
enum
{
LE_CONNECTION_REQUESTED = 1,
LE_NEW_PLAYER_CONNECTED = 0x01,
LE_KART_SELECTION = 2,
LE_PLAYER_DISCONNECTED = 0x02,
LE_KART_SELECTION_UPDATE = 0x03,
LE_START_RACE = 0x04,
LE_START_SELECTION = 0x05,
LE_RACE_FINISHED = 0x06,
LE_CONNECTION_REFUSED = 0x80,
LE_CONNECTION_ACCEPTED = 0x81,
LE_KART_SELECTION_REFUSED = 0x82,
LE_VOTE_MAJOR = 0xc0,
LE_VOTE_RACE_COUNT = 0xc1,
LE_VOTE_MINOR = 0xc2,
LE_VOTE_TRACK = 0xc3,
LE_VOTE_REVERSE = 0xc4,
LE_VOTE_LAPS = 0xc5,
LE_REQUEST_BEGIN,
LE_NEW_PLAYER_CONNECTED,
LE_KART_SELECTION,
LE_PLAYER_DISCONNECTED,
LE_KART_SELECTION_UPDATE,
LE_START_RACE,
LE_START_SELECTION,
LE_RACE_FINISHED,
LE_CONNECTION_REFUSED,
LE_CONNECTION_ACCEPTED,
LE_KART_SELECTION_REFUSED,
LE_VOTE_MAJOR,
LE_VOTE_RACE_COUNT,
LE_VOTE_MINOR,
LE_VOTE_TRACK,
LE_VOTE_REVERSE,
LE_VOTE_LAPS,
};
protected:
/** The game setup. */
GameSetup* m_setup;
public:
LobbyRoomProtocol(CallbackObject* callback_object)

View File

@ -85,6 +85,7 @@ bool ServerLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
switch(message_type)
{
case LE_CONNECTION_REQUESTED: connectionRequested(event); break;
case LE_REQUEST_BEGIN: startSelection(); break;
case LE_KART_SELECTION: kartSelectionRequested(event); break;
case LE_VOTE_MAJOR: playerMajorVote(event); break;
case LE_VOTE_RACE_COUNT: playerRaceCountVote(event); break;
@ -169,7 +170,7 @@ void ServerLobbyRoomProtocol::callback(Protocol *protocol)
//-----------------------------------------------------------------------------
/** Register this server (i.e. its public address) with the STK server
* so that clients can find it. It blocks till a responsce from the
* so that clients can find it. It blocks till a response from the
* stk server is received (this function is executed from the
* ProtocolManager thread). The information about this client is added
* to the table 'server'.

View File

@ -24,6 +24,7 @@
#include "network/network.hpp"
#include "network/network_string.hpp"
#include "network/servers_manager.hpp"
#include "network/transport_address.hpp"
#include "utils/synchronised.hpp"
@ -146,6 +147,7 @@ public:
int mustStopListening();
uint16_t getPort() const;
void setErrorMessage(const irr::core::stringw &message);
bool isAuthorisedToControl() const;
const irr::core::stringw&
getErrorMessage() const;
@ -201,7 +203,7 @@ public:
{
return m_is_registered;
} // isRegistered
// --------------------------------------------------------------------
}; // class STKHost
#endif // STK_HOST_HPP

View File

@ -25,14 +25,16 @@
#include "challenges/unlock_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "main_loop.hpp"
#include "modes/demo_world.hpp"
#include "network/protocol_manager.hpp"
#include "network/protocols/client_lobby_room_protocol.hpp"
#include "network/servers_manager.hpp"
#include "network/stk_host.hpp"
#include "states_screens/online_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
@ -57,6 +59,9 @@ void NetworkingLobby::loadedFromFile()
m_back_widget = getWidget<IconButtonWidget>("back");
assert(m_back_widget != NULL);
m_start_button= getWidget<IconButtonWidget>("start");
assert(m_start_button!= NULL);
m_server_name_widget = getWidget<LabelWidget>("server_name");
assert(m_server_name_widget != NULL);
@ -66,12 +71,13 @@ void NetworkingLobby::loadedFromFile()
m_bottom_menu_widget = getWidget<RibbonWidget>("menu_bottomrow");
assert(m_bottom_menu_widget != NULL);
m_exit_widget = (IconButtonWidget *) m_bottom_menu_widget->findWidgetNamed("exit");
m_exit_widget = (IconButtonWidget *) m_bottom_menu_widget
->findWidgetNamed("exit");
assert(m_exit_widget != NULL);
} // loadedFromFile
// ----------------------------------------------------------------------------
// ---------------------------------------------------------------------------
void NetworkingLobby::beforeAddingWidget()
{
@ -84,21 +90,24 @@ void NetworkingLobby::init()
{
Screen::init();
setInitialFocus();
DemoWorld::resetIdleTime(); //FIXME : what's this?
m_server = ServersManager::get()->getJoinedServer();
if(m_server)
m_server_name_widget->setText(m_server->getName(), false);
m_start_button->setVisible(STKHost::get()->isAuthorisedToControl());
} // init
// ----------------------------------------------------------------------------
void NetworkingLobby::onUpdate(float delta)
{
m_start_button->setVisible(STKHost::get()->isAuthorisedToControl());
} // onUpdate
// ----------------------------------------------------------------------------
void NetworkingLobby::eventCallback(Widget* widget, const std::string& name, const int playerID)
void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
const int playerID)
{
if (name == m_back_widget->m_properties[PROP_ID])
{
@ -106,9 +115,19 @@ void NetworkingLobby::eventCallback(Widget* widget, const std::string& name, con
return;
}
if(name==m_start_button->m_properties[PROP_ID])
{
// Send a message to the server to start
NetworkString start;
start.addUInt8(PROTOCOL_LOBBY_ROOM)
.addUInt8(LobbyRoomProtocol::LE_REQUEST_BEGIN);
STKHost::get()->sendMessage(start, true);
}
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
if (ribbon == NULL) return;
const std::string &selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
const std::string &selection =
ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == m_exit_widget->m_properties[PROP_ID])
{

View File

@ -19,13 +19,16 @@
#define HEADER_NETWORKING_LOBBY_HPP
#include "guiengine/screen.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
class Server;
namespace GUIEngine { class Widget; class ListWidget; }
namespace GUIEngine {
class Widget;
class ListWidget;
class IconButtonWidget;
class LabelWidget;
class RibbonWidget;
}
/**
* \brief Handles the main menu
@ -42,13 +45,11 @@ private:
NetworkingLobby();
GUIEngine::IconButtonWidget * m_back_widget;
GUIEngine::LabelWidget * m_server_name_widget;
GUIEngine::LabelWidget * m_online_status_widget;
GUIEngine::RibbonWidget * m_bottom_menu_widget;
GUIEngine::IconButtonWidget * m_exit_widget;
GUIEngine::IconButtonWidget *m_start_button;
/** \brief Sets which widget has to be focused. Depends on the user state. */
void setInitialFocus();