diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-22 22:42:22 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-22 22:42:22 +0200 |
commit | db5612ed9734d51e6fcd0d7b5a7635e49b773581 (patch) | |
tree | e23e607c9d9eeedc377bf44e57c2b58b41d0389d /src/scalevalapokalypsi/Client | |
parent | 49985d1d11c426968fc298469671326aace96d00 (diff) | |
download | scalevalapokalypsi-db5612ed9734d51e6fcd0d7b5a7635e49b773581.tar.gz scalevalapokalypsi-db5612ed9734d51e6fcd0d7b5a7635e49b773581.zip |
Character safety checking, supported terminals updated
Diffstat (limited to 'src/scalevalapokalypsi/Client')
-rw-r--r-- | src/scalevalapokalypsi/Client/Client.scala | 3 | ||||
-rw-r--r-- | src/scalevalapokalypsi/Client/ReceivedLineParser.scala | 7 | ||||
-rw-r--r-- | src/scalevalapokalypsi/Client/RoomState.scala (renamed from src/scalevalapokalypsi/Client/Turn.scala) | 0 | ||||
-rw-r--r-- | src/scalevalapokalypsi/Client/StdinLineReader.scala | 31 |
4 files changed, 5 insertions, 36 deletions
diff --git a/src/scalevalapokalypsi/Client/Client.scala b/src/scalevalapokalypsi/Client/Client.scala index 0532038..e94fdb0 100644 --- a/src/scalevalapokalypsi/Client/Client.scala +++ b/src/scalevalapokalypsi/Client/Client.scala @@ -5,7 +5,7 @@ import scala.io.Source import scala.sys.process.stdout import scalevalapokalypsi.constants.* import scalevalapokalypsi.utils.{stringToByteArray,getNCharsFromSocket} -import scalevalapokalypsi.Client.{ReceivedLineParser,StdinLineReader,RoomState} +import scalevalapokalypsi.Client.{ReceivedLineParser,RoomState} import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global import scala.util.{Try, Success, Failure} @@ -119,7 +119,6 @@ class Client(socket: Socket): while availableBytes != 0 do val bytesRead = input.read(buffer, 0, availableBytes) if bytesRead != -1 then - // TODO: unsafe conversion parseDataFromServer(buffer.take(bytesRead)) availableBytes = input.available() diff --git a/src/scalevalapokalypsi/Client/ReceivedLineParser.scala b/src/scalevalapokalypsi/Client/ReceivedLineParser.scala index 9337ce1..bccba59 100644 --- a/src/scalevalapokalypsi/Client/ReceivedLineParser.scala +++ b/src/scalevalapokalypsi/Client/ReceivedLineParser.scala @@ -2,6 +2,7 @@ package scalevalapokalypsi.Client import scala.collection.mutable.Buffer import scalevalapokalypsi.constants.* +import scalevalapokalypsi.utils.* /** A class for checking asynchronously for received lines */ class ReceivedLineParser: @@ -10,11 +11,11 @@ class ReceivedLineParser: private var bufferedData: Buffer[Byte] = Buffer.empty // TODO: suboptimal DS - /** Add received data */ + /** Add received data */ def in(data: Array[Byte]): Unit = this.bufferedData ++= data - /** Read a line from the received data */ + /** Read a line from the received data */ def nextLine(): Option[String] = val indexOfCRLF = this.bufferedData.indexOfSlice(CRLF) if indexOfCRLF == -1 then @@ -22,6 +23,6 @@ class ReceivedLineParser: else val splitData = this.bufferedData.splitAt(indexOfCRLF) this.bufferedData = Buffer.from(splitData(1).drop(CRLF.length)) - Some(String(splitData(0).toArray)) + byteArrayToString(splitData(0).toArray) end ReceivedLineParser diff --git a/src/scalevalapokalypsi/Client/Turn.scala b/src/scalevalapokalypsi/Client/RoomState.scala index 02fe11b..02fe11b 100644 --- a/src/scalevalapokalypsi/Client/Turn.scala +++ b/src/scalevalapokalypsi/Client/RoomState.scala diff --git a/src/scalevalapokalypsi/Client/StdinLineReader.scala b/src/scalevalapokalypsi/Client/StdinLineReader.scala deleted file mode 100644 index 6ba8761..0000000 --- a/src/scalevalapokalypsi/Client/StdinLineReader.scala +++ /dev/null @@ -1,31 +0,0 @@ -package scalevalapokalypsi.Client - -import scala.concurrent.Future -import scala.concurrent.ExecutionContext.Implicits.global -import scala.io.StdIn.readLine -import scala.util.{Try, Success, Failure} - -/** This class is for taking new lines from stdin when they are available. - * reading starts when either newLine or clear or startReading are called. - */ -class StdinLineReader: - - private var nextLine: Future[String] = Future.failed(Exception()) - - /** Returns a new line of input if there are any. */ - def newLine(): Option[String] = - this.nextLine.value match - case Some(Success(s)) => - this.startReading() - Some(s) - case Some(Failure(e)) => - this.startReading() - None - case None => None - - /** Discards the line that is currently being read and restarts reading */ - def startReading(): Unit = - this.nextLine = Future(readLine()) - - -end StdinLineReader |