Esempio n. 1
0
    def leaveMatch(self):
        """
		Leave joined match, match stream and match channel

		:return:
		"""
        # Make sure we are in a match
        if self.matchID == -1:
            return

        # Part #multiplayer channel and streams (/ and /playing)
        chat.partChannel(token=self,
                         channel="#multi_{}".format(self.matchID),
                         kick=True)
        self.leaveStream("multi/{}".format(self.matchID))
        self.leaveStream("multi/{}/playing".format(self.matchID))  # optional

        # Set usertoken match to -1
        leavingMatchID = self.matchID
        self.matchID = -1

        # Make sure the match exists
        if leavingMatchID not in glob.matches.matches:
            return

        # The match exists, get object
        match = glob.matches.matches[leavingMatchID]

        # Set slot to free
        match.userLeft(self)

        if match.isTourney:
            # If an user leaves, then the ready status of the match changes and
            # maybe all users are ready. Or maybe nobody is in the match anymore
            match.sendReadyStatus()
Esempio n. 2
0
    def stopSpectating(self):
        """
		Stop spectating, leave spectator stream and channel
		and send required packets to host

		:return:
		"""
        try:
            self._spectLock.acquire()

            # Remove our userID from host's spectators
            if self.spectating is None or self.spectatingUserID <= 0:
                return
            if self.spectating in glob.tokens.tokens:
                hostToken = glob.tokens.tokens[self.spectating]
            else:
                hostToken = None
            streamName = "spect/{}".format(self.spectatingUserID)

            # Remove us from host's spectators list,
            # leave spectator stream
            # and end the spectator left packet to host
            self.leaveStream(streamName)
            if hostToken is not None:
                hostToken.spectators.remove(self.token)
                hostToken.enqueue(serverPackets.removeSpectator(self.userID))

                # and to all other spectators
                for i in hostToken.spectators:
                    if i in glob.tokens.tokens:
                        glob.tokens.tokens[i].enqueue(
                            serverPackets.fellowSpectatorLeft(self.userID))

                # If nobody is spectating the host anymore, close #spectator channel
                # and remove host from spect stream too
                if len(hostToken.spectators) == 0:
                    chat.partChannel(token=hostToken,
                                     channel="#spect_{}".format(
                                         hostToken.userID),
                                     kick=True,
                                     force=True)
                    hostToken.leaveStream(streamName)

                # Console output
                log.info(
                    "{} is no longer spectating {}. Current spectators: {}".
                    format(self.username, self.spectatingUserID,
                           hostToken.spectators))

            # Part #spectator channel
            chat.partChannel(token=self,
                             channel="#spect_{}".format(self.spectatingUserID),
                             kick=True,
                             force=True)

            # Set our spectating user to 0
            self.spectating = None
            self.spectatingUserID = 0
        finally:
            self._spectLock.release()
Esempio n. 3
0
    def leaveMatch(self):
        """
		Leave joined match, match stream and match channel

		:return:
		"""
        # Make sure we are in a match
        if self.matchID == -1:
            return

        # Part #multiplayer channel and streams (/ and /playing)
        chat.partChannel(token=self,
                         channel="#multi_{}".format(self.matchID),
                         kick=True)
        self.leaveStream("multi/{}".format(self.matchID))
        self.leaveStream("multi/{}/playing".format(self.matchID))  # optional

        # Set usertoken match to -1
        leavingMatchID = self.matchID
        self.matchID = -1

        # Make sure the match exists
        if leavingMatchID not in glob.matches.matches:
            return

        # The match exists, get object
        match = glob.matches.matches[leavingMatchID]

        # Set slot to free
        match.userLeft(self)
Esempio n. 4
0
def handle(userToken, packetData):
    packetData = clientPackets.tournamentLeaveMatchChannel(packetData)
    matchID = packetData["matchID"]
    if matchID not in glob.matches.matches or not userToken.tournament:
        return
    chat.partChannel(token=userToken, channel="#multi_{}".format(matchID))
    userToken.matchID = 0
Esempio n. 5
0
    def mp_removeRef():
        userID = userUtils.getID(fro)
        if not can_user_touch_lobby(get_match_id_from_channel(chan), userID,
                                    False, False):
            return False

        if len(message) < 2:
            raise exceptions.invalidArgumentsException(
                "Wrong syntax: !mp removeref <ref username>")

        userRefID = userUtils.getIDSafe(message[1])
        if not userRefID:
            raise exceptions.invalidArgumentsException("User not found")

        _match = glob.matches.matches[get_match_id_from_channel(chan)]
        if not userRefID in _match.refs:
            return "This user is not referre."

        _match.refs.remove(userRefID)
        _match.sendUpdates()
        chat.partChannel(userRefID,
                         "#multi_{}".format(_match.matchID),
                         kick=True)
        chat.partChannel(userRefID, "#multiplayer", kick=True)
        return "Match referre was deleted!"
Esempio n. 6
0
def handle(userToken, _=None, deleteToken=True):
    # get usertoken data
    userID = userToken.userID
    username = userToken.username
    requestToken = userToken.token

    # Big client meme here. If someone logs out and logs in right after,
    # the old logout packet will still be in the queue and will be sent to
    # the server, so we accept logout packets sent at least 5 seconds after login
    # if the user logs out before 5 seconds, he will be disconnected later with timeout check
    if int(time.time() - userToken.loginTime) >= 5 or userToken.irc:
        # Stop spectating
        userToken.stopSpectating()

        # Part matches
        userToken.leaveMatch()

        # Part all joined channels
        for i in userToken.joinedChannels:
            chat.partChannel(token=userToken, channel=i)

        # Leave all joined streams
        userToken.leaveAllStreams()

        # Enqueue our disconnection to everyone else
        glob.streams.broadcast("main", serverPackets.userLogout(userID))

        # Disconnect from IRC if needed
        if userToken.irc and glob.irc:
            glob.ircServer.forceDisconnection(userToken.username)

        # Delete token
        if deleteToken:
            glob.tokens.deleteToken(requestToken)
        else:
            userToken.kicked = True

        # Change username if needed
        newUsername = glob.redis.get(
            "ripple:change_username_pending:{}".format(userID))
        if newUsername is not None:
            log.debug(
                "Sending username change request for user {}".format(userID))
            glob.redis.publish(
                "peppy:change_username",
                json.dumps({
                    "userID": userID,
                    "newUsername": newUsername.decode("utf-8")
                }))

        # Console output
        url = glob.conf.extra["webhook"]
        embed = Webhook(url, color=123123)
        embed.set_author(name=username,
                         icon='https://a.themansions.nl/u/{}',
                         url='http://osu.themansions.nl/u/{}'.format(
                             userID, userID))
        embed.set_title(title='{} has logged out!'.format(username))
        embed.post()
        log.info("{} has been disconnected. (logout)".format(username))
Esempio n. 7
0
def handle(userToken, _=None, deleteToken=True):
    # get usertoken data
    userID = userToken.userID
    username = userToken.username
    requestToken = userToken.token

    # Big client meme here. If someone logs out and logs in right after,
    # the old logout packet will still be in the queue and will be sent to
    # the server, so we accept logout packets sent at least 5 seconds after login
    # if the user logs out before 5 seconds, he will be disconnected later with timeout check
    if int(time.time() - userToken.loginTime) >= 5 or userToken.irc:
        # Stop spectating
        userToken.stopSpectating()

        # Part matches
        userToken.leaveMatch()

        # Check if a users login/logouts are being tracked. If so, log to discord
        tracked = userUtils.getUserTracked(userID)
        if tracked:
            log.cmyui(
                'Tracked user {} ({}) has logged out.'.format(
                    username, userID), 'cm')

        # Part all joined channels
        for i in userToken.joinedChannels:
            chat.partChannel(token=userToken, channel=i)

        # Leave all joined streams
        userToken.leaveAllStreams()

        # Enqueue our disconnection to everyone else
        glob.streams.broadcast("main", serverPackets.userLogout(userID))

        # Disconnect from IRC if needed
        if userToken.irc and glob.irc:
            glob.ircServer.forceDisconnection(userToken.username)

        # Delete token
        if deleteToken:
            glob.tokens.deleteToken(requestToken)
        else:
            userToken.kicked = True

        # Change username if needed
        newUsername = glob.redis.get(
            "ripple:change_username_pending:{}".format(userID))
        if newUsername is not None:
            log.debug(
                "Sending username change request for user {}".format(userID))
            glob.redis.publish(
                "peppy:change_username",
                json.dumps({
                    "userID": userID,
                    "newUsername": newUsername.decode("utf-8")
                }))

        # Console output
        log.info("{} has been disconnected. (logout)".format(username))
Esempio n. 8
0
def handle(userToken, _):
    # Get usertoken data
    username = userToken.username

    # Remove user from users in lobby
    userToken.leaveStream("lobby")

    # Part lobby channel
    # Done automatically by the client
    chat.partChannel(channel="#lobby", token=userToken, kick=True)

    # Console output
    log.info("{} has left multiplayer lobby.".format(username))
Esempio n. 9
0
def handle(userToken, _=None, deleteToken=True):
    # get usertoken data
    userID = userToken.userID
    username = userToken.username
    requestToken = userToken.token

    # Big client meme here. If someone logs out and logs in right after,
    # the old logout packet will still be in the queue and will be sent to
    # the server, so we accept logout packets sent at least 5 seconds after login
    # if the user logs out before 5 seconds, he will be disconnected later with timeout check
    if int(time.time() - userToken.loginTime) >= 5 or userToken.irc:
        # Stop spectating
        userToken.stopSpectating()

        # Part matches
        userToken.leaveMatch()

        # Part all joined channels
        for i in userToken.joinedChannels:
            chat.partChannel(token=userToken, channel=i)

        # Leave all joined streams
        userToken.leaveAllStreams()

        # Enqueue our disconnection to everyone else
        glob.streams.broadcast("main", serverPackets.userLogout(userID))

        # Delete token
        if deleteToken:
            glob.tokens.deleteToken(requestToken)
        else:
            userToken.kicked = True

        #glob.db.execute("UPDATE users_stats SET current_status = 'Offline' WHERE id = %s", [userID])
        # Change username if needed
        newUsername = glob.redis.get(
            "ripple:change_username_pending:{}".format(userID))
        if newUsername is not None:
            log.debug(
                "Sending username change request for user {}".format(userID))
            glob.redis.publish(
                "peppy:change_username",
                json.dumps({
                    "userID": userID,
                    "newUsername": newUsername.decode("utf-8")
                }))

        # Console output
        log.info("{} has been disconnected. (logout)".format(username))
Esempio n. 10
0
    def removeChannel(self, name):
        """
        Removes a channel from channels list

        :param name: channel name
        :return:
        """
        if name not in self.channels:
            log.debug("{} is not in channels list".format(name))
            return
        #glob.streams.broadcast("chat/{}".format(name), serverPackets.channelKicked(name))
        stream = glob.streams.getStream("chat/{}".format(name))
        if stream != None:
            for token in stream.clients:
                if token in glob.tokens.tokens:
                    chat.partChannel(channel=name, token=glob.tokens.tokens[token], kick=True)
        glob.streams.dispose("chat/{}".format(name))
        glob.streams.remove("chat/{}".format(name))
        self.channels.pop(name)
        log.info("Removed channel {}".format(name))
Esempio n. 11
0
def handle(userToken, packetData):
    # Channel join packet
    packetData = clientPackets.channelPart(packetData)
    chat.partChannel(token=userToken, channel=packetData["channel"])