Repository reorganisation

Unified kotlin and java into just src/main
Unified the rs09 and core packages
Took all content out of the core package, and placed it into the new content package
Reorganised all source code relating to content to be easier to find and explore
This commit is contained in:
Ceikry
2023-01-26 13:59:28 +00:00
committed by Ryan
parent e4b799c44a
commit a100affda2
3156 changed files with 24205 additions and 30585 deletions
@@ -0,0 +1,141 @@
package core.net.registry;
import core.cache.misc.buffer.ByteBufferUtils;
import core.game.system.task.Pulse;
import core.net.Constants;
import core.net.IoSession;
import core.ServerConstants;
import core.auth.UserAccountInfo;
import core.tools.SystemLogger;
import core.game.world.GameWorld;
import core.net.packet.in.Login;
import java.nio.ByteBuffer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Handles the registry of new accounts.
* @author Vexia
*
*/
public class AccountRegister {
/**
* The pattern compiler.
*/
private static final Pattern PATTERN = Pattern.compile("[a-z0-9_]{1,12}");
/**
* Reads the incoming opcode of an account register.
* @param session the session.
* @param opcode the opcode.
* @param buffer the buffer.
*/
public static void read(final IoSession session, int opcode, ByteBuffer buffer) {
int day,month,year,country;
UserAccountInfo info = UserAccountInfo.createDefault();
switch (opcode) {
case 147://details
day = buffer.get();
month = buffer.get();
year = buffer.getShort();
country = buffer.getShort();
response(session, RegistryResponse.SUCCESS);
break;
case 186://username
final String username = ByteBufferUtils.getString(buffer).replace(" ", "_").toLowerCase().replace("|", "");
info.setUsername(username);
if (username.length() <= 0 || username.length() > 12) {
response(session, RegistryResponse.INVALID_USERNAME);
break;
}
if (invalidUsername(username)) {
System.out.println("AHAHHA " + username);
response(session,RegistryResponse.INVALID_USERNAME);
break;
}
System.out.println(username);
if (!GameWorld.getAuthenticator().canCreateAccountWith(info)) {
response(session, RegistryResponse.NOT_AVAILBLE_USER);
return;
}
response(session, RegistryResponse.SUCCESS);
break;
case 36://Register details
SystemLogger.logInfo(AccountRegister.class, "Made it to final stage");
buffer.get(); //Useless size being written that is already written in the RSA block
buffer = Login.decryptRSABuffer(buffer, ServerConstants.EXPONENT, ServerConstants.MODULUS);
if(buffer.get() != 10){ //RSA header (aka did this decrypt properly)
SystemLogger.logInfo(AccountRegister.class, "Decryption failed during registration :(");
response(session, RegistryResponse.CANNOT_CREATE);
break;
}
buffer.getShort(); // random data
int revision = buffer.getShort();//revision?
if (revision != Constants.REVISION) {
response(session, RegistryResponse.CANNOT_CREATE);
break;
}
final String name = ByteBufferUtils.getString(buffer).replace(" ", "_").toLowerCase().replace("|", "");
buffer.getInt();
String password = ByteBufferUtils.getString(buffer);
info.setUsername(name);
info.setPassword(password);
if (password.length() < 5 || password.length() > 20) {
response(session, RegistryResponse.INVALID_PASS_LENGTH);
break;
}
if (password.equals(name)) {
response(session, RegistryResponse.PASS_SIMILAR_TO_USER);
break;
}
if (invalidUsername(name)) {
response(session, RegistryResponse.INVALID_USERNAME);
break;
}
buffer.getInt();
buffer.getShort();
day = buffer.get();
month = buffer.get();
buffer.getInt();
year = buffer.getShort();
country = buffer.getShort();
buffer.getInt();
if (!GameWorld.getAuthenticator().canCreateAccountWith(info)) {
response(session, RegistryResponse.CANNOT_CREATE);
return;
}
GameWorld.getAuthenticator().createAccountWith(info);
GameWorld.getPulser().submit(new Pulse() {
@Override
public boolean pulse() {
response(session, RegistryResponse.SUCCESS);
return true;
}
});
break;
default:
SystemLogger.logErr(AccountRegister.class, "Unhandled account registry opcode = " + opcode);
break;
}
}
/**
* Sends a registry response code.
* @param response the response.
*/
private static void response(IoSession session, RegistryResponse response) {
ByteBuffer buf = ByteBuffer.allocate(100);
buf.put((byte) response.getId());
session.queue(buf.flip());
}
/**
* Checks if a username is valid.
* @return {@code True} if so.
*/
public static boolean invalidUsername(final String username) {
Matcher matcher = PATTERN.matcher(username);
return !matcher.matches();
}
}
@@ -0,0 +1,78 @@
package core.net.registry;
import java.sql.Date;
/**
* Represents details of an account to register.
* @author Vexia
*
*/
public class RegistryDetails {
/**
* The username.
*/
private final String username;
/**
* The password.
*/
private final String password;
/**
* The date of birth.
*/
private final Date birth;
/**
* The country.
*/
private final int country;
/**
* Constructs a new {@Code RegistryDetails} {@Code Object}
* @param username The username to register.
* @param password The password to register.
* @param birth The birth year.
* @param country The country code.
*/
public RegistryDetails(String username, String password, Date birth, int country) {
this.username = username;
this.password = password;
this.birth = birth;
this.country = country;
}
/**
* Gets the username.
* @return the username.
*/
public String getUsername() {
return username;
}
/**
* Gets the password.
* @return the password.
*/
public String getPassword() {
return password;
}
/**
* Gets the birth.
* @return the birth.
*/
public Date getBirth() {
return birth;
}
/**
* Gets the country.
* @return the country.
*/
public int getCountry() {
return country;
}
}
@@ -0,0 +1,46 @@
package core.net.registry;
/**
* An account registry response.
* @author Vexia
*
*/
public enum RegistryResponse {
SUCCESS(2),
CONTACT_ERROR(3),
SERVER_BUSY(7),
CANNOT_CREATE(9),
INVALID_BIRTH(10),
FUTURE_BIRTH(11),
BIRTH_THIS_YEAR(12),
BIRTH_LAST_YEAR(13),
INVALID_COUNTRY(14),
NOT_AVAILBLE_USER(20),
INVALID_USERNAME(22),
INVALID_PASS_LENGTH(30),
INVALID_PASS(31),
WEAK_PASS(32),
PASS_SIMILAR_TO_USER(33);
/**
* The response id.
*/
private final int id;
/**
* Constructs a new {@Code RegistryResponse} {@Code Object}
* @param id the id.
*/
RegistryResponse(int id) {
this.id = id;
}
/**
* Gets the id.
* @return the id.
*/
public int getId() {
return id;
}
}