예제 #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)
예제 #2
0
def friend_request_list(socket, args):
    if len(inputs[socket].profile.requests) > 0:
        output = ''.join([' %s' % r.username
                          for r in inputs[socket].profile.requests])[1:]
        send_cmd_success(socket, 145, output)
    else:
        send_error(socket, 224)
예제 #3
0
def register(socket, args):
    logging.debug('Processing registeration')
    if not db.get_user(args[1]):
        User(username=args[1], password=args[2]).save()
        send_cmd_success(socket, 102)
    else:
        send_error(socket, 201)
예제 #4
0
def hangup(socket, args):
    target = socket_by_username(args[1], socket)
    if target:
        call = call_between(socket, target)
        if call:
            call.hangup()
            send_cmd_success(socket, 112)
        else:
            send_error(socket, 403)
예제 #5
0
def login(socket, args):
    logging.debug('Processing login')
    user = db.get_user(args[1])
    if user == 1:
        send_error(socket, 204)
    elif user and user.password == args[2]:
        auth.login(socket, user)
        send_cmd_success(socket, 100, user.username)
    else:
        send_error(socket, 200)
예제 #6
0
def friend_request_reject(socket, args):
    target = db.get_user(args[1])
    if target:
        if target in inputs[socket].profile.requests:
            inputs[socket].profile.requests.remove(target)
            send_cmd_success(socket, 142)
        else:
            send_error(socket, 223)
    else:
        send_error(socket, 220)
예제 #7
0
def call(socket, args):
    target = socket_by_username(args[1], socket)
    if target:
        if not call_between(socket, target):
            if inputs[target].udp_addr:
                Call(caller=socket, target=target)
                send_cmd_success(socket, 110)
            else:
                send_error(socket, 401)
        else:
            send_error(socket, 402)
예제 #8
0
def udp_init(socket, args):
    if inputs[socket].udp_addr:
        send_error(socket, 104)
    elif socket in list(udp_inits.values()):
        send_error(socket, 105)
    else:
        key = ''.join(random.choice(string.ascii_lowercase) for x in range(10))
        # Rest of this happens in brunod.py
        udp_inits.update({key: socket})
        send_cmd_success(socket, 120)
        send_event(socket, 101, (key))
예제 #9
0
def send_msg(socket, args):
    """This will send the normal txt messages"""
    if args.get('user'):
        # message to user
        content = args.get('content')
        sock = socket_by_username(args.get('user'), socket)
        if sock:
            send_message(sock, inputs[socket].profile.username, content)
            send_cmd_success(socket, 130)
    else:
        # TODO: Group message
        pass
예제 #10
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)
예제 #11
0
def answer(socket, args):
    def pending(socket, target):
        call = call_between(socket, target)
        if call and not call.answered:
            return call
        return False
    target = socket_by_username(args[1], socket)
    if target:
        # call = inputs[socket].call_pending(target)
        call = pending(socket, target)
        if call:
            send_cmd_success(socket, 111)
            call.answer()
        else:
            send_error(socket, 400)
예제 #12
0
def register(socket, args):
    logging.debug('Processing registeration')
    if not db.get_user(args[1]):
        try:
            User(username=args[1], password=args[2]).save()
        except ValueError as e:
            if e.args[0]['field'] == 'username':
                send_error(socket, 205)
            elif e.args[0]['field'] == 'password':
                send_error(socket, 206)
            else:
                send_error(socket, 207)
        else:
            send_cmd_success(socket, 102)
    else:
        send_error(socket, 201)
예제 #13
0
def friend_request_accept(socket, args):
    target = db.get_user(args[1])
    if target:
        if target in inputs[socket].profile.requests:
            # Remove request
            inputs[socket].profile.requests.remove(target)
            # Add users to eachothers friends lists
            inputs[socket].profile.friends.append(target)
            target.friends.append(inputs[socket].profile)
            send_cmd_success(socket, 141)
            if target.online:
                s = socket_by_user(target)
                if s:
                    send_event(s, 111, inputs[socket].profile.username)
                    send_event(socket, 111, target.username)
        else:
            send_error(socket, 223)
    else:
        send_error(socket, 220)
예제 #14
0
def friend_request_send(socket, args):
    target = db.get_user(args[1])
    if target:
        if target not in inputs[socket].profile.friends:
            if target not in inputs[socket].profile.requests and\
                    inputs[socket].profile not in target.requests:
                target.requests.append(inputs[socket].profile)
                send_cmd_success(socket, 140)
                # Lets notify the user that it has new friend request
                if target.online:
                    sock = socket_by_user(target)
                    if sock:
                        send_event(sock, 110, inputs[socket].profile.username)
            else:
                send_error(socket, 222)
        else:
            send_error(socket, 221)
    else:
        send_error(socket, 220)
예제 #15
0
def logout(socket, args):
    logging.debug('Precessing logout')
    auth.logout(socket)
    send_cmd_success(socket, 101)
예제 #16
0
def echo(socket, args):
    logging.debug('Echoing args')
    send_cmd_success(socket, 99, "Echoed")
    send_srv_message(socket, args)
예제 #17
0
def online_users(socket, args):
    output = ''
    for i in inputs:
        if inputs[i].profile:
            output += '%s %s;' % (inputs[i].profile.username, str(True))
    send_cmd_success(socket, 131, output)