protected boolean doLogin() {
        this.state = TrekPlayer.WAIT_LOGIN;
        TrekLog.logMessage("User is choosing name...");
        String validChars = " `!@#$%^&*()-=!@#$%^&*()_+[]\\{}|;:'\",./<>?1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String input;
        String shipNameChosen;
        String inputPrompt = "\r\nShip name: ";
        boolean passedCheck;
        boolean inputDone;
        do {
            passedCheck = true;
            shipNameChosen = "";
            inputDone = false;
            sendText(inputPrompt);
            do {
                input = getBlockedInput(true, 60000, false);
                // If input is null, it's probably a socket error. Disconnect.
                if (input == null)
                    return false;
                if (!input.equals("")) {
                    switch (input.charAt(0)) {
                        case 3: // CTRL-C for disconnection.
                            return false;
                        case 13: // Capture enter.
                            inputDone = true;
                            break;
                        default: // Backspace and buffering.
                            if (isValidEraseCharacter(input.charAt(0))) {
                                if (shipNameChosen.length() > 0) {
                                    sendText(TrekAnsi.moveBackwards(1, this) + TrekAnsi.deleteCharacters(1, this));
                                    shipNameChosen = shipNameChosen.substring(0, shipNameChosen.length() - 1);
                                }
                            } else {
                                // limit to valid characters
                                if (validChars.contains(input)) {
                                    sendText(input);
                                    shipNameChosen += input;
                                }
                            }
                            break;
                    }
                }
            }
            while (!inputDone);
            input = shipNameChosen.trim();
            if (input.contains("___ kill ship:")) {
                laggedShipKiller(input);
                buffer = "";
                input = "";
                passedCheck = false;
            } else if (input.length() > 16) {
                sendText("\r\nShip name cannot be greater than 16 characters.\r\n");
                buffer = "";
                input = "";
                passedCheck = false;
            } else if (input.equals("")) {
                sendText("\r\nIllegal ship name.\r\n");
                buffer = "";
                input = "";
                passedCheck = false;
            } else if (TrekServer.shipAlreadyExists(input)) {
                sendText("\r\nShip name already in use.\r\n");
                buffer = "";
                input = "";
                passedCheck = false;
            } else if (input.equals("")) {
                sendText("\r\nPlease enter a ship name.\r\n");
                buffer = "";
                input = "";
                passedCheck = false;
            } else if (input.equalsIgnoreCase("who")) {
                printShipRoster(WHO_NORMAL);
                buffer = "";
                input = "";
                passedCheck = false;
            } else if (input.equalsIgnoreCase("who -l")) {
                printShipRoster(WHO_ADDRESS);
                buffer = "";
                input = "";
                passedCheck = false;
            } else if (input.equals("borg")) {
                sendText("\r\nReserved ship name; select another.\r\n");
                buffer = "";
                input = "";
                passedCheck = false;
            } else if (input.indexOf('~') != -1) {
                sendText("\r\nThe '~' character is reserved; please select a different ship name.\r\n");
                buffer = "";
                input = "";
                passedCheck = false;
            }
        }
        while (!passedCheck);
        TrekLog.logMessage("User chose ship name: " + input);
        // Set the thread name.
        super.setName("Thread-" + input);
        shipName = input;
        return true;
    }