Example #1
0
def get_chat_packet(context, packet):
    """
    :type context: ShipProxy.ShipProxy
    """
    try:
        if context.psoClient and context.playerId and data.clients.connectedClients[
                context.playerId].preferences.get_preference('translate_out'):
            player_id = struct.unpack_from("<I", packet, 0x8)[0]
            if player_id != 0:  # ???
                return None
            channel_id = struct.unpack_from("<I", packet, 0x14)[0]
            if channel_id == 2:
                return packet  # skip team chat
            message = packet[0x1C:].decode('utf-16').rstrip("\0")
            cmd, msg = split_cmd_msg(message)
            if not msg:
                return packet  # Command
            d = threads.deferToThread(generate_translated_message, player_id,
                                      channel_id, cmd, msg, "ja", "en")
            d.addCallback(context.peer.send_crypto_packet)
            return None
    except KeyError:
        return packet
    if context.peer.psoClient and context.peer.playerId in data.clients.connectedClients:
        user_prefs = data.clients.connectedClients[
            context.peer.playerId].preferences
        if not user_prefs.get_preference('translate_chat'):
            return packet
        player_id = struct.unpack_from("<I", packet, 0x8)[0]
        if player_id == 0:  # We sent it
            return packet
        channel_id = struct.unpack_from("<I", packet, 0x14)[0]
        message = packet[0x1C:].decode('utf-16').rstrip("\0")
        cmd, msg = split_cmd_msg(message)
        if not msg:
            return packet  # Command
        japanese = False
        for char in msg:
            char_script = script(unicode(char))
            if char_script != 'Latin' and char_script != 'Common':
                japanese = True
                break
        if not japanese:
            return packet
        d = threads.deferToThread(generate_translated_message, player_id,
                                  channel_id, cmd, msg, "en", "ja")
        d.addCallback(context.peer.send_crypto_packet)
        return None
    return packet
Example #2
0
def get_chat_packet(context, packet):
    """
    :type context: ShipProxy.ShipProxy
    """
    try:
        if context.psoClient and context.playerId and data.clients.connectedClients[context.playerId].preferences.get_preference('translate_out'):
            player_id = struct.unpack_from("<I", packet, 0x8)[0]
            if player_id != 0:  # ???
                return None
            channel_id = struct.unpack_from("<I", packet, 0x14)[0]
            if channel_id == 2:
                return packet  # skip team chat
            message = packet[0x1C:].decode('utf-16').rstrip("\0")
            cmd, msg = split_cmd_msg(message)
            if not msg:
                return packet  # Command
            d = threads.deferToThread(generate_translated_message, player_id, channel_id, cmd, msg, "ja", "en")
            d.addCallback(context.peer.send_crypto_packet)
            return None
    except KeyError:
        return packet
    if context.peer.psoClient and context.peer.playerId in data.clients.connectedClients:
        user_prefs = data.clients.connectedClients[context.peer.playerId].preferences
        if not user_prefs.get_preference('translate_chat'):
            return packet
        player_id = struct.unpack_from("<I", packet, 0x8)[0]
        if player_id == 0:  # We sent it
            return packet
        channel_id = struct.unpack_from("<I", packet, 0x14)[0]
        message = packet[0x1C:].decode('utf-16').rstrip("\0")
        cmd, msg = split_cmd_msg(message)
        if not msg:
            return packet  # Command
        japanese = False
        for char in msg:
            char_script = script(unicode(char))
            if char_script != 'Latin' and char_script != 'Common':
                japanese = True
                break
        if not japanese:
            return packet
        d = threads.deferToThread(generate_translated_message, player_id, channel_id, cmd, msg, "en", "ja")
        d.addCallback(context.peer.send_crypto_packet)
        return None
    return packet
Example #3
0
def get_team_chat_packet(context, packet):
    """
    :type context: ShipProxy.ShipProxy
    """
    try:
        if context.psoClient and context.playerId and data.clients.connectedClients[
                context.playerId].preferences.get_preference('translate_out'):
            player_id = struct.unpack_from("<I", packet, 0x8)[0]
            if player_id != 0:  # ???
                return None

            pis = 0x8  # read the playerid
            player_id = struct.unpack_from("<I", packet, pis)[0]
            pis += 0x14  # let skip to the first unicode string len

            wlen = decode_string_utf16_len(
                struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
            wlen += 1
            if (wlen % 2) == 1:
                wlen += 1

            pis += 0x04  # skipping to start of utf-16 string
            account = packet[pis:pis +
                             (wlen * 2)].decode('utf-16').rstrip("\0")
            pis += (wlen * 2)  # skipping to the end of utf-16 string

            wlen = decode_string_utf16_len(
                struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
            wlen += 1
            if (wlen % 2) == 1:
                wlen += 1

            pis += 0x04  # skipping to start of utf-16 string
            charname = packet[pis:pis +
                              (wlen * 2)].decode('utf-16').rstrip("\0")
            pis += (wlen * 2)  # skipping to the end of utf-16 string

            wlen = decode_string_utf16_len(
                struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
            wlen += 1
            if (wlen % 2) == 1:
                wlen += 1

            pis += 0x04  # skipping to start of utf-16 string
            message = packet[pis:pis +
                             (wlen * 2)].decode('utf-16').rstrip("\0")
            pis += (wlen * 2)  # skipping to the end of utf-16 string

            cmd, msg = split_cmd_msg(message)

            if not msg:
                return packet  # Command

            d = threads.deferToThread(generate_translated_team_message,
                                      player_id, account, charname, cmd, msg,
                                      "ja", "en")
            d.addCallback(context.peer.send_crypto_packet)
            return None
    except KeyError:
        return packet
    if context.peer.psoClient and context.peer.playerId in data.clients.connectedClients:
        user_prefs = data.clients.connectedClients[
            context.peer.playerId].preferences
        if not user_prefs.get_preference('translate_chat'):
            return packet

        pis = 0x8  # read the playerid
        player_id = struct.unpack_from("<I", packet, 0x8)[0]
        if player_id == 0:  # We sent it
            return packet
        pis += 0x14  # let skip to the first unicode string len

        wlen = decode_string_utf16_len(
            struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
        wlen += 1
        if (wlen % 2) == 1:
            wlen += 1

        pis += 0x04  # skipping to start of utf-16 string
        account = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
        pis += (wlen * 2)  # skipping to the end of utf-16 string

        wlen = decode_string_utf16_len(
            struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
        wlen += 1
        if (wlen % 2) == 1:
            wlen += 1

        pis += 0x04  # skipping to start of utf-16 string
        charname = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
        pis += (wlen * 2)  # skipping to the end of utf-16 string

        wlen = decode_string_utf16_len(
            struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
        wlen += 1
        if (wlen % 2) == 1:
            wlen += 1

        pis += 0x04  # skipping to start of utf-16 string
        message = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
        pis += (wlen * 2)  # skipping to the end of utf-16 string

        cmd, msg = split_cmd_msg(message)

        if not msg:
            return packet  # Command

        japanese = False
        for char in msg:
            char_script = script(unicode(char))
            if char_script != 'Latin' and char_script != 'Common':
                japanese = True
                break
        if not japanese:
            return packet
        d = threads.deferToThread(generate_translated_team_message, player_id,
                                  account, charname, cmd, msg, "en", "ja")
        d.addCallback(context.peer.send_crypto_packet)
        return None
    return packet
Example #4
0
#!/bin/python


from PSO2DataTools import split_cmd_msg

if __name__ == "__main__":
    print (split_cmd_msg("/mn16 doom keen hugs"))  # 0 extra swtich
    print (split_cmd_msg("/mn16  "))  # command with no text
    print (split_cmd_msg("/la sit1 doom keen hugs"))  # 1 extra swtich
    print (split_cmd_msg("/ci0 doom keen hugs"))  # up to 4
    print (split_cmd_msg("/ci0 6 t6 nw s99 doom keen hugs"))  # up to 4
    print (split_cmd_msg("/ci0 6 t6 s99 doom keen hugs"))  # 3?
    print (split_cmd_msg("/ci0 6 t6 s99 /doom/keen/hugs"))  # 3 with bad commands
    print (split_cmd_msg(u"doom keen hugs"))  # no commands
Example #5
0
#!/bin/python


from PSO2DataTools import split_cmd_msg

if __name__ == "__main__":
    print (split_cmd_msg("/mn16 doom keen hugs"))  # 0 extra swtich
    print (split_cmd_msg("/mn16  "))  # command with no text
    print (split_cmd_msg("/la sit1 doom keen hugs"))  # 1 extra swtich
    print (split_cmd_msg("/ci "))  # error?
    print (split_cmd_msg("/ci0"))  # blank?
    print (split_cmd_msg("/ci0 doom keen hugs"))  # up to 4
    print (split_cmd_msg("/ci0 6 t6 nw s99 doom keen hugs"))  # up to 4
    print (split_cmd_msg("/ci0 6 t6 s99 doom keen hugs"))  # 3?
    print (split_cmd_msg("/ci0 6 t6 s99 /doom/keen/hugs"))  # 3 with bad commands
    print (split_cmd_msg("/ci1 3 hi"))  # Meebo@IRC
    print (split_cmd_msg("/ci7 2 /la dance22"))  # wsky@IRC
    print (split_cmd_msg(u"doom keen hugs"))  # no commands
Example #6
0
def get_team_chat_packet(context, packet):
    """
    :type context: ShipProxy.ShipProxy
    """
    try:
        if context.psoClient and context.playerId and data.clients.connectedClients[context.playerId].preferences.get_preference('translate_out'):
            player_id = struct.unpack_from("<I", packet, 0x8)[0]
            if player_id != 0:  # ???
                return None

            pis = 0x8  # read the playerid
            player_id = struct.unpack_from("<I", packet, pis)[0]
            pis += 0x14  # let skip to the first unicode string len

            wlen = decode_string_utf16_len(struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
            wlen += 1
            if (wlen % 2) == 1:
                wlen += 1

            pis += 0x04  # skipping to start of utf-16 string
            account = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
            pis += (wlen * 2)  # skipping to the end of utf-16 string

            wlen = decode_string_utf16_len(struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
            wlen += 1
            if (wlen % 2) == 1:
                wlen += 1

            pis += 0x04  # skipping to start of utf-16 string
            charname = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
            pis += (wlen * 2)  # skipping to the end of utf-16 string

            wlen = decode_string_utf16_len(struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
            wlen += 1
            if (wlen % 2) == 1:
                wlen += 1

            pis += 0x04  # skipping to start of utf-16 string
            message = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
            pis += (wlen * 2)  # skipping to the end of utf-16 string

            cmd, msg = split_cmd_msg(message)

            if not msg:
                return packet  # Command

            d = threads.deferToThread(generate_translated_team_message, player_id, account, charname, cmd, msg, "ja", "en")
            d.addCallback(context.peer.send_crypto_packet)
            return None
    except KeyError:
        return packet
    if context.peer.psoClient and context.peer.playerId in data.clients.connectedClients:
        user_prefs = data.clients.connectedClients[context.peer.playerId].preferences
        if not user_prefs.get_preference('translate_chat'):
            return packet

        pis = 0x8  # read the playerid
        player_id = struct.unpack_from("<I", packet, 0x8)[0]
        if player_id == 0:  # We sent it
            return packet
        pis += 0x14  # let skip to the first unicode string len

        wlen = decode_string_utf16_len(struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
        wlen += 1
        if (wlen % 2) == 1:
            wlen += 1

        pis += 0x04  # skipping to start of utf-16 string
        account = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
        pis += (wlen * 2)  # skipping to the end of utf-16 string

        wlen = decode_string_utf16_len(struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
        wlen += 1
        if (wlen % 2) == 1:
            wlen += 1

        pis += 0x04  # skipping to start of utf-16 string
        charname = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
        pis += (wlen * 2)  # skipping to the end of utf-16 string

        wlen = decode_string_utf16_len(struct.unpack_from("<I", packet, pis)[0], 0x7ED7, 0x41)
        wlen += 1
        if (wlen % 2) == 1:
            wlen += 1

        pis += 0x04  # skipping to start of utf-16 string
        message = packet[pis:pis + (wlen * 2)].decode('utf-16').rstrip("\0")
        pis += (wlen * 2)  # skipping to the end of utf-16 string

        cmd, msg = split_cmd_msg(message)

        if not msg:
            return packet  # Command

        japanese = False
        for char in msg:
            char_script = script(unicode(char))
            if char_script != 'Latin' and char_script != 'Common':
                japanese = True
                break
        if not japanese:
            return packet
        d = threads.deferToThread(generate_translated_team_message, player_id, account, charname, cmd, msg, "en", "ja")
        d.addCallback(context.peer.send_crypto_packet)
        return None
    return packet