Prevent clients removing too many official assets

This commit is contained in:
Benau 2018-11-26 16:38:11 +08:00
parent 9ed9787b6f
commit 9e066706aa
8 changed files with 87 additions and 2 deletions

View File

@ -66,6 +66,7 @@ std::string KartProperties::getPerPlayerDifficultyAsString(PerPlayerDifficulty d
*/
KartProperties::KartProperties(const std::string &filename)
{
m_is_addon = false;
m_icon_material = NULL;
m_minimap_icon = NULL;
m_name = "NONAME";
@ -212,7 +213,11 @@ void KartProperties::load(const std::string &filename, const std::string &node)
// case that an addon kart has the same directory name (and therefore
// identifier) as an included kart.
if(Addon::isAddon(filename))
{
m_ident = Addon::createAddonId(m_ident);
m_is_addon = true;
}
try
{
if(!root || root->getName()!="kart")

View File

@ -149,6 +149,8 @@ private:
*/
int8_t m_nitro_min_consumption;
bool m_is_addon;
/** Type of the kart (for the properties) */
std::string m_kart_type;
@ -513,6 +515,8 @@ public:
*/
int8_t getNitroMinConsumptionTicks() const
{ return m_nitro_min_consumption; }
// ------------------------------------------------------------------------
bool isAddon() const { return m_is_addon; }
/* <characteristics-end kpdefs> */

View File

@ -23,6 +23,7 @@
#include "items/powerup_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/controller/player_controller.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/linear_world.hpp"
#include "network/crypto.hpp"
@ -94,6 +95,30 @@
*/
ServerLobby::ServerLobby() : LobbyProtocol(NULL)
{
std::vector<int> all_k =
kart_properties_manager->getKartsInGroup("standard");
std::vector<int> all_t =
track_manager->getTracksInGroup("standard");
std::vector<int> all_arenas =
track_manager->getArenasInGroup("standard", false);
std::vector<int> all_soccers =
track_manager->getArenasInGroup("standard", true);
all_t.insert(all_t.end(), all_arenas.begin(), all_arenas.end());
all_t.insert(all_t.end(), all_soccers.begin(), all_soccers.end());
for (int kart : all_k)
{
const KartProperties* kp = kart_properties_manager->getKartById(kart);
if (!kp->isAddon())
m_official_kts.first.insert(kp->getIdent());
}
for (int track : all_t)
{
Track* t = track_manager->getTrack(track);
if (!t->isAddon())
m_official_kts.second.insert(t->getIdent());
}
m_last_success_poll_time.store(StkTime::getRealTimeMs() + 30000);
m_waiting_players_counts.store(0);
m_server_owner_id.store(-1);
@ -1459,6 +1484,23 @@ void ServerLobby::connectionRequested(Event* event)
// Drop this player if he doesn't have at least 1 kart / track the same
// as server
float okt = 0.0f;
float ott = 0.0f;
for (auto& client_kart : client_karts)
{
if (m_official_kts.first.find(client_kart) !=
m_official_kts.first.end())
okt += 1.0f;
}
okt = okt / (float)m_official_kts.first.size();
for (auto& client_track : client_tracks)
{
if (m_official_kts.second.find(client_track) !=
m_official_kts.second.end())
ott += 1.0f;
}
ott = ott / (float)m_official_kts.second.size();
std::set<std::string> karts_erase, tracks_erase;
for (const std::string& server_kart : m_available_kts.first)
{
@ -1476,7 +1518,9 @@ void ServerLobby::connectionRequested(Event* event)
}
if (karts_erase.size() == m_available_kts.first.size() ||
tracks_erase.size() == m_available_kts.second.size())
tracks_erase.size() == m_available_kts.second.size() ||
okt < ServerConfig::m_official_karts_threshold ||
ott < ServerConfig::m_official_tracks_threshold)
{
NetworkString *message = getNetworkString(2);
message->setSynchronous(true);

View File

@ -75,6 +75,9 @@ private:
std::atomic<uint32_t> m_server_owner_id;
/** Official karts and tracks available in server. */
std::pair<std::set<std::string>, std::set<std::string> > m_official_kts;
/** Available karts and tracks for all clients, this will be initialized
* with data in server first. */
std::pair<std::set<std::string>, std::set<std::string> > m_available_kts;

View File

@ -254,6 +254,11 @@ void loadServerLobbyFromConfig()
if (m_server_mode > 8)
m_server_mode = 3;
if (m_official_karts_threshold > 1.0f)
m_official_karts_threshold = 1.0f;
if (m_official_tracks_threshold > 1.0f)
m_official_tracks_threshold = 1.0f;
auto modes = getLocalGameMode();
race_manager->setMinorMode(modes.first);
race_manager->setMajorMode(modes.second);

View File

@ -176,6 +176,22 @@ namespace ServerConfig
"if satisfied min-start-game-players below for owner less or ranked "
"server."));
SERVER_CFG_PREFIX FloatServerConfigParam m_official_karts_threshold
SERVER_CFG_DEFAULT(FloatServerConfigParam(1.0f,
"official-karts-threshold",
"Clients below this value will be rejected from joining this server. "
"It's determined by number of official karts in client / number of "
"official karts in server"));
SERVER_CFG_PREFIX FloatServerConfigParam m_official_tracks_threshold
SERVER_CFG_DEFAULT(FloatServerConfigParam(0.7f,
"official-tracks-threshold",
"Clients below this value will be rejected from joining this server. "
"It's determined by number of official tracks in client / number of "
"official tracks in server, setting this value too high will prevent "
"android players from joining this server, because STK android apk "
"has some official tracks removed."));
SERVER_CFG_PREFIX IntServerConfigParam m_min_start_game_players
SERVER_CFG_DEFAULT(IntServerConfigParam(2, "min-start-game-players",
"Only auto start kart selection when number of "

View File

@ -116,7 +116,12 @@ Track::Track(const std::string &filename)
// case that an addon track has the same directory name (and therefore
// identifier) as an included track.
if(Addon::isAddon(filename))
{
m_ident = Addon::createAddonId(m_ident);
m_is_addon = true;
}
else
m_is_addon = false;
// The directory should always have a '/' at the end, but getBasename
// above returns "" if a "/" is at the end, so we add the "/" here.

View File

@ -334,6 +334,8 @@ private:
/** True if this track supports using smoothed normals. */
bool m_smooth_normals;
bool m_is_addon;
float m_fog_max;
float m_fog_start;
float m_fog_end;
@ -691,7 +693,8 @@ public:
const btTransform& getRedFlag() const { return m_red_flag; }
// ------------------------------------------------------------------------
const btTransform& getBlueFlag() const { return m_blue_flag; }
// ------------------------------------------------------------------------
bool isAddon() const { return m_is_addon; }
}; // class Track
#endif