Skip to content

Commit

Permalink
Made bloodstains and ghosts in-memory only for both games. Increaase …
Browse files Browse the repository at this point in the history
…database trim time to 8 hours as it should be a lot more lightweight now.
  • Loading branch information
TLeonardUK committed Mar 18, 2024
1 parent 0fe30e8 commit c5a12ff
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ MessageHandleResult DS2_BloodstainManager::OnMessageRecieved(GameClient* Client,

MessageHandleResult DS2_BloodstainManager::Handle_RequestCreateBloodstain(GameClient* Client, const Frpg2ReliableUdpMessage& Message)
{
const RuntimeConfig& Config = ServerInstance->GetConfig();
ServerDatabase& Database = ServerInstance->GetDatabase();
PlayerState& Player = Client->GetPlayerState();

Expand All @@ -99,7 +100,31 @@ MessageHandleResult DS2_BloodstainManager::Handle_RequestCreateBloodstain(GameCl
Data.assign(Request->data().data(), Request->data().data() + Request->data().size());
GhostData.assign(Request->ghost_data().data(), Request->ghost_data().data() + Request->ghost_data().size());

if (std::shared_ptr<Bloodstain> ActiveStain = Database.CreateBloodstain((uint32_t)Request->online_area_id(), (uint64_t)Request->cell_id(), Player.GetPlayerId(), Player.GetSteamId(), Data, GhostData))
std::shared_ptr<Bloodstain> ActiveStain = nullptr;
if (Config.BloodstainMemoryCacheOnly)
{
ActiveStain = std::make_shared<Bloodstain>();
ActiveStain->BloodstainId = (uint32_t)NextMemoryCacheStainId--;
ActiveStain->OnlineAreaId = (uint32_t)Request->online_area_id();
ActiveStain->CellId = (uint64_t)Request->cell_id();
ActiveStain->PlayerId = Player.GetPlayerId();
ActiveStain->PlayerSteamId = Player.GetSteamId();
ActiveStain->Data = Data;
ActiveStain->GhostData = GhostData;
}
else
{
ActiveStain = Database.CreateBloodstain(
(uint32_t)Request->online_area_id(),
0,
Player.GetPlayerId(),
Player.GetSteamId(),
Data,
GhostData
);
}

if (ActiveStain)
{
LiveCache.Add({ ActiveStain->CellId, (DS2_OnlineAreaId)ActiveStain->OnlineAreaId }, ActiveStain->BloodstainId, ActiveStain);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ class DS2_BloodstainManager

OnlineAreaPool<DS2_CellAndAreaId, Bloodstain> LiveCache;

uint32_t NextMemoryCacheStainId = std::numeric_limits<uint32_t>::max();

};
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ MessageHandleResult DS3_BloodstainManager::OnMessageRecieved(GameClient* Client,

MessageHandleResult DS3_BloodstainManager::Handle_RequestCreateBloodstain(GameClient* Client, const Frpg2ReliableUdpMessage& Message)
{
const RuntimeConfig& Config = ServerInstance->GetConfig();
ServerDatabase& Database = ServerInstance->GetDatabase();
PlayerState& Player = Client->GetPlayerState();

Expand All @@ -95,8 +96,32 @@ MessageHandleResult DS3_BloodstainManager::Handle_RequestCreateBloodstain(GameCl
std::vector<uint8_t> GhostData;
Data.assign(Request->data().data(), Request->data().data() + Request->data().size());
GhostData.assign(Request->ghost_data().data(), Request->ghost_data().data() + Request->ghost_data().size());

std::shared_ptr<Bloodstain> ActiveStain = nullptr;
if (Config.BloodstainMemoryCacheOnly)
{
ActiveStain = std::make_shared<Bloodstain>();
ActiveStain->BloodstainId = (uint32_t)NextMemoryCacheStainId--;
ActiveStain->OnlineAreaId = (uint32_t)Request->online_area_id();
ActiveStain->CellId = 0;
ActiveStain->PlayerId = Player.GetPlayerId();
ActiveStain->PlayerSteamId = Player.GetSteamId();
ActiveStain->Data = Data;
ActiveStain->GhostData = GhostData;
}
else
{
ActiveStain = Database.CreateBloodstain(
(uint32_t)Request->online_area_id(),
0,
Player.GetPlayerId(),
Player.GetSteamId(),
Data,
GhostData
);
}

if (std::shared_ptr<Bloodstain> ActiveStain = Database.CreateBloodstain((uint32_t)Request->online_area_id(), 0, Player.GetPlayerId(), Player.GetSteamId(), Data, GhostData))
if (ActiveStain)
{
LiveCache.Add((DS3_OnlineAreaId)ActiveStain->OnlineAreaId, ActiveStain->BloodstainId, ActiveStain);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ class DS3_BloodstainManager

OnlineAreaPool<DS3_OnlineAreaId, Bloodstain> LiveCache;

uint32_t NextMemoryCacheStainId = std::numeric_limits<uint32_t>::max();

};
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ MessageHandleResult DS3_GhostManager::OnMessageRecieved(GameClient* Client, cons

MessageHandleResult DS3_GhostManager::Handle_RequestCreateGhostData(GameClient* Client, const Frpg2ReliableUdpMessage& Message)
{
const RuntimeConfig& Config = ServerInstance->GetConfig();
ServerDatabase& Database = ServerInstance->GetDatabase();
PlayerState& Player = Client->GetPlayerState();

Expand All @@ -90,7 +91,28 @@ MessageHandleResult DS3_GhostManager::Handle_RequestCreateGhostData(GameClient*
std::vector<uint8_t> Data;
Data.assign(Request->data().data(), Request->data().data() + Request->data().size());

if (std::shared_ptr<Ghost> ActiveGhost = Database.CreateGhost((uint32_t)Request->online_area_id(), 0, Player.GetPlayerId(), Player.GetSteamId(), Data))
std::shared_ptr<Ghost> ActiveGhost = nullptr;
if (Config.GhostMemoryCacheOnly)
{
ActiveGhost = std::make_shared<Ghost>();
ActiveGhost->GhostId = (uint32_t)NextMemoryCacheGhostId--;
ActiveGhost->OnlineAreaId = (uint32_t)Request->online_area_id();
ActiveGhost->CellId = 0;
ActiveGhost->PlayerId = Player.GetPlayerId();
ActiveGhost->PlayerSteamId = Player.GetSteamId();
ActiveGhost->Data = Data;
}
else
{
ActiveGhost = Database.CreateGhost(
(uint32_t)Request->online_area_id(),
0,
Player.GetPlayerId(),
Player.GetSteamId(),
Data);
}

if (ActiveGhost)
{
LiveCache.Add((DS3_OnlineAreaId)ActiveGhost->OnlineAreaId, ActiveGhost->GhostId, ActiveGhost);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ class DS3_GhostManager

OnlineAreaPool<DS3_OnlineAreaId, Ghost> LiveCache;

uint32_t NextMemoryCacheGhostId = std::numeric_limits<uint32_t>::max();

};
1 change: 1 addition & 0 deletions Source/Server/Config/RuntimeConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ bool RuntimeConfig::Serialize(nlohmann::json& Json, bool Loading)
SERIALIZE_VAR(BloodstainMaxLivePoolEntriesPerArea);
SERIALIZE_VAR(BloodstainMaxDatabaseEntries);
SERIALIZE_VAR(BloodstainPrimeCountPerArea);
SERIALIZE_VAR(BloodstainMemoryCacheOnly);
SERIALIZE_VAR(GhostMaxLivePoolEntriesPerArea);
SERIALIZE_VAR(GhostPrimeCountPerArea);
SERIALIZE_VAR(GhostPrimeCountPerArea);
Expand Down
6 changes: 5 additions & 1 deletion Source/Server/Config/RuntimeConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class RuntimeConfig
};

// How often (in seconds) between each database trim.
double DatabaseTrimInterval = 60 * 60;
double DatabaseTrimInterval = 60 * 60 * 8;

// Maximum number of blood messages to store per area in the cache.
// If greater than this value are added, the oldest will be removed.
Expand All @@ -247,6 +247,10 @@ class RuntimeConfig
// Maximum number of bloodstains to store in database. More than this will be trimmed.
int BloodstainMaxDatabaseEntries = 1000;

// If set to true bloodstain will only be stored in the memory-cache, and not persistently
// on disk.
bool BloodstainMemoryCacheOnly = true;

// Maximum number of ghoststo store per area in the cache.
// If greater than this value are added, the oldest will be removed.
int GhostMaxLivePoolEntriesPerArea = 50;
Expand Down

0 comments on commit c5a12ff

Please sign in to comment.