From 8a9b28152b61e57ebc6141b6cf9622ecb1d0ec7d Mon Sep 17 00:00:00 2001 From: sadrasabouri Date: Fri, 11 Sep 2020 12:19:33 +0430 Subject: [PATCH 01/12] fix : little bug fixed. --- mafia_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mafia_params.py b/mafia_params.py index 0faabbf..7cb27b0 100644 --- a/mafia_params.py +++ b/mafia_params.py @@ -27,7 +27,7 @@ "Mafia", "Clown", "Resident", - "Mafia" + "Mafia", "Resident", "Resident"] From cba5de3d2d393e0621957dd0cf86b5f3e6f4977c Mon Sep 17 00:00:00 2001 From: omid Date: Sun, 13 Sep 2020 17:19:58 +0430 Subject: [PATCH 02/12] Adding the Player class which game players will be instantiated form --- player.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 player.py diff --git a/player.py b/player.py new file mode 100644 index 0000000..7ae9030 --- /dev/null +++ b/player.py @@ -0,0 +1,28 @@ +class Player: + """A player in mafia game""" + def __init__(self, ip, username, role, image_name): + self.ip = ip + self.username = username + self.state = "alive" + self.role = role + self.image_name = image_name + self.comment = False + def get_state(self): + return self.state + def get_ip(self): + return self.ip + def get_username(self): + return self.username + def get_role(self): + return self.role + def get_image_name(self): + return self.image_name + def get_comment(self): + return self.comment + + def set_state(self, state): + if state in ["alive", "dead", "banned"]: + self.state = state + def set_comment(self, comment): + self.comment = comment + \ No newline at end of file From 19812452355cb7d53b94bd4f4ea6ae083f17552f Mon Sep 17 00:00:00 2001 From: omid Date: Sun, 13 Sep 2020 17:22:03 +0430 Subject: [PATCH 03/12] Replacing ip2role_index_name with a dictionary whose keys are ips and each value represents a player object --- mafia.py | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/mafia.py b/mafia.py index 47f7803..982d6e7 100644 --- a/mafia.py +++ b/mafia.py @@ -3,6 +3,7 @@ from flask import Flask, render_template, url_for, request from flask_httpauth import HTTPBasicAuth from mafia_params import * +from player import Player app = Flask(__name__) auth = HTTPBasicAuth() @@ -11,7 +12,8 @@ id = 0 nPlayers = 0 roles = [] -ip2role_index_name = {} +#ip2role_index_name = {} +ip2players = {} nComments = 0 comments_ordered = [] @@ -24,24 +26,25 @@ def verify_password(username, password): @app.route('/') @auth.login_required def index(): - global id, ip2role_index_name + global id, ip2players username = str(auth.current_user()) role = "" image_name = "" ip = str(request.remote_addr) - if ip in ip2role_index_name.keys(): - return render_template("Player.html", player=ip2role_index_name[ip]) + if ip in ip2players.keys(): + return render_template("Player.html", player=ip2players[ip]) else: if id > nPlayers: return render_template("404.html", is_farsi=True) role = roles[id] - ip2role_index_name[ip] = [role, + """ip2role_index_name[ip] = [role, str(randrange(1, nRoles[role] + 1)), username, "alive", - False] - image_name = role + "_" + str(ip2role_index_name[ip][1]) + False]""" + image_name = role + "_" + str(randrange(1, nRoles[role] + 1)) + ip2players[ip] = Player(ip, username, role, image_name) print("*" * 20, "New Player","*" * 20) toGod = ip + " : " + str(id) + " : " + username + " --> " + role toGod += "/" + role2fa[role] #TODO: Just in Farsi Mode @@ -63,43 +66,43 @@ def verify_password_god(username, password): @app.route('/GOD') @auth_GOD.login_required def GOD_PAGE(): - global ip2role_index_name, nComments, comments_ordered + global ip2players, nComments, comments_ordered msg = "" if request.args.get("Kill") is not None: ip = request.args.get("Kill") - if ip in ip2role_index_name.keys(): - if ip2role_index_name[ip][3] == "alive": - ip2role_index_name[ip][3] = "dead" + if ip in ip2players.keys(): + if ip2players[ip].get_state() == "alive": + ip2players[ip].set_state("dead") else: - ip2role_index_name[ip][3] = "alive" + ip2players[ip].set_state("alive") else: return render_template("404.html", is_farsi=True) if request.args.get("Ban") is not None: ip = request.args.get("Ban") - if ip in ip2role_index_name.keys(): - if ip2role_index_name[ip][3] == "alive": - ip2role_index_name[ip][3] = "banned" - elif ip2role_index_name[ip][3] == "banned": - ip2role_index_name[ip][3] = "alive" + if ip in ip2players.keys(): + if ip2players[ip].get_state() == "alive": + ip2players[ip].set_state("banned") + elif ip2players[ip].get_state() == "banned": + ip2players[ip].set_state("alive") else: return render_template("404.html", is_farsi=True) if request.args.get("Comment") is not None: ip = request.args.get("Comment") - if ip in ip2role_index_name.keys(): - if ip2role_index_name[ip][4] == False: + if ip in ip2players.keys(): + if ip2players[ip].get_comment() == False: if nComments <= nPlayers // 3: - ip2role_index_name[ip][4] = True + ip2players[ip].set_comment(True) nComments += 1 comments_ordered.append(ip) else: msg = "Error: Out of Comments." else: - ip2role_index_name[ip][4] = False + ip2players[ip].set_comment(False) nComments -= 1 comments_ordered.remove(ip) else: return render_template("404.html", is_farsi=True) - return render_template("GOD.html", ip2role_index_name=ip2role_index_name, + return render_template("GOD.html", ip2players=ip2players, prompt_message=msg, roles={role:roles.count(role) for role in set(roles)}, comments=comments_ordered, role2team=role2team) From 09c6851b02dda930cda2a9a8597f0bf7417cdc8b Mon Sep 17 00:00:00 2001 From: omid Date: Sun, 13 Sep 2020 17:35:13 +0430 Subject: [PATCH 04/12] Changing GOD.html and Player.html to accommodate to new player objects --- templates/GOD.html | 42 +++++++++++++++++++++--------------------- templates/Player.html | 8 ++++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/templates/GOD.html b/templates/GOD.html index 77cf431..11b2cde 100644 --- a/templates/GOD.html +++ b/templates/GOD.html @@ -19,12 +19,12 @@

Players

Player Role Actions -{% for ip in ip2role_index_name.keys() %} -{% if ip2role_index_name[ip][3] == "alive" %} - - {% if ip2role_index_name[ip][4] == True%}+{% endif %} - {{ ip2role_index_name[ip][2] }} -

{{ ip2role_index_name[ip][0] }}

+{% for ip in ip2players.keys() %} +{% if ip2players[ip].get_state() == "alive" %} + + {% if ip2players[ip].get_comment() == True%}+{% endif %} + {{ ip2players[ip].get_username() }} +

{{ ip2players[ip].get_role() }}

Ban Comment Kill @@ -32,12 +32,12 @@

Players

{% endif %} {% endfor %} -{% for ip in ip2role_index_name.keys() %} -{% if ip2role_index_name[ip][3] == "banned" %} - - {% if ip2role_index_name[ip][4] == True%}+{% endif %} - {{ ip2role_index_name[ip][2] }} -

{{ ip2role_index_name[ip][0] }}

+{% for ip in ip2players.keys() %} +{% if ip2players[ip].get_state() == "banned" %} + + {% if ip2players[ip].get_comment() == True%}+{% endif %} + {{ ip2players[ip].get_username() }} +

{{ ip2players[ip].get_role() }}

Ban Comment Kill @@ -45,12 +45,12 @@

Players

{% endif %} {% endfor %} -{% for ip in ip2role_index_name.keys() %} -{% if ip2role_index_name[ip][3] == "dead" %} - - {% if ip2role_index_name[ip][4] == True%}+{% endif %} - {{ ip2role_index_name[ip][2] }} -

{{ ip2role_index_name[ip][0] }}

+{% for ip in ip2players.keys() %} +{% if ip2players[ip].get_state() == "dead" %} + + {% if ip2players[ip].get_comment() == True%}+{% endif %} + {{ ip2players[ip].get_username() }} +

{{ ip2players[ip].get_role() }}

Ban Comment Kill @@ -68,10 +68,10 @@

Comments

Player Role {% for ip in comments %} - + {{ comments.index(ip) + 1 }} - {{ ip2role_index_name[ip][2] }} -

{{ ip2role_index_name[ip][0] }}

+ {{ ip2players[ip].get_username() }} +

{{ ip2players[ip].get_role() }}

{% endfor %} {% endblock %} diff --git a/templates/Player.html b/templates/Player.html index 82c2d2a..5a763d7 100644 --- a/templates/Player.html +++ b/templates/Player.html @@ -10,19 +10,19 @@ {% block sub_table_1 %} -

{{ player[2] }}

+

{{ player.get_username() }}

- {% if player[3] == "alive" %} + {% if player.get_state() == "alive" %}
0
{% endif %} - {% if player[3] == "dead" %}You are Killed!{% endif %} - {% if player[3] == "banned" %}You are Banned from speaking this turn!{% endif %} + {% if player.get_state() == "dead" %}You are Killed!{% endif %} + {% if player.get_state() == "banned" %}You are Banned from speaking this turn!{% endif %} {% endblock %} From e3f4618848925943b7cfacc04fd0f1d12cb80184 Mon Sep 17 00:00:00 2001 From: omid Date: Sun, 13 Sep 2020 21:38:13 +0430 Subject: [PATCH 05/12] Adding the file player.py containing Player class which represents a mafia game player --- player.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 player.py diff --git a/player.py b/player.py new file mode 100644 index 0000000..7ae9030 --- /dev/null +++ b/player.py @@ -0,0 +1,28 @@ +class Player: + """A player in mafia game""" + def __init__(self, ip, username, role, image_name): + self.ip = ip + self.username = username + self.state = "alive" + self.role = role + self.image_name = image_name + self.comment = False + def get_state(self): + return self.state + def get_ip(self): + return self.ip + def get_username(self): + return self.username + def get_role(self): + return self.role + def get_image_name(self): + return self.image_name + def get_comment(self): + return self.comment + + def set_state(self, state): + if state in ["alive", "dead", "banned"]: + self.state = state + def set_comment(self, comment): + self.comment = comment + \ No newline at end of file From 99056d7d27848c7b8210b8a067d189470d2832d0 Mon Sep 17 00:00:00 2001 From: omid Date: Sun, 13 Sep 2020 21:41:22 +0430 Subject: [PATCH 06/12] Replacing ip2role_index_name with ip2players dictionary whose keys are ips and each of it's values contain a player object --- mafia.py | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/mafia.py b/mafia.py index 47f7803..982d6e7 100644 --- a/mafia.py +++ b/mafia.py @@ -3,6 +3,7 @@ from flask import Flask, render_template, url_for, request from flask_httpauth import HTTPBasicAuth from mafia_params import * +from player import Player app = Flask(__name__) auth = HTTPBasicAuth() @@ -11,7 +12,8 @@ id = 0 nPlayers = 0 roles = [] -ip2role_index_name = {} +#ip2role_index_name = {} +ip2players = {} nComments = 0 comments_ordered = [] @@ -24,24 +26,25 @@ def verify_password(username, password): @app.route('/') @auth.login_required def index(): - global id, ip2role_index_name + global id, ip2players username = str(auth.current_user()) role = "" image_name = "" ip = str(request.remote_addr) - if ip in ip2role_index_name.keys(): - return render_template("Player.html", player=ip2role_index_name[ip]) + if ip in ip2players.keys(): + return render_template("Player.html", player=ip2players[ip]) else: if id > nPlayers: return render_template("404.html", is_farsi=True) role = roles[id] - ip2role_index_name[ip] = [role, + """ip2role_index_name[ip] = [role, str(randrange(1, nRoles[role] + 1)), username, "alive", - False] - image_name = role + "_" + str(ip2role_index_name[ip][1]) + False]""" + image_name = role + "_" + str(randrange(1, nRoles[role] + 1)) + ip2players[ip] = Player(ip, username, role, image_name) print("*" * 20, "New Player","*" * 20) toGod = ip + " : " + str(id) + " : " + username + " --> " + role toGod += "/" + role2fa[role] #TODO: Just in Farsi Mode @@ -63,43 +66,43 @@ def verify_password_god(username, password): @app.route('/GOD') @auth_GOD.login_required def GOD_PAGE(): - global ip2role_index_name, nComments, comments_ordered + global ip2players, nComments, comments_ordered msg = "" if request.args.get("Kill") is not None: ip = request.args.get("Kill") - if ip in ip2role_index_name.keys(): - if ip2role_index_name[ip][3] == "alive": - ip2role_index_name[ip][3] = "dead" + if ip in ip2players.keys(): + if ip2players[ip].get_state() == "alive": + ip2players[ip].set_state("dead") else: - ip2role_index_name[ip][3] = "alive" + ip2players[ip].set_state("alive") else: return render_template("404.html", is_farsi=True) if request.args.get("Ban") is not None: ip = request.args.get("Ban") - if ip in ip2role_index_name.keys(): - if ip2role_index_name[ip][3] == "alive": - ip2role_index_name[ip][3] = "banned" - elif ip2role_index_name[ip][3] == "banned": - ip2role_index_name[ip][3] = "alive" + if ip in ip2players.keys(): + if ip2players[ip].get_state() == "alive": + ip2players[ip].set_state("banned") + elif ip2players[ip].get_state() == "banned": + ip2players[ip].set_state("alive") else: return render_template("404.html", is_farsi=True) if request.args.get("Comment") is not None: ip = request.args.get("Comment") - if ip in ip2role_index_name.keys(): - if ip2role_index_name[ip][4] == False: + if ip in ip2players.keys(): + if ip2players[ip].get_comment() == False: if nComments <= nPlayers // 3: - ip2role_index_name[ip][4] = True + ip2players[ip].set_comment(True) nComments += 1 comments_ordered.append(ip) else: msg = "Error: Out of Comments." else: - ip2role_index_name[ip][4] = False + ip2players[ip].set_comment(False) nComments -= 1 comments_ordered.remove(ip) else: return render_template("404.html", is_farsi=True) - return render_template("GOD.html", ip2role_index_name=ip2role_index_name, + return render_template("GOD.html", ip2players=ip2players, prompt_message=msg, roles={role:roles.count(role) for role in set(roles)}, comments=comments_ordered, role2team=role2team) From e6301a19ef0cf628f6d677820f7895dd8b5f5dbc Mon Sep 17 00:00:00 2001 From: omid Date: Sun, 13 Sep 2020 21:42:48 +0430 Subject: [PATCH 07/12] Template files GOD.html and Player.html were slightly changed to accommodate the new structure of handling players --- templates/GOD.html | 42 +++++++++++++++++++++--------------------- templates/Player.html | 8 ++++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/templates/GOD.html b/templates/GOD.html index 77cf431..11b2cde 100644 --- a/templates/GOD.html +++ b/templates/GOD.html @@ -19,12 +19,12 @@

Players

Player Role Actions -{% for ip in ip2role_index_name.keys() %} -{% if ip2role_index_name[ip][3] == "alive" %} - - {% if ip2role_index_name[ip][4] == True%}+{% endif %} - {{ ip2role_index_name[ip][2] }} -

{{ ip2role_index_name[ip][0] }}

+{% for ip in ip2players.keys() %} +{% if ip2players[ip].get_state() == "alive" %} + + {% if ip2players[ip].get_comment() == True%}+{% endif %} + {{ ip2players[ip].get_username() }} +

{{ ip2players[ip].get_role() }}

Ban Comment Kill @@ -32,12 +32,12 @@

Players

{% endif %} {% endfor %} -{% for ip in ip2role_index_name.keys() %} -{% if ip2role_index_name[ip][3] == "banned" %} - - {% if ip2role_index_name[ip][4] == True%}+{% endif %} - {{ ip2role_index_name[ip][2] }} -

{{ ip2role_index_name[ip][0] }}

+{% for ip in ip2players.keys() %} +{% if ip2players[ip].get_state() == "banned" %} + + {% if ip2players[ip].get_comment() == True%}+{% endif %} + {{ ip2players[ip].get_username() }} +

{{ ip2players[ip].get_role() }}

Ban Comment Kill @@ -45,12 +45,12 @@

Players

{% endif %} {% endfor %} -{% for ip in ip2role_index_name.keys() %} -{% if ip2role_index_name[ip][3] == "dead" %} - - {% if ip2role_index_name[ip][4] == True%}+{% endif %} - {{ ip2role_index_name[ip][2] }} -

{{ ip2role_index_name[ip][0] }}

+{% for ip in ip2players.keys() %} +{% if ip2players[ip].get_state() == "dead" %} + + {% if ip2players[ip].get_comment() == True%}+{% endif %} + {{ ip2players[ip].get_username() }} +

{{ ip2players[ip].get_role() }}

Ban Comment Kill @@ -68,10 +68,10 @@

Comments

Player Role {% for ip in comments %} - + {{ comments.index(ip) + 1 }} - {{ ip2role_index_name[ip][2] }} -

{{ ip2role_index_name[ip][0] }}

+ {{ ip2players[ip].get_username() }} +

{{ ip2players[ip].get_role() }}

{% endfor %} {% endblock %} diff --git a/templates/Player.html b/templates/Player.html index 82c2d2a..5a763d7 100644 --- a/templates/Player.html +++ b/templates/Player.html @@ -10,19 +10,19 @@ {% block sub_table_1 %} -

{{ player[2] }}

+

{{ player.get_username() }}

- {% if player[3] == "alive" %} + {% if player.get_state() == "alive" %}
0
{% endif %} - {% if player[3] == "dead" %}You are Killed!{% endif %} - {% if player[3] == "banned" %}You are Banned from speaking this turn!{% endif %} + {% if player.get_state() == "dead" %}You are Killed!{% endif %} + {% if player.get_state() == "banned" %}You are Banned from speaking this turn!{% endif %} {% endblock %} From 2ad3febc83b2126ba984a64d45d260d47223182a Mon Sep 17 00:00:00 2001 From: sadrasabouri Date: Mon, 14 Sep 2020 11:38:45 +0430 Subject: [PATCH 08/12] fix : maximum number of players problem fixed. --- mafia.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mafia.py b/mafia.py index 47f7803..bd7f0cd 100644 --- a/mafia.py +++ b/mafia.py @@ -33,7 +33,7 @@ def index(): if ip in ip2role_index_name.keys(): return render_template("Player.html", player=ip2role_index_name[ip]) else: - if id > nPlayers: + if id >= nPlayers: return render_template("404.html", is_farsi=True) role = roles[id] ip2role_index_name[ip] = [role, From 32c80682753b4fdc0954a794b63ba3914a952158 Mon Sep 17 00:00:00 2001 From: omid Date: Mon, 14 Sep 2020 11:49:30 +0430 Subject: [PATCH 09/12] Minor changes requested in the previous pr were applied --- mafia.py | 46 ++++++++++++++++++++-------------------------- player.py | 8 ++++++++ templates/GOD.html | 42 +++++++++++++++++++++--------------------- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/mafia.py b/mafia.py index 982d6e7..43e4119 100644 --- a/mafia.py +++ b/mafia.py @@ -12,8 +12,7 @@ id = 0 nPlayers = 0 roles = [] -#ip2role_index_name = {} -ip2players = {} +ip2player = {} nComments = 0 comments_ordered = [] @@ -26,25 +25,20 @@ def verify_password(username, password): @app.route('/') @auth.login_required def index(): - global id, ip2players + global id, ip2player username = str(auth.current_user()) role = "" image_name = "" ip = str(request.remote_addr) - if ip in ip2players.keys(): - return render_template("Player.html", player=ip2players[ip]) + if ip in ip2player.keys(): + return render_template("Player.html", player=ip2player[ip]) else: if id > nPlayers: return render_template("404.html", is_farsi=True) role = roles[id] - """ip2role_index_name[ip] = [role, - str(randrange(1, nRoles[role] + 1)), - username, - "alive", - False]""" image_name = role + "_" + str(randrange(1, nRoles[role] + 1)) - ip2players[ip] = Player(ip, username, role, image_name) + ip2player[ip] = Player(ip, username, role, image_name) print("*" * 20, "New Player","*" * 20) toGod = ip + " : " + str(id) + " : " + username + " --> " + role toGod += "/" + role2fa[role] #TODO: Just in Farsi Mode @@ -66,43 +60,43 @@ def verify_password_god(username, password): @app.route('/GOD') @auth_GOD.login_required def GOD_PAGE(): - global ip2players, nComments, comments_ordered + global ip2player, nComments, comments_ordered msg = "" if request.args.get("Kill") is not None: ip = request.args.get("Kill") - if ip in ip2players.keys(): - if ip2players[ip].get_state() == "alive": - ip2players[ip].set_state("dead") + if ip in ip2player.keys(): + if ip2player[ip].get_state() == "alive": + ip2player[ip].set_state("dead") else: - ip2players[ip].set_state("alive") + ip2player[ip].set_state("alive") else: return render_template("404.html", is_farsi=True) if request.args.get("Ban") is not None: ip = request.args.get("Ban") - if ip in ip2players.keys(): - if ip2players[ip].get_state() == "alive": - ip2players[ip].set_state("banned") - elif ip2players[ip].get_state() == "banned": - ip2players[ip].set_state("alive") + if ip in ip2player.keys(): + if ip2player[ip].get_state() == "alive": + ip2player[ip].set_state("banned") + elif ip2player[ip].get_state() == "banned": + ip2player[ip].set_state("alive") else: return render_template("404.html", is_farsi=True) if request.args.get("Comment") is not None: ip = request.args.get("Comment") - if ip in ip2players.keys(): - if ip2players[ip].get_comment() == False: + if ip in ip2player.keys(): + if ip2player[ip].get_comment() == False: if nComments <= nPlayers // 3: - ip2players[ip].set_comment(True) + ip2player[ip].set_comment(True) nComments += 1 comments_ordered.append(ip) else: msg = "Error: Out of Comments." else: - ip2players[ip].set_comment(False) + ip2player[ip].set_comment(False) nComments -= 1 comments_ordered.remove(ip) else: return render_template("404.html", is_farsi=True) - return render_template("GOD.html", ip2players=ip2players, + return render_template("GOD.html", ip2player=ip2player, prompt_message=msg, roles={role:roles.count(role) for role in set(roles)}, comments=comments_ordered, role2team=role2team) diff --git a/player.py b/player.py index 7ae9030..9550bea 100644 --- a/player.py +++ b/player.py @@ -7,22 +7,30 @@ def __init__(self, ip, username, role, image_name): self.role = role self.image_name = image_name self.comment = False + def get_state(self): return self.state + def get_ip(self): return self.ip + def get_username(self): return self.username + def get_role(self): return self.role + def get_image_name(self): return self.image_name + def get_comment(self): return self.comment + def set_state(self, state): if state in ["alive", "dead", "banned"]: self.state = state + def set_comment(self, comment): self.comment = comment \ No newline at end of file diff --git a/templates/GOD.html b/templates/GOD.html index 11b2cde..36de706 100644 --- a/templates/GOD.html +++ b/templates/GOD.html @@ -19,12 +19,12 @@

Players

Player Role Actions -{% for ip in ip2players.keys() %} -{% if ip2players[ip].get_state() == "alive" %} - - {% if ip2players[ip].get_comment() == True%}+{% endif %} - {{ ip2players[ip].get_username() }} -

{{ ip2players[ip].get_role() }}

+{% for ip in ip2player.keys() %} +{% if ip2player[ip].get_state() == "alive" %} + + {% if ip2player[ip].get_comment() == True%}+{% endif %} + {{ ip2player[ip].get_username() }} +

{{ ip2player[ip].get_role() }}

Ban Comment Kill @@ -32,12 +32,12 @@

Players

{% endif %} {% endfor %} -{% for ip in ip2players.keys() %} -{% if ip2players[ip].get_state() == "banned" %} - - {% if ip2players[ip].get_comment() == True%}+{% endif %} - {{ ip2players[ip].get_username() }} -

{{ ip2players[ip].get_role() }}

+{% for ip in ip2player.keys() %} +{% if ip2player[ip].get_state() == "banned" %} + + {% if ip2player[ip].get_comment() == True%}+{% endif %} + {{ ip2player[ip].get_username() }} +

{{ ip2player[ip].get_role() }}

Ban Comment Kill @@ -45,12 +45,12 @@

Players

{% endif %} {% endfor %} -{% for ip in ip2players.keys() %} -{% if ip2players[ip].get_state() == "dead" %} - - {% if ip2players[ip].get_comment() == True%}+{% endif %} - {{ ip2players[ip].get_username() }} -

{{ ip2players[ip].get_role() }}

+{% for ip in ip2player.keys() %} +{% if ip2player[ip].get_state() == "dead" %} + + {% if ip2player[ip].get_comment() == True%}+{% endif %} + {{ ip2player[ip].get_username() }} +

{{ ip2player[ip].get_role() }}

Ban Comment Kill @@ -68,10 +68,10 @@

Comments

Player Role {% for ip in comments %} - + {{ comments.index(ip) + 1 }} - {{ ip2players[ip].get_username() }} -

{{ ip2players[ip].get_role() }}

+ {{ ip2player[ip].get_username() }} +

{{ ip2player[ip].get_role() }}

{% endfor %} {% endblock %} From 948d231378198758b77732ddc216de7116ee6b6b Mon Sep 17 00:00:00 2001 From: sadrasabouri Date: Mon, 14 Sep 2020 11:54:01 +0430 Subject: [PATCH 10/12] fix : minor codefactor issues fixed. --- mafia.py | 38 ++++++++++++++++++-------------------- static/css/style.css | 16 ++++++++-------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/mafia.py b/mafia.py index bd7f0cd..6c46237 100644 --- a/mafia.py +++ b/mafia.py @@ -2,13 +2,13 @@ from random import randrange, shuffle from flask import Flask, render_template, url_for, request from flask_httpauth import HTTPBasicAuth -from mafia_params import * +from mafia_params import ordered_roles, nRoles, role2team, descriptions, descriptions_fa, role2fa app = Flask(__name__) auth = HTTPBasicAuth() auth_GOD = HTTPBasicAuth() preshared_key = "" -id = 0 +player_id = 0 nPlayers = 0 roles = [] ip2role_index_name = {} @@ -24,7 +24,7 @@ def verify_password(username, password): @app.route('/') @auth.login_required def index(): - global id, ip2role_index_name + global player_id, ip2role_index_name username = str(auth.current_user()) role = "" image_name = "" @@ -32,21 +32,20 @@ def index(): if ip in ip2role_index_name.keys(): return render_template("Player.html", player=ip2role_index_name[ip]) - else: - if id >= nPlayers: - return render_template("404.html", is_farsi=True) - role = roles[id] - ip2role_index_name[ip] = [role, - str(randrange(1, nRoles[role] + 1)), - username, - "alive", - False] - image_name = role + "_" + str(ip2role_index_name[ip][1]) - print("*" * 20, "New Player","*" * 20) - toGod = ip + " : " + str(id) + " : " + username + " --> " + role - toGod += "/" + role2fa[role] #TODO: Just in Farsi Mode - print(toGod) - id += 1 + if player_id >= nPlayers: + return render_template("404.html", is_farsi=True) + role = roles[player_id] + ip2role_index_name[ip] = [role, + str(randrange(1, nRoles[role] + 1)), + username, + "alive", + False] + image_name = role + "_" + str(ip2role_index_name[ip][1]) + print("*" * 20, "New Player","*" * 20) + toGod = ip + " : " + str(player_id) + " : " + username + " --> " + role + toGod += "/" + role2fa[role] + print(toGod) + player_id += 1 return render_template("index.html", image_name=image_name, role_name=role, role_name_fa=role2fa[role], @@ -86,7 +85,7 @@ def GOD_PAGE(): if request.args.get("Comment") is not None: ip = request.args.get("Comment") if ip in ip2role_index_name.keys(): - if ip2role_index_name[ip][4] == False: + if ip2role_index_name[ip][4] is False: if nComments <= nPlayers // 3: ip2role_index_name[ip][4] = True nComments += 1 @@ -162,5 +161,4 @@ def give_me_roles(ordered_roles): print("_" * 54) app.run(host="0.0.0.0", port=5000, - debug=True, use_reloader=False) diff --git a/static/css/style.css b/static/css/style.css index a5dfda5..40c7cae 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -12,29 +12,29 @@ h1 { font-size: 30px; - padding: 0 0 0 0; - margin: 0 0 0 0; + padding: 0px; + margin: 0px; } h2 { font-size: 25px; color: rgb(172, 161, 147); - padding: 0 0 0 0; - margin: 0 0 0 0; + padding: 0px; + margin: 0px; } .table_header { - margin: 0 0 0 0; + margin: 0px; margin-bottom: 10px; - padding: 0 0 0 0; + padding: 0px; text-align: center; } p { font-size: 10px; color: rgb(163, 157, 150); - padding: 0 0 0 0; - margin: 0 0 0 0; + padding: 0px; + margin: 0px; } table, td, th { From a41e46ea4d52c57606efd38b0e8906554f05a264 Mon Sep 17 00:00:00 2001 From: sadrasabouri Date: Mon, 14 Sep 2020 23:33:42 +0430 Subject: [PATCH 11/12] fix : codefactor issues fixed. --- mafia.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mafia.py b/mafia.py index 6c46237..f4faca2 100644 --- a/mafia.py +++ b/mafia.py @@ -122,6 +122,13 @@ def help_me(): def give_me_roles(ordered_roles): + """ + Check the number of players and roles. + + :param ordered_roles: ordered roles + :type ordered_roles: list + :return: a valid list for roles + """ n = len(ordered_roles) if n >= 14: ordered_roles[12] = 'Groom' From 73e257e5a9ac163179e16ba886f878821b7bdf41 Mon Sep 17 00:00:00 2001 From: sadrasabouri Date: Mon, 14 Sep 2020 23:52:47 +0430 Subject: [PATCH 12/12] fix : codefactor issues fixed. --- mafia.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mafia.py b/mafia.py index 2f2fa3b..abc8b12 100644 --- a/mafia.py +++ b/mafia.py @@ -2,7 +2,7 @@ from random import randrange, shuffle from flask import Flask, render_template, url_for, request from flask_httpauth import HTTPBasicAuth -from mafia_params import * +from mafia_params import ordered_roles, nRoles, role2team, descriptions, descriptions_fa, role2fa from player import Player app = Flask(__name__) @@ -25,7 +25,7 @@ def verify_password(username, password): @app.route('/') @auth.login_required def index(): - global id, ip2player + global player_id, ip2player username = str(auth.current_user()) role = "" image_name = "" @@ -34,16 +34,16 @@ def index(): if ip in ip2player.keys(): return render_template("Player.html", player=ip2player[ip]) else: - if id > nPlayers: + if player_id > nPlayers: return render_template("404.html", is_farsi=True) - role = roles[id] + role = roles[player_id] image_name = role + "_" + str(randrange(1, nRoles[role] + 1)) ip2player[ip] = Player(ip, username, role, image_name) print("*" * 20, "New Player","*" * 20) - toGod = ip + " : " + str(id) + " : " + username + " --> " + role + toGod = ip + " : " + str(player_id) + " : " + username + " --> " + role toGod += "/" + role2fa[role] #TODO: Just in Farsi Mode print(toGod) - id += 1 + player_id += 1 return render_template("index.html", image_name=image_name, role_name=role, role_name_fa=role2fa[role], @@ -83,7 +83,7 @@ def GOD_PAGE(): if request.args.get("Comment") is not None: ip = request.args.get("Comment") if ip in ip2player.keys(): - if ip2player[ip].get_comment() == False: + if ip2player[ip].get_comment() is False: if nComments <= nPlayers // 3: ip2player[ip].set_comment(True) nComments += 1