Remove _chatLock and _internalLock

This commit is contained in:
Giuseppe Guerra 2017-08-11 22:19:39 +02:00
parent 29359ad4fd
commit ce75f5ee99

View File

@ -88,8 +88,6 @@ 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._internalLock = threading.Lock() # Acquired while performing internal operations on this token
self._chatLock = threading.Lock() # Acquired while performing chat operations
self._streamsLock = threading.Lock() # Acquired while joining/leaving streams
self._spectatorLock = threading.Lock() # Acquired while starting/stopping spectating
self._multiplayerLock = threading.Lock()# Acquired while joining/leaving streams
@ -143,8 +141,6 @@ class token:
:raises: exceptions.userAlreadyInChannelException()
exceptions.channelNoPermissionsException()
"""
try:
self._chatLock.acquire()
if channelObject.name in self.joinedChannels:
raise exceptions.userAlreadyInChannelException()
if channelObject.publicRead == False and self.admin == False:
@ -152,8 +148,6 @@ class token:
self.joinedChannels.append(channelObject.name)
self.joinStream("chat/{}".format(channelObject.name))
self.enqueue(serverPackets.channelJoinSuccess(self.userID, channelObject.clientName))
finally:
self._chatLock.release()
def partChannel(self, channelObject):
"""
@ -161,12 +155,8 @@ class token:
:param channelObject: channel object
"""
try:
self._chatLock.acquire()
self.joinedChannels.remove(channelObject.name)
self.leaveStream("chat/{}".format(channelObject.name))
finally:
self._chatLock.release()
def setLocation(self, latitude, longitude):
"""
@ -387,9 +377,6 @@ class token:
:param reason: Kick reason, used in logs. Default: "kick"
:return:
"""
try:
self._internalLock.acquire()
# Send packet to target
log.info("{} has been disconnected. ({})".format(self.username, reason))
if message != "":
@ -398,8 +385,6 @@ class token:
# Logout event
logoutEvent.handle(self, deleteToken=self.irc)
finally:
self._internalLock.release()
def silence(self, seconds = None, reason = "", author = 999):
"""
@ -410,9 +395,6 @@ class token:
:param author: userID of who has silenced the user. Default: 999 (FokaBot)
:return:
"""
try:
self._chatLock.acquire()
if seconds is None:
# Get silence expire from db if needed
seconds = max(0, userUtils.getSilenceEnd(self.userID) - int(time.time()))
@ -428,8 +410,6 @@ class token:
# Send silenced packet to everyone else
glob.streams.broadcast("main", serverPackets.userSilenced(self.userID))
finally:
self._chatLock.release()
def spamProtection(self, increaseSpamRate = True):
"""
@ -438,9 +418,6 @@ class token:
:param increaseSpamRate: set to True if the user has sent a new message. Default: True
:return:
"""
try:
self._chatLock.acquire()
# Increase the spam rate if needed
if increaseSpamRate:
self.spamRate += 1
@ -448,8 +425,6 @@ class token:
# Silence the user if needed
if self.spamRate > 10:
self.silence(1800, "Spamming (auto spam protection)")
finally:
self._chatLock.release()
def isSilenced(self):
"""
@ -474,9 +449,6 @@ class token:
:return:
"""
try:
self._internalLock.acquire()
stats = userUtils.getUserStats(self.userID, self.gameMode)
log.debug(str(stats))
if stats is None:
@ -488,8 +460,6 @@ class token:
self.totalScore = stats["totalScore"]
self.gameRank = stats["gameRank"]
self.pp = stats["pp"]
finally:
self._internalLock.release()
def checkRestricted(self):
"""