Skip to content

Commit a75f868

Browse files
committed
Check if not initialized
1 parent aa2eb22 commit a75f868

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

auth.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@
5656
static std::string hexDecode(const std::string& hex);
5757
std::string get_str_between_two_str(const std::string& s, const std::string& start_delim, const std::string& stop_delim);
5858
bool constantTimeStringCompare(const char* str1, const char* str2, size_t length);
59+
void checkInit();
5960
std::string checksum();
6061
void modify();
6162
void error(std::string message);
6263
std::string signature;
64+
bool initalized;
6365

6466
void KeyAuth::api::init()
6567
{
@@ -126,6 +128,7 @@ void KeyAuth::api::init()
126128
if (json[(XorStr("success"))])
127129
{
128130
sessionid = json[(XorStr("sessionid"))];
131+
initalized = true;
129132
load_app_data(json[(XorStr("appinfo"))]);
130133
}
131134
else if (json[(XorStr("message"))] == XorStr("invalidver"))
@@ -163,6 +166,8 @@ static size_t header_callback(char* buffer, size_t size, size_t nitems, void* us
163166

164167
void KeyAuth::api::login(std::string username, std::string password)
165168
{
169+
checkInit();
170+
166171
std::string hwid = utils::get_hwid();
167172
auto data =
168173
XorStr("type=login") +
@@ -202,6 +207,8 @@ void KeyAuth::api::login(std::string username, std::string password)
202207

203208
void KeyAuth::api::chatget(std::string channel)
204209
{
210+
checkInit();
211+
205212
auto data =
206213
XorStr("type=chatget") +
207214
XorStr("&channel=") + channel +
@@ -216,6 +223,8 @@ void KeyAuth::api::chatget(std::string channel)
216223

217224
bool KeyAuth::api::chatsend(std::string message, std::string channel)
218225
{
226+
checkInit();
227+
219228
auto data =
220229
XorStr("type=chatsend") +
221230
XorStr("&message=") + message +
@@ -232,6 +241,8 @@ bool KeyAuth::api::chatsend(std::string message, std::string channel)
232241

233242
void KeyAuth::api::changeusername(std::string newusername)
234243
{
244+
checkInit();
245+
235246
auto data =
236247
XorStr("type=changeUsername") +
237248
XorStr("&newUsername=") + newusername +
@@ -268,6 +279,7 @@ void KeyAuth::api::changeusername(std::string newusername)
268279

269280
void KeyAuth::api::web_login()
270281
{
282+
checkInit();
271283

272284
// from https://perpetualprogrammers.wordpress.com/2016/05/22/the-http-server-api/
273285

@@ -499,6 +511,7 @@ void KeyAuth::api::web_login()
499511

500512
void KeyAuth::api::button(std::string button)
501513
{
514+
checkInit();
502515

503516
// from https://perpetualprogrammers.wordpress.com/2016/05/22/the-http-server-api/
504517

@@ -626,6 +639,8 @@ void KeyAuth::api::button(std::string button)
626639
}
627640

628641
void KeyAuth::api::regstr(std::string username, std::string password, std::string key, std::string email) {
642+
checkInit();
643+
629644
std::string hwid = utils::get_hwid();
630645
auto data =
631646
XorStr("type=register") +
@@ -666,6 +681,8 @@ void KeyAuth::api::regstr(std::string username, std::string password, std::strin
666681
}
667682

668683
void KeyAuth::api::upgrade(std::string username, std::string key) {
684+
checkInit();
685+
669686
auto data =
670687
XorStr("type=upgrade") +
671688
XorStr("&username=") + username +
@@ -701,6 +718,8 @@ void KeyAuth::api::upgrade(std::string username, std::string key) {
701718
}
702719

703720
void KeyAuth::api::license(std::string key) {
721+
checkInit();
722+
704723
std::string hwid = utils::get_hwid();
705724
auto data =
706725
XorStr("type=license") +
@@ -738,6 +757,8 @@ void KeyAuth::api::license(std::string key) {
738757
}
739758

740759
void KeyAuth::api::setvar(std::string var, std::string vardata) {
760+
checkInit();
761+
741762
auto data =
742763
XorStr("type=setvar") +
743764
XorStr("&var=") + var +
@@ -751,6 +772,7 @@ void KeyAuth::api::setvar(std::string var, std::string vardata) {
751772
}
752773

753774
std::string KeyAuth::api::getvar(std::string var) {
775+
checkInit();
754776

755777
auto data =
756778
XorStr("type=getvar") +
@@ -786,6 +808,7 @@ std::string KeyAuth::api::getvar(std::string var) {
786808
}
787809

788810
void KeyAuth::api::ban(std::string reason) {
811+
checkInit();
789812

790813
auto data =
791814
XorStr("type=ban") +
@@ -820,6 +843,8 @@ void KeyAuth::api::ban(std::string reason) {
820843
}
821844

822845
bool KeyAuth::api::checkblack() {
846+
checkInit();
847+
823848
std::string hwid = utils::get_hwid();
824849
auto data =
825850
XorStr("type=checkblacklist") +
@@ -853,6 +878,8 @@ bool KeyAuth::api::checkblack() {
853878
}
854879

855880
void KeyAuth::api::check() {
881+
checkInit();
882+
856883
auto data =
857884
XorStr("type=check") +
858885
XorStr("&sessionid=") + sessionid +
@@ -886,6 +913,8 @@ void KeyAuth::api::check() {
886913
}
887914

888915
std::string KeyAuth::api::var(std::string varid) {
916+
checkInit();
917+
889918
auto data =
890919
XorStr("type=var") +
891920
XorStr("&varid=") + varid +
@@ -920,6 +949,7 @@ std::string KeyAuth::api::var(std::string varid) {
920949
}
921950

922951
void KeyAuth::api::log(std::string message) {
952+
checkInit();
923953

924954
char acUserName[100];
925955
DWORD nUserName = sizeof(acUserName);
@@ -938,6 +968,8 @@ void KeyAuth::api::log(std::string message) {
938968
}
939969

940970
std::vector<unsigned char> KeyAuth::api::download(std::string fileid) {
971+
checkInit();
972+
941973
auto to_uc_vector = [](std::string value) {
942974
return std::vector<unsigned char>(value.data(), value.data() + value.length() );
943975
};
@@ -985,6 +1017,8 @@ std::vector<unsigned char> KeyAuth::api::download(std::string fileid) {
9851017

9861018
std::string KeyAuth::api::webhook(std::string id, std::string params, std::string body, std::string contenttype)
9871019
{
1020+
checkInit();
1021+
9881022
CURL *curl = curl_easy_init();
9891023
auto data =
9901024
XorStr("type=webhook") +
@@ -1025,6 +1059,8 @@ std::string KeyAuth::api::webhook(std::string id, std::string params, std::strin
10251059

10261060
std::string KeyAuth::api::fetchonline()
10271061
{
1062+
checkInit();
1063+
10281064
auto data =
10291065
XorStr("type=fetchOnline") +
10301066
XorStr("&sessionid=") + sessionid +
@@ -1063,6 +1099,8 @@ std::string KeyAuth::api::fetchonline()
10631099

10641100
void KeyAuth::api::forgot(std::string username, std::string email)
10651101
{
1102+
checkInit();
1103+
10661104
auto data =
10671105
XorStr("type=forgot") +
10681106
XorStr("&username=") + username +
@@ -1267,6 +1305,12 @@ bool constantTimeStringCompare(const char* str1, const char* str2, size_t length
12671305

12681306
return result == 0;
12691307
}
1308+
1309+
void checkInit() {
1310+
if (!initalized) {
1311+
error("You need to run the KeyAuthApp.init(); function before any other KeyAuth functions");
1312+
}
1313+
}
12701314
// code submitted in pull request from https://github.com/BINM7MD
12711315
BOOL bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
12721316
{

0 commit comments

Comments
 (0)