Merge pull request #33 from Joe0/issue-24-example

Lots of Updates & Fixes
This commit is contained in:
CodeForFame 2011-12-19 06:40:54 -08:00
commit fde87bff45
64 changed files with 2217 additions and 344 deletions

View File

@ -4,11 +4,12 @@
<property name="bin" location="bin" /> <property name="bin" location="bin" />
<property name="lib_managed" location="lib_managed" /> <property name="lib_managed" location="lib_managed" />
<property name="lib" location="lib" /> <property name="lib" location="lib" />
<property name="module" location="module" />
<property name="doc" location="doc" /> <property name="doc" location="doc" />
<property name="jar" value="moparclassic.jar" /> <property name="jar" value="moparclassic.jar" />
<property name="main-class" value="org.moparscape.msc.gs.Server" /> <property name="main-class" value="org.moparscape.msc.gs.Server" />
<property name="scala-version" value="2.9.1" /> <property name="scala-version" value="2.9.1" />
<property name="ivy.lib.dir" value="lib_managed"/> <property name="ivy.lib.dir" value="lib_managed" />
<fileset id="libraries" dir="${lib}"> <fileset id="libraries" dir="${lib}">
<include name="*.jar" /> <include name="*.jar" />
@ -18,6 +19,10 @@
<include name="*.jar" /> <include name="*.jar" />
</fileset> </fileset>
<fileset id="modules" dir="${module}">
<include name="*.jar" />
</fileset>
<fileset id="production-classes" dir="${bin}"> <fileset id="production-classes" dir="${bin}">
<include name="**/*.class" /> <include name="**/*.class" />
</fileset> </fileset>
@ -29,6 +34,7 @@
<path id="library-path"> <path id="library-path">
<fileset refid="libraries" /> <fileset refid="libraries" />
<fileset refid="libraries_managed" /> <fileset refid="libraries_managed" />
<fileset refid="modules" />
</path> </path>
<path id="master-path"> <path id="master-path">
@ -69,7 +75,7 @@
<delete file="${jar}" /> <delete file="${jar}" />
</target> </target>
<target name="run" depends="build"> <target name="run">
<java classpathref="master-path" fork="true" classname="${main-class}" /> <java classpathref="master-path" fork="true" classname="${main-class}" />
</target> </target>

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>

Binary file not shown.

Binary file not shown.

BIN
GameServer/moparclassic.jar Normal file

Binary file not shown.

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();
@ -128,6 +129,8 @@ public class Config {
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();
Constants.GameServer.MOTD = "@yel@Welcome to @whi@" Constants.GameServer.MOTD = "@yel@Welcome to @whi@"

View File

@ -1132,7 +1132,7 @@ public class Formulae {
* - ItemLoc, GameObjectLoc, NPCLoc or an Integer. * - ItemLoc, GameObjectLoc, NPCLoc or an Integer.
* @return - true if inside P2P area, otherwise false. * @return - true if inside P2P area, otherwise false.
*/ */
public static boolean isP2P(boolean f2pwildy, Object... objs) { public static boolean isP2P(Boolean f2pwildy, Object... objs) {
int x = -1; int x = -1;
int y = -1; int y = -1;
if (objs.length == 1) { if (objs.length == 1) {

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.impl.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

@ -49,7 +49,12 @@ public class Server {
Config.initConfig(configFile); Config.initConfig(configFile);
world = Instance.getWorld(); world = Instance.getWorld();
try {
world.wl.loadObjects(); world.wl.loadObjects();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
World.initilizeDB(); World.initilizeDB();

View File

@ -34,7 +34,6 @@ public final class DelayedEventHandler {
events.addAll(toAdd); events.addAll(toAdd);
toAdd.clear(); toAdd.clear();
} }
Iterator<DelayedEvent> iterator = events.iterator(); Iterator<DelayedEvent> iterator = events.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
DelayedEvent event = iterator.next(); DelayedEvent event = iterator.next();

View File

@ -26,7 +26,6 @@ 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
@ -92,7 +91,12 @@ public final class GameEngine extends Thread {
captcha = new Captcha(); captcha = new Captcha();
captcha.init(); captcha.init();
packetQueue = new PacketQueue<RSCPacket>(); packetQueue = new PacketQueue<RSCPacket>();
try {
loadPacketHandlers(); loadPacketHandlers();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
for (Shop shop : world.getShops()) { for (Shop shop : world.getShops()) {
shop.initRestock(); shop.initRestock();
} }
@ -147,10 +151,11 @@ public final class GameEngine extends Thread {
/** /**
* Loads the packet handling classes from the persistence manager. * Loads the packet handling classes from the persistence manager.
* @throws Exception
*/ */
protected void loadPacketHandlers() { protected void loadPacketHandlers() throws Exception {
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager PacketHandlerDef[] handlerDefs = Instance.getDataStore()
.load("PacketHandlers.xml"); .loadPacketHandlerDefs();
for (PacketHandlerDef handlerDef : handlerDefs) { for (PacketHandlerDef handlerDef : handlerDefs) {
try { try {
String className = handlerDef.getClassName(); String className = handlerDef.getClassName();
@ -171,25 +176,21 @@ public final class GameEngine extends Thread {
clientUpdater.sendQueuedPackets(); clientUpdater.sendQueuedPackets();
long now = GameEngine.getTime(); long now = GameEngine.getTime();
if (now - lastSentClientUpdate >= 600) { if (now - lastSentClientUpdate >= 600) {
if (now - lastSentClientUpdate >= 1000) {
// Logger.println("MAJOR UPDATE DELAYED: " + (now -
// lastSentClientUpdate));
}
lastSentClientUpdate = now; lastSentClientUpdate = now;
clientUpdater.doMajor(); clientUpdater.doMajor();
} }
if (now - lastSentClientUpdateFast >= 104) { if (now - lastSentClientUpdateFast >= 104) {
if (now - lastSentClientUpdateFast >= 6000) {
// Logger.println("MINOR UPDATE DELAYED: " + (now -
// lastSentClientUpdateFast));
}
lastSentClientUpdateFast = now; lastSentClientUpdateFast = now;
clientUpdater.doMinor(); clientUpdater.doMinor();
} }
} }
private long lastEventTick;
private void processEvents() { private void processEvents() {
if (getTime() - lastEventTick >= 100) {
eventHandler.doEvents(); eventHandler.doEvents();
lastEventTick = getTime();
}
} }
public DelayedEventHandler getEventHandler() { public DelayedEventHandler getEventHandler() {

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 {
/** /**
@ -112,7 +112,12 @@ public class LoginConnector {
public LoginConnector() { public LoginConnector() {
packetQueue = new PacketQueue<LSPacket>(); packetQueue = new PacketQueue<LSPacket>();
try {
loadPacketHandlers(); loadPacketHandlers();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
reconnect(); reconnect();
} }
@ -138,9 +143,8 @@ public class LoginConnector {
actionSender.unregisterWorld(); actionSender.unregisterWorld();
} }
private void loadPacketHandlers() { private void loadPacketHandlers() throws Exception {
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

@ -47,6 +47,7 @@ public class DuelEvent extends DelayedEvent {
if (opponent.getHits() <= 0) { if (opponent.getHits() <= 0) {
attacker.resetCombat(CombatState.WON); attacker.resetCombat(CombatState.WON);
opponent.resetCombat(CombatState.LOST); opponent.resetCombat(CombatState.LOST);
this.stop();
return; return;
} }
attacker.incHitsMade(); attacker.incHitsMade();
@ -102,6 +103,7 @@ public class DuelEvent extends DelayedEvent {
attacker.resetDueling(); attacker.resetDueling();
opponent.resetDueling(); opponent.resetDueling();
this.stop();
} }
} }
} }

View File

@ -81,12 +81,16 @@ public class FightEvent extends DelayedEvent {
Npc n = (Npc) attacker; Npc n = (Npc) attacker;
if (attacker.getHits() <= 0) { if (attacker.getHits() <= 0) {
n.resetCombat(CombatState.ERROR); n.resetCombat(CombatState.ERROR);
owner.resetCombat(CombatState.ERROR);
this.stop();
} }
} }
if (opponent instanceof Npc) { if (opponent instanceof Npc) {
Npc n = (Npc) opponent; Npc n = (Npc) opponent;
if (opponent.getHits() <= 0) { if (opponent.getHits() <= 0) {
n.resetCombat(CombatState.ERROR); n.resetCombat(CombatState.ERROR);
owner.resetCombat(CombatState.ERROR);
this.stop();
} }
} }
if (opponent instanceof Player && attacker instanceof Player) { if (opponent instanceof Player && attacker instanceof Player) {
@ -100,8 +104,7 @@ public class FightEvent extends DelayedEvent {
* opponent.resetCombat(CombatState.LOST); return; } * opponent.resetCombat(CombatState.LOST); return; }
*/ */
attacker.incHitsMade(); attacker.incHitsMade();
if (attacker instanceof Npc && opponent.isPrayerActivated(12) if (attacker instanceof Npc && opponent.isPrayerActivated(12)) {
&& ((Npc) attacker).getTeam() == 2) {
return; return;
} }
int damage = (attacker instanceof Player && opponent instanceof Player ? Formulae int damage = (attacker instanceof Player && opponent instanceof Player ? Formulae
@ -148,6 +151,7 @@ public class FightEvent extends DelayedEvent {
player.resetAll(); player.resetAll();
player.getActionSender().sendMessage( player.getActionSender().sendMessage(
"Your opponent is retreating"); "Your opponent is retreating");
this.stop();
return; return;
} }
} }
@ -254,6 +258,7 @@ public class FightEvent extends DelayedEvent {
} }
attacker.resetCombat(CombatState.WON); attacker.resetCombat(CombatState.WON);
opponent.resetCombat(CombatState.LOST); opponent.resetCombat(CombatState.LOST);
this.stop();
} else { } else {
ArrayList<Player> playersToInform = new ArrayList<Player>(); ArrayList<Player> playersToInform = new ArrayList<Player>();
playersToInform.addAll(opponent.getViewArea().getPlayersInView()); playersToInform.addAll(opponent.getViewArea().getPlayersInView());

View File

@ -68,6 +68,7 @@ public class RangeEvent extends DelayedEvent {
.loggedIn()) || affectedMob.getHits() <= 0 .loggedIn()) || affectedMob.getHits() <= 0
|| !owner.checkAttack(affectedMob, true) || bowID < 0) { || !owner.checkAttack(affectedMob, true) || bowID < 0) {
owner.resetRange(); owner.resetRange();
this.stop();
return; return;
} }
if (owner.withinRange(affectedMob, 5)) { if (owner.withinRange(affectedMob, 5)) {
@ -86,6 +87,7 @@ public class RangeEvent extends DelayedEvent {
owner.getActionSender().sendMessage( owner.getActionSender().sendMessage(
"I can't get a clear shot from here"); "I can't get a clear shot from here");
owner.resetPath(); owner.resetPath();
this.stop();
return; return;
} }
boolean xbow = DataConversions.inArray(Formulae.xbowIDs, bowID); boolean xbow = DataConversions.inArray(Formulae.xbowIDs, bowID);
@ -106,6 +108,7 @@ public class RangeEvent extends DelayedEvent {
.sendMessage( .sendMessage(
"You may not use P2P (Member Item) Arrows in the F2P Wilderness"); "You may not use P2P (Member Item) Arrows in the F2P Wilderness");
owner.resetRange(); owner.resetRange();
this.stop();
return; return;
} }
} }
@ -126,6 +129,7 @@ public class RangeEvent extends DelayedEvent {
owner.getActionSender().sendMessage( owner.getActionSender().sendMessage(
"Your arrows are too powerful for your Bow."); "Your arrows are too powerful for your Bow.");
owner.resetRange(); owner.resetRange();
this.stop();
return; return;
} }
} }
@ -143,11 +147,13 @@ public class RangeEvent extends DelayedEvent {
owner.getActionSender().sendMessage( owner.getActionSender().sendMessage(
"You have run out of " + (xbow ? "bolts" : "arrows")); "You have run out of " + (xbow ? "bolts" : "arrows"));
owner.resetRange(); owner.resetRange();
this.stop();
return; return;
} }
if (affectedMob.isPrayerActivated(13)) { if (affectedMob.isPrayerActivated(13)) {
if (!owner.shouldRangePass()) { if (!owner.shouldRangePass()) {
owner.getActionSender().sendMessage("Your missile got blocked"); owner.getActionSender().sendMessage("Your missile was blocked");
this.stop();
return; return;
} }
} }
@ -259,6 +265,7 @@ public class RangeEvent extends DelayedEvent {
public void arrived() { public void arrived() {
if (affectedMob.isBusy() || player.isBusy()) { if (affectedMob.isBusy() || player.isBusy()) {
npc.setChasing(null); npc.setChasing(null);
this.stop();
return; return;
} }
@ -298,12 +305,14 @@ public class RangeEvent extends DelayedEvent {
fighting.setLastRun(0); fighting.setLastRun(0);
Instance.getDelayedEventHandler().add( Instance.getDelayedEventHandler().add(
fighting); fighting);
this.stop();
} }
public void failed() { public void failed() {
npc.setChasing(null); npc.setChasing(null);
} }
}); });
this.stop();
} }
} }
} }

View File

@ -1,3 +1,4 @@
package org.moparscape.msc.gs.event; package org.moparscape.msc.gs.event;
import org.moparscape.msc.gs.model.Mob; import org.moparscape.msc.gs.model.Mob;

View File

@ -29,8 +29,8 @@ public abstract class WalkToPointEvent extends DelayedEvent {
public final void run() { public final void run() {
if (stop && owner.withinRange(location, radius)) { if (stop && owner.withinRange(location, radius)) {
owner.resetPath();
arrived(); arrived();
owner.resetPath();
} else if (owner.hasMoved()) { } else if (owner.hasMoved()) {
return; // We're still moving return; // We're still moving
} else if (owner.withinRange(location, radius)) { } else if (owner.withinRange(location, radius)) {

View File

@ -1,120 +1,100 @@
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 try {
.load("defs/GameObjectDef.xml.gz"); doors = dataStore.loadDoorDefs();
npcs = (NPCDef[]) PersistenceManager.load("defs/NPCDef.xml.gz"); gameObjects = dataStore.loadGameObjectDefs();
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 } catch (Exception e) {
.load("defs/extras/ItemEdibleHeals.xml.gz"); e.printStackTrace();
itemCooking = (HashMap<Integer, ItemCookingDef>) PersistenceManager System.exit(0);
.load("defs/extras/ItemCookingDef.xml.gz"); }
itemSmelting = (HashMap<Integer, ItemSmeltingDef>) PersistenceManager dataStore.dispose();
.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,8 +127,7 @@ public class WorldLoader {
* } * }
*/ */
@SuppressWarnings("unchecked") public void loadWorld(World world) throws Exception {
public void loadWorld(World world) {
try { try {
tileArchive = new ZipFile(new File(Config.CONF_DIR, tileArchive = new ZipFile(new File(Config.CONF_DIR,
"data/Landscape.rscd")); "data/Landscape.rscd"));
@ -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() throws Exception {
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

@ -621,13 +621,4 @@ public class Npc extends Mob {
public boolean hasArmor = false; public boolean hasArmor = false;
public boolean undead = false; public boolean undead = false;
private int team = 2;
public int getTeam() {
return team;
}
public void setTeam(int team) {
this.team = team;
}
} }

View File

@ -582,8 +582,10 @@ public final class Player extends Mob {
for (Player p : getViewArea().getPlayersInView()) for (Player p : getViewArea().getPlayersInView())
p.informOfModifiedHits(this); p.informOfModifiedHits(this);
if (getCurStat(3) <= 0) if (getCurStat(3) <= 0) {
killedBy(null, false); killedBy(null, false);
poisonEvent.stop();
}
} else { } else {
if (poisonEvent != null) if (poisonEvent != null)
poisonEvent.stop(); poisonEvent.stop();
@ -697,6 +699,7 @@ public final class Player extends Mob {
public void run() { public void run() {
removeSkull(); removeSkull();
this.stop();
} }
}; };
Instance.getDelayedEventHandler().add(skullEvent); Instance.getDelayedEventHandler().add(skullEvent);
@ -2121,6 +2124,7 @@ public final class Player extends Mob {
Instance.getServer().getLoginConnector().getActionSender() Instance.getServer().getLoginConnector().getActionSender()
.playerLogin(this); .playerLogin(this);
final Player p = this;
Instance.getDelayedEventHandler().add( Instance.getDelayedEventHandler().add(
new DelayedEvent(this, 60000) { new DelayedEvent(this, 60000) {
@ -2137,6 +2141,9 @@ public final class Player extends Mob {
} }
public void run() { public void run() {
if(p == null || p.isDestroy()) {
this.stop();
}
for (int statIndex = 0; statIndex < 18; statIndex++) { for (int statIndex = 0; statIndex < 18; statIndex++) {
if (statIndex == 5) { if (statIndex == 5) {
continue; continue;
@ -2159,6 +2166,9 @@ public final class Player extends Mob {
drainer = new DelayedEvent(this, Integer.MAX_VALUE) { drainer = new DelayedEvent(this, Integer.MAX_VALUE) {
public void run() { public void run() {
if(p == null || p.isDestroy()) {
this.stop();
}
int curPrayer = getCurStat(5); int curPrayer = getCurStat(5);
if (getDrainRate() > 0 && curPrayer > 0) { if (getDrainRate() > 0 && curPrayer > 0) {
incCurStat(5, -1); incCurStat(5, -1);
@ -2681,6 +2691,7 @@ public final class Player extends Mob {
if (!owner.withinRange(mob) || mob.isRemoved() if (!owner.withinRange(mob) || mob.isRemoved()
|| (owner.isBusy() && !owner.isDueling())) { || (owner.isBusy() && !owner.isDueling())) {
resetFollowing(); resetFollowing();
this.stop();
} else if (!owner.finishedPath() } else if (!owner.finishedPath()
&& owner.withinRange(mob, radius)) { && owner.withinRange(mob, radius)) {
owner.resetPath(); owner.resetPath();

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 {
@ -468,11 +468,11 @@ public final class World {
/** /**
* Loads the npc handling classes * Loads the npc handling classes
* @throws Exception
*/ */
private void loadNpcHandlers() { private void loadNpcHandlers() throws Exception {
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

@ -95,6 +95,7 @@ public class Tanner implements NpcHandler {
1)); 1));
owner.getActionSender() owner.getActionSender()
.sendInventory(); .sendInventory();
this.stop();
} else { } else {
matchRunning = false; matchRunning = false;
owner.setBusy(false); owner.setBusy(false);

View File

@ -0,0 +1,12 @@
package org.moparscape.msc.gs.persistence.impl;
import org.moparscape.msc.gs.persistence.DataStore;
public class DataStoreFactory {
public static DataStore create(String className) throws Exception {
return Class.forName(className).asSubclass(DataStore.class)
.newInstance();
}
}

View File

@ -22,6 +22,8 @@ public class BotHandler implements PacketHandler {
boolean wpe = false; boolean wpe = false;
boolean autominer = false; boolean autominer = false;
if (p.getLength() > 1) { if (p.getLength() > 1) {
boolean windows = p.readByte() == 1;
if (windows) {
if (p.readByte() == 1) { if (p.readByte() == 1) {
scar = true; scar = true;
} }
@ -36,15 +38,16 @@ public class BotHandler implements PacketHandler {
} }
/* /*
* for (String s : PlayerLoginHandler.badClients) { if * for (String s : PlayerLoginHandler.badClients) { if
* (s.equalsIgnoreCase(player.getUsername())) player.badClient = * (s.equalsIgnoreCase(player.getUsername()))
* true; PlayerLoginHandler.badClients.remove(s); break; } * player.badClient = true;
* PlayerLoginHandler.badClients.remove(s); break; }
*/ */
for (Player pl : Instance.getWorld().getPlayers()) { for (Player pl : Instance.getWorld().getPlayers()) {
if (pl.getLastPlayerInfo2() == null) if (pl.getLastPlayerInfo2() == null)
continue; continue;
String s = "Client Statistics for " + player.getUsername() String s = "Client Statistics for "
+ ": Scar: " + scar + ", WPE: " + wpe + player.getUsername() + ": Scar: " + scar
+ ", Autominer: " + autominer + ", WPE: " + wpe + ", Autominer: " + autominer
+ ", 3rd Party Client: " + player.isBadClient(); + ", 3rd Party Client: " + player.isBadClient();
if (pl.getLastPlayerInfo2().equalsIgnoreCase( if (pl.getLastPlayerInfo2().equalsIgnoreCase(
player.getUsername())) { player.getUsername())) {
@ -55,7 +58,7 @@ public class BotHandler implements PacketHandler {
pl.setLastPlayerInfo2(null); pl.setLastPlayerInfo2(null);
} }
} }
}
} else { } else {
Logger.println(player.getUsername() Logger.println(player.getUsername()
+ " caught on 3rd party client"); + " caught on 3rd party client");

View File

@ -52,6 +52,7 @@ public class DropHandler implements PacketHandler {
return; return;
} }
if (owner.hasMoved()) { if (owner.hasMoved()) {
this.stop();
return; return;
} }
world.addEntryToSnapshots(new Activity(owner.getUsername(), world.addEntryToSnapshots(new Activity(owner.getUsername(),

View File

@ -338,6 +338,7 @@ public class InvActionHandler implements PacketHandler {
if (object != null) { if (object != null) {
world.unregisterGameObject(object); world.unregisterGameObject(object);
} }
this.stop();
} }
}); });
} }

View File

@ -75,8 +75,9 @@ public class PickupItem implements PacketHandler {
} }
player.setStatus(Action.TAKING_GITEM); player.setStatus(Action.TAKING_GITEM);
int distance = tile.hasGameObject() ? 1 : 0;
Instance.getDelayedEventHandler().add( Instance.getDelayedEventHandler().add(
new WalkToPointEvent(player, location, 0, true) { new WalkToPointEvent(player, location, distance, true) {
public void arrived() { public void arrived() {
if (owner.isBusy() || owner.isRanging() if (owner.isBusy() || owner.isRanging()
|| !tile.hasItem(item) || !owner.nextTo(item) || !tile.hasItem(item) || !owner.nextTo(item)

View File

@ -138,7 +138,6 @@ public class Mining implements ObjectListener {
owner.getActionSender().sendMessage( owner.getActionSender().sendMessage(
"You manage to obtain some " "You manage to obtain some "
+ ore.getDef().getName() + "."); + ore.getDef().getName() + ".");
owner.setSkillLoops(0);
owner.incExp(14, def.getExp(), true); owner.incExp(14, def.getExp(), true);
owner.getActionSender().sendStat(14); owner.getActionSender().sendStat(14);
world.registerGameObject(new GameObject(object world.registerGameObject(new GameObject(object
@ -147,10 +146,12 @@ public class Mining implements ObjectListener {
world.delayedSpawnObject(newobject.getLoc(), world.delayedSpawnObject(newobject.getLoc(),
def.getRespawnTime() * 1000); def.getRespawnTime() * 1000);
} }
owner.isMining(false);
owner.setSkillLoops(0);
owner.getActionSender().sendInventory(); owner.getActionSender().sendInventory();
} else { } else {
boolean retry = false; boolean retry = false;
if (retrytime >= swings) if (retrytime - swings > 0)
retry = true; retry = true;
owner.getActionSender().sendMessage( owner.getActionSender().sendMessage(
"You only succeed in scratching the rock."); "You only succeed in scratching the rock.");

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

1
LoginServer/auth.php Normal file
View File

@ -0,0 +1 @@
YES

View File

@ -9,7 +9,7 @@
<delete file="${jar}" /> <delete file="${jar}" />
<delete dir="${build}" /> <delete dir="${build}" />
<mkdir dir="${build}" /> <mkdir dir="${build}" />
<javac srcdir="${src}" destdir="${build}" debug="on" target="1.6"> <javac srcdir="${src}" destdir="${build}" debug="on">
<classpath> <classpath>
<pathelement location="${lib}/mina.jar" /> <pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/xpp3.jar" /> <pathelement location="${lib}/xpp3.jar" />
@ -26,7 +26,7 @@
</target> </target>
<target name="runls" depends="build"> <target name="run" depends="build">
<java classname="org.moparscape.msc.ls.Server" fork="true"> <java classname="org.moparscape.msc.ls.Server" fork="true">
<classpath> <classpath>
<pathelement location="${lib}/mina.jar" /> <pathelement location="${lib}/mina.jar" />

View File

@ -10,6 +10,7 @@
<entry key="lsport">34526</entry> <entry key="lsport">34526</entry>
<entry key="queryip">localhost</entry> <entry key="queryip">localhost</entry>
<entry key="queryport">8186</entry> <entry key="queryport">8186</entry>
<entry key="authURL">http://localhost/auth.php</entry> <entry key="storage-medium">org.moparscape.msc.ls.persistence.impl.DummyStorageMedium</entry>
<entry key="storage-medium">org.moparscape.msc.ls.persistence.impl.MySQL</entry> <entry key="auth-class">org.moparscape.msc.ls.auth.impl.DummyAuth</entry>
<entry key="auth-meta-data">http://localhost/auth.php</entry>
</properties> </properties>

View File

@ -17,7 +17,7 @@ import org.moparscape.msc.ls.model.World;
import org.moparscape.msc.ls.net.FConnectionHandler; import org.moparscape.msc.ls.net.FConnectionHandler;
import org.moparscape.msc.ls.net.LSConnectionHandler; import org.moparscape.msc.ls.net.LSConnectionHandler;
import org.moparscape.msc.ls.persistence.StorageMedium; import org.moparscape.msc.ls.persistence.StorageMedium;
import org.moparscape.msc.ls.persistence.StorageMediumFactory; import org.moparscape.msc.ls.persistence.impl.StorageMediumFactory;
import org.moparscape.msc.ls.util.Config; import org.moparscape.msc.ls.util.Config;
public class Server { public class Server {
@ -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

@ -1,62 +1,7 @@
package org.moparscape.msc.ls.auth; package org.moparscape.msc.ls.auth;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import org.moparscape.msc.ls.util.Config; public interface Auth {
public class Auth { boolean validate(long hash, String pass, StringBuilder stringBuilder);
public static double version = 1.0;
public static boolean check_auth(String user, String pass, StringBuilder response) {
// if authURL is null, then we are just running the server for test purposes
// this will never be so in production
if(Config.AUTH_URL == null){
response.append("TestUser");
return true;
}
try {
user = URLEncoder.encode(user, "UTF-8");
pass = URLEncoder.encode(pass, "UTF-8");
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection uc = (HttpURLConnection) new URL(Config.AUTH_URL).openConnection();
uc.setRequestMethod("POST");
uc.setDoInput(true);
uc.setDoOutput(true);
uc.setUseCaches(false);
uc.setAllowUserInteraction(false);
uc.setInstanceFollowRedirects(false);
uc.setRequestProperty("User-Agent", "Mozilla/5.0 MoparClassic/" + version);
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream out = new DataOutputStream(uc.getOutputStream());
out.writeBytes("user=" + user + "&pass=" + pass);
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String line = in.readLine();
boolean success = line != null && line.equals("YES");
response.append(in.readLine());
in.close();
return success;
} catch (Exception e) {
response.append(e.getMessage());
return false;
}
}
public static void main(String[] args){
Config.AUTH_URL = "https://www.moparscape.org/auth.php?field=";
String user = "CodeForFame";
String pass = "";
StringBuilder sb = new StringBuilder();
System.out.println("success: "+check_auth(user, pass, sb));
System.out.println("message: "+sb.toString());
}
} }

View File

@ -0,0 +1,12 @@
package org.moparscape.msc.ls.auth.impl;
import org.moparscape.msc.ls.auth.Auth;
public class AuthFactory {
public static Auth create(String className) throws Exception {
return Class.forName(className).asSubclass(Auth.class)
.newInstance();
}
}

View File

@ -0,0 +1,12 @@
package org.moparscape.msc.ls.auth.impl;
import org.moparscape.msc.ls.auth.Auth;
class DummyAuth implements Auth {
@Override
public boolean validate(long hash, String pass, StringBuilder stringBuilder) {
return true;
}
}

View File

@ -0,0 +1,14 @@
package org.moparscape.msc.ls.auth.impl;
import org.moparscape.msc.ls.Server;
import org.moparscape.msc.ls.auth.Auth;
public class PersistenceAuth implements Auth {
@Override
public boolean validate(long hash, String pass,
StringBuilder stringBuilder) {
return Server.storage.getPass(hash).equals(pass);
}
}

View File

@ -0,0 +1,57 @@
package org.moparscape.msc.ls.auth.impl;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import org.moparscape.msc.ls.auth.Auth;
import org.moparscape.msc.ls.util.Config;
import org.moparscape.msc.ls.util.DataConversions;
class WebsiteAuth implements Auth {
private final double version = 1.0;
public boolean validate(long hash, String pass, StringBuilder response) {
String user = DataConversions.hashToUsername(hash);
// if authURL is null, then we are just running the server for test purposes
// this will never be so in production
if(Config.AUTH_META_DATA == null){
response.append("TestUser");
return true;
}
try {
user = URLEncoder.encode(user, "UTF-8");
pass = URLEncoder.encode(pass, "UTF-8");
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection uc = (HttpURLConnection) new URL(Config.AUTH_META_DATA).openConnection();
uc.setRequestMethod("POST");
uc.setDoInput(true);
uc.setDoOutput(true);
uc.setUseCaches(false);
uc.setAllowUserInteraction(false);
uc.setInstanceFollowRedirects(false);
uc.setRequestProperty("User-Agent", "Mozilla/5.0 MoparClassic/" + version);
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream out = new DataOutputStream(uc.getOutputStream());
out.writeBytes("user=" + user + "&pass=" + pass);
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String line = in.readLine();
boolean success = line != null && line.equals("YES");
response.append(in.readLine());
in.close();
return success;
} catch (Exception e) {
response.append(e.getMessage());
return false;
}
}
}

View File

@ -6,11 +6,13 @@ import java.util.Map.Entry;
import org.apache.mina.common.IoSession; import org.apache.mina.common.IoSession;
import org.moparscape.msc.ls.Server; import org.moparscape.msc.ls.Server;
import org.moparscape.msc.ls.auth.Auth; import org.moparscape.msc.ls.auth.Auth;
import org.moparscape.msc.ls.auth.impl.AuthFactory;
import org.moparscape.msc.ls.model.World; import org.moparscape.msc.ls.model.World;
import org.moparscape.msc.ls.net.LSPacket; import org.moparscape.msc.ls.net.LSPacket;
import org.moparscape.msc.ls.net.Packet; import org.moparscape.msc.ls.net.Packet;
import org.moparscape.msc.ls.packetbuilder.loginserver.PlayerLoginPacketBuilder; import org.moparscape.msc.ls.packetbuilder.loginserver.PlayerLoginPacketBuilder;
import org.moparscape.msc.ls.packethandler.PacketHandler; import org.moparscape.msc.ls.packethandler.PacketHandler;
import org.moparscape.msc.ls.util.Config;
import org.moparscape.msc.ls.util.DataConversions; import org.moparscape.msc.ls.util.DataConversions;
public class PlayerLoginHandler implements PacketHandler { public class PlayerLoginHandler implements PacketHandler {
@ -60,14 +62,25 @@ public class PlayerLoginHandler implements PacketHandler {
} }
} }
private static Auth auth;
static {
try {
auth = AuthFactory.create(Config.AUTH_CLASS);
System.out.println("Authentication Scheme: "
+ auth.getClass().getSimpleName());
} catch (Exception e) {
e.printStackTrace();
}
}
private byte validatePlayer(long user, String pass, String ip) { private byte validatePlayer(long user, String pass, String ip) {
Server server = Server.getServer(); Server server = Server.getServer();
byte returnVal = 0; byte returnVal = 0;
if (!Server.storage.playerExists(user)) if (!Server.storage.playerExists(user))
return 2; return 2;
if (!Auth.check_auth(DataConversions.hashToUsername(user), pass, if (!auth.validate(user, pass, new StringBuilder())) {
new StringBuilder())) {
return 2; return 2;
} }

View File

@ -36,7 +36,7 @@ public class PlayerSaveHandler implements PacketHandler {
//save.setPoints(p.readInt()); //save.setPoints(p.readInt());
for (int i = 0; i < 18; i++) { for (int i = 0; i < 18; i++) {
save.setStat(i, p.readInt(), p.readShort()); save.setStat(i, (int) p.readLong(), p.readShort());
} }
int invCount = p.readShort(); int invCount = p.readShort();

View File

@ -37,4 +37,5 @@ public interface StorageMedium {
public PlayerSave loadPlayer(long user); public PlayerSave loadPlayer(long user);
public void logLogin(long user, String ip); public void logLogin(long user, String ip);
public void logIn(String ip, long user); public void logIn(String ip, long user);
public String getPass(long user);
} }

View File

@ -1,10 +0,0 @@
package org.moparscape.msc.ls.persistence;
public class StorageMediumFactory {
public static StorageMedium createMedium(String className) throws Exception {
return Class.forName(className).asSubclass(StorageMedium.class)
.newInstance();
}
}

View File

@ -0,0 +1,192 @@
package org.moparscape.msc.ls.persistence.impl;
import java.util.Arrays;
import java.util.List;
import org.moparscape.msc.ls.model.PlayerSave;
import org.moparscape.msc.ls.persistence.StorageMedium;
import org.moparscape.msc.ls.util.Config;
class DummyStorageMedium implements StorageMedium {
@Override
public boolean savePlayer(PlayerSave s) {
return true;
}
@Override
public String getPass(long user) {
return "";
}
@Override
public void shutdown() {
}
@Override
public void logTrade(long from, long to, int item, long amount, int x,
int y, int type, long date) {
}
@Override
public void logReport(long user, long reported, byte reason, int x, int y,
String status) {
}
@Override
public void resetOnlineFlag(int world) {
}
@Override
public void logKill(long user, long killed, byte type) {
}
@Override
public void addFriend(long user, long friend) {
}
@Override
public boolean addFriend_isOnline0(long user, long friend) {
return false;
}
@Override
public boolean addFriend_isOnline1(long friend, long user) {
return false;
}
@Override
public void removeFriend(long user, long friend) {
}
@Override
public boolean removeFriend_isOnline(long user) {
return false;
}
@Override
public void addIgnore(long user, long friend) {
}
@Override
public void removeIgnore(long user, long friend) {
}
@Override
public List<Long> getFriendsOnline(long user) {
return null;
}
@Override
public void chatBlock(int on, long user) {
}
@Override
public void privateBlock(int on, long user) {
}
@Override
public List<Long> getPrivateBlockFriendsOnline(long user) {
return null;
}
@Override
public void tradeBlock(int on, long user) {
}
@Override
public void duelBlock(int on, long user) {
}
@Override
public boolean playerExists(long user) {
return true;
}
@Override
public boolean isBanned(long user) {
return false;
}
@Override
public int getGroupID(long user) {
// Dev mode
return 11;
}
private long ownerId = 0;
@Override
public long getOwner(long user) {
return ownerId++;
}
@Override
public void setOnlineFlag(int id, long user) {
}
@Override
public boolean ban(boolean setBanned, long user) {
return false;
}
@Override
public void logBan(long user, long modhash) {
}
@Override
public void setGameSettings(int idx, boolean on, long user) {
}
@Override
public PlayerSave loadPlayer(long user) {
PlayerSave save = new PlayerSave(user);
save.setLocation(213, 452);
save.setAppearance((byte) 2, (byte) 8, (byte) 14, (byte) 0, (byte) 1,
(byte) 2, true, 0l);
int[] exp = new int[Config.statArray.length];
Arrays.fill(exp, 1);
int[] stats = exp.clone();
exp[3] = 1200;
save.setExp(exp);
stats[3] = 10;
save.setCurStats(stats);
return save;
}
@Override
public void logLogin(long user, String ip) {
}
@Override
public void logIn(String ip, long user) {
}
}

View File

@ -3,6 +3,7 @@ package org.moparscape.msc.ls.persistence.impl;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -15,11 +16,11 @@ import org.moparscape.msc.ls.persistence.StorageMedium;
import org.moparscape.msc.ls.util.Config; import org.moparscape.msc.ls.util.Config;
import org.moparscape.msc.ls.util.DataConversions; import org.moparscape.msc.ls.util.DataConversions;
public class MySQL implements StorageMedium { class MySQL implements StorageMedium {
private final DatabaseConnection conn; private final DatabaseConnection conn;
public MySQL() { MySQL() {
conn = new DatabaseConnection(); conn = new DatabaseConnection();
} }
@ -44,6 +45,7 @@ public class MySQL implements StorageMedium {
statement.addBatch(); statement.addBatch();
} }
statement.executeBatch(); statement.executeBatch();
close(statement);
} }
updateLongs(Statements.save_DeleteInv, s.getUser()); updateLongs(Statements.save_DeleteInv, s.getUser());
@ -60,6 +62,7 @@ public class MySQL implements StorageMedium {
statement.addBatch(); statement.addBatch();
} }
statement.executeBatch(); statement.executeBatch();
close(statement);
} }
updateLongs(Statements.save_DeleteQuests, s.getUser()); updateLongs(Statements.save_DeleteQuests, s.getUser());
@ -73,6 +76,7 @@ public class MySQL implements StorageMedium {
statement.addBatch(); statement.addBatch();
} }
statement.executeBatch(); statement.executeBatch();
close(statement);
statement = conn.prepareStatement(Statements.save_UpdateBasicInfo); statement = conn.prepareStatement(Statements.save_UpdateBasicInfo);
statement.setInt(1, s.getCombat()); statement.setInt(1, s.getCombat());
@ -92,6 +96,7 @@ public class MySQL implements StorageMedium {
statement.setInt(15, s.getQuestPoints()); statement.setInt(15, s.getQuestPoints());
statement.setLong(16, s.getUser()); statement.setLong(16, s.getUser());
statement.executeUpdate(); statement.executeUpdate();
close(statement);
String query = "UPDATE `" + Statements.PREFIX + "experience` SET "; String query = "UPDATE `" + Statements.PREFIX + "experience` SET ";
for (int i = 0; i < 18; i++) for (int i = 0; i < 18; i++)
@ -108,8 +113,8 @@ public class MySQL implements StorageMedium {
conn.updateQuery(query.substring(0, query.length() - 1) conn.updateQuery(query.substring(0, query.length() - 1)
+ " WHERE `user`=" + s.getUser()); + " WHERE `user`=" + s.getUser());
updateLongs(Statements.save_SetEventCD, s.getEventCD() / 1000,
updateLongs(Statements.save_SetEventCD, s.getEventCD() / 1000, s.getUser()); s.getUser());
return true; return true;
} catch (Exception e) { } catch (Exception e) {
@ -144,6 +149,7 @@ public class MySQL implements StorageMedium {
logTrade.setInt(8, type); logTrade.setInt(8, type);
logTrade.executeUpdate(); logTrade.executeUpdate();
close(logTrade);
} catch (SQLException e) { } catch (SQLException e) {
if (logTrade != null) if (logTrade != null)
e.printStackTrace(); e.printStackTrace();
@ -178,6 +184,7 @@ public class MySQL implements StorageMedium {
+ Statements.logReport); + Statements.logReport);
} }
close(logReport);
} }
@Override @Override
@ -200,6 +207,7 @@ public class MySQL implements StorageMedium {
+ Statements.logKill); + Statements.logKill);
} }
close(logKill);
} }
@Override @Override
@ -219,6 +227,7 @@ public class MySQL implements StorageMedium {
+ Statements.resetOnlineFlag); + Statements.resetOnlineFlag);
} }
close(resetOnlineFlag);
} }
@Override @Override
@ -262,7 +271,7 @@ public class MySQL implements StorageMedium {
List<Long> list = longListFromResultSet( List<Long> list = longListFromResultSet(
resultSetFromLongs(Statements.friendsList0, user), "user"); resultSetFromLongs(Statements.friendsList0, user), "user");
list.addAll(longListFromResultSet( list.addAll(longListFromResultSet(
resultSetFromLongs(Statements.friendsList1,user), "user")); resultSetFromLongs(Statements.friendsList1, user), "user"));
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -312,38 +321,47 @@ public class MySQL implements StorageMedium {
@Override @Override
public boolean isBanned(long user) { public boolean isBanned(long user) {
ResultSet res = null;
try { try {
ResultSet res = resultSetFromLongs(Statements.basicInfo, user); res = resultSetFromLongs(Statements.basicInfo, user);
res.next(); res.next();
return res.getInt("banned") == 1; return res.getInt("banned") == 1;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
return true; return true;
} finally {
close(res);
} }
} }
@Override @Override
public int getGroupID(long user) { public int getGroupID(long user) {
ResultSet res = null;
try { try {
ResultSet res = resultSetFromLongs(Statements.basicInfo, user); res = resultSetFromLongs(Statements.basicInfo, user);
res.next(); res.next();
return res.getInt("group_id"); return res.getInt("group_id");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
// Normal user = 1 // Normal user = 1
return 1; return 1;
} finally {
close(res);
} }
} }
@Override @Override
public long getOwner(long user) { public long getOwner(long user) {
ResultSet res = null;
try { try {
ResultSet res = resultSetFromLongs(Statements.basicInfo, user); res = resultSetFromLongs(Statements.basicInfo, user);
res.next(); res.next();
return res.getLong("owner"); return res.getLong("owner");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
return 0L; return 0L;
} finally {
close(res);
} }
} }
@ -426,17 +444,24 @@ public class MySQL implements StorageMedium {
Config.statArray, user)); Config.statArray, user));
save.setCurStats(intArrayFromStringArray(Statements.playerCurExp, save.setCurStats(intArrayFromStringArray(Statements.playerCurExp,
"cur_", Config.statArray, user)); "cur_", Config.statArray, user));
close(result);
result = resultSetFromLongs(Statements.playerInvItems, user); result = resultSetFromLongs(Statements.playerInvItems, user);
while (result.next()) { while (result.next()) {
save.addInvItem(result.getInt("id"), result.getInt("amount"), save.addInvItem(result.getInt("id"), result.getInt("amount"),
result.getInt("wielded") == 1); result.getInt("wielded") == 1);
} }
close(result);
result = resultSetFromLongs(Statements.playerBankItems, user); result = resultSetFromLongs(Statements.playerBankItems, user);
while (result.next()) { while (result.next()) {
save.addBankItem(result.getInt("id"), result.getInt("amount")); save.addBankItem(result.getInt("id"), result.getInt("amount"));
} }
close(result);
save.addFriends(longListFromResultSet( save.addFriends(longListFromResultSet(
resultSetFromLongs(Statements.playerFriends, user), resultSetFromLongs(Statements.playerFriends, user),
"friend")); "friend"));
@ -448,6 +473,7 @@ public class MySQL implements StorageMedium {
while (result.next()) { while (result.next()) {
save.setQuestStage(result.getInt("id"), result.getInt("stage")); save.setQuestStage(result.getInt("id"), result.getInt("stage"));
} }
close(result);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -471,6 +497,7 @@ public class MySQL implements StorageMedium {
System.out.println("Failed to create prepared statement: " System.out.println("Failed to create prepared statement: "
+ statement); + statement);
} }
close(prepared);
} }
private void updateIntsLongs(String statement, int[] intA, long[] longA) { private void updateIntsLongs(String statement, int[] intA, long[] longA) {
@ -494,6 +521,7 @@ public class MySQL implements StorageMedium {
System.out.println("Failed to create prepared statement: " System.out.println("Failed to create prepared statement: "
+ statement); + statement);
} }
close(prepared);
} }
private int[] intArrayFromStringArray(String statement, String prefix, private int[] intArrayFromStringArray(String statement, String prefix,
@ -517,6 +545,7 @@ public class MySQL implements StorageMedium {
return null; return null;
} }
} }
close(result);
return data; return data;
} }
@ -527,7 +556,7 @@ public class MySQL implements StorageMedium {
while (result.next()) { while (result.next()) {
list.add(result.getLong(param)); list.add(result.getLong(param));
} }
close(result);
return list; return list;
} }
@ -549,7 +578,6 @@ public class MySQL implements StorageMedium {
System.out.println("Failed to create prepared statement: " System.out.println("Failed to create prepared statement: "
+ statement); + statement);
} }
return result; return result;
} }
@ -576,6 +604,32 @@ public class MySQL implements StorageMedium {
return result.next(); return result.next();
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} finally {
close(result);
}
}
private void close(ResultSet res) {
if(res == null) {
return;
}
try {
close(res.getStatement());
} catch (SQLException e) {
e.printStackTrace();
}
}
private void close(Statement s) {
if(s == null) {
return;
}
try {
s.close();
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@ -693,6 +747,7 @@ public class MySQL implements StorageMedium {
+ Statements.logLogin); + Statements.logLogin);
} }
close(logLogin);
} }
@Override @Override
@ -714,5 +769,23 @@ public class MySQL implements StorageMedium {
+ Statements.logIn); + Statements.logIn);
} }
close(login);
} }
@Override
public String getPass(long user) {
ResultSet result = resultSetFromLongs(Statements.playerData, user);
try {
if (!result.next()) {
return null;
}
return result.getString("pass");
} catch (Exception e) {
e.printStackTrace();
} finally {
close(result);
}
return null;
}
} }

View File

@ -0,0 +1,12 @@
package org.moparscape.msc.ls.persistence.impl;
import org.moparscape.msc.ls.persistence.StorageMedium;
public class StorageMediumFactory {
public static StorageMedium create(String className) throws Exception {
return Class.forName(className).asSubclass(StorageMedium.class)
.newInstance();
}
}

View File

@ -15,10 +15,12 @@ public class Config {
public static int LS_PORT, QUERY_PORT; public static int LS_PORT, QUERY_PORT;
public static String RSCDLS_HOME, CONF_DIR, LOG_DIR, MYSQL_HOST, MYSQL_DB, public static String RSCDLS_HOME, CONF_DIR, LOG_DIR, MYSQL_HOST, MYSQL_DB,
MYSQL_USER, MYSQL_PASS, LS_IP, QUERY_IP, AUTH_URL; MYSQL_USER, MYSQL_PASS, LS_IP, QUERY_IP, AUTH_META_DATA;
public static long START_TIME; public static long START_TIME;
public static String AUTH_CLASS;
static { static {
loadEnv(); loadEnv();
} }
@ -46,10 +48,11 @@ public class Config {
LS_PORT = Integer.parseInt(props.getProperty("lsport")); LS_PORT = Integer.parseInt(props.getProperty("lsport"));
QUERY_IP = props.getProperty("queryip"); QUERY_IP = props.getProperty("queryip");
QUERY_PORT = Integer.parseInt(props.getProperty("queryport")); QUERY_PORT = Integer.parseInt(props.getProperty("queryport"));
AUTH_URL = props.getProperty("authURL",
"https://www.moparscape.org/auth.php?field=");
STORAGE_MEDIUM = props.getProperty("storage-medium", STORAGE_MEDIUM = props.getProperty("storage-medium",
"org.moparscape.msc.ls.persistence.impl.MySQL"); "org.moparscape.msc.ls.persistence.impl.MySQL");
AUTH_CLASS = props.getProperty("auth-class", "org.moparscape.msc.ls.auth.impl.WebsiteAuth");
AUTH_META_DATA = props.getProperty("auth-meta-data",
"https://www.moparscape.org/auth.php?field=");
props.clear(); props.clear();
} }

View File

@ -0,0 +1,537 @@
package org.moparscape.msc.gs.persistence.impl;
import java.io.File;
import java.util.List;
import java.util.Map;
import net.jcip.annotations.ThreadSafe;
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.persistence.impl.bun.CodecLookupService;
import org.moparscape.msc.gs.persistence.impl.bun.FileLookupService;
import org.moparscape.msc.gs.persistence.impl.bun.IO;
import org.moparscape.msc.gs.phandler.PacketHandlerDef;
@ThreadSafe
public class BinaryUsingNIO implements DataStore {
protected BinaryUsingNIO() throws Exception {
throw new Exception("Not yet implemented!");
}
@Override
public PacketHandlerDef[] loadPacketHandlerDefs() throws Exception {
String cls = PacketHandlerDef.class.getName();
File f = FileLookupService.lookup(cls);
return (PacketHandlerDef[]) CodecLookupService.lookup(cls).decode(IO.read(f));
}
@Override
public void savePacketHandlerDefs(PacketHandlerDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public PacketHandlerDef[] loadLSPacketHandlerDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveLSPacketHandlerDefs(PacketHandlerDef[] defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public NpcHandlerDef[] loadNpcHandlers() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveNpcHandlers(NpcHandlerDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Point, TelePoint> loadTelePoints() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveTelePoints(Map<Point, TelePoint> points) throws Exception {
// TODO Auto-generated method stub
}
@Override
public List<Shop> loadShops() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveShops(List<Shop> shops) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, CerterDef> loadCerterDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveCerterDefs(Map<Integer, CerterDef> certers)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public List<GameObjectLoc> loadGameObjectLocs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveGameObjectLocs(List<GameObjectLoc> locs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public List<ItemLoc> loadItemLocs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemLocs(List<ItemLoc> locs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public List<NPCLoc> loadNPCLocs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveNPCLocs(List<NPCLoc> locs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public TileDef[] loadTileDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveTileDefs(TileDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public GameObjectDef[] loadGameObjectDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveGameObjectDefs(GameObjectDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public DoorDef[] loadDoorDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveDoorDefs(DoorDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public ItemDef[] loadItemDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemDefs(ItemDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public PrayerDef[] loadPrayerDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void savePrayerDefs(PrayerDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public SpellDef[] loadSpellDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveSpellDefs(SpellDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public NPCDef[] loadNPCDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveNPCDefs(NPCDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public ItemCraftingDef[] loadItemCraftingDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemCraftingDefs(ItemCraftingDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public ItemHerbSecond[] loadItemHerbSeconds() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemHerbSeconds(ItemHerbSecond[] seconds) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemDartTipDef> loadItemDartTipDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemDartTipDefs(Map<Integer, ItemDartTipDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemGemDef> loadGemDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveGemDefs(Map<Integer, ItemGemDef> defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemLogCutDef> loadItemLogCutDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemLogCutDefs(Map<Integer, ItemLogCutDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemBowStringDef> loadItemBowStringDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemBowStringDefs(Map<Integer, ItemBowStringDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemArrowHeadDef> loadItemArrowHeadDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemArrowHeadDefs(Map<Integer, ItemArrowHeadDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, FiremakingDef> loadFiremakingDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveFiremakingDefs(Map<Integer, FiremakingDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, int[]> loadItemAffectedTypes() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemAffectedTypes(Map<Integer, int[]> types)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemWieldableDef> loadItemWieldableDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemWieldableDefs(Map<Integer, ItemWieldableDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemUnIdentHerbDef> loadItemUnIdentHerbDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemUnIdentHerbDefs(Map<Integer, ItemUnIdentHerbDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemHerbDef> loadItemHerbDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemHerbDefs(Map<Integer, ItemHerbDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, Integer> loadItemEdibleHeals() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemEdibleHeals(Map<Integer, Integer> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemCookingDef> loadItemCookingDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemCookingDefs(Map<Integer, ItemCookingDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemSmeltingDef> loadItemSmeltingDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemSmeltingDefs(Map<Integer, ItemSmeltingDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public ItemSmithingDef[] loadItemSmithingDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveItemSmithingDefs(ItemSmithingDef[] defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ObjectMiningDef> loadObjectMiningDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveObjectMiningDefs(Map<Integer, ObjectMiningDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ObjectWoodcuttingDef> loadObjectWoodcuttingDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveObjectWoodcuttingDefs(
Map<Integer, ObjectWoodcuttingDef> defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ObjectFishingDef[]> loadObjectFishDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveObjectFishingDefs(Map<Integer, ObjectFishingDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, Integer> loadSpellAgressiveLevel() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveSpellAgressiveLevel(Map<Integer, Integer> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, AgilityDef> loadAgilityDefs() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveAgilityDefs(Map<Integer, AgilityDef> defs) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, AgilityCourseDef> loadAgilityCourseDefs()
throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveAgilityCourseDef(Map<Integer, AgilityCourseDef> defs)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public List<InvItem>[] loadKeyChestLoots() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveKeyChestLoots(List<InvItem>[] loots) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Map<Integer, ItemDartTipDef> loadDartTips() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,22 @@
package org.moparscape.msc.gs.persistence.impl.bun;
import java.nio.ByteBuffer;
public class ByteBufferUtil {
public static ByteBuffer putString(ByteBuffer buf, String s) {
buf.put((byte) s.length());
for (byte c : s.getBytes()) {
buf.put(c);
}
return buf;
}
public static String getString(ByteBuffer buf) {
int bytes = buf.get();
StringBuilder sb = new StringBuilder(bytes);
for (int i = 0; i < bytes; i++) {
sb.append((char) buf.get());
}
return sb.toString();
}
}

View File

@ -0,0 +1,8 @@
package org.moparscape.msc.gs.persistence.impl.bun;
import java.nio.ByteBuffer;
public interface Codec<T> {
public ByteBuffer encode(T t);
public T decode(ByteBuffer buf);
}

View File

@ -0,0 +1,26 @@
package org.moparscape.msc.gs.persistence.impl.bun;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import net.jcip.annotations.ThreadSafe;
@ThreadSafe
public class CodecLookupService {
private static final Map<String, Codec<?>> codecs = new ConcurrentHashMap<String, Codec<?>>();
public static Codec<?> lookup(String className) {
return codecs.get(className);
}
public static boolean register(String className, Codec<?> codec) {
synchronized (codecs) {
Codec<?> prev = codecs.put(className, codec);
if (prev == null) {
codecs.put(className, prev);
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,27 @@
package org.moparscape.msc.gs.persistence.impl.bun;
import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import net.jcip.annotations.ThreadSafe;
@ThreadSafe
public class FileLookupService {
private static Map<String, File> files = new ConcurrentHashMap<String, File>();
public static File lookup(String className) {
return files.get(className);
}
public static boolean register(String className, File file) {
synchronized (files) {
File prev = files.put(className, file);
if (prev == null) {
files.put(className, prev);
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,45 @@
package org.moparscape.msc.gs.persistence.impl.bun;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class IO {
public static void write(File file, ByteBuffer buf) throws Exception {
if(!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
FileChannel chan = fos.getChannel();
chan.write(buf);
chan.close();
fos.close();
}
public static ByteBuffer read(File file) throws Exception {
FileInputStream fis = new FileInputStream(file);
FileChannel chan = fis.getChannel();
long size = chan.size();
if(size > Integer.MAX_VALUE) {
throw new IndexOutOfBoundsException("File too large");
}
ByteBuffer buf = ByteBuffer.allocate((int) size);
chan.read(buf);
chan.close();
fis.close();
buf.flip();
return buf;
}
}

View File

@ -0,0 +1,32 @@
package org.moparscape.msc.gs.persistence.impl.bun.codec;
import java.nio.ByteBuffer;
import org.moparscape.msc.gs.external.NPCDef;
import org.moparscape.msc.gs.persistence.impl.bun.ByteBufferUtil;
import org.moparscape.msc.gs.persistence.impl.bun.Codec;
public class NpcDefCodec implements Codec<NPCDef[]> {
@Override
public ByteBuffer encode(NPCDef[] t) {
return null;
}
private ByteBuffer encode(NPCDef d) {
ByteBuffer buf = ByteBuffer.allocate(d.getName().length() + 1 + d.getDescription().length() + 1 + d.getCommand().length() + 2 + 4 * 2 + 2 + 13 + 8 + 8);
ByteBufferUtil.putString(buf, d.getName());
buf.flip();
return buf;
}
@Override
public NPCDef[] decode(ByteBuffer buf) {
// TODO Auto-generated method stub
return null;
}
}

Binary file not shown.

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="XML Using XStream" default="build" basedir="../../../">
<property name="base" location="Modules/DataStore/XMLUsingXStream" />
<property name="src" location="${base}/src" />
<property name="bin" location="${base}/bin" />
<property name="lib" location="${base}/lib" />
<property name="common-lib" location="${base}/../lib" />
<property name="jar" value="${base}/XMLUsingXStreamDataStore.jar" />
<fileset id="mopar" dir="GameServer">
<include name="moparclassic.jar" />
</fileset>
<fileset id="libraries" dir="${lib}">
<include name="*.jar" />
</fileset>
<fileset id="common-libraries" dir="${common-lib}">
<include name="*.jar" />
</fileset>
<fileset id="datastore-core" dir="${base}/../">
<include name="DataStoreCore.jar" />
</fileset>
<fileset id="production-classes" dir="${bin}">
<include name="**/*.class" />
</fileset>
<path id="binary-path">
<pathelement path="${bin}" />
</path>
<path id="library-path">
<fileset refid="common-libraries" />
<fileset refid="libraries" />
<fileset refid="mopar" />
<fileset refid="datastore-core" />
</path>
<path id="master-path">
<path refid="binary-path" />
<path refid="library-path" />
</path>
<target name="init">
<mkdir dir="${bin}" />
<mkdir dir="${lib}" />
</target>
<target name="build" depends="init">
<javac destdir="${bin}" includeantruntime="false">
<src path="${src}" />
<classpath refid="library-path" />
</javac>
<jar destfile="${jar}">
<zipgroupfileset refid="libraries" />
<fileset refid="production-classes" />
</jar>
</target>
<target name="clean">
<delete dir="${bin}" />
<delete file="${jar}" />
</target>
</project>

View File

@ -0,0 +1,527 @@
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 {
protected XMLUsingXStream() {
// To conform to the contract specified by the DataStore interface.
}
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 Map<Integer, ItemDartTipDef> loadDartTips() {
return (HashMap<Integer, ItemDartTipDef>) load("defs/extras/ItemDartTipDef.xml.gz");
}
@Override
public void dispose() {
}
@Override
public void savePacketHandlerDefs(PacketHandlerDef[] defs) throws Exception {
write("PacketHandlers.xml", defs);
}
@Override
public void saveLSPacketHandlerDefs(PacketHandlerDef[] defs)
throws Exception {
write("LSPacketHanlders.xml", defs);
}
@Override
public void saveNpcHandlers(NpcHandlerDef[] defs) throws Exception {
write("NpcHandlers.xml", defs);
}
@Override
public void saveTelePoints(Map<Point, TelePoint> points) throws Exception {
write("locs/extras/ObjectTelePoints.xml.gz", points);
}
@Override
public void saveShops(List<Shop> shops) throws Exception {
write("locs/Shops.xml.gz", shops);
}
@Override
public void saveCerterDefs(Map<Integer, CerterDef> certers)
throws Exception {
write("defs/extras/NpcCerters.xml.gz", certers);
}
@Override
public void saveGameObjectLocs(List<GameObjectLoc> locs) throws Exception {
write("locs/GameObjectLocs.xml.gz", locs);
}
@Override
public void saveItemLocs(List<ItemLoc> locs) throws Exception {
write("locs/ItemLoc.xml.gz", locs);
}
@Override
public void saveNPCLocs(List<NPCLoc> locs) throws Exception {
write("locs/NpcLoc.xml.gz", locs);
}
@Override
public void saveTileDefs(TileDef[] defs) throws Exception {
write("defs/TileDef.xml.gz", defs);
}
@Override
public void saveGameObjectDefs(GameObjectDef[] defs) throws Exception {
write("defs/GameObjectDef.xml.gz", defs);
}
@Override
public void saveDoorDefs(DoorDef[] defs) throws Exception {
write("defs/DoorDef.xml.gz", defs);
}
@Override
public void saveItemDefs(ItemDef[] defs) throws Exception {
write("defs/ItemDef.xml.gz", defs);
}
@Override
public void savePrayerDefs(PrayerDef[] defs) throws Exception {
write("defs/PrayerDef.xml.gz", defs);
}
@Override
public void saveSpellDefs(SpellDef[] defs) throws Exception {
write("defs/SpellDef.xml.gz", defs);
}
@Override
public void saveNPCDefs(NPCDef[] defs) throws Exception {
write("defs/NPCDef.xml.gz", defs);
}
@Override
public void saveItemCraftingDefs(ItemCraftingDef[] defs) throws Exception {
write("defs/extras/ItemCraftingDef.xml.gz", defs);
}
@Override
public void saveItemHerbSeconds(ItemHerbSecond[] seconds) throws Exception {
write("defs/extras/ItemHerbSecond.xml.gz", seconds);
}
@Override
public void saveItemDartTipDefs(Map<Integer, ItemDartTipDef> defs)
throws Exception {
write("defs/extras/ItemDartTipDef.xml.gz", defs);
}
@Override
public void saveGemDefs(Map<Integer, ItemGemDef> defs) throws Exception {
write("def/extras/ItemGemDef.xml.gz", defs);
}
@Override
public void saveItemLogCutDefs(Map<Integer, ItemLogCutDef> defs)
throws Exception {
write("def/extras/ItemLogCutDefs.xml.gz", defs);
}
@Override
public void saveItemBowStringDefs(Map<Integer, ItemBowStringDef> defs)
throws Exception {
write("defs/extras/ItemBowStringDef.xml.gz", defs);
}
@Override
public void saveItemArrowHeadDefs(Map<Integer, ItemArrowHeadDef> defs)
throws Exception {
write("defs/extras/ItemArrowHeadDef.xml.gz", defs);
}
@Override
public void saveFiremakingDefs(Map<Integer, FiremakingDef> defs)
throws Exception {
write("defs/extras/FiremakingDef.xml.gz", defs);
}
@Override
public void saveItemAffectedTypes(Map<Integer, int[]> types)
throws Exception {
write("defs/extras/ItemAffectedTypes.xml.gz", types);
}
@Override
public void saveItemWieldableDefs(Map<Integer, ItemWieldableDef> defs)
throws Exception {
write("defs/extras/ItemWieldableDef.xml.gz", defs);
}
@Override
public void saveItemUnIdentHerbDefs(Map<Integer, ItemUnIdentHerbDef> defs)
throws Exception {
write("defs/extras/Item.UnIdentHerbDef.xml.gz", defs);
}
@Override
public void saveItemHerbDefs(Map<Integer, ItemHerbDef> defs)
throws Exception {
write("defs/extras/ItemHerbDef.xml.gz", defs);
}
@Override
public void saveItemEdibleHeals(Map<Integer, Integer> defs)
throws Exception {
write("defs/extras/ItemEdibleHeals.xml.gz", defs);
}
@Override
public void saveItemCookingDefs(Map<Integer, ItemCookingDef> defs)
throws Exception {
write("defs/extras/ItemCookingDef.xml.gz", defs);
}
@Override
public void saveItemSmeltingDefs(Map<Integer, ItemSmeltingDef> defs)
throws Exception {
write("defs/extras/ItemSmeltingDef.xml.gz", defs);
}
@Override
public void saveItemSmithingDefs(ItemSmithingDef[] defs) throws Exception {
write("defs/extras/ItemSmithingDef.xml.gz", defs);
}
@Override
public void saveObjectMiningDefs(Map<Integer, ObjectMiningDef> defs)
throws Exception {
write("defs/extras/ObjectMiningDef.xml.gz", defs);
}
@Override
public void saveObjectWoodcuttingDefs(
Map<Integer, ObjectWoodcuttingDef> defs) throws Exception {
write("defs/extras/ObjectWoodcuttingDef.xml.gz", defs);
}
@Override
public void saveObjectFishingDefs(Map<Integer, ObjectFishingDef> defs)
throws Exception {
write("defs/extras/ObjectFishingDef.xml.gz", defs);
}
@Override
public void saveSpellAgressiveLevel(Map<Integer, Integer> defs)
throws Exception {
write("defs/extras/SpellAgressiveLvl.xml.gz", defs);
}
@Override
public void saveAgilityDefs(Map<Integer, AgilityDef> defs) throws Exception {
write("defs/extras/AgilityDef.xml.gz", defs);
}
@Override
public void saveAgilityCourseDef(Map<Integer, AgilityCourseDef> defs)
throws Exception {
write("defs/extras/AgilityCourseDef.xml.gz", defs);
}
@Override
public void saveKeyChestLoots(List<InvItem>[] loots) throws Exception {
write("defs/extras/KeyChestLoot.xml.gz", loots);
}
}

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="DataStore Core" default="build" basedir="../../">
<property name="base" location="Modules/DataStore" />
<property name="src" location="${base}/src" />
<property name="bin" location="${base}/bin" />
<property name="lib" location="${base}/lib" />
<property name="jar" value="${base}/DataStoreCore.jar" />
<fileset id="mopar" dir="GameServer">
<include name="moparclassic.jar" />
</fileset>
<fileset id="libraries" dir="${lib}">
<include name="*.jar" />
</fileset>
<fileset id="production-classes" dir="${bin}">
<include name="**/*.class" />
</fileset>
<path id="binary-path">
<pathelement path="${bin}" />
</path>
<path id="library-path">
<fileset refid="libraries" />
<fileset refid="mopar" />
</path>
<path id="master-path">
<path refid="binary-path" />
<path refid="library-path" />
</path>
<target name="init">
<mkdir dir="${bin}" />
<mkdir dir="${lib}" />
</target>
<target name="build" depends="init">
<javac destdir="${bin}" includeantruntime="false">
<src path="${src}" />
<classpath refid="library-path" />
</javac>
<jar destfile="${jar}">
<zipgroupfileset refid="libraries" />
<fileset refid="production-classes" />
</jar>
</target>
<target name="clean">
<delete dir="${bin}" />
<delete file="${jar}" />
</target>
</project>

Binary file not shown.

View File

@ -0,0 +1,202 @@
package org.moparscape.msc.gs.persistence;
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. All
* implementations should be only accessable by the
* org.moparscape.msc.gs.persistence.impl package.<br>
* Implementations should also use JCIP annotations to specify their degree of
* thread saftey.
*
* @author Joe Pritzel
*
*/
public abstract interface DataStore {
public PacketHandlerDef[] loadPacketHandlerDefs() throws Exception;
public void savePacketHandlerDefs(PacketHandlerDef[] defs) throws Exception;
public PacketHandlerDef[] loadLSPacketHandlerDefs() throws Exception;
public void saveLSPacketHandlerDefs(PacketHandlerDef[] defs)
throws Exception;
public NpcHandlerDef[] loadNpcHandlers() throws Exception;
public void saveNpcHandlers(NpcHandlerDef[] defs) throws Exception;
public Map<Point, TelePoint> loadTelePoints() throws Exception;
public void saveTelePoints(Map<Point, TelePoint> points) throws Exception;
public List<Shop> loadShops() throws Exception;
public void saveShops(List<Shop> shops) throws Exception;
public Map<Integer, CerterDef> loadCerterDefs() throws Exception;
public void saveCerterDefs(Map<Integer, CerterDef> certers)
throws Exception;
public List<GameObjectLoc> loadGameObjectLocs() throws Exception;
public void saveGameObjectLocs(List<GameObjectLoc> locs) throws Exception;
public List<ItemLoc> loadItemLocs() throws Exception;
public void saveItemLocs(List<ItemLoc> locs) throws Exception;
public List<NPCLoc> loadNPCLocs() throws Exception;
public void saveNPCLocs(List<NPCLoc> locs) throws Exception;
public TileDef[] loadTileDefs() throws Exception;
public void saveTileDefs(TileDef[] defs) throws Exception;
public GameObjectDef[] loadGameObjectDefs() throws Exception;
public void saveGameObjectDefs(GameObjectDef[] defs) throws Exception;
public DoorDef[] loadDoorDefs() throws Exception;
public void saveDoorDefs(DoorDef[] defs) throws Exception;
public ItemDef[] loadItemDefs() throws Exception;
public void saveItemDefs(ItemDef[] defs) throws Exception;
public PrayerDef[] loadPrayerDefs() throws Exception;
public void savePrayerDefs(PrayerDef[] defs) throws Exception;
public SpellDef[] loadSpellDefs() throws Exception;
public void saveSpellDefs(SpellDef[] defs) throws Exception;
public NPCDef[] loadNPCDefs() throws Exception;
public void saveNPCDefs(NPCDef[] defs) throws Exception;
public ItemCraftingDef[] loadItemCraftingDefs() throws Exception;
public void saveItemCraftingDefs(ItemCraftingDef[] defs) throws Exception;
public ItemHerbSecond[] loadItemHerbSeconds() throws Exception;
public void saveItemHerbSeconds(ItemHerbSecond[] seconds) throws Exception;
public Map<Integer, ItemDartTipDef> loadItemDartTipDefs() throws Exception;
public void saveItemDartTipDefs(Map<Integer, ItemDartTipDef> defs)
throws Exception;
public Map<Integer, ItemGemDef> loadGemDefs() throws Exception;
public void saveGemDefs(Map<Integer, ItemGemDef> defs) throws Exception;
public Map<Integer, ItemLogCutDef> loadItemLogCutDefs() throws Exception;
public void saveItemLogCutDefs(Map<Integer, ItemLogCutDef> defs)
throws Exception;
public Map<Integer, ItemBowStringDef> loadItemBowStringDefs()
throws Exception;
public void saveItemBowStringDefs(Map<Integer, ItemBowStringDef> defs)
throws Exception;
public Map<Integer, ItemArrowHeadDef> loadItemArrowHeadDefs()
throws Exception;
public void saveItemArrowHeadDefs(Map<Integer, ItemArrowHeadDef> defs)
throws Exception;
public Map<Integer, FiremakingDef> loadFiremakingDefs() throws Exception;
public void saveFiremakingDefs(Map<Integer, FiremakingDef> defs)
throws Exception;
public Map<Integer, int[]> loadItemAffectedTypes() throws Exception;
public void saveItemAffectedTypes(Map<Integer, int[]> types) throws Exception;
public Map<Integer, ItemWieldableDef> loadItemWieldableDefs()
throws Exception;
public void saveItemWieldableDefs(Map<Integer, ItemWieldableDef> defs) throws Exception;
public Map<Integer, ItemUnIdentHerbDef> loadItemUnIdentHerbDefs()
throws Exception;
public void saveItemUnIdentHerbDefs(Map<Integer, ItemUnIdentHerbDef> defs) throws Exception;
public Map<Integer, ItemHerbDef> loadItemHerbDefs() throws Exception;
public void saveItemHerbDefs(Map<Integer, ItemHerbDef> defs) throws Exception;
public Map<Integer, Integer> loadItemEdibleHeals() throws Exception;
public void saveItemEdibleHeals(Map<Integer, Integer> defs) throws Exception;
public Map<Integer, ItemCookingDef> loadItemCookingDefs() throws Exception;
public void saveItemCookingDefs(Map<Integer, ItemCookingDef> defs) throws Exception;
public Map<Integer, ItemSmeltingDef> loadItemSmeltingDefs()
throws Exception;
public void saveItemSmeltingDefs(Map<Integer, ItemSmeltingDef> defs) throws Exception;
public ItemSmithingDef[] loadItemSmithingDefs() throws Exception;
public void saveItemSmithingDefs(ItemSmithingDef[] defs) throws Exception;
public Map<Integer, ObjectMiningDef> loadObjectMiningDefs()
throws Exception;
public void saveObjectMiningDefs(Map<Integer, ObjectMiningDef> defs) throws Exception;
public Map<Integer, ObjectWoodcuttingDef> loadObjectWoodcuttingDefs()
throws Exception;
public void saveObjectWoodcuttingDefs(Map<Integer, ObjectWoodcuttingDef> defs) throws Exception;
public Map<Integer, ObjectFishingDef[]> loadObjectFishDefs()
throws Exception;
public void saveObjectFishingDefs(Map<Integer, ObjectFishingDef> defs) throws Exception;
public Map<Integer, Integer> loadSpellAgressiveLevel() throws Exception;
public void saveSpellAgressiveLevel(Map<Integer, Integer> defs) throws Exception;
public Map<Integer, AgilityDef> loadAgilityDefs() throws Exception;
public void saveAgilityDefs(Map<Integer, AgilityDef> defs) throws Exception;
public Map<Integer, AgilityCourseDef> loadAgilityCourseDefs()
throws Exception;
public void saveAgilityCourseDef(Map<Integer, AgilityCourseDef> defs) throws Exception;
public List<InvItem>[] loadKeyChestLoots() throws Exception;
public void saveKeyChestLoots(List<InvItem>[] loots) throws Exception;
public Map<Integer, ItemDartTipDef> loadDartTips() throws Exception;
public void dispose();
}

16
README
View File

@ -1,4 +1,4 @@
An emulator for an old java MMORPG. An emulator for an old Java MMORPG.
Setup Setup
====== ======
@ -6,6 +6,7 @@ Install the JRE and JDK
Install Ant Install Ant
Install Ivy Install Ivy
Install MySQL Install MySQL
Install a Web-Server
Ensure all the paths are set correctly. Ensure all the paths are set correctly.
@ -13,10 +14,21 @@ Import Database.sql
If you have any questions regarding that use Google. If you have any questions regarding that use Google.
For account authentication (using the default config) you need to copy the auth.php in the LoginServer folder, and ensure that localhost/auth.php is pointed to it.
It is highly recommended that you modify it so that it checks the credentials provided against the database.
Go to LoginServer in the terminal/command prompt and type-- Go to LoginServer in the terminal/command prompt and type--
ant runls ant run
Go to GameServer in the terminal/command prompy and type-- Go to GameServer in the terminal/command prompy and type--
ant run ant run
You're now ready to start accept connections. You're now ready to start accept connections.
Modules
========
To compile modules go in the module's directory and run the following command--
ant build
To use the module copy the newly created JAR into the modules folder in the respective server. You may need to change some configuration files for the module to be used.