Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
Release 0.4!
Browse files Browse the repository at this point in the history
See release page for changelog!
  • Loading branch information
PhlexPlexico authored Aug 23, 2019
2 parents b3ee52e + 164d7a9 commit d2f02c6
Show file tree
Hide file tree
Showing 20 changed files with 369 additions and 170 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Please see the [installation instructions](https://github.com/PhlexPlexico/get5-
Autoformatting:

```sh
cd get5
autopep8 -r get5 --in-place
autopep8 -r get5 --diff # should have no output
```
Expand Down
2 changes: 1 addition & 1 deletion get5/get5_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create_test_data(self):
db.session.commit()

Match.create(user, team1.id, team2.id, '', '', 1, False,
'Map {MAPNUMBER}', ['de_dust2', 'de_cache', 'de_mirage'], season.id, 'always_knife', 'CT', True, server.id, 0, 0, None)
'Map {MAPNUMBER}', ['de_dust2', 'de_cache', 'de_mirage'], season.id, 'always_knife', 'CT', server.id, 0, 0, None, False)
db.session.commit()

vetoBan = Veto.create(1, 'EnvyUs', 'de_dust2', 'ban')
Expand Down
1 change: 0 additions & 1 deletion get5/leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def getPlayerLeaderboard(seasonid=None):
dctPlayer['name'] = (player.get_player_name())
dctPlayer['kills'] = (sum(c.kills for c in totalStats))
dctPlayer['deaths'] = (sum(c.deaths for c in totalStats))
app.logger.info("{}".format(totalStats.count()))
dctPlayer['kdr'] = (mean(c.get_kdr() for c in totalStats))
dctPlayer['assists'] = (sum(c.assists for c in totalStats))
dctPlayer['adr'] = (mean(c.get_adr() for c in totalStats))
Expand Down
165 changes: 127 additions & 38 deletions get5/match.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ class MatchForm(Form):
season_selection = SelectField('Season', coerce=int,
validators=[validators.optional()])

enforce_teams = BooleanField('Enforce Teams',
default=True)

team1_series_score = IntegerField('Team 1 Series Score',
default=0,
validators=[validators.NumberRange(0, 7)])
Expand All @@ -133,6 +130,9 @@ class MatchForm(Form):
spectator_string = StringField('Spectator IDs',
default='')

private_match = BooleanField('Private Match?',
default=False)

def add_teams(self, user):
if self.team1_id.choices is None:
self.team1_id.choices = []
Expand Down Expand Up @@ -197,7 +197,7 @@ def match_create():
max_matches = config_setting('USER_MAX_MATCHES')
season_id = None

if max_matches >= 0 and num_matches >= max_matches and not g.user.admin:
if max_matches >= 0 and num_matches >= max_matches and not (util.is_admin(g.user) or util.is_super_admin(g.user)):
flash('You already have the maximum number of matches ({}) created'.format(
num_matches))

Expand Down Expand Up @@ -251,16 +251,18 @@ def match_create():
suc, new_auth = steamid.auth_to_steam64(auth)
if suc:
specList.append(new_auth)

# End Spectator Feature

match = Match.create(
g.user, form.data['team1_id'], form.data['team2_id'],
form.data['team1_string'], form.data['team2_string'],
max_maps, skip_veto,
form.data['match_title'], form.data[
'veto_mappool'], season_id,
form.data['side_type'], form.data['veto_first'],
form.data['enforce_teams'], form.data['server_id'],
team1_series_score, team2_series_score, specList)
form.data['match_title'], form.data['veto_mappool'],
season_id, form.data['side_type'],
form.data['veto_first'], form.data['server_id'],
team1_series_score, team2_series_score, specList,
form.data['private_match'])

# Save plugin version data if we have it
if json_reply and 'plugin_version' in json_reply:
Expand Down Expand Up @@ -289,20 +291,62 @@ def match_create():
match_text_option=config_setting('CREATE_MATCH_TITLE_TEXT'))


@match_blueprint.route('/match/<int:matchid>/forfeit/<int:teamwinner>')
def match_forfeit(matchid, teamwinner):
match = Match.query.get_or_404(matchid)
super_admintools_check(g.user, match)
if teamwinner == 1:
winnerId = match.team1_id
elif teamwinner == 2:
winnerId = match.team2_id
else:
raise BadRequestError('Did not select a proper team.')

match.winner = winnerId
map_stats = MapStats.get_or_create(match.id, 0, '', '')
if teamwinner == 1:
match.team1_score = 1
match.team2_score = 0
map_stats.team1_score = 16
else:
match.team1_score = 0
match.team2_score = 1
map_stats.team2_score = 16
match.start_time = datetime.now()
match.end_time = datetime.now()
match.forfeit = 1
map_stats.end_time = datetime.now()
server = GameServer.query.get(match.server_id)
if server:
server.in_use = False

db.session.commit()

try:
server.send_rcon_command('get5_endmatch', raise_errors=True)
except util.RconError as e:
flash('Failed to cancel match: ' + str(e))

return redirect('/mymatches')

@match_blueprint.route('/match/<int:matchid>')
def match(matchid):
match = Match.query.get_or_404(matchid)
# Begin Private/Public Match Implementation

vetoes = Veto.query.filter_by(match_id=matchid)
if match.server_id:
server = GameServer.query.get_or_404(match.server_id)
else:
server = None
team1 = Team.query.get_or_404(match.team1_id)
team2 = Team.query.get_or_404(match.team2_id)
check_private_or_public(g.user, match, team1, team2)

map_stat_list = match.map_stats.all()
completed = match.winner
try:
if server is not None and completed is None:
if server is not None and (completed is None and match.cancelled == 0):
password = server.receive_rcon_value('sv_password')
connect_string = str("steam://connect/") + str(server.ip_string) + str(":") + \
str(server.port) + str("/") + str(password)
Expand All @@ -318,17 +362,22 @@ def match(matchid):
app.logger.info('Attempted to connect to server {}, but it is offline'
.format(server.ip_string))

is_owner = False
is_match_owner = False
is_server_op = False
has_admin_access = False
has_super_admin_access = False
if g.user:
is_owner = (g.user.id == match.user_id)
has_admin_access = is_owner or (config_setting(
'ADMINS_ACCESS_ALL_MATCHES') and g.user.admin)
is_match_owner = (g.user.id == match.user_id)
has_admin_access = (config_setting(
'ADMINS_ACCESS_ALL_MATCHES') and util.is_admin(g.user))
has_super_admin_access = util.is_super_admin(g.user)
is_server_op = util.is_server_owner(g.user, server)
return render_template(
'match.html', user=g.user, admin_access=has_admin_access,
match=match, team1=team1, team2=team2,
map_stat_list=map_stat_list, completed=completed, connect_string=connect_string,
gotv_string=gotv_string, vetoes=vetoes)
gotv_string=gotv_string, super_admin_access=has_super_admin_access, vetoes=vetoes,
server_owner=is_server_op, match_owner=is_match_owner)


@match_blueprint.route('/match/<int:matchid>/scoreboard')
Expand All @@ -344,6 +393,7 @@ def merge(a, b):
match = Match.query.get_or_404(matchid)
team1 = Team.query.get_or_404(match.team1_id)
team2 = Team.query.get_or_404(match.team2_id)
check_private_or_public(g.user, match, team1, team2)
map_num = 0
map_stat_list = match.map_stats.all()
player_dict = {}
Expand Down Expand Up @@ -390,22 +440,6 @@ def match_config(matchid):
return response


def admintools_check(user, match):
if user is None:
raise BadRequestError('You do not have access to this page')

grant_admin_access = user.admin and get5.config_setting(
'ADMINS_ACCESS_ALL_MATCHES')
if user.id != match.user_id and not grant_admin_access:
raise BadRequestError('You do not have access to this page')

if match.finished():
raise BadRequestError('Match already finished')

if match.cancelled:
raise BadRequestError('Match is cancelled')


@match_blueprint.route('/match/<int:matchid>/cancel')
def match_cancel(matchid):
app.logger.info("Match server id is: {}".format(matchid))
Expand All @@ -430,10 +464,14 @@ def match_cancel(matchid):
@match_blueprint.route('/match/<int:matchid>/rcon')
def match_rcon(matchid):
match = Match.query.get_or_404(matchid)
admintools_check(g.user, match)

command = request.values.get('command')
server = GameServer.query.get_or_404(match.server_id)
owns_server = util.is_server_owner(g.user, server)
is_sadmin = util.is_super_admin(g.user)
# Check to see if user owns server.
if not owns_server or not is_sadmin:
raise BadRequestError('You are not the server owner.')

if command:
try:
Expand Down Expand Up @@ -546,21 +584,19 @@ def match_backup(matchid):

@match_blueprint.route("/matches")
def matches():
page = util.as_int(request.values.get('page'), on_fail=1)
matches = Match.query.order_by(-Match.id).filter_by(
cancelled=False).paginate(page, 20)
cancelled=False)
return render_template('matches.html', user=g.user, matches=matches,
my_matches=False, all_matches=True, page=page)
my_matches=False, all_matches=True)


@match_blueprint.route("/matches/<int:userid>")
def matches_user(userid):
user = User.query.get_or_404(userid)
page = util.as_int(request.values.get('page'), on_fail=1)
matches = user.matches.order_by(-Match.id).paginate(page, 20)
matches = user.matches.order_by(-Match.id)
is_owner = (g.user is not None) and (userid == g.user.id)
return render_template('matches.html', user=g.user, matches=matches,
my_matches=is_owner, all_matches=False, match_owner=user, page=page)
my_matches=is_owner, all_matches=False, match_owner=user)


@match_blueprint.route("/mymatches")
Expand Down Expand Up @@ -617,3 +653,56 @@ def generate():
# add a filename
response.headers.set("Content-Disposition", "attachment", filename=logName)
return response


# Begin Helper Functions


def super_admintools_check(user, match):
if user is None:
raise BadRequestError('You do not have access to this page')

if not util.is_super_admin(user):
raise BadRequestError('You do not have access to this page')

if match.finished():
raise BadRequestError('Match already finished')

if match.cancelled:
raise BadRequestError('Match is cancelled')


def admintools_check(user, match):
if user is None:
raise BadRequestError('You do not have access to this page')

grant_admin_access = util.is_admin(user) and get5.config_setting(
'ADMINS_ACCESS_ALL_MATCHES')
if user.id != match.user_id and not grant_admin_access:
raise BadRequestError('You do not have access to this page')

if match.finished():
raise BadRequestError('Match already finished')

if match.cancelled:
raise BadRequestError('Match is cancelled')

def check_private_or_public(user, match, team1, team2):
if match.is_private_match():
if not user:
raise BadRequestError("Please login before viewing this match.")
# Get team lists, and check if logged in user is part of match.
if not (user.id == match.user_id) or (config_setting(
'ADMINS_ACCESS_ALL_MATCHES') and util.lis_admin(user)) or util.is_super_admin(user):
isPlayer = False
playerstats_steam = PlayerStats.query(PlayerStats.steam_id).filter_by(
match_id=match.id)
playerList = list(set(team1.auths + team2.auths + playerstats_steam))
for player in playerList:
if user.steam_id == player:
isPlayer = True
break
if not isPlayer:
raise BadRequestError(
"You cannot view this match as you were not a part of it!")
# End Helper Functions
4 changes: 0 additions & 4 deletions get5/match_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def test_match_create_already_live(self):
'series_type': 'bo3',
'veto_first': 'CT',
'veto_mappool': ['de_dust2', 'de_cache', 'de_mirage'],
'enforce_teams': True,
'season_id': None,
'team1_series_score': 0,
'team2_series_score': 0,
Expand Down Expand Up @@ -67,7 +66,6 @@ def test_match_create_not_my_server(self):
'series_type': 'bo3',
'veto_first': 'CT',
'veto_mappool': ['de_dust2', 'de_cache', 'de_mirage'],
'enforce_teams': True,
'season_id': None,
'team1_series_score': 0,
'team2_series_score': 0,
Expand Down Expand Up @@ -97,7 +95,6 @@ def test_match_create(self):
'series_type': 'bo3',
'veto_first': 'CT',
'veto_mappool': ['de_dust2', 'de_cache', 'de_mirage'],
'enforce_teams': True,
'season_id': None,
'team1_series_score': 0,
'team2_series_score': 0,
Expand Down Expand Up @@ -152,7 +149,6 @@ def test_match_create_not_my_server(self):
'series_type': 'bo3',
'veto_first': 'CT',
'veto_mappool': ['de_dust2', 'de_cache', 'de_mirage'],
'enforce_teams': True,
'season_id': None,
'team1_series_score': 0,
'team2_series_score': 0,
Expand Down
Loading

0 comments on commit d2f02c6

Please sign in to comment.