xKIChat.py error

Announcements and discussion regarding any projects related to Cyan Worlds' Plasma Engine including (but not limited to) CyanWorlds.com Engine, Drizzle, OfflineKI, PyPRP, and libHSPlasma.
Post Reply
User avatar
Scarabee
Posts: 30
Joined: Wed Sep 08, 2010 1:55 pm
MOULa KI#: 19032
Contact:

xKIChat.py error

Post by Scarabee »

Good evening.

I'm using the latest moul-scripts forked from H-uru/moul-scripts with my bots for Magic Worlds and the FMT.

I found a mistake in the file xKIChat.py. Here is an excerpt of Python.log:

(08/16 16:44:18) KIHandler - Traceback (most recent call last):
(08/16 16:44:18) File ".\python\ki\__init__.py", line 1279, in OnRTChat
(08/16 16:44:18) self.chatMgr.AddChatLine(player, messagemodif, cFlags, forceKI=not self.sawTheKIAtLeastOnce)
(08/16 16:44:18) File ".\python\ki\xKIChat.py", line 560, in AddChatLine
(08/16 16:44:18) chatHeaderFormatted = U"{}{}{}:".format(pretext, separator, unicode(player.getPlayerName()))
(08/16 16:44:18) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 27: ordinal not in range(128)

The code in xKIChat.py, line 560 is:

Code: Select all

        if player is not None:
            separator = "" if pretext.endswith(" ") else " "
            chatHeaderFormatted = U"{}{}{}:".format(pretext, separator, unicode(player.getPlayerName()))
            chatMessageFormatted = U" {}".format(message)
This occurs when a player plays in a foreign language (the player plays in German language) and he is AFK.
As you know, when you send him a private message, the program returns the message:
in English : (I'm on the surface, be back in a minute) ..........> from the file \dat\KIEnglish.loc
in German : (Ich bin an der Oberfläche, komme gleich zurück) ...........> from the file \dat\KIGerman.loc

You can see special letters : ä and ü which causes the error message quoted above.

I modified the script as follows to prevent the crash of my bots:

Code: Select all

        if player is not None:
            separator = "" if pretext.endswith(" ") else " "
            try:
                chatHeaderFormatted = U"{}{}{}:".format(pretext, separator, unicode(player.getPlayerName()))
            except:
                chatHeaderFormatted = " "
            chatMessageFormatted = U" {}".format(message)
But I think there must be a better solution to this problem.

:)
Image
Mister Magic in Moula 1255010
User avatar
Scarabee
Posts: 30
Joined: Wed Sep 08, 2010 1:55 pm
MOULa KI#: 19032
Contact:

Re: xKIChat.py error

Post by Scarabee »

I think a better solution is to add "utf8" on argument in KIChat.py :

Code: Select all

chatHeaderFormatted = U"{}{}{}:".format(pretext, separator, unicode(player.getPlayerName(), "utf8"))
It seems working with my bots :)
Image
Mister Magic in Moula 1255010
User avatar
Scarabee
Posts: 30
Joined: Wed Sep 08, 2010 1:55 pm
MOULa KI#: 19032
Contact:

Re: xKIChat.py error

Post by Scarabee »

I'll wait the merger's demand of zrax in Huru-master to be sure it's ok before recompile a PLClient with these changes.

"This renames PyUnicode_FromStringEx to PyUnicode_FromPlString for consistency with the PyString_FromPlString macro (and because it's a more descriptive name anyway), and adds a unicode version of ptPlayer.getPlayerName."

thanks
Image
Mister Magic in Moula 1255010
User avatar
Scarabee
Posts: 30
Joined: Wed Sep 08, 2010 1:55 pm
MOULa KI#: 19032
Contact:

Re: xKIChat.py error

Post by Scarabee »

It's perfect !
Everything works fine. I compiled a new client and uses it with my bots. I tested with the French language and everything works fine now! :)
Image
Mister Magic in Moula 1255010
Post Reply

Return to “Plasma Development”