fix: improve lock handling in user session interactions (#36)
Reviewed-on: #36 Reviewed-by: lq64 <lq@blackhole.local> Co-authored-by: Janis <janis.e.20@gmx.de> Co-committed-by: Janis <janis.e.20@gmx.de>
This commit is contained in:
@@ -185,7 +185,7 @@ class GameLobby private(
|
||||
}
|
||||
|
||||
private def getPlayerInteractable(userSession: UserSession, iType: InteractionType): AbstractPlayer = {
|
||||
if (!Thread.holdsLock(userSession.lock)) {
|
||||
if (!userSession.lock.isHeldByCurrentThread) {
|
||||
throw new IllegalStateException("The user session is not locked!")
|
||||
}
|
||||
if (userSession.canInteract.isEmpty || userSession.canInteract.get != iType) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.concurrent.locks.{Lock, ReentrantLock}
|
||||
|
||||
class UserSession(user: User, val host: Boolean) extends PlayerSession {
|
||||
var canInteract: Option[InteractionType] = None
|
||||
val lock: Lock = ReentrantLock()
|
||||
val lock: ReentrantLock = ReentrantLock()
|
||||
|
||||
override def updatePlayer(event: SimpleEvent): Unit = {
|
||||
event match {
|
||||
|
||||
Reference in New Issue
Block a user