Search in sources :

Example 1 with Settings

use of com.rs.Settings in project runesource by PureCS.

the class Player method initSession.

private void initSession(boolean newPlayer) {
    Settings settings = Server.getInstance().getSettings();
    attributes.getSkills().updateTotalLevel();
    attributes.getSkills().updateCombatLevel();
    username = Misc.encodeBase37(attributes.getUsername());
    WorldHandler.getInstance().register(this);
    sendMapRegion();
    sendInventory();
    sendSkills();
    sendEquipment();
    sendWeaponInterface();
    getUpdateContext().setAppearanceUpdateRequired();
    // Send sidebar interfaces
    for (int i = 1; i < SIDEBAR_INTERFACE_IDS.length; i++) {
        sendSidebarInterface(i, SIDEBAR_INTERFACE_IDS[i]);
    }
    sendRunEnergy();
    sendResetAllButtonStates();
    sendMessage("Welcome to " + settings.getServerName() + "!");
    System.out.println(this + " has logged in.");
    PluginHandler.dispatchLogin(this, newPlayer);
}
Also used : Settings(com.rs.Settings)

Example 2 with Settings

use of com.rs.Settings in project runesource by PureCS.

the class Player method login.

public void login(String username, String password) throws Exception {
    Server server = Server.getInstance();
    Settings settings = server.getSettings();
    int response = Misc.LOGIN_RESPONSE_OK;
    // Updating credentials
    attributes.setUsername(username);
    attributes.setPassword(settings.isHashingPasswords() ? Misc.hashSha256(password) : password);
    // Check if the player is already logged in.
    if (WorldHandler.getInstance().isPlayerOnline(username)) {
        response = Misc.LOGIN_RESPONSE_ACCOUNT_ONLINE;
    }
    // Load the player and send the login response.
    PlayerAttributes attributes;
    boolean validPassword = true;
    boolean newPlayer = false;
    try {
        attributes = server.getPlayerFileHandler().load(this.attributes.getUsername());
        validPassword = attributes.getPassword().equals(getAttributes().getPassword());
        this.attributes = attributes;
    } catch (NoSuchFileException e) {
        newPlayer = true;
    } catch (Exception e) {
        response = Misc.LOGIN_RESPONSE_PLEASE_TRY_AGAIN;
    }
    boolean validCredentials = server.getCredentialValidator().validate(this.attributes.getUsername(), password);
    // Invalid username/password - we skip the check if the account is found because the validation may have changed since
    if ((newPlayer && !validCredentials) || !validPassword) {
        response = Misc.LOGIN_RESPONSE_INVALID_CREDENTIALS;
        ConnectionThrottle.enter(getHost());
    }
    // Check if banned
    if (this.attributes.getInfractions().isBanned()) {
        response = Misc.LOGIN_RESPONSE_ACCOUNT_DISABLED;
    }
    // Check if connection limit is exceeded
    if (HostGateway.count(getHost()) >= settings.getMaxConsPerHost() + 1) {
        response = Misc.LOGIN_RESPONSE_LOGIN_LIMIT_EXCEEDED;
    }
    // Check if login attempts exceeded
    if (ConnectionThrottle.throttled(getHost())) {
        response = Misc.LOGIN_RESPONSE_LOGIN_ATTEMPTS_EXCEEDED;
    }
    // Sending response
    StreamBuffer.WriteBuffer resp = StreamBuffer.createWriteBuffer(3);
    resp.writeByte(response);
    resp.writeByte(getAttributes().getPrivilege().toInt());
    resp.writeByte(0);
    send(resp.getBuffer());
    if (response != Misc.LOGIN_RESPONSE_OK) {
        disconnect();
    } else {
        initSession(newPlayer);
    }
}
Also used : Server(com.rs.Server) StreamBuffer(com.rs.net.StreamBuffer) NoSuchFileException(java.nio.file.NoSuchFileException) Settings(com.rs.Settings) NoSuchFileException(java.nio.file.NoSuchFileException)

Aggregations

Settings (com.rs.Settings)2 Server (com.rs.Server)1 StreamBuffer (com.rs.net.StreamBuffer)1 NoSuchFileException (java.nio.file.NoSuchFileException)1