-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmainsrv.py
93 lines (82 loc) · 3.21 KB
/
mainsrv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from flask import Flask, request, redirect, Response, render_template, make_response
import socket
import os
import json
import hashlib
import asyncio
import websockets
cwd = os.path.dirname(os.path.realpath(__file__))
app = Flask(__name__, template_folder=cwd)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 60*60
app.config['TEMPLATES_AUTO_RELOAD'] = True
serverslist = []
# {
# "name": "Official server #1",
# "ip": "site9373r.dns-cloud.net",
# "maxplayers": 10
# }
async def validateServer(uri,srvname,maxplayers):
try:
print(uri)
# uri = "wss://localhost:25555" копипасточка!
connection=await asyncio.wait_for(websockets.connect(uri+"/ping"), 5)
await connection.send("ok")
addthis={
"name":srvname,
"ip":uri,
"maxplayers":maxplayers
}
if not addthis in serverslist:
serverslist.append(addthis)
except Exception as fuckException:
print(fuckException)
print("Failed to validate %s" % uri)
@app.route("/newserver", methods=["post"])
def appendNewServer():
ip = request.values.get("ip")
asyncio.get_event_loop().create_task(validateServer(ip,request.values.get("name"),request.values.get("maxplayers")))
return ip
@app.route("/error", methods=["post"])
def errorinjs():
errorlogfile=open(cwd+"/JSerrors.log","a")
errorlogfile.write("\r\nNew Error!\r\n")
errorlogfile.write(request.values.get("error"))
errorlogfile.write("\r\nfile %s" % request.values.get("file"))
errorlogfile.write("\r\nline %s\r\n" % request.values.get("line"))
errorlogfile.close()
return "OK"
@app.route('/game')
def maingame():
try:
platform = request.user_agent.platform.lower()
print("\033[92m"+platform+"\033[0m")
if platform == "windows" or platform == "linux":
return open(cwd+'/index.html').read()
elif platform == "android":
return open(cwd+'/indexmobile.html').read()
elif platform == "iphone":
return open(cwd+'/indexios.html').read()
else:
return "you're very specific person! wait for updates or change device!"
except:
return open(cwd+'/index.html').read()
@app.route('/main.js')
def mainjs():
try:
platform = request.user_agent.platform.lower()
print("\033[92m"+platform+"\033[0m")
if platform == "windows" or platform == "linux":
return Response(render_template('main.js',device=1), mimetype='text/javascript')
elif platform == "android":
return Response(render_template('main.js',device=0), mimetype='text/javascript')
else:
return "you're very specific person! wait for updates or change device!"
except:
return Response(render_template('main.js',device=1), mimetype='text/javascript')
@app.route('/')
def servers():
return render_template("serverwindow.html", servers=serverslist, sha1=hashlib.sha1)
@app.route("/src.zip")
def aa():
return Response(open(cwd+"/src.zip", 'rb').read(), mimetype='application/zip')
#app.run(ssl_context=('/home/pi/Документы/PEM/certificate.crt','/home/pi/Документы/PEM/private.key'),host="192.168.0.101", debug=True,port=443)