Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
fixed minor server stuff, when first used
Browse files Browse the repository at this point in the history
  • Loading branch information
indietyp committed Apr 28, 2018
1 parent 1bb3c57 commit 9a1be5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ajax/views/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def status(server, *args, **kwargs):

online = sorted(online, key=lambda x: x['date'])

return {'status': SourcemodPluginWrapper(server).status(),
if not recent:
recent = [{'active': 0}]
if not alltime:
alltime = [{'active': 0}]

return {'status': SourcemodPluginWrapper(server).status(truncated=True),
'online': online,
'count': {'last30': recent[0], 'ever': alltime[0]}}

Expand Down
2 changes: 1 addition & 1 deletion interface/templatetags/interface_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def duration(delta):
def dict_to_list(dic, key):
output = [d[key] for d in dic]

if isinstance(output[0], datetime.date):
if len(output) > 0 and isinstance(output[0], datetime.date):
output = [date(d, settings.SHORT_DATE_FORMAT) for d in output]

return output
Expand Down
5 changes: 4 additions & 1 deletion lib/sourcemod.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def mutegag(self, mutegag, *args, **kwargs):

return response

def status(self, *args, **kwargs):
def status(self, truncated=False, *args, **kwargs):
try:
response = self.run('json_status')[0]
except valve.rcon.RCONError as e:
Expand All @@ -65,6 +65,9 @@ def status(self, *args, **kwargs):

response['stats']['uptime'] = datetime.timedelta(seconds=response['stats']['uptime'])

if truncated:
response['stats']['map'] = response['stats']['map'].split('/')[-1]

users = []
for player in response['players']:
try:
Expand Down

0 comments on commit 9a1be5e

Please sign in to comment.