Skip to content

Commit

Permalink
send less messages to round sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jul 11, 2014
1 parent 4c06b00 commit de9af23
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions modules/round/src/main/Socket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import play.api.libs.json._
import actorApi._
import lila.common.LightUser
import lila.game.Event
import lila.hub.actorApi.game.ChangeFeatured
import lila.hub.TimeBomb
import lila.round.actorApi.Bye
import lila.socket._
Expand Down Expand Up @@ -53,7 +54,7 @@ private[round] final class Socket(

def receiveSpecific = {

case PingVersion(uid, v) => {
case PingVersion(uid, v) =>
timeBomb.delay
ping(uid)
ownerOf(uid) foreach { o =>
Expand All @@ -62,19 +63,17 @@ private[round] final class Socket(
withMember(uid) { member =>
(history getEventsSince v).fold(resyncNow(member))(batch(member, _))
}
}

case Bye(color) => playerDo(color, _.setBye)

case Ack(uid) => withMember(uid) { _.channel push ackEvent }

case Broom => {
case Broom =>
broom
if (timeBomb.boom) self ! PoisonPill
else Color.all foreach { c =>
if (playerGet(c, _.isGone)) notifyGone(c, true)
}
}

case GetVersion => sender ! history.getVersion

Expand All @@ -89,7 +88,7 @@ private[round] final class Socket(
sender ! Connected(enumerator, member)
}

case Nil =>
case Nil =>
case eventList: EventList => notify(eventList.events)

case lila.chat.actorApi.ChatLine(chatId, line) => notify(List(line match {
Expand All @@ -105,6 +104,10 @@ private[round] final class Socket(
quit(uid)
notifyCrowd
}

case ChangeFeatured(_, html) =>
val msg = makeMessage("featured", Json.obj("html" -> html.toString))
watchers.foreach(_.channel push msg)
}

def notifyCrowd {
Expand Down Expand Up @@ -148,7 +151,7 @@ private[round] final class Socket(
def ownerOf(uid: String): Option[Member] =
members get uid filter (_.owner)

def watchers: List[Member] = members.values.filter(_.watcher).toList
def watchers: Iterable[Member] = members.values.filter(_.watcher)

private def playerGet[A](color: Color, getter: Player => A): A =
getter(color.fold(whitePlayer, blackPlayer))
Expand Down

0 comments on commit de9af23

Please sign in to comment.