Moved NetworkPlayerProfile into its own file, added getter and
setters for it.
This commit is contained in:
parent
927969e720
commit
2f126ab226
@ -1,5 +1,5 @@
|
||||
# Modify this file to change the last-modified date when you add/remove a file.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "online/online_profile.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
@ -29,7 +30,7 @@
|
||||
GameSetup::GameSetup()
|
||||
{
|
||||
m_race_config = new RaceConfig();
|
||||
}
|
||||
} // GameSetup
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -42,79 +43,64 @@ GameSetup::~GameSetup()
|
||||
};
|
||||
m_players.clear();
|
||||
delete m_race_config;
|
||||
}
|
||||
} // ~GameSetup
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void GameSetup::addPlayer(NetworkPlayerProfile* profile)
|
||||
{
|
||||
m_players.push_back(profile);
|
||||
Log::info("GameSetup", "New player in the game setup. Global id : %u, "
|
||||
Log::info("GameSetup", "New player in the game setup. Global id : %d, "
|
||||
"Race id : %d.",
|
||||
profile->user_profile ? profile->user_profile->getID() : -1,
|
||||
profile->race_id);
|
||||
profile->getGlobalID(), profile->getPlayerID());
|
||||
} // addPlayer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool GameSetup::removePlayer(uint32_t id)
|
||||
/** Removed a player give his NetworkPlayerProfile.
|
||||
* \param profile The NetworkPlayerProfile to remove.
|
||||
* \return True if the player was found and removed, false otherwise.
|
||||
*/
|
||||
bool GameSetup::removePlayer(const NetworkPlayerProfile *profile)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->user_profile->getID() == id)
|
||||
if (m_players[i] == profile)
|
||||
{
|
||||
delete m_players[i];
|
||||
m_players.erase(m_players.begin()+i, m_players.begin()+i+1);
|
||||
Log::verbose("GameSetup", "Removed a player from the game setup. "
|
||||
"Remains %u.", m_players.size());
|
||||
Log::verbose("GameSetup",
|
||||
"Removed a player from the game setup. Remains %u.",
|
||||
m_players.size());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // removePlayer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool GameSetup::removePlayer(uint8_t id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->race_id == id) // check the given id
|
||||
{
|
||||
delete m_players[i];
|
||||
m_players.erase(m_players.begin()+i, m_players.begin()+i+1);
|
||||
Log::verbose("GameSetup", "Removed a player from the game setup. "
|
||||
"Remains %u.", m_players.size());
|
||||
return true;
|
||||
}
|
||||
if (m_players[i]->race_id > id)
|
||||
{
|
||||
m_players[i]->race_id--; // all indices in [0;n[ (n = #players)
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void GameSetup::setPlayerKart(uint8_t id, std::string kart_name)
|
||||
/** Sets the kart the specified player uses.
|
||||
* \param player_id ID of this player (in this race).
|
||||
* \param kart_name Name of the kart the player picked.
|
||||
*/
|
||||
void GameSetup::setPlayerKart(uint8_t player_id, const std::string &kart_name)
|
||||
{
|
||||
bool found = false;
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->race_id == id)
|
||||
if (m_players[i]->getPlayerID() == player_id)
|
||||
{
|
||||
m_players[i]->kart_name = kart_name;
|
||||
m_players[i]->setKartName(kart_name);
|
||||
Log::info("GameSetup::setPlayerKart", "Player %d took kart %s",
|
||||
id, kart_name.c_str());
|
||||
player_id, kart_name.c_str());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
Log::info("GameSetup::setPlayerKart", "The player %d was unknown.", id);
|
||||
Log::info("GameSetup::setPlayerKart", "The player %d was unknown.",
|
||||
player_id);
|
||||
}
|
||||
}
|
||||
} // setPlayerKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -124,20 +110,22 @@ void GameSetup::bindKartsToProfiles()
|
||||
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
Log::info("GameSetup", "Player %d has id %d and kart %s", i, m_players[i]->race_id, m_players[i]->kart_name.c_str());
|
||||
Log::info("GameSetup", "Player %d has id %d and kart %s", i,
|
||||
m_players[i]->getPlayerID(), m_players[i]->getKartName().c_str());
|
||||
}
|
||||
for (unsigned int i = 0; i < karts.size(); i++)
|
||||
{
|
||||
Log::info("GameSetup", "Kart %d has id %d and kart %s", i, karts[i]->getWorldKartId(), karts[i]->getIdent().c_str());
|
||||
Log::info("GameSetup", "Kart %d has id %d and kart %s", i,
|
||||
karts[i]->getWorldKartId(), karts[i]->getIdent().c_str());
|
||||
}
|
||||
for (unsigned int j = 0; j < m_players.size(); j++)
|
||||
{
|
||||
bool found = false;
|
||||
for (unsigned int i = 0 ; i < karts.size(); i++)
|
||||
{
|
||||
if (karts[i]->getIdent() == m_players[j]->kart_name)
|
||||
if (karts[i]->getIdent() == m_players[j]->getKartName())
|
||||
{
|
||||
m_players[j]->world_kart_id = karts[i]->getWorldKartId();
|
||||
m_players[j]->setWorldKartID(karts[i]->getWorldKartId());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -147,7 +135,7 @@ void GameSetup::bindKartsToProfiles()
|
||||
Log::error("GameSetup", "Error while binding world kart ids to players profiles.");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // bindKartsToProfiles
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -155,7 +143,21 @@ const NetworkPlayerProfile* GameSetup::getProfile(uint32_t id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->user_profile->getID() == id)
|
||||
if (m_players[i]->getOnlineProfile()->getID() == id)
|
||||
{
|
||||
return m_players[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
} // getProfile(id)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const NetworkPlayerProfile* GameSetup::getProfile(uint8_t player_id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->getPlayerID()== player_id)
|
||||
{
|
||||
return m_players[i];
|
||||
}
|
||||
@ -165,31 +167,17 @@ const NetworkPlayerProfile* GameSetup::getProfile(uint32_t id)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const NetworkPlayerProfile* GameSetup::getProfile(uint8_t id)
|
||||
const NetworkPlayerProfile* GameSetup::getProfile(const std::string &kart_name)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->race_id == id)
|
||||
if (m_players[i]->getKartName() == kart_name)
|
||||
{
|
||||
return m_players[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const NetworkPlayerProfile* GameSetup::getProfile(std::string kart_name)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->kart_name == kart_name)
|
||||
{
|
||||
return m_players[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
} // getProfile(kart_name)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -197,7 +185,7 @@ bool GameSetup::isKartAvailable(std::string kart_name)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->kart_name == kart_name)
|
||||
if (m_players[i]->getKartName() == kart_name)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -29,80 +29,68 @@
|
||||
#include <string>
|
||||
|
||||
namespace Online { class OnlineProfile; }
|
||||
class NetworkPlayerProfile;
|
||||
|
||||
|
||||
/*! \class PlayerProfile
|
||||
* \brief Contains the profile of a player.
|
||||
*/
|
||||
class NetworkPlayerProfile
|
||||
{
|
||||
public:
|
||||
NetworkPlayerProfile() { race_id = 0; user_profile = NULL; }
|
||||
~NetworkPlayerProfile() {}
|
||||
|
||||
uint8_t race_id; //!< The id of the player for the race
|
||||
std::string kart_name; //!< The selected kart.
|
||||
Online::OnlineProfile* user_profile; //!< Pointer to the lobby profile
|
||||
uint8_t world_kart_id; //!< the kart id in the World class (pointer to AbstractKart)
|
||||
PerPlayerDifficulty difficulty;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
/*! \class GameSetup
|
||||
* \brief Used to store the needed data about the players that join a game.
|
||||
* This class stores all the possible information about players in a lobby.
|
||||
*/
|
||||
class GameSetup
|
||||
{
|
||||
public:
|
||||
GameSetup();
|
||||
virtual ~GameSetup();
|
||||
private:
|
||||
/** Information about all connected players. */
|
||||
std::vector<NetworkPlayerProfile*> m_players;
|
||||
|
||||
void addPlayer(NetworkPlayerProfile* profile); //!< Add a player.
|
||||
bool removePlayer(uint32_t id); //!< Remove a player by id.
|
||||
bool removePlayer(uint8_t id); //!< Remove a player by local id.
|
||||
void setPlayerKart(uint8_t id, std::string kart_name); //!< Set the kart of a player
|
||||
void bindKartsToProfiles(); //!< Sets the right world_kart_id in profiles
|
||||
/** The race configuration. */
|
||||
RaceConfig* 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; }
|
||||
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
|
||||
*/
|
||||
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(std::string kart_name);
|
||||
public:
|
||||
GameSetup();
|
||||
virtual ~GameSetup();
|
||||
|
||||
/*! \brief Used to know if a kart is available.
|
||||
* \param kart_name : Name of the kart to check.
|
||||
* \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).
|
||||
* Currently this is always true as the kart selection screen shows
|
||||
* only the standard karts.
|
||||
*/
|
||||
bool isKartAllowed(std::string kart_name) {return true; }
|
||||
void addPlayer(NetworkPlayerProfile* profile); //!< Add a player.
|
||||
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
|
||||
|
||||
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; }
|
||||
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
|
||||
*/
|
||||
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.
|
||||
* \param kart_name : Name of the kart to check.
|
||||
* \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).
|
||||
* Currently this is always true as the kart selection screen shows
|
||||
* only the standard karts.
|
||||
*/
|
||||
bool isKartAllowed(std::string kart_name) { return true; }
|
||||
|
||||
RaceConfig* getRaceConfig() { return m_race_config; }
|
||||
|
||||
protected:
|
||||
std::vector<NetworkPlayerProfile*> m_players; //!< Information about players
|
||||
NetworkPlayerProfile m_self_profile; //!< Information about self (client only)
|
||||
RaceConfig* m_race_config;
|
||||
};
|
||||
|
||||
#endif // GAME_SETUP_HPP
|
||||
|
47
src/network/network_player_profile.cpp
Normal file
47
src/network/network_player_profile.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013-2015 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.
|
||||
|
||||
#include "network/network_player_profile.hpp"
|
||||
|
||||
#include "online/online_player_profile.hpp"
|
||||
|
||||
NetworkPlayerProfile::NetworkPlayerProfile(int race_player_id)
|
||||
{
|
||||
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;
|
||||
} // BetworkPlayerProfile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
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
|
94
src/network/network_player_profile.hpp
Normal file
94
src/network/network_player_profile.hpp
Normal file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013-2015 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.
|
||||
|
||||
/*! \file game_setup.hpp
|
||||
*/
|
||||
|
||||
#ifndef HEADER_NETWORK_PLAYER_PROFILE
|
||||
#define HEADER_NETWORK_PLAYER_PROFILE
|
||||
|
||||
#include "utils/types.hpp"
|
||||
|
||||
#include "karts/player_difficulty.hpp"
|
||||
|
||||
#include <string>
|
||||
namespace Online { class OnlineProfile; }
|
||||
|
||||
|
||||
/*! \class PlayerProfile
|
||||
* \brief Contains the profile of a player.
|
||||
*/
|
||||
class NetworkPlayerProfile
|
||||
{
|
||||
private:
|
||||
/** The id of the player for the race. */
|
||||
uint8_t m_race_player_id;
|
||||
|
||||
/** The selected kart. */
|
||||
std::string m_kart_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);
|
||||
~NetworkPlayerProfile();
|
||||
int getGlobalID() const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the player id of this player. */
|
||||
void setPlayerID(int player_id) { m_race_player_id = player_id; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** 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; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name of the kart this player has selected. */
|
||||
const std::string &getKartName() const { return m_kart_name; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the world kart id for this player. */
|
||||
void setWorldKartID(int id) { m_world_kart_id = id; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** 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 { return m_per_player_difficulty; }
|
||||
// ------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
}; // class NetworkPlayerProfile
|
||||
|
||||
#endif // HEADER_NETWORK_PLAYER_PROFILE
|
@ -21,6 +21,7 @@
|
||||
#include "config/player_manager.hpp"
|
||||
#include "modes/world_with_rank.hpp"
|
||||
#include "network/event.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/network_world.hpp"
|
||||
#include "network/protocols/start_game_protocol.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
@ -300,7 +301,7 @@ void ClientLobbyRoomProtocol::newPlayer(Event* event)
|
||||
}
|
||||
|
||||
uint32_t global_id = data.gui32(1);
|
||||
uint8_t race_id = data.gui8(6);
|
||||
uint8_t player_id = data.gui8(6);
|
||||
|
||||
if (global_id == PlayerManager::getCurrentOnlineId())
|
||||
{
|
||||
@ -308,14 +309,15 @@ void ClientLobbyRoomProtocol::newPlayer(Event* event)
|
||||
"The server notified me that I'm a new player in the "
|
||||
"room (not normal).");
|
||||
}
|
||||
else if (m_setup->getProfile(race_id) == NULL ||
|
||||
else if (m_setup->getProfile(player_id) == NULL ||
|
||||
m_setup->getProfile(global_id) == NULL)
|
||||
{
|
||||
Log::verbose("ClientLobbyRoomProtocol", "New player connected.");
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
|
||||
profile->kart_name = "";
|
||||
profile->race_id = race_id;
|
||||
profile->user_profile = new Online::OnlineProfile(global_id, "");
|
||||
// FIXME: what player id to use?
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile(-1);
|
||||
profile->setPlayerID(player_id);
|
||||
// FIXME: memory leak??
|
||||
profile->setOnlineProfile(new Online::OnlineProfile(global_id, ""));
|
||||
m_setup->addPlayer(profile);
|
||||
}
|
||||
else
|
||||
@ -347,8 +349,7 @@ void ClientLobbyRoomProtocol::disconnectedPlayer(Event* event)
|
||||
"as expected.");
|
||||
return;
|
||||
}
|
||||
uint8_t id = data[1];
|
||||
if (m_setup->removePlayer(id))
|
||||
if (m_setup->removePlayer(event->getPeer()->getPlayerProfile()))
|
||||
{
|
||||
Log::info("ClientLobbyRoomProtocol", "Peer removed successfully.");
|
||||
}
|
||||
@ -391,10 +392,10 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
"The server accepted the connection.");
|
||||
|
||||
// self profile
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
|
||||
profile->kart_name = "";
|
||||
profile->race_id = data.gui8(1);
|
||||
profile->user_profile = PlayerManager::getCurrentOnlineProfile();
|
||||
//FIXME
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile(-1);
|
||||
profile->setPlayerID(data.gui8(1));
|
||||
profile->setOnlineProfile(PlayerManager::getCurrentOnlineProfile());
|
||||
m_setup->addPlayer(profile);
|
||||
// connection token
|
||||
uint32_t token = data.gui32(3);
|
||||
@ -419,10 +420,10 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
Online::OnlineProfile* new_user =
|
||||
new Online::OnlineProfile(global_id, "");
|
||||
|
||||
NetworkPlayerProfile* profile2 = new NetworkPlayerProfile();
|
||||
profile2->race_id = race_id;
|
||||
profile2->user_profile = new_user;
|
||||
profile2->kart_name = "";
|
||||
// FIXME
|
||||
NetworkPlayerProfile* profile2 = new NetworkPlayerProfile(-1);
|
||||
profile2->setPlayerID(race_id);
|
||||
profile2->setOnlineProfile(new_user);
|
||||
m_setup->addPlayer(profile2);
|
||||
data.removeFront(7);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "karts/controller/controller.hpp"
|
||||
#include "network/event.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/network_world.hpp"
|
||||
@ -45,12 +46,14 @@ void ControllerEventsProtocol::setup()
|
||||
{
|
||||
for (unsigned int j = 0; j < peers.size(); j++)
|
||||
{
|
||||
if (peers[j]->getPlayerProfile()->kart_name == karts[i]->getIdent())
|
||||
if (peers[j]->getPlayerProfile()->getKartName()
|
||||
== karts[i]->getIdent())
|
||||
{
|
||||
peer = peers[j];
|
||||
}
|
||||
Log::info("ControllerEventsProtocol", "Compared %s and %s",
|
||||
peers[j]->getPlayerProfile()->kart_name.c_str(), karts[i]->getIdent().c_str());
|
||||
peers[j]->getPlayerProfile()->getKartName().c_str(),
|
||||
karts[i]->getIdent().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "modes/world.hpp"
|
||||
#include "network/event.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "network/stk_peer.hpp"
|
||||
@ -53,7 +54,8 @@ bool GameEventsProtocol::notifyEvent(Event* event)
|
||||
uint8_t kart_race_id = data.gui8(5);
|
||||
// now set the kart powerup
|
||||
AbstractKart* kart = World::getWorld()->getKart(
|
||||
STKHost::get()->getGameSetup()->getProfile(kart_race_id)->world_kart_id);
|
||||
STKHost::get()->getGameSetup()
|
||||
->getProfile(kart_race_id)->getWorldKartID());
|
||||
ItemManager::get()->collectedItem(
|
||||
ItemManager::get()->getItem(item_id),
|
||||
kart,
|
||||
@ -93,7 +95,8 @@ void GameEventsProtocol::collectedItem(Item* item, AbstractKart* kart)
|
||||
else if (item->getType() == Item::ITEM_BONUS_BOX)
|
||||
powerup = (((int)(kart->getPowerup()->getType()) << 4)&0xf0) + (kart->getPowerup()->getNum()&0x0f);
|
||||
|
||||
ns.ai8(0x01).ai32(item->getItemId()).ai8(powerup).ai8(player_profile->race_id); // send item,
|
||||
ns.ai8(0x01).ai32(item->getItemId()).ai8(powerup)
|
||||
.ai8(player_profile->getPlayerID());
|
||||
ProtocolManager::getInstance()->sendMessage(this, peers[i], ns, true); // reliable
|
||||
Log::info("GameEventsProtocol", "Notified a peer that a kart collected item %d.", (int)(kart->getPowerup()->getType()));
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "network/event.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/network_world.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/protocols/get_public_address.hpp"
|
||||
#include "network/protocols/connect_to_peer.hpp"
|
||||
#include "network/protocols/start_game_protocol.hpp"
|
||||
@ -393,11 +394,11 @@ void ServerLobbyRoomProtocol::kartDisconnected(Event* event)
|
||||
{
|
||||
NetworkString msg(3);
|
||||
msg.ai8(LE_PLAYER_DISCONNECTED).ai8(1)
|
||||
.ai8(peer->getPlayerProfile()->race_id);
|
||||
.ai8(peer->getPlayerProfile()->getPlayerID());
|
||||
sendMessage(msg);
|
||||
Log::info("ServerLobbyRoomProtocol", "Player disconnected : id %d",
|
||||
peer->getPlayerProfile()->race_id);
|
||||
m_setup->removePlayer(peer->getPlayerProfile()->race_id);
|
||||
peer->getPlayerProfile()->getPlayerID());
|
||||
m_setup->removePlayer(peer->getPlayerProfile());
|
||||
STKHost::get()->removePeer(peer);
|
||||
}
|
||||
else
|
||||
@ -461,21 +462,20 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
// do not duplicate the player into the message
|
||||
if (players[i]->race_id != m_next_id &&
|
||||
players[i]->user_profile->getID() != player_id)
|
||||
if (players[i]->getPlayerID() != m_next_id &&
|
||||
players[i]->getGlobalID() != player_id)
|
||||
{
|
||||
message_ack.ai8(1).ai8(players[i]->race_id).ai8(4)
|
||||
.ai32(players[i]->user_profile->getID());
|
||||
message_ack.ai8(1).ai8(players[i]->getPlayerID()).ai8(4)
|
||||
.ai32(players[i]->getGlobalID());
|
||||
}
|
||||
}
|
||||
sendMessage(peer, message_ack);
|
||||
|
||||
peer->setClientServerToken(token);
|
||||
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
|
||||
profile->race_id = m_next_id;
|
||||
profile->kart_name = "";
|
||||
profile->user_profile = new Online::OnlineProfile(player_id, "");
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile(m_next_id);
|
||||
// FIXME: memory leak OnlineProfile
|
||||
profile->setOnlineProfile(new Online::OnlineProfile(player_id, ""));
|
||||
m_setup->addPlayer(profile);
|
||||
peer->setPlayerProfile(profile);
|
||||
Log::verbose("ServerLobbyRoomProtocol", "New player.");
|
||||
@ -559,11 +559,11 @@ void ServerLobbyRoomProtocol::kartSelectionRequested(Event* event)
|
||||
// send a kart update to everyone
|
||||
NetworkString answer(3+1+kart_name.size());
|
||||
// kart update (3), 1, race id
|
||||
answer.ai8(0x03).ai8(1).ai8(peer->getPlayerProfile()->race_id);
|
||||
answer.ai8(0x03).ai8(1).ai8(peer->getPlayerProfile()->getPlayerID());
|
||||
// kart name size, kart name
|
||||
answer.add(kart_name);
|
||||
sendMessage(answer);
|
||||
m_setup->setPlayerKart(peer->getPlayerProfile()->race_id, kart_name);
|
||||
m_setup->setPlayerKart(peer->getPlayerProfile()->getPlayerID(), kart_name);
|
||||
} // kartSelectionRequested
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -586,7 +586,7 @@ void ServerLobbyRoomProtocol::playerMajorVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->race_id;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
m_setup->getRaceConfig()->setPlayerMajorVote(player_id, data[6]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
data.removeFront(5); // remove the token
|
||||
@ -618,7 +618,7 @@ void ServerLobbyRoomProtocol::playerRaceCountVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->race_id;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
m_setup->getRaceConfig()->setPlayerRaceCountVote(player_id, data[6]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
data.removeFront(5); // remove the token
|
||||
@ -650,7 +650,7 @@ void ServerLobbyRoomProtocol::playerMinorVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->race_id;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
m_setup->getRaceConfig()->setPlayerMinorVote(player_id, data[6]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
data.removeFront(5); // remove the token
|
||||
@ -684,7 +684,7 @@ void ServerLobbyRoomProtocol::playerTrackVote(Event* event)
|
||||
std::string track_name = data.getString(6, N);
|
||||
if (!isByteCorrect(event, N+6, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->race_id;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
m_setup->getRaceConfig()->setPlayerTrackVote(player_id, track_name, data[N+7]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
data.removeFront(5); // remove the token
|
||||
@ -718,7 +718,7 @@ void ServerLobbyRoomProtocol::playerReversedVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 7, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->race_id;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
m_setup->getRaceConfig()->setPlayerReversedVote(player_id,
|
||||
data[6]!=0, data[8]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
@ -753,7 +753,7 @@ void ServerLobbyRoomProtocol::playerLapsVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 7, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->race_id;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
m_setup->getRaceConfig()->setPlayerLapsVote(player_id, data[6], data[8]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
data.removeFront(5); // remove the token
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "network/event.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/network_world.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/synchronization_protocol.hpp"
|
||||
@ -99,10 +100,10 @@ void StartGameProtocol::setup()
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool sortKarts(NetworkPlayerProfile* a, NetworkPlayerProfile* b)
|
||||
bool compareKarts(NetworkPlayerProfile* a, NetworkPlayerProfile* b)
|
||||
{
|
||||
return (a->race_id < b->race_id);
|
||||
} // sortKarts
|
||||
return (a->getPlayerID() < b->getPlayerID());
|
||||
} // compareKarts
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void StartGameProtocol::update()
|
||||
@ -122,22 +123,22 @@ void StartGameProtocol::update()
|
||||
race_manager->setNumPlayers(m_game_setup->getPlayerCount());
|
||||
race_manager->setNumLocalPlayers(1);
|
||||
std::vector<NetworkPlayerProfile*> players = m_game_setup->getPlayers();
|
||||
std::sort(players.begin(), players.end(), sortKarts);
|
||||
std::sort(players.begin(), players.end(), compareKarts);
|
||||
// have to add self first
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
bool is_me = (players[i]->user_profile ==
|
||||
bool is_me = (players[i]->getOnlineProfile() ==
|
||||
PlayerManager::getCurrentOnlineProfile());
|
||||
if (is_me)
|
||||
{
|
||||
NetworkPlayerProfile* profile = players[i];
|
||||
RemoteKartInfo rki(profile->race_id, profile->kart_name,
|
||||
profile->user_profile->getUserName(),
|
||||
profile->race_id, !is_me);
|
||||
rki.setDifficulty(profile->difficulty);
|
||||
rki.setGlobalPlayerId(profile->race_id);
|
||||
RemoteKartInfo rki(profile->getPlayerID(), profile->getKartName(),
|
||||
profile->getOnlineProfile()->getUserName().c_str(),
|
||||
profile->getPlayerID(), !is_me);
|
||||
rki.setPerPlayerDifficulty(profile->getPerPlayerDifficulty());
|
||||
rki.setGlobalPlayerId(profile->getPlayerID());
|
||||
rki.setLocalPlayerId(is_me?0:1);
|
||||
rki.setHostId(profile->race_id);
|
||||
rki.setHostId(profile->getPlayerID());
|
||||
PlayerProfile* profile_to_use = PlayerManager::getCurrentPlayer();
|
||||
assert(profile_to_use);
|
||||
InputDevice* device = input_manager->getDeviceManager()
|
||||
@ -156,32 +157,32 @@ void StartGameProtocol::update()
|
||||
input_manager->getDeviceManager()->setSinglePlayer(ap);
|
||||
|
||||
race_manager->setPlayerKart(i, rki);
|
||||
race_manager->setLocalKartInfo(new_player_id, profile->kart_name);
|
||||
race_manager->setLocalKartInfo(new_player_id, profile->getKartName());
|
||||
// self config
|
||||
Log::info("StartGameProtocol", "Self player device added.");
|
||||
NetworkWorld::getInstance()->m_self_kart = profile->kart_name;
|
||||
NetworkWorld::getInstance()->m_self_kart = profile->getKartName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
bool is_me = (players[i]->user_profile ==
|
||||
bool is_me = (players[i]->getOnlineProfile() ==
|
||||
PlayerManager::getCurrentOnlineProfile());
|
||||
NetworkPlayerProfile* profile = players[i];
|
||||
RemoteKartInfo rki(profile->race_id, profile->kart_name,
|
||||
profile->user_profile->getUserName(),
|
||||
profile->race_id, !is_me);
|
||||
rki.setDifficulty(profile->difficulty);
|
||||
rki.setGlobalPlayerId(profile->race_id);
|
||||
RemoteKartInfo rki(profile->getPlayerID(), profile->getKartName(),
|
||||
profile->getOnlineProfile()->getUserName(),
|
||||
profile->getPlayerID(), !is_me);
|
||||
rki.setPerPlayerDifficulty(profile->getPerPlayerDifficulty());
|
||||
rki.setGlobalPlayerId(profile->getPlayerID());
|
||||
// on the server, the race id must be the local one.
|
||||
rki.setLocalPlayerId(NetworkConfig::get()->isServer()
|
||||
? profile->race_id
|
||||
? profile->getPlayerID()
|
||||
: (is_me ? 0 : 1) );
|
||||
rki.setHostId(profile->race_id);
|
||||
rki.setHostId(profile->getPlayerID());
|
||||
Log::info("StartGameProtocol",
|
||||
"Creating kart %s for Player#%d with race_id %d",
|
||||
profile->kart_name.c_str(), i, profile->race_id);
|
||||
|
||||
profile->getKartName().c_str(), i,
|
||||
profile->getPlayerID());
|
||||
if (!is_me)
|
||||
{
|
||||
StateManager::get()->createActivePlayer( NULL, NULL );
|
||||
|
@ -76,8 +76,8 @@ public:
|
||||
void setGlobalPlayerId(int id) { m_global_player_id = id; }
|
||||
void setSoccerTeam(SoccerTeam team) { m_soccer_team = team; }
|
||||
void setNetworkPlayer(bool value) { m_network_player = value; }
|
||||
void setDifficulty(PerPlayerDifficulty value) { m_difficulty = value; }
|
||||
|
||||
void setPerPlayerDifficulty(PerPlayerDifficulty value)
|
||||
{ m_difficulty = value; }
|
||||
int getHostId() const { return m_host_id; }
|
||||
int getLocalPlayerId() const { return m_local_player_id; }
|
||||
int getGlobalPlayerId() const { return m_global_player_id; }
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "network/stk_peer.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/network_string.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/transport_address.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
|
@ -166,11 +166,12 @@ void RaceManager::setLocalKartSoccerTeam(unsigned int player_id, SoccerTeam team
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets the per-player difficulty for a player.
|
||||
*/
|
||||
void RaceManager::setPlayerDifficulty(unsigned int player_id, PerPlayerDifficulty difficulty)
|
||||
void RaceManager::setPlayerDifficulty(unsigned int player_id,
|
||||
PerPlayerDifficulty difficulty)
|
||||
{
|
||||
assert(player_id < m_local_player_karts.size());
|
||||
|
||||
m_local_player_karts[player_id].setDifficulty(difficulty);
|
||||
m_local_player_karts[player_id].setPerPlayerDifficulty(difficulty);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "items/item_manager.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/client_lobby_room_protocol.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
@ -85,22 +86,23 @@ void NetworkKartSelectionScreen::init()
|
||||
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
if (players[i]->user_profile == PlayerManager::getCurrentOnlineProfile())
|
||||
if (players[i]->getOnlineProfile()== PlayerManager::getCurrentOnlineProfile())
|
||||
{
|
||||
m_id_mapping.insert(m_id_mapping.begin(),players[i]->race_id); //!< first kart widget always me
|
||||
Log::info("NKSS", "Insert %d at pos 0", players[i]->race_id);
|
||||
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());
|
||||
continue; // it is me, don't add again
|
||||
}
|
||||
|
||||
Log::info("NKSS", "Adding %d at pos %d", players[i]->race_id, i);
|
||||
m_id_mapping.push_back(players[i]->race_id);
|
||||
Log::info("NKSS", "Adding %d at pos %d", players[i]->getPlayerID(), i);
|
||||
m_id_mapping.push_back(players[i]->getPlayerID());
|
||||
|
||||
StateManager::ActivePlayer* aplayer = NULL; // player is remote
|
||||
|
||||
std::string selected_kart_group = "standard"; // standard group
|
||||
|
||||
PlayerKartWidget* newPlayerWidget =
|
||||
new PlayerKartWidget(this, aplayer, players[i]->user_profile, kartsArea, m_kart_widgets.size(),
|
||||
new PlayerKartWidget(this, aplayer, players[i]->getOnlineProfile(),
|
||||
kartsArea, m_kart_widgets.size(),
|
||||
selected_kart_group);
|
||||
|
||||
manualAddWidget(newPlayerWidget);
|
||||
|
Loading…
Reference in New Issue
Block a user