Add spect lock back
This commit is contained in:
parent
8d97227965
commit
34e7a332e6
|
@ -1,30 +1,15 @@
|
|||
from objects import glob
|
||||
from constants import serverPackets
|
||||
from common.log import logUtils as log
|
||||
|
||||
def handle(userToken, packetData):
|
||||
# get token data
|
||||
userID = userToken.userID
|
||||
|
||||
# Send spectator frames to every spectator
|
||||
glob.streams.broadcast("spect/{}".format(userID), serverPackets.spectatorFrames(packetData[7:]))
|
||||
'''for i in userToken.spectators:
|
||||
# Send to every user but host
|
||||
if i != userID:
|
||||
try:
|
||||
# Get spectator token object
|
||||
spectatorToken = glob.tokens.getTokenFromUserID(i)
|
||||
|
||||
# Make sure the token exists
|
||||
if spectatorToken is None:
|
||||
raise exceptions.stopSpectating
|
||||
|
||||
# Make sure this user is spectating us
|
||||
if spectatorToken.spectating != userID:
|
||||
raise exceptions.stopSpectating
|
||||
|
||||
# Everything seems fine, send spectator frames to this spectator
|
||||
spectatorToken.enqueue(serverPackets.spectatorFrames(packetData[7:]))
|
||||
except exceptions.stopSpectating:
|
||||
# Remove this user from spectators
|
||||
userToken.removeSpectator(i)
|
||||
userToken.enqueue(serverPackets.removeSpectator(i))'''
|
||||
streamName = "spect/{}".format(userID)
|
||||
glob.streams.broadcast(streamName, serverPackets.spectatorFrames(packetData[7:]))
|
||||
log.debug("Broadcasting {}'s frames to {} clients".format(
|
||||
userID,
|
||||
len(glob.streams.streams[streamName].clients))
|
||||
)
|
|
@ -88,6 +88,7 @@ class token:
|
|||
# Locks
|
||||
self.processingLock = threading.Lock() # Acquired while there's an incoming packet from this user
|
||||
self._bufferLock = threading.Lock() # Acquired while writing to packets buffer
|
||||
self._spectLock = threading.RLock()
|
||||
|
||||
# Set stats
|
||||
self.updateCachedStats()
|
||||
|
@ -187,6 +188,9 @@ class token:
|
|||
|
||||
:param host: host osuToken object
|
||||
"""
|
||||
try:
|
||||
self._spectLock.acquire()
|
||||
|
||||
# Stop spectating old client
|
||||
self.stopSpectating()
|
||||
|
||||
|
@ -223,6 +227,8 @@ class token:
|
|||
|
||||
# Log
|
||||
log.info("{} is spectating {}".format(self.username, host.username))
|
||||
finally:
|
||||
self._spectLock.release()
|
||||
|
||||
def stopSpectating(self):
|
||||
"""
|
||||
|
@ -231,8 +237,11 @@ class token:
|
|||
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
self._spectLock.acquire()
|
||||
|
||||
# Remove our userID from host's spectators
|
||||
if self.spectating is None:
|
||||
if self.spectating is None or self.spectatingUserID <= 0:
|
||||
return
|
||||
if self.spectating in glob.tokens.tokens:
|
||||
hostToken = glob.tokens.tokens[self.spectating]
|
||||
|
@ -268,6 +277,8 @@ class token:
|
|||
# Set our spectating user to 0
|
||||
self.spectating = None
|
||||
self.spectatingUserID = 0
|
||||
finally:
|
||||
self._spectLock.release()
|
||||
|
||||
def updatePingTime(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user