th3-z / kf2-magicked-admin

:spider: Mutator-free management, statistics, and in-game bot for ranked Killing Floor 2 servers
https://kf2-ma.th3-z.xyz
MIT License
32 stars 7 forks source link

[BUG] Encoding errors #157

Closed th3-z closed 4 years ago

th3-z commented 4 years ago

Describe the bug There is a crash seemingly related to players with unusual character in their name. Unconfirmed in survival mode. This is known to occur in the following situations.

This is a confirmed issue that I have been unable to reproduce, information and crash reports needed.

Server

Logs Example of the logger error follows. Greeter error missing.

--- Logging error ---
Traceback (most recent call last):
  File "C:\Python\lib\logging\__init__.py", line 989, in emit
  File "C:\Python\lib\encodings\cp1252.py", line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode character '\x86' in position 34: character maps to <undefined>
Call stack:
  File "C:\Python\lib\threading.py", line 884, in _bootstrap
  File "C:\Python\lib\threading.py", line 916, in _bootstrap_inner
  File "C:\Users\wabbi\Desktop\kf2-magicked-admin\magicked_admin\server\game_tracker.py", line 32, in run
  File "C:\Users\wabbi\Desktop\kf2-magicked-admin\magicked_admin\server\game_tracker.py", line 41, in __poll
  File "C:\Users\wabbi\Desktop\kf2-magicked-admin\magicked_admin\server\game_tracker.py", line 148, in __update_players
  File "C:\Users\wabbi\Desktop\kf2-magicked-admin\magicked_admin\server\server.py", line 178, in event_player_join
  File "C:\Users\wabbi\Desktop\kf2-magicked-admin\magicked_admin\utils\__init__.py", line 88, in info
  File "C:\Python\lib\logging\__init__.py", line 1301, in info
  File "C:\Python\lib\logging\__init__.py", line 1437, in _log
  File "C:\Python\lib\logging\__init__.py", line 1447, in handle
  File "C:\Python\lib\logging\__init__.py", line 1509, in callHandlers
  File "C:\Python\lib\logging\__init__.py", line 858, in handle
  File "C:\Python\lib\logging\handlers.py", line 482, in emit
  File "C:\Python\lib\logging\__init__.py", line 1065, in emit
  File "C:\Python\lib\logging\__init__.py", line 993, in emit
Message: 'Player \x86Ðëë?\x86 joined server_one from Unknown (SteamID: 76561198000693531)'
Arguments: ()

\86 is https://www.fileformat.info/info/unicode/char/0086/index.htm Example:

print(u"\u0086".encode("cp1252"))
th3-z commented 4 years ago

Examples so far: https://steamidfinder.com/lookup/76561198800253299/ https://steamidfinder.com/lookup/76561198364535361/ https://steamidfinder.com/lookup/76561198074358300/ https://steamidfinder.com/lookup/76561198253109260/ https://steamidfinder.com/lookup/76561198349593300/ https://steamid.io/lookup/76561198399141515

th3-z commented 4 years ago

Reproduced one of the reported crashes. It isn't an encoding issue, it is caused by name collisions. I think the logger encoding needs changing for the exception above.

th3-z commented 4 years ago
import logging
import logging.handlers

logger = logging.getLogger()
handler = logging.handlers.WatchedFileHandler(
    "./log.log", encoding="cp1252"
)
formatter = logging.Formatter(
    "[%(asctime)s %(levelname)s] %(message)s",
    "%Y-%m-%d %H:%M:%S"
)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

logger.info(u"\u0086")
th3-z commented 4 years ago

fixed in branch 0.1.6