Skip to content

Commit

Permalink
optionally support sending over a peer id
Browse files Browse the repository at this point in the history
  • Loading branch information
pschichtel committed Oct 5, 2024
1 parent 394c7e9 commit e3810f6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/controllers/Ld56C2Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import java.net.InetAddress
import java.time.{Duration, Instant}
import java.util.UUID
import java.util.concurrent.{ConcurrentHashMap, ConcurrentMap}
import scala.collection.mutable
import scala.math.Numeric.Implicits.infixNumericOps
import scala.math.Ordering.Implicits.infixOrderingOps

private val logger = Logger(classOf[Ld56C2Controller])
Expand All @@ -22,14 +20,14 @@ object JoinRequestMessage {
implicit val format: Format[JoinRequestMessage] = Json.format
}

final case class JoinAcceptMessage(answer: String)
final case class JoinAcceptMessage(peerId: Int, answer: String)
object JoinAcceptMessage {
implicit val format: Format[JoinAcceptMessage] = Json.format
}

sealed trait HosterMessage
final case class HostingMessage(playerCount: Int) extends HosterMessage
final case class HostAcceptsJoinMessage(id: UUID, answer: String) extends HosterMessage
final case class HostAcceptsJoinMessage(id: UUID, peerId: Option[Int], answer: String) extends HosterMessage


object HosterMessage {
Expand Down Expand Up @@ -96,10 +94,10 @@ class HostHandler(out: ActorRef,
Json.parse(text).as[HosterMessage] match
case HostingMessage(playerCount) =>
hosts.put(id, GameHost(id, playerCount, Instant.now()))
case controllers.HostAcceptsJoinMessage(id, answer) =>
case controllers.HostAcceptsJoinMessage(id, peerId, answer) =>
val joiner = joiners.get(id)
if (joiner != null) {
joiner ! Json.toJson(JoinAcceptMessage(answer)).toString
joiner ! Json.toJson(JoinAcceptMessage(peerId.getOrElse(2), answer)).toString
}
catch
case e: Exception =>
Expand Down

0 comments on commit e3810f6

Please sign in to comment.