diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 01:59:46 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 01:59:46 +0200 |
commit | e0e720c1b78506f1f9c00e2d275caa170becc927 (patch) | |
tree | 191fca97383d8bab709894f611607e43e0c1b760 | |
parent | 165a89af296cf4f6bff0241477fced2e66e681d4 (diff) | |
download | scalevalapokalypsi-e0e720c1b78506f1f9c00e2d275caa170becc927.tar.gz scalevalapokalypsi-e0e720c1b78506f1f9c00e2d275caa170becc927.zip |
Bug fix: Server.Client.nextLine left newlines at starts of lines
-rw-r--r-- | src/main/scala/Client/Client.scala | 2 | ||||
-rw-r--r-- | src/main/scala/Server/Client.scala | 7 | ||||
-rw-r--r-- | src/main/scala/Server/Server.scala | 4 |
3 files changed, 10 insertions, 3 deletions
diff --git a/src/main/scala/Client/Client.scala b/src/main/scala/Client/Client.scala index 1c5d1b4..fc3e6b8 100644 --- a/src/main/scala/Client/Client.scala +++ b/src/main/scala/Client/Client.scala @@ -149,7 +149,7 @@ class Client(socket: Socket): this.lastTurnStart = currentTimeMillis / 1000 case ServerLineState.ActionDescription => - if !line.isEmpty && line.head == ACTION_BLOCKING_INDICATOR then + if line.nonEmpty && line.head == ACTION_BLOCKING_INDICATOR then this.canAct = false this.displayAction(line.tail) diff --git a/src/main/scala/Server/Client.scala b/src/main/scala/Server/Client.scala index d4f1864..7c7a786 100644 --- a/src/main/scala/Server/Client.scala +++ b/src/main/scala/Server/Client.scala @@ -99,7 +99,12 @@ class Client(val socket: Socket): if this.incompleteMessage(nextCRLF + 1) != CRLF(1) then nextCRLF = -1 if nextCRLF != -1 then val message = this.incompleteMessage.take(nextCRLF) - val rest = this.incompleteMessage.drop(nextCRLF + 1) + val rest = this.incompleteMessage.drop(nextCRLF + 2) + assert(rest.headOption != Some(CRLF(1))) // I will compile this with + // assertions off... I'd + // like to know how to make + // tests work with this + // config... this.incompleteMessage = rest ++ Array.fill(nextCRLF + 1)(0.toByte) // TODO: the conversion may probably be exploited to crash the server Some(String(message)) diff --git a/src/main/scala/Server/Server.scala b/src/main/scala/Server/Server.scala index 230fe59..4a984a5 100644 --- a/src/main/scala/Server/Server.scala +++ b/src/main/scala/Server/Server.scala @@ -104,7 +104,9 @@ class Server( private def writeObservations(): Unit = this.clients.foreach(c => val observations = c.player.map(_.readAndClearObservations()) - observations.foreach(_.foreach((s: String) => this.writeToClient(s"$s\r\n", c))) + observations.foreach(_.foreach((s: String) => + this.writeToClient(s"$ACTION_NONBLOCKING_INDICATOR$s\r\n", c)) + ) ) /** Helper function to determine if the next turn can be taken */ |