Files
Teaspeak-Server/server/src/client/voice/PrecomputedPuzzles.h
T
WolverinDEV 7ef77c3160 Some updates
2020-04-10 23:29:51 +02:00

39 lines
852 B
C++

#pragma once
#include <tommath.h>
#include <memory>
#include <vector>
#include <misc/spin_lock.h>
#include <random>
namespace ts::server::udp {
struct Puzzle {
mp_int x;
mp_int n;
int level;
mp_int result;
uint8_t data_x[64];
uint8_t data_n[64];
uint8_t data_result[64];
};
class PuzzleManager {
public:
PuzzleManager();
~PuzzleManager();
[[nodiscard]] bool precompute_puzzles(size_t amount);
[[nodiscard]] size_t precomputed_puzzle_count();
[[nodiscard]] std::shared_ptr<Puzzle> next_puzzle();
private:
void generate_puzzle(std::mt19937&);
size_t cache_index{0};
spin_lock cache_lock{};
std::vector<std::shared_ptr<Puzzle>> cached_puzzles{};
};
}