Exemplo n.º 1
0
    def __process_add(self, command):
        list_ = command.args[0]
        ver = int(command.args[1])
        passport_id = command.args[2]
        display_name = url_codec.decode(command.args[3])
        group = None
        if list_ == Lists.FORWARD:
            group = self.friend_list.groups[int(command.args[4])]

        self.friend_list.ver = ver

        friend = self.friend_list.get_friend(passport_id, list_)
        if friend != None:
            friend.add_to_group(group)
        else:
            if group != None:
                friend = Friend(passport_id, passport_id, (group))
            else:
                friend = Friend(passport_id, passport_id)
            self.friend_list.lists[list_][passport_id] = friend

        self.__friend_list_updated()

        if group != None:
            self.callbacks.friend_added(list_, passport_id, display_name,
                                        group.get_id())
        else:
            self.callbacks.friend_added(list_, passport_id, display_name)
Exemplo n.º 2
0
    def __process_add(self, command):
        list_ = command.args[0]
        ver = int(command.args[1])
        passport_id = command.args[2]
        display_name = url_codec.decode(command.args[3])
        group = None
        if list_ == Lists.FORWARD:
            group = self.friend_list.groups[int(command.args[4])]

        self.friend_list.ver = ver
 
        friend = self.friend_list.get_friend(passport_id, list_)
        if friend != None and group != None:
            friend.add_to_group(group)
        else:
            if group != None:
                friend = Friend(passport_id, passport_id, (group))
            else:
                friend = Friend(passport_id, passport_id)
            self.friend_list.lists[list_][passport_id] = friend

        self.__friend_list_updated()

        if group != None:
            self.callbacks.friend_added(list_, passport_id, display_name,
                group.get_id())
        else:
            self.callbacks.friend_added(list_, passport_id, display_name)
Exemplo n.º 3
0
    def __process_lsg(self, command):
        id = int(command.args[0])
        name = url_codec.decode(command.args[1])

        group = Group(id, name)
        self.friend_list.groups[id] = group

        self.__friend_list_updated()
Exemplo n.º 4
0
 def __process_adg(self, command):
     ver = int(command.args[0])
     name = url_codec.decode(command.args[1])
     id = int(command.args[2])
     self.friend_list.ver = ver
     self.friend_list.groups[id] = Group(id, name)
     self.__friend_list_updated()
     self.callbacks.group_added(id, name)
Exemplo n.º 5
0
    def __process_lsg(self, command):
        id = int(command.args[0])
        name = url_codec.decode(command.args[1])

        group = Group(id, name)
        self.friend_list.groups[id] = group

        self.__friend_list_updated()
Exemplo n.º 6
0
 def __process_adg(self, command):
     ver = int(command.args[0])
     name = url_codec.decode(command.args[1])
     id = int(command.args[2])
     self.friend_list.ver = ver
     self.friend_list.groups[id] = Group(id, name)
     self.__friend_list_updated()
     self.callbacks.group_added(id, name)
Exemplo n.º 7
0
 def __process_reg(self, command):
     ver = int(command.args[0])
     id = int(command.args[1])
     name = url_codec.decode(command.args[2])
     self.friend_list.ver = ver
     if self.friend_list.groups.has_key(id):
         self.friend_list.groups[id].name = name
     self.__friend_list_updated()
     self.callbacks.group_renamed(id, name)
Exemplo n.º 8
0
    def __init__(self,
                 session,
                 server,
                 hash,
                 passport_id,
                 display_name,
                 session_id=None,
                 invitee=None):

        _Session.__init__(self, ChatCallbacks())

        self.session = session
        self.hash = hash
        self.passport_id = passport_id
        self.display_name = display_name
        self.session_id = session_id
        self.transaction_id = 1
        self.initial_members = []

        self.http_proxy = session.http_proxy

        #print "*** In chat.py:__init__, session %s with %s" % (session_id,passport_id)
        conn = self.conn = self._connect(server)

        if passport_id != session.passport_id:  # invited to chat
            #print "** In chat.py:__init__, sending ANS"
            ans = Command('ANS', self.transaction_id,
                          (session.passport_id, hash, session_id))
            self._send_cmd(ans, conn)

            while 1:
                resp = self._receive_cmd(conn)
                #print "** In chat.py:__init__, got %s to our ANS" % resp.cmd
                if resp.cmd == 'ANS':
                    break
                elif resp.cmd != 'IRO':
                    raise Error(int(resp.cmd), protocol.errors[resp.cmd])
                print "** In chat.py:__init__, adding %s to the chat" % resp.args[
                    2]
                self.initial_members.append(
                    (resp.args[2], url_codec.decode(resp.args[3])))

        else:  # hosting chat
            #print "** In chat.py:__init__, sending USR"
            usr = Command('USR', self.transaction_id, (passport_id, hash))
            resp = self._sync_command(usr, conn)
            #print "** In chat.py:__init__, got %s to our USR" % resp.cmd
            if resp.cmd != 'USR':
                raise Error(int(resp.cmd), protocol.errors[resp.cmd])

            #print "** In chat.py:__init__, sending CAL"
            cal = Command('CAL', self.transaction_id, (invitee, ))
            resp = self._sync_command(cal, conn)
            #print "** In chat.py:__init__, got %s to our CAL" % resp.cmd
            if resp.cmd != 'CAL':
                raise Error(int(resp.cmd), protocol.errors[resp.cmd])
            self.session_id = resp.args[1]
Exemplo n.º 9
0
 def __process_reg(self, command):
     ver = int(command.args[0])
     id = int(command.args[1])
     name = url_codec.decode(command.args[2])
     self.friend_list.ver = ver
     if self.friend_list.groups.has_key(id):
         self.friend_list.groups[id].name = name
     self.__friend_list_updated()
     self.callbacks.group_renamed(id, name)
Exemplo n.º 10
0
    def __process_rea(self, command):
        ver = int(command.args[0])
        passport_id = command.args[1]
        display_name = url_codec.decode(command.args[2])

        if passport_id == self.passport_id:
            self.display_name = display_name
            self.callbacks.display_name_changed(display_name)
        else:
            self.callbacks.display_name_received(passport_id, display_name)
Exemplo n.º 11
0
    def __process_rea(self, command):
        ver = int(command.args[0])
        passport_id = command.args[1]
        display_name = url_codec.decode(command.args[2])

        if passport_id == self.passport_id:
            self.display_name = display_name
            self.callbacks.display_name_changed(display_name)
        else:
            self.callbacks.display_name_received(passport_id, display_name)
Exemplo n.º 12
0
 def __process_nln(self, command):
     state = command.args[0]
     passport_id = command.args[1]
     display_name = url_codec.decode(command.args[2])
     friend = self.friend_list.get_friend(passport_id)
     if friend != None:
         friend.display_name = display_name
         friend.state = state
         self.__friend_list_updated()
     self.callbacks.friend_online(state, passport_id, display_name)
Exemplo n.º 13
0
 def __process_nln(self, command):
     state = command.args[0]
     passport_id = command.args[1]
     display_name = url_codec.decode(command.args[2])
     friend = self.friend_list.get_friend(passport_id)
     if friend != None:
         friend.display_name = display_name
         friend.state = state
         self.__friend_list_updated()
     self.callbacks.friend_online(state, passport_id, display_name)
Exemplo n.º 14
0
    def __handshake(self, server, username, password):
        print "*** In session.py:__handshake"
        conn = self._connect(server)
        try:
            #print "** Sending VER command"
            ver = Command('VER', self.transaction_id, ('MSNP8', 'CVR0'))
            resp = self._sync_command(ver, conn)
            if resp.cmd != 'VER' or resp.args[0] == '0':
                raise Error(0, 'Bad response for VER command.')

            #print "** Sending CVR command"
            cvr = Command('CVR', self.transaction_id,
                          ('0x0409', 'win', '3.51', 'ppc', 'msnp.py', '0.4.1',
                           'MSMSGS ', username))
            resp = self._sync_command(cvr, conn)
            if resp.cmd != 'CVR':
                raise Error(0, 'Bad response for CVR command.')

            #print "** Sending USR command"
            usr = Command('USR', self.transaction_id, ('TWN', 'I', username))
            resp = self._sync_command(usr, conn)
            if resp.cmd != 'USR' and resp.cmd != 'XFR':
                raise Error(0, 'Bad response for USR command.')

            # for dispatch server, response is ver, cvr, xfr; for notification
            # server, it is ver, cvr, usr (or same as dispatch server, in some
            # cases)

            if resp.cmd == 'XFR':
                #print "** We got an XFR"
                return split(resp.args[1], ':', 1)
            elif resp.cmd == 'USR':
                #print "** We got an USR"
                twn_string = resp.args[2]

                ticket = self.__get_twn_ticket(twn_string, username, password)

                usr = Command('USR', self.transaction_id, ('TWN', 'S', ticket))
                resp = self._sync_command(usr, conn)
                if resp.cmd != 'USR':
                    raise Error(int(resp.cmd), protocol.errors[resp.cmd])
                elif resp.args[0] != 'OK':
                    raise Error(0, 'Bad response for USR command.')

                self.passport_id = resp.args[1]
                self.display_name = url_codec.decode(resp.args[2])
                self.logged_in = 1

            else:
                print '!! session.py:__handshake Received unknow cmd: %s' % resp.cmd
        finally:
            if not self.logged_in:
                conn.break_()
            else:
                self.conn = conn
Exemplo n.º 15
0
 def __process_iln(self, command):
     state = command.args[0]
     passport_id = command.args[1]
     display_name = url_codec.decode(command.args[2])
     friend = self.friend_list.get_friend(passport_id)
     if friend != None:
         friend.state = state
         friend.display_name = display_name
         self.__friend_list_updated()
     else:  # usu. immed. after login
         self.friend_list.temp_iln[passport_id] = state
     self.callbacks.friend_online(state, passport_id, display_name)
Exemplo n.º 16
0
 def __process_iln(self, command):
     state = command.args[0]
     passport_id = command.args[1]
     display_name = url_codec.decode(command.args[2])
     friend = self.friend_list.get_friend(passport_id)
     if friend != None:
         friend.state = state
         friend.display_name = display_name
         self.__friend_list_updated()
     else:  # usu. immed. after login
         self.friend_list.temp_iln[passport_id] = state
     self.callbacks.friend_online(state, passport_id, display_name)
Exemplo n.º 17
0
 def __process_rng(self, buf):
     cmdline = split(buf)
     session_id = cmdline[1]
     sb = split(cmdline[2], ":")
     server = (sb[0], int(sb[1]))
     hash = cmdline[4]
     passport_id = cmdline[5]
     display_name = url_codec.decode(cmdline[6])
     try:
         chat_ = chat.Chat(self, server, hash, passport_id, display_name, session_id)
     except Error, e:
         if e.code == 1:  # connection closed
             return
         raise e
Exemplo n.º 18
0
 def __process_rng(self, buf):
     cmdline = split(buf)
     session_id = cmdline[1]
     sb = split(cmdline[2], ':')
     server = (sb[0], int(sb[1]))
     hash = cmdline[4]
     passport_id = cmdline[5]
     display_name = url_codec.decode(cmdline[6])
     try:
         chat_ = chat.Chat(self, server, hash, passport_id, display_name,
                           session_id)
     except Error, e:
         if e.code == 1:  # connection closed
             return
         raise e
Exemplo n.º 19
0
    def __handshake(self, server, username, password):
        conn = self._connect(server)
        try:
            ver = Command("VER", self.transaction_id, ("MSNP8", "CVR0"))
            resp = self._sync_command(ver, conn)
            if resp.cmd != "VER" or resp.args[0] == "0":
                raise Error(0, "Bad response for VER command.")

            cvr = Command(
                "CVR",
                self.transaction_id,
                ("0x0409", "win", "4.10", "i386", "MSNMSGR", "6.0.0602", "MSMSGS ", username),
            )
            resp = self._sync_command(cvr, conn)
            if resp.cmd != "CVR":
                raise Error(0, "Bad response for CVR command.")

            usr = Command("USR", self.transaction_id, ("TWN", "I", username))
            resp = self._sync_command(usr, conn)
            if resp.cmd != "USR" and resp.cmd != "XFR":
                raise Error(0, "Bad response for USR command.")

            # for dispatch server, response is ver, cvr, xfr; for notification
            # server, it is ver, cvr, usr (or same as dispatch server, in some
            # cases)

            if resp.cmd == "XFR":
                return split(resp.args[1], ":", 1)
            elif resp.cmd == "USR":
                twn_string = resp.args[2]

                ticket = self.__get_twn_ticket(twn_string, username, password)

                usr = Command("USR", self.transaction_id, ("TWN", "S", ticket))
                resp = self._sync_command(usr, conn)
                if resp.cmd != "USR":
                    raise Error(int(resp.cmd), protocol.errors[resp.cmd])
                elif resp.args[0] != "OK":
                    raise Error(0, "Bad response for USR command.")

                self.passport_id = resp.args[1]
                self.display_name = url_codec.decode(resp.args[2])
                self.logged_in = 1
        finally:
            if not self.logged_in:
                conn.break_()
            else:
                self.conn = conn
Exemplo n.º 20
0
    def __handshake(self, server, username, password):
        conn = self._connect(server)
        try:
            ver = Command('VER', self.transaction_id, ('MSNP8', 'CVR0'))
            resp = self._sync_command(ver, conn)
            if resp.cmd != 'VER' or resp.args[0] == '0':
                raise Error(0, 'Bad response for VER command.')

            cvr = Command('CVR', self.transaction_id,
                          ('0x0409', 'win', '4.10', 'i386', 'MSNMSGR',
                           '6.0.0602', 'MSMSGS ', username))
            resp = self._sync_command(cvr, conn)
            if resp.cmd != 'CVR':
                raise Error(0, 'Bad response for CVR command.')

            usr = Command('USR', self.transaction_id, ('TWN', 'I', username))
            resp = self._sync_command(usr, conn)
            if resp.cmd != 'USR' and resp.cmd != 'XFR':
                raise Error(0, 'Bad response for USR command.')

            # for dispatch server, response is ver, cvr, xfr; for notification
            # server, it is ver, cvr, usr (or same as dispatch server, in some
            # cases)

            if resp.cmd == 'XFR':
                return split(resp.args[1], ':', 1)
            elif resp.cmd == 'USR':
                twn_string = resp.args[2]

                ticket = self.__get_twn_ticket(twn_string, username, password)

                usr = Command('USR', self.transaction_id, ('TWN', 'S', ticket))
                resp = self._sync_command(usr, conn)
                if resp.cmd != 'USR':
                    raise Error(int(resp.cmd), protocol.errors[resp.cmd])
                elif resp.args[0] != 'OK':
                    raise Error(0, 'Bad response for USR command.')

                self.passport_id = resp.args[1]
                self.display_name = url_codec.decode(resp.args[2])
                self.logged_in = 1
        finally:
            if not self.logged_in:
                conn.break_()
            else:
                self.conn = conn
Exemplo n.º 21
0
    def __handshake(self, server, username, password):
        conn = self._connect(server)
        try:
            ver = Command('VER', self.transaction_id, ('MSNP8', 'CVR0'))
            resp = self._sync_command(ver, conn)
            if resp.cmd != 'VER' or resp.args[0] == '0':
                raise Error(0, 'Bad response for VER command.')

            cvr = Command('CVR', self.transaction_id,
                ('0x0409', 'win', '4.10', 'i386', 'MSNMSGR', '6.0.0602',
                'MSMSGS ', username))
            resp = self._sync_command(cvr, conn)
            if resp.cmd != 'CVR':
                raise Error(0, 'Bad response for CVR command.')

            usr = Command('USR', self.transaction_id, ('TWN', 'I', username))
            resp = self._sync_command(usr, conn)
            if resp.cmd != 'USR' and resp.cmd != 'XFR':
                raise Error(0, 'Bad response for USR command.')

            # for dispatch server, response is ver, cvr, xfr; for notification
            # server, it is ver, cvr, usr (or same as dispatch server, in some
            # cases)

            if resp.cmd == 'XFR':
                return split(resp.args[1], ':', 1)
            elif resp.cmd == 'USR':
                twn_string = resp.args[2]

                ticket = self.__get_twn_ticket(twn_string, username, password)

                usr = Command('USR', self.transaction_id, ('TWN', 'S', ticket))
                resp = self._sync_command(usr, conn)
                if resp.cmd != 'USR':
                    raise Error(int(resp.cmd), protocol.errors[resp.cmd])
                elif resp.args[0] != 'OK':
                    raise Error(0, 'Bad response for USR command.')

                self.passport_id = resp.args[1]
                self.display_name = url_codec.decode(resp.args[2])
                self.logged_in = 1
        finally:
            if not self.logged_in:
                conn.break_()
            else:
                self.conn = conn
Exemplo n.º 22
0
    def __init__(self, session, server, hash, passport_id, display_name,
        session_id = None, invitee = None):

        _Session.__init__(self, ChatCallbacks())

        self.session = session
        self.hash = hash
        self.passport_id = passport_id
        self.display_name = display_name
        self.session_id = session_id
        self.transaction_id = 1
        self.initial_members = []

        self.http_proxy = session.http_proxy
        conn = self.conn = self._connect(server)

        if passport_id != session.passport_id:  # invited to chat
            ans = Command('ANS', self.transaction_id,
                (session.passport_id, hash, session_id))
            self._send_cmd(ans, conn)

            while 1:
                resp = self._receive_cmd(conn)
                if resp.cmd == 'ANS':
                    break
                elif resp.cmd != 'IRO':
                    raise Error(int(resp.cmd), protocol.errors[resp.cmd])
                self.initial_members.append((resp.args[2],
                    url_codec.decode(resp.args[3])))

        else:  # hosting chat
            usr = Command('USR', self.transaction_id,
                (passport_id, hash))
            resp = self._sync_command(usr, conn)
            if resp.cmd != 'USR':
                raise Error(int(resp.cmd), protocol.errors[resp.cmd])

            cal = Command('CAL', self.transaction_id, (invitee,))
            resp = self._sync_command(cal, conn)
            if resp.cmd != 'CAL':
                raise Error(int(resp.cmd), protocol.errors[resp.cmd])
            self.session_id = resp.args[1]
Exemplo n.º 23
0
    def __process_lst(self, command):
        from protocol import list_flags

        passport_id = command.args[0]
        display_name = url_codec.decode(command.args[1])
        list_ = int(command.args[2])
        group_id = []

        if list_ & list_flags[Lists.FORWARD]:
            group_id = [int(i) for i in split(command.args[3], ',')]

        groups = None
        if len(group_id):
            groups = [self.friend_list.groups[g_id] for g_id in group_id]

        friend = Friend(passport_id, display_name, groups=groups)
        for f in list_flags.keys():
            if list_ & list_flags[f]:
                self.friend_list.lists[f][passport_id] = friend

        if self.friend_list.temp_iln.has_key(passport_id):
            friend.state = self.friend_list.temp_iln[passport_id]

        self.__friend_list_updated()
Exemplo n.º 24
0
    def __process_lst(self, command):
        from protocol import list_flags

        passport_id  = command.args[0]
        display_name = url_codec.decode(command.args[1])
        list_        = int(command.args[2])
        group_id     = []

        if list_ & list_flags[Lists.FORWARD]:
            group_id = [int(i) for i in split(command.args[3], ',')]

        groups = None
        if len(group_id):
            groups = [self.friend_list.groups[g_id] for g_id in group_id]

        friend = Friend(passport_id, display_name, groups = groups)
        for f in list_flags.keys():
            if list_ & list_flags[f]:
                self.friend_list.lists[f][passport_id] = friend

        if self.friend_list.temp_iln.has_key(passport_id):
            friend.state = self.friend_list.temp_iln[passport_id]

        self.__friend_list_updated()
Exemplo n.º 25
0
 def __process_joi(self, buf):
     joi = split(buf)
     self.callbacks.friend_joined(joi[1], url_codec.decode(joi[2]))
Exemplo n.º 26
0
 def __process_joi(self, buf):
     joi = split(buf)
     self.callbacks.friend_joined(joi[1], url_codec.decode(joi[2]))
Exemplo n.º 27
0
 def parse(self, str):
     s = split(str)
     self.cmd = s[0]
     self.passport_id = s[1]
     self.display_name = url_codec.decode(s[2])
     self.msg_len = int(s[3])
Exemplo n.º 28
0
 def parse(self, str):
     s = split(str)
     self.cmd = s[0]
     self.passport_id = s[1]
     self.display_name = url_codec.decode(s[2])
     self.msg_len = int(s[3])