Skip to content

Commit fbc855f

Browse files
committed
add : GOD's preshared key added.
1 parent 8f441e5 commit fbc855f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

mafia.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from sys import argv
2-
from random import randrange, shuffle
2+
from random import randrange, shuffle, sample
33
from flask import Flask, render_template, url_for, request
44
from flask_httpauth import HTTPBasicAuth
55
from mafia_params import *
66

77
app = Flask(__name__)
88
auth = HTTPBasicAuth()
9+
auth_GOD = HTTPBasicAuth()
10+
preshared_key = ""
911
id = 0
1012
nPlayers = 0
1113
roles = []
@@ -26,12 +28,17 @@ def index():
2628
image_name = ""
2729
ip = str(request.remote_addr)
2830

31+
if id == 0:
32+
print("_" * 20 + "GOD's password" + "_" * 20)
33+
print(preshared_key)
34+
print("_" * 54)
35+
2936
if ip in ip2role_index_name.keys():
3037
role = ip2role_index_name[ip][0]
3138
image_name = ip2role_index_name[ip][0] + "_" + str(ip2role_index_name[ip][1])
3239
else:
3340
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)
3542
role = roles[id]
3643
ip2role_index_name[ip] = (role, str(randrange(1, nRoles[role] + 1)), username)
3744
image_name = role + "_" + str(ip2role_index_name[ip][1])
@@ -47,7 +54,14 @@ def index():
4754
is_farsi=True)
4855

4956

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+
5063
@app.route('/GOD')
64+
@auth_GOD.login_required
5165
def GOD_PAGE():
5266
global ip2role_index_name
5367
return render_template("GOD.html", ip2role_index_name=ip2role_index_name)
@@ -80,6 +94,9 @@ def help_me():
8094
help_me()
8195
roles = ordered_roles[:nPlayers]
8296
shuffle(roles)
97+
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()"
98+
for i in range(4):
99+
preshared_key += chars[randrange(0, len(chars))]
83100
app.run(host="0.0.0.0", \
84101
port=5000, \
85102
debug=True)

0 commit comments

Comments
 (0)