Removed all references to OnlineProfile, which makes LAN and WAN
server behave idential (and it also fixed potential memory leaks).
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
#include "input/input_device.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "online/online_profile.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "states_screens/kart_selection.hpp"
|
||||
#include <IGUIEnvironment.h>
|
||||
|
||||
@@ -34,7 +34,7 @@ using namespace GUIEngine;
|
||||
|
||||
PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent,
|
||||
StateManager::ActivePlayer* associated_player,
|
||||
Online::OnlineProfile* associated_user,
|
||||
NetworkPlayerProfile* associated_user,
|
||||
core::recti area, const int player_id,
|
||||
std::string kart_group,
|
||||
const int irrlicht_widget_id) : Widget(WTYPE_DIV)
|
||||
@@ -343,7 +343,7 @@ void PlayerKartWidget::add()
|
||||
if (m_associated_player)
|
||||
name = m_associated_player->getProfile()->getName();
|
||||
if (m_associated_user)
|
||||
name = m_associated_user->getUserName();
|
||||
name = m_associated_user->getName();
|
||||
core::stringw label = translations->fribidize(name);
|
||||
|
||||
if (m_parent_screen->m_multiplayer)
|
||||
|
||||
@@ -25,12 +25,9 @@
|
||||
#include <IGUIImage.h>
|
||||
#include <string>
|
||||
|
||||
namespace Online
|
||||
{
|
||||
class OnlineProfile;
|
||||
}
|
||||
|
||||
class KartSelectionScreen;
|
||||
class NetworkPlayerProfile;
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
@@ -69,7 +66,7 @@ namespace GUIEngine
|
||||
int m_player_id;
|
||||
|
||||
/** Network info about the user. */
|
||||
Online::OnlineProfile* m_associated_user;
|
||||
NetworkPlayerProfile* m_associated_user;
|
||||
|
||||
/** Internal name of the spinner; useful to interpret spinner events,
|
||||
* which contain the name of the activated object */
|
||||
@@ -100,7 +97,7 @@ namespace GUIEngine
|
||||
|
||||
PlayerKartWidget(KartSelectionScreen* parent,
|
||||
StateManager::ActivePlayer* associated_player,
|
||||
Online::OnlineProfile* associated_user,
|
||||
NetworkPlayerProfile* associated_user,
|
||||
core::recti area, const int player_id,
|
||||
std::string kart_group,
|
||||
const int irrlicht_idget_id=-1);
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
|
||||
GameSetup::GameSetup()
|
||||
{
|
||||
m_race_config = new RaceConfig();
|
||||
m_race_config = new RaceConfig();
|
||||
m_local_master = 0;
|
||||
} // GameSetup
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -50,9 +51,8 @@ GameSetup::~GameSetup()
|
||||
void GameSetup::addPlayer(NetworkPlayerProfile* profile)
|
||||
{
|
||||
m_players.push_back(profile);
|
||||
Log::info("GameSetup", "New player in the game setup. Global id : %d, "
|
||||
"Race id : %d.",
|
||||
profile->getGlobalID(), profile->getPlayerID());
|
||||
Log::info("GameSetup", "New player in the game setup. Race id : %d.",
|
||||
profile->getPlayerID());
|
||||
} // addPlayer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -77,6 +77,25 @@ bool GameSetup::removePlayer(const NetworkPlayerProfile *profile)
|
||||
return false;
|
||||
} // removePlayer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets the player id of the local master.
|
||||
* \param player_id The id of the player who is the local master.
|
||||
*/
|
||||
void GameSetup::setLocalMaster(uint8_t player_id)
|
||||
{
|
||||
m_local_master = player_id;
|
||||
} // setLocalMaster
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns true if the player id is the local game master (used in the
|
||||
* network game selection.
|
||||
* \param Local player id to test.
|
||||
*/
|
||||
bool GameSetup::isLocalMaster(uint8_t player_id)
|
||||
{
|
||||
return m_local_master == player_id;
|
||||
} // isLocalMaster
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets the kart the specified player uses.
|
||||
* \param player_id ID of this player (in this race).
|
||||
@@ -138,21 +157,11 @@ void GameSetup::bindKartsToProfiles()
|
||||
} // bindKartsToProfiles
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const NetworkPlayerProfile* GameSetup::getProfile(uint32_t id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->getOnlineProfile()->getID() == id)
|
||||
{
|
||||
return m_players[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
} // getProfile(id)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** \brief Get a network player profile with the specified player id.
|
||||
* \param player_id : Player id in this race.
|
||||
* \return The profile of the player having the specified player id, or
|
||||
* NULL if no such player exists.
|
||||
*/
|
||||
const NetworkPlayerProfile* GameSetup::getProfile(uint8_t player_id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
@@ -163,9 +172,14 @@ const NetworkPlayerProfile* GameSetup::getProfile(uint8_t player_id)
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
} // getProfile
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** \brief Get a network player profile matching a kart name.
|
||||
* \param kart_name : Name of the kart used by the player.
|
||||
* \return The profile of the player having the kart kart_name, or NULL
|
||||
* if no such network profile exists.
|
||||
*/
|
||||
|
||||
const NetworkPlayerProfile* GameSetup::getProfile(const std::string &kart_name)
|
||||
{
|
||||
|
||||
@@ -46,6 +46,9 @@ private:
|
||||
/** The race configuration. */
|
||||
RaceConfig* m_race_config;
|
||||
|
||||
/** The player id of the local game master, used in
|
||||
* kart selection screen. */
|
||||
uint8_t m_local_master;
|
||||
public:
|
||||
GameSetup();
|
||||
virtual ~GameSetup();
|
||||
@@ -54,26 +57,10 @@ public:
|
||||
bool removePlayer(const NetworkPlayerProfile *profile);
|
||||
void setPlayerKart(uint8_t player_id, const std::string &kart_name);
|
||||
void bindKartsToProfiles(); //!< Sets the right world_kart_id in profiles
|
||||
void setLocalMaster(uint8_t player_id);
|
||||
|
||||
/** \brief Get the players that are in the game
|
||||
* \return A vector containing pointers on the players profiles.
|
||||
*/
|
||||
const std::vector<NetworkPlayerProfile*>& getPlayers() { return m_players; }
|
||||
int getPlayerCount() { return (int)m_players.size(); }
|
||||
/*! \brief Get a network player profile matching a universal id.
|
||||
* \param id : Global id of the player (the one in the SQL database)
|
||||
* \return The profile of the player matching the id.
|
||||
*/
|
||||
const NetworkPlayerProfile* getProfile(uint32_t id);
|
||||
/*! \brief Get a network player profile matching a kart name.
|
||||
* \param kart_name : Name of the kart used by the player.
|
||||
* \return The profile of the player having the kart kart_name
|
||||
*/
|
||||
bool isLocalMaster(uint8_t player_id);
|
||||
const NetworkPlayerProfile* getProfile(uint8_t id);
|
||||
/*! \brief Get a network player profile matching a kart name.
|
||||
* \param kart_name : Name of the kart used by the player.
|
||||
* \return The profile of the player having the kart kart_name.
|
||||
*/
|
||||
const NetworkPlayerProfile* getProfile(const std::string &kart_name);
|
||||
|
||||
/*! \brief Used to know if a kart is available.
|
||||
@@ -81,6 +68,7 @@ public:
|
||||
* \return True if the kart hasn't been selected yet, false elseway.
|
||||
*/
|
||||
bool isKartAvailable(std::string kart_name);
|
||||
// ------------------------------------------------------------------------
|
||||
/*! \brief Used to know if a kart is playable.
|
||||
* \param kart_name : Name of the kart to check.
|
||||
* \return True if the kart is playable (standard kart).
|
||||
@@ -88,8 +76,18 @@ public:
|
||||
* only the standard karts.
|
||||
*/
|
||||
bool isKartAllowed(std::string kart_name) { return true; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the configuration for this race. */
|
||||
RaceConfig* getRaceConfig() { return m_race_config; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** \brief Get the players that are in the game
|
||||
* \return A vector containing pointers on the players profiles. */
|
||||
const std::vector<NetworkPlayerProfile*>& getPlayers()
|
||||
{
|
||||
return m_players;
|
||||
} // getPlayers
|
||||
// ------------------------------------------------------------------------
|
||||
int getPlayerCount() { return (int)m_players.size(); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ NetworkPlayerProfile::NetworkPlayerProfile(int race_player_id,
|
||||
const irr::core::stringw &name)
|
||||
{
|
||||
m_race_player_id = race_player_id;
|
||||
m_online_profile = NULL;
|
||||
m_kart_name = "";
|
||||
m_world_kart_id = 0;
|
||||
m_per_player_difficulty = PLAYER_DIFFICULTY_NORMAL;
|
||||
@@ -38,15 +37,3 @@ NetworkPlayerProfile::NetworkPlayerProfile(int race_player_id,
|
||||
NetworkPlayerProfile::~NetworkPlayerProfile()
|
||||
{
|
||||
} // ~NetworkPlayerProfile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the global id for the player. This is either the online user id
|
||||
* if that player is online, or -1 otherwise.
|
||||
*/
|
||||
int NetworkPlayerProfile::getGlobalID() const
|
||||
{
|
||||
if(m_online_profile)
|
||||
return m_online_profile->getID();
|
||||
else
|
||||
return -1;
|
||||
} // getGlobalID
|
||||
|
||||
@@ -47,19 +47,15 @@ private:
|
||||
/** The name of the player. */
|
||||
irr::core::stringw m_player_name;
|
||||
|
||||
/** Pointer to the online profile of this player. */
|
||||
Online::OnlineProfile* m_online_profile;
|
||||
|
||||
/** The kart id in the World class (pointer to AbstractKart). */
|
||||
uint8_t m_world_kart_id;
|
||||
|
||||
/** Per player difficulty. */
|
||||
PerPlayerDifficulty m_per_player_difficulty;
|
||||
public:
|
||||
NetworkPlayerProfile(int race_player_id,
|
||||
const irr::core::stringw &name);
|
||||
~NetworkPlayerProfile();
|
||||
int getGlobalID() const;
|
||||
NetworkPlayerProfile(int race_player_id,
|
||||
const irr::core::stringw &name);
|
||||
~NetworkPlayerProfile();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the player id of this player. */
|
||||
@@ -68,12 +64,6 @@ public:
|
||||
/** Returns the loca ID of this player in this race. */
|
||||
int getPlayerID() const { return m_race_player_id; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the online profile for this player. */
|
||||
void setOnlineProfile(Online::OnlineProfile *profile)
|
||||
{
|
||||
m_online_profile = profile;
|
||||
} // setOnlineProfile
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the kart name for this player. */
|
||||
void setKartName(const std::string &kart_name) { m_kart_name = kart_name; }
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -86,10 +76,6 @@ public:
|
||||
/** Retuens the world kart id for this player. */
|
||||
int getWorldKartID() const { return m_world_kart_id; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the pointer to the online profile of this player, or NULL if
|
||||
* the player is not online. */
|
||||
Online::OnlineProfile *getOnlineProfile() { return m_online_profile; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the per-player difficulty. */
|
||||
PerPlayerDifficulty getPerPlayerDifficulty() const
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ int NetworkString::decodeString(int pos, std::string *out) const
|
||||
{
|
||||
uint8_t len = getUInt8(pos);
|
||||
*out = getString(pos+1, len);
|
||||
return len;
|
||||
return len+1;
|
||||
} // decodeString
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -245,9 +245,7 @@ void ClientLobbyRoomProtocol::update()
|
||||
std::string name_u8 = StringUtils::wideToUtf8(name);
|
||||
NetworkString ns(6+1+name_u8.size());
|
||||
// 4 (size of id), global id
|
||||
ns.ai8(LE_CONNECTION_REQUESTED).ai8(4)
|
||||
.addUInt32(PlayerManager::getCurrentOnlineId())
|
||||
.encodeString(name);
|
||||
ns.ai8(LE_CONNECTION_REQUESTED).encodeString(name);
|
||||
sendMessage(ns);
|
||||
m_state = REQUESTING_CONNECTION;
|
||||
}
|
||||
@@ -293,16 +291,16 @@ void ClientLobbyRoomProtocol::update()
|
||||
* \param event : Event providing the information.
|
||||
*
|
||||
* Format of the data :
|
||||
* 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|
|
||||
* -------------------------------------------------------------------
|
||||
* Byte 0 1 2s
|
||||
* ---------------------------------------
|
||||
* Size | 1 | 1 | |
|
||||
* Data | 1 | 0 <= race id < 16 | player name|
|
||||
* ---------------------------------------
|
||||
*/
|
||||
void ClientLobbyRoomProtocol::newPlayer(Event* event)
|
||||
{
|
||||
const NetworkString &data = event->data();
|
||||
if (data.size() != 7 || data[0] != 4 || data[5] != 1) // 7 bytes remains now
|
||||
if (data[0] != 1)
|
||||
{
|
||||
Log::error("ClientLobbyRoomProtocol",
|
||||
"A message notifying a new player wasn't formated "
|
||||
@@ -310,25 +308,21 @@ void ClientLobbyRoomProtocol::newPlayer(Event* event)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t global_id = data.gui32(1);
|
||||
uint8_t player_id = data.gui8(6);
|
||||
uint8_t player_id = data.gui8(1);
|
||||
|
||||
core::stringw name;
|
||||
data.decodeStringW(7, &name);
|
||||
if (global_id == PlayerManager::getCurrentOnlineId())
|
||||
data.decodeStringW(2, &name);
|
||||
// FIXME need adjusting when splitscreen is used/
|
||||
if(STKHost::get()->getGameSetup()->isLocalMaster(player_id))
|
||||
{
|
||||
Log::error("ClientLobbyRoomProtocol",
|
||||
"The server notified me that I'm a new player in the "
|
||||
"room (not normal).");
|
||||
}
|
||||
else if (m_setup->getProfile(player_id) == NULL ||
|
||||
m_setup->getProfile(global_id) == NULL)
|
||||
else if (m_setup->getProfile(player_id) == NULL)
|
||||
{
|
||||
Log::verbose("ClientLobbyRoomProtocol", "New player connected.");
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile(player_id, name);
|
||||
profile->setPlayerID(player_id);
|
||||
// FIXME: memory leak??
|
||||
profile->setOnlineProfile(new Online::OnlineProfile(global_id, ""));
|
||||
m_setup->addPlayer(profile);
|
||||
NetworkingLobby::getInstance()->addPlayer(profile);
|
||||
}
|
||||
@@ -378,17 +372,17 @@ void ClientLobbyRoomProtocol::disconnectedPlayer(Event* event)
|
||||
* \param event : Event providing the information.
|
||||
*
|
||||
* 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 | playernames*
|
||||
* ----------------------------------------------------------
|
||||
* Byte 0 1 2 3 7 8
|
||||
* ---------------------------------------------------------
|
||||
* Size | 1 | 1 | 1 | 4 | |
|
||||
* Data | 1 | 0 <= race id < 16 | 4 | priv token | playernames* |
|
||||
* ---------------------------------------------------------
|
||||
*/
|
||||
void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
{
|
||||
NetworkString &data = event->data();
|
||||
// At least 12 bytes should remain now
|
||||
if (data.size() < 12 || data[0] != 1 || data[2] != 4 || data[7] != 4)
|
||||
if (data.size() < 7|| data[0] != 1 || data[2] != 4)
|
||||
{
|
||||
Log::error("ClientLobbyRoomProtocol",
|
||||
"A message notifying an accepted connection wasn't "
|
||||
@@ -397,14 +391,6 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
}
|
||||
STKPeer* peer = event->getPeer();
|
||||
|
||||
uint32_t global_id = data.gui32(8);
|
||||
if (global_id != PlayerManager::getCurrentOnlineId())
|
||||
{
|
||||
Log::info("ClientLobbyRoomProtocol",
|
||||
"Failure during the connection acceptation process.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Accepted
|
||||
// ========
|
||||
Log::info("ClientLobbyRoomProtocol",
|
||||
@@ -416,9 +402,9 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
name = PlayerManager::getCurrentOnlineUserName();
|
||||
else
|
||||
name = PlayerManager::getCurrentPlayer()->getName();
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile(-1, name);
|
||||
profile->setPlayerID(data.gui8(1));
|
||||
profile->setOnlineProfile(PlayerManager::getCurrentOnlineProfile());
|
||||
uint8_t my_player_id = data.getUInt8(1);
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile(my_player_id, name);
|
||||
STKHost::get()->getGameSetup()->setLocalMaster(my_player_id);
|
||||
m_setup->addPlayer(profile);
|
||||
// connection token
|
||||
uint32_t token = data.gui32(3);
|
||||
@@ -428,27 +414,21 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
|
||||
// Add all players
|
||||
// ===============
|
||||
int n = 12;
|
||||
int n = 7;
|
||||
while (n < data.size())
|
||||
{
|
||||
if (data[n] != 1 || data[n + 2] != 4)
|
||||
if (data[n] != 1 )
|
||||
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);
|
||||
int bytes_read = data.decodeStringW(n + 2, &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;
|
||||
n += bytes_read+2;
|
||||
NetworkingLobby::getInstance()->addPlayer(profile2);
|
||||
}
|
||||
|
||||
@@ -627,7 +607,7 @@ void ClientLobbyRoomProtocol::startSelection(Event* event)
|
||||
"selection update wasn't formated as expected.");
|
||||
return;
|
||||
}
|
||||
uint8_t token = data.gui32(1);
|
||||
uint32_t token = data.gui32(1);
|
||||
if (token == STKHost::get()->getPeers()[0]->getClientServerToken())
|
||||
{
|
||||
m_state = KART_SELECTION;
|
||||
|
||||
@@ -413,25 +413,17 @@ void ServerLobbyRoomProtocol::kartDisconnected(Event* event)
|
||||
* \param event : Event providing the information.
|
||||
*
|
||||
* Format of the data :
|
||||
* Byte 0 1 5
|
||||
* ----------------------------------------
|
||||
* Size | 1 | 4 |1| |
|
||||
* Data | 4 | global player id |n| player name |
|
||||
* ----------------------------------------
|
||||
* Byte 0 1
|
||||
* ---------------------
|
||||
* Size | 1 |1| |
|
||||
* Data | 4 |n| player name |
|
||||
* ---------------------
|
||||
*/
|
||||
void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
{
|
||||
STKPeer* peer = event->getPeer();
|
||||
const NetworkString &data = event->data();
|
||||
if (data[0] != 4)
|
||||
{
|
||||
Log::warn("ServerLobbyRoomProtocol",
|
||||
"Receiving badly formated message. Size is %d and first byte %d",
|
||||
data.size(), data[0]);
|
||||
return;
|
||||
}
|
||||
uint32_t player_id = 0;
|
||||
player_id = data.getUInt32(1);
|
||||
|
||||
// can we add the player ?
|
||||
if (m_setup->getPlayerCount() >= NetworkConfig::get()->getMaxPlayers() ||
|
||||
m_state!=ACCEPTING_CLIENTS )
|
||||
@@ -450,26 +442,24 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
// Connection accepted.
|
||||
// ====================
|
||||
std::string name_u8;
|
||||
int name_len = data.decodeString(5, &name_u8);
|
||||
int name_len = data.decodeString(0, &name_u8);
|
||||
core::stringw name = StringUtils::utf8ToWide(name_u8);
|
||||
|
||||
// add the player to the game setup
|
||||
m_next_player_id.lock();
|
||||
m_next_player_id.getData()++;
|
||||
int next_player_id = m_next_player_id.getData();
|
||||
int new_player_id = m_next_player_id.getData();
|
||||
m_next_player_id.unlock();
|
||||
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile(next_player_id, name);
|
||||
// FIXME: memory leak OnlineProfile
|
||||
profile->setOnlineProfile(new Online::OnlineProfile(player_id, ""));
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile(new_player_id, name);
|
||||
m_setup->addPlayer(profile);
|
||||
peer->setPlayerProfile(profile);
|
||||
|
||||
// notify everybody that there is a new player
|
||||
NetworkString message(8);
|
||||
// size of id -- id -- size of local id -- local id;
|
||||
message.ai8(LE_NEW_PLAYER_CONNECTED).ai8(4).ai32(player_id)
|
||||
.ai8(1).ai8(next_player_id).encodeString(name_u8);
|
||||
message.ai8(LE_NEW_PLAYER_CONNECTED).ai8(1).ai8(new_player_id)
|
||||
.encodeString(name_u8);
|
||||
ProtocolManager::getInstance()->sendMessageExcept(this, peer, message);
|
||||
|
||||
// Now answer to the peer that just connected
|
||||
@@ -484,18 +474,16 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
// send a message to the one that asked to connect
|
||||
// Size is overestimated, probably one player's data will not be sent
|
||||
NetworkString message_ack(13 + players.size() * 7);
|
||||
// connection success (129) -- size of token -- token
|
||||
message_ack.ai8(LE_CONNECTION_ACCEPTED).ai8(1).ai8(next_player_id).ai8(4)
|
||||
.ai32(token).ai8(4).ai32(player_id);
|
||||
// connection success -- size of token -- token
|
||||
message_ack.ai8(LE_CONNECTION_ACCEPTED).ai8(1).ai8(new_player_id).ai8(4)
|
||||
.ai32(token);
|
||||
// add all players so that this user knows
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
// do not duplicate the player into the message
|
||||
if (players[i]->getPlayerID() != next_player_id &&
|
||||
players[i]->getGlobalID() != player_id)
|
||||
if (players[i]->getPlayerID() != new_player_id )
|
||||
{
|
||||
message_ack.ai8(1).ai8(players[i]->getPlayerID()).ai8(4)
|
||||
.ai32(players[i]->getGlobalID())
|
||||
message_ack.ai8(1).ai8(players[i]->getPlayerID())
|
||||
.encodeString(players[i]->getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,15 +125,15 @@ void StartGameProtocol::update()
|
||||
std::vector<NetworkPlayerProfile*> players = m_game_setup->getPlayers();
|
||||
std::sort(players.begin(), players.end(), compareKarts);
|
||||
// have to add self first
|
||||
GameSetup *setup = STKHost::get()->getGameSetup();
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
bool is_me = (players[i]->getOnlineProfile() ==
|
||||
PlayerManager::getCurrentOnlineProfile());
|
||||
bool is_me = setup->isLocalMaster(players[i]->getPlayerID());
|
||||
if (is_me)
|
||||
{
|
||||
NetworkPlayerProfile* profile = players[i];
|
||||
RemoteKartInfo rki(profile->getPlayerID(), profile->getKartName(),
|
||||
profile->getOnlineProfile()->getUserName().c_str(),
|
||||
profile->getName(),
|
||||
profile->getPlayerID(), !is_me);
|
||||
rki.setPerPlayerDifficulty(profile->getPerPlayerDifficulty());
|
||||
rki.setGlobalPlayerId(profile->getPlayerID());
|
||||
@@ -166,11 +166,10 @@ void StartGameProtocol::update()
|
||||
}
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
bool is_me = (players[i]->getOnlineProfile() ==
|
||||
PlayerManager::getCurrentOnlineProfile());
|
||||
bool is_me = setup->isLocalMaster(players[i]->getPlayerID());
|
||||
NetworkPlayerProfile* profile = players[i];
|
||||
RemoteKartInfo rki(profile->getPlayerID(), profile->getKartName(),
|
||||
profile->getOnlineProfile()->getUserName(),
|
||||
profile->getName(),
|
||||
profile->getPlayerID(), !is_me);
|
||||
rki.setPerPlayerDifficulty(profile->getPerPlayerDifficulty());
|
||||
rki.setGlobalPlayerId(profile->getPlayerID());
|
||||
|
||||
@@ -174,10 +174,10 @@ Online::XMLRequest* ServersManager::getLANRefreshRequest() const
|
||||
irr::core::stringw name;
|
||||
// name_len is the number of bytes read
|
||||
uint8_t bytes_read = s.decodeStringW(0, &name);
|
||||
uint8_t max_players = s.getUInt8(1+bytes_read );
|
||||
uint8_t players = s.getUInt8(1+bytes_read+1);
|
||||
uint32_t my_ip = s.getUInt32(1+bytes_read+2);
|
||||
uint32_t my_port = s.getUInt16(1+bytes_read+6);
|
||||
uint8_t max_players = s.getUInt8(bytes_read );
|
||||
uint8_t players = s.getUInt8(bytes_read+1);
|
||||
uint32_t my_ip = s.getUInt32(bytes_read+2);
|
||||
uint32_t my_port = s.getUInt16(bytes_read+6);
|
||||
ServersManager::get()
|
||||
->addServer(new Server(name, /*lan*/true,
|
||||
max_players, players,
|
||||
|
||||
@@ -83,10 +83,10 @@ void NetworkKartSelectionScreen::init()
|
||||
kartsAreaWidget->m_y,
|
||||
kartsAreaWidget->m_x + shift + kartsAreaWidget->m_w,
|
||||
kartsAreaWidget->m_y + kartsAreaWidget->m_h);
|
||||
|
||||
GameSetup *game_setup = STKHost::get()->getGameSetup();
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
if (players[i]->getOnlineProfile()== PlayerManager::getCurrentOnlineProfile())
|
||||
if(game_setup->isLocalMaster(players[i]->getPlayerID()))
|
||||
{
|
||||
m_id_mapping.insert(m_id_mapping.begin(),players[i]->getPlayerID()); //!< first kart widget always me
|
||||
Log::info("NKSS", "Insert %d at pos 0", players[i]->getPlayerID());
|
||||
@@ -101,7 +101,7 @@ void NetworkKartSelectionScreen::init()
|
||||
std::string selected_kart_group = "standard"; // standard group
|
||||
|
||||
PlayerKartWidget* newPlayerWidget =
|
||||
new PlayerKartWidget(this, aplayer, players[i]->getOnlineProfile(),
|
||||
new PlayerKartWidget(this, aplayer, players[i],
|
||||
kartsArea, m_kart_widgets.size(),
|
||||
selected_kart_group);
|
||||
|
||||
|
||||
@@ -106,7 +106,9 @@ void NetworkingLobby::init()
|
||||
// ----------------------------------------------------------------------------
|
||||
void NetworkingLobby::onUpdate(float delta)
|
||||
{
|
||||
m_start_button->setVisible(STKHost::get()->isAuthorisedToControl());
|
||||
// FIXME Network looby should be closed when stkhost is shut down
|
||||
m_start_button->setVisible(STKHost::existHost() &&
|
||||
STKHost::get()->isAuthorisedToControl());
|
||||
} // onUpdate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user