Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making classes simiilar to C# and added requested code #28

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ bool KeyAuth::api::chatsend(std::string message, std::string channel)
return json[("success")];
}

void KeyAuth::api::changeusername(std::string newusername)
void KeyAuth::api::changeUsername(std::string newusername)
{
checkInit();

Expand Down Expand Up @@ -1143,7 +1143,7 @@ std::string KeyAuth::api::fetchonline()

std::string onlineusers;

int y = atoi(api::data.numOnlineUsers.c_str());
int y = atoi(api::app_data.numOnlineUsers.c_str());
for (int i = 0; i < y; i++)
{
onlineusers.append(json[XorStr("users")][i][XorStr("credential")]); onlineusers.append(XorStr("\n"));
Expand Down Expand Up @@ -1261,6 +1261,26 @@ std::string KeyAuth::api::req(std::string data, std::string url) {

debugInfo(data, url, to_return);

struct curl_certinfo* ci;
code = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);

if (!code) {
bool issuer_found = false;

for (int i = 0; i < ci->num_of_certs; i++) {
struct curl_slist* slist;

for (slist = ci->certinfo[i]; slist; slist = slist->next) {
if (std::strstr(slist->data, XorStr("Google Trust Services").c_str()) != NULL || std::strstr(slist->data, XorStr("Let's Encrypt").c_str()) != NULL) {
issuer_found = true;
}
}
}

if (!issuer_found)
error(XorStr("SSL certificate couldn't be verified"));
}

return to_return;
}
void error(std::string message) {
Expand Down
64 changes: 38 additions & 26 deletions auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace KeyAuth {
void regstr(std::string username, std::string password, std::string key, std::string email = "");
void chatget(std::string channel);
bool chatsend(std::string message, std::string channel);
void changeusername(std::string newusername);
void changeUsername(std::string newusername);
std::string fetchonline();
void fetchstats();
void forgot(std::string username, std::string email);
Expand All @@ -48,14 +48,9 @@ namespace KeyAuth {
std::string expiry;
};

class data_class {
class userdata {
public:
// app data
std::string numUsers;
std::string numOnlineUsers;
std::string numKeys;
std::string version;
std::string customerPanelLink;

// user data
std::string username;
std::string ip;
Expand All @@ -64,54 +59,71 @@ namespace KeyAuth {
std::string lastlogin;

std::vector<subscriptions_class> subscriptions;
};

class appdata {
public:
// app data
std::string numUsers;
std::string numOnlineUsers;
std::string numKeys;
std::string version;
std::string customerPanelLink;
};

class responsedata {
public:
// response data
std::vector<channel_struct> channeldata;
bool success{};
std::string message;
};
data_class data;

userdata user_data;
appdata app_data;
responsedata response;
private:
std::string sessionid, enckey;

static std::string req(std::string data, std::string url);


void load_user_data(nlohmann::json data) {
api::data.username = data["username"];
api::data.ip = data["ip"];
api::user_data.username = data["username"];
api::user_data.ip = data["ip"];
if (data["hwid"].is_null()) {
api::data.hwid = "none";
api::user_data.hwid = "none";
}
else {
api::data.hwid = data["hwid"];
api::user_data.hwid = data["hwid"];
}
api::data.createdate = data["createdate"];
api::data.lastlogin = data["lastlogin"];
api::user_data.createdate = data["createdate"];
api::user_data.lastlogin = data["lastlogin"];

for (int i = 0; i < data["subscriptions"].size(); i++) { // Prompto#7895 & stars#2297 was here
subscriptions_class subscriptions;
subscriptions.name = data["subscriptions"][i]["subscription"];
subscriptions.expiry = data["subscriptions"][i]["expiry"];
api::data.subscriptions.emplace_back(subscriptions);
api::user_data.subscriptions.emplace_back(subscriptions);
}
}

void load_app_data(nlohmann::json data) {
api::data.numUsers = data["numUsers"];
api::data.numOnlineUsers = data["numOnlineUsers"];
api::data.numKeys = data["numKeys"];
api::data.version = data["version"];
api::data.customerPanelLink = data["customerPanelLink"];
api::app_data.numUsers = data["numUsers"];
api::app_data.numOnlineUsers = data["numOnlineUsers"];
api::app_data.numKeys = data["numKeys"];
api::app_data.version = data["version"];
api::app_data.customerPanelLink = data["customerPanelLink"];
}

void load_response_data(nlohmann::json data) {
api::data.success = data["success"];
api::data.message = data["message"];
api::response.success = data["success"];
api::response.message = data["message"];
}

void load_channel_data(nlohmann::json data) {
api::data.success = data["success"];
api::data.message = data["message"];
api::response.success = data["success"];
api::response.message = data["message"];
for (const auto sub : data["messages"]) {

std::string authoroutput = sub["author"];
Expand All @@ -121,7 +133,7 @@ namespace KeyAuth {
messageoutput.erase(remove(messageoutput.begin(), messageoutput.end(), '"'), messageoutput.end());
timestampoutput.erase(remove(timestampoutput.begin(), timestampoutput.end(), '"'), timestampoutput.end());
channel_struct output = { authoroutput , messageoutput, timestampoutput };
api::data.channeldata.push_back(output);
api::response.channeldata.push_back(output);
}
}

Expand Down