Exemple #1
0
 def get_account(account_name):
     """ Return the account from the database if it exists, or None. """
     try:
         return Account.get(Account.name == account_name)
     except Account.DoesNotExist:
         LOG.warning("No account with that name: " + account_name)
         return None
Exemple #2
0
    def process(self):
        guid = self.PACKET_BIN.unpack(self.packet)[0]
        character_data = self._get_checked_character(guid)
        if character_data is None:
            LOG.warning("Account {} tried to illegally use character {}".format(
                self.conn.account.name, guid
            ))
            return self.conn.MAIN_ERROR_STATE, None

        # Now that we have the character data, spawn a new player object.
        self.conn.set_player(character_data)

        # Finally, send the packets necessary to let the client get in world.
        # Only the tutorial flags and update object packets are really necessary
        # to let the client show the world.
        self.conn.send_packet(self._get_verify_login_packet())
        self.conn.send_packet(self._get_account_data_md5_packet())
        self.conn.send_packet(self._get_tutorial_flags_packet())
        self.conn.send_packet(self._get_update_object_packet())
        # self.conn.send_packet(self._get_initial_spells_packet())

        self._get_near_objects()
        self._notify_near_players()

        return WorldConnectionState.IN_WORLD, None
Exemple #3
0
 def delete_session(account):
     """ Delete the session assiociated with that account. """
     try:
         session = AccountSession.get(AccountSession.account == account)
         session.delete_instance()
     except AccountSession.DoesNotExist:
         LOG.warning("Tried to delete an non-existing session.")
Exemple #4
0
    def remove_player(self, guid):
        """ Remove the player from the object list and save its data. """
        player = self.get_player(guid)
        if player is None:
            LOG.warning("Tried to remove a non-existing player.")
            return

        self._remove_object(guid)
        self.save_player(player)
Exemple #5
0
    def _slice_packet_opcode(self):
        """ Cut the packet opcode from content. """
        opcode_bytes = self.content[:4]
        opcode_value = int.from_bytes(opcode_bytes, "little")
        self.content = self.content[4:]

        try:
            self.opcode = OpCode(opcode_value)
        except ValueError:
            LOG.warning("Unknown opcode {:X}".format(opcode_value))
Exemple #6
0
    def _generate_local_proof(self):
        account_name = self.conn.account.name
        session = AccountSessionManager.get_session(account_name)
        if session is None:
            LOG.warning("Reconnection proof: account wasn't logged in!")
            return

        challenge = self.conn.recon_challenge
        to_hash = ( account_name.encode("ascii") + self.proof_data +
                    challenge + session.session_key_as_bytes )
        self.local_proof = sha1(to_hash)
Exemple #7
0
 def process(self):
     self._parse_packet(self.packet)
     self._generate_local_proof()
     if self.client_proof == self.local_proof:
         LOG.debug("Reconnection: correct proof")
         response = self._get_success_response()
         return LoginConnectionState.RECON_PROOF, response
     else:
         LOG.warning("Reconnection: wrong proof!")
         response = self._get_failure_response()
         return LoginConnectionState.CLOSED, response
Exemple #8
0
 def _process_reconnection(self):
     session = AccountSessionManager.get_session(self.account_name)
     if session is not None:
         LOG.debug("Reconnection: account was logged in.")
         self.conn.account = ReconChallenge._get_session_account(session)
         self.conn.recon_challenge = os.urandom(16)
         response = self._get_success_response()
         return LoginConnectionState.RECON_CHALL, response
     else:
         LOG.warning("Reconnection: account wasn't logged in!")
         response = self._get_failure_response()
         return LoginConnectionState.CLOSED, response
Exemple #9
0
    def _get_more_data(self):
        some_data = None
        try:
            some_data = self.socket.recv(1024)
        except ConnectionError as exc:
            LOG.warning("WorldPacketReceiver: ConnectionError: " + str(exc))
            traceback.print_tb(exc.__traceback__)

        if not some_data:
            raise WorldPacketReceiverException()

        self.packet_buf += some_data
Exemple #10
0
 def _process_account(self):
     """ Check if the account received can log to the server. """
     account = AccountManager.get_account(self.account_name)
     if account is not None and account.is_valid():
         self.conn.account = account
         self.conn.srp.generate_server_ephemeral(account.srp_verifier_as_int)
         response = self._get_success_response()
         return LoginConnectionState.SENT_CHALL, response
     else:
         LOG.warning("Invalid account {} tried to login".format(
             self.account_name
         ))
         response = self._get_failure_response(account)
         return LoginConnectionState.CLOSED, response
Exemple #11
0
    def process(self):
        self._parse_packet(self.packet)
        LOG.debug("NameQuery: GUID {:X}".format(self.guid))

        object_manager = self.conn.server.object_manager
        unit = object_manager.get_player(self.guid)
        if unit is None:
            LOG.warning("NameQueryHandler: couldn't find player {:X}".format(
                self.guid
            ))
            return None, None

        response = self._get_response_packet(unit)
        return None, response
Exemple #12
0
    def process(self):
        self._parse_packet(self.packet)

        account = self.conn.account
        verifier = account.srp_verifier_as_int
        self.conn.srp.generate_session_key(self.client_ephemeral, verifier)
        self.conn.srp.generate_client_proof(self.client_ephemeral, account)
        local_client_proof = self.conn.srp.client_proof

        if local_client_proof == self.client_proof:
            LOG.debug("Login: authenticated!")
            self.conn.accept_login()
            self.conn.srp.generate_server_proof(self.client_ephemeral)
            response = self._get_success_response()
            return LoginConnectionState.SENT_PROOF, response
        else:
            LOG.warning("Login: wrong proof!")
            response = self._get_failure_response()
            return LoginConnectionState.CLOSED, response
Exemple #13
0
    def process(self):
        self._parse_packet(self.packet)

        # We start by loading the session key because in any case the client
        # expects an encrypted response.
        self._load_session_key()
        if not self.session_key:
            LOG.warning("A client not logged in tried to join world server.")
            return self.conn.MAIN_ERROR_STATE, None

        self._setup_encryption()

        if self.build != int(CONFIG["general"]["build"]):
            LOG.warning("Wrong build tried to auth to world server: {}".format(
                str(self.build)
            ))
            error_code = AuthSessionResponseCode.AUTH_VERSION_MISMATCH
            response = self._get_failure_packet(error_code)
            return self.conn.MAIN_ERROR_STATE, response

        self._generate_server_hash()
        if self.server_hash != self.client_hash:
            LOG.warning("Wrong client hash in world server auth.")
            error_code = AuthSessionResponseCode.AUTH_REJECT
            response = self._get_failure_packet(error_code)
            return self.conn.MAIN_ERROR_STATE, response

        # Once the session cipher is up and the client is fully checked,
        # accept the authentication and move on.
        LOG.debug("World server auth OK.")
        response = self._get_success_packet()
        return WorldConnectionState.AUTH_OK, response