Skip to content

Commit b016811

Browse files
authored
Merge pull request #13 from sadrasabouri/GOD_PAGE
GOD Page
2 parents d227cb0 + 5141697 commit b016811

File tree

13 files changed

+236
-8
lines changed

13 files changed

+236
-8
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ The game continues until a faction achieves its win condition; for the Residents
9090
| Resident | <img width="100" height="100" src="https://raw.githubusercontent.com/sadrasabouri/mafia/master/static/images/roles/Resident_1.png"><img width="100" height="100" src="https://raw.githubusercontent.com/sadrasabouri/mafia/master/static/images/roles/Resident_2.png"><img width="100" height="100" src="https://raw.githubusercontent.com/sadrasabouri/mafia/master/static/images/roles/Resident_3.png"><img width="100" height="100" src="https://raw.githubusercontent.com/sadrasabouri/mafia/master/static/images/roles/Resident_4.png"> | Resident is the typical player of the game. he/she has no power but to blame mafia in order to remove them from the game in day mode. |
9191

9292
## References
93-
Icons made by <a href="https://www.flaticon.com/authors/vectors-market" title="Vectors Market">Vectors Market</a> and <a href="https://www.flaticon.com/authors/pixel-perfect" title="Pixel perfect">Pixel perfect</a> from <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a>
93+
Icons made by <a href="https://www.flaticon.com/authors/vectors-market" title="Vectors Market">Vectors Market</a> and <a href="https://www.flaticon.com/authors/pixel-perfect" title="Pixel perfect">Pixel perfect</a> from <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a>.
94+
95+
Sounds from <a href="https://www.soundjay.com">Soundjay</a>.
9496

9597
+ [https://en.wikipedia.org/wiki/Mafia_(party_game)](https://en.wikipedia.org/wiki/Mafia_(party_game))

mafia.py

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
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 = []
1214
ip2role_index_name = {}
15+
nComments = 0
1316

1417
@auth.verify_password
1518
def verify_password(username, password):
@@ -26,14 +29,22 @@ def index():
2629
image_name = ""
2730
ip = str(request.remote_addr)
2831

32+
if id == 0:
33+
print("_" * 20 + "GOD's password" + "_" * 20)
34+
print(preshared_key)
35+
print("_" * 54)
36+
2937
if ip in ip2role_index_name.keys():
30-
role = ip2role_index_name[ip][0]
31-
image_name = ip2role_index_name[ip][0] + "_" + str(ip2role_index_name[ip][1])
38+
return render_template("Player.html", player=ip2role_index_name[ip])
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]
36-
ip2role_index_name[ip] = (role, str(randrange(1, nRoles[role] + 1)), username)
43+
ip2role_index_name[ip] = [role,
44+
str(randrange(1, nRoles[role] + 1)),
45+
username,
46+
"alive",
47+
False]
3748
image_name = role + "_" + str(ip2role_index_name[ip][1])
3849
print("*" * 20, "New Player","*" * 20)
3950
toGod = ip + " : " + str(id) + " : " + username + " --> " + role
@@ -47,6 +58,52 @@ def index():
4758
is_farsi=True)
4859

4960

61+
@auth_GOD.verify_password
62+
def verify_password_god(username, password):
63+
if username == "GOD" and password == preshared_key:
64+
return username
65+
66+
67+
@app.route('/GOD')
68+
@auth_GOD.login_required
69+
def GOD_PAGE():
70+
global ip2role_index_name, nComments
71+
msg = ""
72+
if request.args.get("Kill") is not None:
73+
ip = request.args.get("Kill")
74+
if ip in ip2role_index_name.keys():
75+
if ip2role_index_name[ip][3] == "alive":
76+
ip2role_index_name[ip][3] = "dead"
77+
else:
78+
ip2role_index_name[ip][3] = "alive"
79+
else:
80+
return render_template("404.html", is_farsi=True)
81+
if request.args.get("Ban") is not None:
82+
ip = request.args.get("Ban")
83+
if ip in ip2role_index_name.keys():
84+
if ip2role_index_name[ip][3] == "alive":
85+
ip2role_index_name[ip][3] = "banned"
86+
elif ip2role_index_name[ip][3] == "banned":
87+
ip2role_index_name[ip][3] = "alive"
88+
else:
89+
return render_template("404.html", is_farsi=True)
90+
if request.args.get("Comment") is not None:
91+
ip = request.args.get("Comment")
92+
if ip in ip2role_index_name.keys():
93+
if ip2role_index_name[ip][4] == False:
94+
if nComments <= nPlayers // 3:
95+
ip2role_index_name[ip][4] = True
96+
nComments += 1
97+
else:
98+
msg = "Error: Out of Comments."
99+
else:
100+
ip2role_index_name[ip][4] = False
101+
else:
102+
return render_template("404.html", is_farsi=True)
103+
return render_template("GOD.html", ip2role_index_name=ip2role_index_name,
104+
prompt_message=msg)
105+
106+
50107
@app.errorhandler(404)
51108
def invalid_route(e):
52109
return render_template("404.html", is_farsi=True)
@@ -74,6 +131,9 @@ def help_me():
74131
help_me()
75132
roles = ordered_roles[:nPlayers]
76133
shuffle(roles)
134+
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()"
135+
for i in range(4):
136+
preshared_key += chars[randrange(0, len(chars))]
77137
app.run(host="0.0.0.0", \
78138
port=5000, \
79139
debug=True)

mafia_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"Resident",
99
"Rebel",
1010
"Bulletproof",
11-
"Mafia",
1211
"Resident",
12+
"Mafia",
1313
"Resident",
1414
"Resident",
1515
"Mafia",

static/css/style.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,47 @@ th, td {
4747
.id_section {
4848
font-size: 10px;
4949
}
50+
51+
.action_table {
52+
width: auto;
53+
border: 1px solid black;
54+
text-align: center;
55+
}
56+
57+
.alive {
58+
background-color: white;
59+
}
60+
.banned {
61+
background-color: darkgray;
62+
}
63+
.dead {
64+
background-color: red;
65+
}
66+
67+
#myProgress {
68+
width: 100%;
69+
background-color: #ddd;
70+
border-radius: 5px;
71+
}
72+
73+
#myBar {
74+
width: 0%;
75+
height: 30px;
76+
background-color: #4f8ace;
77+
color:#ffffff;
78+
text-align: center;
79+
line-height: 30px;
80+
border-radius: 5px;
81+
}
82+
83+
#player_name {
84+
width: 20%;
85+
}
86+
87+
#player_role {
88+
width: 20%;
89+
}
90+
91+
#is_comment {
92+
width: 5%;
93+
}

static/images/Warns/play.png

15.4 KB
Loading

static/js/main.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var i = 0;
2+
function start() {
3+
if (i == 0) {
4+
i = 1;
5+
var elem = document.getElementById("myBar");
6+
var beep_sound = document.getElementById("beep")
7+
var width = 0;
8+
var time_from_start = 0;
9+
var id = setInterval(frame, 10);
10+
function frame() {
11+
if (width >= 100) {
12+
clearInterval(id);
13+
beep_sound.play();
14+
i = 0;
15+
} else {
16+
width += 1 / 45;
17+
time_from_start = 45 * width / 100;
18+
elem.style.width = width + "%";
19+
elem.innerHTML = time_from_start.toFixed(2);
20+
elem.style.backgroundColor = "rgb(" + time_from_start * 6 +", 50, 50)";
21+
}
22+
}
23+
}
24+
}
25+
26+
function delay (URL, delay_time) {
27+
setTimeout( function() { window.location = URL }, delay_time );
28+
}
29+
30+
function kill_sound_play(){
31+
var kill_sound = document.getElementById("kill");
32+
kill_sound.play();
33+
}
34+
35+
function ban_sound_play(){
36+
var ban_sound = document.getElementById("ban");
37+
ban_sound.play();
38+
}

static/voices/ban.mp3

278 KB
Binary file not shown.

static/voices/beep.mp3

15.6 KB
Binary file not shown.

static/voices/kill.mp3

208 KB
Binary file not shown.

templates/GOD.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{% extends 'base_action.html' %}
2+
3+
{% block Audio %}
4+
<audio id="kill">
5+
<source src="static/voices/kill.mp3" type="audio/mpeg">
6+
Your browser does not support the audio element.
7+
</audio>
8+
<audio id="ban">
9+
<source src="static/voices/ban.mp3" type="audio/mpeg">
10+
Your browser does not support the audio element.
11+
</audio>
12+
{% endblock %}
13+
14+
{% block sub_table %}
15+
<tr>
16+
<th class="action_table" id="is_comment">C</th>
17+
<th class="action_table" id="player_name">Player Name</th>
18+
<th class="action_table" id="player_role">Player Role</th>
19+
<th class="action_table" id="actions" colspan="3">Actions</th>
20+
</tr>
21+
{% for ip in ip2role_index_name.keys() %}
22+
<tr class="{{ ip2role_index_name[ip][3] }}">
23+
<td class="action_table" id="is_comment">{% if ip2role_index_name[ip][4] == True%}+{% endif %}</td>
24+
<td class="action_table" id="player_name">{{ ip2role_index_name[ip][2] }}</td>
25+
<td class="action_table" id="player_role">{{ ip2role_index_name[ip][0] }}</td>
26+
<td class="action_table"><a href="javascript:delay('/GOD?Ban={{ ip }}', 2000)" onclick="ban_sound_play()">Ban</a></td>
27+
<td class="action_table"><a href="/GOD?Comment={{ ip }}">Comment</a></td>
28+
<td class="action_table"><a href="javascript:delay('/GOD?Kill={{ ip }}', 1500)" onclick="kill_sound_play()">Kill</a></td>
29+
</tr>
30+
{% endfor %}
31+
{% endblock %}
32+
33+
{% block messages %}
34+
{{ prompt_message }}
35+
{% endblock %}

0 commit comments

Comments
 (0)