Skip to content

Commit

Permalink
XTA awards (fix #58)
Browse files Browse the repository at this point in the history
  • Loading branch information
dansan committed May 13, 2014
1 parent 6bb68ec commit a0c8a54
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This software is licensed as GPLv3, see COPYING.
jQuery, Bootstrap, Respond.js, Moment.js and bootstrap-daterangepicker are released under the terms of the MIT license.
html5shiv is dual licensed under the MIT or GPL Version 2 licenses.
selectize.js is licensed under the Apache License, Version 2.0.
Images under srs/static/img may have different copyright. To lazy to check now, please ask before using any of them!
Images under srs/static/img may have different copyright, some of which are not free in any way. To lazy to list all, do absolutely ask before using any of them!

Website
=======
Expand Down
3 changes: 2 additions & 1 deletion srs/demoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ def parsePacket(self, packet):
size, playerNum, script, mode = struct.unpack('<HBHB', data[:6])
msg = data[6:]
playerName = self.players[playerNum] or ''
return self.write(locals(), 'cmd', 'size', 'playerNum', 'playerName', 'script', 'mode', 'msg')
(msgid,) = struct.unpack("<B", msg[0])
return self.write(locals(), 'cmd', 'size', 'playerNum', 'playerName', 'script', 'mode', 'msg', 'msgid')
elif cmd == 51:
cmd = 'team'
playerNum, action = struct.unpack('<BB', data[:2])
Expand Down
331 changes: 331 additions & 0 deletions srs/migrations/0002_auto__add_xtawards.py

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions srs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,17 @@ class BAwards(models.Model):
def __unicode__(self):
return u"(%d) Replay: %d | EcoKill: %s,%s,%s | FightKill: %s,%s,%s | EffKill: %s,%s,%s | Cow: %s | Eco: %s | DmgRec: %s | Sleep: %s"%(self.pk, self.replay.pk, self.ecoKillAward1st, self.ecoKillAward2nd, self.ecoKillAward3rd, self.fightKillAward1st, self.fightKillAward2nd, self.fightKillAward3rd, self.effKillAward1st, self.effKillAward2nd, self.effKillAward3rd, self.cowAward, self.ecoAward, self.dmgRecAward, self.sleepAward)

class XTAwards(models.Model):
replay = models.ForeignKey(Replay)
isAlive = models.SmallIntegerField(default=-1)
player = models.ForeignKey(Player)
unit = models.CharField(max_length=1024)
kills = models.IntegerField(default=-1)
age = models.IntegerField(default=-1)

def __unicode__(self):
return u"(%d) Replay: %d | isAlive: %d | player: %s | unit: %s | kills: %d | age: %d"%(self.pk, self.replay.pk, self.isAlive, self.player.name, self.unit, self.kills, self.age)

def get_owner_list(uploader):
res = [uploader]
res.extend(AdditionalReplayOwner.objects.filter(uploader=uploader))
Expand All @@ -624,6 +635,9 @@ def update_stats():
replays = Replay.objects.count()
now = datetime.datetime.now(timezone.get_current_timezone())
start_date = now - datetime.timedelta(days=30)
if settings.DEBUG:
# no daily uploads on my dev pc - list can be empty
start_date = now - datetime.timedelta(days=300)
default_tags = Tag.objects.filter(name__in=["1v1", "2v2", "3v3", "4v4", "5v5", "6v6", "7v7", "8v8", "Team", "FFA", "TeamFFA", "Tourney"])
tags = default_tags.annotate(num_replay=Count('replay'))
maps = Map.objects.filter(replay__unixTime__range=(start_date, now)).annotate(num_replay=Count('replay')).order_by('-num_replay')[:10]
Expand Down
34 changes: 31 additions & 3 deletions srs/parse_demo_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,13 @@ def clean(name):
"toID": messageData["toID"],
"message": messageData["message"][:-1]})
elif messageData["cmd"] == "luamsg":
(msgid,) = struct.unpack("<B", messageData["msg"][0])
if msgid == 138:
if messageData["msgid"] == 138:
# faction change
playername = clean(messageData['playerName'])
faction = struct.unpack("<%iB"%(len(messageData["msg"][1:])), messageData["msg"][1:])
logger.debug("%s(%d) changed faction to '%s'", playername, messageData['playerNum'], faction)
self.additional["faction_change"][playername] = (self.players[playername], faction)
elif msgid == 161:
elif messageData["msgid"] == 161:
# BA Awards
# http://imolarpg.dyndns.org/trac/balatest/browser/trunk/luarules/gadgets/gui_awards.lua?rev=2070#L389
# history:
Expand Down Expand Up @@ -419,6 +418,35 @@ def f_(s):
self.additional["awards"] = awards
except Exception, e:
logger.exception("detecting BA Awards, messageData: %s, Exception: %s", messageData, e)
elif messageData["msgid"] == 199:
# XTA Awards, 2014-04-01
# forum thread: http://springrts.com/phpbb/viewtopic.php?f=71&t=28019&start=120#p555847
# XTA_AWARDMARKER,":",isAlive,":",team,":",name,":",kills,":",age
# The fields for 'heroes award':
# 1: string '\199', identify XTA unit award
# 2: isAlive: 1
# 3: teamID, owner of the corresponding unit (0)
# 4: name of unit to get award (Maverick)
# 5: number of kills (27)
# 6: age of unit when game ends (4)
# The fields for 'lost in service award':
# 1: string '\199', identify XTA unit award
# 2: isAlive: 0
# 3: teamID, owner of the corresponding unit (0)
# 4: name of unit to get award (Commander)
# 5: number of kills (43)
# 6: age of unit when game ends (1)
xta_isAlive, xta_team, xta_name, xta_kills, xta_age = messageData["msg"][2:].split(":")
xtawards = {"isAlive": int(xta_isAlive),
"team" : int(xta_team),
"name" : xta_name,
"kills" : int(xta_kills),
"age" : int(xta_age)}
if self.additional.has_key("xtawards"):
if not xtawards in self.additional["xtawards"]:
self.additional["xtawards"].append(xtawards)
else:
self.additional["xtawards"] = [xtawards]
else:
pass
except Exception, e:
Expand Down
Binary file added srs/static/img/xtawards/love-rose-4_128px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added srs/static/img/xtawards/love-rose-4_trans.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions srs/templates/replay.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,85 @@ <h4 class="media-heading">Slept longest</h4>
</div> <!-- row -->
{% endif %}

<!-- XTAwards -->

{% if xtaward_heroes or xtaward_los %}
<div class="row">
<div class="col-sx-12 col-sm-6">
<div class="panel panel-default blind_winner" style="display:none;">
<div class="panel-body">
<center><img src="{{ STATIC_URL }}img/trophy_32.png" alt="trophy" height="24"/> &nbsp;&nbsp; <span style="font-size: larger; font-weight: bold;">Heroes in victory</span> &nbsp;&nbsp; <img src="{{ STATIC_URL }}img/trophy_32.png" alt="trophy" height="24"/></center>
<hr style="margin-top: 7px; margin-bottom: 12px;">
{% if xtaward_heroes %}
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>#</th>
<th>Unit</th>
<th>Owner</th>
<th>Kills</th>
<th>Age</th>
</tr>
</thead>
<tbody>
{% for hero in xtaward_heroes %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ hero.unit }}</td>
<td><a href="{{ hero.player.get_absolute_url }}">{{ hero.player.name }}</a></td>
<td>{{ hero.kills }}</td>
<td>{{ hero.age }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<p>None.</p>
{% endif %}
</div> <!-- panel-body -->
</div> <!-- panel -->
</div> <!--col-sx-12 col-sm-6 -->
<div class="col-sx-12 col-sm-6">
<div class="panel panel-default blind_winner" style="display:none;">
<div class="panel-body">
<center><img src="{{ STATIC_URL }}img/xtawards/love-rose-4_128px.png" alt="rose" height="24"/> &nbsp;&nbsp; <span style="font-size: larger; font-weight: bold;">Lost in service</span> &nbsp;&nbsp; <img src="{{ STATIC_URL }}img/xtawards/love-rose-4_128px.png" alt="rose" height="24"/></center>
<hr style="margin-top: 7px; margin-bottom: 12px;">
{% if xtaward_los %}
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>#</th>
<th>Unit</th>
<th>Owner</th>
<th>Kills</th>
<th>Age</th>
</tr>
</thead>
<tbody>
{% for los in xtaward_los %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ los.unit }}</td>
<td><a href="{{ los.player.get_absolute_url }}">{{ los.player.name }}</a></td>
<td>{{ los.kills }}</td>
<td>{{ los.age }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<p>None.</p>
{% endif %}
</div> <!-- panel-body -->
</div> <!-- panel -->
</div> <!--col-sx-12 col-sm-6 -->
</div> <!-- row -->
{% endif %}

<!-- COMMENTS -->

<div class="row">
Expand Down
12 changes: 12 additions & 0 deletions srs/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,15 @@ def truncate_option(k, v):
save_desc(replay, short, long_text, autotag)
timer.stop(" tags + descriptions")

timer.start(" demofile.additional")
# store if demofile doesn't contain the GAMEOVER msg, because of the spring94.1 bug:
# http://springrts.com/mantis/view.php?id=3950
# http://springrts.com/mantis/view.php?id=3804
if not demofile.additional["gameover_frame"]:
logger.debug("replay(%d) has no GAMEOVER msg", replay.pk)
AdditionalReplayInfo.objects.get_or_create(replay=replay, key="gameover", value="")

# BAward
if demofile.additional.has_key("awards"):
ba_awards, _ = BAwards.objects.get_or_create(replay=replay)
demo_awards = demofile.additional["awards"]
Expand Down Expand Up @@ -614,6 +616,16 @@ def truncate_option(k, v):
setattr(ba_awards, award_name, None)
ba_awards.save()

# XTAwards
if demofile.additional.has_key("xtawards"):
for xta_award in demofile.additional["xtawards"]:
team = Team.objects.get(replay=replay, num=xta_award["team"])
player = Player.objects.get(replay=replay, team=team)
xt, cr = XTAwards.objects.get_or_create(replay=replay, isAlive=xta_award["isAlive"], player=player, unit=xta_award["name"], kills=xta_award["kills"], age=xta_award["age"])
logger.debug("XTA created: %s, award: %s", cr, xt)

timer.stop(" demofile.additional")

pp = pprint.PrettyPrinter(depth=6)
for k, v in demofile.additional.items():
if k == "chat": v = "chat removed for shorter output"
Expand Down
2 changes: 2 additions & 0 deletions srs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def _get_players_skills(pa):
c["metadata"].append(("Error", "Problem with metadata. Please report to Dansan."))
logger.error("Problem with metadata (replay.id '%d'), replay.map_info.metadata: %s", replay.id, replay.map_info.metadata)
logger.exception("Exception: %s", e)
c["xtaward_heroes"] = XTAwards.objects.filter(replay=replay, isAlive=1)
c["xtaward_los"] = XTAwards.objects.filter(replay=replay, isAlive=0)

return render_to_response('replay.html', c, context_instance=RequestContext(request))

Expand Down

0 comments on commit a0c8a54

Please sign in to comment.