Example #1
0
    def mp_make():
        if len(message) < 2:
            raise exceptions.invalidArgumentsException(
                "Wrong syntax: !mp make <name>")
        matchName = " ".join(message[1:]).strip()
        if not matchName:
            raise exceptions.invalidArgumentsException(
                "Match name must not be empty!")
        userID = userUtils.getID(fro)

        for (_, __match) in glob.matches.matches.items():
            if __match.hostUserID == userID:
                return "You have opened match {}, please close it before use this command!".format(
                    __match.matchID)

        matchID = glob.matches.createMatch(matchName,
                                           generalUtils.stringMd5(
                                               generalUtils.randomString(32)),
                                           0,
                                           "Tournament",
                                           "",
                                           0,
                                           userID,
                                           isTourney=True)
        glob.matches.matches[matchID].sendUpdates()
        return "Tourney match #{} created!".format(matchID)
Example #2
0
    def asyncPost(self):
        try:
            if glob.debug:
                requestsManager.printArguments(self)

            # Make sure screenshot file was passed
            if "ss" not in self.request.files:
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "p"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("p")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not verify_password(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if not userUtils.checkBanchoSession(userID, ip):
                raise exceptions.noBanchoSessionException(
                    MODULE_NAME, username, ip)

            # Rate limit
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                return self.write("no")
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            while os.path.exists(
                    path := BASE_PATH.format(generalUtils.randomString(8))):
                pass
Example #3
0
 def make(response, token, sender, channel, message):
     if len(message) < 1:
         raise exceptions.invalidArgumentsException(
             "Wrong syntax: !mp make <name>")
     matchName = " ".join(message[0:]).strip()
     if not matchName:
         raise exceptions.invalidArgumentsException(
             "Match name must not be empty!")
     userID = userUtils.getID(sender)
     matchID = glob.matches.createMatch(matchName,
                                        generalUtils.stringMd5(
                                            generalUtils.randomString(32)),
                                        0,
                                        "Tournament",
                                        "",
                                        0,
                                        -1,
                                        creatorUserID=userID,
                                        isTourney=True)
     glob.matches.matches[matchID].sendUpdates()
     if token.irc:
         newChan = "{}_{}".format(chatChannels.MULTIPLAYER_PREFIX, matchID)
         glob.ircServer.banchoJoinChannel(token.username, newChan)
         for c in glob.ircServer.clients.values():
             if c.banchoUsername == token.username:
                 c.joinHandler(None, [newChan])
     else:
         token.joinMatch(matchID)
         if not token.tournament:
             glob.matches.matches[matchID].setHost(userID)
     response.target = sender
     response.setContent(
         token,
         "Created the tournament match #{} {}".format(matchID, matchName))
Example #4
0
 def mp_random_password():
     userID = userUtils.getID(fro)
     if not can_user_touch_lobby(get_match_id_from_channel(chan), userID):
         return False
     password = generalUtils.stringMd5(generalUtils.randomString(32))
     _match = glob.matches.matches[get_match_id_from_channel(chan)]
     _match.changePassword(password)
     return "Match password has been changed to a random one"
Example #5
0
    def asyncPost(self):
        try:
            if glob.debug:
                requestsManager.printArguments(self)

            # Make sure screenshot file was passed
            if "ss" not in self.request.files:
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "p"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("p")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not userUtils.checkLogin(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if userUtils.check2FA(userID, ip):
                raise exceptions.need2FAException(MODULE_NAME, username, ip)

            # Rate limit
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                self.write("no")
                return
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            # Get a random screenshot id
            found = False
            screenshotID = ""
            while not found:
                screenshotID = generalUtils.randomString(8)
                if not os.path.isfile(
                        ".data/screenshots/{}.png".format(screenshotID)):
                    found = True
                    glob.db.execute(
                        "INSERT INTO screenshots (userid, ssid, sstime) VALUES (%s, %s, %s)",
                        [userID, screenshotID,
                         int(time.time())])

            # Write screenshot file to .data folder
            with open(".data/screenshots/{}.png".format(screenshotID),
                      "wb") as f:
                f.write(self.request.files["ss"][0]["body"])

            # Output
            log.info("New screenshot ({})".format(screenshotID))

            # Return screenshot link
            self.write("{}/ss/{}.png".format(
                glob.conf.config["server"]["serverurl"], screenshotID))
        except exceptions.need2FAException:
            pass
        except exceptions.invalidArgumentsException:
            pass
        except exceptions.loginFailedException:
            pass
Example #6
0
	def mpMake():
		if len(message) < 2:
			raise exceptions.invalidArgumentsException("Wrong syntax: !mp make <name>")
		matchName = " ".join(message[1:]).strip()
		if not matchName:
			raise exceptions.invalidArgumentsException("Match name must not be empty!")
		matchID = glob.matches.createMatch(matchName, generalUtils.stringMd5(generalUtils.randomString(32)), 0, "Tournament", "", 0, -1, isTourney=True)
		glob.matches.matches[matchID].sendUpdates()
		return "Tourney match #{} created!".format(matchID)
    def asyncGet(self):
        statusCode = 400
        response = {'message': "invalid parameters"}

        try:
            # Check args
            if not requestsManager.checkArguments(
                    self.request.arguments,
                ['k', 'matchName', 'gameMode', 'isTourney']):
                raise exceptions.invalidArgumentsException()

            # Check ci key
            key = self.get_argument('k')
            if key is None or key != glob.conf.config["server"]["cikey"]:
                response[
                    'message'] = 'Bad secret key. You are not allowed to access to this api.'
                raise exceptions.invalidArgumentsException()

            matchName = self.get_argument('matchName')
            gameMode = getGameModeForMatchAPI(self.get_argument('gameMode'))
            isTourney = self.get_argument('isTourney')

            if isTourney == 'True':
                isTourney = True
            elif isTourney == 'False':
                isTourney = False
            else:
                response[
                    'message'] = 'isTourney is requirement not optional. Only accepts True or False'
                raise exceptions.invalidArgumentsException()

            if gameMode is None:
                response[
                    'message'] = 'Oh my we only accepts gameMode std, taiko, ctb and mania'
                raise exceptions.invalidArgumentsException()

            matchID = glob.matches.createMatch(
                matchName,
                generalUtils.stringMd5(generalUtils.randomString(32)),
                0,
                "Tournament",
                "",
                gameMode,
                -1,
                isTourney=isTourney)
            glob.matches.matches[matchID].sendUpdates()
            response = {"matchID": matchID}
            statusCode = 200
        except exceptions.invalidArgumentsException:
            statusCode = 400

        self.write(json.dumps(response))
        self.set_status(statusCode)
Example #8
0
	def asyncPost(self):
		try:
			if glob.debug:
				requestsManager.printArguments(self)

			# Make sure screenshot file was passed
			if "ss" not in self.request.files:
				raise exceptions.invalidArgumentsException(MODULE_NAME)

			# Check user auth because of sneaky people
			if not requestsManager.checkArguments(self.request.arguments, ["u", "p"]):
				raise exceptions.invalidArgumentsException(MODULE_NAME)
			username = self.get_argument("u")
			password = self.get_argument("p")
			userID = userUtils.getID(username)
			if not userUtils.checkLogin(userID, password):
				raise exceptions.loginFailedException(MODULE_NAME, username)
			if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
				self.write("no")
				return
			glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)
			# Get a random screenshot id
			found = False
			screenshotID = ""
			while not found:
				screenshotID = generalUtils.randomString(8)
				if not os.path.isfile(".data/screenshots/{}.jpg".format(screenshotID)):
					found = True

			# Write screenshot file to .data folder
			with open(".data/screenshots/{}.jpg".format(screenshotID), "wb") as f:
				f.write(self.request.files["ss"][0]["body"])

			# Output
			log.info("New screenshot ({})".format(screenshotID))

			# Return screenshot link
			self.write("{}/ss/{}.jpg".format("https://osu.gatari.pw", screenshotID))
		except exceptions.invalidArgumentsException:
			pass
		except exceptions.loginFailedException:
			pass
Example #9
0
	def asyncPost(self):
		try:
			if glob.debug:
				requestsManager.printArguments(self)

			# Make sure screenshot file was passed
			if "ss" not in self.request.files:
				raise exceptions.invalidArgumentsException(MODULE_NAME)

			# Check user auth because of sneaky people
			if not requestsManager.checkArguments(self.request.arguments, ["u", "p"]):
				raise exceptions.invalidArgumentsException(MODULE_NAME)
			username = self.get_argument("u")
			password = self.get_argument("p")
			ip = self.getRequestIP()
			userID = userUtils.getID(username)
			if not userUtils.checkLogin(userID, password):
				raise exceptions.loginFailedException(MODULE_NAME, username)
			if userUtils.check2FA(userID, ip):
				raise exceptions.need2FAException(MODULE_NAME, username, ip)

			# Rate limit
			if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
				self.write("no")
				return
			glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

			# Get a random screenshot id
			found = False
			screenshotID = ""
			while not found:
				screenshotID = generalUtils.randomString(8)
				if not os.path.isfile(".data/screenshots/{}.png".format(screenshotID)):
					found = True

			# Write screenshot file to .data folder
			with open(".data/screenshots/{}.png".format(screenshotID), "wb") as f:
				f.write(self.request.files["ss"][0]["body"])

			# Add Akatsuki's watermark
			base_screenshot = Image.open('.data/screenshots/{}.png'.format(screenshotID))
			watermark = Image.open('constants/watermark.png')
			width, height = base_screenshot.size

			position = (width - 330, height - 200)

			transparent = Image.new('RGBA', (width, height), (0,0,0,0))
			transparent.paste(base_screenshot, (0,0))
			transparent.paste(watermark, position, mask=watermark)
			transparent.show()
			transparent.save('.data/screenshots/{}.png'.format(screenshotID))

			# Output
			log.info("New screenshot ({})".format(screenshotID))

			# Return screenshot link
			self.write("{}/ss/{}.png".format(glob.conf.config["server"]["servername"], screenshotID))
		except exceptions.need2FAException:
			pass
		except exceptions.invalidArgumentsException:
			pass
		except exceptions.loginFailedException:
			pass
Example #10
0
 def mpRandomPassword():
     password = generalUtils.stringMd5(generalUtils.randomString(32))
     _match = glob.matches.matches[getMatchIDFromChannel(chan)]
     _match.changePassword(password)
     return "Match password has been changed to a random one"
Example #11
0
    def asyncPost(self):
        try:
            if glob.debug:
                requestsManager.printArguments(self)

            # Make sure screenshot file was passed
            if "ss" not in self.request.files:
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "p"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("p")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not userUtils.checkLogin(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if userUtils.check2FA(userID, ip):
                raise exceptions.need2FAException(MODULE_NAME, username, ip)

            # Rate limit
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                self.write("no")
                return
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            #check if user folder exist
            screenshotID = generalUtils.randomString(8)
            if not os.path.isdir("{}/{}/".format(
                    glob.conf.config["server"]["storagepath"], userID)):
                os.mkdir("{}/{}/".format(
                    glob.conf.config["server"]["storagepath"], userID))

            # Get a random screenshot id
            found = False
            screenshotID = ""
            while not found:
                screenshotID = generalUtils.randomString(8)
                if not os.path.isfile("{}/{}/{}.jpg".format(
                        glob.conf.config["server"]["storagepath"], userID,
                        screenshotID)):
                    found = True

            # Write screenshot file to screenshots folder
            with open(
                    "{}/{}/{}.jpg".format(
                        glob.conf.config["server"]["storagepath"], userID,
                        screenshotID), "wb") as f:
                f.write(self.request.files["ss"][0]["body"])

            # Output
            log.info("New screenshot ({})".format(screenshotID))

            # Return screenshot link
            self.write("https://storage.aeris-dev.pw/get/{}/{}.jpg".format(
                userID, screenshotID))
        except exceptions.need2FAException:
            pass
        except exceptions.invalidArgumentsException:
            pass
        except exceptions.loginFailedException:
            pass
Example #12
0
    def asyncPost(self):
        try:
            if glob.conf["DEBUG"]:
                requestsManager.printArguments(self)

            # Make sure screenshot file was passed
            if "ss" not in self.request.files:
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "p"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("p")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not userUtils.checkLogin(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if userUtils.check2FA(userID, ip):
                raise exceptions.need2FAException(MODULE_NAME, username, ip)

            # Rate limit
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                self.write("no")
                return
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            # Get a random screenshot id
            hasS3 = bool(glob.conf["S3_SCREENSHOTS_BUCKET"]) \
             and bool(glob.conf["S3_SCREENSHOTS_REGION"]) \
             and bool(glob.conf["S3_SCREENSHOTS_ENDPOINT_URL"])
            found = False
            screenshotID = ""
            while not found:
                screenshotID = generalUtils.randomString(8)
                if hasS3:
                    try:
                        glob.threadScope.s3Screenshots.head_object(
                            Bucket=glob.conf["S3_SCREENSHOTS_BUCKET"],
                            Key=f"{screenshotID}.jpg")
                        found = False
                    except botocore.errorfactory.ClientError:
                        found = True
                else:
                    found = not os.path.isfile("{}/{}.jpg".format(
                        glob.conf["SCREENSHOTS_FOLDER"], screenshotID))

            # Output
            log.info("New screenshot ({})".format(screenshotID))

            # Write screenshot file to .data folder
            if hasS3:
                with io.BytesIO(self.request.files["ss"][0]["body"]) as f:
                    glob.threadScope.s3Screenshots.upload_fileobj(
                        f,
                        glob.conf["S3_SCREENSHOTS_BUCKET"],
                        f"{screenshotID}.jpg",
                        ExtraArgs={"ACL": "public-read"})
            else:
                with open(
                        "{}/{}.jpg".format(glob.conf["SCREENSHOTS_FOLDER"],
                                           screenshotID), "wb") as f:
                    f.write(self.request.files["ss"][0]["body"])

            # Return screenshot link
            self.write("{}/ss/{}.jpg".format(glob.conf["SERVER_URL"],
                                             screenshotID))
        except exceptions.need2FAException:
            pass
        except exceptions.invalidArgumentsException:
            pass
        except exceptions.loginFailedException:
            pass
Example #13
0
 def randomPassword(response, token, sender, channel, message):
     password = generalUtils.stringMd5(generalUtils.randomString(32))
     _match = getCurrentMatch(channel)
     _match.changePassword(password)
     response.setContent(token,
                         "Match password has been changed to a random one")