2017-02-26 21:00:51 +00:00
|
|
|
#include "Miscellaneous.hpp"
|
2017-08-18 04:13:08 +00:00
|
|
|
|
2019-08-19 18:39:33 +00:00
|
|
|
#include <components/openmw-mp/TimedLog.hpp>
|
2017-08-18 04:13:08 +00:00
|
|
|
|
2017-02-26 21:00:51 +00:00
|
|
|
#include <apps/openmw-mp/Networking.hpp>
|
|
|
|
|
2019-09-21 11:22:19 +00:00
|
|
|
#include <extern/PicoSHA2/picosha2.h>
|
|
|
|
|
2017-02-26 21:00:51 +00:00
|
|
|
#include <iostream>
|
2019-09-21 11:22:19 +00:00
|
|
|
#include <random>
|
|
|
|
|
|
|
|
const char *MiscellaneousFunctions::GenerateRandomString(unsigned int length) noexcept
|
|
|
|
{
|
|
|
|
const std::string characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
|
|
|
std::random_device randomDevice;
|
|
|
|
std::mt19937 generator(randomDevice());
|
2020-02-09 11:04:08 +00:00
|
|
|
std::uniform_int_distribution<std::mt19937::result_type> distribution(0, characters.size() - 1);
|
2019-09-21 11:22:19 +00:00
|
|
|
|
2020-02-09 11:04:08 +00:00
|
|
|
/* WARNING: this function is no longer reentrant with a static variable */
|
|
|
|
static std::string randomString;
|
2019-09-21 11:22:19 +00:00
|
|
|
|
|
|
|
for (std::size_t i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
randomString += characters[distribution(generator)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return randomString.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MiscellaneousFunctions::GetSHA256Hash(const char* inputString) noexcept
|
|
|
|
{
|
2020-02-09 11:04:08 +00:00
|
|
|
/* WARNING: this function is no longer reentrant with a static variable */
|
|
|
|
static std::string hashString = picosha2::hash256_hex_string(std::string{inputString});
|
2019-09-21 11:22:19 +00:00
|
|
|
|
|
|
|
return hashString.c_str();
|
|
|
|
}
|
|
|
|
|
2017-02-26 21:00:51 +00:00
|
|
|
unsigned int MiscellaneousFunctions::GetLastPlayerId() noexcept
|
|
|
|
{
|
|
|
|
return Players::getLastPlayerId();
|
|
|
|
}
|
2017-04-03 22:47:37 +00:00
|
|
|
|
2017-04-04 09:43:17 +00:00
|
|
|
int MiscellaneousFunctions::GetCurrentMpNum() noexcept
|
|
|
|
{
|
|
|
|
return mwmp::Networking::getPtr()->getCurrentMpNum();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MiscellaneousFunctions::SetCurrentMpNum(int mpNum) noexcept
|
|
|
|
{
|
|
|
|
mwmp::Networking::getPtr()->setCurrentMpNum(mpNum);
|
|
|
|
}
|