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);
}
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);
}
}
Aggregations