diff --git a/handlers/mainHandler.py b/handlers/mainHandler.py index dea0bd0..f4a9613 100644 --- a/handlers/mainHandler.py +++ b/handlers/mainHandler.py @@ -50,7 +50,6 @@ import traceback class handler(requestHelper.asyncRequestHandler): def asyncPost(self): - glob.meme.acquire() try: # Track time if needed if glob.requestTime == True: @@ -69,6 +68,7 @@ class handler(requestHelper.asyncRequestHandler): # No token, first request. Handle login. responseTokenString, responseData = loginEvent.handle(self) else: + userToken = None # default value try: # This is not the first packet, send response based on client's request # Packet start position, used to read stacked packets @@ -78,8 +78,10 @@ class handler(requestHelper.asyncRequestHandler): if requestTokenString not in glob.tokens.tokens: raise exceptions.tokenNotFoundException() - # Token exists, get its object + # Token exists, get its object and lock it userToken = glob.tokens.tokens[requestTokenString] + userToken.lock.acquire() + consoleHelper.printColored("[{}] locked".format(userToken.token), bcolors.YELLOW) # Keep reading packets until everything has been read while pos < len(requestData): @@ -166,6 +168,11 @@ class handler(requestHelper.asyncRequestHandler): responseData += serverPackets.notification("Whoops! Something went wrong, please login again.") consoleHelper.printColored("[!] Received packet from unknown token ({}).".format(requestTokenString), bcolors.RED) consoleHelper.printColored("> {} have been disconnected (invalid token)".format(requestTokenString), bcolors.YELLOW) + finally: + # Unlock token + if userToken != None: + consoleHelper.printColored("[{}] unlocked".format(userToken.token), bcolors.GREEN) + userToken.lock.release() if glob.requestTime == True: # End time @@ -192,7 +199,6 @@ class handler(requestHelper.asyncRequestHandler): discordBotHelper.sendConfidential(msg) finally: self.finish() - glob.meme.release() def asyncGet(self): html = "MA MAURO ESISTE?
"
diff --git a/objects/glob.py b/objects/glob.py
index b15945e..40c5f95 100644
--- a/objects/glob.py
+++ b/objects/glob.py
@@ -5,7 +5,7 @@ from objects import channelList
 from objects import matchList
 import threading
 
-VERSION = "0.9"
+VERSION = "1.2"
 
 db = None
 conf = None
@@ -17,4 +17,3 @@ memes = True
 restarting = False
 pool = None
 requestTime = False
-meme = threading.Lock()
diff --git a/objects/osuToken.py b/objects/osuToken.py
index b27bd2f..aa6ae90 100644
--- a/objects/osuToken.py
+++ b/objects/osuToken.py
@@ -7,6 +7,7 @@ from helpers import consoleHelper
 from constants import bcolors
 from constants import serverPackets
 from events import logoutEvent
+import threading
 
 class token:
 	"""Osu Token object
@@ -75,6 +76,7 @@ class token:
 		self.rank = userHelper.getRankPrivileges(self.userID)
 		self.loginTime = int(time.time())
 		self.pingTime = self.loginTime
+		self.lock = threading.Lock()	# <-- Sync primitive
 
 		# Default variables
 		self.spectators = []
diff --git a/pep.py b/pep.py
index caf1992..bb15258 100644
--- a/pep.py
+++ b/pep.py
@@ -184,7 +184,7 @@ if __name__ == "__main__":
 	glob.requestTime = generalFunctions.stringToBool(glob.conf.config["server"]["outputrequesttime"])
 
 	# Server start message and console output
-	discordBotHelper.sendConfidential("w00t p00t! (pep.py started)")
+	discordBotHelper.sendConfidential("**asyncppytornadovroom** Server started!")
 	consoleHelper.printColored("> Tornado listening for clients on 127.0.0.1:{}...".format(serverPort), bcolors.GREEN)
 
 	# Start tornado