Skip to content

Commit

Permalink
Merge pull request #792 from openmultiplayer/hual/config_options
Browse files Browse the repository at this point in the history
Add config options to disable animation validation and join messages
  • Loading branch information
AmyrAhmady authored Dec 1, 2023
2 parents f09bd5c + f9d882a commit 5490c87
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
6 changes: 4 additions & 2 deletions Server/Components/Actors/actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Actor final : public IActor, public PoolIDProvider, public NoCopy
AnimationData animation_;
ActorSpawnData spawnData_;
bool* allAnimationLibraries_;
bool* validateAnimations_;
ICustomModelsComponent*& modelsComponent_;
IFixesComponent* fixesComponent_;

Expand Down Expand Up @@ -102,7 +103,7 @@ class Actor final : public IActor, public PoolIDProvider, public NoCopy
}
}

Actor(int skin, Vector3 pos, float angle, bool* allAnimationLibraries, ICustomModelsComponent*& modelsComponent, IFixesComponent* fixesComponent)
Actor(int skin, Vector3 pos, float angle, bool* allAnimationLibraries, bool* validateAnimations, ICustomModelsComponent*& modelsComponent, IFixesComponent* fixesComponent)
: virtualWorld_(0)
, skin_(skin)
, invulnerable_(true)
Expand All @@ -112,6 +113,7 @@ class Actor final : public IActor, public PoolIDProvider, public NoCopy
, health_(100.f)
, spawnData_ { pos, angle, skin }
, allAnimationLibraries_(allAnimationLibraries)
, validateAnimations_(validateAnimations)
, modelsComponent_(modelsComponent)
, fixesComponent_(fixesComponent)
{
Expand Down Expand Up @@ -144,7 +146,7 @@ class Actor final : public IActor, public PoolIDProvider, public NoCopy

void applyAnimation(const AnimationData& animation) override
{
if (!animationLibraryValid(animation.lib, *allAnimationLibraries_))
if ((!validateAnimations_ || *validateAnimations_) && !animationLibraryValid(animation.lib, *allAnimationLibraries_))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/Actors/actors_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ActorsComponent final : public IActorsComponent, public PlayerConnectEvent

IActor* create(int skin, Vector3 pos, float angle) override
{
return storage.emplace(skin, pos, angle, core->getConfig().getBool("game.use_all_animations"), modelsComponent, fixesComponent_);
return storage.emplace(skin, pos, angle, core->getConfig().getBool("game.use_all_animations"), core->getConfig().getBool("game.validate_animations"), modelsComponent, fixesComponent_);
}

void free() override
Expand Down
2 changes: 2 additions & 0 deletions Server/Source/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ static const std::map<String, ConfigStorage> Defaults {
{ "game.use_zone_names", false },
{ "game.vehicle_respawn_time", 10000 },
{ "game.weather", 10 },
{ "game.validate_animations", true },
{ "game.use_all_animations", true },
{ "game.lag_compensation_mode", LagCompMode_Enabled },
{ "game.group_player_objects", false },
// logging
{ "logging.enable", true },
{ "logging.file", String("log.txt") },
{ "logging.log_chat", true },
{ "logging.log_connection_messages", true },
{ "logging.log_cookies", false },
{ "logging.log_deaths", true },
{ "logging.log_queries", false },
Expand Down
6 changes: 4 additions & 2 deletions Server/Source/player_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
TimePoint lastScoresAndPings_;
bool kicked_;
bool* allAnimationLibraries_;
bool* validateAnimations_;
bool* allowInteriorWeapons_;

IFixesComponent* fixesComponent_;
Expand Down Expand Up @@ -202,7 +203,7 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
IExtensible::resetExtensions();
}

Player(PlayerPool& pool, const PeerNetworkData& netData, const PeerRequestParams& params, bool* allAnimationLibraries, bool* allowInteriorWeapons, IFixesComponent* fixesComponent)
Player(PlayerPool& pool, const PeerNetworkData& netData, const PeerRequestParams& params, bool* allAnimationLibraries, bool* validateAnimations, bool* allowInteriorWeapons, IFixesComponent* fixesComponent)
: pool_(pool)
, netData_(netData)
, version_(params.version)
Expand Down Expand Up @@ -259,6 +260,7 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
, lastScoresAndPings_(Time::now())
, kicked_(false)
, allAnimationLibraries_(allAnimationLibraries)
, validateAnimations_(validateAnimations)
, allowInteriorWeapons_(allowInteriorWeapons)
, fixesComponent_(fixesComponent)
{
Expand Down Expand Up @@ -751,7 +753,7 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
public:
void applyAnimation(const AnimationData& animation, PlayerAnimationSyncType syncType) override
{
if (!animationLibraryValid(animation.lib, *allAnimationLibraries_))
if ((!validateAnimations_ || *validateAnimations_) && !animationLibraryValid(animation.lib, *allAnimationLibraries_))
{
return;
}
Expand Down
43 changes: 26 additions & 17 deletions Server/Source/player_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
float* markersLimitRadius;
int* gameTimeUpdateRate;
bool* useAllAnimations_;
bool* validateAnimations_;
bool* allowInteriorWeapons_;
int* maxBots;
StaticArray<bool, 256> allowNickCharacter;
Expand Down Expand Up @@ -1634,7 +1635,7 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
return { NewConnectionResult_BadName, nullptr };
}

Player* result = storage.emplace(*this, netData, params, useAllAnimations_, allowInteriorWeapons_, fixesComponent_);
Player* result = storage.emplace(*this, netData, params, useAllAnimations_, validateAnimations_, allowInteriorWeapons_, fixesComponent_);
if (!result)
{
return { NewConnectionResult_NoPlayerSlot, nullptr };
Expand Down Expand Up @@ -1692,20 +1693,24 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
}

// Set player's time & weather to global ones.
static int* hour = core.getConfig().getInt("game.time");
static int* weather = core.getConfig().getInt("game.weather");
IConfig& config = core.getConfig();
static int* hour = config.getInt("game.time");
static int* weather = config.getInt("game.weather");

player.time_ = duration_cast<Minutes>(Hours(*hour));
player.weather_ = *weather;
player.gravity_ = core.getGravity();

core.logLn(
LogLevel::Message,
"[%sjoin] %.*s has joined the server (%d:%s)",
player.isBot_ ? "npc:" : "",
PRINT_VIEW(player.name_),
player.poolID,
addressString.data());
if (config.getBool("logging.log_connection_messages"))
{
core.logLn(
LogLevel::Message,
"[%sjoin] %.*s has joined the server (%d:%s)",
player.isBot_ ? "npc:" : "",
PRINT_VIEW(player.name_),
player.poolID,
addressString.data());
}

NetCode::RPC::SendGameTimeUpdate RPC;
RPC.Time = duration_cast<Milliseconds>(Time::now().time_since_epoch()).count();
Expand Down Expand Up @@ -1756,13 +1761,16 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
packet.Reason = reason;
PacketHelper::broadcast(packet, *this);

core.logLn(
LogLevel::Message,
"[%spart] %.*s has left the server (%d:%d)",
player.isBot_ ? "npc:" : "",
PRINT_VIEW(player.name_),
player.poolID,
reason);
if (core.getConfig().getBool("logging.log_connection_messages"))
{
core.logLn(
LogLevel::Message,
"[%spart] %.*s has left the server (%d:%d)",
player.isBot_ ? "npc:" : "",
PRINT_VIEW(player.name_),
player.poolID,
reason);
}

auto& secondaryPool = player.isBot_ ? botList : playerList;
secondaryPool.erase(&player);
Expand Down Expand Up @@ -1969,6 +1977,7 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
markersUpdateRate = config.getInt("network.player_marker_sync_rate");
gameTimeUpdateRate = config.getInt("network.time_sync_rate");
useAllAnimations_ = config.getBool("game.use_all_animations");
validateAnimations_ = config.getBool("game.validate_animations");
allowInteriorWeapons_ = config.getBool("game.allow_interior_weapons");
maxBots = config.getInt("max_bots");

Expand Down

0 comments on commit 5490c87

Please sign in to comment.