Skip to content

Commit

Permalink
improve replay directing page to have content
Browse files Browse the repository at this point in the history
  • Loading branch information
ColaColin committed Apr 28, 2014
1 parent eda63b7 commit 161e3ef
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 9 deletions.
17 changes: 15 additions & 2 deletions src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import info.nanodesu.model.db.collectors.stats.RuntimeInfoCollector
import info.nanodesu.model.db.collectors.stats.ExtraNumbersCollector
import info.nanodesu.snippet.lib.IFrameSnip
import info.nanodesu.rest.LadderService
import info.nanodesu.snippet.Replay
import info.nanodesu.pages.ReplayPage

// see: http://cookbook.liftweb.net/#InstallAndRunning
/**
Expand Down Expand Up @@ -70,6 +72,7 @@ class Boot extends Loggable {
case "CometInit" => CometInit
case "PlayerSearch" => PlayerSearch
case "IFrameSnip" => IFrameSnip
case "Replay" => Replay
}

CookieBox.init()
Expand All @@ -92,7 +95,8 @@ class Boot extends Loggable {
Menu.i("Extra") / StatsPage.pageName,
Menu.i("Player") / PlayerPage.pageName >> Hidden,
Menu.i("Chart") / GamePage.pageName >> Hidden,
Menu.i("Ingamechart") / "ingamechart" >> Hidden)
Menu.i("Ingamechart") / "ingamechart" >> Hidden,
Menu.i("Replay") / ReplayPage.pageName >> Hidden)

// set the sitemap. Note if you don't want access control for
// each page, just comment this line out.
Expand All @@ -104,9 +108,18 @@ class Boot extends Loggable {
// Use HTML5 for rendering
LiftRules.htmlProperties.default.set((r: Req) =>
new Html5Properties(r.userAgent))


initRewrites()

logger info "BOOT complete! run.mode=" + System.getProperty("run.mode")
logger info "min comet interval is " + Props.getInt("minCometInterval")
logger info "comet serve threshold is " + Props.getInt("cometServeThreshold")
}

def initRewrites() = {
LiftRules.statelessRewrite.prepend(NamedPF("Replay Rewrite") {
case RewriteRequest(ParsePath("replay" :: id :: Nil, _, _, _), _, _) =>
RewriteResponse("replay" :: Nil, Map("replayid" -> id))
})
}
}
2 changes: 1 addition & 1 deletion src/main/scala/info/nanodesu/pages/Page.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait Page {
}

protected def makeLinkAttribute0(p: PageParam*) = {
val fullLinkString = pageName + Page.makeLinkString(p:_*)
val fullLinkString = "/"+pageName + Page.makeLinkString(p:_*)
Attribute(None, "href", Text(fullLinkString), Null)
}

Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/info/nanodesu/pages/ReplayPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package info.nanodesu.pages

case class ReplayIdParam(id: String) extends PageParam {
val paramName = ReplayPage.idParam
val paramValue = id
}

object ReplayPage extends Page {
val pageName = "replay"

protected[pages] val idParam = "replayid"

def makeLink(txt: String, id: ReplayIdParam) = makeLink0(txt, id)
def makeLinkAttribute(id: ReplayIdParam) = makeLinkAttribute0(id)

def getReplayId = getParam(idParam, x => x)
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,7 @@ object StatisticsReportService extends RestHelper with Loggable {
}
}
}

serve {
case "replay" :: id :: Nil Get _ => RedirectResponse(s"startpa://replay=$id")
}


serve {
case "report" :: "getsystem" :: Nil Get _ =>
try {
Expand Down
49 changes: 49 additions & 0 deletions src/main/scala/info/nanodesu/snippet/Replay.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package info.nanodesu.snippet

import net.liftweb.http.DispatchSnippet
import net.liftweb.util.Props
import scala.xml.Attribute
import scala.xml.Text
import scala.xml.Null
import scala.xml.NodeSeq
import scala.Array.canBuildFrom
import net.liftweb.util.Helpers._
import info.nanodesu.pages.ReplayPage
import info.nanodesu.model.ReportDataC
import info.nanodesu.model.db.collectors.gameinfo.loader.GameIdFromIdentLoader
import info.nanodesu.lib.db.CookieBox
import net.liftweb.common.Empty
import net.liftweb.common.Full
import info.nanodesu.pages.GamePage
import info.nanodesu.pages.GameIdParam

object Replay extends DispatchSnippet{
val dispatch: DispatchIt = {
case "relink" => relinkReplay
}

def relinkReplay = {
val startPa = "startpa://replay="
val lobbyId = ReplayPage.getReplayId

val gameIdBox = (CookieBox withSession {db =>
for (l <- lobbyId) yield {
val loader = new Object with GameIdFromIdentLoader
val gameId = loader.getIdForIdent(db, l)
if (gameId.isDefined) Full(gameId.get)
else Empty
}
})

val gameId = gameIdBox match {
case Full(x) => x
case _ => Empty
}

"#replayinfo *+" #> lobbyId &
"#replayinfo [href]" #> lobbyId.map(startPa+_) &
"#redirectmeta" #> lobbyId.map(x => (<meta data-lift="head" http-equiv="Refresh"></meta> %
Attribute(None, "content", Text(s"0; url=$startPa$x"), Null))) &
"#gameLink" #> gameId.map(x => GamePage.makeLink("Game #"+x, GameIdParam(x)))
}
}
16 changes: 16 additions & 0 deletions src/main/webapp/replay.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<body data-lift-content-id="main">
<div id="main" data-lift="surround?with=default;at=content">
<div data-lift="Replay.relink">
<div id="redirectmeta"></div>
<div id="replayheader">PA Replay <a id="gameLink"></a></div>
This page is redirecting to a Planetary Annihilation replay. If you have registered the startpa:// protocol
and you have the PA Stats UI mod your PA should now open and, after you logged in to ubernet, play the replay.
<div>The plain startpa:// link is <a id="replayinfo">startpa://replay=</a></div>
</div>
<div>If this does not work for you, check this post
<a href="https://forums.uberent.com/threads/rel-pa-stats-63180.50690/page-23#post-918834" target="_blank">in the PA forums</a> </div>
</div>
</body>
</html>
5 changes: 5 additions & 0 deletions src/main/webapp/static/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
color: red;
}

#replayheader {
font-size: 25px;
margin-bottom: 5px;
}

a {
color: #000;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/templates-hidden/gameinfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h4 id="players" style="text-align:center"></h4>
<td id="length">Duration: </td>
<td id="version">PA: v.</td>
<td> <span id="gamenum">Game #</span>
<a id="replaylink" target="_blank">(Launch replay in PA)</a> <a href="https://forums.uberent.com/threads/rel-pa-stats-63180.50690/page-23#post-918834" target="_blank">(?)</a>
<a id="replaylink" target="_blank">(Launch replay in PA)</a>
<span id="livenote" data-lift="GameInfo.livenote" style="display: none"><span class="white bold" id="live_note_txt"></span></span> <br />
</td>
</tr>
Expand Down

0 comments on commit 161e3ef

Please sign in to comment.