diff --git a/CHANGES.md b/CHANGES.md index a9dacbf..c7c3b0d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,3 +26,4 @@ This release brings some breaking changes - Messages now have a payload property set when the body cannot be parsed - Updated protocol version to 65580 - Added `CDNClient` +- Update `SteamClient` to use new chat mode diff --git a/steam/client/__init__.py b/steam/client/__init__.py index 2a9efdf..3682bcd 100644 --- a/steam/client/__init__.py +++ b/steam/client/__init__.py @@ -54,6 +54,7 @@ class SteamClient(CMClient, BuiltinBase): credential_location = None #: location for sentry username = None #: username when logged on login_key = None #: can be used for subsequent logins (no 2FA code will be required) + chat_mode = 2 #: chat mode (0=old chat, 2=new chat) def __init__(self): CMClient.__init__(self) @@ -533,8 +534,7 @@ class SteamClient(CMClient, BuiltinBase): message.body.client_language = "english" message.body.should_remember_password = True message.body.supports_rate_limit_response = True - message.body.ui_mode = 0 - message.body.chat_mode = 2 + message.body.chat_mode = self.chat_mode if login_id is None: message.body.obfustucated_private_ip = ip_to_int(self.connection.local_address) ^ 0xF00DBAAD diff --git a/steam/client/builtins/user.py b/steam/client/builtins/user.py index d89676b..181e435 100644 --- a/steam/client/builtins/user.py +++ b/steam/client/builtins/user.py @@ -28,12 +28,20 @@ class User(object): self.on(self.EVENT_LOGGED_ON, self.__handle_set_persona) self.on(EMsg.ClientPersonaState, self.__handle_persona_state) self.on(EMsg.ClientFriendMsgIncoming, self.__handle_message_incoming) + self.on("FriendMessagesClient.IncomingMessage#1", self.__handle_message_incoming2) def __handle_message_incoming(self, msg): + # old chat if msg.body.chat_entry_type == EChatEntryType.ChatMsg: user = self.get_user(msg.body.steamid_from) self.emit("chat_message", user, msg.body.message.decode('utf-8')) + def __handle_message_incoming2(self, msg): + # new chat + if msg.body.chat_entry_type == EChatEntryType.ChatMsg: + user = self.get_user(msg.body.steamid_friend) + self.emit("chat_message", user, msg.body.message) + def __handle_disconnect(self): self.user = None self.current_games_played = [] diff --git a/steam/client/user.py b/steam/client/user.py index a708ed4..1847d02 100644 --- a/steam/client/user.py +++ b/steam/client/user.py @@ -112,8 +112,17 @@ class SteamUser(object): :param message: message to send :type message: str """ - self._steam.send(MsgProto(EMsg.ClientFriendMsg), { - 'steamid': self.steam_id, - 'chat_entry_type': EChatEntryType.ChatMsg, - 'message': message.encode('utf8'), - }) + # new chat + if self._steam.chat_mode == 2: + self._steam.send_um("FriendMessages.SendMessage#1", { + 'steamid': self.steam_id, + 'message': message, + 'chat_entry_type': EChatEntryType.ChatMsg, + }) + # old chat + else: + self._steam.send(MsgProto(EMsg.ClientFriendMsg), { + 'steamid': self.steam_id, + 'chat_entry_type': EChatEntryType.ChatMsg, + 'message': message.encode('utf8'), + }) diff --git a/steam/core/msg/__init__.py b/steam/core/msg/__init__.py index feae3a5..ecb0a80 100644 --- a/steam/core/msg/__init__.py +++ b/steam/core/msg/__init__.py @@ -24,6 +24,7 @@ cmsg_lookup_predefined = { # EMsg.ClientEmailChangeResponse4: steammessages_clientserver_2_pb2.CMsgClientEmailChangeResponse, EMsg.ClientLogonGameServer: steammessages_clientserver_login_pb2.CMsgClientLogon, EMsg.ClientCurrentUIMode: steammessages_clientserver_2_pb2.CMsgClientUIMode, + EMsg.ClientChatOfflineMessageNotification: steammessages_clientserver_2_pb2.CMsgClientOfflineMessageNotification, } cmsg_lookup = dict()