mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 15:07:28 +00:00
fix: Remove usage of rand() and seed randomness for chatserver (#1152)
* Remove usage of rand(), time(0) to time(NULL) Replace it with the random engine mt19937. convert time(0) to time(NULL) * update * revert a bunch of changes
This commit is contained in:
parent
d8a5fd49a4
commit
040a78c386
@ -33,6 +33,7 @@ namespace Game {
|
||||
dChatFilter* chatFilter = nullptr;
|
||||
AssetManager* assetManager = nullptr;
|
||||
bool shouldShutdown = false;
|
||||
std::mt19937 randomEngine;
|
||||
}
|
||||
|
||||
|
||||
@ -115,6 +116,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(Game::config->GetValue("dont_generate_dcf"))));
|
||||
|
||||
Game::randomEngine = std::mt19937(time(0));
|
||||
|
||||
//Run it until server gets a kill message from Master:
|
||||
auto t = std::chrono::high_resolution_clock::now();
|
||||
Packet* packet = nullptr;
|
||||
|
@ -472,7 +472,7 @@ std::vector<uint32_t> BaseSurvivalServer::GetRandomMobSet(SpawnerNetworkCollecti
|
||||
if (mobSets.sets.find(spawnerNetworkCollection.mobSetName) != mobSets.sets.end()) {
|
||||
auto mobSet = mobSets.sets.at(spawnerNetworkCollection.mobSetName);
|
||||
if (setNumber < mobSet.size()) {
|
||||
return mobSet.at(setNumber).at(rand() % mobSet.at(setNumber).size());
|
||||
return mobSet.at(setNumber).at(GeneralUtils::GenerateRandomNumber<int32_t>(0, mobSet.at(setNumber).size() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -487,7 +487,7 @@ SpawnerNetwork BaseSurvivalServer::GetRandomSpawner(SpawnerNetworkCollection& sp
|
||||
}
|
||||
|
||||
if (!validSpawners.empty()) {
|
||||
auto spawner = validSpawners.at(rand() % validSpawners.size());
|
||||
auto spawner = validSpawners.at(GeneralUtils::GenerateRandomNumber<int32_t>(0, validSpawners.size() - 1));
|
||||
spawner.isActive = true;
|
||||
return spawner;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user