Example #1
0
def logout(socket, args):
    logging.debug('Precessing logout')
    user = inputs[socket].profile
    # Notify user's friends of its logout
    notify_friends(user, 112, user.username)
    auth.logout(socket, user=user)
    send_cmd_success(socket, 101)
Example #2
0
def login(socket, args):
    logging.debug('Processing login')
    user = db.get_user(args[1])
    if user and user.online is True:
        send_error(socket, 204)
    elif user and user.valid_password(args[2]):
        auth.login(socket, user)
        send_cmd_success(socket, 100, user.username)
        send_event(socket, 99, (''.join([' %s:%s' % (f.username, f.online)
                                         # [1:] so we dont send extra space
                                         for f in user.friends])[1:],
                                ''.join([r.username for r in user.requests])))
        notify_friends(inputs[socket].profile, 111, user.username)
    else:
        send_error(socket, 200)
Example #3
0
def close_client(socket):
    """
        close_client(socket) -> None

        Closes client's socket and removes entry from env.inputs
    """
    # TODO: Notify online friends for /logout/ (like in commands.logout)
    logging.info('Closing client')
    # if inputs[].profile is not None, the client has disconnected without
    # logout
    if inputs[socket].profile:
        # User has not used logout command, so lets notify
        # its friends for logout
        notify_friends(inputs[socket].profile, 112,
                       inputs[socket].profile.username)
        # And log it out from db
        auth.logout(socket)
    socket.close()
    del inputs[socket]