Improved Delete Character
Improved the Delete Character feature, now aiming to clean all leftovers of the character from the DB. Only works with the ENABLE_PIC flag activated.
This commit is contained in:
@@ -1524,6 +1524,213 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void nextPendingRequest(MapleClient c) {
|
||||
CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
|
||||
if (pendingBuddyRequest != null) {
|
||||
c.announce(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyRemoteChannel(MapleClient c, int remoteChannel, int otherCid, BuddyList.BuddyOperation operation) {
|
||||
MapleCharacter player = c.getPlayer();
|
||||
if (remoteChannel != -1) {
|
||||
c.getWorldServer().buddyChanged(otherCid, player.getId(), player.getName(), c.getChannel(), operation);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteBuddy(int otherCid) {
|
||||
BuddyList bl = getBuddylist();
|
||||
|
||||
if (bl.containsVisible(otherCid)) {
|
||||
notifyRemoteChannel(client, client.getWorldServer().find(otherCid), otherCid, BuddyList.BuddyOperation.DELETED);
|
||||
}
|
||||
bl.remove(otherCid);
|
||||
client.announce(MaplePacketCreator.updateBuddylist(getBuddylist().getBuddies()));
|
||||
nextPendingRequest(client);
|
||||
}
|
||||
|
||||
public static boolean deleteCharFromDB(MapleCharacter player) {
|
||||
int cid = player.getId(), accId = -1, world = 0;
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try {
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT accountid, world FROM characters WHERE id = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if(rs.next()) {
|
||||
accId = rs.getInt("accountid");
|
||||
world = rs.getInt("world");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT buddyid FROM buddies WHERE characterid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while(rs.next()) {
|
||||
int buddyid = rs.getInt("buddyid");
|
||||
MapleCharacter buddy = Server.getInstance().getWorld(world).getPlayerStorage().getCharacterById(buddyid);
|
||||
|
||||
if(buddy != null) {
|
||||
buddy.deleteBuddy(cid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM buddies WHERE characterid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT threadid FROM bbs_threads WHERE postercid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
int tid = rs.getInt("threadid");
|
||||
|
||||
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM bbs_replies WHERE threadid = ?")) {
|
||||
ps2.setInt(1, tid);
|
||||
ps2.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM bbs_threads WHERE postercid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT id, guildid, guildrank, name, allianceRank FROM characters WHERE id = ? AND accountid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.setInt(2, accId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next() && rs.getInt("guildid") > 0) {
|
||||
Server.getInstance().deleteGuildCharacter(new MapleGuildCharacter(player, cid, 0, rs.getString("name"), (byte) -1, (byte) -1, 0, rs.getInt("guildrank"), rs.getInt("guildid"), false, rs.getInt("allianceRank")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(con.isClosed()) con = DatabaseConnection.getConnection(); //wtf tho
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM wishlists WHERE charid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM cooldowns WHERE charid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM area_info WHERE charid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM monsterbook WHERE charid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM characters WHERE id = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM famelog WHERE characterid_to = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT inventoryitemid, petid FROM inventoryitems WHERE characterid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
int inventoryitemid = rs.getInt("inventoryitemid");
|
||||
|
||||
try (PreparedStatement ps2 = con.prepareStatement("SELECT ringid FROM inventoryequipment WHERE inventoryitemid = ?")) {
|
||||
ps2.setInt(1, inventoryitemid);
|
||||
|
||||
try (ResultSet rs2 = ps2.executeQuery()) {
|
||||
while (rs2.next()) {
|
||||
int ringid = rs2.getInt("ringid");
|
||||
|
||||
if(ringid > -1) {
|
||||
try (PreparedStatement ps3 = con.prepareStatement("DELETE FROM rings WHERE id = ?")) {
|
||||
ps3.setInt(1, ringid);
|
||||
ps3.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM inventoryequipment WHERE inventoryitemid = ?")) {
|
||||
ps2.setInt(1, inventoryitemid);
|
||||
ps2.executeUpdate();
|
||||
}
|
||||
|
||||
if(rs.getInt("petid") > -1) {
|
||||
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM pets WHERE petid = ?")) {
|
||||
ps2.setInt(1, rs.getInt("petid"));
|
||||
ps2.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT queststatusid FROM queststatus WHERE characterid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
int queststatusid = rs.getInt("queststatusid");
|
||||
|
||||
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM medalmaps WHERE queststatusid = ?")) {
|
||||
ps2.setInt(1, queststatusid);
|
||||
ps2.executeUpdate();
|
||||
}
|
||||
|
||||
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM questprogress WHERE queststatusid = ?")) {
|
||||
ps2.setInt(1, queststatusid);
|
||||
ps2.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT id FROM mts_cart WHERE cid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
int mtsid = rs.getInt("id");
|
||||
|
||||
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM mts_items WHERE id = ?")) {
|
||||
ps2.setInt(1, mtsid);
|
||||
ps2.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM mts_cart WHERE cid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
String[] toDel = {"famelog", "inventoryitems", "keymap", "queststatus", "savedlocations", "trocklocations", "skillmacros", "skills", "eventstats", "server_queue"};
|
||||
for (String s : toDel) {
|
||||
MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM `" + s + "` WHERE characterid = ?", cid);
|
||||
}
|
||||
|
||||
con.close();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteWhereCharacterId(Connection con, String sql) throws SQLException {
|
||||
try (PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
|
||||
@@ -60,6 +60,7 @@ import net.server.world.World;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
|
||||
import client.inventory.MapleInventoryType;
|
||||
import constants.ServerConstants;
|
||||
import scripting.event.EventManager;
|
||||
import scripting.npc.NPCConversationManager;
|
||||
import scripting.npc.NPCScriptManager;
|
||||
@@ -445,6 +446,8 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public boolean checkPic(String other) {
|
||||
if(!ServerConstants.ENABLE_PIC) return true;
|
||||
|
||||
picattempt++;
|
||||
if (picattempt > 5) {
|
||||
getSession().close(true);
|
||||
@@ -899,50 +902,12 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public boolean deleteCharacter(int cid) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
MapleCharacter player = Server.getInstance().getWorld(0).getPlayerStorage().getCharacterById(cid);
|
||||
if (player != null){
|
||||
player.getClient().disconnect(false, false);
|
||||
disconnect(false, false);
|
||||
return false; //DC both and return, fuck that
|
||||
}
|
||||
try {
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT id, guildid, guildrank, name, allianceRank FROM characters WHERE id = ? AND accountid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.setInt(2, accId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
return false;
|
||||
}
|
||||
if (rs.getInt("guildid") > 0) {
|
||||
try {
|
||||
Server.getInstance().deleteGuildCharacter(new MapleGuildCharacter(player, cid, 0, rs.getString("name"), (byte) -1, (byte) -1, 0, rs.getInt("guildrank"), rs.getInt("guildid"), false, rs.getInt("allianceRank")));
|
||||
} catch (Exception re) {
|
||||
re.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM wishlists WHERE charid = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM characters WHERE id = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
String[] toDel = {"famelog", "inventoryitems", "keymap", "queststatus", "savedlocations", "skillmacros", "skills", "eventstats"};
|
||||
for (String s : toDel) {
|
||||
MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM `" + s + "` WHERE characterid = ?", cid);
|
||||
}
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return MapleCharacter.deleteCharFromDB(MapleCharacter.loadCharFromDB(cid, this, false));
|
||||
} catch(SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getAccountName() {
|
||||
|
||||
@@ -26,6 +26,8 @@ import constants.ServerConstants;
|
||||
import constants.ExpTable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import server.MapleItemInformationProvider;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.Pair;
|
||||
@@ -52,7 +54,7 @@ public class Equip extends Item {
|
||||
private float itemExp;
|
||||
private int ringid = -1;
|
||||
private boolean wear = false;
|
||||
private boolean isElemental = false; // timeless or reverse
|
||||
private boolean isUpgradeable, isElemental = false; // timeless or reverse
|
||||
|
||||
public Equip(int id, short position) {
|
||||
this(id, position, 0);
|
||||
@@ -260,6 +262,8 @@ public class Equip extends Item {
|
||||
}
|
||||
|
||||
private int getStatModifier(boolean isAttribute) {
|
||||
// each set of stat points grants a chance for a bonus stat point upgrade at equip level up.
|
||||
|
||||
if(ServerConstants.USE_EQUIPMNT_LVLUP_POWER) {
|
||||
if(isAttribute) return 2;
|
||||
else return 4;
|
||||
@@ -270,11 +274,42 @@ public class Equip extends Item {
|
||||
}
|
||||
}
|
||||
|
||||
private int randomizeStatUpgrade(int limit) {
|
||||
Map<Integer, Integer> pool = new HashMap<>();
|
||||
|
||||
pool.put(0, 1);
|
||||
pool.put(1, 1);
|
||||
for(int i = 2; i <= limit; i++) {
|
||||
for(int j = 0; j < i; j++) {
|
||||
pool.put(j, pool.get(j) + 1);
|
||||
}
|
||||
pool.put(i, 1);
|
||||
}
|
||||
|
||||
int poolCount = 0;
|
||||
for(Integer i: pool.values()) {
|
||||
poolCount += i;
|
||||
}
|
||||
|
||||
int rnd = Randomizer.rand(0, poolCount);
|
||||
int stat = 0;
|
||||
for(Integer i: pool.values()) {
|
||||
if(rnd < i) break;
|
||||
|
||||
stat++;
|
||||
rnd -= i;
|
||||
}
|
||||
|
||||
return(stat);
|
||||
}
|
||||
|
||||
private void getUnitStatUpgrade(List<Pair<String, Integer>> stats, String name, int curStat, boolean isAttribute) {
|
||||
int maxUpgrade = Randomizer.rand(0, 1 + (curStat / getStatModifier(isAttribute)));
|
||||
isUpgradeable = true;
|
||||
|
||||
int maxUpgrade = randomizeStatUpgrade((int)(1 + (curStat / getStatModifier(isAttribute))));
|
||||
if(maxUpgrade == 0) return;
|
||||
|
||||
stats.add(new Pair<>(name, maxUpgrade)); // each 4 stat point grants a bonus stat upgrade on equip level up.
|
||||
stats.add(new Pair<>(name, maxUpgrade));
|
||||
}
|
||||
|
||||
private void getUnitSlotUpgrade(List<Pair<String, Integer>> stats, String name) {
|
||||
@@ -302,76 +337,103 @@ public class Equip extends Item {
|
||||
|
||||
public void gainLevel(MapleClient c) {
|
||||
List<Pair<String, Integer>> stats = MapleItemInformationProvider.getInstance().getItemLevelupStats(getItemId(), itemLevel);
|
||||
if(stats.isEmpty()) improveDefaultStats(stats);
|
||||
|
||||
if(ServerConstants.USE_EQUIPMNT_LVLUP_SLOTS) {
|
||||
getUnitSlotUpgrade(stats, "incVicious");
|
||||
getUnitSlotUpgrade(stats, "incSlot");
|
||||
if(!stats.isEmpty()) {
|
||||
if(ServerConstants.USE_EQUIPMNT_LVLUP_SLOTS) {
|
||||
if(vicious > 0) getUnitSlotUpgrade(stats, "incVicious");
|
||||
getUnitSlotUpgrade(stats, "incSlot");
|
||||
}
|
||||
}
|
||||
else {
|
||||
isUpgradeable = false;
|
||||
|
||||
do {
|
||||
improveDefaultStats(stats);
|
||||
|
||||
if(ServerConstants.USE_EQUIPMNT_LVLUP_SLOTS) {
|
||||
if(vicious > 0) getUnitSlotUpgrade(stats, "incVicious");
|
||||
getUnitSlotUpgrade(stats, "incSlot");
|
||||
}
|
||||
} while(stats.isEmpty() && isUpgradeable);
|
||||
}
|
||||
|
||||
itemLevel++;
|
||||
if(ServerConstants.USE_DEBUG) c.getPlayer().dropMessage(6, "'" + MapleItemInformationProvider.getInstance().getName(this.getItemId()) + "' has LEVELED UP to level " + itemLevel + "!");
|
||||
boolean gotVicious = false, gotSlot = false;
|
||||
|
||||
String lvupStr = "'" + MapleItemInformationProvider.getInstance().getName(this.getItemId()) + "' is now level " + itemLevel + "! ";
|
||||
for (Pair<String, Integer> stat : stats) {
|
||||
switch (stat.getLeft()) {
|
||||
case "incDEX":
|
||||
dex += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "DEX ";
|
||||
break;
|
||||
case "incSTR":
|
||||
str += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "STR ";
|
||||
break;
|
||||
case "incINT":
|
||||
_int += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "INT ";
|
||||
break;
|
||||
case "incLUK":
|
||||
luk += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "LUK ";
|
||||
break;
|
||||
case "incMHP":
|
||||
hp += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "HP ";
|
||||
break;
|
||||
case "incMMP":
|
||||
mp += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "MP ";
|
||||
break;
|
||||
case "incPAD":
|
||||
watk += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "WATK ";
|
||||
break;
|
||||
case "incMAD":
|
||||
matk += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "MATK ";
|
||||
break;
|
||||
case "incPDD":
|
||||
wdef += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "WDEF ";
|
||||
break;
|
||||
case "incMDD":
|
||||
mdef += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "MDEF ";
|
||||
break;
|
||||
case "incEVA":
|
||||
avoid += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "AVOID ";
|
||||
break;
|
||||
case "incACC":
|
||||
acc += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "ACC ";
|
||||
break;
|
||||
case "incSpeed":
|
||||
speed += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "SPEED ";
|
||||
break;
|
||||
case "incJump":
|
||||
jump += stat.getRight();
|
||||
lvupStr += "+" + stat.getRight() + "JUMP ";
|
||||
break;
|
||||
|
||||
case "incVicious":
|
||||
if(vicious > 0) {
|
||||
vicious -= stat.getRight();
|
||||
if(vicious < 0) vicious = 0;
|
||||
|
||||
c.getPlayer().dropMessage(6, "A new Vicious Hammer opportunity has been found on the '" + MapleItemInformationProvider.getInstance().getName(getItemId()) + "'!");
|
||||
}
|
||||
|
||||
vicious -= stat.getRight();
|
||||
gotVicious = true;
|
||||
break;
|
||||
case "incSlot":
|
||||
upgradeSlots += stat.getRight();
|
||||
c.getPlayer().dropMessage(6, "A new upgrade slot has been found on the '" + MapleItemInformationProvider.getInstance().getName(getItemId()) + "'!");
|
||||
gotSlot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
c.getPlayer().dropMessage(6, lvupStr);
|
||||
if(gotVicious) c.getPlayer().dropMessage(6, "A new Vicious Hammer opportunity has been found on the '" + MapleItemInformationProvider.getInstance().getName(getItemId()) + "'!");
|
||||
if(gotSlot) c.getPlayer().dropMessage(6, "A new upgrade slot has been found on the '" + MapleItemInformationProvider.getInstance().getName(getItemId()) + "'!");
|
||||
|
||||
c.announce(MaplePacketCreator.showEquipmentLevelUp());
|
||||
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showForeignEffect(c.getPlayer().getId(), 15));
|
||||
c.getPlayer().forceUpdateItem(this);
|
||||
|
||||
Reference in New Issue
Block a user