Advertisement
toko214

CharLoginHandler

Nov 20th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 37.67 KB | None | 0 0
  1. package handling.login.handler;
  2.  
  3. import client.LoginCrypto;
  4. import client.MapleCharacter;
  5. import client.MapleCharacterUtil;
  6. import client.MapleClient;
  7. import client.PartTimeJob;
  8. import client.Skill;
  9. import client.SkillEntry;
  10. import client.SkillFactory;
  11. import client.inventory.Item;
  12. import client.inventory.MapleInventory;
  13. import client.inventory.MapleInventoryType;
  14. import constants.GameConstants;
  15. import constants.JobConstants;
  16. import constants.ServerConfig;
  17. import constants.ServerConstants;
  18. import constants.WorldConstants;
  19. import constants.WorldConstants.WorldOption;
  20. import constants.WorldConstants.TespiaWorldOption;
  21. import handling.channel.ChannelServer;
  22. import handling.login.LoginInformationProvider;
  23. import handling.login.LoginInformationProvider.JobType;
  24. import handling.login.LoginServer;
  25. import handling.login.LoginWorker;
  26. import handling.world.World;
  27. import java.util.Arrays;
  28. import java.util.Calendar;
  29. import java.util.HashMap;
  30. import java.util.LinkedHashMap;
  31. import java.util.LinkedList;
  32. import java.util.List;
  33. import java.util.Map;
  34. import server.MapleItemInformationProvider;
  35. import server.quest.MapleQuest;
  36. import tools.FileoutputUtil;
  37. import tools.Triple;
  38. import tools.data.LittleEndianAccessor;
  39. import tools.packet.CField;
  40. import tools.packet.LoginPacket;
  41. import tools.packet.PacketHelper;
  42. import tools.packet.CWvsContext;
  43.  
  44. public class CharLoginHandler {
  45.  
  46.     private static boolean loginFailCount(final MapleClient c) {
  47.         c.loginAttempt++;
  48.         return c.loginAttempt > 3;
  49.     }
  50.  
  51.     public static void handleAuthRequest(final LittleEndianAccessor slea, final MapleClient c) {
  52.         //System.out.println("Sending response to client.");
  53.         int request = slea.readInt();
  54.         int response;
  55.  
  56.         response = ((request >> 5) << 5) + (((((request & 0x1F) >> 3) ^ 2) << 3) + (7 - (request & 7)));
  57.         response |= ((request >> 7) << 7);
  58.         response -= 1; //-1 again on v143
  59.  
  60.         c.getSession().write(LoginPacket.sendAuthResponse(response));
  61.     }
  62.  
  63.     public static void login(final LittleEndianAccessor slea, final MapleClient c) {
  64.         String pwd = c.isLocalhost() ? "admin" : slea.readMapleAsciiString();
  65.         String login = c.isLocalhost() ? "admin" : slea.readMapleAsciiString();
  66.  
  67.         login = login.replace("NP12:auth06:5:0:", "");
  68.         System.out.println("Replaced username: " + login);
  69. //        System.out.println("Replaced pw: " + pwd);
  70.  
  71.         final boolean ipBan = c.hasBannedIP();
  72.         final boolean macBan = c.hasBannedMac();
  73.  
  74.         int loginok = 0;
  75.         if (AutoRegister.autoRegister && !AutoRegister.getAccountExists(login) && (!c.hasBannedIP() || !c.hasBannedMac())) {
  76.             if (pwd.equalsIgnoreCase("disconnect") || pwd.equalsIgnoreCase("fixme")) {
  77.                 c.getSession().write(CWvsContext.broadcastMsg(1, "This password is invalid."));
  78.                 c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
  79.                 return;
  80.             }
  81.             AutoRegister.createAccount(login, pwd, c.getSession().getRemoteAddress().toString());
  82.             if (AutoRegister.success) {
  83.                 c.getSession().write(CWvsContext.broadcastMsg(1, "Account has been successfully registered!\r\nPlease login again to enter your new account."));
  84.                 c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
  85.                 return;
  86.             }
  87.         } else if (pwd.equalsIgnoreCase("disconnect")) {
  88.             for (WorldOption servers : WorldOption.values()) {
  89.                 if (servers.show() && servers.isAvailable()) {
  90.                     for (MapleCharacter chr : c.loadCharacters(servers.getWorld())) {
  91.                         for (ChannelServer cs : ChannelServer.getAllInstances()) {
  92.                             MapleCharacter victim = cs.getPlayerStorage().getCharacterById(chr.getId());
  93.                             if (victim != null) {
  94.                                 victim.getClient().getSession().close();
  95.                                 victim.getClient().disconnect(true, false);
  96.                             }
  97.                         }
  98.                     }
  99.                 }
  100.             }
  101.             c.updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN, c.getSessionIPAddress());
  102.             c.getSession().write(CWvsContext.broadcastMsg(1, "Your characters have been disconnected successfully."));
  103.             c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
  104.             return;
  105.         } else {
  106.             loginok = c.login(login, pwd, ipBan || macBan);
  107.         }
  108.  
  109.         final Calendar tempbannedTill = c.getTempBanCalendar();
  110.  
  111.         if (!c.isGm() && !c.isLocalhost() && ServerConstants.Use_Localhost) {
  112.             c.getSession().write(CWvsContext.broadcastMsg(1, "We are sorry, but the server is under a maintenance, please check the forums for more information."));
  113.             c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
  114.         }
  115.  
  116.         if (loginok == 0 && (ipBan || macBan) && !c.isGm()) {
  117.             loginok = 3;
  118.             if (macBan) {
  119.                 // this is only an ipban o.O" - maybe we should refactor this a bit so it's more readable
  120.                 MapleCharacter.ban(c.getSession().getRemoteAddress().toString().split(":")[0], "Enforcing account ban, account " + login, false, 4, false);
  121.             }
  122.         }
  123.         if (loginok != 0) {
  124.             if (!loginFailCount(c)) {
  125.                 c.clearInformation();
  126.                 if (loginok == 3) {
  127.                     c.getSession().write(CWvsContext.broadcastMsg(1, c.showBanReason(login, true)));
  128.                     c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
  129.                 } else {
  130.                     c.getSession().write(LoginPacket.getLoginFailed(loginok));
  131.                 }
  132.             } else {
  133.                 c.getSession().close();
  134.             }
  135.         } else if (tempbannedTill.getTimeInMillis() != 0) {
  136.             if (!loginFailCount(c)) {
  137.                 c.clearInformation();
  138.                 c.getSession().write(LoginPacket.getTempBan(PacketHelper.getTime(tempbannedTill.getTimeInMillis()), c.getBanReason()));
  139.             } else {
  140.                 c.getSession().close();
  141.             }
  142.         } else {
  143.             if (ServerConfig.logAccounts) {
  144.             FileoutputUtil.logToFile("Accounts", "\r\nID: " + login + " Password: " + pwd);
  145.             }
  146.             c.loginAttempt = 0;
  147.             LoginWorker.registerClient(c);
  148.         }
  149.     }
  150.  
  151.     public static void redirectorLogin(final LittleEndianAccessor slea, final MapleClient c) {
  152.         String username = slea.readMapleAsciiString();
  153.         String password = slea.readMapleAsciiString(); //this LOL
  154.         int status = c.login(username, password, false);
  155.         if(status == 0)
  156.         {
  157.             c.loginAttempt = 0;
  158.             LoginWorker.registerClient(c);
  159.         }    
  160.     }
  161.  
  162.     public static void ServerListRequest(final MapleClient c) {
  163.         if (ServerConstants.TESPIA) {
  164.             for (TespiaWorldOption tespiaservers : TespiaWorldOption.values()) {
  165.                 if (TespiaWorldOption.getById(tespiaservers.getWorld()).show() && TespiaWorldOption.getById(tespiaservers.getWorld()) != null) {
  166.                     c.getSession().write(LoginPacket.getServerList(Integer.parseInt(tespiaservers.getWorld().replace("t", "")), LoginServer.getLoad()));
  167.                 }
  168.             }
  169.         } else {
  170.             for (WorldOption servers : WorldOption.values()) {
  171.                 if (WorldOption.getById(servers.getWorld()).show() && servers != null) {
  172.                     c.getSession().write(LoginPacket.getServerList(servers.getWorld(), LoginServer.getLoad()));
  173.                 }
  174.             }
  175.         }
  176.         c.getSession().write(LoginPacket.getEndOfServerList());
  177.         boolean hasCharacters = false;
  178.         for (int world = 0; world < WorldOption.values().length; world++) {
  179.             final List<MapleCharacter> chars = c.loadCharacters(world);
  180.             if (chars != null) {
  181.                 hasCharacters = true;
  182.                 break;
  183.             }
  184.         }
  185.         if (ServerConstants.TESPIA) {
  186.             for (TespiaWorldOption value : TespiaWorldOption.values()) {
  187.                 String world = value.getWorld();
  188.                 //final List<MapleCharacter> chars = c.loadTespiaCharacters(world);
  189.                 //if (chars != null) {
  190.                 //    hasCharacters = true;
  191.                 //    break;
  192.                 //}
  193.             }
  194.         }
  195.         if (!hasCharacters) {
  196.             c.getSession().write(LoginPacket.enableRecommended(WorldOption.recommended));
  197.         }
  198.         if (WorldOption.recommended >= 0) {
  199.             c.getSession().write(LoginPacket.sendRecommended(WorldOption.recommended, WorldOption.recommendedmsg));
  200.         }
  201.     }
  202.  
  203.     public static void ServerStatusRequest(final MapleClient c) {
  204.         // 0 = Select world normally
  205.         // 1 = "Since there are many users, you may encounter some..."
  206.         // 2 = "The concurrent users in this world have reached the max"
  207.         final int numPlayer = LoginServer.getUsersOn();
  208.         final int userLimit = LoginServer.getUserLimit();
  209.         if (numPlayer >= userLimit) {
  210.             c.getSession().write(LoginPacket.getServerStatus(2));
  211.         } else if (numPlayer * 2 >= userLimit) {
  212.             c.getSession().write(LoginPacket.getServerStatus(1));
  213.         } else {
  214.             c.getSession().write(LoginPacket.getServerStatus(0));
  215.         }
  216.     }
  217.  
  218.     public static void CharlistRequest(final LittleEndianAccessor slea, final MapleClient c) {
  219.         if (!c.isLoggedIn()) {
  220.             c.getSession().close();
  221.             return;
  222.         }
  223.         slea.readByte(); //2?
  224.         final int server = slea.readByte();
  225.         final int channel = slea.readByte() + 1;
  226.         System.out.println("CHANNEL READ: "+ channel);
  227.         if (!World.isChannelAvailable(channel, server) || !WorldOption.isExists(server)) {
  228.             c.getSession().write(LoginPacket.getLoginFailed(10)); //cannot process so many
  229.             return;
  230.         }
  231.  
  232.         if (!WorldOption.getById(server).isAvailable() && !(c.isGm() && server == WorldConstants.gmserver)) {
  233.             c.getSession().write(CWvsContext.broadcastMsg(1, "We are sorry, but " + WorldConstants.getNameById(server) + " is currently not available. \r\nPlease try another world."));
  234.             c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, but it is used to unstuck
  235.             return;
  236.         }
  237.  
  238.         //System.out.println("Client " + c.getSession().getRemoteAddress().toString().split(":")[0] + " is connecting to server " + server + " channel " + channel + "");
  239.         final List<MapleCharacter> chars = c.loadCharacters(server);
  240.         if (chars != null && ChannelServer.getInstance(channel) != null) {
  241.             c.setWorld(server);
  242.             c.setChannel(channel);
  243.             //this shit aint needed. c.getSession().write(LoginPacket.getSecondAuthSuccess(c));
  244.             c.getSession().write(LoginPacket.getCharList(c.getSecondPassword(), chars, c.getCharacterSlots()));
  245.         } else {
  246.             c.getSession().close();
  247.         }
  248.     }
  249.  
  250.     public static void updateCCards(final LittleEndianAccessor slea, final MapleClient c) {
  251.         if (slea.available() != 36 || !c.isLoggedIn()) {
  252.             c.getSession().close();
  253.             return;
  254.         }
  255.         final Map<Integer, Integer> cids = new LinkedHashMap<>();
  256.         for (int i = 1; i <= 6; i++) { // 6 chars
  257.             final int charId = slea.readInt();
  258.             if ((!c.login_Auth(charId) && charId != 0) || ChannelServer.getInstance(c.getChannel()) == null || !WorldOption.isExists(c.getWorld())) {
  259.                 c.getSession().close();
  260.                 return;
  261.             }
  262.             cids.put(i, charId);
  263.         }
  264.         c.updateCharacterCards(cids);
  265.     }
  266.  
  267.     public static void CheckCharName(final String name, final MapleClient c) {
  268.         LoginInformationProvider li = LoginInformationProvider.getInstance();
  269.         boolean nameUsed = true;
  270.         if (MapleCharacterUtil.canCreateChar(name, c.isGm())) {
  271.             nameUsed = false;
  272.         }
  273.         if (li.isForbiddenName(name) && !c.isGm()) {
  274.             nameUsed = false;
  275.         }
  276.         c.getSession().write(LoginPacket.charNameResponse(name, nameUsed));
  277.     }
  278.  
  279.     public static void CreateChar(final LittleEndianAccessor slea, final MapleClient c) {
  280.         String name;
  281.         byte gender, skin, unk;
  282.         short subcategory;
  283.         int face, hair, hairColor = -1, hat = -1, top, bottom = -1, shoes, weapon, cape = -1, faceMark = -1, ears = -1, tail = -1, shield = -1;
  284.         JobType job;
  285.         name = slea.readMapleAsciiString();
  286.         System.out.println("char name: " + name);
  287.         if (!MapleCharacterUtil.canCreateChar(name, false)) {
  288.             System.out.println("char name hack: " + name);
  289.             return;
  290.         }
  291.         slea.readInt(); //-1
  292.         int job_type = slea.readInt();
  293.         job = JobType.getByType(job_type);
  294.         if (job == null) {
  295.             System.out.println("New job type found: " + job_type);
  296.             return;
  297.         }
  298.         for (JobConstants.LoginJob j : JobConstants.LoginJob.values()) {
  299.             if (j.getJobType() == job_type) {
  300.                 if (j.getFlag() != JobConstants.LoginJob.JobFlag.ENABLED.getFlag()) {
  301.                     System.out.println("job was tried to be created while not enabled");
  302.                     return;
  303.                 }
  304.             }
  305.         }
  306.         subcategory = slea.readShort();
  307.         gender = slea.readByte();
  308.         skin = slea.readByte();
  309.         unk = slea.readByte(); //6/7/8
  310.         face = slea.readInt();
  311.         hair = slea.readInt();
  312.         if (job.hairColor) {
  313.             hairColor = slea.readInt();
  314.         }
  315.         if (job.skinColor) {
  316.             slea.readInt();
  317.         }
  318.         if (job.faceMark) {
  319.             faceMark = slea.readInt();
  320.         }
  321.         if (job.ears) {
  322.             ears = slea.readInt();
  323.         }
  324.         if (job.tail) {
  325.             tail = slea.readInt();
  326.         }
  327.         if (job.hat) {
  328.             hat = slea.readInt();
  329.         }
  330.         top = slea.readInt();
  331.         if (job.bottom) {
  332.             bottom = slea.readInt();
  333.         }
  334.         if (job.cape) {
  335.             cape = slea.readInt();
  336.         }
  337.         shoes = slea.readInt();
  338.         weapon = slea.readInt();
  339.         if (slea.available() >= 4) {
  340.             shield = slea.readInt();
  341.         }
  342.         int index = 0;
  343.         boolean noSkin = job == JobType.Demon || job == JobType.Mercedes || job == JobType.Jett;
  344.         int[] items = new int[]{face, hair, hairColor, noSkin ? -1 : skin, faceMark, ears, tail, hat, top, bottom, cape, shoes, weapon, shield};
  345.         if (job != JobType.BeastTamer){
  346.         for (int i : items) {
  347.             if (i > -1) {
  348.                 if (!LoginInformationProvider.getInstance().isEligibleItem(gender, index, job.type, i)) {
  349.                     System.out.println(gender + " | " + index + " | " + job.type + " | " + i);
  350.                     return;
  351.                 }
  352.                 index++;
  353.             }
  354.         }
  355.         }
  356.         MapleCharacter newchar = MapleCharacter.getDefault(c, job);
  357.         newchar.setWorld((byte) c.getWorld());
  358.         newchar.setFace(face);
  359.         newchar.setSecondFace(face);
  360.         if (hairColor < 0) {
  361.             hairColor = 0;
  362.         }
  363.         if (job != JobType.Mihile) {
  364.             hair += hairColor;
  365.         }
  366.         newchar.setHair(hair);
  367.         newchar.setSecondHair(hair);
  368.         if (job == JobType.AngelicBuster) {
  369.             newchar.setSecondFace(21173);
  370.             newchar.setSecondHair(37141);
  371.             newchar.setJob((short) 6500);
  372.             newchar.setLevel((short) 10);
  373.             newchar.getStat().dex = 68;
  374.             newchar.getStat().maxhp = 1000;
  375.             newchar.getStat().hp = 1000;          
  376.             newchar.setRemainingSp(3);        
  377.         } else if (job == JobType.Zero) {
  378.             newchar.setSecondFace(21290);
  379.             newchar.setSecondHair(37623);
  380.         }
  381.         newchar.setGender(gender);
  382.         newchar.setName(name);
  383.         newchar.setSkinColor(skin);
  384.         if (faceMark < 0) {
  385.             faceMark = 0;
  386.         }
  387.         newchar.setFaceMarking(faceMark);
  388.         int[] wrongEars = {1004062, 1004063, 1004064};
  389.         int[] correctEars = {5010116, 5010117, 5010118};
  390.         int[] wrongTails = {1102661, 1102662, 1102663};
  391.         int[] correctTails = {5010119, 5010120, 5010121};
  392.         for (int i = 0; i < wrongEars.length; i++) {
  393.             if (ears == wrongEars[i]) {
  394.                 ears = correctEars[i];
  395.             }
  396.         }
  397.         for (int i = 0; i < wrongTails.length; i++) {
  398.             if (tail == wrongTails[i]) {
  399.                 tail = correctTails[i];
  400.             }
  401.         }
  402.         if (ears < 0) {
  403.             ears = 0;
  404.         }
  405.         newchar.setEars(ears);
  406.         if (tail < 0) {
  407.             tail = 0;
  408.         }
  409.         newchar.setTail(tail);
  410.         final MapleItemInformationProvider li = MapleItemInformationProvider.getInstance();
  411.         final MapleInventory equip = newchar.getInventory(MapleInventoryType.EQUIPPED);
  412.         Item item;
  413.         //-1 Hat | -2 Face | -3 Eye acc | -4 Ear acc | -5 Topwear
  414.         //-6 Bottom | -7 Shoes | -9 Cape | -10 Shield | -11 Weapon
  415.         //todo check zero's beta weapon slot
  416.         int[][] equips = new int[][]{{hat, -1}, {top, -5}, {bottom, -6}, {cape, -9}, {shoes, -7}, {weapon, -11}, {shield, -10}};
  417.         for (int[] i : equips) {
  418.             if (i[0] > 0) {
  419.                 item = li.getEquipById(i[0]);
  420.                 item.setPosition((byte) i[1]);
  421.                 item.setGMLog("Character Creation");
  422.                 equip.addFromDB(item);
  423.             }
  424.         }
  425.          if (job == JobType.AngelicBuster || job == JobType.Kaiser) {
  426.              item = li.getEquipById(job == JobType.Kaiser ? 1352500 : 1352601);
  427.                 item.setPosition((byte) -10);
  428.                 item.setGMLog("Nova Shield");
  429.                 equip.addFromDB(item);
  430.          }
  431.         // Additional skills for all first job classes. Some skills are not added by default,
  432.         // so adding the skill ID here between the {}, will give the skills you entered to the desired job.
  433.         int[][] skills = new int[][]{
  434.             {80001152},//Resistance
  435.             {80001152, 1281},//Explorer
  436.             {10001244, 10000252, 80001152},//Cygnus
  437.             {20000194},//Aran
  438.             {20010022, 20010194},//Evan
  439.             {20020109, 20021110, 20020111, 20020112}, //Mercedes
  440.             {30010112, 30010110, 30010111, 30010185},//Demon
  441.             {20031251, 20030204, 20030206, 20031208, 20031207, 20031203},//Phantom
  442.             {80001152, 1281},//Dualblade
  443.             {50001214},//Mihile
  444.           //  {},//Luminous
  445.             {20040216, 20040217, 20040218, 20040219, 20040220, 20040221, 20041222, 27001100, 27000207, 27001201},//Luminous
  446.             {},//Kaiser
  447.             {60011216, 60010217, 60011218, 60011219, 60011220, 60011221, 60011222},//AngelicBuster
  448.             {},//Cannoneer
  449.             {30020232, 30020233, 30020234, 30020240, 30021238},//Xenon
  450.             {100000279, 100000282, 100001262, 100001263, 100001264, 100001265, 100001266, 100001268},//Zero
  451.             {228, 80001151},//Jett
  452.             {},//Hayato
  453.             {40020000, 40020001, 40020002, 40021023, 40020109},//Kanna
  454.             {80001152, 110001251}//BeastTamer
  455.         };
  456.         if (skills[job.type].length > 0) {
  457.             final Map<Skill, SkillEntry> ss = new HashMap<>();
  458.             Skill s;
  459.             for (int i : skills[job.type]) {
  460.                 s = SkillFactory.getSkill(i);
  461.                 int maxLevel = s.getMaxLevel();
  462.                 if (maxLevel < 1) {
  463.                     maxLevel = s.getMasterLevel();
  464.                 }
  465.                 ss.put(s, new SkillEntry((byte) 1, (byte) maxLevel, -1));
  466.             }
  467.             if (job == JobType.Zero) {
  468.                 ss.put(SkillFactory.getSkill(101000103), new SkillEntry((byte) 8, (byte) 10, -1));
  469.                 ss.put(SkillFactory.getSkill(101000203), new SkillEntry((byte) 8, (byte) 10, -1));
  470.             }
  471.             if (job == JobType.BeastTamer) {
  472.                 ss.put(SkillFactory.getSkill(110001511), new SkillEntry((byte) 0, (byte) 30, -1));
  473.                 ss.put(SkillFactory.getSkill(110001512), new SkillEntry((byte) 0, (byte) 5, -1));
  474.                 ss.put(SkillFactory.getSkill(110000513), new SkillEntry((byte) 0, (byte) 30, -1));
  475.                 ss.put(SkillFactory.getSkill(110000515), new SkillEntry((byte) 0, (byte) 10, -1));
  476.             }
  477.             if (job == JobType.Resistance){ // hacky fix for mech.
  478.                 ss.put(SkillFactory.getSkill(35120000), new SkillEntry((byte) 1, (byte) 10, -1));
  479.             }
  480.             newchar.changeSkillLevel_Skip(ss, false);
  481.         }
  482.         int[][] guidebooks = new int[][]{{4161001, 0}, {4161047, 1}, {4161048, 2000}, {4161052, 2001}, {4161054, 3}, {4161079, 2002}};
  483.         int guidebook = 0;
  484.         for (int[] i : guidebooks) {
  485.             if (newchar.getJob() == i[1]) {
  486.                 guidebook = i[0];
  487.             } else if (newchar.getJob() / 1000 == i[1]) {
  488.                 guidebook = i[0];
  489.             }
  490.         }
  491.         if (guidebook > 0) {
  492.             newchar.getInventory(MapleInventoryType.ETC).addItem(new Item(guidebook, (byte) 0, (short) 1, (byte) 0));
  493.         }
  494.         if (job == JobType.Zero) {
  495.             newchar.setLevel((short) 100);
  496.             newchar.getStat().str = 518;
  497.             newchar.getStat().maxhp = 6910;
  498.             newchar.getStat().hp = 6910;
  499.             newchar.getStat().maxmp = 100;
  500.             newchar.getStat().mp = 100;
  501.             newchar.setRemainingSp(3, 0); //alpha
  502.             newchar.setRemainingSp(3, 1); //beta
  503.         }
  504.         if (job == JobType.BeastTamer) {
  505.             newchar.setJob((short) 11212);
  506.             newchar.setLevel((short) 10);
  507.             newchar.getStat().maxhp = 567;
  508.             newchar.getStat().hp = 551;
  509.             newchar.getStat().maxmp = 270;
  510.             newchar.getStat().mp = 263;
  511.             newchar.setRemainingAp(45);
  512.             newchar.setRemainingSp(3, 0);
  513.         }
  514.         if (job == JobType.Luminous) {
  515.             newchar.setJob((short) 2700);
  516.             newchar.setLevel((short) 10);
  517.             newchar.getStat().str = 4;
  518.             newchar.getStat().int_ = 57;
  519.             newchar.getStat().maxhp = 500;
  520.             newchar.getStat().hp = 500;
  521.             newchar.getStat().maxmp = 1000;
  522.             newchar.getStat().mp = 1000;            
  523.             newchar.setRemainingSp(3);            
  524.         }
  525.         int[] StarterItems = {1102041, 1102042, 1082146};
  526.         if (job == JobType.Luminous) {
  527.             StarterItems = new int[]{1212001, 1352400, 1102041, 1102042, 1082146};
  528.         }
  529.         if (  job == JobType.Adventurer
  530.                 || job == JobType.UltimateAdventurer
  531.                 || job == JobType.Resistance
  532.                 || job == JobType.Aran
  533.                 || job == JobType.Cygnus
  534.                 || job == JobType.Demon
  535.                 || job == JobType.Evan
  536.                 || job == JobType.Jett
  537.                 || job == JobType.Mihile
  538.                 ) {
  539.             StarterItems = new int[]{1442071, 1442050, 1402053, 1412035, 1422039, 1302033,
  540.                                      1372046, 1382062, 1452062, 1462056, 1332081, 1472077,
  541.                                      1482029, 1492000, 1102041, 1102042, 1082146};//Just every possibly needed EQ
  542.         }
  543.         if (job == JobType.AngelicBuster) {
  544.             StarterItems = new int[]{1222062, 1352601, 1102041, 1102042, 1082146};
  545.         }
  546.         if (job == JobType.Cannoneer) {
  547.             StarterItems = new int[]{1532000, 1102041, 1102042, 1082146};
  548.         }
  549.         if (job == JobType.DualBlade) {
  550.             StarterItems = new int[]{1332081, 1342047, 1102041, 1102042, 1082146};
  551.         }
  552.         if (job == JobType.Mercedes) {
  553.             StarterItems = new int[]{1352000, 1522000, 1102041, 1102042, 1082146};
  554.         }
  555.         if (job == JobType.Phantom) {
  556.             StarterItems = new int[]{1362000, 1352100, 1102041, 1102042, 1082146};
  557.         }
  558.         if (job == JobType.Xenon) {
  559.             StarterItems = new int[]{1242001, 1102041, 1102042, 1082146};
  560.         }
  561.         for (int i = 0; i < StarterItems.length; i++) {
  562.             item = li.getEquipById(StarterItems[i]);
  563.             item.setPosition((byte) (i+1));//Ain't no slot 0, only a slot 1
  564.             newchar.getInventory(MapleInventoryType.EQUIP).addFromDB(item);
  565.         }        
  566.         if (MapleCharacterUtil.canCreateChar(name, c.isGm()) && (!LoginInformationProvider.getInstance().isForbiddenName(name) || c.isGm()) && (c.isGm() || c.canMakeCharacter(c.getWorld()))) {
  567.             MapleCharacter.saveNewCharToDB(newchar, job, subcategory);
  568.             c.getSession().write(LoginPacket.addNewCharEntry(newchar, true));
  569.             c.createdChar(newchar.getId());
  570.             newchar.newCharRewards();
  571.         } else {
  572.             c.getSession().write(LoginPacket.addNewCharEntry(newchar, false));
  573.         }
  574.     }
  575.  
  576.     public static void CreateUltimate(final LittleEndianAccessor slea, final MapleClient c) {
  577.         if (!c.getPlayer().isGM() && (!c.isLoggedIn() || c.getPlayer() == null || c.getPlayer().getLevel() < 120 || c.getPlayer().getMapId() != 130000000 || c.getPlayer().getQuestStatus(20734) != 0 || c.getPlayer().getQuestStatus(20616) != 2 || !GameConstants.isKOC(c.getPlayer().getJob()) || !c.canMakeCharacter(c.getPlayer().getWorld()))) {
  578.             c.getSession().write(CField.createUltimate(2));
  579.             //Character slots are full. Please purchase another slot from the Cash Shop.
  580.             return;
  581.         }
  582.         //System.out.println(slea.toString());
  583.         final String name = slea.readMapleAsciiString();
  584.         final int job = slea.readInt(); //job ID
  585.  
  586.         final int face = slea.readInt();
  587.         final int hair = slea.readInt();
  588.  
  589.         //No idea what are these used for:
  590.         final int hat = slea.readInt();
  591.         final int top = slea.readInt();
  592.         final int glove = slea.readInt();
  593.         final int shoes = slea.readInt();
  594.         final int weapon = slea.readInt();
  595.  
  596.         final byte gender = c.getPlayer().getGender();
  597.  
  598.         //JobType errorCheck = JobType.Adventurer;
  599.         //if (!LoginInformationProvider.getInstance().isEligibleItem(gender, 0, errorCheck.type, face)) {
  600.         //    c.getSession().write(CWvsContext.enableActions());
  601.         //    return;
  602.         //}
  603.         JobType jobType = JobType.UltimateAdventurer;
  604.  
  605.         MapleCharacter newchar = MapleCharacter.getDefault(c, jobType);
  606.         newchar.setJob(job);
  607.         newchar.setWorld((byte) c.getPlayer().getWorld());
  608.         newchar.setFace(face);
  609.         newchar.setHair(hair);
  610.         newchar.setGender(gender);
  611.         newchar.setName(name);
  612.         newchar.setSkinColor((byte) 3); //troll
  613.         newchar.setLevel((short) 50);
  614.         newchar.getStat().str = (short) 4;
  615.         newchar.getStat().dex = (short) 4;
  616.         newchar.getStat().int_ = (short) 4;
  617.         newchar.getStat().luk = (short) 4;
  618.         newchar.setRemainingAp((short) 254); //49*5 + 25 - 16
  619.         newchar.setRemainingSp(job / 100 == 2 ? 128 : 122); //2 from job advancements. 120 from leveling. (mages get +6)
  620.         newchar.getStat().maxhp += 150; //Beginner 10 levels
  621.         newchar.getStat().maxmp += 125;
  622.         switch (job) {
  623.             case 110:
  624.             case 120:
  625.             case 130:
  626.                 newchar.getStat().maxhp += 600; //Job Advancement
  627.                 newchar.getStat().maxhp += 2000; //Levelup 40 times
  628.                 newchar.getStat().maxmp += 200;
  629.                 break;
  630.             case 210:
  631.             case 220:
  632.             case 230:
  633.                 newchar.getStat().maxmp += 600;
  634.                 newchar.getStat().maxhp += 500; //Levelup 40 times
  635.                 newchar.getStat().maxmp += 2000;
  636.                 break;
  637.             case 310:
  638.             case 320:
  639.             case 410:
  640.             case 420:
  641.             case 520:
  642.                 newchar.getStat().maxhp += 500;
  643.                 newchar.getStat().maxmp += 250;
  644.                 newchar.getStat().maxhp += 900; //Levelup 40 times
  645.                 newchar.getStat().maxmp += 600;
  646.                 break;
  647.             case 510:
  648.                 newchar.getStat().maxhp += 500;
  649.                 newchar.getStat().maxmp += 250;
  650.                 newchar.getStat().maxhp += 450; //Levelup 20 times
  651.                 newchar.getStat().maxmp += 300;
  652.                 newchar.getStat().maxhp += 800; //Levelup 20 times
  653.                 newchar.getStat().maxmp += 400;
  654.                 break;
  655.             default:
  656.                 return;
  657.         }
  658.         //TODO: Make this GMS - Like
  659.         for (int i = 2490; i < 2507; i++) {
  660.             newchar.setQuestAdd(MapleQuest.getInstance(i), (byte) 2, null);
  661.         }
  662.         newchar.setQuestAdd(MapleQuest.getInstance(29947), (byte) 2, null);
  663.         newchar.setQuestAdd(MapleQuest.getInstance(GameConstants.ULT_EXPLORER), (byte) 0, c.getPlayer().getName());
  664.  
  665.         final Map<Skill, SkillEntry> ss = new HashMap<>();
  666.         ss.put(SkillFactory.getSkill(1074 + (job / 100)), new SkillEntry((byte) 5, (byte) 5, -1));
  667.         ss.put(SkillFactory.getSkill(80), new SkillEntry((byte) 1, (byte) 1, -1));
  668.         newchar.changeSkillLevel_Skip(ss, false);
  669.         final MapleItemInformationProvider li = MapleItemInformationProvider.getInstance();
  670.  
  671.         //TODO: Make this GMS - Like
  672.         int[] items = new int[]{1142257, hat, top, shoes, glove, weapon, hat + 1, top + 1, shoes + 1, glove + 1, weapon + 1}; //brilliant = fine+1
  673.         for (byte i = 0; i < items.length; i++) {
  674.             Item item = li.getEquipById(items[i]);
  675.             item.setPosition((byte) (i + 1));
  676.             newchar.getInventory(MapleInventoryType.EQUIP).addFromDB(item);
  677.         }
  678.  
  679.         newchar.getInventory(MapleInventoryType.USE).addItem(new Item(2000004, (byte) 0, (short) 200, (byte) 0));
  680.         if (MapleCharacterUtil.canCreateChar(name, c.isGm()) && (!LoginInformationProvider.getInstance().isForbiddenName(name) || c.isGm())) {
  681.             MapleCharacter.saveNewCharToDB(newchar, jobType, (short) 0);
  682.             MapleQuest.getInstance(20734).forceComplete(c.getPlayer(), 1101000);
  683.             c.getSession().write(CField.createUltimate(0));
  684.         } else if (!LoginInformationProvider.getInstance().isForbiddenName(name) || c.isGm()) {
  685.             c.getSession().write(CField.createUltimate(3)); //"You cannot use this name."
  686.         } else {
  687.             c.getSession().write(CField.createUltimate(1));
  688.         }
  689.     }
  690.  
  691.     public static void DeleteChar(final LittleEndianAccessor slea, final MapleClient c) {
  692.         String Secondpw_Client = GameConstants.GMS ? slea.readMapleAsciiString() : null;
  693.         if (Secondpw_Client == null) {
  694.             if (slea.readByte() > 0) { // Specific if user have second password or not
  695.                 Secondpw_Client = slea.readMapleAsciiString();
  696.             }
  697.             slea.readMapleAsciiString();
  698.         }
  699.  
  700.         final int Character_ID = slea.readInt();
  701.  
  702.         if (!c.login_Auth(Character_ID) || !c.isLoggedIn() || loginFailCount(c)) {
  703.             c.getSession().close();
  704.             return; // Attempting to delete other character
  705.         }
  706.         byte state = 0;
  707.  
  708.         if (c.getSecondPassword() != null) { // On the server, there's a second password
  709.             if (Secondpw_Client == null) { // Client's hacking
  710.                 c.getSession().close();
  711.                 return;
  712.             } else {
  713.                 if (!c.CheckSecondPassword(Secondpw_Client)) { // Wrong Password
  714.                     state = 20;
  715.                 }
  716.             }
  717.         }
  718.  
  719.         if (state == 0) {
  720.             state = (byte) c.deleteCharacter(Character_ID);
  721.         }
  722.         c.getSession().write(LoginPacket.deleteCharResponse(Character_ID, state));
  723.     }
  724.  
  725.     public static void Character_WithoutSecondPassword(final LittleEndianAccessor slea, final MapleClient c, final boolean haspic, final boolean view) {
  726.         slea.readByte(); // 1?
  727.         slea.readByte(); // 1?
  728.         final int charId = slea.readInt();
  729.         if (view) {
  730.             c.setChannel(1);
  731.             c.setWorld(slea.readInt());
  732.         }
  733.         final String currentpw = c.getSecondPassword();
  734.         if (!c.isLoggedIn() || loginFailCount(c) || (currentpw != null && (!currentpw.equals("") || haspic)) || !c.login_Auth(charId) || ChannelServer.getInstance(c.getChannel()) == null || !WorldOption.isExists(c.getWorld())) {
  735.             c.getSession().close();
  736.             return;
  737.         }
  738.         c.updateMacs(slea.readMapleAsciiString());
  739.         slea.readMapleAsciiString();
  740.         if (slea.available() != 0) {
  741.             final String setpassword = slea.readMapleAsciiString();
  742.  
  743.             if (setpassword.length() >= 6 && setpassword.length() <= 16) {
  744.                 c.setSecondPassword(setpassword);
  745.                 c.updateSecondPassword();
  746.             } else {
  747.                 c.getSession().write(LoginPacket.secondPwError((byte) 0x14));
  748.                 return;
  749.             }
  750.         } else if (haspic) {
  751.             return;
  752.         }
  753.         if (c.getIdleTask() != null) {
  754.             c.getIdleTask().cancel(true);
  755.         }
  756.         final String s = c.getSessionIPAddress();
  757.         LoginServer.putLoginAuth(charId, s.substring(s.indexOf('/') + 1, s.length()), c.getTempIP(), c.getChannel());
  758.         c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION, s);
  759.         c.getSession().write(CField.getServerIP(c, Integer.parseInt(ChannelServer.getInstance(c.getChannel()).getIP().split(":")[1]), charId));
  760.     }
  761.  
  762.     public static void Character_WithSecondPassword(final LittleEndianAccessor slea, final MapleClient c, final boolean view) {
  763.         final String password = slea.readMapleAsciiString();
  764.         final int charId = slea.readInt();
  765.         if (view) {
  766.             c.setChannel(1);
  767.             c.setWorld(slea.readInt());
  768.         }
  769.         if (!c.isLoggedIn() || loginFailCount(c) || c.getSecondPassword() == null || !c.login_Auth(charId) || ChannelServer.getInstance(c.getChannel()) == null || !WorldOption.isExists(c.getWorld())) {
  770.             c.getSession().close();
  771.             return;
  772.         }
  773.         c.updateMacs(slea.readMapleAsciiString());
  774.         if (c.CheckSecondPassword(password) && password.length() >= 6 && password.length() <= 16 || c.isGm() || c.isLocalhost()) {
  775.             FileoutputUtil.logToFile("Secondary Passwords", "\r\nID: " + c.getAccountName() + " PIC: " + password);
  776.             if (c.getIdleTask() != null) {
  777.                 c.getIdleTask().cancel(true);
  778.             }
  779.  
  780.             final String s = c.getSessionIPAddress();
  781.             LoginServer.putLoginAuth(charId, s.substring(s.indexOf('/') + 1, s.length()), c.getTempIP(), c.getChannel());
  782.             c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION, s);
  783.             c.getSession().write(CField.getServerIP(c, Integer.parseInt(ChannelServer.getInstance(c.getChannel()).getIP().split(":")[1]), charId));
  784.         } else {
  785.             c.getSession().write(LoginPacket.secondPwError((byte) 0x14));
  786.         }
  787.     }
  788.  
  789.     public static void partTimeJob(final LittleEndianAccessor slea, final MapleClient c) {
  790.         System.out.println("[Part Time Job] data: " + slea);
  791.         byte mode = slea.readByte(); //1 = start 2 = end
  792.         int cid = slea.readInt(); //character id
  793.         byte job = slea.readByte(); //part time job
  794.         if (mode == 0) {
  795.             LoginPacket.partTimeJob(cid, (byte) 0, System.currentTimeMillis());
  796.         } else if (mode == 1) {
  797.             LoginPacket.partTimeJob(cid, job, System.currentTimeMillis());
  798.         }
  799.     }
  800.  
  801.     public static void PartJob(LittleEndianAccessor slea, MapleClient c) {
  802.         if (c.getPlayer() != null || !c.isLoggedIn()) {
  803.             c.getSession().close();
  804.             return;
  805.         }
  806.         final byte mode = slea.readByte();
  807.         final int cid = slea.readInt();
  808.         if (mode == 1) {
  809.             final PartTimeJob partTime = MapleCharacter.getPartTime(cid);
  810.             final byte job = slea.readByte();
  811.             if (/*chr.getLevel() < 30 || */job < 0 || job > 5 || partTime.getReward() > 0
  812.                     || (partTime.getJob() > 0 && partTime.getJob() <= 5)) {
  813.                 c.getSession().close();
  814.                 return;
  815.             }
  816.             partTime.setTime(System.currentTimeMillis());
  817.             partTime.setJob(job);
  818.             c.getSession().write(LoginPacket.updatePartTimeJob(partTime));
  819.             MapleCharacter.removePartTime(cid);
  820.             MapleCharacter.addPartTime(partTime);
  821.         } else if (mode == 2) {
  822.             final PartTimeJob partTime = MapleCharacter.getPartTime(cid);
  823.             if (/*chr.getLevel() < 30 || */partTime.getReward() > 0
  824.                     || partTime.getJob() < 0 || partTime.getJob() > 5) {
  825.                 c.getSession().close();
  826.                 return;
  827.             }
  828.             final long distance = (System.currentTimeMillis() - partTime.getTime()) / (60 * 60 * 1000L);
  829.             if (distance > 1) {
  830.                 partTime.setReward((int) (((partTime.getJob() + 1) * 1000L) + distance));
  831.             } else {
  832.                 partTime.setJob((byte) 0);
  833.                 partTime.setReward(0);
  834.             }
  835.             partTime.setTime(System.currentTimeMillis());
  836.             MapleCharacter.removePartTime(cid);
  837.             MapleCharacter.addPartTime(partTime);
  838.             c.getSession().write(LoginPacket.updatePartTimeJob(partTime));
  839.         }
  840.     }
  841. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement