def _parse_message(self, message): emsg_id, = struct.unpack_from("<I", message) emsg = EMsg(clear_proto_bit(emsg_id)) if not self.connected and emsg != EMsg.ClientLogOnResponse: return if emsg in ( EMsg.ChannelEncryptRequest, EMsg.ChannelEncryptResponse, EMsg.ChannelEncryptResult, ): msg = Msg(emsg, message) else: try: if is_proto(emsg_id): msg = MsgProto(emsg, message) else: msg = Msg(emsg, message, extended=True) except Exception as e: self._LOG.fatal( "Failed to deserialize message: %s (is_proto: %s)", str(emsg), is_proto(emsg_id)) self._LOG.exception(e) if self.verbose_debug: self._LOG.debug("Incoming: %s\n%s" % (repr(msg), str(msg))) else: self._LOG.debug("Incoming: %s", repr(msg)) self.emit(emsg, msg)
def change_password(self, password, new_password, email_code): """Change account's password :param password: current account password :type password: :class:`str` :param new_password: new account password :type new_password: :class:`str` :param email_code: confirmation code from email :type email_code: :class:`str` :return: result :rtype: :class:`.EResult` .. note:: First request change mail via :meth:`request_password_change_mail()` to get the email code """ message = Msg(EMsg.ClientPasswordChange3, extended=True) message.body.password = password message.body.new_password = new_password message.body.code = email_code resp = self.send_job_and_wait(message, timeout=10) if resp is None: return EResult.Timeout else: return EResult(resp.eresult)
def send_group_msg(self, chatroomid, msg): m = Msg(EMsg.ClientChatMsg, extended=True) m.body.steamIdChatter = self.client.steam_id.as_64 m.body.steamIdChatRoom = chatroomid m.body.ChatMsgType = 1 m.body.text = msg self.client.send(m)
def join_chat(self, chatroomid): """Joins a group chat given its id. """ msg = Msg(EMsg.ClientJoinChat, extended=True) msg.body.steamIdChat = chatroomid self.client.send(msg) self.chats[chatroomid] = []
def request_validation_mail(self): """Request validation email :return: result :rtype: :class:`.EResult` """ message = Msg(EMsg.ClientRequestValidationMail, extended=True) resp = self.send_job_and_wait(message, timeout=10) if resp is None: return EResult.Timeout else: return EResult(resp.eresult)
def request_password_change_mail(self, password): """Request password change mail :param password: current account password :type password: :class:`str` :return: result :rtype: :class:`.EResult` """ message = Msg(EMsg.ClientRequestChangeMail, extended=True) message.body.password = password resp = self.send_job_and_wait(message, timeout=10) if resp is None: return EResult.Timeout else: return EResult(resp.eresult)
def __handle_encrypt_request(self, req): self._LOG.debug("Securing channel") try: if req.body.protocolVersion != 1: raise RuntimeError("Unsupported protocol version") if req.body.universe != EUniverse.Public: raise RuntimeError("Unsupported universe") except RuntimeError as e: self._LOG.exception(e) gevent.spawn(self.disconnect) return resp = Msg(EMsg.ChannelEncryptResponse) challenge = req.body.challenge key, resp.body.key = crypto.generate_session_key(challenge) resp.body.crc = binascii.crc32(resp.body.key) & 0xffffffff self.send(resp) result = self.wait_event(EMsg.ChannelEncryptResult, timeout=5) if result is None: self.cm_servers.mark_bad(self.current_server_addr) gevent.spawn(self.disconnect) return eresult = result[0].body.eresult if eresult != EResult.OK: self._LOG.error("Failed to secure channel: %s" % eresult) gevent.spawn(self.disconnect) return self.channel_key = key if challenge: self._LOG.debug("Channel secured") self.channel_hmac = key[:16] else: self._LOG.debug("Channel secured (legacy mode)") self.channel_secured = True self.emit(self.EVENT_CHANNEL_SECURED)