Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | None | 0 0
  1. public class AccountCreationDecoder {
  2.  
  3.     private static boolean BadName(String name) {
  4.         return name.contains("nerd") || name.contains("fuck") || name.contains("gay") || name.contains("motherf");
  5.     }
  6.  
  7.     private static List<String> SuggestedNames(String name) {
  8.         List<String> Names = new ArrayList<String>();
  9.         for (byte i = 0; i < 5; i++) {
  10.             String newName = name + Misc.random(5000);
  11.             if (AccountExists(newName) || Names.contains(newName))
  12.                 continue;
  13.             Names.add(newName);
  14.         }
  15.         return Names;
  16.     }
  17.  
  18.     private static boolean AccountExists(String name) {
  19.         return new File("./data/savedgames/" + name + ".ser").exists();
  20.  
  21.     }
  22.  
  23.     /*
  24.      *Where i say noob hacker means only way to that code part be called is by hacking
  25.       */
  26.     public static void decode(ConnectionHandler c, InStream in) {
  27.         switch(c.getConnectionStage()) {
  28.             case Constants.CHECK_ACC_NAME:
  29.                 if(in.remaining() < 8) {
  30.                     c.setConnectionStage(Constants.DISCONNECT);
  31.                     return;
  32.                 }
  33.                 List<String> suggestions = null;
  34.                 String user = Misc.longToString(in.readLong());
  35.                 int packetSize = in.readUnsignedByte();
  36.                 int returnCode = 0;
  37.                 if(user==null)
  38.                     returnCode = 22;
  39.                 else if(BadName(user))
  40.                     returnCode = 20;
  41.                 else if(AccountExists(user)) {
  42.                     returnCode = 21;
  43.                     OutStream outstream = new OutStream();
  44.                     suggestions = SuggestedNames(user);
  45.                 } else {
  46.                     returnCode = 2;
  47.                 }
  48.                 OutStream out = new OutStream((suggestions==null)?2:512);
  49.                 out.writeByte(returnCode);
  50.                 if(returnCode==21) {
  51.                     if(suggestions==null) {
  52.                         out.writeByte(1);
  53.                         out.writeLong(Misc.stringToLong("gtfo"));
  54.                     } else {
  55.                         out.writeByte(suggestions.size());
  56.                         for(String suggestion:suggestions)
  57.                             out.writeLong(Misc.stringToLong(suggestion));
  58.                     }
  59.                 }
  60.                 c.write(out);
  61.                 c.setConnectionStage(Constants.DISCONNECT);
  62.             break;
  63.             case Constants.MAKE_ACC:    
  64.                 int length = in.readShort();
  65.                 int version = in.readShort();
  66.                 int b3 = in.readByte();
  67.                 int b4 = in.readByte();
  68.                 in.skip(26);
  69.                 int b1 = in.readByte();
  70.                 int s1 = in.readShort();
  71.                 String username = Misc.formatPlayerNameForProtocol(Misc.longToString(in.readLong()));
  72.                 int s2 = in.readShort();
  73.                 String password = in.readString();
  74.                 System.out.println("Creating account: "+username+", password: "+password+".");
  75.                 long l1 = in.readLong();
  76.                 //2 longs or 4 ints client sided
  77.                 long l2 = in.readLong();
  78.                 long l3 = in.readLong();
  79.                 int i1 = in.readInt();
  80.                 out = new OutStream(1);
  81.                 out.writeByte(2);
  82.                 c.write(out);
  83.                 Player player = new Player(username, password, new GregorianCalendar(), new GregorianCalendar(), (short) 1, "", (byte) 1);
  84.                 Serializer.SaveAccount(player);
  85.             break;
  86.         }
  87.     }
  88.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement