Пример #1
0
    def usersTimeoutCheckLoop(self):
        """
		Start timed out users disconnect loop.
		This function will be called every `checkTime` seconds and so on, forever.
		CALL THIS FUNCTION ONLY ONCE!
		:return:
		"""
        log.debug("Checking timed out clients")
        timedOutTokens = []  # timed out users
        timeoutLimit = int(time.time()) - 100
        for key, value in self.tokens.items():
            # Check timeout (fokabot is ignored)
            if value.pingTime < timeoutLimit and value.userID != 999 and value.irc == False and value.tournament == False:
                # That user has timed out, add to disconnected tokens
                # We can't delete it while iterating or items() throws an error
                timedOutTokens.append(key)

        # Delete timed out users from self.tokens
        # i is token string (dictionary key)
        for i in timedOutTokens:
            log.debug("{} timed out!!".format(self.tokens[i].username))
            self.tokens[i].enqueue(
                serverPackets.notification(
                    "Your connection to the server timed out."))
            logoutEvent.handle(self.tokens[i], None)
        del timedOutTokens

        # Schedule a new check (endless loop)
        threading.Timer(100, self.usersTimeoutCheckLoop).start()
Пример #2
0
    def checkBanned(self):
        """
		Check if this user is banned. If so, disconnect it.

		:return:
		"""
        if userUtils.isBanned(self.userID):
            self.enqueue(serverPackets.loginBanned())
            logoutEvent.handle(self, deleteToken=False)
Пример #3
0
	def checkBanned(self):
		"""
		Check if this user is banned. If so, disconnect it.

		:return:
		"""

		# Ok so the only place where this is used is right after a priv refresh
		# from db so...
		if userUtils.isBanned(self.userID):
			self.enqueue(serverPackets.loginBanned())
			logoutEvent.handle(self, deleteToken=False)
Пример #4
0
def IRCDisconnect(username):
    """
	Handle IRC logout bancho-side.
	Remove token and broadcast logout packet.

	:param username: username
	:return:
	"""
    token = glob.tokens.getTokenFromUsername(username)
    if token is None:
        log.warning("{} doesn't exist".format(username))
        return
    logoutEvent.handle(token)
    log.info("{} disconnected from IRC".format(username))
Пример #5
0
    def silentKick(self, reason="kick"):
        """
		Kick this user from the server

		:param message: Notification message to send to this user.
						Default: "You have been kicked from the server. Please login again."
		:param reason: Kick reason, used in logs. Default: "kick"
		:return:
		"""
        # Send packet to target
        log.info("{} has been disconnected. (silent {})".format(
            self.username, reason))
        self.enqueue(serverPackets.loginFailed())

        # Logout event
        logoutEvent.handle(self, deleteToken=self.irc)
Пример #6
0
    def deleteOldTokens(self, userID):
        """
		Delete old userID's tokens if found

		:param userID: tokens associated to this user will be deleted
		:return:
		"""
        # Delete older tokens
        delete = []
        for key, value in list(self.tokens.items()):
            if value.userID == userID:
                # Delete this token from the dictionary
                #self.tokens[key].kick("You have logged in from somewhere else. You can't connect to Bancho/IRC from more than one device at the same time.", "kicked, multiple clients")
                delete.append(self.tokens[key])

        for i in delete:
            logoutEvent.handle(i)
Пример #7
0
    def usersTimeoutCheckLoop(self):
        """
		Start timed out users disconnect loop.
		This function will be called every `checkTime` seconds and so on, forever.
		CALL THIS FUNCTION ONLY ONCE!
		:return:
		"""
        try:
            log.debug("Checking timed out clients")
            exceptions = []
            timedOutTokens = []  # timed out users
            timeoutLimit = int(time.time()) - 100
            for key, value in self.tokens.items():
                # Check timeout (fokabot is ignored)
                #print("UserID {} Always Online: {}".format(value.userID, aobaHelper.getAlwaysOnline(value.userID)))
                if aobaHelper.getAlwaysOnline(value.userID) == False:
                    if value.pingTime < timeoutLimit and not value.irc and not value.tournament:
                        # That user has timed out, add to disconnected tokens
                        # We can't delete it while iterating or items() throws an error
                        timedOutTokens.append(key)

            # Delete timed out users from self.tokens
            # i is token string (dictionary key)
            for i in timedOutTokens:
                log.debug("{} timed out!!".format(self.tokens[i].username))
                self.tokens[i].enqueue(
                    serverPackets.notification(
                        "Your connection to the server timed out."))
                try:
                    logoutEvent.handle(self.tokens[i], None)
                except Exception as e:
                    exceptions.append(e)
                    log.error(
                        "Something wrong happened while disconnecting a timed out client. Reporting to Sentry "
                        "when the loop ends.")
            del timedOutTokens

            # Re-raise exceptions if needed
            if exceptions:
                raise periodicLoopException(exceptions)
        finally:
            # Schedule a new check (endless loop)
            threading.Timer(100, self.usersTimeoutCheckLoop).start()