Exemplo n.º 1
0
def validateUserRoomPwd(password, isRetype=False):
    if not password:
        if isRetype:
            errorID = CHANNEL_ERROR_ID.PASSWORD_EMPTY
        else:
            errorID = CHANNEL_ERROR_ID.RETYPE_EMPTY
        return ('', ClientChannelError(errorID))
    else:
        try:
            password = ResourcePrep.prepare(password)
        except XmppStringPrepError:
            if isRetype:
                errorID = CHANNEL_ERROR_ID.PASSWORD_INVALID
            else:
                errorID = CHANNEL_ERROR_ID.RETYPE_INVALID
            return ('', ClientChannelError(errorID))

        length = len(password)
        return ('',
                ClientIntLimitError(
                    LIMIT_ERROR_ID.PWD_INVALID_LENGTH,
                    CHANNEL_LIMIT.PWD_MIN_CHARS_COUNT,
                    CHANNEL_LIMIT.PWD_MAX_CHARS_COUNT)) if not isRetype and (
                        CHANNEL_LIMIT.PWD_MIN_CHARS_COUNT > length
                        or CHANNEL_LIMIT.PWD_MAX_CHARS_COUNT < length) else (
                            password.encode('utf-8'), None)
Exemplo n.º 2
0
 def addIgnored(self, dbID, name):
     error = self._checkCooldown(CLIENT_ACTION_ID.ADD_IGNORED)
     if error:
         return (False, error)
     tasks, itemType = [], XMPP_ITEM_TYPE.EMPTY_ITEM
     contact = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP)
     if contact:
         if contact.isCurrentPlayer():
             return (False,
                     ClientActionError(CLIENT_ACTION_ID.ADD_IGNORED,
                                       CLIENT_ERROR_ID.GENERIC))
         itemType = contact.getItemType()
         if itemType in XMPP_ITEM_TYPE.BLOCK_ITEMS:
             return (False,
                     ClientContactError(CONTACT_ERROR_ID.BLOCK_ITEM_EXISTS,
                                        contact.getFullName()))
     length = self.usersStorage.getCount(
         ItemsFindCriteria(XMPP_ITEM_TYPE.PERSISTENT_BLOCKING_LIST))
     if length >= CONTACT_LIMIT.BLOCK_MAX_COUNT:
         return (False,
                 ClientIntLimitError(LIMIT_ERROR_ID.MAX_BLOCK_ITEMS,
                                     CONTACT_LIMIT.BLOCK_MAX_COUNT))
     if contact:
         jid = contact.getJID()
         if itemType in XMPP_ITEM_TYPE.SUB_PENDING_ITEMS:
             tasks.append(sub_tasks.CancelSubscriptionTask(jid))
     else:
         jid = makeContactJID(dbID)
     tasks.append(block_tasks.AddBlockItemTask(jid, name))
     if itemType in XMPP_ITEM_TYPE.ROSTER_ITEMS:
         groups = contact.getGroups()
         if groups:
             tasks.append(roster_tasks.EmptyGroupsTask(jid, groups=groups))
     self.__cooldown.process(CLIENT_ACTION_ID.ADD_IGNORED)
     return self.__addTasks(CLIENT_ACTION_ID.ADD_IGNORED, jid, *tasks)
 def canAddFriends(self):
     if self._useCachedCounts:
         length = self._cachedRosterCount
     else:
         length = self._getRosterCount()
     return (False,
             ClientIntLimitError(LIMIT_ERROR_ID.MAX_ROSTER_ITEMS,
                                 CONTACT_LIMIT.ROSTER_MAX_COUNT)
             ) if length >= CONTACT_LIMIT.ROSTER_MAX_COUNT else (True, None)
Exemplo n.º 4
0
def validateContactNote(note):
    if not note:
        return ('', ClientContactError(CONTACT_ERROR_ID.NOTE_EMPTY))
    if len(unicode_from_utf8(note)[0]) not in xrange(
            CONTACT_LIMIT.NOTE_MIN_CHARS_COUNT,
            CONTACT_LIMIT.NOTE_MAX_CHARS_COUNT + 1):
        return (note,
                ClientIntLimitError(LIMIT_ERROR_ID.NOTE_INVALID_LENGTH,
                                    CONTACT_LIMIT.NOTE_MIN_CHARS_COUNT,
                                    CONTACT_LIMIT.NOTE_MAX_CHARS_COUNT))
    return (note, None)
def validateRosterItemGroup(name):
    if not name:
        return ('', ClientContactError(CONTACT_ERROR_ID.GROUP_EMPTY))
    else:
        try:
            name = ResourcePrep.prepare(name)
        except XmppStringPrepError:
            return ('', ClientContactError(CONTACT_ERROR_ID.GROUP_INVALID_NAME, name))

        length = len(name)
        return (name.encode('utf-8'), ClientIntLimitError(LIMIT_ERROR_ID.GROUP_INVALID_LENGTH, CONTACT_LIMIT.GROUP_MAX_LENGTH, CONTACT_LIMIT.GROUP_MIN_LENGTH)) if CONTACT_LIMIT.GROUP_MIN_LENGTH > length or CONTACT_LIMIT.GROUP_MAX_LENGTH < length else (name.encode('utf-8'), None)
def validateUserRoomName(name):
    if not name:
        return ('', ClientChannelError(CHANNEL_ERROR_ID.NAME_EMPTY))
    else:
        try:
            name = ResourcePrep.prepare(name)
        except XmppStringPrepError:
            return ('', ClientChannelError(CHANNEL_ERROR_ID.NAME_INVALID, name))

        length = len(name)
        return (name.encode('utf-8'), ClientIntLimitError(LIMIT_ERROR_ID.CHANNEL_INVALID_LENGTH, CHANNEL_LIMIT.NAME_MAX_CHARS_COUNT, CHANNEL_LIMIT.NAME_MIN_CHARS_COUNT)) if CHANNEL_LIMIT.NAME_MIN_CHARS_COUNT > length or CHANNEL_LIMIT.NAME_MAX_CHARS_COUNT < length else (name.encode('utf-8'), None)
Exemplo n.º 7
0
 def addGroup(self, name):
     error = self._checkCooldown(CLIENT_ACTION_ID.ADD_GROUP)
     if error:
         return (False, error)
     elif self.usersStorage.isGroupExists(name):
         return (False, ClientContactError(CONTACT_ERROR_ID.GROUP_EXISTS, name))
     elif len(self.usersStorage.getGroups()) >= CONTACT_LIMIT.GROUPS_MAX_COUNT:
         return (False, ClientIntLimitError(LIMIT_ERROR_ID.MAX_GROUP, CONTACT_LIMIT.GROUPS_MAX_COUNT))
     else:
         self.usersStorage.addEmptyGroup(name)
         g_messengerEvents.users.onEmptyGroupsChanged({name}, None)
         self.__cooldown.process(CLIENT_ACTION_ID.ADD_GROUP)
         return (True, None)