Skip to content

Commit

Permalink
pick based on player count
Browse files Browse the repository at this point in the history
  • Loading branch information
pschichtel committed Oct 6, 2024
1 parent 7a3ba37 commit 23a0897
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/controllers/Ld56C2Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ class JoinHandler(out: ActorRef,
}
}
if (viableHosts.nonEmpty) {
hosters.get(pickBestHost(viableHosts.toIndexedSeq).id) ! Json.toJson(JoiningMessage(myId)).toString
for { host <- pickBestHost(viableHosts.toIndexedSeq) } {
hosters.get(host.id) ! Json.toJson(JoiningMessage(myId)).toString
}
}
case OfferMessage(dest, offer) =>
hosters.get(dest) ! Json.toJson(OfferingMessage(myId, offer)).toString
Expand All @@ -169,7 +171,9 @@ class JoinHandler(out: ActorRef,
logger.error("Kaputt", e)
}

private def pickBestHost(hosts: IndexedSeq[GameHost]): GameHost = {
hosts.maxBy(_.lastUpdated)
private def pickBestHost(hosts: IndexedSeq[GameHost]): Option[GameHost] = {
val actuallyViable = hosts.filter(_.playerCount < 30)
implicit val ordering: Ordering[GameHost] = Ordering.by(_.playerCount)
actuallyViable.sorted(ordering).headOption
}
}

0 comments on commit 23a0897

Please sign in to comment.