mirror of
https://github.com/moparisthebest/MoparClassic
synced 2024-12-21 23:18:52 -05:00
Merge pull request #22 from Joe0/master
Persistence, README, and Poison
This commit is contained in:
commit
cbe085c05c
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,3 +13,6 @@ build
|
||||
!.gitmodules
|
||||
!.gitkeep
|
||||
!.gitattributes
|
||||
lib_managed
|
||||
doc
|
||||
|
||||
|
@ -1,84 +1,91 @@
|
||||
<project name="GameServer" default="build" basedir=".">
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="MoparClassic" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
|
||||
<property name="src" location="src" />
|
||||
<property name="build" location="build" />
|
||||
<property name="doc" location="../doc" />
|
||||
<property name="bin" location="bin" />
|
||||
<property name="lib_managed" location="lib_managed" />
|
||||
<property name="lib" location="lib" />
|
||||
<property name="jar" location="rscd.jar" />
|
||||
<property name="settings" location="settings.ini" />
|
||||
<property name="quests" location="conf/server/quests" />
|
||||
<property name="scala-library.jar" value="lib/scala-library.jar" />
|
||||
<property name="doc" location="doc" />
|
||||
<property name="jar" value="moparclassic.jar" />
|
||||
<property name="main-class" value="org.moparscape.msc.gs.Server" />
|
||||
<property name="scala-version" value="2.9.1" />
|
||||
<property name="ivy.lib.dir" value="lib_managed"/>
|
||||
|
||||
<target name="build">
|
||||
<delete file="${jar}" />
|
||||
<delete dir="${build}" />
|
||||
<mkdir dir="${build}" />
|
||||
<taskdef resource="scala/tools/ant/antlib.xml">
|
||||
<fileset id="libraries" dir="${lib}">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
|
||||
<fileset id="libraries_managed" dir="${lib_managed}">
|
||||
<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="libraries_managed" />
|
||||
</path>
|
||||
|
||||
<path id="master-path">
|
||||
<path refid="binary-path" />
|
||||
<path refid="library-path" />
|
||||
</path>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${bin}" />
|
||||
<mkdir dir="${doc}" />
|
||||
<mkdir dir="${lib}" />
|
||||
<mkdir dir="${lib_managed}" />
|
||||
</target>
|
||||
|
||||
<target name="resolve" depends="init">
|
||||
<ivy:retrieve sync="true" />
|
||||
</target>
|
||||
|
||||
<target name="build" depends="resolve">
|
||||
<taskdef resource="scala/tools/ant/antlib.xml" classpathref="library-path">
|
||||
<classpath>
|
||||
<pathelement location="lib/scala-compiler.jar" />
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="${lib}/scala-compiler-${scala-version}.jar" />
|
||||
<pathelement location="${lib}/scala-library-${scala-version}.jar" />
|
||||
</classpath>
|
||||
</taskdef>
|
||||
<scalac srcdir="${src}" destdir="${build}">
|
||||
<classpath>
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="${lib}/mina.jar" />
|
||||
<pathelement location="${lib}/xpp3.jar" />
|
||||
<pathelement location="${lib}/slf4j.jar" />
|
||||
<pathelement location="${lib}/bsh.jar" />
|
||||
<pathelement location="${lib}/commons-collections-3.2.1.jar" />
|
||||
<pathelement location="${lib}/xstream.jar" />
|
||||
<pathelement location="${lib}/mysql-connector.jar" />
|
||||
<pathelement location="${lib}/hex-string.jar" />
|
||||
<pathelement location="${lib}/mail.jar" />
|
||||
<pathelement path="${java.class.path}/" />
|
||||
</classpath>
|
||||
<include name="**/*.scala" />
|
||||
<scalac destdir="${bin}" classpathref="library-path">
|
||||
<src path="${src}" />
|
||||
</scalac>
|
||||
<javac srcdir="${src}" destdir="${build}" debug="on" target="1.6">
|
||||
<classpath>
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="${lib}/mina.jar" />
|
||||
<pathelement location="${lib}/xpp3.jar" />
|
||||
<pathelement location="${lib}/slf4j.jar" />
|
||||
<pathelement location="${lib}/bsh.jar" />
|
||||
<pathelement location="${lib}/commons-collections-3.2.1.jar" />
|
||||
<pathelement location="${lib}/xstream.jar" />
|
||||
<pathelement location="${lib}/mysql-connector.jar" />
|
||||
<pathelement location="${lib}/hex-string.jar" />
|
||||
<pathelement location="${lib}/mail.jar" />
|
||||
<pathelement path="${java.class.path}/" />
|
||||
</classpath>
|
||||
<javac destdir="${bin}" includeantruntime="false">
|
||||
<src path="${src}" />
|
||||
<classpath refid="library-path" />
|
||||
</javac>
|
||||
<jar basedir="${build}" destfile="${jar}" />
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${bin}" />
|
||||
<delete dir="${doc}" />
|
||||
<delete file="${jar}" />
|
||||
</target>
|
||||
|
||||
<target name="run" depends="build">
|
||||
<java classpathref="master-path" fork="true" classname="${main-class}" />
|
||||
</target>
|
||||
|
||||
<target name="doc" depends="build">
|
||||
<javadoc sourcepath="${src}" destdir="${doc}" verbose="on" />
|
||||
<scaladoc srcdir="${src}" destdir="${doc}" deprecation="yes" unchecked="yes" doctitle="MoparClassic Documentation" classpathref="master-path">
|
||||
<include name="**/*.scala" />
|
||||
</scaladoc>
|
||||
</target>
|
||||
|
||||
<target name="runf2p" depends="build">
|
||||
<java classname="org.moparscape.msc.gs.Server" fork="true">
|
||||
<jvmarg value="-Xms128m" />
|
||||
<jvmarg value="-Xmx512m" />
|
||||
<arg value="world.xml" />
|
||||
<arg value="f2p" />
|
||||
<arg value="no" />
|
||||
<classpath>
|
||||
<pathelement location="${lib}/mysql-connector.jar" />
|
||||
<pathelement location="${lib}/mina.jar" />
|
||||
<pathelement location="${lib}/xpp3.jar" />
|
||||
<pathelement location="${lib}/bsh.jar" />
|
||||
<pathelement location="${lib}/commons-collections-3.2.1.jar" />
|
||||
<pathelement location="${lib}/slf4j.jar" />
|
||||
<pathelement location="${lib}/xstream.jar" />
|
||||
<pathelement location="${lib}/hex-string.jar" />
|
||||
<pathelement location="${lib}/mail.jar" />
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="quests/" />
|
||||
<pathelement path="${jar}/" />
|
||||
</classpath>
|
||||
</java>
|
||||
<target name="jar" depends="build">
|
||||
<jar destfile="${jar}">
|
||||
<zipgroupfileset refid="libraries" />
|
||||
<fileset refid="production-classes" />
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}" />
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
|
@ -62,8 +62,8 @@
|
||||
This uses a LRUMap, and only has a limited number of entries, so only the
|
||||
most active IPs will be stored at a time. -->
|
||||
<entry key="connection-throttle">5</entry>
|
||||
<!-- The amount of time (in ms) after a connection is closed that the count is kept.
|
||||
This is used to throttle spam logging. -->
|
||||
<!-- The amount of time (in ms) after a connection is closed that the count
|
||||
is kept. This is used to throttle spam logging. -->
|
||||
<entry key="connection-throttle-remove-delay">180000</entry>
|
||||
|
||||
<!-- Every 100 minutes -->
|
||||
|
19
GameServer/ivy.xml
Normal file
19
GameServer/ivy.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ivy-module version="2.0">
|
||||
<info organisation="org.moparscape" module="MoparClassic" />
|
||||
<dependencies>
|
||||
<dependency org="org.scala-lang" name="scala-library" rev="2.9.1" />
|
||||
|
||||
<dependency org="org.scala-lang" name="scala-compiler" rev="2.9.1" />
|
||||
|
||||
<dependency org="javax.mail" name="mail" rev="1.4.4" />
|
||||
|
||||
<dependency org="mysql" name="mysql-connector-java" rev="5.1.18" />
|
||||
|
||||
<dependency org="org.beanshell" name="bsh" rev="2.0b4"/>
|
||||
|
||||
<dependency org="commons-collections" name="commons-collections" rev="3.2.1"/>
|
||||
|
||||
<dependency org="org.slf4j" name="slf4j-simple" rev="1.6.3"/>
|
||||
</dependencies>
|
||||
</ivy-module>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -37,9 +37,16 @@ public class Server {
|
||||
File f = new File(args[0]);
|
||||
if (f.exists()) {
|
||||
configFile = f.getName();
|
||||
} else {
|
||||
System.out.println("Config not found: " + f.getCanonicalPath());
|
||||
displayConfigDefaulting(configFile);
|
||||
}
|
||||
} else {
|
||||
System.out.println("No config file specified.");
|
||||
displayConfigDefaulting(configFile);
|
||||
}
|
||||
|
||||
|
||||
Config.initConfig(configFile);
|
||||
world = Instance.getWorld();
|
||||
world.wl.loadObjects();
|
||||
@ -157,7 +164,12 @@ public class Server {
|
||||
acceptor.bind(new InetSocketAddress(Config.SERVER_IP,
|
||||
Config.SERVER_PORT), new RSCConnectionHandler(engine),
|
||||
config);
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
acceptor.unbindAll();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
@ -235,4 +247,8 @@ public class Server {
|
||||
public static Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
private static void displayConfigDefaulting(String file) {
|
||||
System.out.println("Defaulting to use " + file);
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,8 @@ import org.moparscape.msc.gs.model.snapshot.Chatlog;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
import org.moparscape.msc.gs.util.EntityList;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.gs.util.Processor;
|
||||
import org.moparscape.msc.gs.util.WorkGroup;
|
||||
|
||||
public final class ClientUpdater implements Processor {
|
||||
public final class ClientUpdater {
|
||||
|
||||
public static int pktcount = 0;
|
||||
private static World world = Instance.getWorld();
|
||||
@ -37,11 +35,9 @@ public final class ClientUpdater implements Processor {
|
||||
private WallObjectPositionPacketBuilder wallObjectPositionPacketBuilder = new WallObjectPositionPacketBuilder();
|
||||
|
||||
private EntityList<Player> players = world.getPlayers();
|
||||
private WorkGroup<Player> clientInformerGroup = null;
|
||||
|
||||
public ClientUpdater() {
|
||||
world.setClientUpdater(this);
|
||||
this.clientInformerGroup = new WorkGroup<Player>(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,13 +130,6 @@ public final class ClientUpdater implements Processor {
|
||||
|
||||
updateOffers();
|
||||
|
||||
if (threaded) {
|
||||
try {
|
||||
clientInformerGroup.processWorkload(players);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
for (Player p : players) {
|
||||
// Logging.debug("Process for player " + p.getUsername() +
|
||||
// " | threaded: " + threaded);
|
||||
@ -158,7 +147,6 @@ public final class ClientUpdater implements Processor {
|
||||
}
|
||||
updateCollections();
|
||||
}
|
||||
}
|
||||
|
||||
public void process(Player p) {
|
||||
|
||||
|
@ -328,40 +328,39 @@ public final class GameEngine extends Thread {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
time = System.currentTimeMillis();
|
||||
long Delay;
|
||||
long deltaTime = updateTime();
|
||||
processLoginServer();
|
||||
Delay = System.currentTimeMillis() - time;
|
||||
if (Delay >= 1000)
|
||||
if ((deltaTime = getDeltaTime()) >= 1000)
|
||||
Logger.println("processLoginServer is taking longer than it should, exactly "
|
||||
+ Delay + "ms");
|
||||
time = System.currentTimeMillis();
|
||||
+ deltaTime + "ms");
|
||||
processIncomingPackets();
|
||||
Delay = System.currentTimeMillis() - time;
|
||||
if (Delay >= 1000)
|
||||
if ((deltaTime = getDeltaTime()) >= 1000)
|
||||
Logger.println("processIncomingPackets is taking longer than it should, exactly "
|
||||
+ Delay + "ms");
|
||||
time = System.currentTimeMillis();
|
||||
+ deltaTime + "ms");
|
||||
processEvents();
|
||||
Delay = System.currentTimeMillis() - time;
|
||||
if (Delay >= 1000)
|
||||
if ((deltaTime = getDeltaTime()) >= 1000)
|
||||
Logger.println("processEvents is taking longer than it should, exactly "
|
||||
+ Delay + "ms");
|
||||
time = System.currentTimeMillis();
|
||||
+ deltaTime + "ms");
|
||||
processClients();
|
||||
Delay = System.currentTimeMillis() - time;
|
||||
if (Delay >= 1000)
|
||||
if ((deltaTime = getDeltaTime()) >= 1000)
|
||||
Logger.println("processClients is taking longer than it should, exactly "
|
||||
+ Delay + "ms");
|
||||
time = System.currentTimeMillis();
|
||||
+ deltaTime + "ms");
|
||||
cleanSnapshotDeque();
|
||||
Delay = System.currentTimeMillis() - time;
|
||||
if (Delay >= 1000)
|
||||
if ((deltaTime = getDeltaTime()) >= 1000)
|
||||
Logger.println("processSnapshotDeque is taking longer than it should, exactly "
|
||||
+ Delay + "ms");
|
||||
+ deltaTime + "ms");
|
||||
}
|
||||
}
|
||||
|
||||
public long getDeltaTime() {
|
||||
long t1 = time;
|
||||
return updateTime() - t1;
|
||||
}
|
||||
|
||||
public long updateTime() {
|
||||
return time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans snapshots of entries over 60 seconds old (executed every second)
|
||||
*/
|
||||
|
@ -200,6 +200,9 @@ public class LoginConnector {
|
||||
+ connectionAttempts + " tries");
|
||||
System.exit(1);
|
||||
return false;
|
||||
} else {
|
||||
// Add a delay so it doesn't instantly get to 100
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
return reconnect();
|
||||
|
||||
|
@ -532,6 +532,65 @@ public final class Player extends Mob {
|
||||
private int[] wornItems = new int[12];
|
||||
private int wrongwords = 0;
|
||||
|
||||
private int poisonPower = 0;
|
||||
private DelayedEvent poisonEvent;
|
||||
|
||||
public boolean isPoisoned() {
|
||||
return poisonPower > 0;
|
||||
}
|
||||
|
||||
public void poison(int power) {
|
||||
if (!isPoisoned()) {
|
||||
this.poisonPower = power;
|
||||
poisonEvent = new DelayedEvent(this, 19500) {
|
||||
public void run() {
|
||||
damagePoison(true);
|
||||
}
|
||||
};
|
||||
World.getWorld().getDelayedEventHandler().add(poisonEvent);
|
||||
} else
|
||||
this.poisonPower = power;
|
||||
}
|
||||
|
||||
public void curePoison() {
|
||||
this.poisonPower = 0;
|
||||
if (poisonEvent != null)
|
||||
poisonEvent.stop();
|
||||
}
|
||||
|
||||
public void startPoison(int power) {
|
||||
this.poison(power);
|
||||
this.poisonPower = power;
|
||||
|
||||
damagePoison(false);
|
||||
}
|
||||
|
||||
public void damagePoison(boolean decrease) {
|
||||
if (this.poisonPower > 0) {
|
||||
double calcDamage = Math.ceil(poisonPower / 5);
|
||||
int damage = (int) calcDamage + 1;
|
||||
|
||||
if (decrease)
|
||||
poisonPower--;
|
||||
|
||||
setLastDamage(damage);
|
||||
setCurStat(3, getCurStat(3) - damage);
|
||||
getActionSender().sendStat(3);
|
||||
getActionSender().sendMessage(
|
||||
"@gr3@You @gr2@are @gr1@Poisoned! @gr2@You @gr3@lose "
|
||||
+ damage + " @gr1@health.");
|
||||
|
||||
for (Player p : getViewArea().getPlayersInView())
|
||||
p.informOfModifiedHits(this);
|
||||
if (getCurStat(3) <= 0)
|
||||
killedBy(null, false);
|
||||
} else {
|
||||
if (poisonEvent != null)
|
||||
poisonEvent.stop();
|
||||
this.poisonPower = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Player(IoSession ios) {
|
||||
|
||||
ioSession = ios;
|
||||
@ -586,9 +645,11 @@ public final class Player extends Mob {
|
||||
|
||||
/**
|
||||
* This method acts as a throttle for packets, and adds them to a list.<br>
|
||||
* If the player sends more than 20 packets per second they're disconnected (60 packets per 3000ms)
|
||||
* If the player sends more than 20 packets per second they're disconnected
|
||||
* (60 packets per 3000ms)
|
||||
*
|
||||
* @param p - the packet to add...
|
||||
* @param p
|
||||
* - the packet to add...
|
||||
*/
|
||||
public void addPacket(RSCPacket p) {
|
||||
long now = GameEngine.getTime();
|
||||
@ -660,13 +721,14 @@ public final class Player extends Mob {
|
||||
if (this != null && this.location != null
|
||||
&& this.location.inWilderness()) {
|
||||
if (GameEngine.getTime() - this.getLastMoved() < Config.WILD_STAND_STILL_TIME) {
|
||||
getActionSender()
|
||||
.sendMessage(
|
||||
"You must stand peacefully in one place for " + Config.WILD_STAND_STILL_TIME + " seconds!");
|
||||
getActionSender().sendMessage(
|
||||
"You must stand peacefully in one place for "
|
||||
+ Config.WILD_STAND_STILL_TIME + " seconds!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !isBusy() && GameEngine.getTime() - getCombatTimer() > Config.WILD_STAND_STILL_TIME;
|
||||
return !isBusy()
|
||||
&& GameEngine.getTime() - getCombatTimer() > Config.WILD_STAND_STILL_TIME;
|
||||
}
|
||||
|
||||
public boolean canReport() {
|
||||
@ -1618,7 +1680,8 @@ public final class Player extends Mob {
|
||||
if (getLocation().wildernessLevel() > 1) {
|
||||
if (combat)
|
||||
exprate += Config.WILD_COMBAT_BONUS;
|
||||
if (getLocation().wildernessLevel() > Config.WILD_LEVEL_FOR_NON_COMBAT_BONUS && !combat)
|
||||
if (getLocation().wildernessLevel() > Config.WILD_LEVEL_FOR_NON_COMBAT_BONUS
|
||||
&& !combat)
|
||||
exprate += Config.WILD_NON_COMBAT_BONUS;
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,9 @@ import java.util.Random;
|
||||
import org.moparscape.msc.gs.connection.RSCPacket;
|
||||
import org.moparscape.msc.gs.core.GameEngine;
|
||||
import org.moparscape.msc.gs.model.Point;
|
||||
import org.moparscape.msc.gs.util.HexString;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
import com.bombaydigital.vault.HexString;
|
||||
|
||||
public final class DataConversions {
|
||||
private static char characters[] = { ' ', 'e', 't', 'a', 'o', 'i', 'h',
|
||||
'n', 's', 'r', 'd', 'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p',
|
||||
@ -261,7 +260,7 @@ public final class DataConversions {
|
||||
public static String md5(String s) {
|
||||
md.reset();
|
||||
md.update(s.getBytes());
|
||||
return HexString.bufferToHex(md.digest());
|
||||
return new HexString(md.digest()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,49 +0,0 @@
|
||||
package org.moparscape.msc.gs.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class DelayMonitor {
|
||||
private static final DecimalFormat formatter = new DecimalFormat(
|
||||
"###,###.###");
|
||||
private long t, t1, t2;
|
||||
private int totalItemsUpdated;
|
||||
private int numRepeats;
|
||||
|
||||
public void startMeasuring() {
|
||||
t1 = System.nanoTime();
|
||||
}
|
||||
|
||||
public void setItemsUpdated(int i) {
|
||||
totalItemsUpdated += i;
|
||||
}
|
||||
|
||||
public void endMeasuring() {
|
||||
t2 = System.nanoTime();
|
||||
processMeasurements();
|
||||
}
|
||||
|
||||
public double getAvgDelay() {
|
||||
return (t / numRepeats) / 1e6;
|
||||
}
|
||||
|
||||
public double getAvgItemsPerRepeat() {
|
||||
return (totalItemsUpdated / numRepeats);
|
||||
}
|
||||
|
||||
public int getRepeatCount() {
|
||||
return numRepeats;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
t = t1 = t2 = numRepeats = totalItemsUpdated = 0;
|
||||
}
|
||||
|
||||
private void processMeasurements() {
|
||||
t += (t2 - t1);
|
||||
numRepeats++;
|
||||
}
|
||||
|
||||
public static String toString(double d) {
|
||||
return formatter.format(d);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.moparscape.msc.gs.util
|
||||
|
||||
class HexString(bytes: Array[Byte]) {
|
||||
lazy val string = bytes.map(0xFF & _).map { "%02x".format(_) }.foldLeft("") { _ + _ }
|
||||
|
||||
override def toString = string
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package org.moparscape.msc.gs.util;
|
||||
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
|
||||
public interface Processor {
|
||||
public void process(Player p);
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package org.moparscape.msc.gs.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
import org.moparscape.msc.gs.core.ClientUpdater;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
|
||||
/**
|
||||
* This class manages a set of Workers.
|
||||
*/
|
||||
public class WorkGroup<E> {
|
||||
private List<Throwable> uncaughtExceptions;
|
||||
private Worker<?>[] workers;
|
||||
private Thread[] workerThreads;
|
||||
private BlockingQueue<Player> workload = null;
|
||||
private Processor processor;
|
||||
|
||||
public WorkGroup(Processor p) {
|
||||
this(p, Runtime.getRuntime().availableProcessors() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the workgroup. All threads are initiated into a sleeping state.
|
||||
*/
|
||||
public WorkGroup(Processor p, int numWorkers) {
|
||||
this.workload = new ArrayBlockingQueue<Player>(1000);
|
||||
this.processor = p;
|
||||
this.workers = new Worker[numWorkers];
|
||||
this.uncaughtExceptions = new ArrayList<Throwable>();
|
||||
workerThreads = new Thread[workers.length];
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i] = new Worker<E>(this, workload, processor);
|
||||
workerThreads[i] = new Thread(workers[i], "-" + i);
|
||||
workerThreads[i].start();
|
||||
}
|
||||
}
|
||||
|
||||
public void processWorkload(Collection<Player> players)
|
||||
throws InterruptedException {
|
||||
uncaughtExceptions.clear();
|
||||
setWorkload(players);
|
||||
waitFor();
|
||||
}
|
||||
|
||||
public boolean shouldProcess() {
|
||||
return !((ClientUpdater) processor).updatingCollections;
|
||||
}
|
||||
|
||||
private void waitFor() throws InterruptedException {
|
||||
while (!workload.isEmpty())
|
||||
Thread.sleep(10);
|
||||
|
||||
((ClientUpdater) processor).updateCollections();
|
||||
}
|
||||
|
||||
public int remainingJobs() {
|
||||
return workload.size();
|
||||
}
|
||||
|
||||
public int getNumWorkers() {
|
||||
return workers.length;
|
||||
}
|
||||
|
||||
public void addUncaughtException(Throwable t) {
|
||||
t.printStackTrace();
|
||||
uncaughtExceptions.add(t);
|
||||
}
|
||||
|
||||
public void setWorkload(Collection<Player> c) {
|
||||
workload.clear();
|
||||
workload.addAll(c);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package org.moparscape.msc.gs.util;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
|
||||
/**
|
||||
* The Worker class is a runnable class that can be used for splitting up a
|
||||
* workload into multiple Workers. This class should only ever be used through a
|
||||
* WorkGroup.
|
||||
*/
|
||||
public class Worker<E> implements Runnable {
|
||||
private WorkGroup<?> parent;
|
||||
private BlockingQueue<Player> workload;
|
||||
private Processor processor;
|
||||
private boolean running = true;
|
||||
|
||||
public Worker(WorkGroup<?> wg, BlockingQueue<Player> workload, Processor p) {
|
||||
this.parent = wg;
|
||||
this.workload = workload;
|
||||
this.processor = p;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (running) {
|
||||
try {
|
||||
if (parent.shouldProcess()) {
|
||||
Player element = workload.take();
|
||||
processor.process(element);
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
// thread has been asked to stop
|
||||
running = false;
|
||||
} catch (Exception e) {
|
||||
parent.addUncaughtException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
<property name="build" location="build" />
|
||||
<property name="lib" location="lib" />
|
||||
<property name="jar" location="ls.jar" />
|
||||
<property name="settings" location="settings.ini" />
|
||||
|
||||
<target name="build">
|
||||
<delete file="${jar}" />
|
||||
@ -29,18 +28,15 @@
|
||||
|
||||
<target name="runls" depends="build">
|
||||
<java classname="org.moparscape.msc.ls.Server" fork="true">
|
||||
<jvmarg value="-Xms128m" />
|
||||
<jvmarg value="-Xmx512m" />
|
||||
<arg value="ls.conf" />
|
||||
<classpath>
|
||||
<pathelement location="${lib}/mina.jar" />
|
||||
<pathelement location="${lib}/xpp3.jar" />
|
||||
<pathelement location="${lib}/pircbot.jar" />
|
||||
<pathelement location="${lib}/slf4j.jar" />
|
||||
<pathelement location="${lib}/xstream.jar" />
|
||||
<pathelement location="${lib}/mysql-connector.jar" />
|
||||
<pathelement location="${lib}/hex-string.jar" />
|
||||
<pathelement path="${jar}/" />
|
||||
<pathelement location="${jar}" />
|
||||
<pathelement path="${java.class.path}/" />
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
@ -11,4 +11,5 @@
|
||||
<entry key="queryip">localhost</entry>
|
||||
<entry key="queryport">8186</entry>
|
||||
<entry key="authURL">http://localhost/auth.php</entry>
|
||||
<entry key="storage-medium">org.moparscape.msc.ls.persistence.impl.MySQL</entry>
|
||||
</properties>
|
@ -106,7 +106,7 @@ public class LoginEngine extends Thread {
|
||||
handler.handlePacket(p, p.getSession());
|
||||
uniqueHandlers.remove(p.getUID());
|
||||
} catch (Exception e) {
|
||||
Server.error("Exception with p[" + p.getID() + "]: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Server.error("Unhandled packet from server: " + p.getID());
|
||||
@ -118,7 +118,7 @@ public class LoginEngine extends Thread {
|
||||
try {
|
||||
handler.handlePacket(p, p.getSession());
|
||||
} catch (Exception e) {
|
||||
Server.error("Exception with p[" + p.getID() + "]: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Server.error("Unhandled packet from frontend: " + p.getID());
|
||||
|
@ -14,17 +14,14 @@ import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
|
||||
import org.apache.mina.transport.socket.nio.SocketSessionConfig;
|
||||
import org.moparscape.msc.ls.model.PlayerSave;
|
||||
import org.moparscape.msc.ls.model.World;
|
||||
import org.moparscape.msc.ls.net.DatabaseConnection;
|
||||
import org.moparscape.msc.ls.net.FConnectionHandler;
|
||||
import org.moparscape.msc.ls.net.LSConnectionHandler;
|
||||
import org.moparscape.msc.ls.persistence.StorageMedium;
|
||||
import org.moparscape.msc.ls.persistence.StorageMediumFactory;
|
||||
import org.moparscape.msc.ls.util.Config;
|
||||
|
||||
|
||||
public class Server {
|
||||
/**
|
||||
* Connection to the MySQL database
|
||||
*/
|
||||
public static DatabaseConnection db;
|
||||
public static StorageMedium storage;
|
||||
private static Server server;
|
||||
|
||||
public static void error(Object o) {
|
||||
@ -45,17 +42,29 @@ public class Server {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String configFile = "conf/ls/Conf.xml";
|
||||
String configFile = "conf" + File.separator + "Config.xml";
|
||||
if (args.length > 0) {
|
||||
File f = new File(args[0]);
|
||||
if (f.exists()) {
|
||||
configFile = f.getName();
|
||||
} else {
|
||||
System.out.println("Config not found: " + f.getCanonicalPath());
|
||||
displayConfigDefaulting(configFile);
|
||||
}
|
||||
} else {
|
||||
System.out.println("No config file specified.");
|
||||
displayConfigDefaulting(configFile);
|
||||
}
|
||||
System.out.println("Login Server starting up...");
|
||||
Config.initConfig(configFile);
|
||||
db = new DatabaseConnection();
|
||||
System.out.println("Connected to MySQL");
|
||||
try {
|
||||
storage = StorageMediumFactory.createMedium(Config.STORAGE_MEDIUM);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
System.out.println("Storage Medium: "
|
||||
+ storage.getClass().getSimpleName());
|
||||
Server.getServer();
|
||||
}
|
||||
|
||||
@ -81,19 +90,28 @@ public class Server {
|
||||
try {
|
||||
engine = new LoginEngine(this);
|
||||
engine.start();
|
||||
serverAcceptor = createListener(Config.LS_IP, Config.LS_PORT, new LSConnectionHandler(engine));
|
||||
frontendAcceptor = createListener(Config.QUERY_IP, Config.QUERY_PORT, new FConnectionHandler(engine));
|
||||
serverAcceptor = createListener(Config.LS_IP, Config.LS_PORT,
|
||||
new LSConnectionHandler(engine));
|
||||
frontendAcceptor = createListener(Config.QUERY_IP,
|
||||
Config.QUERY_PORT, new FConnectionHandler(engine));
|
||||
} catch (IOException e) {
|
||||
Server.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private IoAcceptor createListener(String ip, int port, IoHandler handler) throws IOException {
|
||||
IoAcceptor acceptor = new SocketAcceptor();
|
||||
private IoAcceptor createListener(String ip, int port, IoHandler handler)
|
||||
throws IOException {
|
||||
final IoAcceptor acceptor = new SocketAcceptor();
|
||||
IoAcceptorConfig config = new SocketAcceptorConfig();
|
||||
config.setDisconnectOnUnbind(true);
|
||||
((SocketSessionConfig) config.getSessionConfig()).setReuseAddress(true);
|
||||
acceptor.bind(new InetSocketAddress(ip, port), handler, config);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
acceptor.unbindAll();
|
||||
}
|
||||
});
|
||||
return acceptor;
|
||||
}
|
||||
|
||||
@ -154,7 +172,7 @@ public class Server {
|
||||
try {
|
||||
serverAcceptor.unbindAll();
|
||||
frontendAcceptor.unbindAll();
|
||||
db.close();
|
||||
storage.shutdown();
|
||||
} catch (Exception e) {
|
||||
Server.error(e);
|
||||
}
|
||||
@ -194,4 +212,8 @@ public class Server {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void displayConfigDefaulting(String file) {
|
||||
System.out.println("Defaulting to use " + file);
|
||||
}
|
||||
}
|
@ -1,136 +1,16 @@
|
||||
package org.moparscape.msc.ls.model;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.util.DataConversions;
|
||||
|
||||
public class PlayerSave {
|
||||
public static final String[] statArray = { "attack", "defense", "strength",
|
||||
"hits", "ranged", "prayer", "magic", "cooking", "woodcut",
|
||||
"fletching", "fishing", "firemaking", "crafting", "smithing",
|
||||
"mining", "herblaw", "agility", "thieving" };
|
||||
|
||||
public static PlayerSave loadPlayer(long user) {
|
||||
PlayerSave save = new PlayerSave(user);
|
||||
ResultSet result;
|
||||
|
||||
try {
|
||||
result = Server.db
|
||||
.getQuery("SELECT * FROM `pk_players` WHERE `user`='"
|
||||
+ save.getUser() + "'");
|
||||
if (!result.next()) {
|
||||
return save;
|
||||
}
|
||||
|
||||
long eventcd = result.getLong("eventcd");
|
||||
long subexp = result.getLong("sub_expires");
|
||||
@SuppressWarnings("unused")
|
||||
long now = System.currentTimeMillis() / 1000;
|
||||
int sowner = result.getInt("owner");
|
||||
save.setOwner(sowner, result.getInt("group_id"), subexp);
|
||||
save.setMuted(result.getLong("muted"));
|
||||
/*
|
||||
* if(subexp - now < 1) {
|
||||
* Server.db.updateQuery("UPDATE users SET group_id='4' WHERE `id`='"
|
||||
* + sowner + "'"); save.setOwner(sowner, 0,
|
||||
* result.getLong("subexp")); }
|
||||
*/
|
||||
|
||||
save.setLogin(result.getLong("login_date"),
|
||||
DataConversions.IPToLong(result.getString("login_ip")));
|
||||
save.setLocation(result.getInt("x"), result.getInt("y"));
|
||||
|
||||
save.setFatigue(result.getInt("fatigue"));
|
||||
save.setCombatStyle((byte) result.getInt("combatstyle"));
|
||||
|
||||
save.setPrivacy(result.getInt("block_chat") == 1,
|
||||
result.getInt("block_private") == 1,
|
||||
result.getInt("block_trade") == 1,
|
||||
result.getInt("block_duel") == 1);
|
||||
save.setSettings(result.getInt("cameraauto") == 1,
|
||||
result.getInt("onemouse") == 1,
|
||||
result.getInt("soundoff") == 1,
|
||||
result.getInt("showroof") == 1,
|
||||
result.getInt("autoscreenshot") == 1,
|
||||
result.getInt("combatwindow") == 1);
|
||||
|
||||
save.setAppearance((byte) result.getInt("haircolour"),
|
||||
(byte) result.getInt("topcolour"),
|
||||
(byte) result.getInt("trousercolour"),
|
||||
(byte) result.getInt("skincolour"),
|
||||
(byte) result.getInt("headsprite"),
|
||||
(byte) result.getInt("bodysprite"),
|
||||
result.getInt("male") == 1, result.getInt("skulled"));
|
||||
|
||||
save.setQuestPoints(result.getInt("quest_points"));
|
||||
|
||||
result = Server.db
|
||||
.getQuery("SELECT * FROM `pk_experience` WHERE `user`='"
|
||||
+ save.getUser() + "'");
|
||||
if (!result.next()) {
|
||||
return save;
|
||||
}
|
||||
for (int i = 0; i < 18; i++) {
|
||||
save.setExp(i, result.getInt("exp_" + statArray[i]));
|
||||
}
|
||||
|
||||
result = Server.db
|
||||
.getQuery("SELECT * FROM `pk_curstats` WHERE `user`='"
|
||||
+ save.getUser() + "'");
|
||||
if (!result.next()) {
|
||||
return save;
|
||||
}
|
||||
for (int i = 0; i < 18; i++) {
|
||||
save.setLvl(i, result.getInt("cur_" + statArray[i]));
|
||||
}
|
||||
|
||||
result = Server.db
|
||||
.getQuery("SELECT id,amount,wielded FROM `pk_invitems` WHERE `user`='"
|
||||
+ save.getUser() + "' ORDER BY `slot` ASC");
|
||||
while (result.next()) {
|
||||
save.addInvItem(result.getInt("id"), result.getInt("amount"),
|
||||
result.getInt("wielded") == 1);
|
||||
}
|
||||
|
||||
result = Server.db
|
||||
.getQuery("SELECT id,amount FROM `pk_bank` WHERE `user`='"
|
||||
+ save.getUser() + "' ORDER BY `slot` ASC");
|
||||
while (result.next()) {
|
||||
save.addBankItem(result.getInt("id"), result.getInt("amount"));
|
||||
}
|
||||
|
||||
result = Server.db
|
||||
.getQuery("SELECT friend FROM `pk_friends` WHERE `user`='"
|
||||
+ save.getUser() + "'");
|
||||
while (result.next()) {
|
||||
save.addFriend(result.getLong("friend"));
|
||||
}
|
||||
|
||||
result = Server.db
|
||||
.getQuery("SELECT `ignore` FROM `pk_ignores` WHERE `user`='"
|
||||
+ save.getUser() + "'");
|
||||
while (result.next()) {
|
||||
save.addIgnore(result.getLong("ignore"));
|
||||
}
|
||||
result = Server.db
|
||||
.getQuery("SELECT * FROM `pk_quests` WHERE `user`='"
|
||||
+ save.getUser() + "'");
|
||||
while (result.next()) {
|
||||
save.setQuestStage(result.getInt("id"), result.getInt("stage"));
|
||||
}
|
||||
save.setEventCD(eventcd);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Server.error("SQL Exception Loading "
|
||||
+ DataConversions.hashToUsername(user) + ": "
|
||||
+ e.getMessage());
|
||||
}
|
||||
|
||||
return save;
|
||||
return Server.storage.loadPlayer(user);
|
||||
}
|
||||
|
||||
private long eventcd = 0;
|
||||
@ -141,7 +21,7 @@ public class PlayerSave {
|
||||
combatWindow;
|
||||
private int combat, skillTotal;
|
||||
private byte combatStyle;
|
||||
private long[] exp = new long[18];
|
||||
private int[] exp = new int[18];
|
||||
private int fatigue;
|
||||
private ArrayList<Long> friendList = new ArrayList<Long>();
|
||||
private byte hairColour, topColour, trouserColour, skinColour, headSprite,
|
||||
@ -162,7 +42,7 @@ public class PlayerSave {
|
||||
|
||||
private int x, y;
|
||||
|
||||
private PlayerSave(long user) {
|
||||
public PlayerSave(long user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@ -174,9 +54,15 @@ public class PlayerSave {
|
||||
friendList.add(friend);
|
||||
}
|
||||
|
||||
public void addFriends(List<Long> friends) {
|
||||
friendList.addAll(friends);
|
||||
}
|
||||
public void addIgnore(long friend) {
|
||||
ignoreList.add(friend);
|
||||
}
|
||||
public void addIgnore(List<Long> ignored) {
|
||||
ignoreList.addAll(ignored);
|
||||
}
|
||||
|
||||
public void addInvItem(int id, int amount, boolean wielded) {
|
||||
invItems.add(new InvItem(id, amount, wielded));
|
||||
@ -230,6 +116,10 @@ public class PlayerSave {
|
||||
return bankItems.get(i);
|
||||
}
|
||||
|
||||
public List<BankItem> getBankItems() {
|
||||
return bankItems;
|
||||
}
|
||||
|
||||
public int getBodySprite() {
|
||||
return bodySprite;
|
||||
}
|
||||
@ -367,86 +257,7 @@ public class PlayerSave {
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
try {
|
||||
String query;
|
||||
|
||||
Server.db.updateQuery("DELETE FROM `pk_bank` WHERE `user`='" + user
|
||||
+ "'");
|
||||
if (bankItems.size() > 0) {
|
||||
query = "INSERT INTO `pk_bank`(`user`, `id`, `amount`, `slot`) VALUES";
|
||||
int slot = 0;
|
||||
for (BankItem item : bankItems) {
|
||||
query += "('" + user + "', '" + item.getID() + "', '"
|
||||
+ item.getAmount() + "', '" + (slot++) + "'),";
|
||||
}
|
||||
Server.db.updateQuery(query.substring(0, query.length() - 1));
|
||||
}
|
||||
|
||||
Server.db.updateQuery("DELETE FROM `pk_invitems` WHERE `user`='"
|
||||
+ user + "'");
|
||||
|
||||
ResultSet result = Server.db
|
||||
.getQuery("Select 1 FROM `pk_players` WHERE `user`='"
|
||||
+ user + "' AND `owner`='" + owner + "'");
|
||||
if (!result.next())
|
||||
return false;
|
||||
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET `combat`=" + combat
|
||||
+ ", skill_total=" + skillTotal + ", `x`=" + x + ", `y`='"
|
||||
+ y + "', `fatigue`='" + fatigue + "', `haircolour`="
|
||||
+ hairColour + ", `topcolour`=" + topColour
|
||||
+ ", `trousercolour`=" + trouserColour + ", `skincolour`="
|
||||
+ skinColour + ", `headsprite`=" + headSprite
|
||||
+ ", `bodysprite`=" + bodySprite + ", `male`="
|
||||
+ (male ? 1 : 0) + ", `skulled`=" + skulled
|
||||
+ ", `combatstyle`=" + combatStyle + ", `quest_points`="
|
||||
+ questPoints + " WHERE `user`='" + user + "'");
|
||||
|
||||
query = "UPDATE `pk_experience` SET ";
|
||||
for (int i = 0; i < 18; i++)
|
||||
query += "`exp_" + statArray[i] + "`=" + exp[i] + ",";
|
||||
|
||||
Server.db.updateQuery(query.substring(0, query.length() - 1)
|
||||
+ " WHERE `user`='" + user + "'");
|
||||
|
||||
query = "UPDATE `pk_curstats` SET ";
|
||||
for (int i = 0; i < 18; i++)
|
||||
query += "`cur_" + statArray[i] + "`=" + lvl[i] + ",";
|
||||
|
||||
Server.db.updateQuery(query.substring(0, query.length() - 1)
|
||||
+ " WHERE `user`='" + user + "'");
|
||||
|
||||
if (invItems.size() > 0) {
|
||||
query = "INSERT INTO `pk_invitems`(`user`, `id`, `amount`, `wielded`, `slot`) VALUES";
|
||||
int slot = 0;
|
||||
for (InvItem item : invItems)
|
||||
query += "('" + user + "', '" + item.getID() + "', '"
|
||||
+ item.getAmount() + "', '"
|
||||
+ (item.isWielded() ? 1 : 0) + "', '" + (slot++)
|
||||
+ "'),";
|
||||
|
||||
Server.db.updateQuery(query.substring(0, query.length() - 1));
|
||||
}
|
||||
|
||||
Server.db.updateQuery("DELETE FROM `pk_quests` WHERE `user`='"
|
||||
+ user + "'");
|
||||
query = "INSERT INTO `pk_quests` (`user`, `id`, `stage`) VALUES";
|
||||
java.util.Set<Integer> keys = questStage.keySet();
|
||||
for (int id : keys)
|
||||
query += "('" + user + "', '" + id + "', '"
|
||||
+ questStage.get(id) + "'),";
|
||||
|
||||
Server.db.updateQuery(query.substring(0, query.length() - 1));
|
||||
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET eventcd='"
|
||||
+ getEventCD() + "' WHERE user='" + user + "'");
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Server.error(e);
|
||||
return false;
|
||||
}
|
||||
return Server.storage.savePlayer(this);
|
||||
}
|
||||
|
||||
public void setAppearance(byte hairColour, byte topColour,
|
||||
@ -461,15 +272,18 @@ public class PlayerSave {
|
||||
this.male = male;
|
||||
this.skulled = skulled;
|
||||
}
|
||||
|
||||
public void setCombatStyle(byte combatStyle) {
|
||||
this.combatStyle = combatStyle;
|
||||
}
|
||||
|
||||
public void setExp(int stat, long exp) {
|
||||
public void setExp(int stat, int exp) {
|
||||
this.exp[stat] = exp;
|
||||
}
|
||||
|
||||
public void setExp(int[] is) {
|
||||
this.exp = is;
|
||||
}
|
||||
|
||||
public void setFatigue(int fatigue) {
|
||||
this.fatigue = fatigue;
|
||||
}
|
||||
@ -523,6 +337,10 @@ public class PlayerSave {
|
||||
this.lvl[stat] = lvl;
|
||||
}
|
||||
|
||||
public void setCurStats(int[] stats) {
|
||||
this.lvl = stats;
|
||||
}
|
||||
|
||||
public void setOwner(int owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
@ -577,7 +395,7 @@ public class PlayerSave {
|
||||
this.combatWindow = combatWindow;
|
||||
}
|
||||
|
||||
public void setStat(int stat, long exp, int lvl) {
|
||||
public void setStat(int stat, int exp, int lvl) {
|
||||
this.exp[stat] = exp;
|
||||
this.lvl[stat] = lvl;
|
||||
}
|
||||
@ -602,4 +420,16 @@ public class PlayerSave {
|
||||
public long getMuted() {
|
||||
return muted;
|
||||
}
|
||||
|
||||
public List<InvItem> getInvItems() {
|
||||
return invItems;
|
||||
}
|
||||
|
||||
public int getCombat() {
|
||||
return combat;
|
||||
}
|
||||
|
||||
public int getSkillTotal() {
|
||||
return skillTotal;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.moparscape.msc.ls.model;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -10,11 +10,10 @@ import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.packetbuilder.loginserver.MiscPacketBuilder;
|
||||
import org.moparscape.msc.ls.util.DataConversions;
|
||||
|
||||
|
||||
public class World {
|
||||
private MiscPacketBuilder actionSender = new MiscPacketBuilder();
|
||||
private int id = -1;
|
||||
private TreeMap<Long, Integer> players = new TreeMap<Long, Integer>();
|
||||
private TreeMap<Long, Long> players = new TreeMap<Long, Long>();
|
||||
private TreeMap<Long, PlayerSave> saves = new TreeMap<Long, PlayerSave>();
|
||||
private IoSession session;
|
||||
|
||||
@ -28,12 +27,14 @@ public class World {
|
||||
}
|
||||
|
||||
public void clearPlayers() {
|
||||
for (Entry<Long, Integer> player : getPlayers()) {
|
||||
for (Entry<Long, Long> player : getPlayers()) {
|
||||
long user = player.getKey();
|
||||
for (World w : Server.getServer().getWorlds()) {
|
||||
w.getActionSender().friendLogout(user);
|
||||
}
|
||||
System.out.println("Removed " + DataConversions.hashToUsername(user) + " from world " + id);
|
||||
System.out.println("Removed "
|
||||
+ DataConversions.hashToUsername(user) + " from world "
|
||||
+ id);
|
||||
}
|
||||
players.clear();
|
||||
}
|
||||
@ -50,7 +51,7 @@ public class World {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Collection<Entry<Long, Integer>> getPlayers() {
|
||||
public Collection<Entry<Long, Long>> getPlayers() {
|
||||
return players.entrySet();
|
||||
}
|
||||
|
||||
@ -68,29 +69,22 @@ public class World {
|
||||
|
||||
public void registerPlayer(long user, String ip) {
|
||||
Server server = Server.getServer();
|
||||
ResultSet result;
|
||||
try {
|
||||
result = Server.db.getQuery("SELECT owner, block_private FROM `pk_players` WHERE `user`='" + user + "'");
|
||||
if (!result.next()) {
|
||||
return;
|
||||
}
|
||||
int owner = result.getInt("owner");
|
||||
boolean blockPrivate = result.getInt("block_private") == 1;
|
||||
long owner = Server.storage.getOwner(user);
|
||||
|
||||
result = Server.db.getQuery("SELECT user FROM `pk_friends` WHERE `friend`='" + user + "'" + (blockPrivate ? " AND user IN (SELECT friend FROM `pk_friends` WHERE `user`='" + user + "')" : ""));
|
||||
while (result.next()) {
|
||||
long friend = result.getLong("user");
|
||||
List<Long> friends = Server.storage.getFriendsOnline(user);
|
||||
if (friends != null)
|
||||
for (long friend : friends) {
|
||||
World w = server.findWorld(friend);
|
||||
if (w != null) {
|
||||
w.getActionSender().friendLogin(friend, user, id);
|
||||
}
|
||||
}
|
||||
long now = (int) (System.currentTimeMillis() / 1000);
|
||||
Server.db.updateQuery("INSERT INTO `pk_logins`(`user`, `time`, `ip`) VALUES('" + user + "', '" + now + "', '" + ip + "')");
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET login_date=" + now + ", login_ip='" + ip + "' WHERE user='" + user + "'");
|
||||
|
||||
Server.storage.logLogin(user, ip);
|
||||
Server.storage.logIn(ip, user);
|
||||
players.put(user, owner);
|
||||
System.out.println("Added " + DataConversions.hashToUsername(user) + " to world " + id);
|
||||
System.out.println("Added " + DataConversions.hashToUsername(user)
|
||||
+ " to world " + id);
|
||||
} catch (Exception e) {
|
||||
Server.error(e);
|
||||
}
|
||||
@ -109,14 +103,9 @@ public class World {
|
||||
w.getActionSender().friendLogout(user);
|
||||
}
|
||||
players.remove(user);
|
||||
System.out.println("Removed " + DataConversions.hashToUsername(user) + " from world " + id);
|
||||
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET online=0 WHERE user='" + user + "'");
|
||||
} catch (Exception e) {
|
||||
Server.error(e);
|
||||
}
|
||||
|
||||
System.out.println("Removed " + DataConversions.hashToUsername(user)
|
||||
+ " from world " + id);
|
||||
Server.storage.setOnlineFlag(id, user);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -120,4 +120,8 @@ public class DatabaseConnection {
|
||||
throw new SQLException(e.getMessage() + ": '" + lastQuery + "'", e.getSQLState(), e.getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
public java.sql.PreparedStatement prepareStatement(String statement) throws SQLException {
|
||||
return con.prepareStatement(statement);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package org.moparscape.msc.ls.packetbuilder.loginserver;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.model.BankItem;
|
||||
@ -89,19 +87,7 @@ public class PlayerLoginPacketBuilder {
|
||||
packet.addInt(item.getAmount());
|
||||
}
|
||||
|
||||
ArrayList<Long> friendsWithUs = new ArrayList<Long>();
|
||||
try {
|
||||
ResultSet result = Server.db.getQuery("SELECT p.user FROM `pk_friends` AS f INNER JOIN `pk_players` AS p ON p.user=f.friend WHERE p.block_private=0 AND f.user='" + save.getUser() + "'");
|
||||
while (result.next()) {
|
||||
friendsWithUs.add(result.getLong("user"));
|
||||
}
|
||||
result = Server.db.getQuery("SELECT user FROM `pk_friends` WHERE friend='" + save.getUser() + "'");
|
||||
while (result.next()) {
|
||||
friendsWithUs.add(result.getLong("user"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Server.error(e);
|
||||
}
|
||||
List<Long> friendsWithUs = Server.storage.getFriendsOnline(save.getUser());
|
||||
|
||||
int friendCount = save.getFriendCount();
|
||||
packet.addShort(friendCount);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.moparscape.msc.ls.packethandler.loginserver;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.model.World;
|
||||
@ -11,24 +9,22 @@ import org.moparscape.msc.ls.packetbuilder.loginserver.ReplyPacketBuilder;
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
import org.moparscape.msc.ls.util.DataConversions;
|
||||
|
||||
|
||||
public class BanHandler implements PacketHandler {
|
||||
private ReplyPacketBuilder builder = new ReplyPacketBuilder();
|
||||
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
final long uID = ((LSPacket) p).getUID();
|
||||
boolean banned = ((LSPacket) p).getID() == 4;
|
||||
boolean setBanned = ((LSPacket) p).getID() == 4;
|
||||
long user = p.readLong();
|
||||
long modhash = p.readLong();
|
||||
|
||||
ResultSet result = Server.db.getQuery("SELECT u.group_id, p.playermod, p.owner FROM `users` AS u INNER JOIN `pk_players` AS p ON p.owner=u.id WHERE p.user='" + user + "'");
|
||||
if (!result.next()) {
|
||||
if (!Server.storage.playerExists(user)) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("There is not an account by that username");
|
||||
} else if (banned && (result.getInt("group_id") < 3 || result.getInt("playermod") == 1)) {
|
||||
} else if (setBanned && Server.storage.getGroupID(user) < 3) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("You cannot ban a (p)mod or admin!");
|
||||
} else if (Server.db.updateQuery("UPDATE `pk_players` SET `banned`='" + (banned ? "1" : "0") + "' WHERE `user` LIKE '" + user + "'") == 0) {
|
||||
} else if (Server.storage.ban(setBanned, user)) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("There is not an account by that username");
|
||||
} else {
|
||||
@ -36,10 +32,11 @@ public class BanHandler implements PacketHandler {
|
||||
if (w != null) {
|
||||
w.getActionSender().logoutUser(user);
|
||||
}
|
||||
if (banned)
|
||||
Server.db.updateQuery("INSERT `pk_banlog` VALUES('" + user + "','" + modhash + "','" + (System.currentTimeMillis() / 1000) + "')");
|
||||
if (setBanned)
|
||||
Server.storage.logBan(user, modhash);
|
||||
builder.setSuccess(true);
|
||||
builder.setReply(DataConversions.hashToUsername(user) + " has been " + (banned ? "banned" : "unbanned"));
|
||||
builder.setReply(DataConversions.hashToUsername(user)
|
||||
+ " has been " + (setBanned ? "banned" : "unbanned"));
|
||||
}
|
||||
builder.setUID(uID);
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.moparscape.msc.ls.packethandler.loginserver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.model.PlayerSave;
|
||||
@ -10,7 +8,6 @@ import org.moparscape.msc.ls.net.LSPacket;
|
||||
import org.moparscape.msc.ls.net.Packet;
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
|
||||
|
||||
public class FriendHandler implements PacketHandler {
|
||||
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
@ -32,54 +29,40 @@ public class FriendHandler implements PacketHandler {
|
||||
}
|
||||
break;
|
||||
case 11: // Add friend
|
||||
try {
|
||||
save.addFriend(friend);
|
||||
Server.db.updateQuery("INSERT INTO `pk_friends`(`user`, `friend`) VALUES('" + user + "', '" + friend + "')");
|
||||
if (Server.db.getQuery("SELECT 1 FROM `pk_players` AS p LEFT JOIN `pk_friends` AS f ON f.user=p.user WHERE (p.block_private=0 OR f.friend='" + user + "') AND p.user='" + friend + "'").next()) {
|
||||
Server.storage.addFriend(user, friend);
|
||||
if (Server.storage.addFriend_isOnline0(user, friend)) {
|
||||
w = server.findWorld(friend);
|
||||
if (w != null) {
|
||||
world.getActionSender().friendLogin(user, friend, w.getID());
|
||||
world.getActionSender()
|
||||
.friendLogin(user, friend, w.getID());
|
||||
}
|
||||
}
|
||||
if (Server.db.getQuery("SELECT 1 FROM `pk_players` AS p LEFT JOIN `pk_friends` AS f ON f.friend=p.user WHERE p.block_private=1 AND f.user='" + friend + "' AND p.user='" + user + "'").next()) {
|
||||
if (Server.storage.addFriend_isOnline1(friend, user)) {
|
||||
w = server.findWorld(friend);
|
||||
if (w != null) {
|
||||
w.getActionSender().friendLogin(friend, user, world.getID());
|
||||
w.getActionSender()
|
||||
.friendLogin(friend, user, world.getID());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
case 12: // Remove friend
|
||||
try {
|
||||
save.removeFriend(friend);
|
||||
Server.db.updateQuery("DELETE FROM `pk_friends` WHERE `user` LIKE '" + user + "' AND `friend` LIKE '" + friend + "'");
|
||||
if (Server.db.getQuery("SELECT 1 FROM `pk_players` WHERE block_private=1 AND user='" + user + "'").next()) {
|
||||
Server.storage.removeFriend(user, friend);
|
||||
if (Server.storage.removeFriend_isOnline(user)) {
|
||||
w = server.findWorld(friend);
|
||||
if (w != null) {
|
||||
w.getActionSender().friendLogout(friend, user);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
case 13: // Add ignore
|
||||
try {
|
||||
save.addIgnore(friend);
|
||||
Server.db.updateQuery("INSERT INTO `pk_ignores`(`user`, `ignore`) VALUES('" + user + "', '" + friend + "')");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
Server.storage.addIgnore(user, friend);
|
||||
break;
|
||||
case 14: // Remove ignore
|
||||
try {
|
||||
save.removeIgnore(friend);
|
||||
Server.db.updateQuery("DELETE FROM `pk_ignores` WHERE `user` LIKE '" + user + "' AND `ignore` LIKE '" + friend + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
Server.storage.removeIgnore(user, friend);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.moparscape.msc.ls.packethandler.loginserver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.model.World;
|
||||
@ -16,50 +14,7 @@ public class GameSettingHandler implements PacketHandler {
|
||||
long user = p.readLong();
|
||||
boolean on = p.readByte() == 1;
|
||||
int idx = (int) p.readByte();
|
||||
switch (idx) {
|
||||
case 0: // Camera Auto
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET cameraauto=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
case 2: // One Mouse
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET onemouse=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
case 3: // Sound Off
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET soundoff=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
case 4: // Show Roof
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET showroof=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
case 5: // Auto Screenshot
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET autoscreenshot=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
case 6: // Combat Window
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET combatwindow=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
Server.storage.setGameSettings(idx, on, user);
|
||||
Server.getServer().findSave(user, world).setGameSetting(idx, on);
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,17 @@
|
||||
package org.moparscape.msc.ls.packethandler.loginserver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.net.Packet;
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
|
||||
|
||||
public class KillHandler implements PacketHandler {
|
||||
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
try {
|
||||
Server.db.updateQuery("INSERT INTO `pk_kills`(`user`, `killed`, `time`, `type`) VALUES('" + p.readLong() + "', '" + p.readLong() + "', " + (int) (System.currentTimeMillis() / 1000) + ", " + p.readByte() + ")");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long user = p.readLong();
|
||||
long killed = p.readLong();
|
||||
byte type = p.readByte();
|
||||
Server.storage.logKill(user, killed, type);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.moparscape.msc.ls.packethandler.loginserver;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -15,7 +13,6 @@ import org.moparscape.msc.ls.packetbuilder.loginserver.PlayerLoginPacketBuilder;
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
import org.moparscape.msc.ls.util.DataConversions;
|
||||
|
||||
|
||||
public class PlayerLoginHandler implements PacketHandler {
|
||||
public static ArrayList<String> badClients = new ArrayList<String>();
|
||||
private PlayerLoginPacketBuilder builder = new PlayerLoginPacketBuilder();
|
||||
@ -33,9 +30,11 @@ public class PlayerLoginHandler implements PacketHandler {
|
||||
if (loginCode == 0 || loginCode == 1 || loginCode == 99) {
|
||||
try {
|
||||
badClients.add(DataConversions.hashToUsername(user));
|
||||
System.out.println("Class: " + className + " Player: " + DataConversions.hashToUsername(user));
|
||||
System.out.println("Class: " + className + " Player: "
|
||||
+ DataConversions.hashToUsername(user));
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception in classname printer :" + e.getMessage());
|
||||
System.out.println("Exception in classname printer :"
|
||||
+ e.getMessage());
|
||||
}
|
||||
// if(!className.equals("ORG.RSCDAEMON.CLIENT.MUDCLIENT")) {
|
||||
// System.out.println(DataConversions.hashToUsername(user) +
|
||||
@ -46,12 +45,10 @@ public class PlayerLoginHandler implements PacketHandler {
|
||||
// "', '" + ip + "', 'Unknown main class: \"" + className +"\"')");
|
||||
// } catch(Exception e) { }
|
||||
// }
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET online=1 WHERE user='" + user + "'");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
Server.storage.setOnlineFlag(world.getID(), user);
|
||||
|
||||
builder.setPlayer(Server.getServer().findSave(user, world), loginCode);
|
||||
builder.setPlayer(Server.getServer().findSave(user, world),
|
||||
loginCode);
|
||||
world.registerPlayer(user, ip);
|
||||
} else {
|
||||
builder.setPlayer(null, loginCode);
|
||||
@ -67,27 +64,27 @@ public class PlayerLoginHandler implements PacketHandler {
|
||||
Server server = Server.getServer();
|
||||
byte returnVal = 0;
|
||||
|
||||
try {
|
||||
ResultSet result = Server.db.getQuery("SELECT banned, owner, group_id FROM `pk_players` WHERE `user` = '" + user + "'");
|
||||
if (!result.next()) {
|
||||
if (!Server.storage.playerExists(user))
|
||||
return 2;
|
||||
}
|
||||
if (!Auth.check_auth(DataConversions.hashToUsername(user), pass, new StringBuilder())) {
|
||||
if (!Auth.check_auth(DataConversions.hashToUsername(user), pass,
|
||||
new StringBuilder())) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (result.getInt("banned") == 1) {
|
||||
System.out.println("Banned player: " + DataConversions.hashToUsername(user) + " trying to login.");
|
||||
if (Server.storage.isBanned(user)) {
|
||||
System.out.println("Banned player: "
|
||||
+ DataConversions.hashToUsername(user)
|
||||
+ " trying to login.");
|
||||
return 6;
|
||||
}
|
||||
|
||||
if (result.getInt("group_id") >= 5) {
|
||||
if (Server.storage.getGroupID(user) >= 5) {
|
||||
returnVal = 99;
|
||||
}
|
||||
|
||||
int owner = result.getInt("owner");
|
||||
long owner = Server.storage.getOwner(user);
|
||||
for (World w : server.getWorlds()) {
|
||||
for (Entry<Long, Integer> player : w.getPlayers()) {
|
||||
for (Entry<Long, Long> player : w.getPlayers()) {
|
||||
if (player.getKey() == user) {
|
||||
return 3;
|
||||
}
|
||||
@ -100,10 +97,5 @@ public class PlayerLoginHandler implements PacketHandler {
|
||||
}
|
||||
}
|
||||
return returnVal;
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Exception in PlayerLoginHandler :" + e.getMessage());
|
||||
//System.out.println(e.getMessage(), e);
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ public class PlayerSaveHandler implements PacketHandler {
|
||||
//save.setPoints(p.readInt());
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
save.setStat(i, p.readLong(), p.readShort());
|
||||
save.setStat(i, p.readInt(), p.readShort());
|
||||
}
|
||||
|
||||
int invCount = p.readShort();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.moparscape.msc.ls.packethandler.loginserver;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.ls.Server;
|
||||
@ -9,7 +8,6 @@ import org.moparscape.msc.ls.model.World;
|
||||
import org.moparscape.msc.ls.net.Packet;
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
|
||||
|
||||
public class PrivacySettingHandler implements PacketHandler {
|
||||
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
@ -19,46 +17,32 @@ public class PrivacySettingHandler implements PacketHandler {
|
||||
long user = p.readLong();
|
||||
boolean on = p.readByte() == 1;
|
||||
int idx = (int) p.readByte();
|
||||
int isOn = (on ? 1 : 0);
|
||||
switch (idx) {
|
||||
case 0: // Chat block
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET block_chat=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
Server.storage.chatBlock(isOn, user);
|
||||
break;
|
||||
case 1: // Private block
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET block_private=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
ResultSet result = Server.db.getQuery("SELECT user FROM `pk_friends` WHERE friend='" + user + "' AND user NOT IN (SELECT friend FROM `pk_friends` WHERE user='" + user + "')");
|
||||
while (result.next()) {
|
||||
long friend = result.getLong("user");
|
||||
Server.storage.privateBlock(isOn, user);
|
||||
List<Long> friends = Server.storage
|
||||
.getPrivateBlockFriendsOnline(user);
|
||||
for (long friend : friends) {
|
||||
World w = server.findWorld(friend);
|
||||
if (w != null) {
|
||||
if (on) {
|
||||
w.getActionSender().friendLogout(friend, user);
|
||||
} else {
|
||||
w.getActionSender().friendLogin(friend, user, world.getID());
|
||||
w.getActionSender().friendLogin(friend, user,
|
||||
world.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
break;
|
||||
case 2: // Trade block
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET block_trade=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
Server.storage.tradeBlock(isOn, user);
|
||||
break;
|
||||
case 3: // Duel block
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET block_duel=" + (on ? 1 : 0) + " WHERE user='" + user + "'");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e.getMessage());
|
||||
}
|
||||
Server.storage.duelBlock(isOn, user);
|
||||
break;
|
||||
}
|
||||
server.findSave(user, world).setPrivacySetting(idx, on);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.moparscape.msc.ls.packethandler.loginserver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.model.World;
|
||||
@ -11,7 +9,6 @@ import org.moparscape.msc.ls.packetbuilder.loginserver.WorldRegisteredPacketBuil
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
import org.moparscape.msc.ls.util.DataConversions;
|
||||
|
||||
|
||||
public class RegisterWorld implements PacketHandler {
|
||||
private WorldRegisteredPacketBuilder builder = new WorldRegisteredPacketBuilder();
|
||||
|
||||
@ -29,27 +26,19 @@ public class RegisterWorld implements PacketHandler {
|
||||
world = new World(id, session);
|
||||
server.registerWorld(world);
|
||||
System.out.println("Registering world: " + id);
|
||||
try {
|
||||
if (id == 1)
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET online=0");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e);
|
||||
}
|
||||
Server.storage.resetOnlineFlag(id);
|
||||
|
||||
} else {
|
||||
world.setSession(session);
|
||||
server.setIdle(world, false);
|
||||
System.out.println("Reattached to world " + id);
|
||||
try {
|
||||
Server.db.updateQuery("UPDATE `pk_players` SET online=0");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e);
|
||||
}
|
||||
Server.storage.resetOnlineFlag(id);
|
||||
|
||||
}
|
||||
int playerCount = p.readShort();
|
||||
for (int i = 0; i < playerCount; i++) {
|
||||
world.registerPlayer(p.readLong(), DataConversions.IPToString(p.readLong()));
|
||||
world.registerPlayer(p.readLong(),
|
||||
DataConversions.IPToString(p.readLong()));
|
||||
}
|
||||
session.setAttachment(world);
|
||||
builder.setSuccess(true);
|
||||
|
@ -1,14 +1,11 @@
|
||||
package org.moparscape.msc.ls.packethandler.loginserver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.model.World;
|
||||
import org.moparscape.msc.ls.net.Packet;
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
|
||||
|
||||
public class ReportHandler implements PacketHandler {
|
||||
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
@ -17,16 +14,15 @@ public class ReportHandler implements PacketHandler {
|
||||
final long user = p.readLong();
|
||||
final long reported = p.readLong();
|
||||
final byte reason = p.readByte();
|
||||
world.getActionSender().requestReportInfo(reported, new PacketHandler() {
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
world.getActionSender().requestReportInfo(reported,
|
||||
new PacketHandler() {
|
||||
public void handlePacket(Packet p, IoSession session)
|
||||
throws Exception {
|
||||
int x = p.readShort();
|
||||
int y = p.readShort();
|
||||
String status = p.readString();
|
||||
try {
|
||||
Server.db.updateQuery("INSERT INTO `pk_reports`(`from`, `about`, `time`, `reason`, `x`, `y`, `status`) VALUES('" + user + "', '" + reported + "', '" + (System.currentTimeMillis() / 1000) + "', '" + reason + "', '" + x + "', '" + y + "', '" + status + "')");
|
||||
} catch (SQLException e) {
|
||||
Server.error(e);
|
||||
}
|
||||
Server.storage.logReport(user, reported, reason, x, y,
|
||||
status);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.net.Packet;
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
|
||||
|
||||
public class Tradelog implements PacketHandler {
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
long from = p.readLong();
|
||||
@ -16,6 +15,6 @@ public class Tradelog implements PacketHandler {
|
||||
int y = p.readInt();
|
||||
int type = p.readInt();
|
||||
long date = (System.currentTimeMillis() / 1000);
|
||||
Server.db.updateQuery("INSERT `pk_tradelog` VALUES('" + from + "','" + to + "','" + date + "','" + item + "','" + x + "','" + y + "','" + amount + "','" + type + "')");
|
||||
Server.storage.logTrade(from, to, item, amount, x, y, type, date);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package org.moparscape.msc.ls.persistence;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.moparscape.msc.ls.model.PlayerSave;
|
||||
|
||||
public interface StorageMedium {
|
||||
public boolean savePlayer(PlayerSave s);
|
||||
public void shutdown();
|
||||
public void logTrade(long from, long to, int item, long amount, int x,
|
||||
int y, int type, long date);
|
||||
public void logReport(long user, long reported, byte reason, int x,
|
||||
int y, String status);
|
||||
public void resetOnlineFlag(int world);
|
||||
public void logKill(long user, long killed, byte type);
|
||||
public void addFriend(long user, long friend);
|
||||
public boolean addFriend_isOnline0(long user, long friend);
|
||||
public boolean addFriend_isOnline1(long friend, long user);
|
||||
public void removeFriend(long user, long friend);
|
||||
public boolean removeFriend_isOnline(long user);
|
||||
public void addIgnore(long user, long friend);
|
||||
public void removeIgnore(long user, long friend);
|
||||
public List<Long> getFriendsOnline(long user);
|
||||
public void chatBlock(int on, long user);
|
||||
public void privateBlock(int on, long user);
|
||||
public List<Long> getPrivateBlockFriendsOnline(long user);
|
||||
public void tradeBlock(int on, long user);
|
||||
public void duelBlock(int on, long user);
|
||||
public boolean playerExists(long user);
|
||||
public boolean isBanned(long user);
|
||||
public int getGroupID(long user);
|
||||
public long getOwner(long user);
|
||||
public void setOnlineFlag(int id, long user);
|
||||
public boolean ban(boolean setBanned, long user);
|
||||
public void logBan(long user, long modhash);
|
||||
public void setGameSettings(int idx, boolean on, long user);
|
||||
public PlayerSave loadPlayer(long user);
|
||||
public void logLogin(long user, String ip);
|
||||
public void logIn(String ip, long user);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,718 @@
|
||||
package org.moparscape.msc.ls.persistence.impl;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.moparscape.msc.ls.model.BankItem;
|
||||
import org.moparscape.msc.ls.model.InvItem;
|
||||
import org.moparscape.msc.ls.model.PlayerSave;
|
||||
import org.moparscape.msc.ls.net.DatabaseConnection;
|
||||
import org.moparscape.msc.ls.persistence.StorageMedium;
|
||||
import org.moparscape.msc.ls.util.Config;
|
||||
import org.moparscape.msc.ls.util.DataConversions;
|
||||
|
||||
public class MySQL implements StorageMedium {
|
||||
|
||||
private final DatabaseConnection conn;
|
||||
|
||||
public MySQL() {
|
||||
conn = new DatabaseConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean savePlayer(PlayerSave s) {
|
||||
if (!playerExists(s.getUser())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement statement;
|
||||
try {
|
||||
updateLongs(Statements.save_DeleteBank, s.getUser());
|
||||
|
||||
if (s.getBankCount() > 0) {
|
||||
statement = conn.prepareStatement(Statements.save_AddBank);
|
||||
int slot = 0;
|
||||
for (BankItem item : s.getBankItems()) {
|
||||
statement.setLong(1, s.getUser());
|
||||
statement.setInt(2, item.getID());
|
||||
statement.setInt(3, item.getAmount());
|
||||
statement.setInt(4, slot);
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
}
|
||||
|
||||
updateLongs(Statements.save_DeleteInv, s.getUser());
|
||||
|
||||
if (s.getInvCount() > 0) {
|
||||
statement = conn.prepareStatement(Statements.save_AddInvItem);
|
||||
int slot = 0;
|
||||
for (InvItem item : s.getInvItems()) {
|
||||
statement.setLong(1, s.getUser());
|
||||
statement.setInt(2, item.getID());
|
||||
statement.setInt(3, item.getAmount());
|
||||
statement.setInt(4, (item.isWielded() ? 1 : 0));
|
||||
statement.setInt(5, slot++);
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
}
|
||||
|
||||
updateLongs(Statements.save_DeleteQuests, s.getUser());
|
||||
|
||||
statement = conn.prepareStatement(Statements.save_AddQuest);
|
||||
Set<Integer> keys = s.getQuestStages().keySet();
|
||||
for (int id : keys) {
|
||||
statement.setLong(1, s.getUser());
|
||||
statement.setInt(2, id);
|
||||
statement.setInt(3, s.getQuestStage(id));
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
|
||||
statement = conn.prepareStatement(Statements.save_UpdateBasicInfo);
|
||||
statement.setInt(1, s.getCombat());
|
||||
statement.setInt(2, s.getSkillTotal());
|
||||
statement.setInt(3, s.getX());
|
||||
statement.setInt(4, s.getY());
|
||||
statement.setInt(5, s.getFatigue());
|
||||
statement.setInt(6, s.getHairColour());
|
||||
statement.setInt(7, s.getTopColour());
|
||||
statement.setInt(8, s.getTrouserColour());
|
||||
statement.setInt(9, s.getSkinColour());
|
||||
statement.setInt(10, s.getHeadSprite());
|
||||
statement.setInt(11, s.getBodySprite());
|
||||
statement.setInt(12, s.isMale() ? 1 : 0);
|
||||
statement.setLong(13, s.getSkullTime());
|
||||
statement.setInt(14, s.getCombatStyle());
|
||||
statement.setInt(15, s.getQuestPoints());
|
||||
statement.setLong(16, s.getUser());
|
||||
statement.executeUpdate();
|
||||
|
||||
String query = "UPDATE `" + Statements.PREFIX + "experience` SET ";
|
||||
for (int i = 0; i < 18; i++)
|
||||
query += "`exp_" + Config.statArray[i] + "`=" + s.getExp(i)
|
||||
+ ",";
|
||||
|
||||
conn.updateQuery(query.substring(0, query.length() - 1)
|
||||
+ " WHERE `user`=" + s.getUser());
|
||||
|
||||
query = "UPDATE `" + Statements.PREFIX + "curstats` SET ";
|
||||
for (int i = 0; i < 18; i++)
|
||||
query += "`cur_" + Config.statArray[i] + "`=" + s.getStat(i)
|
||||
+ ",";
|
||||
|
||||
conn.updateQuery(query.substring(0, query.length() - 1)
|
||||
+ " WHERE `user`=" + s.getUser());
|
||||
|
||||
updateLongs(Statements.save_SetEventCD, s.getEventCD() / 1000, s.getUser());
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Unable to cleanly close MySQL connection");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logTrade(long from, long to, int item, long amount, int x,
|
||||
int y, int type, long date) {
|
||||
PreparedStatement logTrade = null;
|
||||
try {
|
||||
logTrade = conn.prepareStatement(Statements.logTrade);
|
||||
|
||||
logTrade.setLong(1, from);
|
||||
logTrade.setLong(2, to);
|
||||
logTrade.setLong(3, date);
|
||||
logTrade.setInt(4, item);
|
||||
logTrade.setInt(5, x);
|
||||
logTrade.setInt(6, y);
|
||||
logTrade.setLong(7, amount);
|
||||
logTrade.setInt(8, type);
|
||||
|
||||
logTrade.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
if (logTrade != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ Statements.logTrade);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logReport(long user, long reported, byte reason, int x, int y,
|
||||
String status) {
|
||||
PreparedStatement logReport = null;
|
||||
try {
|
||||
logReport = conn.prepareStatement(Statements.logReport);
|
||||
|
||||
logReport.setLong(1, user);
|
||||
logReport.setLong(2, reported);
|
||||
logReport.setLong(3, System.currentTimeMillis() / 1000);
|
||||
logReport.setByte(4, reason);
|
||||
logReport.setInt(5, x);
|
||||
logReport.setInt(6, y);
|
||||
logReport.setString(7, status);
|
||||
|
||||
logReport.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
if (logReport != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ Statements.logReport);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logKill(long user, long killed, byte type) {
|
||||
PreparedStatement logKill = null;
|
||||
try {
|
||||
logKill = conn.prepareStatement(Statements.logKill);
|
||||
|
||||
logKill.setLong(1, user);
|
||||
logKill.setLong(2, killed);
|
||||
logKill.setLong(3, System.currentTimeMillis() / 1000);
|
||||
logKill.setByte(4, type);
|
||||
|
||||
logKill.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
if (logKill != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ Statements.logKill);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetOnlineFlag(int world) {
|
||||
PreparedStatement resetOnlineFlag = null;
|
||||
try {
|
||||
resetOnlineFlag = conn.prepareStatement(Statements.resetOnlineFlag);
|
||||
|
||||
resetOnlineFlag.setInt(1, world);
|
||||
|
||||
resetOnlineFlag.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
if (resetOnlineFlag != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ Statements.resetOnlineFlag);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFriend(long user, long friend) {
|
||||
updateLongs(Statements.addFriend, user, friend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFriend_isOnline0(long user, long friend) {
|
||||
return hasNextFromLongs(Statements.addFriend_isOnline0, user, friend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFriend_isOnline1(long friend, long user) {
|
||||
return hasNextFromLongs(Statements.addFriend_isOnline1, friend, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFriend(long user, long friend) {
|
||||
updateLongs(Statements.removeFriend, user, friend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFriend_isOnline(long user) {
|
||||
return hasNextFromLongs(Statements.removeFriend_isOnline, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addIgnore(long user, long friend) {
|
||||
updateLongs(Statements.addIgnore, user, friend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeIgnore(long user, long friend) {
|
||||
updateLongs(Statements.removeIgnore, user, friend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getFriendsOnline(long user) {
|
||||
try {
|
||||
List<Long> list = longListFromResultSet(
|
||||
resultSetFromLongs(Statements.friendsList0, user), "user");
|
||||
list.addAll(longListFromResultSet(
|
||||
resultSetFromLongs(Statements.friendsList1,user), "user"));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chatBlock(int on, long user) {
|
||||
updateIntsLongs(Statements.chatBlock, new int[] { on },
|
||||
new long[] { user });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void privateBlock(int on, long user) {
|
||||
updateIntsLongs(Statements.privateBlock, new int[] { on },
|
||||
new long[] { user });
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getPrivateBlockFriendsOnline(long user) {
|
||||
try {
|
||||
return longListFromResultSet(
|
||||
resultSetFromLongs(Statements.privateBlock_online, user,
|
||||
user), "user");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tradeBlock(int on, long user) {
|
||||
updateIntsLongs(Statements.tradeBlock, new int[] { on },
|
||||
new long[] { user });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void duelBlock(int on, long user) {
|
||||
updateIntsLongs(Statements.duelBlock, new int[] { on },
|
||||
new long[] { user });
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerExists(long user) {
|
||||
return hasNextFromLongs(Statements.basicInfo, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBanned(long user) {
|
||||
try {
|
||||
ResultSet res = resultSetFromLongs(Statements.basicInfo, user);
|
||||
res.next();
|
||||
return res.getInt("banned") == 1;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupID(long user) {
|
||||
try {
|
||||
ResultSet res = resultSetFromLongs(Statements.basicInfo, user);
|
||||
res.next();
|
||||
return res.getInt("group_id");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
// Normal user = 1
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getOwner(long user) {
|
||||
try {
|
||||
ResultSet res = resultSetFromLongs(Statements.basicInfo, user);
|
||||
res.next();
|
||||
return res.getLong("owner");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnlineFlag(int id, long user) {
|
||||
updateIntsLongs(Statements.setOnlineFlag, new int[] { id },
|
||||
new long[] { user });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logBan(long user, long modhash) {
|
||||
updateLongs(Statements.logBan, user, modhash,
|
||||
(System.currentTimeMillis() / 1000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ban(boolean setBanned, long user) {
|
||||
updateLongs(Statements.setBanned, (setBanned ? 1 : 0), user);
|
||||
return isBanned(user);
|
||||
}
|
||||
|
||||
private static final String[] gameSettings = { "cameraauto", "",
|
||||
"onemouse", "soundoff", "showroof", "autoscreenshot",
|
||||
"combatwindow" };
|
||||
|
||||
@Override
|
||||
public void setGameSettings(int idx, boolean on, long user) {
|
||||
try {
|
||||
conn.updateQuery("UPDATE `" + Statements.PREFIX + "players` SET "
|
||||
+ gameSettings[idx] + "=" + (on ? 1 : 0) + " WHERE user='"
|
||||
+ user + "'");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerSave loadPlayer(long user) {
|
||||
PlayerSave save = new PlayerSave(user);
|
||||
ResultSet result = resultSetFromLongs(Statements.playerData, user);
|
||||
try {
|
||||
if (!result.next()) {
|
||||
return save;
|
||||
}
|
||||
|
||||
save.setEventCD(result.getLong("eventcd"));
|
||||
save.setOwner(result.getInt("owner"), result.getInt("group_id"),
|
||||
result.getLong("sub_expires"));
|
||||
save.setMuted(result.getLong("muted"));
|
||||
|
||||
save.setLogin(result.getLong("login_date"),
|
||||
DataConversions.IPToLong(result.getString("login_ip")));
|
||||
save.setLocation(result.getInt("x"), result.getInt("y"));
|
||||
|
||||
save.setFatigue(result.getInt("fatigue"));
|
||||
save.setCombatStyle((byte) result.getInt("combatstyle"));
|
||||
|
||||
save.setPrivacy(result.getInt("block_chat") == 1,
|
||||
result.getInt("block_private") == 1,
|
||||
result.getInt("block_trade") == 1,
|
||||
result.getInt("block_duel") == 1);
|
||||
save.setSettings(result.getInt("cameraauto") == 1,
|
||||
result.getInt("onemouse") == 1,
|
||||
result.getInt("soundoff") == 1,
|
||||
result.getInt("showroof") == 1,
|
||||
result.getInt("autoscreenshot") == 1,
|
||||
result.getInt("combatwindow") == 1);
|
||||
|
||||
save.setAppearance((byte) result.getInt("haircolour"),
|
||||
(byte) result.getInt("topcolour"),
|
||||
(byte) result.getInt("trousercolour"),
|
||||
(byte) result.getInt("skincolour"),
|
||||
(byte) result.getInt("headsprite"),
|
||||
(byte) result.getInt("bodysprite"),
|
||||
result.getInt("male") == 1, result.getInt("skulled"));
|
||||
|
||||
save.setQuestPoints(result.getInt("quest_points"));
|
||||
|
||||
save.setExp(intArrayFromStringArray(Statements.playerExp, "exp_",
|
||||
Config.statArray, user));
|
||||
save.setCurStats(intArrayFromStringArray(Statements.playerCurExp,
|
||||
"cur_", Config.statArray, user));
|
||||
result = resultSetFromLongs(Statements.playerInvItems, user);
|
||||
while (result.next()) {
|
||||
save.addInvItem(result.getInt("id"), result.getInt("amount"),
|
||||
result.getInt("wielded") == 1);
|
||||
}
|
||||
|
||||
result = resultSetFromLongs(Statements.playerBankItems, user);
|
||||
while (result.next()) {
|
||||
save.addBankItem(result.getInt("id"), result.getInt("amount"));
|
||||
}
|
||||
|
||||
save.addFriends(longListFromResultSet(
|
||||
resultSetFromLongs(Statements.playerFriends, user),
|
||||
"friend"));
|
||||
save.addIgnore(longListFromResultSet(
|
||||
resultSetFromLongs(Statements.playerIngored, user),
|
||||
"ignore"));
|
||||
|
||||
result = resultSetFromLongs(Statements.playerQuests, user);
|
||||
while (result.next()) {
|
||||
save.setQuestStage(result.getInt("id"), result.getInt("stage"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return save;
|
||||
}
|
||||
|
||||
private void updateLongs(String statement, long... longA) {
|
||||
PreparedStatement prepared = null;
|
||||
try {
|
||||
prepared = conn.prepareStatement(statement);
|
||||
|
||||
for (int i = 1; i <= longA.length; i++) {
|
||||
prepared.setLong(i, longA[i - 1]);
|
||||
}
|
||||
|
||||
prepared.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
if (prepared != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ statement);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateIntsLongs(String statement, int[] intA, long[] longA) {
|
||||
PreparedStatement prepared = null;
|
||||
try {
|
||||
prepared = conn.prepareStatement(statement);
|
||||
|
||||
for (int i = 1; i <= intA.length; i++) {
|
||||
prepared.setInt(i, intA[i - 1]);
|
||||
}
|
||||
int offset = intA.length + 1;
|
||||
for (int i = 0; i < longA.length; i++) {
|
||||
prepared.setLong(i + offset, longA[i]);
|
||||
}
|
||||
|
||||
prepared.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
if (prepared != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ statement);
|
||||
}
|
||||
}
|
||||
|
||||
private int[] intArrayFromStringArray(String statement, String prefix,
|
||||
String[] stringArray, long... args) {
|
||||
ResultSet result = resultSetFromLongs(statement, args);
|
||||
|
||||
try {
|
||||
result.next();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
int[] data = new int[stringArray.length];
|
||||
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
try {
|
||||
data[i] = result.getInt(prefix + stringArray[i]);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<Long> longListFromResultSet(ResultSet result, String param)
|
||||
throws SQLException {
|
||||
List<Long> list = new ArrayList<Long>();
|
||||
|
||||
while (result.next()) {
|
||||
list.add(result.getLong(param));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private ResultSet resultSetFromLongs(String statement, long... longA) {
|
||||
PreparedStatement prepared = null;
|
||||
ResultSet result = null;
|
||||
try {
|
||||
prepared = conn.prepareStatement(statement);
|
||||
|
||||
for (int i = 1; i <= longA.length; i++) {
|
||||
prepared.setLong(i, longA[i - 1]);
|
||||
}
|
||||
|
||||
result = prepared.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
if (prepared != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ statement);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean hasNextFromLongs(String statement, long... longA) {
|
||||
PreparedStatement prepared = null;
|
||||
ResultSet result = null;
|
||||
try {
|
||||
prepared = conn.prepareStatement(statement);
|
||||
|
||||
for (int i = 1; i <= longA.length; i++) {
|
||||
prepared.setLong(i, longA[i - 1]);
|
||||
}
|
||||
|
||||
result = prepared.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
if (prepared != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ statement);
|
||||
}
|
||||
|
||||
try {
|
||||
return result.next();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class Statements {
|
||||
private static final String PREFIX = "pk_";
|
||||
private static final String logTrade = "INSERT `" + PREFIX
|
||||
+ "_tradelog` VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String logReport = "INSERT INTO `"
|
||||
+ PREFIX
|
||||
+ "reports`(`from`, `about`, `time`, `reason`, `x`, `y`, `status`) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String resetOnlineFlag = "UPDATE `" + PREFIX
|
||||
+ "players` SET online=0, world=-1 WHERE world=?";
|
||||
private static final String logKill = "INSERT INTO `" + PREFIX
|
||||
+ "kills`(`user`, `killed`, `time`, `type`) VALUES(?, ?, ?, ?)";
|
||||
private static final String addFriend = "INSERT INTO `" + PREFIX
|
||||
+ "friends`(`user`, `friend`) VALUES(?, ?)";
|
||||
private static final String addFriend_isOnline0 = "SELECT 1 FROM `"
|
||||
+ PREFIX
|
||||
+ "players` AS p LEFT JOIN `"
|
||||
+ PREFIX
|
||||
+ "friends` AS f ON f.user=p.user WHERE (p.block_private=0 OR f.friend=?) AND p.user=?";
|
||||
private static final String addFriend_isOnline1 = "SELECT 1 FROM `"
|
||||
+ PREFIX
|
||||
+ "players` AS p LEFT JOIN `"
|
||||
+ PREFIX
|
||||
+ "friends` AS f ON f.friend=p.user WHERE p.block_private=1 AND f.user=? AND p.user=?";
|
||||
private static final String removeFriend = "DELETE FROM `" + PREFIX
|
||||
+ "friends` WHERE `user` LIKE ? AND `friend` LIKE ?";
|
||||
private static final String removeFriend_isOnline = "SELECT 1 FROM `"
|
||||
+ PREFIX + "players` WHERE block_private=1 AND user=?";
|
||||
private static final String addIgnore = "INSERT INTO `" + PREFIX
|
||||
+ "ignores`(`user`, `ignore`) VALUES(?, ?)";
|
||||
private static final String removeIgnore = "DELETE FROM `" + PREFIX
|
||||
+ "ignores` WHERE `user` LIKE ? AND `ignore` LIKE ?";
|
||||
private static final String friendsList0 = "SELECT p.user FROM `"
|
||||
+ PREFIX
|
||||
+ "friends` AS f INNER JOIN `"
|
||||
+ PREFIX
|
||||
+ "players` AS p ON p.user=f.friend WHERE p.block_private=0 AND f.user=?";
|
||||
private static final String friendsList1 = "SELECT user FROM `"
|
||||
+ PREFIX + "friends` WHERE friend=?";
|
||||
private static final String chatBlock = "UPDATE `" + PREFIX
|
||||
+ "players` SET block_chat=? WHERE user=?";
|
||||
private static final String privateBlock = "UPDATE `" + PREFIX
|
||||
+ "players` SET block_private=? WHERE user=?";
|
||||
private static final String privateBlock_online = "SELECT user FROM `"
|
||||
+ PREFIX
|
||||
+ "friends` WHERE friend=? AND user NOT IN (SELECT friend FROM `"
|
||||
+ PREFIX + "friends` WHERE user=?)";
|
||||
private static final String tradeBlock = "UPDATE `" + PREFIX
|
||||
+ "players` SET block_trade=? WHERE user=?";
|
||||
private static final String duelBlock = "UPDATE `pk_players` SET block_duel=? WHERE user=?";
|
||||
private static final String basicInfo = "SELECT banned, owner, group_id FROM `"
|
||||
+ PREFIX + "players` WHERE `user` = ?";
|
||||
private static final String setOnlineFlag = "UPDATE `" + PREFIX
|
||||
+ "players` SET online=1, world=? WHERE user=?";
|
||||
private static final String setBanned = "UPDATE `" + PREFIX
|
||||
+ "players` SET `banned`=? WHERE `user` = ?";
|
||||
private static final String logBan = "INSERT `" + PREFIX
|
||||
+ "banlog` VALUES(?, ?, ?)";
|
||||
private static final String playerData = "SELECT * FROM `" + PREFIX
|
||||
+ "players` WHERE `user`=?";
|
||||
private static final String playerExp = "SELECT * FROM `" + PREFIX
|
||||
+ "experience` WHERE `user`=?";
|
||||
private static final String playerCurExp = "SELECT * FROM `" + PREFIX
|
||||
+ "curstats` WHERE `user`=?";
|
||||
private static final String playerInvItems = "SELECT id,amount,wielded FROM `"
|
||||
+ PREFIX + "invitems` WHERE `user`=? ORDER BY `slot` ASC";
|
||||
private static final String playerBankItems = "SELECT id,amount FROM `"
|
||||
+ PREFIX + "bank` WHERE `user`=? ORDER BY `slot` ASC";
|
||||
private static final String playerFriends = "SELECT friend FROM `"
|
||||
+ PREFIX + "friends` WHERE `user`=?";
|
||||
private static final String playerIngored = "SELECT `ignore` FROM `"
|
||||
+ PREFIX + "ignores` WHERE `user`=?";
|
||||
private static final String playerQuests = "SELECT * FROM `" + PREFIX
|
||||
+ "quests` WHERE `user`=?";
|
||||
private static final String save_DeleteBank = "DELETE FROM `" + PREFIX
|
||||
+ "bank` WHERE `user`=?";
|
||||
private static final String save_AddBank = "INSERT INTO `" + PREFIX
|
||||
+ "bank`(`user`, `id`, `amount`, `slot`) VALUES(?, ?, ?, ?)";
|
||||
private static final String save_DeleteInv = "DELETE FROM `" + PREFIX
|
||||
+ "invitems` WHERE `user`=?";
|
||||
private static final String save_AddInvItem = "INSERT INTO `"
|
||||
+ PREFIX
|
||||
+ "invitems`(`user`, `id`, `amount`, `wielded`, `slot`) VALUES(?, ?, ?, ?, ?)";
|
||||
private static final String save_UpdateBasicInfo = "UPDATE `"
|
||||
+ PREFIX
|
||||
+ "players` SET `combat`=?, skill_total=?, `x`=?, `y`=?, `fatigue`=?, `haircolour`=?, `topcolour`=?, `trousercolour`=?, `skincolour`=?, `headsprite`=?, `bodysprite`=?, `male`=?, `skulled`=?, `combatstyle`=?, `quest_points`=? WHERE `user`=?";
|
||||
private static final String save_DeleteQuests = "DELETE FROM `"
|
||||
+ PREFIX + "quests` WHERE `user`=?";
|
||||
private static final String save_AddQuest = "INSERT INTO `" + PREFIX
|
||||
+ "quests` (`user`, `id`, `stage`) VALUES(?, ?, ?)";
|
||||
private static final String save_SetEventCD = "UPDATE `" + PREFIX
|
||||
+ "players` SET eventcd=? WHERE user=?";
|
||||
private static final String logLogin = "INSERT INTO `pk_logins`(`user`, `time`, `ip`) VALUES(?, ?, ?)";
|
||||
private static final String logIn = "UPDATE `pk_players` SET login_date=?, login_ip=? WHERE user=?";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logLogin(long user, String ip) {
|
||||
PreparedStatement logLogin = null;
|
||||
try {
|
||||
logLogin = conn.prepareStatement(Statements.logLogin);
|
||||
|
||||
logLogin.setLong(1, user);
|
||||
logLogin.setLong(2, System.currentTimeMillis() / 1000);
|
||||
logLogin.setString(3, ip);
|
||||
|
||||
logLogin.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
if (logLogin != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ Statements.logLogin);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logIn(String ip, long user) {
|
||||
PreparedStatement login = null;
|
||||
try {
|
||||
login = conn.prepareStatement(Statements.logIn);
|
||||
|
||||
login.setLong(1, System.currentTimeMillis() / 1000);
|
||||
login.setString(2, ip);
|
||||
login.setLong(3, user);
|
||||
|
||||
login.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
if (login != null)
|
||||
e.printStackTrace();
|
||||
else
|
||||
System.out.println("Failed to create prepared statement: "
|
||||
+ Statements.logIn);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -10,9 +10,12 @@ import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Config {
|
||||
public static String STORAGE_MEDIUM;
|
||||
|
||||
public static int LS_PORT, QUERY_PORT;
|
||||
|
||||
public static String RSCDLS_HOME, CONF_DIR, LOG_DIR, MYSQL_HOST, MYSQL_DB, MYSQL_USER, MYSQL_PASS, LS_IP, QUERY_IP, AUTH_URL;
|
||||
public static String RSCDLS_HOME, CONF_DIR, LOG_DIR, MYSQL_HOST, MYSQL_DB,
|
||||
MYSQL_USER, MYSQL_PASS, LS_IP, QUERY_IP, AUTH_URL;
|
||||
|
||||
public static long START_TIME;
|
||||
|
||||
@ -43,7 +46,10 @@ public class Config {
|
||||
LS_PORT = Integer.parseInt(props.getProperty("lsport"));
|
||||
QUERY_IP = props.getProperty("queryip");
|
||||
QUERY_PORT = Integer.parseInt(props.getProperty("queryport"));
|
||||
AUTH_URL = props.getProperty("authURL", "https://www.moparscape.org/auth.php?field=");
|
||||
AUTH_URL = props.getProperty("authURL",
|
||||
"https://www.moparscape.org/auth.php?field=");
|
||||
STORAGE_MEDIUM = props.getProperty("storage-medium",
|
||||
"org.moparscape.msc.ls.persistence.impl.MySQL");
|
||||
|
||||
props.clear();
|
||||
}
|
||||
@ -61,4 +67,9 @@ public class Config {
|
||||
LOG_DIR = home + File.separator + "logs";
|
||||
RSCDLS_HOME = home;
|
||||
}
|
||||
|
||||
public static final String[] statArray = { "attack", "defense", "strength",
|
||||
"hits", "ranged", "prayer", "magic", "cooking", "woodcut",
|
||||
"fletching", "fishing", "firemaking", "crafting", "smithing",
|
||||
"mining", "herblaw", "agility", "thieving" };
|
||||
}
|
||||
|
21
README
21
README
@ -1 +1,22 @@
|
||||
An emulator for an old java MMORPG.
|
||||
|
||||
Setup
|
||||
======
|
||||
Install the JRE and JDK
|
||||
Install Ant
|
||||
Install Ivy
|
||||
Install MySQL
|
||||
|
||||
Ensure all the paths are set correctly.
|
||||
|
||||
Import Database.sql
|
||||
|
||||
If you have any questions regarding that use Google.
|
||||
|
||||
Go to LoginServer in the terminal/command prompt and type--
|
||||
ant runls
|
||||
|
||||
Go to GameServer in the terminal/command prompy and type--
|
||||
ant run
|
||||
|
||||
You're now ready to start accept connections.
|
||||
|
Loading…
Reference in New Issue
Block a user