2013-07-11 12:03:28 +00:00
|
|
|
|
//
|
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2015-03-30 11:31:42 +11:00
|
|
|
|
// Copyright (C) 2013-2015 SuperTuxKart-Team
|
2013-07-11 12:03:28 +00:00
|
|
|
|
//
|
|
|
|
|
// 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"
|
|
|
|
|
|
2014-04-10 16:32:58 +10:00
|
|
|
|
#include "config/player_manager.hpp"
|
2014-03-07 11:02:07 +11:00
|
|
|
|
#include "modes/world_with_rank.hpp"
|
2015-10-21 17:39:53 +11:00
|
|
|
|
#include "network/event.hpp"
|
2015-11-26 07:41:37 +11:00
|
|
|
|
#include "network/network_player_profile.hpp"
|
2013-08-01 01:03:07 +00:00
|
|
|
|
#include "network/network_world.hpp"
|
2014-03-07 11:02:07 +11:00
|
|
|
|
#include "network/protocols/start_game_protocol.hpp"
|
2015-10-27 08:23:59 +11:00
|
|
|
|
#include "network/protocol_manager.hpp"
|
|
|
|
|
#include "network/stk_host.hpp"
|
|
|
|
|
#include "network/stk_peer.hpp"
|
2014-03-07 11:02:07 +11:00
|
|
|
|
#include "online/online_profile.hpp"
|
2015-11-27 23:05:05 +11:00
|
|
|
|
#include "states_screens/networking_lobby.hpp"
|
2013-07-26 12:49:05 +00:00
|
|
|
|
#include "states_screens/network_kart_selection.hpp"
|
2014-03-07 11:02:07 +11:00
|
|
|
|
#include "states_screens/state_manager.hpp"
|
2013-07-10 20:15:17 +00:00
|
|
|
|
#include "utils/log.hpp"
|
|
|
|
|
|
2015-11-20 17:02:47 +11:00
|
|
|
|
ClientLobbyRoomProtocol::
|
|
|
|
|
ClientLobbyRoomProtocol(const TransportAddress& server_address)
|
2015-10-12 21:37:22 +11:00
|
|
|
|
: LobbyRoomProtocol(NULL)
|
2013-07-10 22:46:23 +00:00
|
|
|
|
{
|
2015-10-16 23:55:54 +11:00
|
|
|
|
m_server_address.copy(server_address);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_server = NULL;
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // ClientLobbyRoomProtocol
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientLobbyRoomProtocol::~ClientLobbyRoomProtocol()
|
|
|
|
|
{
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // ClientLobbyRoomProtocol
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::setup()
|
|
|
|
|
{
|
2015-10-25 00:19:30 +11:00
|
|
|
|
m_setup = STKHost::get()->setupNewGame(); // create a new setup
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_state = NONE;
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // setup
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2015-11-19 14:20:10 +11:00
|
|
|
|
void ClientLobbyRoomProtocol::requestKartSelection(const std::string &kart_name)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-10-16 00:03:23 +11:00
|
|
|
|
NetworkString request(6+1+kart_name.size());
|
2015-11-20 16:41:54 +11:00
|
|
|
|
// size_token (4), token, size kart name, kart name
|
|
|
|
|
request.ai8(LE_KART_SELECTION).ai8(4).ai32(m_server->getClientServerToken())
|
2015-11-27 08:55:21 +11:00
|
|
|
|
.encodeString(kart_name);
|
2015-10-24 12:39:17 +11:00
|
|
|
|
sendMessage(request, true);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // requestKartSelection
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteMajor(uint8_t major)
|
|
|
|
|
{
|
2015-10-16 00:03:23 +11:00
|
|
|
|
NetworkString request(8);
|
2015-11-20 16:41:54 +11:00
|
|
|
|
// size_token (4), token, size major(1),major
|
|
|
|
|
request.ai8(LE_VOTE_MAJOR).ai8(4)
|
|
|
|
|
.ai32(m_server->getClientServerToken()).ai8(1).ai8(major);
|
2015-10-24 12:39:17 +11:00
|
|
|
|
sendMessage(request, true);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // voteMajor
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteRaceCount(uint8_t count)
|
|
|
|
|
{
|
2015-10-16 00:03:23 +11:00
|
|
|
|
NetworkString request(8);
|
2015-11-20 16:41:54 +11:00
|
|
|
|
// size_token (4), token, size race count(1), count
|
|
|
|
|
request.ai8(LE_VOTE_RACE_COUNT).ai8(4)
|
|
|
|
|
.ai32(m_server->getClientServerToken()).ai8(1).ai8(count);
|
2015-10-24 12:39:17 +11:00
|
|
|
|
sendMessage(request, true);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // voteRaceCount
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteMinor(uint8_t minor)
|
|
|
|
|
{
|
2015-10-16 00:03:23 +11:00
|
|
|
|
NetworkString request(8);
|
2015-11-20 16:41:54 +11:00
|
|
|
|
// size_token (4), token, size minor(1),minor
|
|
|
|
|
request.ai8(LE_VOTE_MINOR).ai8(4).ai32(m_server->getClientServerToken())
|
2015-11-19 14:20:10 +11:00
|
|
|
|
.ai8(1).ai8(minor);
|
2015-10-24 12:39:17 +11:00
|
|
|
|
sendMessage(request, true);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // voteMinor
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2015-11-19 14:20:10 +11:00
|
|
|
|
void ClientLobbyRoomProtocol::voteTrack(const std::string &track,
|
|
|
|
|
uint8_t track_nb)
|
2013-09-22 20:40:14 +00:00
|
|
|
|
{
|
2015-10-16 00:03:23 +11:00
|
|
|
|
NetworkString request(8+1+track.size());
|
2015-11-20 16:41:54 +11:00
|
|
|
|
// size_token (4), token, size track, track, size #track, #track
|
|
|
|
|
request.ai8(LE_VOTE_TRACK).ai8(4).ai32(m_server->getClientServerToken())
|
2015-11-27 08:55:21 +11:00
|
|
|
|
.encodeString(track).ai8(1).ai8(track_nb);
|
2015-10-24 12:39:17 +11:00
|
|
|
|
sendMessage(request, true);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // voteTrack
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteReversed(bool reversed, uint8_t track_nb)
|
|
|
|
|
{
|
2015-10-16 00:03:23 +11:00
|
|
|
|
NetworkString request(9);
|
2015-11-20 16:41:54 +11:00
|
|
|
|
// size_token (4), token, size reversed(1),reversed, size #track, #track
|
|
|
|
|
request.ai8(LE_VOTE_REVERSE).ai8(4).ai32(m_server->getClientServerToken())
|
|
|
|
|
.ai8(1).ai8(reversed).ai8(1).ai8(track_nb);
|
2015-10-24 12:39:17 +11:00
|
|
|
|
sendMessage(request, true);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // voteReversed
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::voteLaps(uint8_t laps, uint8_t track_nb)
|
|
|
|
|
{
|
2015-10-16 00:03:23 +11:00
|
|
|
|
NetworkString request(10);
|
2015-11-20 16:41:54 +11:00
|
|
|
|
// size_token (4), token, size laps(1),laps, size #track, #track
|
2015-11-20 17:02:47 +11:00
|
|
|
|
request.ai8(LE_VOTE_LAPS).ai8(4).ai32(m_server->getClientServerToken())
|
|
|
|
|
.ai8(1).ai8(laps).ai8(1).ai8(track_nb);
|
2015-10-24 12:39:17 +11:00
|
|
|
|
sendMessage(request, true);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // voteLaps
|
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();
|
2015-10-16 00:52:28 +11:00
|
|
|
|
m_server_address.clear();
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // leave
|
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
|
2015-10-21 08:07:00 +11:00
|
|
|
|
if (event->getType() == EVENT_TYPE_MESSAGE)
|
2013-08-01 19:55:09 +00:00
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:55:09 +00:00
|
|
|
|
assert(data.size()); // assert that data isn't empty
|
|
|
|
|
uint8_t message_type = data[0];
|
2015-11-20 16:41:54 +11:00
|
|
|
|
if (message_type != LE_KART_SELECTION_UPDATE &&
|
|
|
|
|
message_type != LE_RACE_FINISHED )
|
2013-08-21 19:04:46 +00:00
|
|
|
|
return false; // don't treat the event
|
2013-08-01 19:55:09 +00:00
|
|
|
|
|
|
|
|
|
event->removeFront(1);
|
2015-11-19 14:20:10 +11:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Synchronous message of type %d",
|
|
|
|
|
message_type);
|
2015-11-20 16:41:54 +11:00
|
|
|
|
if (message_type == LE_KART_SELECTION_UPDATE) // kart selection update
|
2013-08-01 19:55:09 +00:00
|
|
|
|
kartSelectionUpdate(event);
|
2015-11-20 16:41:54 +11:00
|
|
|
|
else if (message_type == LE_RACE_FINISHED) // end of race
|
2013-08-21 19:04:46 +00:00
|
|
|
|
raceFinished(event);
|
2013-08-01 19:55:09 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
return false;
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // notifyEvent
|
2013-08-01 19:49:57 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
assert(m_setup); // assert that the setup exists
|
2015-10-21 08:07:00 +11:00
|
|
|
|
if (event->getType() == EVENT_TYPE_MESSAGE)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:49:57 +00:00
|
|
|
|
assert(data.size()); // assert that data isn't empty
|
|
|
|
|
uint8_t message_type = data[0];
|
2015-11-21 10:39:56 +11:00
|
|
|
|
if (message_type == LE_KART_SELECTION_UPDATE ||
|
|
|
|
|
message_type == LE_RACE_FINISHED )
|
2013-08-21 19:04:46 +00:00
|
|
|
|
return false; // don't treat the event
|
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
event->removeFront(1);
|
2015-11-19 14:20:10 +11:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Asynchronous message of type %d",
|
|
|
|
|
message_type);
|
2015-11-21 10:39:56 +11:00
|
|
|
|
switch(message_type)
|
|
|
|
|
{
|
|
|
|
|
case LE_NEW_PLAYER_CONNECTED: newPlayer(event); break;
|
|
|
|
|
case LE_PLAYER_DISCONNECTED : disconnectedPlayer(event); break;
|
|
|
|
|
case LE_START_RACE: startGame(event); break;
|
|
|
|
|
case LE_START_SELECTION: startSelection(event); break;
|
|
|
|
|
case LE_CONNECTION_REFUSED: connectionRefused(event); break;
|
|
|
|
|
case LE_CONNECTION_ACCEPTED: connectionAccepted(event); break;
|
|
|
|
|
case LE_KART_SELECTION_REFUSED: kartSelectionRefused(event); break;
|
|
|
|
|
case LE_VOTE_MAJOR : playerMajorVote(event); break;
|
|
|
|
|
case LE_VOTE_RACE_COUNT: playerRaceCountVote(event); break;
|
|
|
|
|
case LE_VOTE_MINOR: playerMinorVote(event); break;
|
|
|
|
|
case LE_VOTE_TRACK: playerTrackVote(event); break;
|
|
|
|
|
case LE_VOTE_REVERSE: playerReversedVote(event); break;
|
|
|
|
|
case LE_VOTE_LAPS: playerLapsVote(event); break;
|
|
|
|
|
} // switch
|
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
|
2015-10-21 08:07:00 +11:00
|
|
|
|
else if (event->getType() == EVENT_TYPE_CONNECTED)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2013-08-01 19:55:09 +00:00
|
|
|
|
return true;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
} // connection
|
2015-11-19 14:20:10 +11:00
|
|
|
|
else if (event->getType() == EVENT_TYPE_DISCONNECTED)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-19 14:20:10 +11:00
|
|
|
|
// means we left essentially
|
2015-10-26 08:33:07 +11:00
|
|
|
|
STKHost::get()->removePeer(m_server);
|
2013-07-29 23:43:28 +00:00
|
|
|
|
m_server = NULL;
|
2015-10-26 08:33:07 +11:00
|
|
|
|
STKHost::get()->deleteAllPeers();
|
2015-10-24 12:39:17 +11:00
|
|
|
|
ProtocolManager::getInstance()->requestTerminate(this);
|
2015-10-26 08:33:07 +11:00
|
|
|
|
STKHost::get()->reset();
|
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;
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // notifyEventAsynchronous
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void ClientLobbyRoomProtocol::update()
|
|
|
|
|
{
|
|
|
|
|
switch (m_state)
|
|
|
|
|
{
|
|
|
|
|
case NONE:
|
2015-10-26 18:31:32 +11:00
|
|
|
|
if (STKHost::get()->isConnectedTo(m_server_address))
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
m_state = LINKED;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LINKED:
|
|
|
|
|
{
|
2015-11-27 08:24:02 +11:00
|
|
|
|
core::stringw name;
|
|
|
|
|
if(PlayerManager::getCurrentOnlineState()==PlayerProfile::OS_SIGNED_IN)
|
|
|
|
|
name = PlayerManager::getCurrentOnlineUserName();
|
|
|
|
|
else
|
|
|
|
|
name = PlayerManager::getCurrentPlayer()->getName();
|
|
|
|
|
|
|
|
|
|
std::string name_u8 = StringUtils::wideToUtf8(name);
|
|
|
|
|
NetworkString ns(6+1+name_u8.size());
|
2015-11-20 16:41:54 +11:00
|
|
|
|
// 4 (size of id), global id
|
|
|
|
|
ns.ai8(LE_CONNECTION_REQUESTED).ai8(4)
|
2015-11-27 08:24:02 +11:00
|
|
|
|
.addUInt32(PlayerManager::getCurrentOnlineId())
|
|
|
|
|
.encodeString(name);
|
2015-10-24 12:39:17 +11:00
|
|
|
|
sendMessage(ns);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
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
|
|
|
|
{
|
2015-11-19 14:20:10 +11:00
|
|
|
|
NetworkKartSelectionScreen* screen =
|
|
|
|
|
NetworkKartSelectionScreen::getInstance();
|
2014-09-23 16:43:50 +10:00
|
|
|
|
screen->push();
|
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
|
|
|
|
{
|
2015-11-19 14:20:10 +11:00
|
|
|
|
// race is now over, kill race protocols and return to connected state
|
|
|
|
|
if (NetworkWorld::getInstance<NetworkWorld>()->isRaceOver())
|
2013-08-01 01:03:07 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2015-10-24 12:39:17 +11:00
|
|
|
|
ProtocolManager::getInstance()->requestTerminate(this);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
break;
|
2013-07-18 17:56:32 +00:00
|
|
|
|
case EXITING:
|
|
|
|
|
break;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // update
|
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 :
|
2015-11-27 08:24:02 +11:00
|
|
|
|
* Byte 0 1 5 6 7 8
|
|
|
|
|
* -------------------------------------------------------------------
|
|
|
|
|
* Size | 1 | 4 | 1 | 1 | 1 | |
|
|
|
|
|
* Data | 4 | player global id | 1 | 0 <= race id < 16 | len | player name|
|
|
|
|
|
* -------------------------------------------------------------------
|
2013-07-10 20:15:17 +00:00
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::newPlayer(Event* event)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:49:57 +00:00
|
|
|
|
if (data.size() != 7 || data[0] != 4 || data[5] != 1) // 7 bytes remains now
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"A message notifying a new player wasn't formated "
|
|
|
|
|
"as expected.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint32_t global_id = data.gui32(1);
|
2015-11-26 07:41:37 +11:00
|
|
|
|
uint8_t player_id = data.gui8(6);
|
2015-11-27 08:55:21 +11:00
|
|
|
|
|
|
|
|
|
core::stringw name;
|
|
|
|
|
data.decodeStringW(7, &name);
|
2014-04-11 16:06:51 +10:00
|
|
|
|
if (global_id == PlayerManager::getCurrentOnlineId())
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"The server notified me that I'm a new player in the "
|
|
|
|
|
"room (not normal).");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
2015-11-26 07:41:37 +11:00
|
|
|
|
else if (m_setup->getProfile(player_id) == NULL ||
|
2015-11-20 17:02:47 +11:00
|
|
|
|
m_setup->getProfile(global_id) == NULL)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::verbose("ClientLobbyRoomProtocol", "New player connected.");
|
2015-11-27 08:24:02 +11:00
|
|
|
|
NetworkPlayerProfile* profile = new NetworkPlayerProfile(player_id, name);
|
2015-11-26 07:41:37 +11:00
|
|
|
|
profile->setPlayerID(player_id);
|
|
|
|
|
// FIXME: memory leak??
|
|
|
|
|
profile->setOnlineProfile(new Online::OnlineProfile(global_id, ""));
|
2013-07-10 20:15:17 +00:00
|
|
|
|
m_setup->addPlayer(profile);
|
2015-11-27 23:05:05 +11:00
|
|
|
|
NetworkingLobby::getInstance()->addPlayer(profile);
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
2013-07-11 15:35:31 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"One of the player notified in the list is myself.");
|
2013-07-11 15:35:31 +00:00
|
|
|
|
}
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // newPlayer
|
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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:49:57 +00:00
|
|
|
|
if (data.size() != 2 || data[0] != 1)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"A message notifying a new player wasn't formated "
|
|
|
|
|
"as expected.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-11-26 07:41:37 +11:00
|
|
|
|
if (m_setup->removePlayer(event->getPeer()->getPlayerProfile()))
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Peer removed successfully.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"The disconnected peer wasn't known.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
}
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // disconnectedPlayer
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \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 |
|
2015-11-27 08:24:02 +11:00
|
|
|
|
* Data | 1 | 0 <= race id < 16 | 4 | priv token | 4 | global id | playernames*
|
2013-07-10 20:15:17 +00:00
|
|
|
|
* ----------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
NetworkString &data = event->data();
|
2015-11-27 08:24:02 +11:00
|
|
|
|
// At least 12 bytes should remain now
|
2015-11-20 17:02:47 +11:00
|
|
|
|
if (data.size() < 12 || data[0] != 1 || data[2] != 4 || data[7] != 4)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"A message notifying an accepted connection wasn't "
|
|
|
|
|
"formated as expected.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-10-21 08:11:35 +11:00
|
|
|
|
STKPeer* peer = event->getPeer();
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
2013-08-01 19:49:57 +00:00
|
|
|
|
uint32_t global_id = data.gui32(8);
|
2015-11-27 08:24:02 +11:00
|
|
|
|
if (global_id != PlayerManager::getCurrentOnlineId())
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol",
|
2015-11-27 08:24:02 +11:00
|
|
|
|
"Failure during the connection acceptation process.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-07-12 14:08:33 +00:00
|
|
|
|
|
2015-11-27 08:24:02 +11:00
|
|
|
|
// Accepted
|
|
|
|
|
// ========
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol",
|
|
|
|
|
"The server accepted the connection.");
|
2013-07-12 14:08:33 +00:00
|
|
|
|
|
2015-11-27 08:24:02 +11:00
|
|
|
|
// self profile
|
|
|
|
|
irr::core::stringw name;
|
|
|
|
|
if (PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_IN)
|
|
|
|
|
name = PlayerManager::getCurrentOnlineUserName();
|
2013-07-11 13:39:36 +00:00
|
|
|
|
else
|
2015-11-27 08:24:02 +11:00
|
|
|
|
name = PlayerManager::getCurrentPlayer()->getName();
|
|
|
|
|
NetworkPlayerProfile* profile = new NetworkPlayerProfile(-1, name);
|
|
|
|
|
profile->setPlayerID(data.gui8(1));
|
|
|
|
|
profile->setOnlineProfile(PlayerManager::getCurrentOnlineProfile());
|
|
|
|
|
m_setup->addPlayer(profile);
|
|
|
|
|
// connection token
|
|
|
|
|
uint32_t token = data.gui32(3);
|
|
|
|
|
peer->setClientServerToken(token);
|
2015-11-27 23:05:05 +11:00
|
|
|
|
NetworkingLobby::getInstance()->addPlayer(profile);
|
|
|
|
|
|
2015-11-27 08:24:02 +11:00
|
|
|
|
|
|
|
|
|
// Add all players
|
|
|
|
|
// ===============
|
|
|
|
|
int n = 12;
|
|
|
|
|
while (n < data.size())
|
|
|
|
|
{
|
|
|
|
|
if (data[n] != 1 || data[n + 2] != 4)
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"Bad format in players list.");
|
|
|
|
|
|
|
|
|
|
uint8_t race_player_id = data[n + 1];
|
|
|
|
|
uint32_t global_id = data.gui32(n + 3);
|
|
|
|
|
irr::core::stringw name;
|
|
|
|
|
int bytes_read = data.decodeStringW(n + 7, &name);
|
|
|
|
|
// FIXME - leak?
|
|
|
|
|
Online::OnlineProfile* new_user =
|
|
|
|
|
new Online::OnlineProfile(global_id, name);
|
|
|
|
|
|
|
|
|
|
NetworkPlayerProfile* profile2 =
|
|
|
|
|
new NetworkPlayerProfile(race_player_id, name);
|
|
|
|
|
profile2->setPlayerID(race_player_id);
|
|
|
|
|
profile2->setOnlineProfile(new_user);
|
|
|
|
|
m_setup->addPlayer(profile2);
|
|
|
|
|
n += bytes_read+7;
|
2015-11-27 23:05:05 +11:00
|
|
|
|
NetworkingLobby::getInstance()->addPlayer(profile2);
|
2015-11-27 08:24:02 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add self
|
|
|
|
|
m_server = event->getPeer();
|
|
|
|
|
m_state = CONNECTED;
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // connectionAccepted
|
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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:49:57 +00:00
|
|
|
|
if (data.size() != 2 || data[0] != 1) // 2 bytes remains now
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"A message notifying a refused connection wasn't formated "
|
|
|
|
|
"as expected.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
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:
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol",
|
|
|
|
|
"Connection refused : too many players.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Connection refused : banned.");
|
|
|
|
|
break;
|
2015-11-24 07:55:58 +11:00
|
|
|
|
case 2:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Client busy.");
|
|
|
|
|
break;
|
2013-07-10 20:15:17 +00:00
|
|
|
|
default:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Connection refused.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // connectionRefused
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:49:57 +00:00
|
|
|
|
if (data.size() != 2 || data[0] != 1)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"A message notifying a refused kart selection wasn't "
|
|
|
|
|
"formated as expected.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
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:
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol",
|
|
|
|
|
"Kart selection refused : already taken.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol",
|
|
|
|
|
"Kart selection refused : not available.");
|
2013-07-10 20:15:17 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Kart selection refused.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // kartSelectionRefused
|
2013-07-10 20:15:17 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:49:57 +00:00
|
|
|
|
if (data.size() < 3 || data[0] != 1)
|
2013-07-10 20:15:17 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11: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];
|
2015-11-27 08:55:21 +11:00
|
|
|
|
std::string kart_name;
|
|
|
|
|
data.decodeString(2, &kart_name);
|
2013-08-01 19:49:57 +00:00
|
|
|
|
if (!m_setup->isKartAvailable(kart_name))
|
2013-07-10 22:46:23 +00:00
|
|
|
|
{
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"The updated kart is taken already.");
|
2013-07-10 22:46:23 +00:00
|
|
|
|
}
|
2013-08-01 19:49:57 +00:00
|
|
|
|
m_setup->setPlayerKart(player_id, kart_name);
|
2015-11-20 17:02:47 +11:00
|
|
|
|
NetworkKartSelectionScreen::getInstance()->playerSelected(player_id,
|
|
|
|
|
kart_name);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // kartSelectionUpdate
|
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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:49:57 +00:00
|
|
|
|
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);
|
2015-10-26 08:33:07 +11:00
|
|
|
|
if (token == STKHost::get()->getPeers()[0]->getClientServerToken())
|
2013-07-14 21:19:22 +00:00
|
|
|
|
{
|
2013-07-26 12:49:05 +00:00
|
|
|
|
m_state = PLAYING;
|
2015-11-20 17:02:47 +11:00
|
|
|
|
ProtocolManager::getInstance()
|
|
|
|
|
->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");
|
|
|
|
|
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // startGame
|
2013-07-14 21:19:22 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-08-01 19:49:57 +00:00
|
|
|
|
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);
|
2015-10-26 08:33:07 +11:00
|
|
|
|
if (token == STKHost::get()->getPeers()[0]->getClientServerToken())
|
2013-07-26 12:49:05 +00:00
|
|
|
|
{
|
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");
|
|
|
|
|
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // startSelection
|
2013-07-26 12:49:05 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
NetworkString &data = event->data();
|
|
|
|
|
if (data.size() < 5)
|
2013-08-15 12:35:23 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Not enough data provided.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-10-21 08:11:35 +11:00
|
|
|
|
if (event->getPeer()->getClientServerToken() != data.gui32(1))
|
2013-08-15 12:35:23 +00:00
|
|
|
|
{
|
|
|
|
|
Log::error("ClientLobbyRoomProtocol", "Bad token");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
data.removeFront(5);
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"Server notified that the race is finished.");
|
2013-08-21 19:04:46 +00:00
|
|
|
|
|
|
|
|
|
// stop race protocols
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Protocol* protocol = ProtocolManager::getInstance()
|
|
|
|
|
->getProtocol(PROTOCOL_CONTROLLER_EVENTS);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
if (protocol)
|
2015-10-24 12:39:17 +11:00
|
|
|
|
ProtocolManager::getInstance()->requestTerminate(protocol);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
else
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"No controller events protocol registered.");
|
2013-08-21 19:04:46 +00:00
|
|
|
|
|
2015-11-20 17:02:47 +11:00
|
|
|
|
protocol = ProtocolManager::getInstance()
|
|
|
|
|
->getProtocol(PROTOCOL_KART_UPDATE);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
if (protocol)
|
2015-10-24 12:39:17 +11:00
|
|
|
|
ProtocolManager::getInstance()->requestTerminate(protocol);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
else
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"No kart update protocol registered.");
|
2013-08-21 19:04:46 +00:00
|
|
|
|
|
2015-11-20 17:02:47 +11:00
|
|
|
|
protocol = ProtocolManager::getInstance()
|
|
|
|
|
->getProtocol(PROTOCOL_GAME_EVENTS);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
if (protocol)
|
2015-10-24 12:39:17 +11:00
|
|
|
|
ProtocolManager::getInstance()->requestTerminate(protocol);
|
2013-08-21 19:04:46 +00:00
|
|
|
|
else
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::error("ClientLobbyRoomProtocol",
|
|
|
|
|
"No game events protocol registered.");
|
2013-08-21 19:04:46 +00:00
|
|
|
|
|
|
|
|
|
// 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);
|
2015-11-20 17:02:47 +11:00
|
|
|
|
Log::info("ClientLobbyRoomProtocol", "Kart %d has finished #%d",
|
|
|
|
|
kart_id, position);
|
2013-08-15 12:35:23 +00:00
|
|
|
|
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();
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // raceFinished
|
2013-08-15 12:35:23 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-09-22 20:40:14 +00:00
|
|
|
|
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]);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // playerMajorVote
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
2015-10-12 21:37:22 +11:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-09-22 20:40:14 +00:00
|
|
|
|
/*! \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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-09-22 20:40:14 +00:00
|
|
|
|
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]);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // playerRaceCountVote
|
2013-09-22 20:40:14 +00:00
|
|
|
|
|
2015-10-12 21:37:22 +11:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-09-22 20:40:14 +00:00
|
|
|
|
/*! \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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-09-22 20:40:14 +00:00
|
|
|
|
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]);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // playerMinorVote
|
|
|
|
|
|
2013-09-22 20:40:14 +00:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \brief Called when a player votes for a track.
|
|
|
|
|
* \param event : Event providing the information.
|
|
|
|
|
*
|
|
|
|
|
* Format of the data :
|
2015-11-20 17:02:47 +11:00
|
|
|
|
* Byte 0 1 5 6 7 8 N+8 N+9 N+10
|
2013-09-22 20:40:14 +00:00
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
|
* 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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-09-22 20:40:14 +00:00
|
|
|
|
if (!checkDataSizeAndToken(event, 10))
|
|
|
|
|
return;
|
|
|
|
|
if (!isByteCorrect(event, 5, 1))
|
|
|
|
|
return;
|
2015-11-27 08:55:21 +11:00
|
|
|
|
std::string track_name;
|
|
|
|
|
int N = data.decodeString(7, &track_name);
|
2013-09-22 20:40:14 +00:00
|
|
|
|
if (!isByteCorrect(event, N+8, 1))
|
|
|
|
|
return;
|
2015-11-27 08:55:21 +11:00
|
|
|
|
m_setup->getRaceConfig()->setPlayerTrackVote(data[6], track_name,
|
|
|
|
|
data[N+9]);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // playerTrackVote
|
|
|
|
|
|
2013-09-22 20:40:14 +00:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*! \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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-09-22 20:40:14 +00:00
|
|
|
|
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]);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // playerReversedVote
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2015-10-22 21:43:06 +11:00
|
|
|
|
const NetworkString &data = event->data();
|
2013-09-22 20:40:14 +00:00
|
|
|
|
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]);
|
2015-10-12 21:37:22 +11:00
|
|
|
|
} // playerLapsVote
|
|
|
|
|
|
2013-09-22 20:40:14 +00:00
|
|
|
|
//-----------------------------------------------------------------------------
|