예제 #1
0
파일: env.py 프로젝트: najeebk/bruno-server
    def __init__(self, caller, target):
        # These needs to be sockets
        self.caller = caller
        self.target = target

        inputs[self.caller].call = self
        inputs[self.target].call = self
        # FIXME: Another stupid import
        from bruno.send_utils import send_event
        send_event(self.target, 102, (inputs[self.caller].profile.username))
예제 #2
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))
예제 #3
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)
예제 #4
0
파일: env.py 프로젝트: najeebk/bruno-server
 def answer(self):
     if inputs[self.caller].udp_addr and inputs[self.target].udp_addr:
         # FIXME: This is just stupid import
         from bruno.send_utils import send_event
         self._state = self.ANSWERED
         key = ''.join(random.choice(string.ascii_lowercase)
                       for x in range(10))
         send_event(self.caller, 100,
                    (inputs[self.target].udp_addr[0],
                     inputs[self.target].udp_addr[1], key))
         send_event(self.target, 100,
                    (inputs[self.caller].udp_addr[0],
                     inputs[self.caller].udp_addr[1], key))
     else:
         # TODO: No udp avaiable
         pass
예제 #5
0
파일: env.py 프로젝트: B-Rich/bruno-server
def notify_friends(user, code, content=""):
    """
        notify_friends(user) -> None

        user = db.models.User
        code = int (event code)
        content = str (if there is content to event message, add it here)

        Sends event as notify to all user.friends. Requires that friend is
        online and in inputs in order to evet to be sended
    """
    from bruno.send_utils import send_event
    for friend in user.friends:
        if friend.online:
            s = socket_by_user(friend)
            if not s:
                continue
            send_event(s, code, content)
예제 #6
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)
예제 #7
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)
예제 #8
0
def udp_init(socket, args):
    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_event(socket, 101, (key))
예제 #9
0
파일: env.py 프로젝트: B-Rich/bruno-server
 def hangup(self):
     from bruno.send_utils import send_event
     inputs[self.caller].calls.remove(self)
     inputs[self.target].calls.remove(self)
     send_event(self.caller, 103, inputs[self.target].profile.username)
     send_event(self.target, 103, inputs[self.caller].profile.username)