Guest User

Untitled

a guest
Dec 28th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.20 KB | None | 0 0
  1. package server.refactor.io.player.impl;
  2.  
  3. import java.net.InetSocketAddress;
  4.  
  5. import server.Config;
  6. import server.Server;
  7. import server.database.model.impl.LoginLogDAO;
  8. import server.database.passive.PassiveDatabaseWorker;
  9. import server.database.util.PlayerDatabase;
  10. import server.model.players.Client;
  11. import server.model.players.PlayerHandler;
  12. import server.model.players.moderation.PlayerPunishment;
  13. import server.model.players.moderation.PlayerPunishment.PunishmentType;
  14. import server.model.players.moderation.PunishHandler;
  15. import server.model.players.storage.GameStorage;
  16. import server.net.StaticPacketBuilder;
  17. import server.refactor.io.player.PlayerLoaderResponse;
  18. import server.refactor.net.codec.login.LoginConstants;
  19. import server.refactor.security.AccountAccessLocker;
  20. import server.refactor.security.PlayerCredentials;
  21. import server.util.ISAACRandomGen;
  22.  
  23. public final class BinaryPlayerLoader {
  24.  
  25. public PlayerLoaderResponse loadPlayer(final PlayerCredentials credentials, int returnCode) throws Exception {
  26.  
  27. if (Config.SERVER_DEBUG) {
  28. System.err.println("load player");
  29. }
  30. String statusMessage = "Undefined error.";
  31. final int uid = credentials.getUid();
  32. final String name = credentials.getUsername();
  33. final String pass = credentials.getPassword();
  34. final ISAACRandomGen inC = credentials.getRandomGenPair().getDecodingRandom();
  35. final ISAACRandomGen outC = credentials.getRandomGenPair().getEncodingRandom();
  36. final int clientVersion = credentials.get_clientVersion();
  37. final String systemName = encodeString(credentials.getClientSerial());
  38. final String playerMacAdress = credentials.getPlayerMacAddress();
  39. final String regSerial = credentials.getRegSerial();
  40. final int loginDelay = 1;
  41. String formattedName = name.trim().toLowerCase();
  42. final String formattedPassword = pass.toLowerCase();
  43. boolean isReconnecting = false;
  44.  
  45. Client cl = new Client(credentials.getChannel(), -1);
  46.  
  47. cl.webClient = credentials.isWebclient();
  48. cl.playerName = formattedName;
  49. cl.playerPass = formattedPassword;
  50. cl.setInStreamDecryption(inC);
  51. cl.setOutStreamDecryption(outC);
  52. cl.outStream.packetEncryption = outC;
  53. cl.clientVersion = clientVersion;
  54. cl.systemName = systemName;
  55. cl.playerMacAdress = playerMacAdress;
  56. cl.regSerial = regSerial;
  57. cl.saveCharacter = false;
  58. cl.connectedFrom = ((InetSocketAddress) cl.getChannel().getRemoteAddress()).getAddress().getHostAddress();
  59.  
  60. int totalClients = PlayerHandler.getTotalComputerConnection(cl.regSerial);
  61. // final char first = name.charAt(1);
  62.  
  63. if (Config.DEVELOPER_MACHINE || Config.TEST_ENVIRONMENT) {
  64. if (Config.RESTRICT_DEVELOPMENT_WORLD_ACCESS) {
  65. boolean isDevelopmentSupporter = PlayerDatabase.isDevelopementSupporter(cl.playerName, cl.regSerial);
  66. if (!isDevelopmentSupporter && !cl.isPb600() && !cl.isDevelopmentSupporter()) {// && !cl.isStaff()
  67. returnCode = 29;
  68. statusMessage = "This world is available only\nfor Game Development\nSupport team.";
  69. System.out.println("Blocked login for " + formattedName);
  70. } else {
  71. if (Config.ALLOW_ALL_COMMANDS)
  72. cl.developmentSupporter = true;
  73. }
  74. } else {
  75. if (Config.ALLOW_ALL_COMMANDS)
  76. cl.developmentSupporter = true;
  77. }
  78. }
  79.  
  80. if (Config.blockMainUsersTable) {
  81. returnCode = LoginConstants.STATUS_UPDATING;
  82. }
  83. System.out.println("UID? " + uid);
  84. if (returnCode == 2 && uid != 18644998) {
  85. returnCode = LoginConstants.STATUS_BAD_SESSION_ID;
  86. }
  87.  
  88. if (returnCode == 2 && clientVersion < Config.CLIENT_VERSION) {
  89. returnCode = LoginConstants.STATUS_OUTDATED_CLIENT;
  90. }
  91.  
  92. if(returnCode == 2 && totalClients >= 2) {
  93. returnCode = LoginConstants.STATUS_TOO_MANY_CONNECTIONS;
  94. }
  95.  
  96. int punishmentID = -1;
  97. long punishmentTime = 0;
  98. if (returnCode == 2) {
  99. if (!cl.isPb600() && !cl.regSerial.equals("8B9aYlTTjL8lKn9")) {
  100. PlayerPunishment ban = PunishHandler.getPlayerPunishment(name, cl.playerMacAdress, cl.connectedFrom, cl.regSerial, PunishmentType.BAN);
  101. if (ban != null) {
  102. punishmentTime = ban.getTimeLeft();
  103. punishmentID = ban.getIndex();
  104. punishmentID <<= 2;
  105. returnCode = (ban.getExpireDate() > 0 ? LoginConstants.STATUS_ACCOUNT_TEMPORARILY_DISABLED : LoginConstants.STATUS_ACCOUNT_DISABLED);
  106. }
  107. }
  108. }
  109.  
  110. if (returnCode == 2) {
  111. if (PlayerHandler.isPlayerOn(name)) {
  112. Client player = PlayerHandler.getClient(name);
  113. if (player != null) {
  114. if (cl.playerPass.equals(player.playerPass)) {
  115. if (!credentials.isReconnecting()) {
  116. if (player.getClient().validateLogout()) {
  117. player.kick();
  118. }
  119. returnCode = LoginConstants.STATUS_ACCOUNT_ONLINE;
  120. } else {
  121. if (player.getClient().validateLogout() && cl.playerPass.equals(player.playerPass)) {
  122. player.kick();
  123. returnCode = LoginConstants.STATUS_DELAY;
  124. } else {
  125. returnCode = LoginConstants.STATUS_ACCOUNT_ONLINE;
  126. }
  127. }
  128. } else {
  129. returnCode = LoginConstants.STATUS_INVALID_CREDENTIALS;
  130. }
  131. }
  132. }
  133. }
  134.  
  135. if (PlayerHandler.playerCount >= Config.MAX_PLAYERS) {
  136. returnCode = LoginConstants.STATUS_SERVER_FULL;
  137. }
  138.  
  139. if (returnCode == 2 && (Server.updateHandler.isUpdating() && Server.updateHandler.getTimeLeft() < 50) && !cl.isDeveloper()) {
  140. returnCode = LoginConstants.STATUS_UPDATING;
  141. }
  142.  
  143. if (returnCode == 2 && restrictAccess(name, regSerial)) {
  144. returnCode = LoginConstants.STATUS_INVALID_CREDENTIALS;
  145. }
  146.  
  147. if (Config.DEVELOPER_MACHINE && Config.RESTRICT_DEVELOPMENT_WORLD_ACCESS) {
  148. boolean isDevelopmentSupporter = PlayerDatabase.isDevelopementSupporter(cl.regSerial, cl.playerName);
  149. if (!isDevelopmentSupporter && !cl.isPb600() && !cl.isDevelopmentSupporter()) {// && !cl.isStaff()
  150. // &&
  151. returnCode = 29;
  152. statusMessage = "This world is available only\nfor Game Development\nSupport team.";
  153. } else {
  154. cl.developmentSupporter = true;
  155. }
  156. }
  157.  
  158. if (returnCode == LoginConstants.STATUS_OK && !isReconnecting) {
  159. final int loadResponde;
  160. long object = System.currentTimeMillis();
  161. loadResponde = GameStorage.loadGame(cl, cl.playerName, cl.playerPass);
  162. boolean flaggedName = false;
  163. if (loadResponde == 0) {// Account doesn't exist.
  164. if (innapropriateName(cl.playerName)) {
  165. returnCode = LoginConstants.STATUS_INAPROPRIATE_NAME;
  166. flaggedName = true;
  167. } else if (hasDoubleSpaces(cl.playerName)) {
  168. returnCode = 29;
  169. statusMessage = "You are not allowed to use\ndouble spaces in your username.";
  170. flaggedName = true;
  171. } else
  172. cl.starter = true;
  173. }
  174.  
  175. if (loadResponde == LoginConstants.STATUS_ERROR_TRANSFERING_PROFILE) {
  176. returnCode = 29;
  177. statusMessage = "An error occurred while\ntransferring your profile.";
  178. }
  179. if (loadResponde == LoginConstants.STATUS_ACCOUNT_CREATION_LIMIT) {
  180. returnCode = loadResponde;
  181. }
  182. if (loadResponde == LoginConstants.STATUS_UPDATING) {
  183. returnCode = loadResponde;
  184. }
  185. if (loadResponde == 3) {
  186. returnCode = LoginConstants.STATUS_INVALID_CREDENTIALS;
  187. cl.saveFile = false;
  188. } else if (loadResponde == LoginConstants.STATUS_COULD_NOT_COMPLETE_LOGIN) {
  189. returnCode = LoginConstants.STATUS_COULD_NOT_COMPLETE_LOGIN;
  190. cl.saveFile = false;
  191. } else if (!flaggedName) {
  192. // TODO: Fix this.
  193. // cl.getPlayerEquipment().clearItems();
  194. if (!Server.playerHandler.newPlayerClient(cl)) {
  195. returnCode = LoginConstants.STATUS_SERVER_FULL;// World is
  196. // full
  197. cl.saveFile = false;
  198. } else
  199. cl.saveFile = true;
  200. }
  201. }
  202. boolean cancelConnection = returnCode != 2;
  203. final StaticPacketBuilder bldr = new StaticPacketBuilder().setBare(true).addByte((byte) returnCode);
  204. if (returnCode == LoginConstants.STATUS_OK) {
  205. cl.saveCharacter = true;
  206. if (!credentials.isReconnecting())
  207. PassiveDatabaseWorker.addRequest(new LoginLogDAO(cl.accountID, cl.playerName, cl.playerRights, credentials.getRegSerial(), credentials.getPlayerMacAddress(), cl.systemName, cl.connectedFrom));
  208. int playerID = cl.accountID;
  209. bldr.addByte((byte) cl.getPlayerCrown());
  210. bldr.addByte((byte) ((playerID >> 16) & 0xFF));
  211. bldr.addByte((byte) ((playerID >> 8) & 0xFF));
  212. bldr.addByte((byte) (playerID & 0xFF));
  213. } else if (returnCode == LoginConstants.STATUS_ACCOUNT_DISABLED) {
  214. bldr.addInt(punishmentID);
  215. } else if (returnCode == LoginConstants.STATUS_ACCOUNT_TEMPORARILY_DISABLED) {
  216. bldr.addLong(punishmentTime);
  217. bldr.addInt(punishmentID);
  218. } else if (returnCode == 29) {
  219. bldr.addSizedString(statusMessage);
  220. } else {
  221. bldr.addByte((byte) 0);
  222. }
  223. bldr.addByte((byte) 0);
  224. // cl.getSession().write(bldr.toPacket());
  225. cl.isActive = true;
  226. return new PlayerLoaderResponse(cancelConnection, cl, bldr.toPacket().getData());
  227. }
  228.  
  229. private boolean isValidCredentials(String formattedName, String pass, String playerMacAdress, String regSerial) {
  230. if (formattedName.length() > 12) {
  231. return false;
  232. }
  233. if (playerMacAdress.length() > 17) {
  234. System.err.println("Invalid mac length: " + playerMacAdress.length() + "(" + formattedName + ")");
  235. return false;
  236. }
  237. if (regSerial.length() != 15) {
  238. System.err.println("Invalid serial length: " + regSerial.length() + "(" + formattedName + ")");
  239. return false;
  240. }
  241. if (pass.length() > 20 || pass.length() < 4) {
  242. System.err.println("Invalid pass length: " + pass.length() + "(" + formattedName + ")");
  243. return false;
  244. }
  245. if (formattedName.isEmpty()) {
  246. return false;
  247. }
  248. if (!playerMacAdress.isEmpty() && !playerMacAdress.matches("[A-Za-z0-9-]+")) {
  249. System.err.println("Invalid mac: " + playerMacAdress + "(" + formattedName + ")");
  250. return false;
  251. }
  252. if (!regSerial.matches("[A-Za-z0-9 ]+")) {
  253. System.err.println("Invalid regSerial: " + regSerial + "(" + formattedName + ")");
  254. return false;
  255. }
  256. if (!pass.matches("[A-Za-z0-9 ]+")) {
  257. System.err.println("Invalid pass regex: " + pass + "(" + formattedName + ")");
  258. return false;
  259. }
  260. if (!formattedName.matches("[A-Za-z0-9 ]+")) {
  261. return false;
  262. }
  263. return true;
  264. }
  265.  
  266. private static boolean restrictAccess(String name, String regSerial) {
  267. return AccountAccessLocker.getSingleton().restrictAccess(name, regSerial);
  268. }
  269.  
  270. private static char[][] CONVERTION_TABLE = { { 'a', 'á', 'à', 'â', 'ã', 'ä' }, { 'A', 'Á', 'À', 'Â', 'Ã', 'Ä' }, { 'e', 'é', 'è', 'ê', 'ë' }, { 'E', 'É', 'È', 'Ê', 'Ë' }, { 'i', 'í', 'ì', 'î', 'ï' }, { 'I', 'Í', 'Ì', 'Î', 'Ï' }, { 'o', 'ó', 'ò', 'ô', 'õ', 'ö' }, { 'O', 'Ó', 'Ò', 'Ô', 'Õ', 'Ö' }, { 'u', 'ú', 'ù', 'û', 'ü' }, { 'U', 'Ú', 'Ù', 'Û', 'Ü' } };
  271.  
  272. private static String encodeString(String string) {
  273.  
  274. byte[] charSequence = string.getBytes();
  275. charLoop: for (int i = 0; i < charSequence.length; i++) {
  276. byte charByte = charSequence[i];
  277. if (charByte < 0 || charByte > 127) {
  278. // for (int tableRow = 0; tableRow < CONVERTION_TABLE.length;
  279. // tableRow++) {
  280. // for (int tableColum = 1; tableColum <
  281. // CONVERTION_TABLE[tableRow].length; tableColum++) {
  282. // if (charByte == (byte)
  283. // CONVERTION_TABLE[tableRow][tableColum]) {
  284. // charSequence[i] = (byte) CONVERTION_TABLE[tableRow][0];
  285. // continue charLoop;
  286. // }
  287. // }
  288. // }
  289. charSequence[i] = 63;
  290. }
  291. }
  292. return new String(charSequence);
  293. }
  294.  
  295. 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", };
  296.  
  297. /**
  298. * Verify if player name contains any inappropriate words.
  299. *
  300. * @param playerName
  301. * : Name to be verified.
  302. * @return: true if name contains any inappropriate word.
  303. */
  304. private static boolean innapropriateName(String playerName) {
  305. playerName = playerName.toLowerCase();
  306. for (String word : INNAPROPRIATE_ENGLISH_WORDS) {
  307. if (playerName.contains(word))
  308. return true;
  309. }
  310. return false;
  311. }
  312.  
  313. private static boolean hasDoubleSpaces(String playerName) {
  314.  
  315. for (int i = 0; i < playerName.length(); i++) {
  316. char curChar = playerName.charAt(i);
  317. if (curChar == ' ') {
  318. boolean hasNext = i + 1 < playerName.length();
  319. if (hasNext) {
  320. char nextChar = playerName.charAt(i + 1);
  321. if (nextChar == ' ') {
  322. return true;
  323. }
  324. }
  325. }
  326. }
  327. return false;
  328. }
  329. }
Add Comment
Please, Sign In to add comment