Skip to content

Commit a4f5b1d

Browse files
Merge pull request #28 from Shxde1/main
Making classes simiilar to C# and added requested code
2 parents 6b540e4 + 1f5464b commit a4f5b1d

File tree

2 files changed

+60
-28
lines changed

2 files changed

+60
-28
lines changed

auth.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ bool KeyAuth::api::chatsend(std::string message, std::string channel)
250250
return json[("success")];
251251
}
252252

253-
void KeyAuth::api::changeusername(std::string newusername)
253+
void KeyAuth::api::changeUsername(std::string newusername)
254254
{
255255
checkInit();
256256

@@ -1143,7 +1143,7 @@ std::string KeyAuth::api::fetchonline()
11431143

11441144
std::string onlineusers;
11451145

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

12621262
debugInfo(data, url, to_return);
12631263

1264+
struct curl_certinfo* ci;
1265+
code = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
1266+
1267+
if (!code) {
1268+
bool issuer_found = false;
1269+
1270+
for (int i = 0; i < ci->num_of_certs; i++) {
1271+
struct curl_slist* slist;
1272+
1273+
for (slist = ci->certinfo[i]; slist; slist = slist->next) {
1274+
if (std::strstr(slist->data, XorStr("Google Trust Services").c_str()) != NULL || std::strstr(slist->data, XorStr("Let's Encrypt").c_str()) != NULL) {
1275+
issuer_found = true;
1276+
}
1277+
}
1278+
}
1279+
1280+
if (!issuer_found)
1281+
error(XorStr("SSL certificate couldn't be verified"));
1282+
}
1283+
12641284
return to_return;
12651285
}
12661286
void error(std::string message) {

auth.hpp

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace KeyAuth {
3737
void regstr(std::string username, std::string password, std::string key, std::string email = "");
3838
void chatget(std::string channel);
3939
bool chatsend(std::string message, std::string channel);
40-
void changeusername(std::string newusername);
40+
void changeUsername(std::string newusername);
4141
std::string fetchonline();
4242
void fetchstats();
4343
void forgot(std::string username, std::string email);
@@ -48,14 +48,9 @@ namespace KeyAuth {
4848
std::string expiry;
4949
};
5050

51-
class data_class {
51+
class userdata {
5252
public:
53-
// app data
54-
std::string numUsers;
55-
std::string numOnlineUsers;
56-
std::string numKeys;
57-
std::string version;
58-
std::string customerPanelLink;
53+
5954
// user data
6055
std::string username;
6156
std::string ip;
@@ -64,54 +59,71 @@ namespace KeyAuth {
6459
std::string lastlogin;
6560

6661
std::vector<subscriptions_class> subscriptions;
62+
};
6763

64+
class appdata {
65+
public:
66+
// app data
67+
std::string numUsers;
68+
std::string numOnlineUsers;
69+
std::string numKeys;
70+
std::string version;
71+
std::string customerPanelLink;
72+
};
73+
74+
class responsedata {
75+
public:
6876
// response data
6977
std::vector<channel_struct> channeldata;
7078
bool success{};
7179
std::string message;
7280
};
73-
data_class data;
81+
82+
userdata user_data;
83+
appdata app_data;
84+
responsedata response;
7485
private:
7586
std::string sessionid, enckey;
7687

7788
static std::string req(std::string data, std::string url);
89+
7890

7991
void load_user_data(nlohmann::json data) {
80-
api::data.username = data["username"];
81-
api::data.ip = data["ip"];
92+
api::user_data.username = data["username"];
93+
api::user_data.ip = data["ip"];
8294
if (data["hwid"].is_null()) {
83-
api::data.hwid = "none";
95+
api::user_data.hwid = "none";
8496
}
8597
else {
86-
api::data.hwid = data["hwid"];
98+
api::user_data.hwid = data["hwid"];
8799
}
88-
api::data.createdate = data["createdate"];
89-
api::data.lastlogin = data["lastlogin"];
100+
api::user_data.createdate = data["createdate"];
101+
api::user_data.lastlogin = data["lastlogin"];
90102

91103
for (int i = 0; i < data["subscriptions"].size(); i++) { // Prompto#7895 & stars#2297 was here
92104
subscriptions_class subscriptions;
93105
subscriptions.name = data["subscriptions"][i]["subscription"];
94106
subscriptions.expiry = data["subscriptions"][i]["expiry"];
95-
api::data.subscriptions.emplace_back(subscriptions);
107+
api::user_data.subscriptions.emplace_back(subscriptions);
96108
}
97109
}
98110

99111
void load_app_data(nlohmann::json data) {
100-
api::data.numUsers = data["numUsers"];
101-
api::data.numOnlineUsers = data["numOnlineUsers"];
102-
api::data.numKeys = data["numKeys"];
103-
api::data.version = data["version"];
104-
api::data.customerPanelLink = data["customerPanelLink"];
112+
api::app_data.numUsers = data["numUsers"];
113+
api::app_data.numOnlineUsers = data["numOnlineUsers"];
114+
api::app_data.numKeys = data["numKeys"];
115+
api::app_data.version = data["version"];
116+
api::app_data.customerPanelLink = data["customerPanelLink"];
105117
}
106118

107119
void load_response_data(nlohmann::json data) {
108-
api::data.success = data["success"];
109-
api::data.message = data["message"];
120+
api::response.success = data["success"];
121+
api::response.message = data["message"];
110122
}
111123

112124
void load_channel_data(nlohmann::json data) {
113-
api::data.success = data["success"];
114-
api::data.message = data["message"];
125+
api::response.success = data["success"];
126+
api::response.message = data["message"];
115127
for (const auto sub : data["messages"]) {
116128

117129
std::string authoroutput = sub["author"];
@@ -121,7 +133,7 @@ namespace KeyAuth {
121133
messageoutput.erase(remove(messageoutput.begin(), messageoutput.end(), '"'), messageoutput.end());
122134
timestampoutput.erase(remove(timestampoutput.begin(), timestampoutput.end(), '"'), timestampoutput.end());
123135
channel_struct output = { authoroutput , messageoutput, timestampoutput };
124-
api::data.channeldata.push_back(output);
136+
api::response.channeldata.push_back(output);
125137
}
126138
}
127139

0 commit comments

Comments
 (0)