Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.refactor.io.player.impl;
- import java.net.InetSocketAddress;
- import server.Config;
- import server.Server;
- import server.database.model.impl.LoginLogDAO;
- import server.database.passive.PassiveDatabaseWorker;
- import server.database.util.PlayerDatabase;
- import server.model.players.Client;
- import server.model.players.PlayerHandler;
- import server.model.players.moderation.PlayerPunishment;
- import server.model.players.moderation.PlayerPunishment.PunishmentType;
- import server.model.players.moderation.PunishHandler;
- import server.model.players.storage.GameStorage;
- import server.net.StaticPacketBuilder;
- import server.refactor.io.player.PlayerLoaderResponse;
- import server.refactor.net.codec.login.LoginConstants;
- import server.refactor.security.AccountAccessLocker;
- import server.refactor.security.PlayerCredentials;
- import server.util.ISAACRandomGen;
- public final class BinaryPlayerLoader {
- public PlayerLoaderResponse loadPlayer(final PlayerCredentials credentials, int returnCode) throws Exception {
- if (Config.SERVER_DEBUG) {
- System.err.println("load player");
- }
- String statusMessage = "Undefined error.";
- final int uid = credentials.getUid();
- final String name = credentials.getUsername();
- final String pass = credentials.getPassword();
- final ISAACRandomGen inC = credentials.getRandomGenPair().getDecodingRandom();
- final ISAACRandomGen outC = credentials.getRandomGenPair().getEncodingRandom();
- final int clientVersion = credentials.get_clientVersion();
- final String systemName = encodeString(credentials.getClientSerial());
- final String playerMacAdress = credentials.getPlayerMacAddress();
- final String regSerial = credentials.getRegSerial();
- final int loginDelay = 1;
- String formattedName = name.trim().toLowerCase();
- final String formattedPassword = pass.toLowerCase();
- boolean isReconnecting = false;
- Client cl = new Client(credentials.getChannel(), -1);
- cl.webClient = credentials.isWebclient();
- cl.playerName = formattedName;
- cl.playerPass = formattedPassword;
- cl.setInStreamDecryption(inC);
- cl.setOutStreamDecryption(outC);
- cl.outStream.packetEncryption = outC;
- cl.clientVersion = clientVersion;
- cl.systemName = systemName;
- cl.playerMacAdress = playerMacAdress;
- cl.regSerial = regSerial;
- cl.saveCharacter = false;
- cl.connectedFrom = ((InetSocketAddress) cl.getChannel().getRemoteAddress()).getAddress().getHostAddress();
- int totalClients = PlayerHandler.getTotalComputerConnection(cl.regSerial);
- // final char first = name.charAt(1);
- if (Config.DEVELOPER_MACHINE || Config.TEST_ENVIRONMENT) {
- if (Config.RESTRICT_DEVELOPMENT_WORLD_ACCESS) {
- boolean isDevelopmentSupporter = PlayerDatabase.isDevelopementSupporter(cl.playerName, cl.regSerial);
- if (!isDevelopmentSupporter && !cl.isPb600() && !cl.isDevelopmentSupporter()) {// && !cl.isStaff()
- returnCode = 29;
- statusMessage = "This world is available only\nfor Game Development\nSupport team.";
- System.out.println("Blocked login for " + formattedName);
- } else {
- if (Config.ALLOW_ALL_COMMANDS)
- cl.developmentSupporter = true;
- }
- } else {
- if (Config.ALLOW_ALL_COMMANDS)
- cl.developmentSupporter = true;
- }
- }
- if (Config.blockMainUsersTable) {
- returnCode = LoginConstants.STATUS_UPDATING;
- }
- System.out.println("UID? " + uid);
- if (returnCode == 2 && uid != 18644998) {
- returnCode = LoginConstants.STATUS_BAD_SESSION_ID;
- }
- if (returnCode == 2 && clientVersion < Config.CLIENT_VERSION) {
- returnCode = LoginConstants.STATUS_OUTDATED_CLIENT;
- }
- if(returnCode == 2 && totalClients >= 2) {
- returnCode = LoginConstants.STATUS_TOO_MANY_CONNECTIONS;
- }
- int punishmentID = -1;
- long punishmentTime = 0;
- if (returnCode == 2) {
- if (!cl.isPb600() && !cl.regSerial.equals("8B9aYlTTjL8lKn9")) {
- PlayerPunishment ban = PunishHandler.getPlayerPunishment(name, cl.playerMacAdress, cl.connectedFrom, cl.regSerial, PunishmentType.BAN);
- if (ban != null) {
- punishmentTime = ban.getTimeLeft();
- punishmentID = ban.getIndex();
- punishmentID <<= 2;
- returnCode = (ban.getExpireDate() > 0 ? LoginConstants.STATUS_ACCOUNT_TEMPORARILY_DISABLED : LoginConstants.STATUS_ACCOUNT_DISABLED);
- }
- }
- }
- if (returnCode == 2) {
- if (PlayerHandler.isPlayerOn(name)) {
- Client player = PlayerHandler.getClient(name);
- if (player != null) {
- if (cl.playerPass.equals(player.playerPass)) {
- if (!credentials.isReconnecting()) {
- if (player.getClient().validateLogout()) {
- player.kick();
- }
- returnCode = LoginConstants.STATUS_ACCOUNT_ONLINE;
- } else {
- if (player.getClient().validateLogout() && cl.playerPass.equals(player.playerPass)) {
- player.kick();
- returnCode = LoginConstants.STATUS_DELAY;
- } else {
- returnCode = LoginConstants.STATUS_ACCOUNT_ONLINE;
- }
- }
- } else {
- returnCode = LoginConstants.STATUS_INVALID_CREDENTIALS;
- }
- }
- }
- }
- if (PlayerHandler.playerCount >= Config.MAX_PLAYERS) {
- returnCode = LoginConstants.STATUS_SERVER_FULL;
- }
- if (returnCode == 2 && (Server.updateHandler.isUpdating() && Server.updateHandler.getTimeLeft() < 50) && !cl.isDeveloper()) {
- returnCode = LoginConstants.STATUS_UPDATING;
- }
- if (returnCode == 2 && restrictAccess(name, regSerial)) {
- returnCode = LoginConstants.STATUS_INVALID_CREDENTIALS;
- }
- if (Config.DEVELOPER_MACHINE && Config.RESTRICT_DEVELOPMENT_WORLD_ACCESS) {
- boolean isDevelopmentSupporter = PlayerDatabase.isDevelopementSupporter(cl.regSerial, cl.playerName);
- if (!isDevelopmentSupporter && !cl.isPb600() && !cl.isDevelopmentSupporter()) {// && !cl.isStaff()
- // &&
- returnCode = 29;
- statusMessage = "This world is available only\nfor Game Development\nSupport team.";
- } else {
- cl.developmentSupporter = true;
- }
- }
- if (returnCode == LoginConstants.STATUS_OK && !isReconnecting) {
- final int loadResponde;
- long object = System.currentTimeMillis();
- loadResponde = GameStorage.loadGame(cl, cl.playerName, cl.playerPass);
- boolean flaggedName = false;
- if (loadResponde == 0) {// Account doesn't exist.
- if (innapropriateName(cl.playerName)) {
- returnCode = LoginConstants.STATUS_INAPROPRIATE_NAME;
- flaggedName = true;
- } else if (hasDoubleSpaces(cl.playerName)) {
- returnCode = 29;
- statusMessage = "You are not allowed to use\ndouble spaces in your username.";
- flaggedName = true;
- } else
- cl.starter = true;
- }
- if (loadResponde == LoginConstants.STATUS_ERROR_TRANSFERING_PROFILE) {
- returnCode = 29;
- statusMessage = "An error occurred while\ntransferring your profile.";
- }
- if (loadResponde == LoginConstants.STATUS_ACCOUNT_CREATION_LIMIT) {
- returnCode = loadResponde;
- }
- if (loadResponde == LoginConstants.STATUS_UPDATING) {
- returnCode = loadResponde;
- }
- if (loadResponde == 3) {
- returnCode = LoginConstants.STATUS_INVALID_CREDENTIALS;
- cl.saveFile = false;
- } else if (loadResponde == LoginConstants.STATUS_COULD_NOT_COMPLETE_LOGIN) {
- returnCode = LoginConstants.STATUS_COULD_NOT_COMPLETE_LOGIN;
- cl.saveFile = false;
- } else if (!flaggedName) {
- // TODO: Fix this.
- // cl.getPlayerEquipment().clearItems();
- if (!Server.playerHandler.newPlayerClient(cl)) {
- returnCode = LoginConstants.STATUS_SERVER_FULL;// World is
- // full
- cl.saveFile = false;
- } else
- cl.saveFile = true;
- }
- }
- boolean cancelConnection = returnCode != 2;
- final StaticPacketBuilder bldr = new StaticPacketBuilder().setBare(true).addByte((byte) returnCode);
- if (returnCode == LoginConstants.STATUS_OK) {
- cl.saveCharacter = true;
- if (!credentials.isReconnecting())
- PassiveDatabaseWorker.addRequest(new LoginLogDAO(cl.accountID, cl.playerName, cl.playerRights, credentials.getRegSerial(), credentials.getPlayerMacAddress(), cl.systemName, cl.connectedFrom));
- int playerID = cl.accountID;
- bldr.addByte((byte) cl.getPlayerCrown());
- bldr.addByte((byte) ((playerID >> 16) & 0xFF));
- bldr.addByte((byte) ((playerID >> 8) & 0xFF));
- bldr.addByte((byte) (playerID & 0xFF));
- } else if (returnCode == LoginConstants.STATUS_ACCOUNT_DISABLED) {
- bldr.addInt(punishmentID);
- } else if (returnCode == LoginConstants.STATUS_ACCOUNT_TEMPORARILY_DISABLED) {
- bldr.addLong(punishmentTime);
- bldr.addInt(punishmentID);
- } else if (returnCode == 29) {
- bldr.addSizedString(statusMessage);
- } else {
- bldr.addByte((byte) 0);
- }
- bldr.addByte((byte) 0);
- // cl.getSession().write(bldr.toPacket());
- cl.isActive = true;
- return new PlayerLoaderResponse(cancelConnection, cl, bldr.toPacket().getData());
- }
- private boolean isValidCredentials(String formattedName, String pass, String playerMacAdress, String regSerial) {
- if (formattedName.length() > 12) {
- return false;
- }
- if (playerMacAdress.length() > 17) {
- System.err.println("Invalid mac length: " + playerMacAdress.length() + "(" + formattedName + ")");
- return false;
- }
- if (regSerial.length() != 15) {
- System.err.println("Invalid serial length: " + regSerial.length() + "(" + formattedName + ")");
- return false;
- }
- if (pass.length() > 20 || pass.length() < 4) {
- System.err.println("Invalid pass length: " + pass.length() + "(" + formattedName + ")");
- return false;
- }
- if (formattedName.isEmpty()) {
- return false;
- }
- if (!playerMacAdress.isEmpty() && !playerMacAdress.matches("[A-Za-z0-9-]+")) {
- System.err.println("Invalid mac: " + playerMacAdress + "(" + formattedName + ")");
- return false;
- }
- if (!regSerial.matches("[A-Za-z0-9 ]+")) {
- System.err.println("Invalid regSerial: " + regSerial + "(" + formattedName + ")");
- return false;
- }
- if (!pass.matches("[A-Za-z0-9 ]+")) {
- System.err.println("Invalid pass regex: " + pass + "(" + formattedName + ")");
- return false;
- }
- if (!formattedName.matches("[A-Za-z0-9 ]+")) {
- return false;
- }
- return true;
- }
- private static boolean restrictAccess(String name, String regSerial) {
- return AccountAccessLocker.getSingleton().restrictAccess(name, regSerial);
- }
- private static char[][] CONVERTION_TABLE = { { 'a', 'á', 'à', 'â', 'ã', 'ä' }, { 'A', 'Á', 'À', 'Â', 'Ã', 'Ä' }, { 'e', 'é', 'è', 'ê', 'ë' }, { 'E', 'É', 'È', 'Ê', 'Ë' }, { 'i', 'í', 'ì', 'î', 'ï' }, { 'I', 'Í', 'Ì', 'Î', 'Ï' }, { 'o', 'ó', 'ò', 'ô', 'õ', 'ö' }, { 'O', 'Ó', 'Ò', 'Ô', 'Õ', 'Ö' }, { 'u', 'ú', 'ù', 'û', 'ü' }, { 'U', 'Ú', 'Ù', 'Û', 'Ü' } };
- private static String encodeString(String string) {
- byte[] charSequence = string.getBytes();
- charLoop: for (int i = 0; i < charSequence.length; i++) {
- byte charByte = charSequence[i];
- if (charByte < 0 || charByte > 127) {
- // for (int tableRow = 0; tableRow < CONVERTION_TABLE.length;
- // tableRow++) {
- // for (int tableColum = 1; tableColum <
- // CONVERTION_TABLE[tableRow].length; tableColum++) {
- // if (charByte == (byte)
- // CONVERTION_TABLE[tableRow][tableColum]) {
- // charSequence[i] = (byte) CONVERTION_TABLE[tableRow][0];
- // continue charLoop;
- // }
- // }
- // }
- charSequence[i] = 63;
- }
- }
- return new String(charSequence);
- }
- private final static String[] INNAPROPRIATE_ENGLISH_WORDS = new String[] { "pb600", "mod", "admin", "vagina", "dick", "cunt", "fuck", "shit", "twat", "ass", "bitch", "nigger", "nigga", "gook", "spic", "gringo", "whore", "slut", "vag", "cock", "kike", "ballsack", "prick", "tits", "boner", "erection", "jizz", "nazi", "hitler", "goebbles", "bormann", "donitz", "doenitz", "goring", "goering", "hess", "kaltenbrunner", "jodl", "keitel", "papen", "raeder", "ribbentrop", "rosenberg", "sauckel", "schirach", "seyss-inquart", "seyssinquart", "speer", "streicher", "himmler", "rockwell", "fuhrer", "fuehrer", "holocaust", "swastika", "hakenkreuz", "nsdap", "schutzstaffel", "sturmabteilung", "waffenss", "fascism", "gleichschaltung", "machtergreifung", "strasserism", "strasserismus", "jungvolk", "blutundboden", "eugenics", "euthanasie", "eugenik", "aryan", "arier", "konzentrationslager", "voelkermord", "volkermord", "pogrom", "antisemitism", "antisemite", "antisemitisch", "antisemit", "judenfeindlichkeit", "kristallnacht", "bookburning", "biblioclasm", "libricide", "bucherverbrennung", "buecherverbrennung", "rohmputsch", "roehmputsch", };
- /**
- * Verify if player name contains any inappropriate words.
- *
- * @param playerName
- * : Name to be verified.
- * @return: true if name contains any inappropriate word.
- */
- private static boolean innapropriateName(String playerName) {
- playerName = playerName.toLowerCase();
- for (String word : INNAPROPRIATE_ENGLISH_WORDS) {
- if (playerName.contains(word))
- return true;
- }
- return false;
- }
- private static boolean hasDoubleSpaces(String playerName) {
- for (int i = 0; i < playerName.length(); i++) {
- char curChar = playerName.charAt(i);
- if (curChar == ' ') {
- boolean hasNext = i + 1 < playerName.length();
- if (hasNext) {
- char nextChar = playerName.charAt(i + 1);
- if (nextChar == ' ') {
- return true;
- }
- }
- }
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment