Skip to content

Commit 9f8f28d

Browse files
author
William Nelson
authored
Merge pull request KeyAuth#44 from mazk5145/main
Added FetchOnline, ChatGet, ChatGet + Examples for them
2 parents 22c286b + 716b5cb commit 9f8f28d

File tree

4 files changed

+99
-4
lines changed

4 files changed

+99
-4
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 KeyAuth
3+
Copyright (c) 2022 KeyAuth
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# KeyAuth-Python-Example
2-
KeyAuth Python Example For The https://keyauth.win Authentication system.
2+
KeyAuth Python Example For The https://keyauth.cc Authentication system.
33

44
# Instructions
55

@@ -20,4 +20,4 @@ Setup video: https://www.youtube.com/watch?v=L2eAQOmuUiA
2020
**What is KeyAuth?**
2121

2222
KeyAuth is a GameChanging authentication system. We have never-seen before features, and we listen to our customers.
23-
Feel free to join https://keyauth.win/discord/ if you have questions or suggestions.
23+
Feel free to join https://keyauth.cc/discord/ if you have questions or suggestions.

keyauth.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,78 @@ def log(self, message):
412412
}
413413

414414
self.__do_request(post_data)
415+
416+
def fetchOnline(self):
417+
self.checkinit()
418+
init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
419+
420+
post_data = {
421+
"type": binascii.hexlify(("fetchOnline").encode()),
422+
"sessionid": binascii.hexlify(self.sessionid.encode()),
423+
"name": binascii.hexlify(self.name.encode()),
424+
"ownerid": binascii.hexlify(self.ownerid.encode()),
425+
"init_iv": init_iv
426+
}
427+
428+
response = self.__do_request(post_data)
429+
response = encryption.decrypt(response, self.enckey, init_iv)
430+
431+
json = jsond.loads(response)
432+
433+
if json["success"]:
434+
if json["users"]["0"]:
435+
return None ## THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022 so it will return none if it is not an array.
436+
else:
437+
return json["users"]
438+
else:
439+
return None
440+
441+
def chatGet(self, channel):
442+
self.checkinit()
443+
init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
444+
445+
post_data = {
446+
"type": binascii.hexlify(("chatget").encode()),
447+
"channel": encryption.encrypt(channel, self.enckey, init_iv),
448+
"sessionid": binascii.hexlify(self.sessionid.encode()),
449+
"name": binascii.hexlify(self.name.encode()),
450+
"ownerid": binascii.hexlify(self.ownerid.encode()),
451+
"init_iv": init_iv
452+
}
453+
454+
response = self.__do_request(post_data)
455+
response = encryption.decrypt(response, self.enckey, init_iv)
456+
457+
json = jsond.loads(response)
458+
459+
if json["success"]:
460+
return json["messages"]
461+
else:
462+
return None
463+
464+
def chatSend(self, message, channel):
465+
self.checkinit()
466+
init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
467+
468+
post_data = {
469+
"type": binascii.hexlify(("chatsend").encode()),
470+
"message": encryption.encrypt(message, self.enckey, init_iv),
471+
"channel": encryption.encrypt(channel, self.enckey, init_iv),
472+
"sessionid": binascii.hexlify(self.sessionid.encode()),
473+
"name": binascii.hexlify(self.name.encode()),
474+
"ownerid": binascii.hexlify(self.ownerid.encode()),
475+
"init_iv": init_iv
476+
}
477+
478+
response = self.__do_request(post_data)
479+
response = encryption.decrypt(response, self.enckey, init_iv)
480+
481+
json = jsond.loads(response)
482+
483+
if json["success"]:
484+
return True
485+
else:
486+
return False
415487

416488
def checkinit(self):
417489
if not self.initialized:
@@ -430,7 +502,7 @@ class application_data_class:
430502
numUsers = numKeys = app_ver = customer_panel = onlineUsers = ""
431503
# region user_data
432504
class user_data_class:
433-
username = ip = hwid = expires = createdate = lastlogin = subscription = ""
505+
username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions ""
434506

435507
user_data = user_data_class()
436508
app_data = application_data_class()

main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def getchecksum():
2929
version = "1.0",
3030
hash_to_check = getchecksum()
3131
)
32+
3233
print(f"""
3334
App data:
3435
Number of users: {keyauthapp.app_data.numUsers}
@@ -101,6 +102,18 @@ def getchecksum():
101102
#* example to send normal request with no POST data
102103
#data = keyauthapp.webhook("WebhookID", "?type=resetuser&user=username")
103104

105+
#* Get chat messages
106+
#messages = keyauthapp.chatGet("CHANNEL")
107+
108+
#Messages = ""
109+
#for i in range(len(messages)):
110+
# Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n"
111+
112+
#print("\n\n" + Messages)
113+
114+
#* Send chat message
115+
#keyauthapp.chatSend("MESSAGE", "CHANNEL")
116+
104117
#endregion
105118

106119
print("\nUser data: ")
@@ -117,6 +130,16 @@ def getchecksum():
117130

118131
print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}")
119132

133+
onlineUsers = keyauthapp.fetchOnline()
134+
OU = "" ## KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING.
135+
if onlineUsers == None:
136+
OU = "No online users"
137+
else:
138+
for i in range(len(onlineUsers)):
139+
OU += onlineUsers[i]["credential"] + " "
140+
141+
print("\n" + OU + "\n")
142+
120143

121144
print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S'))
122145
print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S'))

0 commit comments

Comments
 (0)