8000 Minor changes requested in the previous pr were applied · sadrasabouri/mafia@32c8068 · GitHub
[go: up one dir, main page]

Skip to content

Commit 32c8068

Browse files
Minor changes requested in the previous pr were applied
1 parent 09c6851 commit 32c8068

File tree

3 files changed

+49
-47
lines changed

3 files changed

+49
-47
lines changed

mafia.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
id = 0
1313
nPlayers = 0
1414
roles = []
15-
#ip2role_index_name = {}
16-
ip2players = {}
15+
ip2player = {}
1716
nComments = 0
1817
comments_ordered = []
1918

@@ -26,25 +25,20 @@ def verify_password(username, password):
2625
@app.route('/')
2726
@auth.login_required
2827
def index():
29-
global id, ip2players
28+
global id, ip2player
3029
username = str(auth.current_user())
3130
role = ""
3231
image_name = ""
3332
ip = str(request.remote_addr)
3433

35-
if ip in ip2players.keys():
36-
return render_template("Player.html", player=ip2players[ip])
34+
if ip in ip2player.keys():
35+
return render_template("Player.html", player=ip2player[ip])
3736
else:
3837
if id > nPlayers:
3938
return render_template("404.html", is_farsi=True)
4039
role = roles[id]
41-
"""ip2role_index_name[ip] = [role,
42-
str(randrange(1, nRoles[role] + 1)),
43-
username,
44-
"alive",
45-
False]"""
4640
image_name = role + "_" + str(randrange(1, nRoles[role] + 1))
47-
ip2players[ip] = Player(ip, username, role, image_name)
41+
ip2player[ip] = Player(ip, username, role, image_name)
4842
print("*" * 20, "New Player","*" * 20)
4943
toGod = ip + " : " + str(id) + " : " + username + " --> " + role
5044
toGod += "/" + role2fa[role] #TODO: Just in Farsi Mode
@@ -66,43 +60,43 @@ def verify_password_god(username, password):
6660
@app.route('/GOD')
6761
@auth_GOD.login_required
6862
def GOD_PAGE():
69-
global ip2players, nComments, comments_ordered
63+
global ip2player, nComments, comments_ordered
7064
msg = ""
7165
if request.args.get("Kill") is not None:
7266
ip = request.args.get("Kill")
73-
if ip in ip2players.keys():
74-
if ip2players[ip].get_state() == "alive":
75-
ip2players[ip].set_state("dead")
67+
if ip in ip2player.keys():
68+
if ip2player[ip].get_state() == "alive":
69+
ip2player[ip].set_state("dead")
7670
else:
77-
ip2players[ip].set_state("alive")
71+
ip2player[ip].set_state("alive")
7872
else:
7973
return render_template("404.html", is_farsi=True)
8074
if request.args.get("Ban") is not None:
8175
ip = request.args.get("Ban")
82-
if ip in ip2players.keys():
83-
if ip2players[ip].get_state() == "alive":
84-
ip2players[ip].set_state("banned")
85-
elif ip2players[ip].get_state() == "banned":
86-
ip2players[ip].set_state("alive")
76+
if ip in ip2player.keys():
77+
if ip2player[ip].get_state() == "alive":
78+
ip2player[ip].set_state("banned")
79+
elif ip2player[ip].get_state() == "banned":
80+
ip2player[ip].set_state("alive")
8781
else:
8882
return render_template("404.html", is_farsi=True)
8983
if request.args.get("Comment") is not None:
9084
ip = request.args.get("Comment")
91-
if ip in ip2players.keys():
92-
if ip2players[ip].get_comment() == False:
85+
if ip in ip2player.keys():
86+
if ip2player[ip].get_comment() == False:
9387
if nComments <= nPlayers // 3:
94-
ip2players[ip].set_comment(True)
88+
ip2player[ip].set_comment(True)
9589
nComments += 1
9690
comments_ordered.append(ip)
9791
else:
9892
msg = "Error: Out of Comments."
9993
else:
100-
ip2players[ip].set_comment(False)
94+
ip2player[ip].set_comment(False)
10195
nComments -= 1
10296
comments_ordered.remove(ip)
10397
else:
10498
return render_template("404.html", is_farsi=True)
105-
return render_template("GOD.html", ip2players=ip2players,
99+
return render_template("GOD.html", ip2player=ip2player,
106100
prompt_message=msg, roles={role:roles.count(role) for role in set(roles)},
107101
comments=comments_ordered, role2team=role2team)
108102

player.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,30 @@ def __init__(self, ip, username, role, image_name):
77
self.role = role
88
self.image_name = image_name
99
self.comment = False
10+
1011
def get_state(self):
1112
return self.state
13+
1214
def get_ip(self):
1315
return self.ip
16+
1417
def get_username(self):
1518
return self.username
19+
1620
def get_role(self):
1721
return self.role
22+
1823
def get_image_name(self):
1924
return self.image_name
25+
2026
def get_comment(self):
2127
return self.comment
2228

29+
2330
def set_state(self, state):
2431
if state in ["alive", "dead", "banned"]:
2532
self.state = state
33+
2634
def set_comment(self, comment):
2735
self.comment = comment
2836

templates/GOD.html

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,38 @@ <h4 class="table_header">Players</h4>
1919
<th class="action_table" id="player_role">Player Role</th>
2020
<th class="action_table" id="actions" colspan="3">Actions</th>
2121
</tr>
22-
{% for ip in ip2players.keys() %}
23-
{% if ip2players[ip].get_state() == "alive" %}
24-
<tr class="{{ ip2players[ip].get_state() }}">
25-
<td class="action_table" id="is_comment">{% if ip2players[ip].get_comment() == True%}+{% endif %}</td>
26-
<td class="action_table" id="player_name">{{ ip2players[ip].get_username() }}</td>
27-
<td class="action_table" id="player_role"><p class="{{ role2team[ip2players[ip].get_role()] }}">{{ ip2players[ip].get_role() }}</p></td>
22+
{% for ip in ip2player.keys() %}
23+
{% if ip2player[ip].get_state() == "alive" %}
24+
<tr class="{{ ip2player[ip].get_state() }}">
25+
<td class="action_table" id="is_comment">{% if ip2player[ip].get_comment() == True%}+{% endif %}</td>
26+
<td class="action_table" id="player_name">{{ ip2player[ip].get_username() }}</td>
27+
<td class="action_table" id="player_role"><p class="{{ role2team[ip2player[ip].get_role()] }}">{{ ip2player[ip].get_role() }}</p></td>
2828
<td class="action_table"><a href="javascript:delay('/GOD?Ban={{ ip }}', 2000)" onclick="ban_sound_play()">Ban</a></td>
2929
<td class="action_table"><a href="/GOD?Comment={{ ip }}">Comment</< 10000 span class=pl-ent>a></td>
3030
<td class="action_table"><a href="javascript:delay('/GOD?Kill={{ ip }}', 1500)" onclick="kill_sound_play()">Kill</a></td>
3131
</tr>
3232
{% endif %}
3333
{% endfor %}
3434

35-
{% for ip in ip2players.keys() %}
36-
{% if ip2players[ip].get_state() == "banned" %}
37-
<tr class="{{ ip2players[ip].get_state() }}">
38-
<td class="action_table" id="is_comment">{% if ip2players[ip].get_comment() == True%}+{% endif %}</td>
39-
<td class="action_table" id="player_name">{{ ip2players[ip].get_username() }}</td>
40-
<td class="action_table" id="player_role"><p class="{{ role2team[ip2players[ip].get_role()] }}">{{ ip2players[ip].get_role() }}</p></td>
35+
{% for ip in ip2player.keys() %}
36+
{% if ip2player[ip].get_state() == "banned" %}
37+
<tr class="{{ ip2player[ip].get_state() }}">
38+
<td class="action_table" id="is_comment">{% if ip2player[ip].get_comment() == True%}+{% endif %}</td>
39+
<td class="action_table" id="player_name">{{ ip2player[ip].get_username() }}</td>
40+
<td class="action_table" id="player_role"><p class="{{ role2team[ip2player[ip].get_role()] }}">{{ ip2player[ip].get_role() }}</p></td>
4141
<td class="action_table"><a href="javascript:delay('/GOD?Ban={{ ip }}', 2000)" onclick="ban_sound_play()">Ban</a></td>
4242
<td class="action_table"><a href="/GOD?Comment={{ ip }}">Comment</a></td>
4343
<td class="action_table"><a href="javascript:delay('/GOD?Kill={{ ip }}', 1500)" onclick="kill_sound_play()">Kill</a></td>
4444
</tr>
4545
{% endif %}
4646
{% endfor %}
4747

48-
{% for ip in ip2players.keys() %}
49-
{% if ip2players[ip].get_state() == "dead" %}
50-
<tr class="{{ ip2players[ip].get_state() }}">
51-
<td class="action_table" id="is_comment">{% if ip2players[ip].get_comment() == True%}+{% endif %}</td>
52-
<td class="action_table" id="player_name">{{ ip2players[ip].get_username() }}</td>
53-
<td class="action_table" id="player_role"><p class="{{ role2team[ip2players[ip].get_role()] }}">{{ ip2players[ip].get_role() }}</p></td>
48+
{% for ip in ip2player.keys() %}
49+
{% if ip2player[ip].get_state() == "dead" %}
50+
<tr class="{{ ip2player[ip].get_state() }}">
51+
<td class="action_table" id="is_comment">{% if ip2player[ip].get_comment() == True%}+{% endif %}</td>
52+
<td class="action_table" id="player_name">{{ ip2player[ip].get_username() }}</td>
53+
<td class="action_table" id="player_role"><p class="{{ role2team[ip2player[ip].get_role()] }}">{{ ip2player[ip].get_role() }}</p></td>
5454
<td class="action_table"><a href="javascript:delay('/GOD?Ban={{ ip }}', 2000)" onclick="ban_sound_play()">Ban</a></td>
5555
<td class="action_table"><a href="/GOD?Comment={{ ip }}">Comment</a></td>
5656
<td class="action_table"><a href="javascript:delay('/GOD?Kill={{ ip }}', 1500)" onclick="kill_sound_play()">Kill</a></td>
@@ -68,10 +68,10 @@ <h4 class="table_header">Comments</h4>
6868
<th class="action_table" id="player_role">Player Role</th>
6969
</tr>
7070
{% for ip in comments %}
71-
<tr class="{{ ip2players[ip].get_state() }}">
71+
<tr class="{{ ip2player[ip].get_state() }}">
7272
<td class="action_table" id="is_comment">{{ comments.index(ip) + 1 }}</td>
73-
<td class="action_table" id="player_name">{{ ip2players[ip].get_username() }}</td>
74-
<td class="action_table" id="player_role"><p class="{{ role2team[ip2players[ip].get_role()] }}">{{ ip2players[ip].get_role() }}</p></td>
73+
<td class="action_table" id="player_name">{{ ip2player[ip].get_username() }}</td>
74+
<td class="action_table" id="player_role"><p class="{{ role2team[ip2player[ip].get_role()] }}">{{ ip2player[ip].get_role() }}</p></td>
7575
</tr>
7676
{% endfor %}
7777
{% endblock %}

0 commit comments

Comments
 (0)
0