Permalink
Browse files

chat

  • Loading branch information...
ilanpillemer committed Jul 31, 2017
1 parent 28102e8 commit 6dcc22c1a82b09290995831f400ff45c960c3341
Showing with 19 additions and 6 deletions.
  1. +19 −6 app/controllers/HomeController.scala
@@ -46,19 +46,32 @@ object RoomActor {
"roomInventory" -> List("yoyo","top")
)
def chat(message : String, username : String) : JsValue = Json.obj (
"type" -> "chat",
"username" -> username,
"content" -> message,
"bookmark" -> "GIRAFFE!"
)
}
class RoomActor(out: ActorRef) extends Actor {
val pattern = """(?s)(\w+),([^,]*),(.*)""".r
def receive = {
case str : String => str match {
case "marco" => out ! ("polo")
case pattern ("roomHello", id, payload) => out ! ("player," + (Json.parse(payload) \ "userId").as[String] + "," + RoomActor.sampleRoom.toString)
case pattern ("roomJoin", id, payload) => out ! ("player," + (Json.parse(payload) \ "userId").as[String] + "," + RoomActor.sampleRoom.toString)
case pattern ("roomGoodbye", id, payload) => out ! ("Don't slam door on way out, please.")
case pattern ("roomPart", id, payload) => out ! ("Don't slam door on way out, please.")
case pattern ("room", id, payload) => out ! ("Your wish is my command.")
case _ => out ! ("whatever, I dont care...")
case pattern ("roomHello", id, payload) =>
out ! ("player," + (Json.parse(payload) \ "userId").as[String] + "," + RoomActor.sampleRoom.toString)
case pattern ("roomJoin", id, payload) =>
out ! ("player," + (Json.parse(payload) \ "userId").as[String] + "," + RoomActor.sampleRoom.toString)
case pattern ("roomGoodbye", id, payload) =>
out ! ("Don't slam door on way out, please.")
case pattern ("roomPart", id, payload)
=> out ! ("Don't slam door on way out, please.")
case pattern ("room", id, payload) if ((Json.parse(payload) \ "content").as[String]).startsWith("/") =>
out ! ("Your wish is my command.")
case pattern ("room", id, payload) =>
out ! ("player,*," + RoomActor.chat( (Json.parse(payload) \ "content").as[String], (Json.parse(payload) \ "username").as[String]))
case _ => out ! ("whatever, I dont care...")
}
case _ => out ! ("So long, and thanks for the fish.")
}

0 comments on commit 6dcc22c

Please sign in to comment.