-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
171 lines (167 loc) · 5.03 KB
/
main.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from flask import Flask,render_template,request,send_file
from flask_socketio import SocketIO, emit
import os
app = Flask(__name__)
socketio = SocketIO(app, cors_allowed_origins=[os.environ["BASE_URL"]])
dictionary = {}
def emittoallstations(event,data):
socketio.emit(event,data, namespace="/commander")
socketio.emit(event,data, namespace="/navigator")
socketio.emit(event,data, namespace="/tactical")
socketio.emit(event,data, namespace="/engineer")
socketio.emit(event,data, namespace="/operations")
socketio.emit(event,data, namespace="/mvs")
socketio.emit(event,data, namespace="/fd")
@socketio.on('broadcast', namespace="/commander")
def broadcast(json):
for key,value in json.items():
emittoallstations(key,value)
@socketio.on('broadcast', namespace="/navigator")
def broadcast(json):
for key,value in json.items():
emittoallstations(key,value)
@socketio.on('broadcast', namespace="/tactical")
def broadcast(json):
for key,value in json.items():
emittoallstations(key,value)
@socketio.on('broadcast', namespace="/operations")
def broadcast(json):
for key,value in json.items():
emittoallstations(key,value)
@socketio.on('broadcast', namespace="/engineer")
def broadcast(json):
for key,value in json.items():
emittoallstations(key,value)
@socketio.on('broadcast', namespace="/mvs")
def broadcast(json):
for key,value in json.items():
emittoallstations(key,value)
@socketio.on('broadcast', namespace="/fd")
def broadcast(json):
for key,value in json.items():
emittoallstations(key,value)
@socketio.on('update', namespace="/commander")
def update(json):
for key,value in json.items():
dictionary[key] = value
emittoallstations("update",json)
@socketio.on('update', namespace="/navigator")
def update(json):
for key,value in json.items():
dictionary[key] = value
emittoallstations("update",json)
@socketio.on('update', namespace="/tactical")
def update(json):
for key,value in json.items():
dictionary[key] = value
emittoallstations("update",json)
@socketio.on('update', namespace="/operations")
def update(json):
for key,value in json.items():
dictionary[key] = value
emittoallstations("update",json)
@socketio.on('update', namespace="/engineer")
def update(json):
for key,value in json.items():
dictionary[key] = value
emittoallstations("update",json)
@socketio.on('update', namespace="/mvs")
def update(json):
for key,value in json.items():
dictionary[key] = value
emittoallstations("update",json)
@socketio.on('update', namespace="/fd")
def update(json):
for key,value in json.items():
dictionary[key] = value
emittoallstations("update",json)
@socketio.on('reset', namespace="/fd")
def reset(json):
for key,value in dictionary.items():
dictionary[key] = ""
emittoallstations("update",dictionary)
@socketio.on('connect', namespace="/commander")
def stationconnect():
emit("update",dictionary)
@socketio.on('connect', namespace="/navigator")
def stationconnect():
emit("update",dictionary)
@socketio.on('connect', namespace="/tactical")
def stationconnect():
emit("update",dictionary)
@socketio.on('connect', namespace="/engineer")
def stationconnect():
emit("update",dictionary)
@socketio.on('connect', namespace="/operations")
def stationconnect():
emit("update",dictionary)
@socketio.on('connect', namespace="/mvs")
def stationconnect():
emit("update",dictionary)
@socketio.on('connect', namespace="/fd")
def stationconnect():
emit("update",dictionary)
@app.route('/')
def home():
templateData = {
}
return render_template('main.html', **templateData)
@app.route("/robots.txt")
def verify():
return send_file("robots.txt")
@app.route("/commander/")
def commander():
templateData = {
}
return render_template("commander.html", **templateData)
@app.route("/navigator/")
def navigator():
templateData = {
}
return render_template("navigator.html", **templateData)
@app.route("/tactical/")
def tactical():
templateData = {
}
return render_template("tactical.html", **templateData)
@app.route("/operations/")
def operations():
templateData = {
}
return render_template("operations.html", **templateData)
@app.route("/engineer/")
def engineer():
templateData = {
}
return render_template("engineer.html", **templateData)
@app.route("/mvs/")
def mvs():
templateData = {
}
return render_template("mvs.html", **templateData)
@app.route("/fd/", methods=['POST'])
def fd():
password = request.form['pass']
if password != os.environ['PASSWORD']:
return "<h1>Access denied. Please contact the admin for the password.</h1>"
templateData = {
}
return render_template("fd.html", **templateData)
@app.errorhandler(404)
def page_not_found(error):
templateData = {
'error':"Page Not Found"
}
return render_template("error.html",**templateData)
@app.errorhandler(500)
def internalerror(error):
templateData = {
'error':error
}
return render_template("error.html",**templateData)
if __name__ == '__main__':
print("Server running")
if 'PORT' in os.environ:
socketio.run(app, "0.0.0.0",int(os.environ['PORT']))
else:
socketio.run(app, "0.0.0.0", 3000)