Skip to content

Commit 0bd680e

Browse files
authored
Merge pull request #16 from sadrasabouri/dev
Dev
2 parents 47e3315 + 16a4d82 commit 0bd680e

File tree

143 files changed

+671
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+671
-60
lines changed

CODE_OF_CONDUCT.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at sabouri.sadra@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

README.md

+32-11
Large diffs are not rendered by default.

mafia.py

+95-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
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
16+
comments_ordered = []
1317

1418
@auth.verify_password
1519
def verify_password(username, password):
@@ -27,13 +31,16 @@ def index():
2731
ip = str(request.remote_addr)
2832

2933
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])
34+
return render_template("Player.html", player=ip2role_index_name[ip])
3235
else:
3336
if id > nPlayers:
34-
return "Numbers of players out of range!" #TODO:well defined Error Page
37+
return render_template("404.html", is_farsi=True)
3538
role = roles[id]
36-
ip2role_index_name[ip] = (role, str(randrange(1, nRoles[role] + 1)), username)
39+
ip2role_index_name[ip] = [role,
40+
str(randrange(1, nRoles[role] + 1)),
41+
username,
42+
"alive",
43+
False]
3744
image_name = role + "_" + str(ip2role_index_name[ip][1])
3845
print("*" * 20, "New Player","*" * 20)
3946
toGod = ip + " : " + str(id) + " : " + username + " --> " + role
@@ -47,6 +54,56 @@ def index():
4754
is_farsi=True)
4855

4956

57+
@auth_GOD.verify_password
58+
def verify_password_god(username, password):
59+
if password == preshared_key:
60+
return username
61+
62+
63+
@app.route('/GOD')
64+
@auth_GOD.login_required
65+
def GOD_PAGE():
66+
global ip2role_index_name, nComments, comments_ordered
67+
msg = ""
68+
if request.args.get("Kill") is not None:
69+
ip = request.args.get("Kill")
70+
if ip in ip2role_index_name.keys():
71+
if ip2role_index_name[ip][3] == "alive":
72+
ip2role_index_name[ip][3] = "dead"
73+
else:
74+
ip2role_index_name[ip][3] = "alive"
75+
else:
76+
return render_template("404.html", is_farsi=True)
77+
if request.args.get("Ban") is not None:
78+
ip = request.args.get("Ban")
79+
if ip in ip2role_index_name.keys():
80+
if ip2role_index_name[ip][3] == "alive":
81+
ip2role_index_name[ip][3] = "banned"
82+
elif ip2role_index_name[ip][3] == "banned":
83+
ip2role_index_name[ip][3] = "alive"
84+
else:
85+
return render_template("404.html", is_farsi=True)
86+
if request.args.get("Comment") is not None:
87+
ip = request.args.get("Comment")
88+
if ip in ip2role_index_name.keys():
89+
if ip2role_index_name[ip][4] == False:
90+
if nComments <= nPlayers // 3:
91+
ip2role_index_name[ip][4] = True
92+
nComments += 1
93+
comments_ordered.append(ip)
94+
else:
95+
msg = "Error: Out of Comments."
96+
else:
97+
ip2role_index_name[ip][4] = False
98+
nComments -= 1
99+
comments_ordered.remove(ip)
100+
else:
101+
return render_template("404.html", is_farsi=True)
102+
return render_template("GOD.html", ip2role_index_name=ip2role_index_name,
103+
prompt_message=msg, roles={role:roles.count(role) for role in set(roles)},
104+
comments=comments_ordered, role2team=role2team)
105+
106+
50107
@app.errorhandler(404)
51108
def invalid_route(e):
52109
return render_template("404.html", is_farsi=True)
@@ -65,15 +122,45 @@ def help_me():
65122
exit()
66123

67124

125+
def give_me_roles(ordered_roles):
126+
n = len(ordered_roles)
127+
if n >= 14:
128+
ordered_roles[12] = 'Groom'
129+
ordered_roles[13] = 'Bride'
130+
if n % 3 == 0:
131+
ordered_roles[14] = 'Serial Killer'
132+
if n % 3 != 0:
133+
try:
134+
i = ordered_roles.index('Mafia')
135+
ordered_roles[i] = 'Made Man'
136+
ordered_roles[2] = 'Reporter'
137+
except ValueError:
138+
pass
139+
if n % 3 == 2:
140+
try:
141+
i = ordered_roles.index('Mafia')
142+
ordered_roles[i] = 'Kind Wife'
143+
except ValueError:
144+
pass
145+
return ordered_roles
146+
147+
68148
if __name__ == "__main__":
69149
if len(argv) < 2 or argv[1] in ['--help', 'help', '-h']:
70150
help_me()
71151
nPlayers = int(argv[1])
72152
if nPlayers > len(ordered_roles):
73153
print("Too many players, mafia doesn't support a game with", nPlayers, "player.")
74154
help_me()
75-
roles = ordered_roles[:nPlayers]
155+
roles = give_me_roles(ordered_roles[:nPlayers])
76156
shuffle(roles)
77-
app.run(host="0.0.0.0", \
78-
port=5000, \
79-
debug=True)
157+
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()"
158+
for i in range(4):
159+
preshared_key += chars[randrange(0, len(chars))]
160+
print("_" * 20 + "GOD's password" + "_" * 20)
161+
print(preshared_key)
162+
print("_" * 54)
163+
app.run(host="0.0.0.0",
164+
port=5000,
165+
debug=True,
166+
use_reloader=False)

0 commit comments

Comments
 (0)