aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/Server/Server.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-07 21:00:04 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-07 21:00:04 +0200
commit891b6f877ba848a3f78851a757734ebd1f066798 (patch)
tree849d4f9bac3b3e83f84b6319d7148f93f5a44c06 /src/main/scala/Server/Server.scala
parentfdaec6534eb7ee902c75be3e4b732b6970abd859 (diff)
downloadscalevalapokalypsi-891b6f877ba848a3f78851a757734ebd1f066798.tar.gz
scalevalapokalypsi-891b6f877ba848a3f78851a757734ebd1f066798.zip
Added comments for documentation and reformatted old ones
Diffstat (limited to 'src/main/scala/Server/Server.scala')
-rw-r--r--src/main/scala/Server/Server.scala19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main/scala/Server/Server.scala b/src/main/scala/Server/Server.scala
index c0a76ca..6fa284c 100644
--- a/src/main/scala/Server/Server.scala
+++ b/src/main/scala/Server/Server.scala
@@ -3,14 +3,17 @@ package o1game.Server
// TODO: TLS/SSL / import javax.net.ssl.SSLServerSocketFactory
-import java.io.IOException
import java.lang.Thread.sleep
import java.net.{ServerSocket, Socket}
import o1game.constants.*
import o1game.Model.Adventure
import o1game.Model.Entity
-import scala.collection.mutable.Map
+/** Converts this string to an array of bytes (probably for transmission).
+ *
+ * @param str the string to convert
+ * @return an array of bytes representing the string in UTF8.
+ */
def stringToByteArray(str: String): Array[Byte] =
str.toVector.map(_.toByte).toArray
@@ -50,9 +53,9 @@ class Server(port: Int, maxClients: Int, val timeLimit: Int):
/** Receives a new client and stores it in `clients`.
- *
- * @return describes if a client was added
- */
+ *
+ * @return describes if a client was added
+ */
private def receiveNewClient(): Boolean =
this.clientGetter.newClient() match
case Some(c) =>
@@ -62,9 +65,9 @@ class Server(port: Int, maxClients: Int, val timeLimit: Int):
false
/** Sends `message` to all clients
- *
- * @param message the message to send
- */
+ *
+ * @param message the message to send
+ */
private def writeToAll(message: String): Unit =
this.clients.mapAndRemove(c =>
val output = c.socket.getOutputStream