Improved login phase + C. scheduler & EXP share & MoveLifeHandler fix
Refactored login system, caching account data, merging some queries and using way less DB queries on login. Server now uses associative tables for character-account and character-world, lowering considerably usage of some DB queries. Fixed getPartyMembersOnSameMap method trying to access disconnected members, promptly throwing nulls. Improved EXP distribution system, now crediting damage-contributing EXP to the party when the player is not present on the map. Improved the "View-all-chars" feature mechanics, not so often disconnecting players for server response timeout anymore. Improved Mystic Doors mechanics, now correctly spawning party players at actual door location on the off-town map. Fixed "fly" command not working properly. All characters of that account are able to use this mechanic (client session limitation). Fixed a critical deadlock issue on the new channel scheduler system. Fixed some mobs not using skills, issue brought on the latest MoveLifeHandler update. Improved slightly skill/movement synergy on the MoveLifeHandler responses. GMs no longer creates Hall-of-fame PlayerNPCs when reaching max class level. Fixed monsterValue script method being triggered multiple times for party members. Fixed pinkbean not dropping items inside expedition. Moved "recharge" command from Donator to JrGM.
This commit is contained in:
@@ -21,9 +21,6 @@
|
||||
*/
|
||||
package net.server;
|
||||
|
||||
import net.server.worker.CharacterDiseaseWorker;
|
||||
import net.server.worker.CouponWorker;
|
||||
import net.server.worker.RankingWorker;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -43,14 +40,22 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import tools.locks.MonitoredReentrantLock;
|
||||
import tools.locks.MonitoredReentrantReadWriteLock;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
import net.MapleServerHandler;
|
||||
import net.mina.MapleCodecFactory;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.guild.MapleAlliance;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.worker.CharacterDiseaseWorker;
|
||||
import net.server.worker.CouponWorker;
|
||||
import net.server.worker.RankingWorker;
|
||||
import net.server.world.World;
|
||||
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
@@ -64,6 +69,8 @@ import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
|
||||
import client.MapleClient;
|
||||
import client.MapleCharacter;
|
||||
import client.SkillFactory;
|
||||
import client.inventory.Item;
|
||||
import client.inventory.ItemFactory;
|
||||
import client.newyear.NewYearCardRecord;
|
||||
import constants.ItemConstants;
|
||||
import constants.GameConstants;
|
||||
@@ -96,14 +103,18 @@ public class Server {
|
||||
private final Map<Integer, MapleGuild> guilds = new HashMap<>(100);
|
||||
private final Map<MapleClient, Long> inLoginState = new HashMap<>(100);
|
||||
private final Lock srvLock = new MonitoredReentrantLock(MonitoredLockType.SERVER);
|
||||
private final Lock lgnLock = new MonitoredReentrantLock(MonitoredLockType.SERVER_LOGIN);
|
||||
private final Lock disLock = new MonitoredReentrantLock(MonitoredLockType.SERVER_DISEASES);
|
||||
private final ReentrantReadWriteLock lgnLock = new MonitoredReentrantReadWriteLock(MonitoredLockType.SERVER_LOGIN, true);
|
||||
private final ReadLock lgnRLock = lgnLock.readLock();
|
||||
private final WriteLock lgnWLock = lgnLock.writeLock();
|
||||
private final PlayerBuffStorage buffStorage = new PlayerBuffStorage();
|
||||
private final Map<Integer, MapleAlliance> alliances = new HashMap<>(100);
|
||||
private final Map<Integer, NewYearCardRecord> newyears = new HashMap<>();
|
||||
private final List<MapleClient> processDiseaseAnnouncePlayers = new LinkedList<>();
|
||||
private final List<MapleClient> registeredDiseaseAnnouncePlayers = new LinkedList<>();
|
||||
|
||||
private final AtomicLong currentTime = new AtomicLong(0);
|
||||
|
||||
private boolean availableDeveloperRoom = false;
|
||||
private boolean online = false;
|
||||
public static long uptime = System.currentTimeMillis();
|
||||
@@ -115,6 +126,20 @@ public class Server {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void updateCurrentTime() {
|
||||
currentTime.addAndGet(ServerConstants.UPDATE_INTERVAL);
|
||||
}
|
||||
|
||||
public long forceUpdateCurrentTime() {
|
||||
long timeNow = System.currentTimeMillis();
|
||||
currentTime.set(timeNow);
|
||||
return timeNow;
|
||||
}
|
||||
|
||||
public long getCurrentTime() { // returns a slightly delayed time value
|
||||
return currentTime.get();
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return online;
|
||||
}
|
||||
@@ -372,7 +397,7 @@ public class Server {
|
||||
disconnectIdlesOnLoginTask();
|
||||
|
||||
long timeLeft = getTimeLeftForNextHour();
|
||||
tMan.register(new CharacterDiseaseWorker(), 777, 777);
|
||||
tMan.register(new CharacterDiseaseWorker(), ServerConstants.UPDATE_INTERVAL, ServerConstants.UPDATE_INTERVAL);
|
||||
tMan.register(new CouponWorker(), ServerConstants.COUPON_INTERVAL, timeLeft);
|
||||
tMan.register(new RankingWorker(), ServerConstants.RANKING_INTERVAL, timeLeft);
|
||||
|
||||
@@ -822,123 +847,223 @@ public class Server {
|
||||
public List<World> getWorlds() {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
private static void loadCharacteridsFromDb(Integer accountid, Set<Integer> accChars) {
|
||||
try {
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT id FROM characters WHERE accountid = ?")) {
|
||||
ps.setInt(1, accountid);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while(rs.next()) {
|
||||
accChars.add(rs.getInt("id"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean haveCharacterid(Integer accountid, Integer chrid) {
|
||||
lgnLock.lock();
|
||||
try {
|
||||
Set<Integer> accChars = accountChars.get(accountid);
|
||||
if(accChars == null) {
|
||||
accChars = new HashSet<>(5);
|
||||
loadCharacteridsFromDb(accountid, accChars);
|
||||
|
||||
accountChars.put(accountid, accChars);
|
||||
}
|
||||
|
||||
return accChars.contains(chrid);
|
||||
} finally {
|
||||
lgnLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void createCharacterid(Integer accountid, Integer chrid, Integer world) {
|
||||
lgnLock.lock();
|
||||
try {
|
||||
Set<Integer> accChars = accountChars.get(accountid);
|
||||
if(accChars == null) {
|
||||
accChars = new HashSet<>(5);
|
||||
accountChars.put(accountid, accChars);
|
||||
}
|
||||
|
||||
accChars.add(chrid);
|
||||
worldChars.put(chrid, world);
|
||||
} finally {
|
||||
lgnLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteCharacterid(Integer accountid, Integer chrid) {
|
||||
lgnLock.lock();
|
||||
try {
|
||||
Set<Integer> accChars = accountChars.get(accountid);
|
||||
if(accChars != null) {
|
||||
accChars.remove(chrid);
|
||||
}
|
||||
|
||||
worldChars.remove(chrid);
|
||||
} finally {
|
||||
lgnLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private static int getCharacterWorldFromDB(int chrid) {
|
||||
int world = -1;
|
||||
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT world FROM characters WHERE id = ?")) {
|
||||
ps.setInt(1, chrid);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if(rs.next()) {
|
||||
world = rs.getInt("world");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
public int getCharacterWorld(Integer chrid) {
|
||||
lgnLock.lock();
|
||||
lgnRLock.lock();
|
||||
try {
|
||||
Integer worldid = worldChars.get(chrid);
|
||||
return worldid != null ? worldid : -1;
|
||||
} finally {
|
||||
lgnRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean haveCharacterEntry(Integer accountid, Integer chrid) {
|
||||
lgnRLock.lock();
|
||||
try {
|
||||
Set<Integer> accChars = accountChars.get(accountid);
|
||||
return accChars.contains(chrid);
|
||||
} finally {
|
||||
lgnRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Integer> getAccountCharacterEntries(Integer accountid) {
|
||||
lgnRLock.lock();
|
||||
try {
|
||||
return new HashSet<>(accountChars.get(accountid));
|
||||
} finally {
|
||||
lgnRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCharacterEntry(MapleCharacter chr) {
|
||||
MapleCharacter chrView = chr.generateCharacterEntry();
|
||||
World wserv = worlds.get(chrView.getWorld());
|
||||
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void createCharacterEntry(MapleCharacter chr) {
|
||||
Integer accountid = chr.getAccountID(), chrid = chr.getId(), world = chr.getWorld();
|
||||
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
Set<Integer> accChars = accountChars.get(accountid);
|
||||
accChars.add(chrid);
|
||||
|
||||
if(worldid == null) {
|
||||
worldid = getCharacterWorldFromDB(chrid);
|
||||
worldChars.put(chrid, worldid);
|
||||
worldChars.put(chrid, world);
|
||||
|
||||
MapleCharacter chrView = chr.generateCharacterEntry();
|
||||
World wserv = worlds.get(chrView.getWorld());
|
||||
wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteCharacterEntry(Integer accountid, Integer chrid) {
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
Set<Integer> accChars = accountChars.get(accountid);
|
||||
accChars.remove(chrid);
|
||||
|
||||
Integer world = worldChars.remove(chrid);
|
||||
if(world != null) {
|
||||
World wserv = worlds.get(world);
|
||||
wserv.unregisterAccountCharacterView(accountid, chrid);
|
||||
}
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void transferWorldCharacterEntry(MapleCharacter chr, Integer toWorld) { // used before setting the new worldid on the character object
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
Integer chrid = chr.getId(), accountid = chr.getAccountID(), world = worldChars.get(chr.getId());
|
||||
if(world != null) {
|
||||
World wserv = worlds.get(world);
|
||||
wserv.unregisterAccountCharacterView(accountid, chrid);
|
||||
}
|
||||
|
||||
return worldid;
|
||||
worldChars.put(chrid, toWorld);
|
||||
|
||||
MapleCharacter chrView = chr.generateCharacterEntry();
|
||||
World wserv = worlds.get(toWorld);
|
||||
wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
} finally {
|
||||
lgnLock.unlock();
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void deleteAccount(Integer accountid) { is this even a thing?
|
||||
lgnLock.lock();
|
||||
public void deleteAccountEntry(Integer accountid) { is this even a thing?
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
accountChars.remove(accountid);
|
||||
} finally {
|
||||
lgnLock.unlock();
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private static List<List<MapleCharacter>> loadAccountCharactersViewFromDb(MapleClient c, int wlen) {
|
||||
List<List<MapleCharacter>> wchars = new ArrayList<>(wlen);
|
||||
for(int i = 0; i < wlen; i++) wchars.add(i, new LinkedList<MapleCharacter>());
|
||||
|
||||
List<MapleCharacter> chars = new LinkedList<>();
|
||||
int curWorld = 0;
|
||||
try {
|
||||
List<Pair<Item, Integer>> accEquips = ItemFactory.loadEquippedItems(c.getAccID(), true, true);
|
||||
Map<Integer, List<Item>> accPlayerEquips = new HashMap<>();
|
||||
|
||||
for(Pair<Item, Integer> ae : accEquips) {
|
||||
List<Item> playerEquips = accPlayerEquips.get(ae.getRight());
|
||||
if(playerEquips == null) {
|
||||
playerEquips = new LinkedList<>();
|
||||
accPlayerEquips.put(ae.getRight(), playerEquips);
|
||||
}
|
||||
|
||||
playerEquips.add(ae.getLeft());
|
||||
}
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE accountid = ? ORDER BY world, id")) {
|
||||
ps.setInt(1, c.getAccID());
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
int cworld = rs.getByte("world");
|
||||
if(cworld >= wlen) break;
|
||||
|
||||
if(cworld > curWorld) {
|
||||
wchars.add(curWorld, chars);
|
||||
|
||||
curWorld = cworld;
|
||||
chars = new LinkedList<>();
|
||||
}
|
||||
|
||||
Integer cid = rs.getInt("id");
|
||||
chars.add(MapleCharacter.loadCharacterEntryFromDB(rs, accPlayerEquips.get(cid)));
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
|
||||
wchars.add(curWorld, chars);
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
|
||||
return wchars;
|
||||
}
|
||||
|
||||
public void loadAccountCharactersView(MapleClient c) {
|
||||
int accId = c.getAccID();
|
||||
int gmLevel = 0;
|
||||
boolean firstAccountLogin;
|
||||
|
||||
lgnRLock.lock();
|
||||
try {
|
||||
firstAccountLogin = !accountChars.containsKey(accId);
|
||||
} finally {
|
||||
lgnRLock.unlock();
|
||||
}
|
||||
|
||||
if(!firstAccountLogin) {
|
||||
Set<Integer> accWorlds = new HashSet<>();
|
||||
|
||||
lgnRLock.lock();
|
||||
try {
|
||||
for(Integer chrid : getAccountCharacterEntries(accId)) {
|
||||
accWorlds.add(worldChars.get(chrid));
|
||||
}
|
||||
} finally {
|
||||
lgnRLock.unlock();
|
||||
}
|
||||
|
||||
for(Integer aw : accWorlds) {
|
||||
for(MapleCharacter chr : worlds.get(aw).getAllCharactersView()) {
|
||||
if(gmLevel < chr.gmLevel()) gmLevel = chr.gmLevel();
|
||||
}
|
||||
}
|
||||
|
||||
c.setGMLevel(gmLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
List<List<MapleCharacter>> accChars = loadAccountCharactersViewFromDb(c, worlds.size());
|
||||
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
Set<Integer> chars = new HashSet<>(5);
|
||||
for(int wid = 0; wid < worlds.size(); wid++) {
|
||||
World w = worlds.get(wid);
|
||||
List<MapleCharacter> wchars = accChars.get(wid);
|
||||
w.loadAccountCharactersView(accId, wchars);
|
||||
|
||||
for(MapleCharacter chr : wchars) {
|
||||
int cid = chr.getId();
|
||||
if(gmLevel < chr.gmLevel()) gmLevel = chr.gmLevel();
|
||||
|
||||
chars.add(cid);
|
||||
worldChars.put(cid, wid);
|
||||
}
|
||||
}
|
||||
|
||||
accountChars.put(accId, chars);
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
|
||||
c.setGMLevel(gmLevel);
|
||||
}
|
||||
|
||||
private static String getRemoteIp(InetSocketAddress isa) {
|
||||
return isa.getAddress().getHostAddress();
|
||||
}
|
||||
@@ -946,23 +1071,23 @@ public class Server {
|
||||
public void setCharacteridInTransition(InetSocketAddress isa, int charId) {
|
||||
String remoteIp = getRemoteIp(isa);
|
||||
|
||||
lgnLock.lock();
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
transitioningChars.put(remoteIp, charId);
|
||||
} finally {
|
||||
lgnLock.unlock();
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateCharacteridInTransition(InetSocketAddress isa, int charId) {
|
||||
String remoteIp = getRemoteIp(isa);
|
||||
|
||||
lgnLock.lock();
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
Integer cid = transitioningChars.remove(remoteIp);
|
||||
return cid != null && cid.equals(charId);
|
||||
} finally {
|
||||
lgnLock.unlock();
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ public final class AdminCommandHandler extends AbstractMaplePacketHandler {
|
||||
MapleMonster monster = (MapleMonster) monsterx.get(x);
|
||||
if (monster.getId() == mobToKill) {
|
||||
c.getPlayer().getMap().killMonster(monster, c.getPlayer(), true);
|
||||
monster.giveExpToCharacter(c.getPlayer(), monster.getExp(), true, 1);
|
||||
//monster.giveExpToCharacter(c.getPlayer(), monster.getExp(), true, 1); already being done
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -24,7 +24,7 @@ package net.server.channel.handlers;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.SendOpcode;
|
||||
import net.opcodes.SendOpcode;
|
||||
import net.server.Server;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
|
||||
@@ -23,17 +23,19 @@ package net.server.channel.handlers;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.inventory.MapleInventoryType;
|
||||
import client.inventory.manipulator.MapleInventoryManipulator;
|
||||
import server.MaplePortal;
|
||||
import server.MapleTrade;
|
||||
import server.maps.MapleMap;
|
||||
import tools.FilePrinter;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.inventory.MapleInventoryType;
|
||||
|
||||
public final class ChangeMapHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@@ -42,6 +44,10 @@ public final class ChangeMapHandler extends AbstractMaplePacketHandler {
|
||||
MapleCharacter chr = c.getPlayer();
|
||||
|
||||
if (chr.isChangingMaps() || chr.isBanned()) {
|
||||
if(chr.isChangingMaps()) {
|
||||
FilePrinter.printError(FilePrinter.PORTAL_STUCK + chr.getName() + ".txt", "Player " + chr.getName() + " got stuck when changing maps. Timestamp: " + Calendar.getInstance().getTime().toString() + " Last visited mapids: " + chr.getLastVisitedMapids());
|
||||
}
|
||||
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
@@ -49,7 +55,7 @@ public final class ChangeMapHandler extends AbstractMaplePacketHandler {
|
||||
MapleTrade.cancelTrade(chr);
|
||||
}
|
||||
if (slea.available() == 0) { //Cash Shop :)
|
||||
if(!chr.getCashShop().isOpened()) {
|
||||
if(!chr.getCashShop().isOpened()) {
|
||||
c.disconnect(false, false);
|
||||
return;
|
||||
}
|
||||
@@ -62,7 +68,7 @@ public final class ChangeMapHandler extends AbstractMaplePacketHandler {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if(chr.getCashShop().isOpened()) {
|
||||
if(chr.getCashShop().isOpened()) {
|
||||
c.disconnect(false, false);
|
||||
return;
|
||||
}
|
||||
@@ -138,21 +144,22 @@ public final class ChangeMapHandler extends AbstractMaplePacketHandler {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
|
||||
if (chr.getMapId() == 109040004) {
|
||||
chr.getFitness().resetTimes();
|
||||
}
|
||||
if (chr.getMapId() == 109030003 || chr.getMapId() == 109030103) {
|
||||
} else if (chr.getMapId() == 109030003 || chr.getMapId() == 109030103) {
|
||||
chr.getOla().resetTimes();
|
||||
}
|
||||
|
||||
if (portal != null) {
|
||||
if(portal.getPosition().distanceSq(chr.getPosition()) > 400000) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
|
||||
portal.enterPortal(c);
|
||||
} else {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -21,10 +21,14 @@
|
||||
*/
|
||||
package net.server.channel.handlers;
|
||||
|
||||
import java.util.Calendar;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import server.maps.MapleDoorObject;
|
||||
import server.maps.MapleMapObject;
|
||||
import tools.FilePrinter;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
|
||||
/**
|
||||
@@ -35,15 +39,29 @@ public final class DoorHandler extends AbstractMaplePacketHandler {
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
int ownerid = slea.readInt();
|
||||
boolean mode = (slea.readByte() == 0); // specifies if backwarp or not, 1 town to target, 0 target to town
|
||||
for (MapleMapObject obj : c.getPlayer().getMap().getMapObjects()) {
|
||||
slea.readByte(); // specifies if backwarp or not, 1 town to target, 0 target to town
|
||||
|
||||
MapleCharacter chr = c.getPlayer();
|
||||
if (chr.isChangingMaps() || chr.isBanned()) {
|
||||
if(chr.isChangingMaps()) {
|
||||
FilePrinter.printError(FilePrinter.PORTAL_STUCK + chr.getName() + ".txt", "Player " + chr.getName() + " got stuck when changing maps (using Mystic Door). Timestamp: " + Calendar.getInstance().getTime().toString() + " Last visited mapids: " + chr.getLastVisitedMapids());
|
||||
}
|
||||
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
|
||||
for (MapleMapObject obj : chr.getMap().getMapObjects()) {
|
||||
if (obj instanceof MapleDoorObject) {
|
||||
MapleDoorObject door = (MapleDoorObject) obj;
|
||||
if (door.getOwnerId() == ownerid) {
|
||||
door.warp(c.getPlayer(), mode);
|
||||
door.warp(chr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.announce(MaplePacketCreator.blockedMessage(6));
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class EnterCashShopHandler extends AbstractMaplePacketHandler {
|
||||
c.getChannelServer().removePlayer(mc);
|
||||
mc.getMap().removePlayer(mc);
|
||||
mc.getCashShop().open(true);
|
||||
mc.saveToDB();
|
||||
mc.saveCharToDB();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public final class EnterMTSHandler extends AbstractMaplePacketHandler {
|
||||
chr.forfeitExpirableQuests();
|
||||
chr.cancelQuestExpirationTask();
|
||||
|
||||
chr.saveToDB();
|
||||
chr.saveCharToDB();
|
||||
chr.getMap().removePlayer(c.getPlayer());
|
||||
try {
|
||||
c.announce(MaplePacketCreator.openCashShop(c, true));
|
||||
|
||||
@@ -25,7 +25,7 @@ import constants.ServerConstants;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.SendOpcode;
|
||||
import net.opcodes.SendOpcode;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
import tools.data.output.MaplePacketLittleEndianWriter;
|
||||
|
||||
|
||||
@@ -26,12 +26,14 @@ import client.MapleClient;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.server.Server;
|
||||
import server.life.MapleMonster;
|
||||
import server.life.MapleMonsterInformationProvider;
|
||||
//import server.life.MobAttackInfo;
|
||||
//import server.life.MobAttackInfoFactory;
|
||||
import server.life.MobSkill;
|
||||
import server.life.MobSkillFactory;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
import server.maps.MapleMapObjectType;
|
||||
import server.movement.LifeMovementFragment;
|
||||
@@ -48,9 +50,12 @@ import tools.data.input.SeekableLittleEndianAccessor;
|
||||
public final class MoveLifeHandler extends AbstractMovementPacketHandler {
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
MapleCharacter player = c.getPlayer();
|
||||
MapleMap map = player.getMap();
|
||||
|
||||
int objectid = slea.readInt();
|
||||
short moveid = slea.readShort();
|
||||
MapleMapObject mmo = c.getPlayer().getMap().getMapObject(objectid);
|
||||
MapleMapObject mmo = map.getMapObject(objectid);
|
||||
if (mmo == null || mmo.getType() != MapleMapObjectType.MONSTER) {
|
||||
return;
|
||||
}
|
||||
@@ -95,8 +100,18 @@ public final class MoveLifeHandler extends AbstractMovementPacketHandler {
|
||||
nextCastSkill = skillToUse.getLeft();
|
||||
nextCastSkillLevel = skillToUse.getRight();
|
||||
toUse = MobSkillFactory.getMobSkill(nextCastSkill, nextCastSkillLevel);
|
||||
|
||||
if (!isSkill && !isAttack) {
|
||||
long curtime = Server.getInstance().getCurrentTime();
|
||||
if(curtime >= monster.getNextBasicSkillTime()) { // dont use the special attack too often, chase the player f3
|
||||
//MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
|
||||
monster.setNextBasicSkillTime(curtime);
|
||||
} else {
|
||||
toUse = null; // paliative measure for suspicious mob movement
|
||||
}
|
||||
}
|
||||
|
||||
if (isSkill || isAttack) {
|
||||
if (toUse != null) {
|
||||
int percHpLeft = (int) (((float) monster.getHp() / monster.getMaxHp()) * 100);
|
||||
if (nextCastSkill != toUse.getSkillId() || nextCastSkillLevel != toUse.getSkillLevel()) {
|
||||
//toUse.resetAnticipatedSkill();
|
||||
@@ -106,25 +121,13 @@ public final class MoveLifeHandler extends AbstractMovementPacketHandler {
|
||||
} else if (monster.canUseSkill(toUse)) {
|
||||
int animationTime = MapleMonsterInformationProvider.getInstance().getMobSkillAnimationTime(monster.getId(), rndSkill);
|
||||
if(animationTime > 0) {
|
||||
toUse.applyDelayedEffect(c.getPlayer(), monster, true, banishPlayers, animationTime);
|
||||
toUse.applyDelayedEffect(player, monster, true, banishPlayers, animationTime);
|
||||
} else {
|
||||
toUse.applyEffect(c.getPlayer(), monster, true, banishPlayers);
|
||||
toUse.applyEffect(player, monster, true, banishPlayers);
|
||||
}
|
||||
} else {
|
||||
toUse = null;
|
||||
}
|
||||
} else {
|
||||
toUse = null; // paliative measure for suspicious mob movement
|
||||
|
||||
/*
|
||||
long curtime = System.currentTimeMillis();
|
||||
if(curtime >= monster.getNextBasicSkillTime()) { // dont use the special attack too often, chase the player f3
|
||||
MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
|
||||
monster.setNextBasicSkillTime(curtime);
|
||||
} else {
|
||||
toUse = null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -133,35 +136,44 @@ public final class MoveLifeHandler extends AbstractMovementPacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if(toUse == null) {
|
||||
useSkillId = 0;
|
||||
useSkillLevel = 0;
|
||||
rawActivity = -1;
|
||||
pOption = 0;
|
||||
}
|
||||
|
||||
slea.readByte();
|
||||
slea.readInt(); // whatever
|
||||
short start_x = slea.readShort(); // hmm.. startpos?
|
||||
short start_y = slea.readShort(); // hmm...
|
||||
Point startPos = new Point(start_x, start_y);
|
||||
res = parseMovement(slea);
|
||||
if (monster.getController() != c.getPlayer()) {
|
||||
if (monster.isAttackedBy(c.getPlayer())) {
|
||||
monster.switchController(c.getPlayer(), true);
|
||||
if (monster.getController() != player) {
|
||||
if (monster.isAttackedBy(player)) {
|
||||
monster.switchController(player, true);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (rawActivity == -1 && monster.isControllerKnowsAboutAggro() && !monster.isMobile() && !monster.isFirstAttack()) {
|
||||
monster.setControllerHasAggro(false);
|
||||
monster.setControllerHasAggro(false);
|
||||
monster.setControllerKnowsAboutAggro(false);
|
||||
}
|
||||
boolean aggro = monster.isControllerHasAggro();
|
||||
if (toUse != null) {
|
||||
c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro, toUse.getSkillId(), toUse.getSkillLevel()));
|
||||
|
||||
if (toUse != null) {
|
||||
c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro, toUse.getSkillId(), toUse.getSkillLevel()));
|
||||
} else {
|
||||
c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro));
|
||||
}
|
||||
|
||||
if (aggro) {
|
||||
monster.setControllerKnowsAboutAggro(true);
|
||||
}
|
||||
if (res != null) {
|
||||
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.moveMonster(objectid, nextMovementCouldBeSkill, rawActivity, useSkillId, useSkillLevel, pOption, startPos, res), monster.getPosition());
|
||||
map.broadcastMessage(player, MaplePacketCreator.moveMonster(objectid, nextMovementCouldBeSkill, rawActivity, useSkillId, useSkillLevel, pOption, startPos, res), monster.getPosition());
|
||||
updatePosition(res, monster, -1);
|
||||
c.getPlayer().getMap().moveMonster(monster, monster.getPosition());
|
||||
map.moveMonster(monster, monster.getPosition());
|
||||
}
|
||||
|
||||
for (MapleCharacter chr : banishPlayers) {
|
||||
|
||||
@@ -23,7 +23,7 @@ package net.server.channel.handlers;
|
||||
|
||||
import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.SendOpcode;
|
||||
import net.opcodes.SendOpcode;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
import tools.data.output.MaplePacketLittleEndianWriter;
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2018 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.server.channel.handlers;
|
||||
|
||||
import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public final class PlayerMapTransitionHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
c.getPlayer().setMapTransitionComplete();
|
||||
}
|
||||
}
|
||||
@@ -26,9 +26,7 @@ import net.AbstractMaplePacketHandler;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
|
||||
public final class PlayerUpdateHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
c.getPlayer().setMapTransitionComplete();
|
||||
}
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
This file is part of the HeavenMS (MapleSolaxiaV2) MapleStory Server
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2018 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
This file is part of the HeavenMS (MapleSolaxiaV2) MapleStory Server
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2018 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
This file is part of the HeavenMS (MapleSolaxiaV2) MapleStory Server
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2018 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
This file is part of the HeavenMS (MapleSolaxiaV2) MapleStory Server
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2018 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
This file is part of the HeavenMS (MapleSolaxiaV2) MapleStory Server
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2018 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -60,6 +60,8 @@ public abstract class BaseScheduler {
|
||||
}
|
||||
|
||||
private void runBaseSchedule() {
|
||||
List<Object> toRemove;
|
||||
|
||||
schedulerLock.lock();
|
||||
try {
|
||||
if(registeredEntries.isEmpty()) {
|
||||
@@ -77,7 +79,7 @@ public abstract class BaseScheduler {
|
||||
idleProcs = 0;
|
||||
|
||||
long timeNow = System.currentTimeMillis();
|
||||
List<Object> toRemove = new LinkedList<>();
|
||||
toRemove = new LinkedList<>();
|
||||
for(Entry<Object, Pair<Runnable, Long>> rmd : registeredEntries.entrySet()) {
|
||||
Pair<Runnable, Long> r = rmd.getValue();
|
||||
|
||||
@@ -90,17 +92,11 @@ public abstract class BaseScheduler {
|
||||
for(Object mse : toRemove) {
|
||||
registeredEntries.remove(mse);
|
||||
}
|
||||
|
||||
dispatchRemovedEntries(toRemove, true);
|
||||
} finally {
|
||||
schedulerLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchRemovedEntries(List<Object> toRemove, boolean fromUpdate) {
|
||||
for (SchedulerListener listener : listeners.toArray(new SchedulerListener[listeners.size()])) {
|
||||
listener.removedScheduledEntries(toRemove, fromUpdate);
|
||||
}
|
||||
|
||||
dispatchRemovedEntries(toRemove, true);
|
||||
}
|
||||
|
||||
protected void registerEntry(Object key, Runnable removalAction, long duration) {
|
||||
@@ -122,10 +118,16 @@ public abstract class BaseScheduler {
|
||||
try {
|
||||
Pair<Runnable, Long> rm = registeredEntries.remove(key);
|
||||
if(rm != null) rm.getLeft().run();
|
||||
|
||||
dispatchRemovedEntries(Collections.singletonList(key), false);
|
||||
} finally {
|
||||
schedulerLock.unlock();
|
||||
}
|
||||
|
||||
dispatchRemovedEntries(Collections.singletonList(key), false);
|
||||
}
|
||||
|
||||
private void dispatchRemovedEntries(List<Object> toRemove, boolean fromUpdate) {
|
||||
for (SchedulerListener listener : listeners.toArray(new SchedulerListener[listeners.size()])) {
|
||||
listener.removedScheduledEntries(toRemove, fromUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,9 @@ public class MobAnimationScheduler extends BaseScheduler {
|
||||
public boolean registerAnimationMode(Integer mobHash, long animationTime) {
|
||||
animationLock.lock();
|
||||
try {
|
||||
if(onAnimationMobs.contains(mobHash)) return false;
|
||||
if(onAnimationMobs.contains(mobHash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
registerEntry(mobHash, r, animationTime);
|
||||
onAnimationMobs.add(mobHash);
|
||||
|
||||
@@ -30,7 +30,6 @@ public final class AfterLoginHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
|
||||
byte c2 = slea.readByte();
|
||||
byte c3 = 5;
|
||||
if (slea.available() > 0) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class CharSelectedHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
|
||||
Server server = Server.getInstance();
|
||||
if(!server.haveCharacterid(c.getAccID(), charId)) {
|
||||
if(!server.haveCharacterEntry(c.getAccID(), charId)) {
|
||||
c.getSession().close(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class CharSelectedWithPicHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
|
||||
Server server = Server.getInstance();
|
||||
if(!server.haveCharacterid(c.getAccID(), charId)) {
|
||||
if(!server.haveCharacterEntry(c.getAccID(), charId)) {
|
||||
c.getSession().close(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ public final class LoginPasswordHandler implements MaplePacketHandler {
|
||||
}
|
||||
|
||||
private static void login(MapleClient c){
|
||||
Server.getInstance().loadAccountCharactersView(c); // locks the login session until data is recovered from the cache or the DB.
|
||||
c.announce(MaplePacketCreator.getAuthSuccess(c));//why the fk did I do c.getAccountName()?
|
||||
|
||||
Server.getInstance().registerLoginState(c);
|
||||
|
||||
@@ -27,7 +27,7 @@ public final class RegisterPicHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
|
||||
Server server = Server.getInstance();
|
||||
if(!server.haveCharacterid(c.getAccID(), charId)) {
|
||||
if(!server.haveCharacterEntry(c.getAccID(), charId)) {
|
||||
c.getSession().close(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,10 +32,13 @@ public final class ServerStatusRequestHandler extends AbstractMaplePacketHandler
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
byte world = (byte) slea.readShort();//Wuuu? ):
|
||||
byte world = (byte) slea.readShort();
|
||||
World wserv = Server.getInstance().getWorld(world);
|
||||
int status = wserv.getWorldCapacityStatus();
|
||||
|
||||
c.announce(MaplePacketCreator.getServerStatus(status));
|
||||
if(wserv != null) {
|
||||
int status = wserv.getWorldCapacityStatus();
|
||||
c.announce(MaplePacketCreator.getServerStatus(status));
|
||||
} else {
|
||||
c.announce(MaplePacketCreator.getServerStatus(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
80
src/net/server/handlers/login/ViewAllCharHandler.java
Normal file
80
src/net/server/handlers/login/ViewAllCharHandler.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.handlers.login;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import constants.ServerConstants;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.server.Server;
|
||||
import net.server.world.World;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
import tools.Pair;
|
||||
|
||||
public final class ViewAllCharHandler extends AbstractMaplePacketHandler {
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
try {
|
||||
List<World> wlist = Server.getInstance().getWorlds();
|
||||
List<Pair<Integer, List<MapleCharacter>>> worldChars = new ArrayList<>(wlist.size() + 1);
|
||||
|
||||
int chrTotal = 0;
|
||||
int accountId = c.getAccID();
|
||||
List<MapleCharacter> lastwchars = null;
|
||||
for(World w : wlist) {
|
||||
List<MapleCharacter> wchars = w.getAccountCharactersView(accountId);
|
||||
|
||||
if(!wchars.isEmpty()) {
|
||||
lastwchars = wchars;
|
||||
|
||||
worldChars.add(new Pair<>(w.getId(), wchars));
|
||||
chrTotal += wchars.size();
|
||||
}
|
||||
}
|
||||
|
||||
if (chrTotal > 9) {
|
||||
int padRight = chrTotal % 3;
|
||||
if (padRight > 0 && lastwchars != null) {
|
||||
MapleCharacter chr = lastwchars.get(lastwchars.size() - 1);
|
||||
|
||||
for(int i = padRight; i < 3; i++) { // filling the remaining slots with the last character loaded
|
||||
chrTotal++;
|
||||
lastwchars.add(chr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int charsSize = chrTotal;
|
||||
int unk = charsSize + (3 - charsSize % 3); //rowSize?
|
||||
c.announce(MaplePacketCreator.showAllCharacter(charsSize, unk));
|
||||
|
||||
for (Pair<Integer, List<MapleCharacter>> wchars : worldChars) {
|
||||
c.announce(MaplePacketCreator.showAllCharacterInfo(wchars.getLeft(), wchars.getRight(), ServerConstants.ENABLE_PIC));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import tools.MaplePacketCreator;
|
||||
import tools.Randomizer;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
|
||||
public final class ViewAllPicRegisterHandler extends AbstractMaplePacketHandler { //Gey class name lol
|
||||
public final class ViewAllCharRegisterPicHandler extends AbstractMaplePacketHandler { //Gey class name lol
|
||||
|
||||
|
||||
@Override
|
||||
@@ -20,7 +20,7 @@ public final class ViewAllPicRegisterHandler extends AbstractMaplePacketHandler
|
||||
slea.readInt(); // please don't let the client choose which world they should login
|
||||
|
||||
Server server = Server.getInstance();
|
||||
if(!server.haveCharacterid(c.getAccID(), charId)) {
|
||||
if(!server.haveCharacterEntry(c.getAccID(), charId)) {
|
||||
c.getSession().close(true);
|
||||
return;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public final class ViewAllPicRegisterHandler extends AbstractMaplePacketHandler
|
||||
return;
|
||||
}
|
||||
|
||||
int channel = Randomizer.rand(0, server.getWorld(c.getWorld()).getChannels().size());
|
||||
int channel = Randomizer.rand(1, server.getWorld(c.getWorld()).getChannels().size());
|
||||
c.setChannel(channel);
|
||||
|
||||
String mac = slea.readMapleAsciiString();
|
||||
@@ -31,7 +31,7 @@ import tools.MaplePacketCreator;
|
||||
import tools.Randomizer;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
|
||||
public final class PickCharHandler extends AbstractMaplePacketHandler {
|
||||
public final class ViewAllCharSelectedHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
@@ -39,7 +39,7 @@ public final class PickCharHandler extends AbstractMaplePacketHandler {
|
||||
slea.readInt(); // please don't let the client choose which world they should login
|
||||
|
||||
Server server = Server.getInstance();
|
||||
if(!server.haveCharacterid(c.getAccID(), charId)) {
|
||||
if(!server.haveCharacterEntry(c.getAccID(), charId)) {
|
||||
c.getSession().close(true);
|
||||
return;
|
||||
}
|
||||
@@ -58,7 +58,8 @@ public final class PickCharHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
|
||||
try {
|
||||
c.setChannel(Randomizer.nextInt(c.getWorldServer().getChannels().size()));
|
||||
int channel = Randomizer.rand(1, c.getWorldServer().getChannels().size());
|
||||
c.setChannel(channel);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
c.setChannel(1);
|
||||
@@ -21,13 +21,13 @@ public class ViewAllCharSelectedWithPicHandler extends AbstractMaplePacketHandle
|
||||
slea.readInt(); // please don't let the client choose which world they should login
|
||||
|
||||
Server server = Server.getInstance();
|
||||
if(!server.haveCharacterid(c.getAccID(), charId)) {
|
||||
if(!server.haveCharacterEntry(c.getAccID(), charId)) {
|
||||
c.getSession().close(true);
|
||||
return;
|
||||
}
|
||||
|
||||
c.setWorld(server.getCharacterWorld(charId));
|
||||
int channel = Randomizer.rand(0, c.getWorldServer().getChannels().size());
|
||||
int channel = Randomizer.rand(1, c.getWorldServer().getChannels().size());
|
||||
c.setChannel(channel);
|
||||
|
||||
String macs = slea.readMapleAsciiString();
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.handlers.login;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.server.Server;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
|
||||
public final class ViewCharHandler extends AbstractMaplePacketHandler {
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
try {
|
||||
short charsNum;
|
||||
List<Integer> worlds;
|
||||
List<MapleCharacter> chars;
|
||||
|
||||
int wlen = Server.getInstance().getWorlds().size();
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT world, id FROM characters WHERE accountid = ?")) {
|
||||
ps.setInt(1, c.getAccID());
|
||||
charsNum = 0;
|
||||
worlds = new ArrayList<>();
|
||||
chars = new ArrayList<>();
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
int cworld = rs.getByte("world");
|
||||
if(cworld >= wlen) continue;
|
||||
|
||||
boolean inside = false;
|
||||
for (int w : worlds) {
|
||||
if (w == cworld) {
|
||||
inside = true;
|
||||
}
|
||||
}
|
||||
if (!inside) {
|
||||
worlds.add(cworld);
|
||||
}
|
||||
MapleCharacter chr = MapleCharacter.loadCharFromDB(rs.getInt("id"), c, false);
|
||||
chars.add(chr);
|
||||
charsNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
int unk = charsNum + 3 - charsNum % 3;
|
||||
c.announce(MaplePacketCreator.showAllCharacter(charsNum, unk));
|
||||
for (Iterator<Integer> it = worlds.iterator(); it.hasNext();) {
|
||||
int w = it.next();
|
||||
List<MapleCharacter> chrsinworld = new ArrayList<>();
|
||||
for (MapleCharacter chr : chars) {
|
||||
if (chr.getWorld() == w) {
|
||||
chrsinworld.add(chr);
|
||||
}
|
||||
}
|
||||
c.announce(MaplePacketCreator.showAllCharacterInfo(w, chrsinworld));
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class CharacterAutosaverWorker extends BaseWorker implements Runnable {
|
||||
PlayerStorage ps = wserv.getPlayerStorage();
|
||||
for(MapleCharacter chr: ps.getAllCharacters()) {
|
||||
if(chr != null && chr.isLoggedin()) {
|
||||
chr.saveToDB(false);
|
||||
chr.saveCharToDB(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ import net.server.Server;
|
||||
public class CharacterDiseaseWorker implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
Server.getInstance().runAnnouncePlayerDiseasesSchedule();
|
||||
Server serv = Server.getInstance();
|
||||
|
||||
serv.updateCurrentTime();
|
||||
serv.runAnnouncePlayerDiseasesSchedule();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
This file is part of the HeavenMS (MapleSolaxiaV2) MapleStory Server
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2017 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
@@ -43,6 +44,8 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import tools.locks.MonitoredReentrantLock;
|
||||
@@ -77,7 +80,7 @@ import tools.locks.MonitoredLockType;
|
||||
/**
|
||||
*
|
||||
* @author kevintjuh93
|
||||
* @author Ronan (thread-oriented world schedules)
|
||||
* @author Ronan (thread-oriented world schedules, guild queue, marriages & party chars)
|
||||
*/
|
||||
public class World {
|
||||
|
||||
@@ -94,10 +97,14 @@ public class World {
|
||||
private Map<Integer, MapleGuildSummary> gsStore = new HashMap<>();
|
||||
private PlayerStorage players = new PlayerStorage();
|
||||
|
||||
private Map<Integer, SortedMap<Integer, MapleCharacter>> accountChars = new HashMap<>();
|
||||
private Lock accountCharsLock = new MonitoredReentrantLock(MonitoredLockType.WORLD_CHARS, true);
|
||||
|
||||
private Set<Integer> queuedGuilds = new HashSet<>();
|
||||
private Map<Integer, Pair<Pair<Boolean, Boolean>, Pair<Integer, Integer>>> queuedMarriages = new HashMap<>();
|
||||
private Map<Integer, Set<Integer>> marriageGuests = new HashMap<>();
|
||||
|
||||
private Map<Integer, Integer> partyChars = new HashMap<>();
|
||||
private Map<Integer, MapleParty> parties = new HashMap<>();
|
||||
private AtomicInteger runningPartyId = new AtomicInteger();
|
||||
private Lock partyLock = new MonitoredReentrantLock(MonitoredLockType.WORLD_PARTY, true);
|
||||
@@ -242,6 +249,87 @@ public class World {
|
||||
this.questrate = quest;
|
||||
}
|
||||
|
||||
public void loadAccountCharactersView(Integer accountId, List<MapleCharacter> chars) {
|
||||
SortedMap<Integer, MapleCharacter> charsMap = new TreeMap<>();
|
||||
for(MapleCharacter chr : chars) {
|
||||
charsMap.put(chr.getId(), chr);
|
||||
}
|
||||
|
||||
accountCharsLock.lock(); // accountCharsLock should be used after server's lgnWLock for compliance
|
||||
try {
|
||||
accountChars.put(accountId, charsMap);
|
||||
} finally {
|
||||
accountCharsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerAccountCharacterView(Integer accountId, MapleCharacter chr) {
|
||||
accountCharsLock.lock();
|
||||
try {
|
||||
accountChars.get(accountId).put(chr.getId(), chr);
|
||||
} finally {
|
||||
accountCharsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterAccountCharacterView(Integer accountId, Integer chrId) {
|
||||
accountCharsLock.lock();
|
||||
try {
|
||||
accountChars.get(accountId).remove(chrId);
|
||||
} finally {
|
||||
accountCharsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Entry<Integer, SortedMap<Integer, MapleCharacter>>> getSortedAccountCharacterView(Map<Integer, SortedMap<Integer, MapleCharacter>> map) {
|
||||
List<Entry<Integer, SortedMap<Integer, MapleCharacter>>> list = new ArrayList<>(map.size());
|
||||
for(Entry<Integer, SortedMap<Integer, MapleCharacter>> e : map.entrySet()) {
|
||||
list.add(e);
|
||||
}
|
||||
|
||||
Collections.sort(list, new Comparator<Entry<Integer, SortedMap<Integer, MapleCharacter>>>() {
|
||||
@Override
|
||||
public int compare(Entry<Integer, SortedMap<Integer, MapleCharacter>> o1, Entry<Integer, SortedMap<Integer, MapleCharacter>> o2) {
|
||||
return o1.getKey() - o2.getKey();
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<MapleCharacter> getAllCharactersView() { // sorted by accountid, charid
|
||||
List<MapleCharacter> chrList = new LinkedList<>();
|
||||
Map<Integer, SortedMap<Integer, MapleCharacter>> accChars;
|
||||
|
||||
accountCharsLock.lock();
|
||||
try {
|
||||
accChars = new HashMap<>(accountChars);
|
||||
} finally {
|
||||
accountCharsLock.unlock();
|
||||
}
|
||||
|
||||
for (Entry<Integer, SortedMap<Integer, MapleCharacter>> e : getSortedAccountCharacterView(accChars)) {
|
||||
for (MapleCharacter chr : e.getValue().values()) {
|
||||
chrList.add(chr);
|
||||
}
|
||||
}
|
||||
|
||||
return chrList;
|
||||
}
|
||||
|
||||
public List<MapleCharacter> getAccountCharactersView(Integer accountId) {
|
||||
List<MapleCharacter> chrList;
|
||||
|
||||
accountCharsLock.lock();
|
||||
try {
|
||||
chrList = new LinkedList<>(accountChars.get(accountId).values());
|
||||
} finally {
|
||||
accountCharsLock.unlock();
|
||||
}
|
||||
|
||||
return chrList;
|
||||
}
|
||||
|
||||
public PlayerStorage getPlayerStorage() {
|
||||
return players;
|
||||
}
|
||||
@@ -511,6 +599,37 @@ public class World {
|
||||
System.out.println("Guest list: " + marriageGuests);
|
||||
}
|
||||
|
||||
private void registerCharacterParty(Integer chrid, Integer partyid) {
|
||||
partyLock.lock();
|
||||
try {
|
||||
partyChars.put(chrid, partyid);
|
||||
} finally {
|
||||
partyLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterCharacterPartyInternal(Integer chrid) {
|
||||
partyChars.remove(chrid);
|
||||
}
|
||||
|
||||
private void unregisterCharacterParty(Integer chrid) {
|
||||
partyLock.lock();
|
||||
try {
|
||||
unregisterCharacterPartyInternal(chrid);
|
||||
} finally {
|
||||
partyLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getCharacterPartyid(Integer chrid) {
|
||||
partyLock.lock();
|
||||
try {
|
||||
return partyChars.get(chrid);
|
||||
} finally {
|
||||
partyLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public MapleParty createParty(MaplePartyCharacter chrfor) {
|
||||
int partyid = runningPartyId.getAndIncrement();
|
||||
MapleParty party = new MapleParty(partyid, chrfor);
|
||||
@@ -518,6 +637,7 @@ public class World {
|
||||
partyLock.lock();
|
||||
try {
|
||||
parties.put(party.getId(), party);
|
||||
registerCharacterParty(chrfor.getId(), partyid);
|
||||
} finally {
|
||||
partyLock.unlock();
|
||||
}
|
||||
@@ -534,7 +654,7 @@ public class World {
|
||||
}
|
||||
}
|
||||
|
||||
public MapleParty disbandParty(int partyid) {
|
||||
private MapleParty disbandParty(int partyid) {
|
||||
partyLock.lock();
|
||||
try {
|
||||
return parties.remove(partyid);
|
||||
@@ -542,9 +662,39 @@ public class World {
|
||||
partyLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateParty(MapleParty party, PartyOperation operation, MaplePartyCharacter target) {
|
||||
for (MaplePartyCharacter partychar : party.getMembers()) {
|
||||
|
||||
private void updateCharacterParty(MapleParty party, PartyOperation operation, MaplePartyCharacter target, Collection<MaplePartyCharacter> partyMembers) {
|
||||
switch (operation) {
|
||||
case JOIN:
|
||||
registerCharacterParty(target.getId(), party.getId());
|
||||
break;
|
||||
|
||||
case LEAVE:
|
||||
case EXPEL:
|
||||
unregisterCharacterParty(target.getId());
|
||||
break;
|
||||
|
||||
case DISBAND:
|
||||
partyLock.lock();
|
||||
try {
|
||||
for (MaplePartyCharacter partychar : partyMembers) {
|
||||
unregisterCharacterPartyInternal(partychar.getId());
|
||||
}
|
||||
} finally {
|
||||
partyLock.unlock();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateParty(MapleParty party, PartyOperation operation, MaplePartyCharacter target) {
|
||||
Collection<MaplePartyCharacter> partyMembers = party.getMembers();
|
||||
updateCharacterParty(party, operation, target, partyMembers);
|
||||
|
||||
for (MaplePartyCharacter partychar : partyMembers) {
|
||||
MapleCharacter chr = getPlayerStorage().getCharacterByName(partychar.getName());
|
||||
if (chr != null) {
|
||||
if (operation == PartyOperation.DISBAND) {
|
||||
|
||||
Reference in New Issue
Block a user