Skip to content

Commit

Permalink
Merge pull request #16 from sadrasabouri/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
sadrasabouri authored Sep 10, 2020
2 parents 47e3315 + 16a4d82 commit 0bd680e
Show file tree
Hide file tree
Showing 143 changed files with 671 additions and 60 deletions.
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at sabouri.sadra@gmail.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
43 changes: 32 additions & 11 deletions README.md

Large diffs are not rendered by default.

103 changes: 95 additions & 8 deletions mafia.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

app = Flask(__name__)
auth = HTTPBasicAuth()
auth_GOD = HTTPBasicAuth()
preshared_key = ""
id = 0
nPlayers = 0
roles = []
ip2role_index_name = {}
nComments = 0
comments_ordered = []

@auth.verify_password
def verify_password(username, password):
Expand All @@ -27,13 +31,16 @@ def index():
ip = str(request.remote_addr)

if ip in ip2role_index_name.keys():
role = ip2role_index_name[ip][0]
image_name = ip2role_index_name[ip][0] + "_" + str(ip2role_index_name[ip][1])
return render_template("Player.html", player=ip2role_index_name[ip])
else:
if id > nPlayers:
return "Numbers of players out of range!" #TODO:well defined Error Page
return render_template("404.html", is_farsi=True)
role = roles[id]
ip2role_index_name[ip] = (role, str(randrange(1, nRoles[role] + 1)), username)
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
Expand All @@ -47,6 +54,56 @@ def index():
is_farsi=True)


@auth_GOD.verify_password
def verify_password_god(username, password):
if password == preshared_key:
return username


@app.route('/GOD')
@auth_GOD.login_required
def GOD_PAGE():
global ip2role_index_name, 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"
else:
ip2role_index_name[ip][3] = "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"
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 nComments <= nPlayers // 3:
ip2role_index_name[ip][4] = True
nComments += 1
comments_ordered.append(ip)
else:
msg = "Error: Out of Comments."
else:
ip2role_index_name[ip][4] = 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,
prompt_message=msg, roles={role:roles.count(role) for role in set(roles)},
comments=comments_ordered, role2team=role2team)


@app.errorhandler(404)
def invalid_route(e):
return render_template("404.html", is_farsi=True)
Expand All @@ -65,15 +122,45 @@ def help_me():
exit()


def give_me_roles(ordered_roles):
n = len(ordered_roles)
if n >= 14:
ordered_roles[12] = 'Groom'
ordered_roles[13] = 'Bride'
if n % 3 == 0:
ordered_roles[14] = 'Serial Killer'
if n % 3 != 0:
try:
i = ordered_roles.index('Mafia')
ordered_roles[i] = 'Made Man'
ordered_roles[2] = 'Reporter'
except ValueError:
pass
if n % 3 == 2:
try:
i = ordered_roles.index('Mafia')
ordered_roles[i] = 'Kind Wife'
except ValueError:
pass
return ordered_roles


if __name__ == "__main__":
if len(argv) < 2 or argv[1] in ['--help', 'help', '-h']:
help_me()
nPlayers = int(argv[1])
if nPlayers > len(ordered_roles):
print("Too many players, mafia doesn't support a game with", nPlayers, "player.")
help_me()
roles = ordered_roles[:nPlayers]
roles = give_me_roles(ordered_roles[:nPlayers])
shuffle(roles)
app.run(host="0.0.0.0", \
port=5000, \
debug=True)
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()"
for i in range(4):
preshared_key += chars[randrange(0, len(chars))]
print("_" * 20 + "GOD's password" + "_" * 20)
print(preshared_key)
print("_" * 54)
app.run(host="0.0.0.0",
port=5000,
debug=True,
use_reloader=False)
Loading

0 comments on commit 0bd680e

Please sign in to comment.