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
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
u'Tibetan': [u'р╜Жр╜┤'], u'Ugaritic': [u'ЁРОО', u'', u'', u'', u'', u''], u'Old Italic': [u'ЁРМЦЁРМХЁРМЦ', u'', u'', u'', u'', u''], #Umbrian u'Yi': [u'ъТЙ'], } if __name__ == "__main__": datasorted = sorted(data.keys()) for script in datasorted: print script, output = u'' flag = False for character in data[script]: character = character.encode('utf-8').decode( 'utf-8' ) # Work around for a bug in python2.5 UCS4 build which, when compiling a module treats UTTF-8 encoded characters outside the BMP as surrogate UTF-16 pairs # If we were to compile this module, and then import it and run it, it would work fine without this hack. if character: output += character + u' ' normalized = unicodedata.normalize('NFC', character) for n in normalized: s = unicodescript.script(n) output += s + u' ' if s == script.split(':')[0]: output += 'OK' + u' ' else: output += 'FAILED' + u' ' + n + "(" + unicodescript.script( n) + ")" flag = True if flag: print output else: print 'OK ' + "".join(data[script]).encode('utf-8')
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
u'Tamil': [u'தண்ணீர்', u'', u'', u'', u'', u''], u'Telugu': [u'జము', u'ల'], u'Thaana': [u'ފެ', u'ން'], u'Thai': [u'น้', u'ำ'], u'Tibetan': [u'ཆུ'], u'Ugaritic': [u'𐎎', u'', u'', u'', u'', u''], u'Umbrian': [u'𐌖𐌕𐌖', u'', u'', u'', u'', u''], u'Yi': [u'ꒉ'], } if __name__ == "__main__": datasorted=sorted(data.keys()) for script in datasorted: print "script: ",script, output=u'' ; flag = False for character in data[script]: character = character.encode('utf-8').decode('utf-8') # Work around for a bug in python2.5 UCS4 build which, when compiling a module treats UTTF-8 encoded characters outside the BMP as surrogate UTF-16 pairs # If we were to compile this module, and then import it and run it, it would work fine without this hack. if character: output+= character + u' ' normalized=unicodedata.normalize('NFC', character) for n in normalized: s = unicodescript.script(n) output+= s + u' ' if s == script.split(':')[0]: output+= 'OK' + u' ' else: output+= 'FAILED' + u' ' + n + "(" + unicodescript.script(n) + ")" flag= True if flag: print output else: print 'OK'
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