Teaspeak-Server/license/LicenseClientMain.cpp

116 lines
3.2 KiB
C++
Raw Normal View History

#include <iostream>
#include <shared/License.h>
#include <shared/LicenseRequest.h>
#include <event2/thread.h>
2019-09-22 06:36:30 -04:00
#include <random>
#include <ed25519/ed25519.h>
using namespace std;
using namespace std::chrono;
using namespace license;
/*
struct LicenseInfo {
LicenseType type;
std::string username;
std::string first_name;
std::string last_name;
std::string email;
std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point end;
std::chrono::system_clock::time_point creation;
inline bool isValid() { return (end.time_since_epoch().count() == 0 || std::chrono::system_clock::now() < this->end); }
};
*/
int main(int ac, char** av){
auto state = evthread_use_pthreads();
assert(state == 0);
2019-09-22 06:36:30 -04:00
string error;
2019-09-22 06:36:30 -04:00
std::array<uint8_t, 32> private_key, public_key;
std::random_device rd;
std::uniform_int_distribution<uint8_t> d;
uint8_t root_seed[64];
for(auto& e : root_seed)
e = d(rd);
ed25519_create_keypair(public_key.data(), private_key.data(), root_seed);
cout << "Key Pair generated:" << endl;
cout << "Private Key:" << hex;
for(auto& e : private_key)
cout << " 0x" << (e <= 0xF ? "0" : "") << (uint32_t) e << ",";
cout << endl;
cout << "Public Key :" << hex;
for(auto& e : public_key)
cout << " 0x" << (e <= 0xF ? "0" : "") << (uint32_t) e << ",";
cout << endl;
return true;
#if 0
srand(system_clock::now().time_since_epoch().count());
cout << "Generating new license" << endl;
std::string name = "WolverinDEV";
auto raw_license = createLocalLicence(LicenseType::PREMIUM, system_clock::now() - chrono::hours((int) (24 * 30.5 * 3)), "WolverinDEV");
auto license = readLocalLicence(raw_license, error);
assert(license);
sockaddr_in serv_addr{};
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = ((in_addr*) gethostbyname("localhost")->h_addr)->s_addr;
serv_addr.sin_port = htons(27786);
/*
* struct LicenseRequestData {
std::shared_ptr<License> license;
int64_t speach_total;
int64_t speach_dead;
int64_t speach_online;
int64_t speach_varianz;
int64_t client_online;
int64_t bots_online;
int64_t queries_online;
int64_t servers_online;
};
*/
auto data = make_shared<LicenseRequestData>();
data->license = license;
data->info = make_shared<ServerInfo>();
while(true) {
LicenceRequest request(data, serv_addr);
try {
cout << "Requesting license" << endl;
auto info = request.requestInfo().waitAndGet(nullptr);
if(!info) {
cout << "Invalid result! Error: " << (request.exception() ? "yes => " + string(request.exception()->what()) : "no") << endl;
throw *request.exception();
}
cout << "Got result!" << endl;
cout << "Valid: " << info->license_valid << endl;
if(info->license) {
cout << "License:" << endl;
cout << " Type: " << info->license->type << endl;
cout << " User name: " << info->license->username << endl;
cout << " First name: " << info->license->first_name << endl;
cout << " Last name: " << info->license->last_name << endl;
cout << " EMail: " << info->license->email << endl;
} else cout << "License: none";
} catch (const std::exception& ex){
cerr << "Could not load info after throwing: " << endl << ex.what() << endl;
}
}
2019-09-22 06:36:30 -04:00
#endif
return 0;
}