From a43812ed462630850edbf29bda182fbf1e5e1263 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Thu, 14 Nov 2024 19:25:19 +0200 Subject: Immediate printing of actions & no prompt on blocking action & refactoring --- src/main/scala/Server/Client.scala | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/main/scala/Server/Client.scala') 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 -- cgit v1.2.3