mirror of
https://github.com/wolfswolke/DeathGarden_API_Rebirth.git
synced 2026-07-06 19:55:26 -05:00
Added SHA Handler for Game client
This commit is contained in:
parent
aaf93b9fc1
commit
b9ab04c297
|
|
@ -306,3 +306,15 @@ def api_debug_matchmaking():
|
|||
"len_open_lobbies": len_open_lobbies,
|
||||
"lobby_data": lobby_return_data
|
||||
})
|
||||
|
||||
|
||||
@app.route("/api/sha", methods=["GET"])
|
||||
def api_sha():
|
||||
try:
|
||||
# todo generate this on BOOT
|
||||
# generate SHA256 of PAK and SIG on boot then save it to a file and return here
|
||||
hashes = hash_handler.get_hash()
|
||||
return jsonify({"pak": hashes[0], "sig": hashes[1]})
|
||||
except Exception as e:
|
||||
logger.graylog_logger(level="error", handler="web-api-sha", message=e)
|
||||
return jsonify({"status": "error"}), 500
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from logic.mongodb_handler import mongo
|
|||
from logic.webhook_handler import discord_webhook
|
||||
from logic.time_handler import get_lifetime
|
||||
from logic.challenge_handler import get_challenge
|
||||
from logic.hash_handler import hash_handler
|
||||
import json
|
||||
import os
|
||||
|
||||
|
|
|
|||
25
src/logic/hash_handler.py
Normal file
25
src/logic/hash_handler.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import hashlib
|
||||
import mmap
|
||||
|
||||
class HashHandler:
|
||||
def __init__(self):
|
||||
self.pak = ""
|
||||
self.sig = ""
|
||||
self.pak_path = "files/TheExitRebirthBackendAPI-WindowsNoEditor_P.pak"
|
||||
self.sig_path = "files/TheExitRebirthBackendAPI-WindowsNoEditor_P.sig"
|
||||
|
||||
def setup(self):
|
||||
self.pak = self.get_256_sum(self.pak_path)
|
||||
self.sig = self.get_256_sum(self.sig_path)
|
||||
|
||||
def get_256_sum(self, filename):
|
||||
h = hashlib.sha256()
|
||||
with open(filename, 'rb') as f:
|
||||
with mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ) as mm:
|
||||
h.update(mm)
|
||||
return h.hexdigest()
|
||||
|
||||
def get_hash(self):
|
||||
return str(self.pak), str(self.sig)
|
||||
|
||||
hash_handler = HashHandler()
|
||||
|
|
@ -53,4 +53,5 @@ def keep_alive():
|
|||
logger.setup_graylog(use_graylog, graylog_server)
|
||||
mongo.setup(mongo_host, mongo_db, mongo_collection)
|
||||
session_manager.setup()
|
||||
hash_handler.setup()
|
||||
keep_alive()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user