diff options
Diffstat (limited to 'src/main/scala/Server')
-rw-r--r-- | src/main/scala/Server/Client.scala | 14 | ||||
-rw-r--r-- | src/main/scala/Server/constants.scala | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/main/scala/Server/Client.scala b/src/main/scala/Server/Client.scala index cd557c6..323b78c 100644 --- a/src/main/scala/Server/Client.scala +++ b/src/main/scala/Server/Client.scala @@ -89,7 +89,7 @@ class Client(val socket: Socket): * @param data data to buffer for sending */ private def addDataToSend(data: String): Unit = - this.outData += s"$data\r\n" + this.outData += s"$data" /** Returns one line of data if there are any line breaks. @@ -109,6 +109,7 @@ class Client(val socket: Socket): /** Makes the client play its turn */ def act(): Unit = + this.addDataToSend(ACTION_BLOCKING_INDICATOR.toString) this.nextAction.foreach(this.executeAction(_)) this.nextAction = None @@ -134,11 +135,11 @@ class Client(val socket: Socket): this.protocolIsIntact = this.protocolState match case WaitingForVersion => if line == GAME_VERSION then - addDataToSend(PROTOCOL_VERSION_GOOD) + addDataToSend(s"$PROTOCOL_VERSION_GOOD\r\n") this.protocolState = WaitingForClientName true else - addDataToSend(PROTOCOL_VERSION_BAD) + addDataToSend(s"$PROTOCOL_VERSION_BAD\r\n") false case WaitingForClientName => this.name = Some(line) @@ -158,13 +159,14 @@ class Client(val socket: Socket): ) then this.nextAction = Some(action) else if this.nextAction.isEmpty then - executeAction(action) + this.addDataToSend(ACTION_NONBLOCKING_INDICATOR.toString) + this.executeAction(action) /** Executes the specified action and buffers its description for sending */ private def executeAction(action: Action) = this.character.flatMap(action.execute(_)) match - case Some(s) => this.addDataToSend((s)) - case None => this.addDataToSend("You can't do that") + case Some(s) => this.addDataToSend(s"$s\r\n") + case None => this.addDataToSend("You can't do that\r\n") end Client diff --git a/src/main/scala/Server/constants.scala b/src/main/scala/Server/constants.scala index a9e4502..083db4e 100644 --- a/src/main/scala/Server/constants.scala +++ b/src/main/scala/Server/constants.scala @@ -6,6 +6,8 @@ val CRLF: Vector[Byte] = Vector(13.toByte, 10.toByte) val POLL_INTERVAL = 100 // millisec. val GAME_VERSION = "0.1.0" val TURN_INDICATOR = ">" +val ACTION_BLOCKING_INDICATOR='.' +val ACTION_NONBLOCKING_INDICATOR='+' val LIST_SEPARATOR=";" |