Skip to content

Commit

Permalink
minor fixes to have less stale bad state and less logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ColaColin committed Mar 30, 2014
1 parent 03fed37 commit bca4007
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/main/scala/info/nanodesu/rest/LadderService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ object LadderService extends RestHelper with Loggable with RefreshRunner{
registeredPlayers remove x._1
}

var hadStuff = false;
if (!registeredPlayers.isEmpty) {
hadStuff = true
logger info "registered Players are => " + registeredPlayers
}
if (!registeredGames.isEmpty) {
hadStuff = true
logger info "registered Games are => " + registeredGames
}
if (!registeredLobbyIdByHost.isEmpty) {
hadStuff = true
logger info "registered Lobby id for hosts => " + registeredLobbyIdByHost
}
if (!clientsReadyByLobby.isEmpty) {
Expand All @@ -70,13 +66,8 @@ object LadderService extends RestHelper with Loggable with RefreshRunner{
//logger info "clients ready for lobby => " + clientsReadyByLobby
}
if (!gameCreationTimes.isEmpty) {
hadStuff = true
logger info "game creation times => " + gameCreationTimes
}

if (hadStuff) {
logger info "\n\n\n\n"
}
}
}

Expand Down Expand Up @@ -177,6 +168,8 @@ object LadderService extends RestHelper with Loggable with RefreshRunner{

logger info "registered " + data.uber_name

cleanDataForSearchingPlayer(data.uber_name)

if (registeredPlayers.size >= 2) {
val iter = registeredPlayers.iterator
val pA = iter.next._1
Expand Down Expand Up @@ -229,7 +222,13 @@ object LadderService extends RestHelper with Loggable with RefreshRunner{
}
}

private def timeOutFor(uberName: String) = gameCreationTimes.count(x => x._1._1 == uberName || x._1._2 == uberName) == 0
private def timeOutFor(uberName: String) = {
val hasTimeOut = gameCreationTimes.count(x => x._1._1 == uberName || x._1._2 == uberName) == 0
if (hasTimeOut) {
cleanDataForSearchingPlayer(uberName)
}
hasTimeOut
}

private def resetTimeOutFor(uberName: String) = {
for(game <- gameCreationTimes.find(x => x._1._1 == uberName || x._1._2 == uberName)) {
Expand Down Expand Up @@ -259,8 +258,8 @@ object LadderService extends RestHelper with Loggable with RefreshRunner{
if (resp.shouldStart) {
mutex synchronized {
clientsReadyByLobby remove data.game_id
registeredLobbyIdByHost remove data.uber_name
registeredGames remove data.uber_name

cleanDataForSearchingPlayer(data.uber_name)

successfulGameIds += data.game_id

Expand All @@ -272,6 +271,11 @@ object LadderService extends RestHelper with Loggable with RefreshRunner{
}
}

private def cleanDataForSearchingPlayer(uberName: String) = {
registeredLobbyIdByHost remove uberName
registeredGames remove uberName
}

case class TimeOutInfo(hasTimeOut: Boolean)
serve {
case "readyToStart" :: Nil JsonPost NameMessage(data) -> _ => {
Expand Down

0 comments on commit bca4007

Please sign in to comment.