|
@ -1,20 +1,18 @@ |
|
|
#!/usr/bin/env python3 |
|
|
#!/usr/bin/env python3 |
|
|
from http.server import * |
|
|
|
|
|
from http import HTTPStatus |
|
|
from http import HTTPStatus |
|
|
|
|
|
from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler |
|
|
from urllib.parse import urlparse, parse_qs |
|
|
from urllib.parse import urlparse, parse_qs |
|
|
|
|
|
from configparser import ConfigParser |
|
|
from base64 import b64encode |
|
|
from base64 import b64encode |
|
|
from os.path import getmtime |
|
|
from os.path import getmtime |
|
|
import json |
|
|
import json |
|
|
|
|
|
|
|
|
server_domain = "127.0.0.1" |
|
|
|
|
|
server_url = "http://%s:25564" % server_domain |
|
|
|
|
|
|
|
|
|
|
|
userdata = { |
|
|
userdata = { |
|
|
"9a10d47934294527b3a0a32ab41d207e": { |
|
|
"9a10d47934294527b3a0a32ab41d207e": { |
|
|
"name": "Sneppe" |
|
|
"name": "test1" |
|
|
}, |
|
|
}, |
|
|
"4ad1f41992193cb986741243f14d81e8": { |
|
|
"4ad1f41992193cb986741243f14d81e8": { |
|
|
"name": "mid-kid" |
|
|
"name": "test2" |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
connections = {} |
|
|
connections = {} |
|
@ -22,6 +20,10 @@ connections = {} |
|
|
class HTTPRequestHandler(BaseHTTPRequestHandler): |
|
|
class HTTPRequestHandler(BaseHTTPRequestHandler): |
|
|
protocol_version = "HTTP/1.1" |
|
|
protocol_version = "HTTP/1.1" |
|
|
|
|
|
|
|
|
|
|
|
def setup(self, *args, **kwargs): |
|
|
|
|
|
super().setup(*args, **kwargs) |
|
|
|
|
|
self.config = self.server.config["server"] |
|
|
|
|
|
|
|
|
def send_ok(self, data): |
|
|
def send_ok(self, data): |
|
|
self.send_response(HTTPStatus.OK) |
|
|
self.send_response(HTTPStatus.OK) |
|
|
self.send_header("Content-Length", len(data)) |
|
|
self.send_header("Content-Length", len(data)) |
|
@ -203,14 +205,15 @@ class HTTPRequestHandler(BaseHTTPRequestHandler): |
|
|
check_skin = self.check_skin(user["name"]) |
|
|
check_skin = self.check_skin(user["name"]) |
|
|
check_cape = self.check_cape(user["name"]) |
|
|
check_cape = self.check_cape(user["name"]) |
|
|
|
|
|
|
|
|
|
|
|
url = self.config["server_url"] |
|
|
textures = {} |
|
|
textures = {} |
|
|
textures_stamp = 0 |
|
|
textures_stamp = 0 |
|
|
if check_skin is not None: |
|
|
if check_skin is not None: |
|
|
textures_stamp = max(textures_stamp, check_skin) |
|
|
textures_stamp = max(textures_stamp, check_skin) |
|
|
textures["SKIN"] = {"url": server_url + "/skin/%s.png" % user["name"]} |
|
|
textures["SKIN"] = {"url": url + "/skin/%s.png" % user["name"]} |
|
|
if check_cape is not None: |
|
|
if check_cape is not None: |
|
|
textures_stamp = max(textures_stamp, check_cape) |
|
|
textures_stamp = max(textures_stamp, check_cape) |
|
|
textures["CAPE"] = {"url": server_url + "/cape/%s.cape.png" % user["name"]} |
|
|
textures["CAPE"] = {"url": url + "/cape/%s.cape.png" % user["name"]} |
|
|
|
|
|
|
|
|
if textures: |
|
|
if textures: |
|
|
prop = { |
|
|
prop = { |
|
@ -249,7 +252,7 @@ class HTTPRequestHandler(BaseHTTPRequestHandler): |
|
|
"feature.no_mojang_namespace": True, |
|
|
"feature.no_mojang_namespace": True, |
|
|
"feature.legacy_skin_api": True |
|
|
"feature.legacy_skin_api": True |
|
|
}, |
|
|
}, |
|
|
"skinDomains": [server_domain] |
|
|
"skinDomains": [self.config["server_dom"]] |
|
|
} |
|
|
} |
|
|
body = json.dumps(settings).encode() |
|
|
body = json.dumps(settings).encode() |
|
|
self.send_ok(body) |
|
|
self.send_ok(body) |
|
@ -259,11 +262,13 @@ class HTTPRequestHandler(BaseHTTPRequestHandler): |
|
|
self.send_header("X-Authlib-Injector-API-Location", server_url + "/ygg") |
|
|
self.send_header("X-Authlib-Injector-API-Location", server_url + "/ygg") |
|
|
self.end_headers() |
|
|
self.end_headers() |
|
|
|
|
|
|
|
|
def run(server_class=ThreadingHTTPServer, handler_class=HTTPRequestHandler): |
|
|
if __name__ == "__main__": |
|
|
server_address = ('', 25564) |
|
|
server_address = ("", 25564) |
|
|
httpd = server_class(server_address, handler_class) |
|
|
config = ConfigParser() |
|
|
httpd.serve_forever() |
|
|
config.read("config.ini") |
|
|
try: |
|
|
httpd = ThreadingHTTPServer(server_address, HTTPRequestHandler) |
|
|
run() |
|
|
httpd.config = config |
|
|
except KeyboardInterrupt: |
|
|
try: |
|
|
pass |
|
|
httpd.serve_forever() |
|
|
|
|
|
except KeyboardInterrupt: |
|
|
|
|
|
pass |
|
|