mirror of
https://github.com/moparisthebest/MoparClassic
synced 2024-12-21 23:18:52 -05:00
Framework to resolve issue #24 -- uses the DataStore interface and
DataStoreFactory to read data from a DataStore. A new DataStore needs to be implemented to remove the XStream dependency. Methods to save each type of data need to be implemented.
This commit is contained in:
parent
1f064e322a
commit
978de20d53
@ -78,4 +78,7 @@
|
||||
<entry key="alert-config">conf/alert-config.xml</entry>
|
||||
<!-- Location of configuration file for commands -->
|
||||
<entry key="command-config">conf/command-config.xml</entry>
|
||||
|
||||
<!-- The class that should be used for the DataStore -->
|
||||
<entry key="data-store">org.moparscape.msc.gs.persistence.impl.XMLUsingXStream</entry>
|
||||
</properties>
|
||||
|
@ -15,5 +15,8 @@
|
||||
<dependency org="commons-collections" name="commons-collections" rev="3.2.1"/>
|
||||
|
||||
<dependency org="org.slf4j" name="slf4j-simple" rev="1.6.3"/>
|
||||
|
||||
<dependency org="net.jcip" name="jcip-annotations" rev="1.0"/>
|
||||
|
||||
</dependencies>
|
||||
</ivy-module>
|
||||
|
@ -42,6 +42,7 @@ public class Config {
|
||||
public static boolean OS_LEVEL_BLOCKING, APPLICATION_LEVEL_THROTTLE_ALERT,
|
||||
OS_LEVEL_THROTTLE_ALERT, OS_LEVEL_UNBLOCK_FAILED_ALERT,
|
||||
CONGRATS_FOR_MAX_LEVEL;
|
||||
public static String DATA_STORE;
|
||||
|
||||
static {
|
||||
loadEnv();
|
||||
@ -127,6 +128,8 @@ public class Config {
|
||||
.getProperty("wild-combat-bonus"));
|
||||
CONGRATS_FOR_MAX_LEVEL = Boolean.parseBoolean(props
|
||||
.getProperty("max-level-congrats"));
|
||||
|
||||
DATA_STORE = props.getProperty("data-store");
|
||||
|
||||
props.clear();
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package org.moparscape.msc.gs;
|
||||
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.core.DelayedEventHandler;
|
||||
import org.moparscape.msc.gs.db.DBConnection;
|
||||
import org.moparscape.msc.gs.db.ReportHandlerQueries;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.persistence.DataStore;
|
||||
import org.moparscape.msc.gs.persistence.DataStoreFactory;
|
||||
import org.moparscape.msc.gs.plugins.dependencies.PluginHandler;
|
||||
|
||||
/**
|
||||
@ -33,4 +36,23 @@ public class Instance {
|
||||
public static ReportHandlerQueries getReport() {
|
||||
return DBConnection.getReport();
|
||||
}
|
||||
|
||||
private static DataStore dataStore;
|
||||
|
||||
private static void createDataStore() {
|
||||
try {
|
||||
dataStore = DataStoreFactory.create(Config.DATA_STORE);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Could not create DataStore - " + Config.DATA_STORE);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static DataStore getDataStore() {
|
||||
if(dataStore == null) {
|
||||
createDataStore();
|
||||
}
|
||||
return dataStore;
|
||||
}
|
||||
}
|
||||
|
@ -26,14 +26,13 @@ import org.moparscape.msc.gs.phandler.PacketHandlerDef;
|
||||
import org.moparscape.msc.gs.plugins.dependencies.NpcAI;
|
||||
import org.moparscape.msc.gs.tools.Captcha;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.gs.util.PersistenceManager;
|
||||
|
||||
/**
|
||||
* The central motor of the game. This class is responsible for the primary
|
||||
* operation of the entire game.
|
||||
*/
|
||||
public final class GameEngine extends Thread {
|
||||
|
||||
|
||||
private static Captcha captcha;
|
||||
/**
|
||||
* World instance
|
||||
@ -149,8 +148,7 @@ public final class GameEngine extends Thread {
|
||||
* Loads the packet handling classes from the persistence manager.
|
||||
*/
|
||||
protected void loadPacketHandlers() {
|
||||
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager
|
||||
.load("PacketHandlers.xml");
|
||||
PacketHandlerDef[] handlerDefs = Instance.getDataStore().loadPacketHandlerDefs();
|
||||
for (PacketHandlerDef handlerDef : handlerDefs) {
|
||||
try {
|
||||
String className = handlerDef.getClassName();
|
||||
|
@ -11,6 +11,7 @@ import org.apache.mina.transport.socket.nio.SocketConnector;
|
||||
import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
|
||||
import org.apache.mina.transport.socket.nio.SocketSessionConfig;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.builders.ls.MiscPacketBuilder;
|
||||
import org.moparscape.msc.gs.connection.LSConnectionHandler;
|
||||
import org.moparscape.msc.gs.connection.LSPacket;
|
||||
@ -18,7 +19,6 @@ import org.moparscape.msc.gs.connection.PacketQueue;
|
||||
import org.moparscape.msc.gs.phandler.PacketHandler;
|
||||
import org.moparscape.msc.gs.phandler.PacketHandlerDef;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.gs.util.PersistenceManager;
|
||||
|
||||
public class LoginConnector {
|
||||
/**
|
||||
@ -139,8 +139,7 @@ public class LoginConnector {
|
||||
}
|
||||
|
||||
private void loadPacketHandlers() {
|
||||
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager
|
||||
.load("LSPacketHandlers.xml");
|
||||
PacketHandlerDef[] handlerDefs = Instance.getDataStore().loadLSPacketHandlerDefs();
|
||||
for (PacketHandlerDef handlerDef : handlerDefs) {
|
||||
try {
|
||||
String className = handlerDef.getClassName();
|
||||
|
@ -1,120 +1,95 @@
|
||||
package org.moparscape.msc.gs.external;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.model.InvItem;
|
||||
import org.moparscape.msc.gs.model.Point;
|
||||
import org.moparscape.msc.gs.model.TelePoint;
|
||||
import org.moparscape.msc.gs.util.PersistenceManager;
|
||||
import org.moparscape.msc.gs.persistence.DataStore;
|
||||
|
||||
/**
|
||||
* This class handles the loading of entities from the conf files, and provides
|
||||
* methods for relaying these entities to the user.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EntityHandler {
|
||||
|
||||
private static HashMap<Integer, AgilityCourseDef> agilityCourses;
|
||||
private static HashMap<Integer, AgilityDef> agilityObjects;
|
||||
private static HashMap<Integer, ItemArrowHeadDef> arrowHeads;
|
||||
private static HashMap<Integer, ItemBowStringDef> bowString;
|
||||
private static HashMap<Integer, CerterDef> certers;
|
||||
private static HashMap<Integer, ItemDartTipDef> dartTips;
|
||||
private static Map<Integer, AgilityCourseDef> agilityCourses;
|
||||
private static Map<Integer, AgilityDef> agilityObjects;
|
||||
private static Map<Integer, ItemArrowHeadDef> arrowHeads;
|
||||
private static Map<Integer, ItemBowStringDef> bowString;
|
||||
private static Map<Integer, CerterDef> certers;
|
||||
private static Map<Integer, ItemDartTipDef> dartTips;
|
||||
|
||||
private static DoorDef[] doors;
|
||||
private static HashMap<Integer, FiremakingDef> firemaking;
|
||||
private static Map<Integer, FiremakingDef> firemaking;
|
||||
private static GameObjectDef[] gameObjects;
|
||||
private static HashMap<Integer, ItemGemDef> gems;
|
||||
private static Map<Integer, ItemGemDef> gems;
|
||||
private static ItemHerbSecond[] herbSeconds;
|
||||
private static HashMap<Integer, int[]> itemAffectedTypes;
|
||||
private static HashMap<Integer, ItemCookingDef> itemCooking;
|
||||
private static Map<Integer, int[]> itemAffectedTypes;
|
||||
private static Map<Integer, ItemCookingDef> itemCooking;
|
||||
private static ItemCraftingDef[] itemCrafting;
|
||||
private static HashMap<Integer, Integer> itemEdibleHeals;
|
||||
private static HashMap<Integer, ItemHerbDef> itemHerb;
|
||||
private static Map<Integer, Integer> itemEdibleHeals;
|
||||
private static Map<Integer, ItemHerbDef> itemHerb;
|
||||
private static ItemDef[] items;
|
||||
private static HashMap<Integer, ItemSmeltingDef> itemSmelting;
|
||||
private static Map<Integer, ItemSmeltingDef> itemSmelting;
|
||||
private static ItemSmithingDef[] itemSmithing;
|
||||
private static HashMap<Integer, ItemUnIdentHerbDef> itemUnIdentHerb;
|
||||
private static HashMap<Integer, ItemWieldableDef> itemWieldable;
|
||||
private static List<?>[] keyChestLoots;
|
||||
private static HashMap<Integer, ItemLogCutDef> logCut;
|
||||
private static Map<Integer, ItemUnIdentHerbDef> itemUnIdentHerb;
|
||||
private static Map<Integer, ItemWieldableDef> itemWieldable;
|
||||
private static List<InvItem>[] keyChestLoots;
|
||||
private static Map<Integer, ItemLogCutDef> logCut;
|
||||
|
||||
private static NPCDef[] npcs;
|
||||
private static HashMap<Integer, ObjectFishingDef[]> objectFishing;
|
||||
private static Map<Integer, ObjectFishingDef[]> objectFishing;
|
||||
|
||||
private static HashMap<Integer, ObjectMiningDef> objectMining;
|
||||
private static HashMap<Point, TelePoint> objectTelePoints;
|
||||
private static HashMap<Integer, ObjectWoodcuttingDef> objectWoodcutting;
|
||||
private static Map<Integer, ObjectMiningDef> objectMining;
|
||||
private static Map<Point, TelePoint> objectTelePoints;
|
||||
private static Map<Integer, ObjectWoodcuttingDef> objectWoodcutting;
|
||||
private static PrayerDef[] prayers;
|
||||
private static HashMap<Integer, Integer> spellAggressiveLvl;
|
||||
private static Map<Integer, Integer> spellAggressiveLvl;
|
||||
private static SpellDef[] spells;
|
||||
private static TileDef[] tiles;
|
||||
|
||||
static {
|
||||
doors = (DoorDef[]) PersistenceManager.load("defs/DoorDef.xml.gz");
|
||||
gameObjects = (GameObjectDef[]) PersistenceManager
|
||||
.load("defs/GameObjectDef.xml.gz");
|
||||
npcs = (NPCDef[]) PersistenceManager.load("defs/NPCDef.xml.gz");
|
||||
DataStore dataStore = Instance.getDataStore();
|
||||
doors = dataStore.loadDoorDefs();
|
||||
gameObjects = dataStore.loadGameObjectDefs();
|
||||
npcs = dataStore.loadNPCDefs();
|
||||
for (NPCDef n : npcs) {
|
||||
if (n.isAttackable()) {
|
||||
n.respawnTime -= (n.respawnTime / 3);
|
||||
}
|
||||
}
|
||||
prayers = (PrayerDef[]) PersistenceManager
|
||||
.load("defs/PrayerDef.xml.gz");
|
||||
items = (ItemDef[]) PersistenceManager.load("defs/ItemDef.xml.gz");
|
||||
spells = (SpellDef[]) PersistenceManager.load("defs/SpellDef.xml.gz");
|
||||
tiles = (TileDef[]) PersistenceManager.load("defs/TileDef.xml.gz");
|
||||
keyChestLoots = (List[]) PersistenceManager
|
||||
.load("defs/extras/KeyChestLoot.xml.gz");
|
||||
herbSeconds = (ItemHerbSecond[]) PersistenceManager
|
||||
.load("defs/extras/ItemHerbSecond.xml.gz");
|
||||
dartTips = (HashMap<Integer, ItemDartTipDef>) PersistenceManager
|
||||
.load("defs/extras/ItemDartTipDef.xml.gz");
|
||||
gems = (HashMap<Integer, ItemGemDef>) PersistenceManager
|
||||
.load("defs/extras/ItemGemDef.xml.gz");
|
||||
logCut = (HashMap<Integer, ItemLogCutDef>) PersistenceManager
|
||||
.load("defs/extras/ItemLogCutDef.xml.gz");
|
||||
bowString = (HashMap<Integer, ItemBowStringDef>) PersistenceManager
|
||||
.load("defs/extras/ItemBowStringDef.xml.gz");
|
||||
arrowHeads = (HashMap<Integer, ItemArrowHeadDef>) PersistenceManager
|
||||
.load("defs/extras/ItemArrowHeadDef.xml.gz");
|
||||
firemaking = (HashMap<Integer, FiremakingDef>) PersistenceManager
|
||||
.load("defs/extras/FiremakingDef.xml.gz");
|
||||
itemAffectedTypes = (HashMap<Integer, int[]>) PersistenceManager
|
||||
.load("defs/extras/ItemAffectedTypes.xml.gz");
|
||||
itemWieldable = (HashMap<Integer, ItemWieldableDef>) PersistenceManager
|
||||
.load("defs/extras/ItemWieldableDef.xml.gz");
|
||||
itemUnIdentHerb = (HashMap<Integer, ItemUnIdentHerbDef>) PersistenceManager
|
||||
.load("defs/extras/ItemUnIdentHerbDef.xml.gz");
|
||||
itemHerb = (HashMap<Integer, ItemHerbDef>) PersistenceManager
|
||||
.load("defs/extras/ItemHerbDef.xml.gz");
|
||||
itemEdibleHeals = (HashMap<Integer, Integer>) PersistenceManager
|
||||
.load("defs/extras/ItemEdibleHeals.xml.gz");
|
||||
itemCooking = (HashMap<Integer, ItemCookingDef>) PersistenceManager
|
||||
.load("defs/extras/ItemCookingDef.xml.gz");
|
||||
itemSmelting = (HashMap<Integer, ItemSmeltingDef>) PersistenceManager
|
||||
.load("defs/extras/ItemSmeltingDef.xml.gz");
|
||||
itemSmithing = (ItemSmithingDef[]) PersistenceManager
|
||||
.load("defs/extras/ItemSmithingDef.xml.gz");
|
||||
itemCrafting = (ItemCraftingDef[]) PersistenceManager
|
||||
.load("defs/extras/ItemCraftingDef.xml.gz");
|
||||
objectMining = (HashMap<Integer, ObjectMiningDef>) PersistenceManager
|
||||
.load("defs/extras/ObjectMining.xml.gz");
|
||||
objectWoodcutting = (HashMap<Integer, ObjectWoodcuttingDef>) PersistenceManager
|
||||
.load("defs/extras/ObjectWoodcutting.xml.gz");
|
||||
objectFishing = (HashMap<Integer, ObjectFishingDef[]>) PersistenceManager
|
||||
.load("defs/extras/ObjectFishing.xml.gz");
|
||||
spellAggressiveLvl = (HashMap<Integer, Integer>) PersistenceManager
|
||||
.load("defs/extras/SpellAggressiveLvl.xml.gz");
|
||||
objectTelePoints = (HashMap<Point, TelePoint>) PersistenceManager
|
||||
.load("locs/extras/ObjectTelePoints.xml.gz");
|
||||
certers = (HashMap<Integer, CerterDef>) PersistenceManager
|
||||
.load("defs/extras/NpcCerters.xml.gz");
|
||||
agilityObjects = (HashMap<Integer, AgilityDef>) PersistenceManager
|
||||
.load("defs/extras/AgilityDef.xml.gz");
|
||||
agilityCourses = (HashMap<Integer, AgilityCourseDef>) PersistenceManager
|
||||
.load("defs/extras/AgilityCourseDef.xml.gz");
|
||||
prayers = dataStore.loadPrayerDefs();
|
||||
items = dataStore.loadItemDefs();
|
||||
spells = dataStore.loadSpellDefs();
|
||||
tiles = dataStore.loadTileDefs();
|
||||
keyChestLoots = dataStore.loadKeyChestLoots();
|
||||
herbSeconds = dataStore.loadItemHerbSeconds();
|
||||
dartTips = dataStore.loadDartTips();
|
||||
gems = dataStore.loadGemDefs();
|
||||
logCut = dataStore.loadItemLogCutDefs();
|
||||
bowString = dataStore.loadItemBowStringDefs();
|
||||
arrowHeads = dataStore.loadItemArrowHeadDefs();
|
||||
firemaking = dataStore.loadFiremakingDefs();
|
||||
itemAffectedTypes = dataStore.loadItemAffectedTypes();
|
||||
itemWieldable = dataStore.loadItemWieldableDefs();
|
||||
itemUnIdentHerb = dataStore.loadItemUnIdentHerbDefs();
|
||||
itemHerb = dataStore.loadItemHerbDefs();
|
||||
itemEdibleHeals = dataStore.loadItemEdibleHeals();
|
||||
itemCooking = dataStore.loadItemCookingDefs();
|
||||
itemSmelting = dataStore.loadItemSmeltingDefs();
|
||||
itemSmithing = dataStore.loadItemSmithingDefs();
|
||||
itemCrafting = dataStore.loadItemCraftingDefs();
|
||||
objectMining = dataStore.loadObjectMiningDefs();
|
||||
objectWoodcutting = dataStore.loadObjectWoodcuttingDefs();
|
||||
objectFishing = dataStore.loadObjectFishDefs();
|
||||
spellAggressiveLvl = dataStore.loadSpellAgressiveLevel();
|
||||
objectTelePoints = dataStore.loadTelePoints();
|
||||
certers = dataStore.loadCerterDefs();
|
||||
agilityObjects = dataStore.loadAgilityDefs();
|
||||
agilityCourses = dataStore.loadAgilityCourseDefs();
|
||||
dataStore.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,6 @@ package org.moparscape.msc.gs.io;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@ -22,7 +21,6 @@ import org.moparscape.msc.gs.model.Shop;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.gs.util.PersistenceManager;
|
||||
|
||||
public class WorldLoader {
|
||||
private ZipFile tileArchive;
|
||||
@ -129,7 +127,6 @@ public class WorldLoader {
|
||||
* }
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadWorld(World world) {
|
||||
try {
|
||||
tileArchive = new ZipFile(new File(Config.CONF_DIR,
|
||||
@ -154,26 +151,22 @@ public class WorldLoader {
|
||||
}
|
||||
Logger.error((System.currentTimeMillis() - now) / 1000 + "s to parse");
|
||||
// try { out.close(); } catch(Exception e) { Logger.error(e); }
|
||||
for (Shop shop : (List<Shop>) PersistenceManager
|
||||
.load("locs/Shops.xml.gz")) {
|
||||
for (Shop shop : Instance.getDataStore().loadShops()) {
|
||||
world.registerShop(shop);
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadObjects() {
|
||||
World world = Instance.getWorld();
|
||||
for (GameObjectLoc gameObject : (List<GameObjectLoc>) PersistenceManager
|
||||
.load("locs/GameObjectLoc.xml.gz")) {
|
||||
for (GameObjectLoc gameObject : Instance.getDataStore().loadGameObjectLocs()) {
|
||||
if (Config.f2pWildy && Formulae.isP2P(true, gameObject))
|
||||
continue;
|
||||
if (Formulae.isP2P(gameObject) && !World.isMembers())
|
||||
continue;
|
||||
world.registerGameObject(new GameObject(gameObject));
|
||||
}
|
||||
for (ItemLoc item : (List<ItemLoc>) PersistenceManager
|
||||
.load("locs/ItemLoc.xml.gz")) {
|
||||
for (ItemLoc item : Instance.getDataStore().loadItemLocs()) {
|
||||
if (Config.f2pWildy && Formulae.isP2P(true, item))
|
||||
continue;
|
||||
if (Formulae.isP2P(item) && !World.isMembers())
|
||||
@ -181,8 +174,7 @@ public class WorldLoader {
|
||||
world.registerItem(new Item(item));
|
||||
}// ember
|
||||
|
||||
for (NPCLoc npc : (List<NPCLoc>) PersistenceManager
|
||||
.load("locs/NpcLoc.xml.gz")) {
|
||||
for (NPCLoc npc : Instance.getDataStore().loadNPCLocs()) {
|
||||
if (Config.f2pWildy && Formulae.isP2P(true, npc))
|
||||
continue;
|
||||
if (Formulae.isP2P(npc) && !World.isMembers())
|
||||
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.Server;
|
||||
import org.moparscape.msc.gs.core.ClientUpdater;
|
||||
import org.moparscape.msc.gs.core.DelayedEventHandler;
|
||||
@ -25,7 +26,6 @@ import org.moparscape.msc.gs.quest.QuestManager;
|
||||
import org.moparscape.msc.gs.states.CombatState;
|
||||
import org.moparscape.msc.gs.util.EntityList;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.gs.util.PersistenceManager;
|
||||
|
||||
public final class World {
|
||||
|
||||
@ -471,8 +471,7 @@ public final class World {
|
||||
*/
|
||||
private void loadNpcHandlers() {
|
||||
|
||||
NpcHandlerDef[] handlerDefs = (NpcHandlerDef[]) PersistenceManager
|
||||
.load("NpcHandlers.xml");
|
||||
NpcHandlerDef[] handlerDefs = Instance.getDataStore().loadNpcHandlers();
|
||||
for (NpcHandlerDef handlerDef : handlerDefs) {
|
||||
try {
|
||||
String className = handlerDef.getClassName();
|
||||
|
104
GameServer/src/org/moparscape/msc/gs/persistence/DataStore.java
Normal file
104
GameServer/src/org/moparscape/msc/gs/persistence/DataStore.java
Normal file
@ -0,0 +1,104 @@
|
||||
package org.moparscape.msc.gs.persistence;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.moparscape.msc.gs.external.*;
|
||||
import org.moparscape.msc.gs.model.InvItem;
|
||||
import org.moparscape.msc.gs.model.Point;
|
||||
import org.moparscape.msc.gs.model.Shop;
|
||||
import org.moparscape.msc.gs.model.TelePoint;
|
||||
import org.moparscape.msc.gs.npchandler.NpcHandlerDef;
|
||||
import org.moparscape.msc.gs.phandler.PacketHandlerDef;
|
||||
|
||||
/**
|
||||
* Any retrieval of unchanging data should be done through this interface.
|
||||
*
|
||||
* @author Joe Pritzel
|
||||
*
|
||||
*/
|
||||
public interface DataStore {
|
||||
public PacketHandlerDef[] loadPacketHandlerDefs();
|
||||
|
||||
public PacketHandlerDef[] loadLSPacketHandlerDefs();
|
||||
|
||||
public NpcHandlerDef[] loadNpcHandlers();
|
||||
|
||||
public Map<Point, TelePoint> loadTelePoints();
|
||||
|
||||
public List<Shop> loadShops();
|
||||
|
||||
public Map<Integer, CerterDef> loadCerterDefs();
|
||||
|
||||
public List<GameObjectLoc> loadGameObjectLocs();
|
||||
|
||||
public List<ItemLoc> loadItemLocs();
|
||||
|
||||
public List<NPCLoc> loadNPCLocs();
|
||||
|
||||
public TileDef[] loadTileDefs();
|
||||
|
||||
public GameObjectDef[] loadGameObjectDefs();
|
||||
|
||||
public DoorDef[] loadDoorDefs();
|
||||
|
||||
public ItemDef[] loadItemDefs();
|
||||
|
||||
public PrayerDef[] loadPrayerDefs();
|
||||
|
||||
public SpellDef[] loadSpellDefs();
|
||||
|
||||
public NPCDef[] loadNPCDefs();
|
||||
|
||||
public ItemCraftingDef[] loadItemCraftingDefs();
|
||||
|
||||
public ItemHerbSecond[] loadItemHerbSeconds();
|
||||
|
||||
public Map<Integer, ItemDartTipDef> loadItemDartTipDefs();
|
||||
|
||||
public Map<Integer, ItemGemDef> loadGemDefs();
|
||||
|
||||
public Map<Integer, ItemLogCutDef> loadItemLogCutDefs();
|
||||
|
||||
public Map<Integer, ItemBowStringDef> loadItemBowStringDefs();
|
||||
|
||||
public Map<Integer, ItemArrowHeadDef> loadItemArrowHeadDefs();
|
||||
|
||||
public Map<Integer, FiremakingDef> loadFiremakingDefs();
|
||||
|
||||
public Map<Integer, int[]> loadItemAffectedTypes();
|
||||
|
||||
public Map<Integer, ItemWieldableDef> loadItemWieldableDefs();
|
||||
|
||||
public Map<Integer, ItemUnIdentHerbDef> loadItemUnIdentHerbDefs();
|
||||
|
||||
public Map<Integer, ItemHerbDef> loadItemHerbDefs();
|
||||
|
||||
public Map<Integer, Integer> loadItemEdibleHeals();
|
||||
|
||||
public Map<Integer, ItemCookingDef> loadItemCookingDefs();
|
||||
|
||||
public Map<Integer, ItemSmeltingDef> loadItemSmeltingDefs();
|
||||
|
||||
public ItemSmithingDef[] loadItemSmithingDefs();
|
||||
|
||||
public Map<Integer, ObjectMiningDef> loadObjectMiningDefs();
|
||||
|
||||
public Map<Integer, ObjectWoodcuttingDef> loadObjectWoodcuttingDefs();
|
||||
|
||||
public Map<Integer, ObjectFishingDef[]> loadObjectFishDefs();
|
||||
|
||||
public Map<Integer, Integer> loadSpellAgressiveLevel();
|
||||
|
||||
public Map<Integer, AgilityDef> loadAgilityDefs();
|
||||
|
||||
public Map<Integer, AgilityCourseDef> loadAgilityCourseDefs();
|
||||
|
||||
public List<InvItem>[] loadKeyChestLoots();
|
||||
|
||||
public HashMap<Integer, ItemDartTipDef> loadDartTips();
|
||||
|
||||
public void dispose();
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package org.moparscape.msc.gs.persistence;
|
||||
|
||||
public class DataStoreFactory {
|
||||
|
||||
public static DataStore create(String className) throws Exception {
|
||||
return Class.forName(className).asSubclass(DataStore.class)
|
||||
.newInstance();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,309 @@
|
||||
package org.moparscape.msc.gs.persistence.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import net.jcip.annotations.NotThreadSafe;
|
||||
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.external.*;
|
||||
import org.moparscape.msc.gs.model.InvItem;
|
||||
import org.moparscape.msc.gs.model.Point;
|
||||
import org.moparscape.msc.gs.model.Shop;
|
||||
import org.moparscape.msc.gs.model.TelePoint;
|
||||
import org.moparscape.msc.gs.npchandler.NpcHandlerDef;
|
||||
import org.moparscape.msc.gs.persistence.DataStore;
|
||||
import org.moparscape.msc.gs.phandler.PacketHandlerDef;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* A DataStore that parses XML using XStream.
|
||||
*
|
||||
* @author Joe Pritzel
|
||||
*
|
||||
*/
|
||||
@NotThreadSafe
|
||||
@SuppressWarnings("unchecked")
|
||||
public class XMLUsingXStream implements DataStore {
|
||||
|
||||
private static final XStream xstream = new XStream();
|
||||
|
||||
static {
|
||||
try {
|
||||
setupAliases();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Object load(String filename) {
|
||||
filename = filename.replaceAll(Pattern.quote("/"),
|
||||
Matcher.quoteReplacement(File.separator));
|
||||
try {
|
||||
InputStream is = new FileInputStream(new File(Config.CONF_DIR,
|
||||
filename));
|
||||
if (filename.endsWith(".gz")) {
|
||||
is = new GZIPInputStream(is);
|
||||
}
|
||||
Object rv = xstream.fromXML(is);
|
||||
return rv;
|
||||
} catch (IOException ioe) {
|
||||
Logger.error("Filename = " + filename);
|
||||
Logger.error(ioe);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setupAliases() {
|
||||
try {
|
||||
Properties aliases = new Properties();
|
||||
FileInputStream fis = new FileInputStream(new File(Config.CONF_DIR,
|
||||
"aliases.xml"));
|
||||
aliases.loadFromXML(fis);
|
||||
for (Enumeration<?> e = aliases.propertyNames(); e
|
||||
.hasMoreElements();) {
|
||||
String alias = (String) e.nextElement();
|
||||
Class<?> c = Class.forName((String) aliases.get(alias));
|
||||
xstream.alias(alias, c);
|
||||
}
|
||||
} catch (Exception ioe) {
|
||||
Logger.error(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(String filename, Object o) {
|
||||
filename = filename.replaceAll(Pattern.quote("/"),
|
||||
Matcher.quoteReplacement(File.separator));
|
||||
try {
|
||||
OutputStream os = new FileOutputStream(new File(Config.CONF_DIR,
|
||||
filename));
|
||||
if (filename.endsWith(".gz")) {
|
||||
os = new GZIPOutputStream(os);
|
||||
}
|
||||
xstream.toXML(o, os);
|
||||
} catch (IOException ioe) {
|
||||
Logger.error(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketHandlerDef[] loadPacketHandlerDefs() {
|
||||
return (PacketHandlerDef[]) load("PacketHandlers.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketHandlerDef[] loadLSPacketHandlerDefs() {
|
||||
return (PacketHandlerDef[]) load("LSPacketHandlers.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NpcHandlerDef[] loadNpcHandlers() {
|
||||
return (NpcHandlerDef[]) load("NpcHandlers.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Point, TelePoint> loadTelePoints() {
|
||||
return (Map<Point, TelePoint>) load("locs/extras/ObjectTelePoints.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Shop> loadShops() {
|
||||
return (List<Shop>) load("locs/Shops.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, CerterDef> loadCerterDefs() {
|
||||
return (Map<Integer, CerterDef>) load("defs/extras/NpcCerters.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GameObjectLoc> loadGameObjectLocs() {
|
||||
return (List<GameObjectLoc>) load("locs/GameObjectLoc.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemLoc> loadItemLocs() {
|
||||
return (List<ItemLoc>) load("locs/ItemLoc.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NPCLoc> loadNPCLocs() {
|
||||
return (List<NPCLoc>) load("locs/NpcLoc.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileDef[] loadTileDefs() {
|
||||
return (TileDef[]) load("defs/TileDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObjectDef[] loadGameObjectDefs() {
|
||||
return (GameObjectDef[]) load("defs/GameObjectDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoorDef[] loadDoorDefs() {
|
||||
return (DoorDef[]) load("defs/DoorDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDef[] loadItemDefs() {
|
||||
return (ItemDef[]) load("defs/ItemDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrayerDef[] loadPrayerDefs() {
|
||||
return (PrayerDef[]) load("defs/PrayerDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpellDef[] loadSpellDefs() {
|
||||
return (SpellDef[]) load("defs/SpellDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCDef[] loadNPCDefs() {
|
||||
return (NPCDef[]) load("defs/NPCDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCraftingDef[] loadItemCraftingDefs() {
|
||||
return (ItemCraftingDef[]) load("defs/extras/ItemCraftingDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemHerbSecond[] loadItemHerbSeconds() {
|
||||
return (ItemHerbSecond[]) load("defs/extras/ItemHerbSecond.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemDartTipDef> loadItemDartTipDefs() {
|
||||
return (Map<Integer, ItemDartTipDef>) load("defs/extras/ItemDartTipDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemGemDef> loadGemDefs() {
|
||||
return (Map<Integer, ItemGemDef>) load("defs/extras/ItemGemDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemLogCutDef> loadItemLogCutDefs() {
|
||||
return (Map<Integer, ItemLogCutDef>) load("defs/extras/ItemLogCutDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemBowStringDef> loadItemBowStringDefs() {
|
||||
return (Map<Integer, ItemBowStringDef>) load("defs/extras/ItemBowStringDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemArrowHeadDef> loadItemArrowHeadDefs() {
|
||||
return (Map<Integer, ItemArrowHeadDef>) load("defs/extras/ItemArrowHeadDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, FiremakingDef> loadFiremakingDefs() {
|
||||
return (Map<Integer, FiremakingDef>) load("defs/extras/FiremakingDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, int[]> loadItemAffectedTypes() {
|
||||
return (Map<Integer, int[]>) load("defs/extras/ItemAffectedTypes.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemWieldableDef> loadItemWieldableDefs() {
|
||||
return (Map<Integer, ItemWieldableDef>) load("defs/extras/ItemWieldableDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemUnIdentHerbDef> loadItemUnIdentHerbDefs() {
|
||||
return (Map<Integer, ItemUnIdentHerbDef>) load("defs/extras/ItemUnIdentHerbDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemHerbDef> loadItemHerbDefs() {
|
||||
return (Map<Integer, ItemHerbDef>) load("defs/extras/ItemHerbDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Integer> loadItemEdibleHeals() {
|
||||
return (Map<Integer, Integer>) load("defs/extras/ItemEdibleHeals.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemCookingDef> loadItemCookingDefs() {
|
||||
return (Map<Integer, ItemCookingDef>) load("defs/extras/ItemCookingDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ItemSmeltingDef> loadItemSmeltingDefs() {
|
||||
return (Map<Integer, ItemSmeltingDef>) load("defs/extras/ItemSmeltingDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSmithingDef[] loadItemSmithingDefs() {
|
||||
return (ItemSmithingDef[]) load("defs/extras/ItemSmithingDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ObjectMiningDef> loadObjectMiningDefs() {
|
||||
return (Map<Integer, ObjectMiningDef>) load("defs/extras/ObjectMining.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ObjectWoodcuttingDef> loadObjectWoodcuttingDefs() {
|
||||
return (Map<Integer, ObjectWoodcuttingDef>) load("defs/extras/ObjectWoodcutting.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ObjectFishingDef[]> loadObjectFishDefs() {
|
||||
return (Map<Integer, ObjectFishingDef[]>) load("defs/extras/ObjectFishing.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Integer> loadSpellAgressiveLevel() {
|
||||
return (Map<Integer, Integer>) load("defs/extras/SpellAggressiveLvl.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, AgilityDef> loadAgilityDefs() {
|
||||
return (Map<Integer, AgilityDef>) load("defs/extras/AgilityDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, AgilityCourseDef> loadAgilityCourseDefs() {
|
||||
return (Map<Integer, AgilityCourseDef>) load("defs/extras/AgilityCourseDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InvItem>[] loadKeyChestLoots() {
|
||||
return (List<InvItem>[]) load("defs/extras/KeyChestLoot.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemDartTipDef> loadDartTips() {
|
||||
return (HashMap<Integer, ItemDartTipDef>) load("defs/extras/ItemDartTipDef.xml.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.moparscape.msc.gs.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.moparscape.msc.config.Config;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
public class PersistenceManager {
|
||||
private static final XStream xstream = new XStream();
|
||||
|
||||
static {
|
||||
setupAliases();
|
||||
}
|
||||
|
||||
public static Object load(String filename) {
|
||||
try {
|
||||
InputStream is = new FileInputStream(new File(Config.CONF_DIR,
|
||||
filename));
|
||||
if (filename.endsWith(".gz")) {
|
||||
is = new GZIPInputStream(is);
|
||||
}
|
||||
Object rv = xstream.fromXML(is);
|
||||
return rv;
|
||||
} catch (IOException ioe) {
|
||||
Logger.error(ioe);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setupAliases() {
|
||||
try {
|
||||
Properties aliases = new Properties();
|
||||
FileInputStream fis = new FileInputStream(new File(Config.CONF_DIR,
|
||||
"aliases.xml"));
|
||||
aliases.loadFromXML(fis);
|
||||
for (Enumeration<?> e = aliases.propertyNames(); e
|
||||
.hasMoreElements();) {
|
||||
String alias = (String) e.nextElement();
|
||||
Class<?> c = Class.forName((String) aliases.get(alias));
|
||||
xstream.alias(alias, c);
|
||||
}
|
||||
} catch (Exception ioe) {
|
||||
Logger.error(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(String filename, Object o) {
|
||||
try {
|
||||
OutputStream os = new FileOutputStream(new File(Config.CONF_DIR,
|
||||
filename));
|
||||
if (filename.endsWith(".gz")) {
|
||||
os = new GZIPOutputStream(os);
|
||||
}
|
||||
xstream.toXML(o, os);
|
||||
} catch (IOException ioe) {
|
||||
Logger.error(ioe);
|
||||
}
|
||||
}
|
||||
}
|
@ -58,7 +58,7 @@ public class Server {
|
||||
System.out.println("Login Server starting up...");
|
||||
Config.initConfig(configFile);
|
||||
try {
|
||||
storage = StorageMediumFactory.createMedium(Config.STORAGE_MEDIUM);
|
||||
storage = StorageMediumFactory.create(Config.STORAGE_MEDIUM);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
|
@ -2,7 +2,7 @@ package org.moparscape.msc.ls.persistence;
|
||||
|
||||
public class StorageMediumFactory {
|
||||
|
||||
public static StorageMedium createMedium(String className) throws Exception {
|
||||
public static StorageMedium create(String className) throws Exception {
|
||||
return Class.forName(className).asSubclass(StorageMedium.class)
|
||||
.newInstance();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user