2013-07-11 12:03:28 +00:00
|
|
|
|
//
|
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
|
// Copyright (C) 2013 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.
|
|
|
|
|
|
2013-07-10 20:15:17 +00:00
|
|
|
|
#include "network/protocols/client_lobby_room_protocol.hpp"
|
|
|
|
|
|
|
|
|
|
#include "network/network_manager.hpp"
|
2013-07-14 21:19:22 +00:00
|
|
|
|
#include "network/protocols/start_game_protocol.hpp"
|
2013-08-01 01:03:07 +00:00
|
|
|
|
#include "network/network_world.hpp"
|
2013-08-15 12:35:23 +00:00
|
|
|
|
|
|
|
|
|
#include "modes/world_with_rank.hpp"
|
2013-07-24 15:43:54 +00:00
|
|
|
|
#include "online/current_user.hpp"
|
2013-07-26 12:49:05 +00:00
|
|
|
|
#include "states_screens/state_manager.hpp"
|
|
|
|
|
#include "states_screens/network_kart_selection.hpp"
|
2013-07-10 20:15:17 +00:00
|
|
|
|
#include "utils/log.hpp"
|
|
|
|
|
|
2013-07-10 22:46:23 +00:00
|
|
|
|
ClientLobbyRoomProtocol::ClientLobbyRoomProtocol(const TransportAddress& server_address)
|
|
|
|
|
: LobbyRoomProtocol(NULL)
|
|
|
|
|
{
|
|
|
|
|
m_server_address = server_address;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_server = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientLobbyRoomProtocol::~ClientLobbyRoomProtocol()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::setup()
|
|
|
|
|
{
|
|
|
|
|
m_setup = NetworkManager::getInstance()->setupNewGame(); // create a new setup
|
2013-09-22 20:40:14 +00:00
|
|
|
|
m_setup->getRaceConfig()->setPlayerCount(16); //FIXME : this has to be changed when logging into the server
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_state = NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::requestKartSelection(std::string kart_name)
|
|
|
|
|
{
|
|
|
|
|
NetworkString request;
|
|
|
|
|
// 0x02 : kart selection request, size_token (4), token, size kart name, kart name
|
|
|
|
|
request.ai8(0x02).ai8(4).ai32(m_server->getClientServerToken()).ai8(kart_name.size()).as(kart_name);
|
2013-09-22 20:40:14 +00:00
|
|
|
|
m_listener->sendMessage(this, request, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteMajor(uint8_t major)
|
|
|
|
|
{
|
|
|
|
|
NetworkString request;
|
|
|
|
|
// 0xc0 : major vote, size_token (4), token, size major(1),major
|
|
|
|
|
request.ai8(0xc0).ai8(4).ai32(m_server->getClientServerToken()).ai8(1).ai8(major);
|
|
|
|
|
m_listener->sendMessage(this, request, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteRaceCount(uint8_t count)
|
|
|
|
|
{
|
|
|
|
|
NetworkString request;
|
|
|
|
|
// 0xc0 : race count vote, size_token (4), token, size race count(1), count
|
|
|
|
|
request.ai8(0xc1).ai8(4).ai32(m_server->getClientServerToken()).ai8(1).ai8(count);
|
|
|
|
|
m_listener->sendMessage(this, request, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteMinor(uint8_t minor)
|
|
|
|
|
{
|
|
|
|
|
NetworkString request;
|
|
|
|
|
// 0xc0 : minor vote, size_token (4), token, size minor(1),minor
|
|
|
|
|
request.ai8(0xc2).ai8(4).ai32(m_server->getClientServerToken()).ai8(1).ai8(minor);
|
|
|
|
|
m_listener->sendMessage(this, request, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteTrack(std::string track, uint8_t track_nb)
|
|
|
|
|
{
|
|
|
|
|
NetworkString request;
|
|
|
|
|
// 0xc0 : major vote, size_token (4), token, size track, track, size #track, #track
|
|
|
|
|
request.ai8(0xc3).ai8(4).ai32(m_server->getClientServerToken()).ai8(track.size()).as(track).ai8(1).ai8(track_nb);
|
|
|
|
|
m_listener->sendMessage(this, request, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteReversed(bool reversed, uint8_t track_nb)
|
|
|
|
|
{
|
|
|
|
|
NetworkString request;
|
|
|
|
|
// 0xc0 : major vote, size_token (4), token, size reversed(1),reversed, size #track, #track
|
|
|
|
|
request.ai8(0xc4).ai8(4).ai32(m_server->getClientServerToken()).ai8(1).ai8(reversed).ai8(1).ai8(track_nb);
|
|
|
|
|
m_listener->sendMessage(this, request, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteLaps(uint8_t laps, uint8_t track_nb)
|
|
|
|
|
{
|
|
|
|
|
NetworkString request;
|
|
|
|
|
// 0xc0 : major vote, size_token (4), token, size laps(1),laps, size #track, #track
|
|
|
|
|
request.ai8(0xc5).ai8(4).ai32(m_server->getClientServerToken()).ai8(1).ai8(laps).ai8(1).ai8(track_nb);
|
|
|
|
|
m_listener->sendMessage(this, request, true);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2013-07-29 15:27:25 +00:00
|
|
|
|
void ClientLobbyRoomProtocol::leave()
|
|
|
|
|
{
|
2013-07-29 23:43:28 +00:00
|
|
|
|
m_server->disconnect();
|
|
|
|
|
m_server_address.ip = 0;
|
|
|
|
|
m_server_address.port = 0;
|
2013-07-29 15:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
bool ClientLobbyRoomProtocol::notifyEvent(Event* event)
|
|
|
|
|
{
|
2013-08-01 19:55:09 +00:00
|
|
|
|
assert(m_setup); // assert that the setup exists
|
|
|
|
|
if (event->type == EVENT_TYPE_MESSAGE)
|
|
|
|
|
{
|
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
assert(data.size()); // assert that data isn't empty
|
|
|
|
|
uint8_t message_type = data[0];
|
2013-08-21 19:04:46 +00:00
|
|
|
|
if (message_type != 0x03 &&
|
|
|
|
|
message_type != 0x06)
|
|
|
|
|
return false; // don't treat the event
|
2013-08-01 19:55:09 +00:00
|
|
|
|
|
|
|
|
|
event->removeFront(1);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Synchronous message of type %d", message_type);
|
2013-08-01 19:55:09 +00:00
|
|
|
|
if (message_type == 0x03) // kart selection update
|
|
|
|
|
kartSelectionUpdate(event);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
else if (message_type == 0x06) // end of race
|
|
|
|
|
raceFinished(event);
|
2013-08-01 19:55:09 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
assert(m_setup); // assert that the setup exists
|
|
|
|
|
if (event->type == EVENT_TYPE_MESSAGE)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
assert(data.size()); // assert that data isn't empty
|
|
|
|
|
uint8_t message_type = data[0];
|
2013-08-21 19:04:46 +00:00
|
|
|
|
if (message_type == 0x03 ||
|
|
|
|
|
message_type == 0x06)
|
|
|
|
|
return false; // don't treat the event
|
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
event->removeFront(1);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Asynchronous message of type %d", message_type);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
if (message_type == 0x01) // new player connected
|
|
|
|
|
newPlayer(event);
|
|
|
|
|
else if (message_type == 0x02) // player disconnected
|
|
|
|
|
disconnectedPlayer(event);
|
2013-07-14 21:19:22 +00:00
|
|
|
|
else if (message_type == 0x04) // start race
|
|
|
|
|
startGame(event);
|
2013-07-26 12:49:05 +00:00
|
|
|
|
else if (message_type == 0x05) // start selection phase
|
|
|
|
|
startSelection(event);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
else if (message_type == 0x80) // connection refused
|
|
|
|
|
connectionRefused(event);
|
|
|
|
|
else if (message_type == 0x81) // connection accepted
|
|
|
|
|
connectionAccepted(event);
|
|
|
|
|
else if (message_type == 0x82) // kart selection refused
|
|
|
|
|
kartSelectionRefused(event);
|
2013-09-22 20:40:14 +00:00
|
|
|
|
else if (message_type == 0xc0) // vote for major mode
|
|
|
|
|
playerMajorVote(event);
|
|
|
|
|
else if (message_type == 0xc1) // vote for race count
|
|
|
|
|
playerRaceCountVote(event);
|
|
|
|
|
else if (message_type == 0xc2) // vote for minor mode
|
|
|
|
|
playerMinorVote(event);
|
|
|
|
|
else if (message_type == 0xc3) // vote for track
|
|
|
|
|
playerTrackVote(event);
|
|
|
|
|
else if (message_type == 0xc4) // vote for reversed mode
|
|
|
|
|
playerReversedVote(event);
|
|
|
|
|
else if (message_type == 0xc5) // vote for laps
|
|
|
|
|
playerLapsVote(event);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
|
2013-08-01 19:55:09 +00:00
|
|
|
|
return true;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
} // message
|
|
|
|
|
else if (event->type == EVENT_TYPE_CONNECTED)
|
|
|
|
|
{
|
2013-08-01 19:55:09 +00:00
|
|
|
|
return true;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
} // connection
|
2013-07-29 23:43:28 +00:00
|
|
|
|
else if (event->type == EVENT_TYPE_DISCONNECTED) // means we left essentially
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2013-07-29 23:43:28 +00:00
|
|
|
|
NetworkManager::getInstance()->removePeer(m_server);
|
|
|
|
|
m_server = NULL;
|
|
|
|
|
NetworkManager::getInstance()->disconnected();
|
|
|
|
|
m_listener->requestTerminate(this);
|
|
|
|
|
NetworkManager::getInstance()->reset();
|
|
|
|
|
NetworkManager::getInstance()->removePeer(*event->peer); // prolly the same as m_server
|
2013-08-01 19:55:09 +00:00
|
|
|
|
return true;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
} // disconnection
|
2013-08-01 19:55:09 +00:00
|
|
|
|
return false;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::update()
|
|
|
|
|
{
|
|
|
|
|
switch (m_state)
|
|
|
|
|
{
|
|
|
|
|
case NONE:
|
|
|
|
|
if (NetworkManager::getInstance()->isConnectedTo(m_server_address))
|
|
|
|
|
{
|
|
|
|
|
m_state = LINKED;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LINKED:
|
|
|
|
|
{
|
|
|
|
|
NetworkString ns;
|
|
|
|
|
// 1 (connection request), 4 (size of id), global id
|
2013-08-18 22:59:23 +00:00
|
|
|
|
ns.ai8(1).ai8(4).ai32(Online::CurrentUser::get()->getID());
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_listener->sendMessage(this, ns);
|
|
|
|
|
m_state = REQUESTING_CONNECTION;
|
2013-08-21 19:04:46 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
case REQUESTING_CONNECTION:
|
|
|
|
|
break;
|
|
|
|
|
case CONNECTED:
|
|
|
|
|
break;
|
2013-07-26 23:47:43 +00:00
|
|
|
|
case KART_SELECTION:
|
2013-07-27 23:13:03 +00:00
|
|
|
|
{
|
|
|
|
|
NetworkKartSelectionScreen* screen = NetworkKartSelectionScreen::getInstance();
|
|
|
|
|
StateManager::get()->pushScreen(screen);
|
2013-07-26 23:47:43 +00:00
|
|
|
|
m_state = SELECTING_KARTS;
|
2013-08-21 19:04:46 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2013-07-26 12:49:05 +00:00
|
|
|
|
case SELECTING_KARTS:
|
|
|
|
|
break;
|
|
|
|
|
case PLAYING:
|
2013-08-01 01:03:07 +00:00
|
|
|
|
{
|
|
|
|
|
if (NetworkWorld::getInstance<NetworkWorld>()->isRaceOver()) // race is now over, kill race protocols and return to connected state
|
|
|
|
|
{
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Game finished.");
|
2013-08-21 13:54:50 +00:00
|
|
|
|
m_state = RACE_FINISHED;
|
2013-08-01 01:03:07 +00:00
|
|
|
|
}
|
2013-08-21 19:04:46 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2013-08-21 13:54:50 +00:00
|
|
|
|
case RACE_FINISHED:
|
|
|
|
|
break;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
case DONE:
|
2013-07-18 15:58:46 +00:00
|
|
|
|
m_state = EXITING;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_listener->requestTerminate(this);
|
|
|
|
|
break;
|
2013-07-18 17:56:32 +00:00
|
|
|
|
case EXITING:
|
|
|
|
|
break;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when a new player is connected to the server
|
|
|
|
|
* \param event : Event providing the information.
|
2013-07-10 22:46:23 +00:00
|
|
|
|
*
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 5 6 7
|
|
|
|
|
* ------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 |
|
|
|
|
|
* Data | 4 | player global id | 1 | 0 <= race id < 16 |
|
|
|
|
|
* ------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::newPlayer(Event* event)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (data.size() != 7 || data[0] != 4 || data[5] != 1) // 7 bytes remains now
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "A message notifying a new player wasn't formated as expected.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint32_t global_id = data.gui32(1);
|
|
|
|
|
uint8_t race_id = data.gui8(6);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
2013-08-18 22:59:23 +00:00
|
|
|
|
if (global_id == Online::CurrentUser::get()->getID())
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "The server notified me that i'm a new player in the room (not normal).");
|
|
|
|
|
}
|
2013-07-11 15:35:31 +00:00
|
|
|
|
else if (m_setup->getProfile(race_id) == NULL || m_setup->getProfile(global_id) == NULL)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::verbose("ClientLobbyRoomProtocol", "New player connected.");
|
2013-07-11 15:35:31 +00:00
|
|
|
|
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
|
|
|
|
|
profile->kart_name = "";
|
|
|
|
|
profile->race_id = race_id;
|
2013-08-18 22:59:23 +00:00
|
|
|
|
profile->user_profile = new Online::Profile(global_id, "");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_setup->addPlayer(profile);
|
|
|
|
|
}
|
2013-07-11 15:35:31 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "One of the player notified in the list is myself.");
|
|
|
|
|
}
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when a new player is disconnected
|
|
|
|
|
* \param event : Event providing the information.
|
2013-07-10 22:46:23 +00:00
|
|
|
|
*
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 2
|
|
|
|
|
* -------------------------
|
|
|
|
|
* Size | 1 | 1 |
|
|
|
|
|
* Data | 1 | 0 <= race id < 16 |
|
|
|
|
|
* -------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::disconnectedPlayer(Event* event)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (data.size() != 2 || data[0] != 1)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "A message notifying a new player wasn't formated as expected.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint8_t id = data[1];
|
2013-07-10 20:15:17 +00:00
|
|
|
|
if (m_setup->removePlayer(id))
|
|
|
|
|
{
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Peer removed successfully.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "The disconnected peer wasn't known.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when the server accepts the connection.
|
|
|
|
|
* \param event : Event providing the information.
|
2013-07-10 22:46:23 +00:00
|
|
|
|
*
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 2 3 7 8 12
|
|
|
|
|
* ----------------------------------------------------------
|
|
|
|
|
* Size | 1 | 1 | 1 | 4 | 1 | 4 |
|
|
|
|
|
* Data | 1 | 0 <= race id < 16 | 4 | priv token | 4 | global id |
|
|
|
|
|
* ----------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (data.size() < 12 || data[0] != 1 || data[2] != 4 || data[7] != 4) // 12 bytes remains now
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "A message notifying an accepted connection wasn't formated as expected.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-07-11 13:30:16 +00:00
|
|
|
|
STKPeer* peer = *(event->peer);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint32_t global_id = data.gui32(8);
|
2013-08-18 22:59:23 +00:00
|
|
|
|
if (global_id == Online::CurrentUser::get()->getID())
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "The server accepted the connection.");
|
2013-07-12 14:08:33 +00:00
|
|
|
|
|
|
|
|
|
// self profile
|
|
|
|
|
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
|
|
|
|
|
profile->kart_name = "";
|
2013-08-01 19:49:57 +00:00
|
|
|
|
profile->race_id = data.gui8(1);
|
2013-08-18 22:59:23 +00:00
|
|
|
|
profile->user_profile = Online::CurrentUser::get()->getProfile();
|
2013-07-12 14:08:33 +00:00
|
|
|
|
m_setup->addPlayer(profile);
|
|
|
|
|
// connection token
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint32_t token = data.gui32(3);
|
2013-07-12 14:08:33 +00:00
|
|
|
|
peer->setClientServerToken(token);
|
2013-07-11 14:05:18 +00:00
|
|
|
|
// add all players
|
2013-08-01 19:49:57 +00:00
|
|
|
|
data.removeFront(12); // remove the 12 first bytes
|
|
|
|
|
int remaining = data.size();
|
2013-07-11 14:05:18 +00:00
|
|
|
|
if (remaining%7 != 0)
|
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "ConnectionAccepted : Error in the server list");
|
|
|
|
|
}
|
|
|
|
|
remaining /= 7;
|
|
|
|
|
for (int i = 0; i < remaining; i++)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
if (data[0] != 1 || data[2] != 4)
|
2013-07-11 14:05:18 +00:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Bad format in players list.");
|
2013-09-21 20:56:39 +00:00
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint8_t race_id = data[1];
|
|
|
|
|
uint32_t global_id = data.gui32(3);
|
2013-08-18 22:59:23 +00:00
|
|
|
|
Online::Profile* new_user = new Online::Profile(global_id, "");
|
2013-09-21 20:56:39 +00:00
|
|
|
|
|
2013-07-11 14:05:18 +00:00
|
|
|
|
NetworkPlayerProfile* profile2 = new NetworkPlayerProfile();
|
|
|
|
|
profile2->race_id = race_id;
|
|
|
|
|
profile2->user_profile = new_user;
|
|
|
|
|
profile2->kart_name = "";
|
|
|
|
|
m_setup->addPlayer(profile2);
|
2013-08-01 19:49:57 +00:00
|
|
|
|
data.removeFront(7);
|
2013-07-11 14:05:18 +00:00
|
|
|
|
}
|
2013-07-12 14:08:33 +00:00
|
|
|
|
|
2013-07-11 14:05:18 +00:00
|
|
|
|
// add self
|
2013-07-11 13:30:16 +00:00
|
|
|
|
m_server = *(event->peer);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_state = CONNECTED;
|
|
|
|
|
}
|
2013-07-11 13:39:36 +00:00
|
|
|
|
else
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Failure during the connection acceptation process.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when the server refuses the connection.
|
|
|
|
|
* \param event : Event providing the information.
|
2013-07-10 22:46:23 +00:00
|
|
|
|
*
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 2
|
|
|
|
|
* --------------------
|
|
|
|
|
* Size | 1 | 1 |
|
|
|
|
|
* Data | 1 | refusal code |
|
|
|
|
|
* --------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::connectionRefused(Event* event)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (data.size() != 2 || data[0] != 1) // 2 bytes remains now
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "A message notifying a refused connection wasn't formated as expected.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
switch (data[1]) // the second byte
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Connection refused : too many players.");
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Connection refused : banned.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Connection refused.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when the server refuses the kart selection request.
|
|
|
|
|
* \param event : Event providing the information.
|
2013-07-10 22:46:23 +00:00
|
|
|
|
*
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 2
|
|
|
|
|
* --------------------
|
|
|
|
|
* Size | 1 | 1 |
|
|
|
|
|
* Data | 1 | refusal code |
|
|
|
|
|
* --------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::kartSelectionRefused(Event* event)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (data.size() != 2 || data[0] != 1)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "A message notifying a refused kart selection wasn't formated as expected.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
switch (data[1]) // the error code
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Kart selection refused : already taken.");
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Kart selection refused : not available.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Kart selection refused.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2013-07-10 22:46:23 +00:00
|
|
|
|
/*! \brief Called when the server tells to update a player's kart.
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* \param event : Event providing the information.
|
2013-07-10 22:46:23 +00:00
|
|
|
|
*
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* Format of the data :
|
2013-07-10 22:46:23 +00:00
|
|
|
|
* Byte 0 1 2 3 N+3
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* ------------------------------------------------
|
|
|
|
|
* Size | 1 | 1 | 1 | N |
|
|
|
|
|
* Data | 1 | race id | N (kart name size) | kart name |
|
|
|
|
|
* ------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::kartSelectionUpdate(Event* event)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (data.size() < 3 || data[0] != 1)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2013-07-10 22:46:23 +00:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "A message notifying a kart selection update wasn't formated as expected.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint8_t player_id = data[1];
|
|
|
|
|
uint8_t kart_name_length = data[2];
|
|
|
|
|
std::string kart_name = data.getString(3, kart_name_length);
|
|
|
|
|
if (kart_name.size() != kart_name_length)
|
2013-07-10 22:46:23 +00:00
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Kart names sizes differ: told: %d, real: %d.", kart_name_length, kart_name.size());
|
2013-07-10 22:46:23 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
if (!m_setup->isKartAvailable(kart_name))
|
2013-07-10 22:46:23 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "The updated kart is taken already.");
|
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
m_setup->setPlayerKart(player_id, kart_name);
|
|
|
|
|
NetworkKartSelectionScreen::getInstance()->playerSelected(player_id, kart_name);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
2013-07-10 22:46:23 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-07-14 21:19:22 +00:00
|
|
|
|
|
|
|
|
|
/*! \brief Called when the race needs to be started.
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 5
|
|
|
|
|
* -------------
|
|
|
|
|
* Size | 1 | 4 |
|
|
|
|
|
* Data | 4 | token |
|
|
|
|
|
* -------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::startGame(Event* event)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (data.size() < 5 || data[0] != 4)
|
2013-07-14 21:19:22 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "A message notifying a kart "
|
2013-08-21 19:04:46 +00:00
|
|
|
|
"selection update wasn't formated as expected.");
|
2013-07-14 21:19:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint8_t token = data.gui32(1);
|
2013-07-14 21:19:22 +00:00
|
|
|
|
if (token == NetworkManager::getInstance()->getPeers()[0]->getClientServerToken())
|
|
|
|
|
{
|
2013-07-26 12:49:05 +00:00
|
|
|
|
m_state = PLAYING;
|
2013-07-14 21:19:22 +00:00
|
|
|
|
m_listener->requestStart(new StartGameProtocol(m_setup));
|
2013-07-14 22:54:45 +00:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Starting new game");
|
2013-07-14 21:19:22 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Bad token when starting game");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-07-26 12:49:05 +00:00
|
|
|
|
|
|
|
|
|
/*! \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)
|
|
|
|
|
{
|
2013-08-01 19:49:57 +00:00
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (data.size() < 5 || data[0] != 4)
|
2013-07-26 12:49:05 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "A message notifying a kart "
|
2013-08-21 19:04:46 +00:00
|
|
|
|
"selection update wasn't formated as expected.");
|
2013-07-26 12:49:05 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint8_t token = data.gui32(1);
|
2013-07-26 12:49:05 +00:00
|
|
|
|
if (token == NetworkManager::getInstance()->getPeers()[0]->getClientServerToken())
|
|
|
|
|
{
|
2013-07-26 23:47:43 +00:00
|
|
|
|
m_state = KART_SELECTION;
|
2013-07-26 12:49:05 +00:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Kart selection starts now");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Bad token");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-08-15 12:35:23 +00:00
|
|
|
|
|
|
|
|
|
/*! \brief Called when all karts have finished the race.
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
2013-08-21 13:54:50 +00:00
|
|
|
|
* Byte 0 1 5 6 7 8 9
|
|
|
|
|
* ---------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 | 1 | 1 | |
|
|
|
|
|
* Data | 4 | token | 1 | Kart 1 ID | 1 | kart id 2 | ... |
|
|
|
|
|
* ---------------------------------------------------
|
2013-08-15 12:35:23 +00:00
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::raceFinished(Event* event)
|
|
|
|
|
{
|
|
|
|
|
if (event->data().size() < 5)
|
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Not enough data provided.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if ((*event->peer)->getClientServerToken() != data.gui32(1))
|
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Bad token");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
data.removeFront(5);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Server notified that the race is finished.");
|
|
|
|
|
|
|
|
|
|
// stop race protocols
|
|
|
|
|
Protocol* protocol = NULL;
|
|
|
|
|
protocol = m_listener->getProtocol(PROTOCOL_CONTROLLER_EVENTS);
|
|
|
|
|
if (protocol)
|
|
|
|
|
m_listener->requestTerminate(protocol);
|
|
|
|
|
else
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "No controller events protocol registered.");
|
|
|
|
|
|
|
|
|
|
protocol = m_listener->getProtocol(PROTOCOL_KART_UPDATE);
|
|
|
|
|
if (protocol)
|
|
|
|
|
m_listener->requestTerminate(protocol);
|
|
|
|
|
else
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "No kart update protocol registered.");
|
|
|
|
|
|
|
|
|
|
protocol = m_listener->getProtocol(PROTOCOL_GAME_EVENTS);
|
|
|
|
|
if (protocol)
|
|
|
|
|
m_listener->requestTerminate(protocol);
|
|
|
|
|
else
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "No game events protocol registered.");
|
|
|
|
|
|
|
|
|
|
// finish the race
|
2013-08-15 12:35:23 +00:00
|
|
|
|
WorldWithRank* ranked_world = (WorldWithRank*)(World::getWorld());
|
2013-08-21 19:04:46 +00:00
|
|
|
|
ranked_world->beginSetKartPositions();
|
|
|
|
|
ranked_world->setPhase(WorldStatus::RESULT_DISPLAY_PHASE);
|
2013-08-21 13:54:50 +00:00
|
|
|
|
int position = 1;
|
2013-08-15 12:35:23 +00:00
|
|
|
|
while(data.size()>0)
|
|
|
|
|
{
|
|
|
|
|
if (data.size() < 2)
|
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Incomplete field.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-21 13:54:50 +00:00
|
|
|
|
if (data[0] != 1)
|
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Badly formatted field.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uint8_t kart_id = data[1];
|
2013-08-15 12:35:23 +00:00
|
|
|
|
ranked_world->setKartPosition(kart_id,position);
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Kart %d has finished #%d", kart_id, position);
|
|
|
|
|
data.removeFront(2);
|
2013-08-21 13:54:50 +00:00
|
|
|
|
position++;
|
2013-08-15 12:35:23 +00:00
|
|
|
|
}
|
2013-08-21 19:04:46 +00:00
|
|
|
|
ranked_world->endSetKartPositions();
|
2013-08-21 13:54:50 +00:00
|
|
|
|
m_state = RACE_FINISHED;
|
2013-08-15 12:35:23 +00:00
|
|
|
|
ranked_world->terminateRace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
|
|
|
|
/*! \brief Called when a player votes for a major race mode.
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 5 6 7 8 9
|
|
|
|
|
* --------------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 | 1 | 1 |
|
|
|
|
|
* Data | 4 | priv token | 1 | player id | 1 | major mode vote |
|
|
|
|
|
* --------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::playerMajorVote(Event* event)
|
|
|
|
|
{
|
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (!checkDataSizeAndToken(event, 9))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 5, 1))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 7, 1))
|
|
|
|
|
return;
|
|
|
|
|
m_setup->getRaceConfig()->setPlayerMajorVote(data[6], data[8]);
|
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when a player votes for the number of races in a GP.
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 5 6 7 8 9
|
|
|
|
|
* ----------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 | 1 | 1 |
|
|
|
|
|
* Data | 4 | priv token | 1 | player id | 1 | races count |
|
|
|
|
|
* ----------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::playerRaceCountVote(Event* event)
|
|
|
|
|
{
|
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (!checkDataSizeAndToken(event, 9))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 5, 1))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 7, 1))
|
|
|
|
|
return;
|
|
|
|
|
m_setup->getRaceConfig()->setPlayerRaceCountVote(data[6], data[8]);
|
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when a player votes for a minor race mode.
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 5 6 7 8 9
|
|
|
|
|
* --------------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 | 1 | 1 |
|
|
|
|
|
* Data | 4 | priv token | 1 | player id | 1 | minor mode vote |
|
|
|
|
|
* --------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::playerMinorVote(Event* event)
|
|
|
|
|
{
|
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (!checkDataSizeAndToken(event, 9))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 5, 1))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 7, 1))
|
|
|
|
|
return;
|
|
|
|
|
m_setup->getRaceConfig()->setPlayerMinorVote(data[6], data[8]);
|
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when a player votes for a track.
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 5 6 7 8 N+8 N+9 N+10
|
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 | 1 | N | 1 | 1 |
|
|
|
|
|
* Data | 4 | priv token | 1 | player id | N | track name | 1 | track number (gp) |
|
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::playerTrackVote(Event* event)
|
|
|
|
|
{
|
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (!checkDataSizeAndToken(event, 10))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 5, 1))
|
|
|
|
|
return;
|
|
|
|
|
int N = data[7];
|
|
|
|
|
std::string track_name = data.gs(8, N);
|
|
|
|
|
if (!isByteCorrect(event, N+8, 1))
|
|
|
|
|
return;
|
|
|
|
|
m_setup->getRaceConfig()->setPlayerTrackVote(data[6], track_name, data[N+9]);
|
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when a player votes for the reverse mode of a race
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 5 6 7 8 9 10 11
|
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 | 1 | 1 | 1 | 1 |
|
|
|
|
|
* Data | 4 | priv token | 1 | player id | 1 | reversed | 1 | track number (gp) |
|
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::playerReversedVote(Event* event)
|
|
|
|
|
{
|
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (!checkDataSizeAndToken(event, 11))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 5, 1))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 7, 1))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 9, 1))
|
|
|
|
|
return;
|
2013-10-21 04:32:05 +00:00
|
|
|
|
m_setup->getRaceConfig()->setPlayerReversedVote(data[6], data[8]!=0, data[10]);
|
2013-09-22 20:40:14 +00:00
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when a player votes for a major race mode.
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
|
|
|
|
* Byte 0 1 5 6 7 8 9 10 11
|
|
|
|
|
* ---------------------------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 | 1 | 1 | 1 | 1 |
|
|
|
|
|
* Data | 4 | priv token | 1 | player id | 1 | laps | 1 | track number (gp) |
|
|
|
|
|
* ---------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::playerLapsVote(Event* event)
|
|
|
|
|
{
|
|
|
|
|
NetworkString data = event->data();
|
|
|
|
|
if (!checkDataSizeAndToken(event, 9))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 5, 1))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 7, 1))
|
|
|
|
|
return;
|
|
|
|
|
m_setup->getRaceConfig()->setPlayerLapsVote(data[6], data[8], data[10]);
|
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|