1
1
from sys import argv
2
- from random import randrange , shuffle
2
+ from random import randrange , shuffle , sample
3
3
from flask import Flask , render_template , url_for , request
4
4
from flask_httpauth import HTTPBasicAuth
5
5
from mafia_params import *
6
6
7
7
app = Flask (__name__ )
8
8
auth = HTTPBasicAuth ()
9
+ auth_GOD = HTTPBasicAuth ()
10
+ preshared_key = ""
9
11
id = 0
10
12
nPlayers = 0
11
13
roles = []
@@ -26,12 +28,17 @@ def index():
26
28
image_name = ""
27
29
ip = str (request .remote_addr )
28
30
31
+ if id == 0 :
32
+ print ("_" * 20 + "GOD's password" + "_" * 20 )
33
+ print (preshared_key )
34
+ print ("_" * 54 )
35
+
29
36
if ip in ip2role_index_name .keys ():
30
37
role = ip2role_index_name [ip ][0 ]
31
38
image_name = ip2role_index_name [ip ][0 ] + "_" + str (ip2role_index_name [ip ][1 ])
32
39
else :
33
40
if id > nPlayers :
34
- return "Numbers of players out of range!" #TODO:well defined Error Page
41
+ return render_template ( "404.html" , is_farsi = True )
35
42
role = roles [id ]
36
43
ip2role_index_name [ip ] = (role , str (randrange (1 , nRoles [role ] + 1 )), username )
37
44
image_name = role + "_" + str (ip2role_index_name [ip ][1 ])
@@ -47,7 +54,14 @@ def index():
47
54
is_farsi = True )
48
55
49
56
57
+ @auth_GOD .verify_password
58
+ def verify_password_god (username , password ):
59
+ if username == "GOD" and password == preshared_key :
60
+ return username
61
+
62
+
50
63
@app .route ('/GOD' )
64
+ @auth_GOD .login_required
51
65
def GOD_PAGE ():
52
66
global ip2role_index_name
53
67
return render_template ("GOD.html" , ip2role_index_name = ip2role_index_name )
@@ -80,6 +94,9 @@ def help_me():
80
94
help_me ()
81
95
roles = ordered_roles [:nPlayers ]
82
96
shuffle (roles )
97
+ chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()"
98
+ for i in range (4 ):
99
+ preshared_key += chars [randrange (0 , len (chars ))]
83
100
app .run (host = "0.0.0.0" , \
84
101
port = 5000 , \
85
102
debug = True )
0 commit comments