adding possibility for the server to decide when to start the selection
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13354 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -223,6 +223,7 @@ src/states_screens/help_screen_3.cpp
|
||||
src/states_screens/help_screen_4.cpp
|
||||
src/states_screens/kart_selection.cpp
|
||||
src/states_screens/main_menu_screen.cpp
|
||||
src/states_screens/network_kart_selection.cpp
|
||||
src/states_screens/networking_lobby.cpp
|
||||
src/states_screens/networking_lobby_settings.cpp
|
||||
src/states_screens/online_screen.cpp
|
||||
@@ -515,6 +516,7 @@ src/states_screens/help_screen_3.hpp
|
||||
src/states_screens/help_screen_4.hpp
|
||||
src/states_screens/kart_selection.hpp
|
||||
src/states_screens/main_menu_screen.hpp
|
||||
src/states_screens/network_kart_selection.cpp
|
||||
src/states_screens/networking_lobby.hpp
|
||||
src/states_screens/networking_lobby_settings.hpp
|
||||
src/states_screens/online_screen.hpp
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "network/network_manager.hpp"
|
||||
#include "network/protocols/start_game_protocol.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/network_kart_selection.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
ClientLobbyRoomProtocol::ClientLobbyRoomProtocol(const TransportAddress& server_address)
|
||||
@@ -73,6 +75,8 @@ void ClientLobbyRoomProtocol::notifyEvent(Event* event)
|
||||
kartSelectionUpdate(event);
|
||||
else if (message_type == 0x04) // start race
|
||||
startGame(event);
|
||||
else if (message_type == 0x05) // start selection phase
|
||||
startSelection(event);
|
||||
else if (message_type == 0x80) // connection refused
|
||||
connectionRefused(event);
|
||||
else if (message_type == 0x81) // connection accepted
|
||||
@@ -113,6 +117,10 @@ void ClientLobbyRoomProtocol::update()
|
||||
break;
|
||||
case CONNECTED:
|
||||
break;
|
||||
case SELECTING_KARTS:
|
||||
break;
|
||||
case PLAYING:
|
||||
break;
|
||||
case DONE:
|
||||
m_state = EXITING;
|
||||
m_listener->requestTerminate(this);
|
||||
@@ -388,6 +396,7 @@ void ClientLobbyRoomProtocol::startGame(Event* event)
|
||||
uint8_t token = event->data.gui32(1);
|
||||
if (token == NetworkManager::getInstance()->getPeers()[0]->getClientServerToken())
|
||||
{
|
||||
m_state = PLAYING;
|
||||
m_listener->requestStart(new StartGameProtocol(m_setup));
|
||||
Log::error("ClientLobbyRoomProtocol", "Starting new game");
|
||||
}
|
||||
@@ -397,3 +406,35 @@ void ClientLobbyRoomProtocol::startGame(Event* event)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*! \brief Called when the kart selection starts.
|
||||
* \param event : Event providing the information.
|
||||
*
|
||||
* Format of the data :
|
||||
* Byte 0 1 5
|
||||
* -------------
|
||||
* Size | 1 | 4 |
|
||||
* Data | 4 | token |
|
||||
* -------------
|
||||
*/
|
||||
void ClientLobbyRoomProtocol::startSelection(Event* event)
|
||||
{
|
||||
if (event->data.size() < 5 || event->data[0] != 4)
|
||||
{
|
||||
Log::error("ClientLobbyRoomProtocol", "A message notifying a kart "
|
||||
"selection update wasn't formated as expected.");
|
||||
return;
|
||||
}
|
||||
uint8_t token = event->data.gui32(1);
|
||||
if (token == NetworkManager::getInstance()->getPeers()[0]->getClientServerToken())
|
||||
{
|
||||
m_state = SELECTING_KARTS;
|
||||
StateManager::get()->pushScreen(NetworkKartSelectionScreen::getInstance());
|
||||
Log::info("ClientLobbyRoomProtocol", "Kart selection starts now");
|
||||
}
|
||||
else
|
||||
Log::error("ClientLobbyRoomProtocol", "Bad token");
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -26,6 +26,7 @@ class ClientLobbyRoomProtocol : public LobbyRoomProtocol
|
||||
void kartSelectionRefused(Event* event);
|
||||
void kartSelectionUpdate(Event* event);
|
||||
void startGame(Event* event);
|
||||
void startSelection(Event* event);
|
||||
|
||||
TransportAddress m_server_address;
|
||||
STKPeer* m_server;
|
||||
@@ -35,7 +36,9 @@ class ClientLobbyRoomProtocol : public LobbyRoomProtocol
|
||||
NONE,
|
||||
LINKED,
|
||||
REQUESTING_CONNECTION,
|
||||
CONNECTED,
|
||||
CONNECTED, // means in the lobby room
|
||||
SELECTING_KARTS, // in the network kart selection screen
|
||||
PLAYING,
|
||||
DONE,
|
||||
EXITING
|
||||
};
|
||||
|
||||
@@ -47,7 +47,7 @@ void RequestConnection::asynchronousUpdate()
|
||||
{
|
||||
case NONE:
|
||||
{
|
||||
m_request = new Online::XMLRequest();
|
||||
m_request = new Online::CurrentUser::ServerJoinRequest();
|
||||
m_request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
m_request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
|
||||
Online::CurrentUser::release();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define REQUEST_CONNECTION_HPP
|
||||
|
||||
#include "network/protocol.hpp"
|
||||
#include "online/request.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
|
||||
class RequestConnection : public Protocol
|
||||
{
|
||||
@@ -17,7 +17,7 @@ class RequestConnection : public Protocol
|
||||
|
||||
protected:
|
||||
uint32_t m_server_id;
|
||||
Online::XMLRequest* m_request;
|
||||
Online::CurrentUser::ServerJoinRequest* m_request;
|
||||
enum STATE
|
||||
{
|
||||
NONE,
|
||||
|
||||
@@ -51,6 +51,7 @@ void ServerLobbyRoomProtocol::setup()
|
||||
m_state = NONE;
|
||||
m_public_address.ip = 0;
|
||||
m_public_address.port = 0;
|
||||
m_selection_enabled = false;
|
||||
Log::info("ServerLobbyRoomProtocol", "Starting the protocol.");
|
||||
}
|
||||
|
||||
@@ -187,6 +188,20 @@ void ServerLobbyRoomProtocol::startGame()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ServerLobbyRoomProtocol::startSelection()
|
||||
{
|
||||
std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
|
||||
for (unsigned int i = 0; i < peers.size(); i++)
|
||||
{
|
||||
NetworkString ns;
|
||||
ns.ai8(0x05).ai8(4).ai32(peers[i]->getClientServerToken()); // start selection
|
||||
m_listener->sendMessage(this, peers[i], ns, true); // reliably
|
||||
}
|
||||
m_selection_enabled = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ServerLobbyRoomProtocol::kartDisconnected(Event* event)
|
||||
{
|
||||
STKPeer* peer = *(event->peer);
|
||||
@@ -318,6 +333,15 @@ void ServerLobbyRoomProtocol::kartSelectionRequested(Event* event)
|
||||
"%d, real: %d.", kart_name_size, kart_name.size());
|
||||
return;
|
||||
}
|
||||
// check if selection is possible
|
||||
if (!m_selection_enabled)
|
||||
{
|
||||
NetworkString answer;
|
||||
answer.ai8(0x82).ai8(1).ai8(2); // selection still not started
|
||||
m_listener->sendMessage(this, peer, answer);
|
||||
return;
|
||||
}
|
||||
// check if somebody picked that kart
|
||||
if (!m_setup->isKartAvailable(kart_name))
|
||||
{
|
||||
NetworkString answer;
|
||||
|
||||
@@ -15,6 +15,7 @@ class ServerLobbyRoomProtocol : public LobbyRoomProtocol
|
||||
virtual void asynchronousUpdate() {};
|
||||
|
||||
void startGame();
|
||||
void startSelection();
|
||||
|
||||
protected:
|
||||
void kartDisconnected(Event* event);
|
||||
@@ -26,6 +27,7 @@ class ServerLobbyRoomProtocol : public LobbyRoomProtocol
|
||||
std::vector<uint32_t> m_incoming_peers_ids;
|
||||
uint32_t m_current_protocol_id;
|
||||
TransportAddress m_public_address;
|
||||
bool m_selection_enabled;
|
||||
|
||||
enum STATE
|
||||
{
|
||||
|
||||
@@ -56,6 +56,12 @@ void* waitInput2(void* data)
|
||||
assert(protocol);
|
||||
protocol->startGame();
|
||||
}
|
||||
else if (str == "selection")
|
||||
{
|
||||
ServerLobbyRoomProtocol* protocol = static_cast<ServerLobbyRoomProtocol*>(ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM));
|
||||
assert(protocol);
|
||||
protocol->startSelection();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t id = ProtocolManager::getInstance()->requestStart(new StopServer());
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/connect_to_server.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
#include "online/messages.hpp"
|
||||
@@ -40,10 +42,11 @@ using namespace Online;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ServerInfoDialog::ServerInfoDialog(uint32_t server_id, bool from_server_creation) :
|
||||
ServerInfoDialog::ServerInfoDialog(uint32_t server_id, uint32_t host_id,bool from_server_creation) :
|
||||
ModalDialog(0.8f,0.8f)
|
||||
{
|
||||
m_server_id = server_id;
|
||||
m_host_id = host_id;
|
||||
m_self_destroy = false;
|
||||
m_enter_lobby = false;
|
||||
m_from_server_creation = from_server_creation;
|
||||
@@ -73,13 +76,16 @@ ServerInfoDialog::ServerInfoDialog(uint32_t server_id, bool from_server_creation
|
||||
// -----------------------------------------------------------------------------
|
||||
ServerInfoDialog::~ServerInfoDialog()
|
||||
{
|
||||
delete m_server_join_request;
|
||||
if (m_server_join_request)
|
||||
delete m_server_join_request;
|
||||
m_server_join_request = NULL;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void ServerInfoDialog::requestJoin()
|
||||
{
|
||||
m_server_join_request = Online::CurrentUser::acquire()->requestServerJoin(m_server_id);
|
||||
Online::CurrentUser::release();
|
||||
//m_server_join_request = Online::CurrentUser::acquire()->requestServerJoin(m_server_id);
|
||||
ProtocolManager::getInstance()->requestStart(new ConnectToServer(m_host_id));
|
||||
//Online::CurrentUser::release();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -38,7 +38,7 @@ class ServerInfoDialog : public GUIEngine::ModalDialog
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
|
||||
bool m_self_destroy;
|
||||
bool m_enter_lobby;
|
||||
bool m_from_server_creation;
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
float m_load_timer;
|
||||
|
||||
uint32_t m_server_id;
|
||||
uint32_t m_host_id;
|
||||
|
||||
GUIEngine::LabelWidget * m_name_widget;
|
||||
GUIEngine::LabelWidget * m_info_widget;
|
||||
@@ -54,16 +55,16 @@ private:
|
||||
GUIEngine::RibbonWidget * m_options_widget;
|
||||
GUIEngine::IconButtonWidget * m_join_widget;
|
||||
GUIEngine::IconButtonWidget * m_cancel_widget;
|
||||
|
||||
|
||||
void requestJoin();
|
||||
|
||||
public:
|
||||
ServerInfoDialog(uint32_t server_id, bool just_created = false);
|
||||
ServerInfoDialog(uint32_t server_id, uint32_t host_id, bool just_created = false);
|
||||
~ServerInfoDialog();
|
||||
|
||||
void onEnterPressedInternal();
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
|
||||
|
||||
virtual void onUpdate(float dt);
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class KartSelectionScreen : public GUIEngine::Screen,
|
||||
friend class KartHoverListener;
|
||||
friend class PlayerNameSpinner;
|
||||
friend class FocusDispatcher;
|
||||
|
||||
protected:
|
||||
/** Contains the custom widget shown for every player. (ref only since
|
||||
* we're adding them to a Screen, and the Screen will take ownership
|
||||
* of these widgets)
|
||||
|
||||
@@ -164,7 +164,9 @@ void ServerSelection::eventCallback( GUIEngine::Widget* widget,
|
||||
m_selected_index = m_server_list_widget->getSelectionID();
|
||||
uint32_t server_id = ServersManager::acquire()->getServerBySort(m_selected_index)->getServerId();
|
||||
ServersManager::release();
|
||||
new ServerInfoDialog(server_id);
|
||||
uint32_t host_id = ServersManager::acquire()->getServerBySort(m_selected_index)->getHostId();
|
||||
ServersManager::release();
|
||||
new ServerInfoDialog(server_id, host_id);
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
|
||||
Reference in New Issue
Block a user