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:
Joe0 2011-12-04 16:38:08 -06:00
parent 1f064e322a
commit 978de20d53
15 changed files with 526 additions and 178 deletions

View File

@ -78,4 +78,7 @@
<entry key="alert-config">conf/alert-config.xml</entry> <entry key="alert-config">conf/alert-config.xml</entry>
<!-- Location of configuration file for commands --> <!-- Location of configuration file for commands -->
<entry key="command-config">conf/command-config.xml</entry> <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> </properties>

View File

@ -15,5 +15,8 @@
<dependency org="commons-collections" name="commons-collections" rev="3.2.1"/> <dependency org="commons-collections" name="commons-collections" rev="3.2.1"/>
<dependency org="org.slf4j" name="slf4j-simple" rev="1.6.3"/> <dependency org="org.slf4j" name="slf4j-simple" rev="1.6.3"/>
<dependency org="net.jcip" name="jcip-annotations" rev="1.0"/>
</dependencies> </dependencies>
</ivy-module> </ivy-module>

View File

@ -42,6 +42,7 @@ public class Config {
public static boolean OS_LEVEL_BLOCKING, APPLICATION_LEVEL_THROTTLE_ALERT, public static boolean OS_LEVEL_BLOCKING, APPLICATION_LEVEL_THROTTLE_ALERT,
OS_LEVEL_THROTTLE_ALERT, OS_LEVEL_UNBLOCK_FAILED_ALERT, OS_LEVEL_THROTTLE_ALERT, OS_LEVEL_UNBLOCK_FAILED_ALERT,
CONGRATS_FOR_MAX_LEVEL; CONGRATS_FOR_MAX_LEVEL;
public static String DATA_STORE;
static { static {
loadEnv(); loadEnv();
@ -127,6 +128,8 @@ public class Config {
.getProperty("wild-combat-bonus")); .getProperty("wild-combat-bonus"));
CONGRATS_FOR_MAX_LEVEL = Boolean.parseBoolean(props CONGRATS_FOR_MAX_LEVEL = Boolean.parseBoolean(props
.getProperty("max-level-congrats")); .getProperty("max-level-congrats"));
DATA_STORE = props.getProperty("data-store");
props.clear(); props.clear();

View File

@ -1,9 +1,12 @@
package org.moparscape.msc.gs; package org.moparscape.msc.gs;
import org.moparscape.msc.config.Config;
import org.moparscape.msc.gs.core.DelayedEventHandler; import org.moparscape.msc.gs.core.DelayedEventHandler;
import org.moparscape.msc.gs.db.DBConnection; import org.moparscape.msc.gs.db.DBConnection;
import org.moparscape.msc.gs.db.ReportHandlerQueries; import org.moparscape.msc.gs.db.ReportHandlerQueries;
import org.moparscape.msc.gs.model.World; 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; import org.moparscape.msc.gs.plugins.dependencies.PluginHandler;
/** /**
@ -33,4 +36,23 @@ public class Instance {
public static ReportHandlerQueries getReport() { public static ReportHandlerQueries getReport() {
return DBConnection.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;
}
} }

View File

@ -26,14 +26,13 @@ import org.moparscape.msc.gs.phandler.PacketHandlerDef;
import org.moparscape.msc.gs.plugins.dependencies.NpcAI; import org.moparscape.msc.gs.plugins.dependencies.NpcAI;
import org.moparscape.msc.gs.tools.Captcha; import org.moparscape.msc.gs.tools.Captcha;
import org.moparscape.msc.gs.util.Logger; 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 * The central motor of the game. This class is responsible for the primary
* operation of the entire game. * operation of the entire game.
*/ */
public final class GameEngine extends Thread { public final class GameEngine extends Thread {
private static Captcha captcha; private static Captcha captcha;
/** /**
* World instance * World instance
@ -149,8 +148,7 @@ public final class GameEngine extends Thread {
* Loads the packet handling classes from the persistence manager. * Loads the packet handling classes from the persistence manager.
*/ */
protected void loadPacketHandlers() { protected void loadPacketHandlers() {
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager PacketHandlerDef[] handlerDefs = Instance.getDataStore().loadPacketHandlerDefs();
.load("PacketHandlers.xml");
for (PacketHandlerDef handlerDef : handlerDefs) { for (PacketHandlerDef handlerDef : handlerDefs) {
try { try {
String className = handlerDef.getClassName(); String className = handlerDef.getClassName();

View File

@ -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.SocketConnectorConfig;
import org.apache.mina.transport.socket.nio.SocketSessionConfig; import org.apache.mina.transport.socket.nio.SocketSessionConfig;
import org.moparscape.msc.config.Config; 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.builders.ls.MiscPacketBuilder;
import org.moparscape.msc.gs.connection.LSConnectionHandler; import org.moparscape.msc.gs.connection.LSConnectionHandler;
import org.moparscape.msc.gs.connection.LSPacket; 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.PacketHandler;
import org.moparscape.msc.gs.phandler.PacketHandlerDef; import org.moparscape.msc.gs.phandler.PacketHandlerDef;
import org.moparscape.msc.gs.util.Logger; import org.moparscape.msc.gs.util.Logger;
import org.moparscape.msc.gs.util.PersistenceManager;
public class LoginConnector { public class LoginConnector {
/** /**
@ -139,8 +139,7 @@ public class LoginConnector {
} }
private void loadPacketHandlers() { private void loadPacketHandlers() {
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager PacketHandlerDef[] handlerDefs = Instance.getDataStore().loadLSPacketHandlerDefs();
.load("LSPacketHandlers.xml");
for (PacketHandlerDef handlerDef : handlerDefs) { for (PacketHandlerDef handlerDef : handlerDefs) {
try { try {
String className = handlerDef.getClassName(); String className = handlerDef.getClassName();

View File

@ -1,120 +1,95 @@
package org.moparscape.msc.gs.external; package org.moparscape.msc.gs.external;
import java.util.HashMap;
import java.util.List; 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.Point;
import org.moparscape.msc.gs.model.TelePoint; 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 * This class handles the loading of entities from the conf files, and provides
* methods for relaying these entities to the user. * methods for relaying these entities to the user.
*/ */
@SuppressWarnings("unchecked")
public class EntityHandler { public class EntityHandler {
private static Map<Integer, AgilityCourseDef> agilityCourses;
private static HashMap<Integer, AgilityCourseDef> agilityCourses; private static Map<Integer, AgilityDef> agilityObjects;
private static HashMap<Integer, AgilityDef> agilityObjects; private static Map<Integer, ItemArrowHeadDef> arrowHeads;
private static HashMap<Integer, ItemArrowHeadDef> arrowHeads; private static Map<Integer, ItemBowStringDef> bowString;
private static HashMap<Integer, ItemBowStringDef> bowString; private static Map<Integer, CerterDef> certers;
private static HashMap<Integer, CerterDef> certers; private static Map<Integer, ItemDartTipDef> dartTips;
private static HashMap<Integer, ItemDartTipDef> dartTips;
private static DoorDef[] doors; private static DoorDef[] doors;
private static HashMap<Integer, FiremakingDef> firemaking; private static Map<Integer, FiremakingDef> firemaking;
private static GameObjectDef[] gameObjects; private static GameObjectDef[] gameObjects;
private static HashMap<Integer, ItemGemDef> gems; private static Map<Integer, ItemGemDef> gems;
private static ItemHerbSecond[] herbSeconds; private static ItemHerbSecond[] herbSeconds;
private static HashMap<Integer, int[]> itemAffectedTypes; private static Map<Integer, int[]> itemAffectedTypes;
private static HashMap<Integer, ItemCookingDef> itemCooking; private static Map<Integer, ItemCookingDef> itemCooking;
private static ItemCraftingDef[] itemCrafting; private static ItemCraftingDef[] itemCrafting;
private static HashMap<Integer, Integer> itemEdibleHeals; private static Map<Integer, Integer> itemEdibleHeals;
private static HashMap<Integer, ItemHerbDef> itemHerb; private static Map<Integer, ItemHerbDef> itemHerb;
private static ItemDef[] items; private static ItemDef[] items;
private static HashMap<Integer, ItemSmeltingDef> itemSmelting; private static Map<Integer, ItemSmeltingDef> itemSmelting;
private static ItemSmithingDef[] itemSmithing; private static ItemSmithingDef[] itemSmithing;
private static HashMap<Integer, ItemUnIdentHerbDef> itemUnIdentHerb; private static Map<Integer, ItemUnIdentHerbDef> itemUnIdentHerb;
private static HashMap<Integer, ItemWieldableDef> itemWieldable; private static Map<Integer, ItemWieldableDef> itemWieldable;
private static List<?>[] keyChestLoots; private static List<InvItem>[] keyChestLoots;
private static HashMap<Integer, ItemLogCutDef> logCut; private static Map<Integer, ItemLogCutDef> logCut;
private static NPCDef[] npcs; private static NPCDef[] npcs;
private static HashMap<Integer, ObjectFishingDef[]> objectFishing; private static Map<Integer, ObjectFishingDef[]> objectFishing;
private static HashMap<Integer, ObjectMiningDef> objectMining; private static Map<Integer, ObjectMiningDef> objectMining;
private static HashMap<Point, TelePoint> objectTelePoints; private static Map<Point, TelePoint> objectTelePoints;
private static HashMap<Integer, ObjectWoodcuttingDef> objectWoodcutting; private static Map<Integer, ObjectWoodcuttingDef> objectWoodcutting;
private static PrayerDef[] prayers; private static PrayerDef[] prayers;
private static HashMap<Integer, Integer> spellAggressiveLvl; private static Map<Integer, Integer> spellAggressiveLvl;
private static SpellDef[] spells; private static SpellDef[] spells;
private static TileDef[] tiles; private static TileDef[] tiles;
static { static {
doors = (DoorDef[]) PersistenceManager.load("defs/DoorDef.xml.gz"); DataStore dataStore = Instance.getDataStore();
gameObjects = (GameObjectDef[]) PersistenceManager doors = dataStore.loadDoorDefs();
.load("defs/GameObjectDef.xml.gz"); gameObjects = dataStore.loadGameObjectDefs();
npcs = (NPCDef[]) PersistenceManager.load("defs/NPCDef.xml.gz"); npcs = dataStore.loadNPCDefs();
for (NPCDef n : npcs) { for (NPCDef n : npcs) {
if (n.isAttackable()) { if (n.isAttackable()) {
n.respawnTime -= (n.respawnTime / 3); n.respawnTime -= (n.respawnTime / 3);
} }
} }
prayers = (PrayerDef[]) PersistenceManager prayers = dataStore.loadPrayerDefs();
.load("defs/PrayerDef.xml.gz"); items = dataStore.loadItemDefs();
items = (ItemDef[]) PersistenceManager.load("defs/ItemDef.xml.gz"); spells = dataStore.loadSpellDefs();
spells = (SpellDef[]) PersistenceManager.load("defs/SpellDef.xml.gz"); tiles = dataStore.loadTileDefs();
tiles = (TileDef[]) PersistenceManager.load("defs/TileDef.xml.gz"); keyChestLoots = dataStore.loadKeyChestLoots();
keyChestLoots = (List[]) PersistenceManager herbSeconds = dataStore.loadItemHerbSeconds();
.load("defs/extras/KeyChestLoot.xml.gz"); dartTips = dataStore.loadDartTips();
herbSeconds = (ItemHerbSecond[]) PersistenceManager gems = dataStore.loadGemDefs();
.load("defs/extras/ItemHerbSecond.xml.gz"); logCut = dataStore.loadItemLogCutDefs();
dartTips = (HashMap<Integer, ItemDartTipDef>) PersistenceManager bowString = dataStore.loadItemBowStringDefs();
.load("defs/extras/ItemDartTipDef.xml.gz"); arrowHeads = dataStore.loadItemArrowHeadDefs();
gems = (HashMap<Integer, ItemGemDef>) PersistenceManager firemaking = dataStore.loadFiremakingDefs();
.load("defs/extras/ItemGemDef.xml.gz"); itemAffectedTypes = dataStore.loadItemAffectedTypes();
logCut = (HashMap<Integer, ItemLogCutDef>) PersistenceManager itemWieldable = dataStore.loadItemWieldableDefs();
.load("defs/extras/ItemLogCutDef.xml.gz"); itemUnIdentHerb = dataStore.loadItemUnIdentHerbDefs();
bowString = (HashMap<Integer, ItemBowStringDef>) PersistenceManager itemHerb = dataStore.loadItemHerbDefs();
.load("defs/extras/ItemBowStringDef.xml.gz"); itemEdibleHeals = dataStore.loadItemEdibleHeals();
arrowHeads = (HashMap<Integer, ItemArrowHeadDef>) PersistenceManager itemCooking = dataStore.loadItemCookingDefs();
.load("defs/extras/ItemArrowHeadDef.xml.gz"); itemSmelting = dataStore.loadItemSmeltingDefs();
firemaking = (HashMap<Integer, FiremakingDef>) PersistenceManager itemSmithing = dataStore.loadItemSmithingDefs();
.load("defs/extras/FiremakingDef.xml.gz"); itemCrafting = dataStore.loadItemCraftingDefs();
itemAffectedTypes = (HashMap<Integer, int[]>) PersistenceManager objectMining = dataStore.loadObjectMiningDefs();
.load("defs/extras/ItemAffectedTypes.xml.gz"); objectWoodcutting = dataStore.loadObjectWoodcuttingDefs();
itemWieldable = (HashMap<Integer, ItemWieldableDef>) PersistenceManager objectFishing = dataStore.loadObjectFishDefs();
.load("defs/extras/ItemWieldableDef.xml.gz"); spellAggressiveLvl = dataStore.loadSpellAgressiveLevel();
itemUnIdentHerb = (HashMap<Integer, ItemUnIdentHerbDef>) PersistenceManager objectTelePoints = dataStore.loadTelePoints();
.load("defs/extras/ItemUnIdentHerbDef.xml.gz"); certers = dataStore.loadCerterDefs();
itemHerb = (HashMap<Integer, ItemHerbDef>) PersistenceManager agilityObjects = dataStore.loadAgilityDefs();
.load("defs/extras/ItemHerbDef.xml.gz"); agilityCourses = dataStore.loadAgilityCourseDefs();
itemEdibleHeals = (HashMap<Integer, Integer>) PersistenceManager dataStore.dispose();
.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");
} }
/** /**

View File

@ -3,7 +3,6 @@ package org.moparscape.msc.gs.io;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; 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.model.World;
import org.moparscape.msc.gs.tools.DataConversions; import org.moparscape.msc.gs.tools.DataConversions;
import org.moparscape.msc.gs.util.Logger; import org.moparscape.msc.gs.util.Logger;
import org.moparscape.msc.gs.util.PersistenceManager;
public class WorldLoader { public class WorldLoader {
private ZipFile tileArchive; private ZipFile tileArchive;
@ -129,7 +127,6 @@ public class WorldLoader {
* } * }
*/ */
@SuppressWarnings("unchecked")
public void loadWorld(World world) { public void loadWorld(World world) {
try { try {
tileArchive = new ZipFile(new File(Config.CONF_DIR, tileArchive = new ZipFile(new File(Config.CONF_DIR,
@ -154,26 +151,22 @@ public class WorldLoader {
} }
Logger.error((System.currentTimeMillis() - now) / 1000 + "s to parse"); Logger.error((System.currentTimeMillis() - now) / 1000 + "s to parse");
// try { out.close(); } catch(Exception e) { Logger.error(e); } // try { out.close(); } catch(Exception e) { Logger.error(e); }
for (Shop shop : (List<Shop>) PersistenceManager for (Shop shop : Instance.getDataStore().loadShops()) {
.load("locs/Shops.xml.gz")) {
world.registerShop(shop); world.registerShop(shop);
} }
System.gc(); System.gc();
} }
@SuppressWarnings("unchecked")
public void loadObjects() { public void loadObjects() {
World world = Instance.getWorld(); World world = Instance.getWorld();
for (GameObjectLoc gameObject : (List<GameObjectLoc>) PersistenceManager for (GameObjectLoc gameObject : Instance.getDataStore().loadGameObjectLocs()) {
.load("locs/GameObjectLoc.xml.gz")) {
if (Config.f2pWildy && Formulae.isP2P(true, gameObject)) if (Config.f2pWildy && Formulae.isP2P(true, gameObject))
continue; continue;
if (Formulae.isP2P(gameObject) && !World.isMembers()) if (Formulae.isP2P(gameObject) && !World.isMembers())
continue; continue;
world.registerGameObject(new GameObject(gameObject)); world.registerGameObject(new GameObject(gameObject));
} }
for (ItemLoc item : (List<ItemLoc>) PersistenceManager for (ItemLoc item : Instance.getDataStore().loadItemLocs()) {
.load("locs/ItemLoc.xml.gz")) {
if (Config.f2pWildy && Formulae.isP2P(true, item)) if (Config.f2pWildy && Formulae.isP2P(true, item))
continue; continue;
if (Formulae.isP2P(item) && !World.isMembers()) if (Formulae.isP2P(item) && !World.isMembers())
@ -181,8 +174,7 @@ public class WorldLoader {
world.registerItem(new Item(item)); world.registerItem(new Item(item));
}// ember }// ember
for (NPCLoc npc : (List<NPCLoc>) PersistenceManager for (NPCLoc npc : Instance.getDataStore().loadNPCLocs()) {
.load("locs/NpcLoc.xml.gz")) {
if (Config.f2pWildy && Formulae.isP2P(true, npc)) if (Config.f2pWildy && Formulae.isP2P(true, npc))
continue; continue;
if (Formulae.isP2P(npc) && !World.isMembers()) if (Formulae.isP2P(npc) && !World.isMembers())

View File

@ -9,6 +9,7 @@ import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
import org.moparscape.msc.config.Config; import org.moparscape.msc.config.Config;
import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.Server; import org.moparscape.msc.gs.Server;
import org.moparscape.msc.gs.core.ClientUpdater; import org.moparscape.msc.gs.core.ClientUpdater;
import org.moparscape.msc.gs.core.DelayedEventHandler; 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.states.CombatState;
import org.moparscape.msc.gs.util.EntityList; import org.moparscape.msc.gs.util.EntityList;
import org.moparscape.msc.gs.util.Logger; import org.moparscape.msc.gs.util.Logger;
import org.moparscape.msc.gs.util.PersistenceManager;
public final class World { public final class World {
@ -471,8 +471,7 @@ public final class World {
*/ */
private void loadNpcHandlers() { private void loadNpcHandlers() {
NpcHandlerDef[] handlerDefs = (NpcHandlerDef[]) PersistenceManager NpcHandlerDef[] handlerDefs = Instance.getDataStore().loadNpcHandlers();
.load("NpcHandlers.xml");
for (NpcHandlerDef handlerDef : handlerDefs) { for (NpcHandlerDef handlerDef : handlerDefs) {
try { try {
String className = handlerDef.getClassName(); String className = handlerDef.getClassName();

View 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();
}

View File

@ -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();
}
}

View File

@ -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() {
}
}

View File

@ -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);
}
}
}

View File

@ -58,7 +58,7 @@ public class Server {
System.out.println("Login Server starting up..."); System.out.println("Login Server starting up...");
Config.initConfig(configFile); Config.initConfig(configFile);
try { try {
storage = StorageMediumFactory.createMedium(Config.STORAGE_MEDIUM); storage = StorageMediumFactory.create(Config.STORAGE_MEDIUM);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return; return;

View File

@ -2,7 +2,7 @@ package org.moparscape.msc.ls.persistence;
public class StorageMediumFactory { 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) return Class.forName(className).asSubclass(StorageMedium.class)
.newInstance(); .newInstance();
} }