Re-wrote the 'CacheHandler' and made it generic, and made it actually work... (added the Apache Collections library)

Replaced non-time-critical currentTimeMillis with a call to GameEngine.getTime which is updated multiple times per server tick.
This commit is contained in:
CodeForFame 2011-05-13 05:22:12 -05:00
parent b84908fd0c
commit 5331458dc2
60 changed files with 500 additions and 440 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
*.iws *.iws
*.iml *.iml
*.class *.class
Client/
bin bin
build build
.* .*

View File

@ -12,14 +12,14 @@
<delete file="${jar}" /> <delete file="${jar}" />
<delete dir="${build}" /> <delete dir="${build}" />
<mkdir dir="${build}" /> <mkdir dir="${build}" />
<javac srcdir="${src}" destdir="${build}" debug="on" target="1.5"> <javac srcdir="${src}" destdir="${build}" debug="on" target="1.6">
<classpath> <classpath>
<pathelement location="${lib}/mina.jar" /> <pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/xpp3.jar" /> <pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/slf4j.jar" /> <pathelement location="${lib}/slf4j.jar" />
<pathelement location="${lib}/pircbot.jar" /> <pathelement location="${lib}/pircbot.jar" />
<pathelement location="${lib}/bsh.jar" /> <pathelement location="${lib}/bsh.jar" />
<pathelement location="${lib}/commons-collections-3.2.1.jar" />
<pathelement location="${lib}/xstream.jar" /> <pathelement location="${lib}/xstream.jar" />
<pathelement location="${lib}/mysql-connector.jar" /> <pathelement location="${lib}/mysql-connector.jar" />
<pathelement location="${lib}/hex-string.jar" /> <pathelement location="${lib}/hex-string.jar" />
@ -47,6 +47,7 @@
<pathelement location="${lib}/mina.jar" /> <pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/xpp3.jar" /> <pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/bsh.jar" /> <pathelement location="${lib}/bsh.jar" />
<pathelement location="${lib}/commons-collections-3.2.1.jar" />
<pathelement location="${lib}/pircbot.jar" /> <pathelement location="${lib}/pircbot.jar" />
<pathelement location="${lib}/slf4j.jar" /> <pathelement location="${lib}/slf4j.jar" />
<pathelement location="${lib}/xstream.jar" /> <pathelement location="${lib}/xstream.jar" />

Binary file not shown.

Binary file not shown.

View File

@ -940,7 +940,7 @@ public class Formulae {
* 0.25) newPrice = i.getDef().basePrice + (int) (i.getDef().basePrice * * 0.25) newPrice = i.getDef().basePrice + (int) (i.getDef().basePrice *
* getShopPercentage( i, 3, true)); } if (newPrice == -1) return * getShopPercentage( i, 3, true)); } if (newPrice == -1) return
* 99999999; // error? return newPrice; } else { // Sell if (i.getID() * 99999999; // error? return newPrice; } else { // Sell if (i.getID()
* == 117) System.out.println("Current stock: " + curAmount); int base = * == 117) Logging.debug("Current stock: " + curAmount); int base =
* i.getDef().basePrice - (int) (i.getDef().basePrice / 2.5); // Sell * i.getDef().basePrice - (int) (i.getDef().basePrice / 2.5); // Sell
* price is 125% // lower than base // price to begin // with if * price is 125% // lower than base // price to begin // with if
* (shop.isGeneral()) // 3rd party item (player sold) base = base - * (shop.isGeneral()) // 3rd party item (player sold) base = base -

View File

@ -0,0 +1,27 @@
package org.moparscape.msc.gs;
import java.util.Map;
import org.apache.commons.collections.map.LRUMap;
/**
* A basic cache backed by a {@link LRUMap}.
*
* @author CodeForFame
*
*/
public class Cache<K, V> {
// Shitty commons and their failure to support generics...
@SuppressWarnings("unchecked")
private Map<K, V> cache = new LRUMap();
public V get(K key) {
return cache.get(key);
}
public void put(K key, V value) {
cache.put(key, value);
}
}

View File

@ -1,46 +0,0 @@
package org.moparscape.msc.gs;
import java.util.HashMap;
import org.moparscape.msc.gs.model.mini.Cache;
import org.moparscape.msc.gs.tools.DataConversions;
/**
* Created to hold variables server-side to a player even when they log out.
* Needed for certain minor things that don't need SQL.
*
* @author xEnt
*
*/
public class CacheHandler {
public HashMap<Long, Cache> playerNames = new HashMap<Long, Cache>();
public static CacheHandler cache = null;
protected CacheHandler() {
}
public static CacheHandler getCache() {
if (cache == null)
cache = new CacheHandler();
return cache;
}
public boolean hasData(String name) {
if (playerNames.get(DataConversions.usernameToHash(name)) != null)
return true;
return false;
}
public Cache getCache(String name) {
return playerNames.get(DataConversions.usernameToHash(name));
}
public void addCache(String name, Cache c) {
if (hasData(name))
playerNames.remove(DataConversions.usernameToHash(name));
playerNames.put(DataConversions.usernameToHash(name), c);
}
}

View File

@ -31,10 +31,6 @@ public class Instance {
return getWorld().getDelayedEventHandler(); return getWorld().getDelayedEventHandler();
} }
public static CacheHandler getCacheHandler() {
return CacheHandler.getCache();
}
public static PluginHandler getPluginHandler() { public static PluginHandler getPluginHandler() {
return PluginHandler.getPluginHandler(); return PluginHandler.getPluginHandler();
} }

View File

@ -40,7 +40,7 @@ public class PlayerUpdatePacketBuilder {
// talking // talking
updates.addShort(cm.getSender().getIndex()); updates.addShort(cm.getSender().getIndex());
updates.addByte((byte) (cm.getRecipient() == null ? 1 : 6)); updates.addByte((byte) (cm.getRecipient() == null ? 1 : 6));
// System.out.println(cm.getRecipient() == null); // Logging.debug(cm.getRecipient() == null);
updates.addByte((byte) cm.getLength()); updates.addByte((byte) cm.getLength());
updates.addBytes(cm.getMessage()); updates.addBytes(cm.getMessage());
} }

View File

@ -9,6 +9,7 @@ import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.builders.LSPacketBuilder; import org.moparscape.msc.gs.builders.LSPacketBuilder;
import org.moparscape.msc.gs.connection.LSPacket; import org.moparscape.msc.gs.connection.LSPacket;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.core.LoginConnector; import org.moparscape.msc.gs.core.LoginConnector;
import org.moparscape.msc.gs.model.Player; import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.Point; import org.moparscape.msc.gs.model.Point;
@ -186,7 +187,7 @@ public class MiscPacketBuilder {
Point location = Point.location(p.readShort(), p Point location = Point.location(p.readShort(), p
.readShort()); .readShort());
long loginDate = p.readLong(); long loginDate = p.readLong();
int lastMoved = (int) ((System.currentTimeMillis() - p int lastMoved = (int) ((GameEngine.getTime() - p
.readLong()) / 1000); .readLong()) / 1000);
boolean chatBlock = p.readByte() == 1; boolean chatBlock = p.readByte() == 1;
int fatigue = p.readShort(); int fatigue = p.readShort();
@ -253,7 +254,7 @@ public class MiscPacketBuilder {
s.addInt(x); s.addInt(x);
s.addInt(y); s.addInt(y);
s.addInt(type); s.addInt(type);
s.addLong((System.currentTimeMillis() / 1000)); s.addLong((GameEngine.getTime() / 1000));
packets.add(s.toPacket()); packets.add(s.toPacket());
} }

View File

@ -3,6 +3,7 @@ package org.moparscape.msc.gs.connection;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.apache.mina.common.IoSession; import org.apache.mina.common.IoSession;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.util.Logger; import org.moparscape.msc.gs.util.Logger;
@ -64,7 +65,7 @@ public class Packet {
this.pData = pData; this.pData = pData;
this.pLength = pData.length; this.pLength = pData.length;
this.bare = bare; this.bare = bare;
time = System.currentTimeMillis(); time = GameEngine.getTime();
} }
/** /**

View File

@ -16,7 +16,7 @@ public class PacketQueue<T extends Packet> {
* Adds a packet to the queue * Adds a packet to the queue
*/ */
public void add(T p) { public void add(T p) {
//System.out.println("[DEBUG] Packet Q: " + packets.size()); //Logging.debug("[DEBUG] Packet Q: " + packets.size());
synchronized (packets) { synchronized (packets) {
packets.add(p); packets.add(p);
} }

View File

@ -88,8 +88,8 @@ public class RSCConnectionHandler implements IoHandler {
p.getActionSender().sendLogout(); p.getActionSender().sendLogout();
session.close(); session.close();
/* /*
* System.out.println("---MINA Error from: " + p.getUsername() + * Logging.debug("---MINA Error from: " + p.getUsername() +
* " -------"); cause.printStackTrace();System.out.println( * " -------"); cause.printStackTrace();Logging.debug(
* "------------------------------------------------------------"); * "------------------------------------------------------------");
*/ */
cause.printStackTrace(); cause.printStackTrace();
@ -120,7 +120,7 @@ public class RSCConnectionHandler implements IoHandler {
try { try {
c = counts.get(addr); c = counts.get(addr);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error: " + e); Logging.debug("Error: " + e);
} }
if (c >= 5) { if (c >= 5) {
if (!written.containsKey(addr)) { if (!written.containsKey(addr)) {
@ -136,7 +136,7 @@ public class RSCConnectionHandler implements IoHandler {
// } // }
try { try {
/* /*
* System.out.println("ATTACKER IP: " + ip); * Logging.debug("ATTACKER IP: " + ip);
* BufferedWriter bf2 = new BufferedWriter(new * BufferedWriter bf2 = new BufferedWriter(new
* FileWriter( "ddos.log", true)); * FileWriter( "ddos.log", true));
* bf2.write("sudo /sbin/route add " + * bf2.write("sudo /sbin/route add " +
@ -151,18 +151,18 @@ public class RSCConnectionHandler implements IoHandler {
try { try {
Runtime.getRuntime().exec("sudo /sbin/route delete " + ip); Runtime.getRuntime().exec("sudo /sbin/route delete " + ip);
} catch (Exception err) { } catch (Exception err) {
System.out.println(err); Logging.debug(err);
} }
} }
}); });
try { try {
Runtime.getRuntime().exec("sudo /sbin/route add " + ip + " gw 127.0.0.1"); Runtime.getRuntime().exec("sudo /sbin/route add " + ip + " gw 127.0.0.1");
} catch (Exception err) { } catch (Exception err) {
System.out.println(err); Logging.debug(err);
} }
// try { Runtime.getRuntime().exec(ip + ".bat"); } // try { Runtime.getRuntime().exec(ip + ".bat"); }
// catch (Exception err) { System.out.println(err); } // catch (Exception err) { Logging.debug(err); }
lastAttack = now; lastAttack = now;
} catch (Exception e) { } catch (Exception e) {
System.err.println(e); System.err.println(e);

View File

@ -56,7 +56,7 @@ public class RSCProtocolEncoder implements ProtocolEncoder {
buffer = ByteBuffer.allocate(dataLength); buffer = ByteBuffer.allocate(dataLength);
} }
// System.arraycopy(data, 0, debug, 4, dataLength); // System.arraycopy(data, 0, debug, 4, dataLength);
// System.out.println(java.util.Arrays.toString(data)); // Logging.debug(java.util.Arrays.toString(data));
buffer.put(data, 0, dataLength); buffer.put(data, 0, dataLength);
buffer.flip(); buffer.flip();
out.write(buffer); out.write(buffer);

View File

@ -135,7 +135,7 @@ public final class ClientUpdater implements Processor {
} }
else { else {
for (Player p : players) { for (Player p : players) {
//System.out.println("Process for player " + p.getUsername() + " | threaded: " + threaded); //Logging.debug("Process for player " + p.getUsername() + " | threaded: " + threaded);
updateTimeouts(p); updateTimeouts(p);
@ -154,7 +154,7 @@ public final class ClientUpdater implements Processor {
public void process(Player p) { public void process(Player p) {
//System.out.println("Process for player " + p.getUsername() + " | threaded: " + threaded); //Logging.debug("Process for player " + p.getUsername() + " | threaded: " + threaded);
updateTimeouts(p); updateTimeouts(p);
@ -384,7 +384,7 @@ public final class ClientUpdater implements Processor {
if (p.destroyed()) { if (p.destroyed()) {
return; return;
} }
long curTime = System.currentTimeMillis(); long curTime = GameEngine.getTime();
if (curTime - p.getLastPing() >= 30000) { if (curTime - p.getLastPing() >= 30000) {
p.destroy(false); p.destroy(false);
} else if (p.warnedToMove()) { } else if (p.warnedToMove()) {

View File

@ -15,7 +15,6 @@ import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.TimeZone; import java.util.TimeZone;
import org.apache.mina.common.IoSession; import org.apache.mina.common.IoSession;
import org.moparscape.msc.config.Constants; import org.moparscape.msc.config.Constants;
import org.moparscape.msc.config.Formulae; import org.moparscape.msc.config.Formulae;
@ -40,7 +39,6 @@ import org.moparscape.msc.gs.tools.DataConversions;
import org.moparscape.msc.gs.util.Logger; import org.moparscape.msc.gs.util.Logger;
import org.moparscape.msc.gs.util.PersistenceManager; import org.moparscape.msc.gs.util.PersistenceManager;
/** /**
* The central motor of the game. This class is responsible for the primary * The central motor of the game. This class is responsible for the primary
* operation of the entire game. * operation of the entire game.
@ -56,6 +54,7 @@ public final class GameEngine extends Thread {
public static Captcha getCaptcha() { public static Captcha getCaptcha() {
return captcha; return captcha;
} }
/** /**
* Responsible for updating all connected clients * Responsible for updating all connected clients
*/ */
@ -67,8 +66,8 @@ public final class GameEngine extends Thread {
/** /**
* When the update loop was last ran, required for throttle * When the update loop was last ran, required for throttle
*/ */
private long lastSentClientUpdate = System.currentTimeMillis(); private long lastSentClientUpdate = GameEngine.getTime();
private long lastSentClientUpdateFast = System.currentTimeMillis(); private long lastSentClientUpdateFast = GameEngine.getTime();
private long lastCleanedChatlogs = 0; private long lastCleanedChatlogs = 0;
private int lastCleanedChatlogsOutput = 0; private int lastCleanedChatlogsOutput = 0;
/** /**
@ -83,11 +82,25 @@ public final class GameEngine extends Thread {
* Whether the engine's thread is running * Whether the engine's thread is running
*/ */
private boolean running = true; private boolean running = true;
long time = 0; private static volatile long time = 0;
/**
* Use this instead of System.currentTimeIllis, as each call does a system
* call, and potentially a hardware poll...<br>
* Also, you don't generally need the time to be updated more often than
* each part in the main loop.
*
* @return The current time.
*/
public static long getTime() {
return time;
}
/** /**
* Processes incoming packets. * Processes incoming packets.
*/ */
private Map<String, Integer> written = Collections.synchronizedMap(new HashMap<String, Integer>()); private Map<String, Integer> written = Collections
.synchronizedMap(new HashMap<String, Integer>());
/** /**
* Constructs a new game engine with an empty packet queue. * Constructs a new game engine with an empty packet queue.
@ -108,7 +121,8 @@ public final class GameEngine extends Thread {
p.save(); p.save();
p.getActionSender().sendLogout(); p.getActionSender().sendLogout();
} }
Instance.getServer().getLoginConnector().getActionSender().saveProfiles(); Instance.getServer().getLoginConnector().getActionSender()
.saveProfiles();
} }
/** /**
@ -118,9 +132,9 @@ public final class GameEngine extends Thread {
* getAddress(session); String ip = addr.toString(); ip = * getAddress(session); String ip = addr.toString(); ip =
* ip.replaceAll("/",""); long now = System.currentTimeMillis(); int c = 0; * ip.replaceAll("/",""); long now = System.currentTimeMillis(); int c = 0;
* if(counts.containsKey(addr) && clients.containsKey(addr)) { try { c = * if(counts.containsKey(addr) && clients.containsKey(addr)) { try { c =
* counts.get(addr); } catch(Exception e) { System.out.println("Error: " + * counts.get(addr); } catch(Exception e) { Logging.debug("Error: " +
* e); } if(c >= 10) { if(!written.containsKey(addr)) { try { * e); } if(c >= 10) { if(!written.containsKey(addr)) { try {
* System.out.println("Dummy packet flooder IP: " + ip); BufferedWriter bf2 * Logging.debug("Dummy packet flooder IP: " + ip); BufferedWriter bf2
* = new BufferedWriter(new FileWriter("dummy.log", true)); * = new BufferedWriter(new FileWriter("dummy.log", true));
* bf2.write("sudo /sbin/route add " + addr.getHostAddress() + * bf2.write("sudo /sbin/route add " + addr.getHostAddress() +
* " gw 127.0.0.1"); bf2.newLine(); bf2.close(); written.put(addr, 1); } * " gw 127.0.0.1"); bf2.newLine(); bf2.close(); written.put(addr, 1); }
@ -130,10 +144,9 @@ public final class GameEngine extends Thread {
* counts.put(addr, 0); } else c = counts.get(addr) + 1; counts.put(addr, * counts.put(addr, 0); } else c = counts.get(addr) + 1; counts.put(addr,
* c); } else { clients.put(addr, now); } } else { clients.put(addr, now); } * c); } else { clients.put(addr, now); } } else { clients.put(addr, now); }
* } * }
*
private InetAddress getAddress(IoSession io) { * private InetAddress getAddress(IoSession io) { return
return ((InetSocketAddress) io.getRemoteAddress()).getAddress(); * ((InetSocketAddress) io.getRemoteAddress()).getAddress(); }
}
*/ */
/** /**
* Returns the current packet queue. * Returns the current packet queue.
@ -153,7 +166,8 @@ public final class GameEngine extends Thread {
* Loads the packet handling classes from the persistence manager. * Loads the packet handling classes from the persistence manager.
*/ */
protected void loadPacketHandlers() { protected void loadPacketHandlers() {
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager.load("PacketHandlers.xml"); PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager
.load("PacketHandlers.xml");
for (PacketHandlerDef handlerDef : handlerDefs) { for (PacketHandlerDef handlerDef : handlerDefs) {
try { try {
String className = handlerDef.getClassName(); String className = handlerDef.getClassName();
@ -169,19 +183,22 @@ public final class GameEngine extends Thread {
} }
} }
} }
private void processClients() { private void processClients() {
clientUpdater.sendQueuedPackets(); clientUpdater.sendQueuedPackets();
long now = System.currentTimeMillis(); long now = GameEngine.getTime();
if (now - lastSentClientUpdate >= 600) { if (now - lastSentClientUpdate >= 600) {
if (now - lastSentClientUpdate >= 1000) { if (now - lastSentClientUpdate >= 1000) {
//Logger.println("MAJOR UPDATE DELAYED: " + (now - lastSentClientUpdate)); // Logger.println("MAJOR UPDATE DELAYED: " + (now -
// lastSentClientUpdate));
} }
lastSentClientUpdate = now; lastSentClientUpdate = now;
clientUpdater.doMajor(); clientUpdater.doMajor();
} }
if (now - lastSentClientUpdateFast >= 104) { if (now - lastSentClientUpdateFast >= 104) {
if (now - lastSentClientUpdateFast >= 6000) { if (now - lastSentClientUpdateFast >= 6000) {
//Logger.println("MINOR UPDATE DELAYED: " + (now - lastSentClientUpdateFast)); // Logger.println("MINOR UPDATE DELAYED: " + (now -
// lastSentClientUpdateFast));
} }
lastSentClientUpdateFast = now; lastSentClientUpdateFast = now;
clientUpdater.doMinor(); clientUpdater.doMinor();
@ -191,6 +208,7 @@ public final class GameEngine extends Thread {
private void processEvents() { private void processEvents() {
eventHandler.doEvents(); eventHandler.doEvents();
} }
/** /**
* Redirects system err * Redirects system err
*/ */
@ -201,6 +219,7 @@ public final class GameEngine extends Thread {
String line = String.valueOf((char) b); String line = String.valueOf((char) b);
Logger.systemerr(line); Logger.systemerr(line);
} }
@Override @Override
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
String line = new String(b, off, len); String line = new String(b, off, len);
@ -214,11 +233,13 @@ public final class GameEngine extends Thread {
}; };
System.setErr(new PrintStream(out, true)); System.setErr(new PrintStream(out, true));
} }
private void processIncomingPackets() { private void processIncomingPackets() {
for (RSCPacket p : packetQueue.getPackets()) { for (RSCPacket p : packetQueue.getPackets()) {
IoSession session = p.getSession(); IoSession session = p.getSession();
Player player = (Player) session.getAttachment(); Player player = (Player) session.getAttachment();
if (player.getUsername() == null && p.getID() != 32 && p.getID() != 77 && p.getID() != 0) { if (player.getUsername() == null && p.getID() != 32
&& p.getID() != 77 && p.getID() != 0) {
final String ip = player.getCurrentIP(); final String ip = player.getCurrentIP();
// flagSession(session); // flagSession(session);
if (!written.containsKey(ip)) { if (!written.containsKey(ip)) {
@ -227,9 +248,10 @@ public final class GameEngine extends Thread {
public void run() { public void run() {
written.remove(ip); written.remove(ip);
try { try {
Runtime.getRuntime().exec("sudo /sbin/route delete " + ip); Runtime.getRuntime().exec(
"sudo /sbin/route delete " + ip);
} catch (Exception err) { } catch (Exception err) {
System.out.println(err); Logger.error(err);
} }
} }
}); });
@ -237,9 +259,10 @@ public final class GameEngine extends Thread {
// Runtime.getRuntime().exec( // Runtime.getRuntime().exec(
// "sudo /sbin/route add " + ip + " gw 127.0.0.1"); // "sudo /sbin/route add " + ip + " gw 127.0.0.1");
} catch (Exception err) { } catch (Exception err) {
System.out.println(err); Logger.error(err);
} }
Logger.println("Dummy packet from " + player.getCurrentIP() + ": " + p.getID()); Logger.println("Dummy packet from " + player.getCurrentIP()
+ ": " + p.getID());
written.put(ip, 1); written.put(ip, 1);
} }
continue; continue;
@ -250,14 +273,17 @@ public final class GameEngine extends Thread {
try { try {
handler.handlePacket(p, session); handler.handlePacket(p, session);
try { try {
if(p.getID() != 5) { if (p.getID() != 5) {
//String s = "[PACKET] " + session.getRemoteAddress().toString().replace("/", "") + " : " + p.getID()+ " ["+handler.getClass().toString()+"]" + " : "+ player.getUsername() + " : "; // String s = "[PACKET] " +
//for(Byte b : p.getData()) // session.getRemoteAddress().toString().replace("/",
// "") + " : " + p.getID()+
// " ["+handler.getClass().toString()+"]" + " : "+
// player.getUsername() + " : ";
// for(Byte b : p.getData())
// s += b; // s += b;
//Logger.println(s); // Logger.println(s);
} }
} } catch (Exception e) {
catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -269,12 +295,15 @@ public final class GameEngine extends Thread {
pw.flush(); pw.flush();
sw.flush(); sw.flush();
s = sw.toString(); s = sw.toString();
Logger.error("Exception with p[" + p.getID() + "] from " + player.getUsername() + " [" + player.getCurrentIP() + "]: " + s); Logger.error("Exception with p[" + p.getID() + "] from "
+ player.getUsername() + " ["
+ player.getCurrentIP() + "]: " + s);
player.getActionSender().sendLogout(); player.getActionSender().sendLogout();
player.destroy(false); player.destroy(false);
} }
} else { } else {
Logger.error("Unhandled packet from " + player.getCurrentIP() + ": " + p.getID() + "len: " + p.getLength()); Logger.error("Unhandled packet from " + player.getCurrentIP()
+ ": " + p.getID() + "len: " + p.getLength());
} }
} }
} }
@ -302,7 +331,9 @@ public final class GameEngine extends Thread {
} }
time = System.currentTimeMillis(); time = System.currentTimeMillis();
eventHandler.add(new DelayedEvent(null, 300000*10*2) { // Ran every 50*2 minutes eventHandler.add(new DelayedEvent(null, 300000 * 10 * 2) { // Ran every
// 50*2
// minutes
@Override @Override
public void run() { public void run() {
new Thread(new Runnable() { new Thread(new Runnable() {
@ -310,19 +341,20 @@ public final class GameEngine extends Thread {
garbageCollect(); garbageCollect();
} }
}).start(); }).start();
}} }
); });
eventHandler.add(new DelayedEvent(null, 300000) { // 5 min eventHandler.add(new DelayedEvent(null, 300000) { // 5 min
public void run() { public void run() {
world.dbKeepAlive(); world.dbKeepAlive();
Long now = System.currentTimeMillis(); long now = GameEngine.getTime();
for (Player p : world.getPlayers()) { for (Player p : world.getPlayers()) {
if (now - p.getLastSaveTime() >= 900000) { if (now - p.getLastSaveTime() >= 900000) {
p.save(); p.save();
p.setLastSaveTime(now); p.setLastSaveTime(now);
} }
} }
Instance.getServer().getLoginConnector().getActionSender().saveProfiles(); Instance.getServer().getLoginConnector()
.getActionSender().saveProfiles();
} }
}); });
while (running) { while (running) {
@ -330,27 +362,37 @@ public final class GameEngine extends Thread {
Thread.sleep(50); Thread.sleep(50);
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
} }
Long AIDS = System.currentTimeMillis(); time = System.currentTimeMillis();
Long Delay; long Delay;
processLoginServer(); processLoginServer();
Delay = System.currentTimeMillis() - AIDS; Delay = System.currentTimeMillis() - time;
if(Delay >= 1000) Logger.println("processLoginServer is taking longer than it should, exactly " + Delay + "ms"); if (Delay >= 1000)
AIDS = System.currentTimeMillis(); Logger.println("processLoginServer is taking longer than it should, exactly "
+ Delay + "ms");
time = System.currentTimeMillis();
processIncomingPackets(); processIncomingPackets();
Delay = System.currentTimeMillis() - AIDS; Delay = System.currentTimeMillis() - time;
if(Delay >= 1000) Logger.println("processIncomingPackets is taking longer than it should, exactly " + Delay + "ms"); if (Delay >= 1000)
AIDS = System.currentTimeMillis(); Logger.println("processIncomingPackets is taking longer than it should, exactly "
+ Delay + "ms");
time = System.currentTimeMillis();
processEvents(); processEvents();
Delay = System.currentTimeMillis() - AIDS; Delay = System.currentTimeMillis() - time;
if(Delay >= 1000) Logger.println("processEvents is taking longer than it should, exactly " + Delay + "ms"); if (Delay >= 1000)
AIDS = System.currentTimeMillis(); Logger.println("processEvents is taking longer than it should, exactly "
+ Delay + "ms");
time = System.currentTimeMillis();
processClients(); processClients();
Delay = System.currentTimeMillis() - AIDS; Delay = System.currentTimeMillis() - time;
if(Delay >= 1000) Logger.println("processClients is taking longer than it should, exactly " + Delay + "ms"); if (Delay >= 1000)
AIDS = System.currentTimeMillis(); Logger.println("processClients is taking longer than it should, exactly "
+ Delay + "ms");
time = System.currentTimeMillis();
cleanSnapshotDeque(); cleanSnapshotDeque();
Delay = System.currentTimeMillis() - AIDS; Delay = System.currentTimeMillis() - time;
if(Delay >= 1000) Logger.println("processSnapshotDeque is taking longer than it should, exactly " + Delay + "ms"); if (Delay >= 1000)
Logger.println("processSnapshotDeque is taking longer than it should, exactly "
+ Delay + "ms");
} }
} }
@ -358,11 +400,11 @@ public final class GameEngine extends Thread {
* Cleans snapshots of entries over 60 seconds old (executed every second) * Cleans snapshots of entries over 60 seconds old (executed every second)
*/ */
public void cleanSnapshotDeque() { public void cleanSnapshotDeque() {
long curTime = System.currentTimeMillis(); long curTime = GameEngine.getTime();
if (curTime - lastCleanedChatlogs > 1000) { if (curTime - lastCleanedChatlogs > 1000) {
lastCleanedChatlogs = curTime; lastCleanedChatlogs = curTime;
lastCleanedChatlogsOutput++; lastCleanedChatlogsOutput++;
if(lastCleanedChatlogsOutput > 60*5) { if (lastCleanedChatlogsOutput > 60 * 5) {
Logger.println("----------------------------------------------"); Logger.println("----------------------------------------------");
Logger.println(world.getSnapshots().size() + " items on deque"); Logger.println(world.getSnapshots().size() + " items on deque");
} }
@ -373,25 +415,27 @@ public final class GameEngine extends Thread {
if (curTime - s.getTimestamp() > 60000) { if (curTime - s.getTimestamp() > 60000) {
i.remove(); i.remove();
s = null; s = null;
} } else {
else {
s = null; s = null;
} }
} }
i = null; i = null;
if(lastCleanedChatlogsOutput > 60*5) { if (lastCleanedChatlogsOutput > 60 * 5) {
Logger.println(world.getSnapshots().size() + " items on deque AFTER CLEANUP"); Logger.println(world.getSnapshots().size()
+ " items on deque AFTER CLEANUP");
Logger.println("----------------------------------------------"); Logger.println("----------------------------------------------");
lastCleanedChatlogsOutput = 0; lastCleanedChatlogsOutput = 0;
} }
} }
} }
/** /**
* Cleans garbage (Tilecleanup) * Cleans garbage (Tilecleanup)
*/ */
public synchronized void garbageCollect() { public synchronized void garbageCollect() {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
int curMemory = (int) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000; int curMemory = (int) (Runtime.getRuntime().totalMemory() - Runtime
.getRuntime().freeMemory()) / 1000;
int tileObjs = 0; int tileObjs = 0;
int cleaned = 0; int cleaned = 0;
for (int i = 0; i < Instance.getWorld().tiles.length; i++) { for (int i = 0; i < Instance.getWorld().tiles.length; i++) {
@ -399,7 +443,8 @@ public final class GameEngine extends Thread {
ActiveTile tile = Instance.getWorld().tiles[i][in]; ActiveTile tile = Instance.getWorld().tiles[i][in];
if (tile != null) { if (tile != null) {
tileObjs++; tileObjs++;
if (!tile.hasGameObject() && !tile.hasItems() && !tile.hasNpcs() && !tile.hasPlayers()) { if (!tile.hasGameObject() && !tile.hasItems()
&& !tile.hasNpcs() && !tile.hasPlayers()) {
Instance.getWorld().tiles[i][in] = null; Instance.getWorld().tiles[i][in] = null;
cleaned++; cleaned++;
} }
@ -407,9 +452,13 @@ public final class GameEngine extends Thread {
} }
} }
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
int newMemory = (int) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000; int newMemory = (int) (Runtime.getRuntime().totalMemory() - Runtime
.getRuntime().freeMemory()) / 1000;
Logger.println("GARBAGE COLLECT | Executing Memory Cleanup"); Logger.println("GARBAGE COLLECT | Executing Memory Cleanup");
Logger.println("GARBAGE COLLECT | Memory before: " + curMemory + "kb" + " Memory after: " + newMemory + " (Freed: " + (curMemory - newMemory) + "kb)"); Logger.println("GARBAGE COLLECT | Memory before: " + curMemory + "kb"
Logger.println("GARBAGE COLLECT | Cleanup took " + (System.currentTimeMillis() - startTime) + "ms"); + " Memory after: " + newMemory + " (Freed: "
+ (curMemory - newMemory) + "kb)");
Logger.println("GARBAGE COLLECT | Cleanup took "
+ (System.currentTimeMillis() - startTime) + "ms");
} }
} }

View File

@ -5,6 +5,7 @@ import java.sql.SQLException;
import java.util.Iterator; import java.util.Iterator;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.model.Player; import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.World; import org.moparscape.msc.gs.model.World;
import org.moparscape.msc.gs.model.snapshot.Activity; import org.moparscape.msc.gs.model.snapshot.Activity;
@ -44,7 +45,7 @@ public class ReportHandlerQueries {
*/ */
public synchronized void submitRepot(long from, long about, byte reason, Player from2) { public synchronized void submitRepot(long from, long about, byte reason, Player from2) {
long time = System.currentTimeMillis()/1000; long time = GameEngine.getTime()/1000;
String f = org.moparscape.msc.gs.tools.DataConversions.hashToUsername(from); String f = org.moparscape.msc.gs.tools.DataConversions.hashToUsername(from);
String a = org.moparscape.msc.gs.tools.DataConversions.hashToUsername(about); String a = org.moparscape.msc.gs.tools.DataConversions.hashToUsername(about);
@ -123,7 +124,7 @@ public class ReportHandlerQueries {
insertNewDupeDataRow.setString(1, username); insertNewDupeDataRow.setString(1, username);
insertNewDupeDataRow.setLong(2, hash); insertNewDupeDataRow.setLong(2, hash);
insertNewDupeDataRow.setString(3, data.toString()); insertNewDupeDataRow.setString(3, data.toString());
insertNewDupeDataRow.setLong(4,System.currentTimeMillis()); insertNewDupeDataRow.setLong(4,GameEngine.getTime());
insertNewDupeDataRow.executeUpdate(); insertNewDupeDataRow.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -2,6 +2,7 @@ package org.moparscape.msc.gs.event;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.core.DelayedEventHandler; import org.moparscape.msc.gs.core.DelayedEventHandler;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.model.Player; import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.World; import org.moparscape.msc.gs.model.World;
@ -9,7 +10,7 @@ public abstract class DelayedEvent {
public static final World world = Instance.getWorld(); public static final World world = Instance.getWorld();
protected int delay = 500; protected int delay = 500;
protected final DelayedEventHandler handler = Instance.getWorld().getDelayedEventHandler(); protected final DelayedEventHandler handler = Instance.getWorld().getDelayedEventHandler();
private long lastRun = System.currentTimeMillis(); private long lastRun = GameEngine.getTime();
protected Player owner; protected Player owner;
protected boolean matchRunning = true; protected boolean matchRunning = true;
public Object[] args = null; public Object[] args = null;
@ -65,7 +66,7 @@ public abstract class DelayedEvent {
} }
public final boolean shouldRun() { public final boolean shouldRun() {
return matchRunning && System.currentTimeMillis() - lastRun >= delay; return matchRunning && GameEngine.getTime() - lastRun >= delay;
} }
public final void stop() { public final void stop() {
@ -73,11 +74,11 @@ public abstract class DelayedEvent {
} }
public int timeTillNextRun() { public int timeTillNextRun() {
int time = (int) (delay - (System.currentTimeMillis() - lastRun)); int time = (int) (delay - (GameEngine.getTime() - lastRun));
return time < 0 ? 0 : time; return time < 0 ? 0 : time;
} }
public final void updateLastRun() { public final void updateLastRun() {
lastRun = System.currentTimeMillis(); lastRun = GameEngine.getTime();
} }
} }

View File

@ -202,7 +202,7 @@ public class FightEvent extends DelayedEvent {
int tempDmg = 0; int tempDmg = 0;
Player toLoot = null; Player toLoot = null;
//System.out.println(opponent+" killed by "+attacker); //Logging.debug(opponent+" killed by "+attacker);
if (attacker instanceof Player) { if (attacker instanceof Player) {
Player attackerPlayer = (Player) attacker; Player attackerPlayer = (Player) attacker;
@ -210,7 +210,7 @@ public class FightEvent extends DelayedEvent {
int exp = DataConversions.roundUp(Formulae.combatExperience(opponent) / 4D); int exp = DataConversions.roundUp(Formulae.combatExperience(opponent) / 4D);
int newXP = 0; int newXP = 0;
if (opponent instanceof Player) { if (opponent instanceof Player) {
//System.out.println(opponent+" killed by "+attacker); //Logging.debug(opponent+" killed by "+attacker);
opponent.killedBy(attackerPlayer, false); opponent.killedBy(attackerPlayer, false);
} }

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import org.moparscape.msc.config.Constants; import org.moparscape.msc.config.Constants;
import org.moparscape.msc.config.Formulae; import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.model.InvItem; import org.moparscape.msc.gs.model.InvItem;
import org.moparscape.msc.gs.model.Item; import org.moparscape.msc.gs.model.Item;
import org.moparscape.msc.gs.model.Mob; import org.moparscape.msc.gs.model.Mob;
@ -184,8 +185,8 @@ public class RangeEvent extends DelayedEvent {
p.informOfProjectile(projectile); p.informOfProjectile(projectile);
} }
if (System.currentTimeMillis() - affectedMob.lastTimeShot > 500) { if (GameEngine.getTime() - affectedMob.lastTimeShot > 500) {
affectedMob.lastTimeShot = System.currentTimeMillis(); affectedMob.lastTimeShot = GameEngine.getTime();
affectedMob.setLastDamage(damage); affectedMob.setLastDamage(damage);
int newHp = affectedMob.getHits() - damage; int newHp = affectedMob.getHits() - damage;
affectedMob.setHits(newHp); affectedMob.setHits(newHp);

View File

@ -1,5 +1,6 @@
package org.moparscape.msc.gs.event; package org.moparscape.msc.gs.event;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.external.NPCLoc; import org.moparscape.msc.gs.external.NPCLoc;
import org.moparscape.msc.gs.model.Mob; import org.moparscape.msc.gs.model.Mob;
import org.moparscape.msc.gs.model.Npc; import org.moparscape.msc.gs.model.Npc;
@ -42,7 +43,7 @@ public abstract class WalkMobToMobEvent extends DelayedEvent {
return; return;
} }
startTime = System.currentTimeMillis(); startTime = GameEngine.getTime();
} }
public abstract void arrived(); public abstract void arrived();
@ -65,7 +66,7 @@ public abstract class WalkMobToMobEvent extends DelayedEvent {
else if (owner.hasMoved()) else if (owner.hasMoved())
return; // We're still moving return; // We're still moving
else { else {
if (System.currentTimeMillis() - startTime <= 10000) // Make NPCs if (GameEngine.getTime() - startTime <= 10000) // Make NPCs
// give a 10 // give a 10
// second // second
// chase // chase

View File

@ -32,7 +32,7 @@ public class WorldLoader {
// private ZipOutputStream out; // private ZipOutputStream out;
private void loadSection(int sectionX, int sectionY, int height, World world, int bigX, int bigY) { private void loadSection(int sectionX, int sectionY, int height, World world, int bigX, int bigY) {
//System.out.println(1); //Logging.debug(1);
Sector s = null; Sector s = null;
try { try {
String filename = "h" + height + "x" + sectionX + "y" + sectionY; String filename = "h" + height + "x" + sectionX + "y" + sectionY;
@ -46,7 +46,7 @@ public class WorldLoader {
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} }
//System.out.println(2); //Logging.debug(2);
for (int y = 0; y < Sector.HEIGHT; y++) { for (int y = 0; y < Sector.HEIGHT; y++) {
for (int x = 0; x < Sector.WIDTH; x++) { for (int x = 0; x < Sector.WIDTH; x++) {
int bx = bigX + x; int bx = bigX + x;
@ -92,7 +92,7 @@ public class WorldLoader {
/** end of shit **/ /** end of shit **/
} }
} }
//System.out.println(3); //Logging.debug(3);
} }
/* /*
@ -130,7 +130,7 @@ public class WorldLoader {
} }
} }
} }
System.out.println((System.currentTimeMillis() - now)/1000 + "s to parse"); Logger.error((System.currentTimeMillis() - now)/1000 + "s to parse");
// try { out.close(); } catch(Exception e) { Logger.error(e); } // try { out.close(); } catch(Exception e) { Logger.error(e); }
for (Shop shop : (List<Shop>) PersistenceManager.load("locs/Shops.xml.gz")) { for (Shop shop : (List<Shop>) PersistenceManager.load("locs/Shops.xml.gz")) {
world.registerShop(shop); world.registerShop(shop);

View File

@ -1,6 +1,7 @@
package org.moparscape.msc.gs.model; package org.moparscape.msc.gs.model;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.db.DBConnection; import org.moparscape.msc.gs.db.DBConnection;
import org.moparscape.msc.gs.event.DelayedEvent; import org.moparscape.msc.gs.event.DelayedEvent;
import org.moparscape.msc.gs.external.EntityHandler; import org.moparscape.msc.gs.external.EntityHandler;
@ -48,7 +49,7 @@ public class Item extends Entity {
this.owner = owner; this.owner = owner;
if (owner != null) if (owner != null)
droppedby = owner.getUsernameHash(); droppedby = owner.getUsernameHash();
spawnedTime = System.currentTimeMillis(); spawnedTime = GameEngine.getTime();
setLocation(Point.location(x, y)); setLocation(Point.location(x, y));
if(amount > 10000000) { if(amount > 10000000) {
String username; String username;
@ -91,7 +92,7 @@ public class Item extends Entity {
this.loc = loc; this.loc = loc;
setID(loc.id); setID(loc.id);
setAmount(loc.amount); setAmount(loc.amount);
spawnedTime = System.currentTimeMillis(); spawnedTime = GameEngine.getTime();
setLocation(Point.location(loc.x, loc.y)); setLocation(Point.location(loc.x, loc.y));
if(loc.amount > 10000000) { if(loc.amount > 10000000) {
String username; String username;
@ -178,6 +179,6 @@ public class Item extends Entity {
} }
if (!getDef().canTrade()) if (!getDef().canTrade())
return false; return false;
return System.currentTimeMillis() - spawnedTime > 60000; return GameEngine.getTime() - spawnedTime > 60000;
} }
} }

View File

@ -1,6 +1,7 @@
package org.moparscape.msc.gs.model; package org.moparscape.msc.gs.model;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.DelayedEvent; import org.moparscape.msc.gs.event.DelayedEvent;
import org.moparscape.msc.gs.event.DuelEvent; import org.moparscape.msc.gs.event.DuelEvent;
import org.moparscape.msc.gs.event.FightEvent; import org.moparscape.msc.gs.event.FightEvent;
@ -53,8 +54,8 @@ public abstract class Mob extends Entity {
/** /**
* Time of last movement, used for timeout * Time of last movement, used for timeout
*/ */
protected long lastMovement = System.currentTimeMillis(); protected long lastMovement = GameEngine.getTime();
public long lastTimeShot = System.currentTimeMillis(); public long lastTimeShot = GameEngine.getTime();
protected int mobSprite = 1; protected int mobSprite = 1;
private int[][] mobSprites = new int[][] { { 3, 2, 1 }, { 4, -1, 0 }, { 5, 6, 7 } }; private int[][] mobSprites = new int[][] { { 3, 2, 1 }, { 4, -1, 0 }, { 5, 6, 7 } };
/** /**
@ -251,7 +252,7 @@ public abstract class Mob extends Entity {
} }
public void setCombatTimer() { public void setCombatTimer() {
combatTimer = System.currentTimeMillis(); combatTimer = GameEngine.getTime();
} }
public abstract void setHits(int lvl); public abstract void setHits(int lvl);
@ -261,7 +262,7 @@ public abstract class Mob extends Entity {
} }
public void setLastMoved() { public void setLastMoved() {
lastMovement = System.currentTimeMillis(); lastMovement = GameEngine.getTime();
} }
public void setLocation(Point p) { public void setLocation(Point p) {

View File

@ -6,6 +6,7 @@ import java.util.ConcurrentModificationException;
import org.moparscape.msc.config.Constants; import org.moparscape.msc.config.Constants;
import org.moparscape.msc.config.Formulae; import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.DelayedEvent; import org.moparscape.msc.gs.event.DelayedEvent;
import org.moparscape.msc.gs.event.FightEvent; import org.moparscape.msc.gs.event.FightEvent;
import org.moparscape.msc.gs.external.EntityHandler; import org.moparscape.msc.gs.external.EntityHandler;
@ -315,7 +316,7 @@ public class Npc extends Mob {
if (hasRan()) { if (hasRan()) {
return null; return null;
} }
long now = System.currentTimeMillis(); long now = GameEngine.getTime();
if (getChasing() != null) { if (getChasing() != null) {
return null; return null;
} }
@ -534,7 +535,7 @@ public class Npc extends Mob {
} }
public void updatePosition() { public void updatePosition() {
long now = System.currentTimeMillis(); long now = GameEngine.getTime();
Player victim = null; Player victim = null;
if (!isBusy() && def.isAggressive() && now - getCombatTimer() > 3000 && (victim = findVictim()) != null) { if (!isBusy() && def.isAggressive() && now - getCombatTimer() > 3000 && (victim = findVictim()) != null) {
resetPath(); resetPath();

View File

@ -21,6 +21,7 @@ import org.moparscape.msc.gs.builders.MiscPacketBuilder;
import org.moparscape.msc.gs.builders.ls.SavePacketBuilder; import org.moparscape.msc.gs.builders.ls.SavePacketBuilder;
import org.moparscape.msc.gs.connection.LSPacket; import org.moparscape.msc.gs.connection.LSPacket;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.db.DBConnection; import org.moparscape.msc.gs.db.DBConnection;
import org.moparscape.msc.gs.event.DelayedEvent; import org.moparscape.msc.gs.event.DelayedEvent;
import org.moparscape.msc.gs.event.MiniEvent; import org.moparscape.msc.gs.event.MiniEvent;
@ -64,24 +65,24 @@ public final class Player extends Mob {
private int lastwithdrawamount = 0; private int lastwithdrawamount = 0;
public void setLastWithdrawTime(int itemid, int amount) { public void setLastWithdrawTime(int itemid, int amount) {
this.lastwithdrawtime = System.currentTimeMillis(); this.lastwithdrawtime = GameEngine.getTime();
lastwithdrawitem = itemid; lastwithdrawitem = itemid;
lastwithdrawamount = amount; lastwithdrawamount = amount;
} }
public void setLastDepositTime(int itemid, int amount) { public void setLastDepositTime(int itemid, int amount) {
this.lastbanktime = System.currentTimeMillis(); this.lastbanktime = GameEngine.getTime();
lastdepositeditem = itemid; lastdepositeditem = itemid;
lastdepositedamount = amount; lastdepositedamount = amount;
} }
public void setLastInvTime(int itemposition) { public void setLastInvTime(int itemposition) {
this.lastinvtime = System.currentTimeMillis(); this.lastinvtime = GameEngine.getTime();
lastitemposition = itemposition; lastitemposition = itemposition;
} }
public boolean shouldThrowDepositError(int itemid, int amount) { public boolean shouldThrowDepositError(int itemid, int amount) {
if(System.currentTimeMillis() - lastbanktime < 100 && lastdepositeditem == itemid && lastdepositedamount == amount) if(GameEngine.getTime() - lastbanktime < 100 && lastdepositeditem == itemid && lastdepositedamount == amount)
return false; return false;
if(amount == 0) if(amount == 0)
return false; return false;
@ -89,7 +90,7 @@ public final class Player extends Mob {
} }
public boolean shouldThrowWithdrawError(int itemid, int amount) { public boolean shouldThrowWithdrawError(int itemid, int amount) {
if(System.currentTimeMillis() - lastwithdrawtime < 100 && lastwithdrawitem == itemid && lastwithdrawamount == amount) if(GameEngine.getTime() - lastwithdrawtime < 100 && lastwithdrawitem == itemid && lastwithdrawamount == amount)
return false; return false;
if(amount == 0) if(amount == 0)
return false; return false;
@ -99,7 +100,7 @@ public final class Player extends Mob {
private int lastitemposition = 0; private int lastitemposition = 0;
public boolean shouldThrowInvError(int itemposition) { public boolean shouldThrowInvError(int itemposition) {
if(System.currentTimeMillis() - lastinvtime < 100 && lastitemposition == itemposition) if(GameEngine.getTime() - lastinvtime < 100 && lastitemposition == itemposition)
return false; return false;
return true; return true;
@ -113,7 +114,7 @@ public final class Player extends Mob {
public boolean hasAdminPriv = false; public boolean hasAdminPriv = false;
public boolean hasModPriv = false; public boolean hasModPriv = false;
public boolean hasPmodPriv = false; public boolean hasPmodPriv = false;
public long lastCommandUsed = System.currentTimeMillis(); public long lastCommandUsed = GameEngine.getTime();
/** /**
* Has the first major update for this player been sent? If not, we can't * Has the first major update for this player been sent? If not, we can't
* send them any minor updates. * send them any minor updates.
@ -234,7 +235,7 @@ public final class Player extends Mob {
public int tempy = -1; public int tempy = -1;
public Npc lastNpcChasingYou = null; public Npc lastNpcChasingYou = null;
public long lastNPCChat = System.currentTimeMillis(); public long lastNPCChat = GameEngine.getTime();
public boolean doricDependency = false; public boolean doricDependency = false;
public boolean flagCarrier = false; public boolean flagCarrier = false;
@ -249,13 +250,13 @@ public final class Player extends Mob {
public void addInterval() { public void addInterval() {
if (lastInterval == 0) { if (lastInterval == 0) {
lastInterval = System.currentTimeMillis(); lastInterval = GameEngine.getTime();
} else { } else {
intervals.addFirst(System.currentTimeMillis() - lastInterval); intervals.addFirst(GameEngine.getTime() - lastInterval);
if (intervals.size() > 75) { if (intervals.size() > 75) {
intervals.removeLast(); intervals.removeLast();
} }
lastInterval = System.currentTimeMillis(); lastInterval = GameEngine.getTime();
} }
} }
@ -286,7 +287,7 @@ public final class Player extends Mob {
* @return * @return
*/ */
public boolean isMuted() { public boolean isMuted() {
return (muted - System.currentTimeMillis() > 0); return (muted - GameEngine.getTime() > 0);
} }
/** /**
@ -295,7 +296,7 @@ public final class Player extends Mob {
* @return day * @return day
*/ */
public int getDaysMuted() { public int getDaysMuted() {
return (int) ((muted - System.currentTimeMillis()) / 1000 / 3600 / 24); return (int) ((muted - GameEngine.getTime()) / 1000 / 3600 / 24);
} }
/** /**
@ -483,7 +484,7 @@ public final class Player extends Mob {
* The last menu reply this player gave in a quest * The last menu reply this player gave in a quest
*/ */
// //
public long lastCast = System.currentTimeMillis(); public long lastCast = GameEngine.getTime();
/** /**
* Time of last charge spell * Time of last charge spell
*/ */
@ -492,7 +493,7 @@ public final class Player extends Mob {
* Last packet count time * Last packet count time
*/ */
private long lastCount = 0; private long lastCount = 0;
public long lastDeath = System.currentTimeMillis(); public long lastDeath = GameEngine.getTime();
/** /**
* Stores the last IP address used * Stores the last IP address used
*/ */
@ -503,7 +504,7 @@ public final class Player extends Mob {
private long lastLogin = 0; private long lastLogin = 0;
// Player(IoSession // Player(IoSession
public long lastMineTimer = 0; public long lastMineTimer = 0;
public long lastPacketRecTime = System.currentTimeMillis() / 1000; public long lastPacketRecTime = GameEngine.getTime() / 1000;
/** /**
* Queue of last 100 packets, used for auto detection purposes * Queue of last 100 packets, used for auto detection purposes
*/ */
@ -512,20 +513,20 @@ public final class Player extends Mob {
/** /**
* Last time a 'ping' was received * Last time a 'ping' was received
*/ */
private long lastPing = System.currentTimeMillis(); private long lastPing = GameEngine.getTime();
public String lastPlayerInfo2 = null; public String lastPlayerInfo2 = null;
private int lastQuestMenuReply = -1; private int lastQuestMenuReply = -1;
// don't remove this. -xEnt // don't remove this. -xEnt
public int lastRandom = 0; public int lastRandom = 0;
public long lastRange = System.currentTimeMillis(); public long lastRange = GameEngine.getTime();
/** /**
* Time last report was sent, used to throttle reports * Time last report was sent, used to throttle reports
*/ */
private long lastReport = 0; private long lastReport = 0;
public long lastRun = System.currentTimeMillis(); // Leave this here public long lastRun = GameEngine.getTime(); // Leave this here
private long lastSaveTime = System.currentTimeMillis() private long lastSaveTime = GameEngine.getTime()
+ DataConversions.random(600000, 1800000); + DataConversions.random(600000, 1800000);
private long lastSleepTime = System.currentTimeMillis(); private long lastSleepTime = GameEngine.getTime();
/** /**
* The time of the last spell cast, used as a throttle * The time of the last spell cast, used as a throttle
*/ */
@ -708,14 +709,14 @@ public final class Player extends Mob {
*/ */
public boolean infected = false; public boolean infected = false;
public long lastInfected = System.currentTimeMillis(); public long lastInfected = GameEngine.getTime();
/* /*
* Informs the server that the player has just used Infected Blood and activate the cooldown. * Informs the server that the player has just used Infected Blood and activate the cooldown.
*/ */
public void setLastInfected() { public void setLastInfected() {
lastInfected = System.currentTimeMillis(); lastInfected = GameEngine.getTime();
} }
/* /*
@ -750,7 +751,7 @@ public final class Player extends Mob {
ioSession = ios; ioSession = ios;
currentIP = ((InetSocketAddress) ios.getRemoteAddress()).getAddress() currentIP = ((InetSocketAddress) ios.getRemoteAddress()).getAddress()
.getHostAddress(); .getHostAddress();
currentLogin = System.currentTimeMillis(); currentLogin = GameEngine.getTime();
actionSender = new MiscPacketBuilder(this); actionSender = new MiscPacketBuilder(this);
setBusy(true); setBusy(true);
Instance.getWorld(); Instance.getWorld();
@ -768,7 +769,7 @@ public final class Player extends Mob {
} }
public void addAttackedBy(Player p) { public void addAttackedBy(Player p) {
attackedBy.put(p.getUsernameHash(), System.currentTimeMillis()); attackedBy.put(p.getUsernameHash(), GameEngine.getTime());
} }
public void addFriend(long id, int world) { public void addFriend(long id, int world) {
@ -787,7 +788,7 @@ public final class Player extends Mob {
} }
public void addPacket(RSCPacket p) { public void addPacket(RSCPacket p) {
long now = System.currentTimeMillis(); long now = GameEngine.getTime();
if (now - lastCount > 3000) { if (now - lastCount > 3000) {
lastCount = now; lastCount = now;
packetCount = 0; packetCount = 0;
@ -838,7 +839,7 @@ public final class Player extends Mob {
super.setAppearnceChanged(true); super.setAppearnceChanged(true);
} }
skullEvent skullEvent
.setLastRun(System.currentTimeMillis() - (1200000 - timeLeft)); .setLastRun(GameEngine.getTime() - (1200000 - timeLeft));
} }
public void addToDuelOffer(InvItem item) { public void addToDuelOffer(InvItem item) {
@ -851,20 +852,20 @@ public final class Player extends Mob {
public boolean canLogout() { public boolean canLogout() {
if(this.location.inWilderness()) { if(this.location.inWilderness()) {
if(System.currentTimeMillis() - this.getLastMoved() < 10000) { if(GameEngine.getTime() - this.getLastMoved() < 10000) {
getActionSender().sendMessage("You must stand peacefully in one place for 10 seconds!"); getActionSender().sendMessage("You must stand peacefully in one place for 10 seconds!");
return false; return false;
} }
} }
return !isBusy() && System.currentTimeMillis() - getCombatTimer() > 10000; return !isBusy() && GameEngine.getTime() - getCombatTimer() > 10000;
} }
public boolean canReport() { public boolean canReport() {
return System.currentTimeMillis() - lastReport > 60000; return GameEngine.getTime() - lastReport > 60000;
} }
public boolean castTimer() { public boolean castTimer() {
return System.currentTimeMillis() - lastSpellCast > 1200; return GameEngine.getTime() - lastSpellCast > 1200;
} }
public boolean checkAttack(Mob mob, boolean missile) { public boolean checkAttack(Mob mob, boolean missile) {
@ -894,7 +895,7 @@ public final class Player extends Mob {
return true; return true;
} }
} }
if (System.currentTimeMillis() - mob.getCombatTimer() < (mob if (GameEngine.getTime() - mob.getCombatTimer() < (mob
.getCombatState() == CombatState.RUNNING .getCombatState() == CombatState.RUNNING
|| mob.getCombatState() == CombatState.WAITING ? 3000 : 500) || mob.getCombatState() == CombatState.WAITING ? 3000 : 500)
&& !mob.inCombat()) { && !mob.inCombat()) {
@ -978,11 +979,11 @@ public final class Player extends Mob {
destroy = true; destroy = true;
actionSender.sendLogout(); actionSender.sendLogout();
} else { } else {
final long startDestroy = System.currentTimeMillis(); final long startDestroy = GameEngine.getTime();
Instance.getDelayedEventHandler().add(new DelayedEvent(this, 3000) { Instance.getDelayedEventHandler().add(new DelayedEvent(this, 3000) {
public void run() { public void run() {
if (owner.canLogout() || (!(owner.inCombat() && owner.isDueling()) && System.currentTimeMillis() - startDestroy > 600000*2)) { if (owner.canLogout() || (!(owner.inCombat() && owner.isDueling()) && GameEngine.getTime() - startDestroy > 600000*2)) {
owner.destroy(true); owner.destroy(true);
matchRunning = false; matchRunning = false;
} }
@ -999,11 +1000,11 @@ public final class Player extends Mob {
destroy = true; destroy = true;
actionSender.sendLogout(); actionSender.sendLogout();
} else { } else {
final long startDestroy = System.currentTimeMillis(); final long startDestroy = GameEngine.getTime();
Instance.getDelayedEventHandler().add(new DelayedEvent(this, 3000) { Instance.getDelayedEventHandler().add(new DelayedEvent(this, 3000) {
public void run() { public void run() {
if (owner.canLogout() || (!(owner.inCombat() && owner.isDueling()) && System.currentTimeMillis() - startDestroy > 60000)) { if (owner.canLogout() || (!(owner.inCombat() && owner.isDueling()) && GameEngine.getTime() - startDestroy > 60000)) {
owner.destroy(true); owner.destroy(true);
matchRunning = false; matchRunning = false;
} }
@ -1115,7 +1116,7 @@ public final class Player extends Mob {
} }
public int getDaysSubscriptionLeft() { public int getDaysSubscriptionLeft() {
long now = (System.currentTimeMillis() / 1000); long now = (GameEngine.getTime() / 1000);
if (subscriptionExpires == 0 || now >= subscriptionExpires) { if (subscriptionExpires == 0 || now >= subscriptionExpires) {
return 0; return 0;
} }
@ -1379,8 +1380,7 @@ public final class Player extends Mob {
} }
public int getSpellWait() { public int getSpellWait() {
return DataConversions.roundUp((double) (1200 - (System return DataConversions.roundUp((double) (1200 - (GameEngine.getTime() - lastSpellCast)) / 1000D);
.currentTimeMillis() - lastSpellCast)) / 1000D);
} }
public Action getStatus() { public Action getStatus() {
@ -1638,7 +1638,7 @@ public final class Player extends Mob {
} }
public boolean isCharged() { public boolean isCharged() {
return System.currentTimeMillis() - lastCharge < 600000; return GameEngine.getTime() - lastCharge < 600000;
} }
public boolean isDuelConfirmAccepted() { public boolean isDuelConfirmAccepted() {
@ -1806,7 +1806,7 @@ public final class Player extends Mob {
opponent.resetCombat(CombatState.WON); opponent.resetCombat(CombatState.WON);
} }
actionSender.sendSound("death"); actionSender.sendSound("death");
lastDeath = System.currentTimeMillis(); lastDeath = GameEngine.getTime();
actionSender.sendDied(); actionSender.sendDied();
for (int i = 0; i < 18; i++) { for (int i = 0; i < 18; i++) {
curStat[i] = maxStat[i]; curStat[i] = maxStat[i];
@ -1979,7 +1979,7 @@ public final class Player extends Mob {
} }
public void ping() { public void ping() {
lastPing = System.currentTimeMillis(); lastPing = GameEngine.getTime();
} }
public void remove() { public void remove() {
@ -2215,7 +2215,7 @@ public final class Player extends Mob {
} }
public void setArrowFired() { public void setArrowFired() {
lastArrow = System.currentTimeMillis(); lastArrow = GameEngine.getTime();
} }
public void setBank(Bank b) { public void setBank(Bank b) {
@ -2223,7 +2223,7 @@ public final class Player extends Mob {
} }
public void setCastTimer() { public void setCastTimer() {
lastSpellCast = System.currentTimeMillis(); lastSpellCast = GameEngine.getTime();
} }
public void setChangingAppearance(boolean b) { public void setChangingAppearance(boolean b) {
@ -2231,7 +2231,7 @@ public final class Player extends Mob {
} }
public void setCharged() { public void setCharged() {
lastCharge = System.currentTimeMillis(); lastCharge = GameEngine.getTime();
} }
public void setClassName(String className) { public void setClassName(String className) {
@ -2373,7 +2373,7 @@ public final class Player extends Mob {
} }
public void setLastReport() { public void setLastReport() {
lastReport = System.currentTimeMillis(); lastReport = GameEngine.getTime();
} }
public void setLastSaveTime(long save) { public void setLastSaveTime(long save) {
@ -2386,7 +2386,7 @@ public final class Player extends Mob {
public void setLoggedIn(boolean loggedIn) { public void setLoggedIn(boolean loggedIn) {
if (loggedIn) { if (loggedIn) {
currentLogin = System.currentTimeMillis(); currentLogin = GameEngine.getTime();
} }
this.loggedIn = loggedIn; this.loggedIn = loggedIn;
} }
@ -2421,7 +2421,7 @@ public final class Player extends Mob {
} }
public void setNpc(Npc npc) { public void setNpc(Npc npc) {
// System.out.println("setNpc(npc)"); // Logging.debug("setNpc(npc)");
interactingNpc = npc; interactingNpc = npc;
} }
@ -2446,7 +2446,7 @@ public final class Player extends Mob {
if (save) { if (save) {
// save(); // save();
setLastSaveTime(System.currentTimeMillis()); setLastSaveTime(GameEngine.getTime());
getActionSender().sendQuestInfo(); getActionSender().sendQuestInfo();
getActionSender().sendMessage( getActionSender().sendMessage(
"@gre@You just gained " + gained + " quest point" "@gre@You just gained " + gained + " quest point"
@ -2530,7 +2530,7 @@ public final class Player extends Mob {
public void setSkulledOn(Player player) { public void setSkulledOn(Player player) {
player.addAttackedBy(this); player.addAttackedBy(this);
if (System.currentTimeMillis() - lastAttackedBy(player) > 1200000) { if (GameEngine.getTime() - lastAttackedBy(player) > 1200000) {
addSkull(1200000); addSkull(1200000);
} }
} }
@ -2552,7 +2552,7 @@ public final class Player extends Mob {
} }
public void setSpellFail() { public void setSpellFail() {
lastSpellCast = System.currentTimeMillis() + 20000; lastSpellCast = GameEngine.getTime() + 20000;
} }
public void setStatus(Action a) { public void setStatus(Action a) {
@ -2643,7 +2643,7 @@ public final class Player extends Mob {
} }
public boolean tradeDuelThrottling() { public boolean tradeDuelThrottling() {
long now = System.currentTimeMillis(); long now = GameEngine.getTime();
if (now - lastTradeDuelRequest > 1000) { if (now - lastTradeDuelRequest > 1000) {
lastTradeDuelRequest = now; lastTradeDuelRequest = now;
return false; return false;

View File

@ -4,6 +4,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.external.EntityHandler; import org.moparscape.msc.gs.external.EntityHandler;
import org.moparscape.msc.gs.util.Logger; import org.moparscape.msc.gs.util.Logger;
@ -193,7 +194,7 @@ public class Script {
*/ */
public int PickOption(String[] strs) { public int PickOption(String[] strs) {
try { try {
long time = System.currentTimeMillis(); long time = GameEngine.getTime();
player.setBusy(false); player.setBusy(false);
player.lastOption = -2; player.lastOption = -2;
player.setMenuHandler(new MenuHandler(strs) { player.setMenuHandler(new MenuHandler(strs) {
@ -208,7 +209,7 @@ public class Script {
} }
}); });
player.getActionSender().sendMenu(strs); player.getActionSender().sendMenu(strs);
while (player.lastOption == -2 && System.currentTimeMillis() - time < 20000) { // timeout while (player.lastOption == -2 && GameEngine.getTime() - time < 20000) { // timeout
Wait(25); Wait(25);
} }
if (player.lastOption == -1 || player.lastOption == -2) { if (player.lastOption == -1 || player.lastOption == -2) {

View File

@ -6,7 +6,7 @@ package org.moparscape.msc.gs.model.mini;
* @author xEnt * @author xEnt
* *
*/ */
public class Cache { public class CacheObject {
public boolean muted = false; public boolean muted = false;
public boolean inRed = false; public boolean inRed = false;

View File

@ -1,5 +1,7 @@
package org.moparscape.msc.gs.model.snapshot; package org.moparscape.msc.gs.model.snapshot;
import org.moparscape.msc.gs.core.GameEngine;
/** /**
* Snapshot abstract class * Snapshot abstract class
@ -13,7 +15,7 @@ public abstract class Snapshot {
public Snapshot(String owner) { public Snapshot(String owner) {
this.owner = owner; this.owner = owner;
this.eventTime = System.currentTimeMillis(); this.eventTime = GameEngine.getTime();
} }

View File

@ -140,7 +140,7 @@ public class PlayerLogin implements PacketHandler {
player.setQuestPoints(p.readShort(), false); player.setQuestPoints(p.readShort(), false);
int questCount = p.readShort(); int questCount = p.readShort();
// System.out.println(questCount); // Logging.debug(questCount);
for (int i = 0; i < questCount; i++) for (int i = 0; i < questCount; i++)
player.setQuestStage(p.readShort(), p.readShort(), false, false); player.setQuestStage(p.readShort(), p.readShort(), false, false);

View File

@ -6,6 +6,7 @@ import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.FightEvent; import org.moparscape.msc.gs.event.FightEvent;
import org.moparscape.msc.gs.event.RangeEvent; import org.moparscape.msc.gs.event.RangeEvent;
import org.moparscape.msc.gs.event.WalkToMobEvent; import org.moparscape.msc.gs.event.WalkToMobEvent;
@ -76,7 +77,7 @@ public class AttackHandler implements PacketHandler {
if (affectedMob instanceof Player) { if (affectedMob instanceof Player) {
Player opp = (Player) affectedMob; Player opp = (Player) affectedMob;
if (System.currentTimeMillis() - opp.lastMineTimer < 2000 && opp.isBusy()) if (GameEngine.getTime() - opp.lastMineTimer < 2000 && opp.isBusy())
cont = true; cont = true;
} }
if(affectedMob instanceof Player) { if(affectedMob instanceof Player) {

View File

@ -13,6 +13,7 @@ import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.builders.ls.MiscPacketBuilder; import org.moparscape.msc.gs.builders.ls.MiscPacketBuilder;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.core.ClientUpdater; import org.moparscape.msc.gs.core.ClientUpdater;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.db.DBConnection; import org.moparscape.msc.gs.db.DBConnection;
import org.moparscape.msc.gs.event.MiniEvent; import org.moparscape.msc.gs.event.MiniEvent;
import org.moparscape.msc.gs.event.SingleEvent; import org.moparscape.msc.gs.event.SingleEvent;
@ -45,14 +46,14 @@ public class CommandHandler implements PacketHandler {
public void handleCommand(String cmd, String[] args, Player player) throws Exception { public void handleCommand(String cmd, String[] args, Player player) throws Exception {
MiscPacketBuilder loginServer = Instance.getServer().getLoginConnector().getActionSender(); MiscPacketBuilder loginServer = Instance.getServer().getLoginConnector().getActionSender();
if(System.currentTimeMillis() - player.lastCommandUsed < 2000 && !player.isMod()) { if(GameEngine.getTime() - player.lastCommandUsed < 2000 && !player.isMod()) {
if(System.currentTimeMillis() - player.lastCommandUsed < 100) { // incase spammers if(GameEngine.getTime() - player.lastCommandUsed < 100) { // incase spammers
return; return;
} }
player.getActionSender().sendMessage("2 second delay on using a new command"); player.getActionSender().sendMessage("2 second delay on using a new command");
return; return;
} }
player.lastCommandUsed = System.currentTimeMillis(); player.lastCommandUsed = GameEngine.getTime();
if (cmd.equals("help")) { if (cmd.equals("help")) {
player.getActionSender().sendAlert("List of commands are shown on forums!", true); player.getActionSender().sendAlert("List of commands are shown on forums!", true);
return; return;
@ -89,20 +90,20 @@ public class CommandHandler implements PacketHandler {
} }
if (cmd.equals("stuck")) { if (cmd.equals("stuck")) {
if (System.currentTimeMillis() - player.getCurrentLogin() < 30000) { if (GameEngine.getTime() - player.getCurrentLogin() < 30000) {
player.getActionSender().sendMessage("You cannot do this after you have recently logged in"); player.getActionSender().sendMessage("You cannot do this after you have recently logged in");
return; return;
} }
if(!player.canLogout() || System.currentTimeMillis() - player.getLastMoved() < 10000) { if(!player.canLogout() || GameEngine.getTime() - player.getLastMoved() < 10000) {
player.getActionSender().sendMessage("You must stand peacefully in one place for 10 seconds!"); player.getActionSender().sendMessage("You must stand peacefully in one place for 10 seconds!");
return; return;
} }
if (player.getLocation().inModRoom() && !player.isMod()) { if (player.getLocation().inModRoom() && !player.isMod()) {
player.getActionSender().sendMessage("You cannot use ::stuck here"); player.getActionSender().sendMessage("You cannot use ::stuck here");
} else if (!player.isMod() && System.currentTimeMillis() - player.getLastMoved() < 300000 && System.currentTimeMillis() - player.getCastTimer() < 300000) { } else if (!player.isMod() && GameEngine.getTime() - player.getLastMoved() < 300000 && GameEngine.getTime() - player.getCastTimer() < 300000) {
player.getActionSender().sendMessage("There is a 5 minute delay on using ::stuck, please stand still for 5 minutes."); player.getActionSender().sendMessage("There is a 5 minute delay on using ::stuck, please stand still for 5 minutes.");
player.getActionSender().sendMessage("This command is logged ONLY use it when you are REALLY stuck."); player.getActionSender().sendMessage("This command is logged ONLY use it when you are REALLY stuck.");
} else if (!player.inCombat() && System.currentTimeMillis() - player.getCombatTimer() > 300000 || player.isMod()) { } else if (!player.inCombat() && GameEngine.getTime() - player.getCombatTimer() > 300000 || player.isMod()) {
Logger.mod(player.getUsername() + " used stuck at " + player.getX() + ":" + player.getY()); Logger.mod(player.getUsername() + " used stuck at " + player.getX() + ":" + player.getY());
player.setCastTimer(); player.setCastTimer();
player.teleport(122, 647, true); player.teleport(122, 647, true);

View File

@ -5,6 +5,7 @@ import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.DuelEvent; import org.moparscape.msc.gs.event.DuelEvent;
import org.moparscape.msc.gs.event.SingleEvent; import org.moparscape.msc.gs.event.SingleEvent;
import org.moparscape.msc.gs.event.WalkToMobEvent; import org.moparscape.msc.gs.event.WalkToMobEvent;
@ -246,7 +247,7 @@ public class DuelHandler implements PacketHandler {
affectedPlayer.setBusy(false); affectedPlayer.setBusy(false);
} }
}; };
walking.setLastRun(System.currentTimeMillis() + 500); walking.setLastRun(GameEngine.getTime() + 500);
Instance.getDelayedEventHandler().add(walking); Instance.getDelayedEventHandler().add(walking);
} }
break; break;

View File

@ -3,6 +3,7 @@ package org.moparscape.msc.gs.phandler.client;
import org.apache.mina.common.IoSession; import org.apache.mina.common.IoSession;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.model.Player; import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.World; import org.moparscape.msc.gs.model.World;
import org.moparscape.msc.gs.model.snapshot.Activity; import org.moparscape.msc.gs.model.snapshot.Activity;
@ -26,7 +27,7 @@ public class FollowRequest implements PacketHandler {
player.resetPath(); player.resetPath();
return; return;
} }
if (System.currentTimeMillis() - player.lastRun < 3000) if (GameEngine.getTime() - player.lastRun < 3000)
return; return;
player.resetAll(); player.resetAll();
player.setFollowing(affectedPlayer, 1); player.setFollowing(affectedPlayer, 1);

View File

@ -5,6 +5,7 @@ import org.moparscape.msc.config.Constants;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.Server; import org.moparscape.msc.gs.Server;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.DelayedEvent; import org.moparscape.msc.gs.event.DelayedEvent;
import org.moparscape.msc.gs.event.MiniEvent; import org.moparscape.msc.gs.event.MiniEvent;
import org.moparscape.msc.gs.event.SingleEvent; import org.moparscape.msc.gs.event.SingleEvent;
@ -174,7 +175,7 @@ public class InvActionHandler implements PacketHandler {
} else if (item.getDef().getCommand().equalsIgnoreCase("open")) { } else if (item.getDef().getCommand().equalsIgnoreCase("open")) {
if(item.getID() == INFECTED_BLOOD) { if(item.getID() == INFECTED_BLOOD) {
if(!player.isInfected()) { player.setInfected(); return; } if(!player.isInfected()) { player.setInfected(); return; }
long lastUsed = System.currentTimeMillis() - player.lastInfected(); long lastUsed = GameEngine.getTime() - player.lastInfected();
long remaining = 5 - lastUsed / 1000; long remaining = 5 - lastUsed / 1000;
InvItem INFECTED_BLOOD_I = new InvItem(1322, 1); InvItem INFECTED_BLOOD_I = new InvItem(1322, 1);
if(lastUsed / 1000 <= 5) { player.getActionSender().sendMessage("You have to wait " + remaining + " seconds before using that again."); return; } if(lastUsed / 1000 <= 5) { player.getActionSender().sendMessage("You have to wait " + remaining + " seconds before using that again."); return; }

View File

@ -8,6 +8,7 @@ import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.Server; import org.moparscape.msc.gs.Server;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.MiniEvent; import org.moparscape.msc.gs.event.MiniEvent;
import org.moparscape.msc.gs.event.ShortEvent; import org.moparscape.msc.gs.event.ShortEvent;
import org.moparscape.msc.gs.event.WalkToObjectEvent; import org.moparscape.msc.gs.event.WalkToObjectEvent;
@ -466,9 +467,9 @@ public class InvUseOnObject implements PacketHandler {
if (i.getID() == 517 && i.getAmount() > 20) { if (i.getID() == 517 && i.getAmount() > 20) {
i = new InvItem(517, DataConversions.random(0, 20) + 1); i = new InvItem(517, DataConversions.random(0, 20) + 1);
} }
Logger.println("Player: " + owner.getUsername() + " Got item: " + i.getID() + " From CHEST (" + i.getAmount() + ") sys time (" + System.currentTimeMillis() + ")"); Logger.println("Player: " + owner.getUsername() + " Got item: " + i.getID() + " From CHEST (" + i.getAmount() + ") sys time (" + GameEngine.getTime() + ")");
if (i.getAmount() > 4000) { if (i.getAmount() > 4000) {
Logger.println("WARNING!!!! Player: " + owner.getUsername() + " was about to get " + i.getAmount() + " of " + i.getID() + " from the CHEST sys time (" + System.currentTimeMillis() + ")"); Logger.println("WARNING!!!! Player: " + owner.getUsername() + " was about to get " + i.getAmount() + " of " + i.getID() + " from the CHEST sys time (" + GameEngine.getTime() + ")");
owner.setBusy(false); owner.setBusy(false);
owner.getActionSender().sendInventory(); owner.getActionSender().sendInventory();
return; return;

View File

@ -3,6 +3,7 @@ package org.moparscape.msc.gs.phandler.client;
import org.apache.mina.common.IoSession; import org.apache.mina.common.IoSession;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.ShortEvent; import org.moparscape.msc.gs.event.ShortEvent;
import org.moparscape.msc.gs.event.WalkToMobEvent; import org.moparscape.msc.gs.event.WalkToMobEvent;
import org.moparscape.msc.gs.model.Bubble; import org.moparscape.msc.gs.model.Bubble;
@ -33,7 +34,7 @@ public class InvUseOnPlayer implements PacketHandler {
if (affectedPlayer == null || item == null) { // This shouldn't happen if (affectedPlayer == null || item == null) { // This shouldn't happen
return; return;
} }
if (System.currentTimeMillis() - affectedPlayer.lastRun < 2000) { if (GameEngine.getTime() - affectedPlayer.lastRun < 2000) {
player.resetPath(); player.resetPath();
return; return;
} }

View File

@ -9,6 +9,7 @@ import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.Server; import org.moparscape.msc.gs.Server;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.DelayedEvent; import org.moparscape.msc.gs.event.DelayedEvent;
import org.moparscape.msc.gs.event.MiniEvent; import org.moparscape.msc.gs.event.MiniEvent;
import org.moparscape.msc.gs.event.ShortEvent; import org.moparscape.msc.gs.event.ShortEvent;
@ -38,6 +39,7 @@ import org.moparscape.msc.gs.phandler.PacketHandler;
import org.moparscape.msc.gs.plugins.extras.Thieving; import org.moparscape.msc.gs.plugins.extras.Thieving;
import org.moparscape.msc.gs.states.Action; import org.moparscape.msc.gs.states.Action;
import org.moparscape.msc.gs.tools.DataConversions; import org.moparscape.msc.gs.tools.DataConversions;
import org.moparscape.msc.gs.util.Logger;
public class ObjectAction implements PacketHandler { public class ObjectAction implements PacketHandler {
@ -72,7 +74,7 @@ public class ObjectAction implements PacketHandler {
/* /*
if (newtime == 0) { if (newtime == 0) {
if (player.sessionFlags < 4) { if (player.sessionFlags < 4) {
System.out.println("[Anti-Bot] " + player.getUsername() + " is using a 3rd party client [B&]"); Logging.debug("[Anti-Bot] " + player.getUsername() + " is using a 3rd party client [B&]");
player.sessionFlags++; player.sessionFlags++;
} }
} else {// dummy } else {// dummy
@ -80,7 +82,7 @@ public class ObjectAction implements PacketHandler {
player.lastPacketTime = newtime; player.lastPacketTime = newtime;
else { else {
if (newtime <= player.lastPacketTime && (System.currentTimeMillis() / 1000) > player.lastPacketRecTime) { if (newtime <= player.lastPacketTime && (System.currentTimeMillis() / 1000) > player.lastPacketRecTime) {
System.out.println("[Anti-Bot] " + player.getUsername() + " tried to send a recorded packet, WPE."); Logging.debug("[Anti-Bot] " + player.getUsername() + " tried to send a recorded packet, WPE.");
player.destroy(false); player.destroy(false);
} else { } else {
player.lastPacketTime = newtime; player.lastPacketTime = newtime;
@ -130,9 +132,9 @@ public class ObjectAction implements PacketHandler {
return; return;
} }
String command = (click == 0 ? def.getCommand1() : def.getCommand2()).toLowerCase(); String command = (click == 0 ? def.getCommand1() : def.getCommand2()).toLowerCase();
// System.out.println(object.getID() + " " + // Logging.debug(object.getID() + " " +
// command); // command);
if(object.getID() == 487 && System.currentTimeMillis() - owner.getLastMoved() < 10000) { owner.getActionSender().sendMessage("You must stand still for 10 seconds before using this"); return; } if(object.getID() == 487 && GameEngine.getTime() - owner.getLastMoved() < 10000) { owner.getActionSender().sendMessage("You must stand still for 10 seconds before using this"); return; }
Point telePoint = EntityHandler.getObjectTelePoint(object.getLocation(), command); Point telePoint = EntityHandler.getObjectTelePoint(object.getLocation(), command);
if (telePoint != null) { if (telePoint != null) {
owner.teleport(telePoint.getX(), telePoint.getY(), false); owner.teleport(telePoint.getX(), telePoint.getY(), false);
@ -163,7 +165,7 @@ public class ObjectAction implements PacketHandler {
// owner.teleport(251, 1411, false); // owner.teleport(251, 1411, false);
} }
} }
System.out.println("Command: " + command); Logger.println("Command: " + command);
if(command.equalsIgnoreCase("talk to") && object.getID() == 391) { if(command.equalsIgnoreCase("talk to") && object.getID() == 391) {
final String[] options = { "Yes please!", "No thanks I prefer to walk!" }; final String[] options = { "Yes please!", "No thanks I prefer to walk!" };

View File

@ -9,6 +9,7 @@ import org.apache.mina.common.IoSession;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.model.Player; import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.World; import org.moparscape.msc.gs.model.World;
import org.moparscape.msc.gs.model.snapshot.Activity; import org.moparscape.msc.gs.model.snapshot.Activity;
@ -25,11 +26,11 @@ public class Sleepword implements PacketHandler {
public void handlePacket(Packet p, IoSession session) throws Exception { public void handlePacket(Packet p, IoSession session) throws Exception {
Player player = (Player) session.getAttachment(); Player player = (Player) session.getAttachment();
int pID = ((RSCPacket) p).getID(); int pID = ((RSCPacket) p).getID();
long now = System.currentTimeMillis(); long now = GameEngine.getTime();
try { try {
String sleepword_result = ((RSCPacket) p).readString().trim(); String sleepword_result = ((RSCPacket) p).readString().trim();
if (System.currentTimeMillis() - player.getLastSleepTime() < 1000) if (GameEngine.getTime() - player.getLastSleepTime() < 1000)
return; return;
if (player.getWrongWords() >= 10) { if (player.getWrongWords() >= 10) {

View File

@ -13,6 +13,7 @@ import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.FightEvent; import org.moparscape.msc.gs.event.FightEvent;
import org.moparscape.msc.gs.event.ObjectRemover; import org.moparscape.msc.gs.event.ObjectRemover;
import org.moparscape.msc.gs.event.WalkMobToMobEvent; import org.moparscape.msc.gs.event.WalkMobToMobEvent;
@ -121,7 +122,7 @@ public class SpellHandler implements PacketHandler {
private Random r = new Random(); private Random r = new Random();
private void finalizeSpell(Player player, SpellDef spell) { private void finalizeSpell(Player player, SpellDef spell) {
player.lastCast = System.currentTimeMillis(); player.lastCast = GameEngine.getTime();
player.getActionSender().sendSound("spellok"); player.getActionSender().sendSound("spellok");
player.getActionSender().sendMessage("Cast spell successfully"); player.getActionSender().sendMessage("Cast spell successfully");
player.setCastTimer(); player.setCastTimer();
@ -398,12 +399,12 @@ public class SpellHandler implements PacketHandler {
} }
if (affectedMob instanceof Player) { if (affectedMob instanceof Player) {
Player other = (Player) affectedMob; Player other = (Player) affectedMob;
if (player.getLocation().inWilderness() && System.currentTimeMillis() - other.lastRun < 1000) { if (player.getLocation().inWilderness() && GameEngine.getTime() - other.lastRun < 1000) {
player.resetPath(); player.resetPath();
return; return;
} }
} }
if (player.getLocation().inWilderness() && System.currentTimeMillis() - player.lastRun < 3000) { if (player.getLocation().inWilderness() && GameEngine.getTime() - player.lastRun < 3000) {
player.resetPath(); player.resetPath();
return; return;
} }

View File

@ -7,6 +7,7 @@ import org.apache.mina.common.IoSession;
import org.moparscape.msc.config.Formulae; import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.WalkToMobEvent; import org.moparscape.msc.gs.event.WalkToMobEvent;
import org.moparscape.msc.gs.model.ChatMessage; import org.moparscape.msc.gs.model.ChatMessage;
import org.moparscape.msc.gs.model.Npc; import org.moparscape.msc.gs.model.Npc;
@ -32,10 +33,10 @@ public class TalkToNpcHandler implements PacketHandler {
player.resetPath(); player.resetPath();
return; return;
} }
if (System.currentTimeMillis() - player.lastNPCChat < 1500) if (GameEngine.getTime() - player.lastNPCChat < 1500)
return; return;
player.setLastQuestMenuReply(-2); player.setLastQuestMenuReply(-2);
player.lastNPCChat = System.currentTimeMillis(); player.lastNPCChat = GameEngine.getTime();
player.resetAll(); player.resetAll();
final Npc affectedNpc = world.getNpc(p.readShort()); final Npc affectedNpc = world.getNpc(p.readShort());
if (affectedNpc == null || !world.getQuestManager().isNpcVisible(affectedNpc, player)) { if (affectedNpc == null || !world.getQuestManager().isNpcVisible(affectedNpc, player)) {
@ -106,7 +107,7 @@ public class TalkToNpcHandler implements PacketHandler {
if (!(e instanceof InvocationTargetException)) { if (!(e instanceof InvocationTargetException)) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println(affectedNpc.getID()); Logger.println(affectedNpc.getID());
affectedNpc.unblock(); affectedNpc.unblock();
owner.setBusy(false); owner.setBusy(false);
} }

View File

@ -8,6 +8,7 @@ import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.builders.ls.MiscPacketBuilder; import org.moparscape.msc.gs.builders.ls.MiscPacketBuilder;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.db.DBConnection; import org.moparscape.msc.gs.db.DBConnection;
import org.moparscape.msc.gs.external.ItemDef; import org.moparscape.msc.gs.external.ItemDef;
import org.moparscape.msc.gs.model.InvItem; import org.moparscape.msc.gs.model.InvItem;
@ -225,7 +226,7 @@ public class TradeHandler implements PacketHandler {
player.getActionSender().sendInventory(); player.getActionSender().sendInventory();
player.getActionSender().sendEquipmentStats(); player.getActionSender().sendEquipmentStats();
Long now = System.currentTimeMillis(); long now = GameEngine.getTime();
player.save(); player.save();
player.setLastSaveTime(now); player.setLastSaveTime(now);
affectedPlayer.save(); affectedPlayer.save();

View File

@ -4,6 +4,7 @@ import org.apache.mina.common.IoSession;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.FightEvent; import org.moparscape.msc.gs.event.FightEvent;
import org.moparscape.msc.gs.event.MiniEvent; import org.moparscape.msc.gs.event.MiniEvent;
import org.moparscape.msc.gs.event.WalkMobToMobEvent; import org.moparscape.msc.gs.event.WalkMobToMobEvent;
@ -38,10 +39,10 @@ public class WalkRequest implements PacketHandler {
player.getActionSender().sendMessage("Running has been disabled in this duel."); player.getActionSender().sendMessage("Running has been disabled in this duel.");
return; return;
} }
player.lastRun = System.currentTimeMillis(); player.lastRun = GameEngine.getTime();
player.resetCombat(CombatState.RUNNING); player.resetCombat(CombatState.RUNNING);
if(player.isInfected() && System.currentTimeMillis() - player.getLastMoved() < 1900) { if(player.isInfected() && GameEngine.getTime() - player.getLastMoved() < 1900) {
final Packet newpacket = p; final Packet newpacket = p;
final IoSession newsession = session; final IoSession newsession = session;
Instance.getDelayedEventHandler().add(new MiniEvent(player, 2000) { Instance.getDelayedEventHandler().add(new MiniEvent(player, 2000) {
@ -127,11 +128,11 @@ public class WalkRequest implements PacketHandler {
} else { } else {
return; return;
} }
} else if (player.isBusy() && System.currentTimeMillis() - player.lastMineTimer > 2000) { } else if (player.isBusy() && GameEngine.getTime() - player.lastMineTimer > 2000) {
return; return;
} }
if (System.currentTimeMillis() - player.lastCast < 600) if (GameEngine.getTime() - player.lastCast < 600)
return; return;
player.isMining(false); player.isMining(false);

View File

@ -5,6 +5,7 @@ import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.Server; import org.moparscape.msc.gs.Server;
import org.moparscape.msc.gs.connection.Packet; import org.moparscape.msc.gs.connection.Packet;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.ShortEvent; import org.moparscape.msc.gs.event.ShortEvent;
import org.moparscape.msc.gs.event.WalkToPointEvent; import org.moparscape.msc.gs.event.WalkToPointEvent;
import org.moparscape.msc.gs.external.DoorDef; import org.moparscape.msc.gs.external.DoorDef;
@ -111,7 +112,7 @@ public class WallObjectAction implements PacketHandler {
if (object.getX() != 282 || object.getY() != 3020) { if (object.getX() != 282 || object.getY() != 3020) {
break; break;
} }
if(System.currentTimeMillis() - owner.getLastMoved() < 10000) { if(GameEngine.getTime() - owner.getLastMoved() < 10000) {
owner.getActionSender().sendMessage("You must stand still for 10 seconds before using this"); owner.getActionSender().sendMessage("You must stand still for 10 seconds before using this");
return; return;
} }

View File

@ -16,6 +16,7 @@ import org.moparscape.msc.gs.model.Script;
import org.moparscape.msc.gs.model.World; import org.moparscape.msc.gs.model.World;
import org.moparscape.msc.gs.phandler.PacketHandler; import org.moparscape.msc.gs.phandler.PacketHandler;
import org.moparscape.msc.gs.quest.Quest; import org.moparscape.msc.gs.quest.Quest;
import org.moparscape.msc.gs.util.Logger;
public class WieldHandler implements PacketHandler { public class WieldHandler implements PacketHandler {
@ -101,7 +102,7 @@ public class WieldHandler implements PacketHandler {
count++; count++;
} }
} }
System.out.println(count +" - " + World.getQuestManager().getQuests().size() ); Logger.println(count +" - " + World.getQuestManager().getQuests().size() );
if (count < World.getQuestManager().getQuests().size() || player.getCurStat(Script.MINING) < 50 || player.getCurStat(Script.HERBLAW) < 25 || player.getCurStat(Script.FISHING) < 53 || player.getCurStat(Script.COOKING) < 53 || player.getCurStat(Script.CRAFTING) < 31 || player.getCurStat(Script.WOODCUT) < 36 || player.getCurStat(Script.MAGIC) < 33) { if (count < World.getQuestManager().getQuests().size() || player.getCurStat(Script.MINING) < 50 || player.getCurStat(Script.HERBLAW) < 25 || player.getCurStat(Script.FISHING) < 53 || player.getCurStat(Script.COOKING) < 53 || player.getCurStat(Script.CRAFTING) < 31 || player.getCurStat(Script.WOODCUT) < 36 || player.getCurStat(Script.MAGIC) < 33) {
player.getActionSender().sendMessage("You must have completed at least " + (World.getQuestManager().getQuests().size()) + " quests and have these stat reqs:"); player.getActionSender().sendMessage("You must have completed at least " + (World.getQuestManager().getQuests().size()) + " quests and have these stat reqs:");
player.getActionSender().sendMessage("50 Mining, 25 Herblaw, 53 Fishing, 53 Cooking, 31 Crafting, 36 Woodcutting and 33 Magic"); player.getActionSender().sendMessage("50 Mining, 25 Herblaw, 53 Fishing, 53 Cooking, 31 Crafting, 36 Woodcutting and 33 Magic");

View File

@ -89,8 +89,8 @@ public class Quiz extends Thread {
* int index = -1; for(int i=0; i < players.size(); i++) { if * int index = -1; for(int i=0; i < players.size(); i++) { if
* (players.get(i).equals(p.getUsername())) index = i; * (players.get(i).equals(p.getUsername())) index = i;
* *
* if(i == -1) { System.out.println("Error removing " + p.getUsername() + * if(i == -1) { Logging.debug("Error removing " + p.getUsername() +
* " from the Quiz list."); return; } else { System.out.println("[QUIZ] " + * " from the Quiz list."); return; } else { Logging.debug("[QUIZ] " +
* players.get(index) + " has left the Quiz"); players.remove(index); * players.get(index) + " has left the Quiz"); players.remove(index);
* p.getActionSender().sendMessage("You have Quit the Quiz Queue"); } } * p.getActionSender().sendMessage("You have Quit the Quiz Queue"); } }
* *

View File

@ -421,7 +421,7 @@ public class Thieving {
player.setBusy(false); player.setBusy(false);
affectedNpc.setBusy(false); affectedNpc.setBusy(false);
affectedNpc.unblock(); affectedNpc.unblock();
System.out.println(e.getMessage() + "\nStack: " + e.getStackTrace()); Logger.error(e.getMessage() + "\nStack: " + e.getStackTrace());
player.setSpam(false); player.setSpam(false);
} }
@ -459,7 +459,7 @@ public class Thieving {
return false; return false;
} }
for (Npc n : t.getNpcs()) { for (Npc n : t.getNpcs()) {
System.out.println(t.getNpcs().get(0)); Logger.error(t.getNpcs().get(0));
} }
} }
} }
@ -542,7 +542,7 @@ public class Thieving {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
System.out.println(e.getMessage()); Logger.error(e.getMessage());
} }
} }
@ -887,7 +887,7 @@ public class Thieving {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
System.out.println(e.getMessage()); Logger.error(e.getMessage());
} }
} }

View File

@ -2,6 +2,7 @@ package org.moparscape.msc.gs.plugins.plugs.skills;
import org.moparscape.msc.config.Formulae; import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance; import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.ShortEvent; import org.moparscape.msc.gs.event.ShortEvent;
import org.moparscape.msc.gs.event.SingleEvent; import org.moparscape.msc.gs.event.SingleEvent;
import org.moparscape.msc.gs.external.EntityHandler; import org.moparscape.msc.gs.external.EntityHandler;
@ -112,7 +113,7 @@ public class Mining implements ObjectListener {
} }
final int retrytime = retrytimes; final int retrytime = retrytimes;
owner.lastMineTimer = System.currentTimeMillis(); owner.lastMineTimer = GameEngine.getTime();
owner.getActionSender().sendMessage("You swing your pick at the rock..."); owner.getActionSender().sendMessage("You swing your pick at the rock...");
Instance.getDelayedEventHandler().add(new ShortEvent(owner) { Instance.getDelayedEventHandler().add(new ShortEvent(owner) {
public void action() { public void action() {

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.SingleEvent; import org.moparscape.msc.gs.event.SingleEvent;
import org.moparscape.msc.gs.model.ActiveTile; import org.moparscape.msc.gs.model.ActiveTile;
import org.moparscape.msc.gs.model.ChatMessage; import org.moparscape.msc.gs.model.ChatMessage;
@ -277,8 +278,8 @@ public abstract class Quest {
} }
}); });
long start = System.currentTimeMillis(); long start = GameEngine.getTime();
while (player.getLastQuestMenuReply() == -1 && (System.currentTimeMillis() - start) <= timeout) { while (player.getLastQuestMenuReply() == -1 && (GameEngine.getTime() - start) <= timeout) {
if (player.getLastQuestMenuReply() == -2) if (player.getLastQuestMenuReply() == -2)
return -1; return -1;
sleep(10); sleep(10);

View File

@ -10,6 +10,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.moparscape.msc.config.Config; import org.moparscape.msc.config.Config;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.model.GameObject; import org.moparscape.msc.gs.model.GameObject;
import org.moparscape.msc.gs.model.InvItem; import org.moparscape.msc.gs.model.InvItem;
import org.moparscape.msc.gs.model.Item; import org.moparscape.msc.gs.model.Item;
@ -105,7 +106,7 @@ public class QuestManager {
*/ */
public final boolean loadQuests() { public final boolean loadQuests() {
try { try {
long start = System.currentTimeMillis(); long start = GameEngine.getTime();
if (quests != null) if (quests != null)
quests.clear(); quests.clear();
@ -151,7 +152,7 @@ public class QuestManager {
} }
} }
Logger.println("Loaded " + questCount + " quests successfully (" + (System.currentTimeMillis() - start) + "ms)"); Logger.println("Loaded " + questCount + " quests successfully (" + (GameEngine.getTime() - start) + "ms)");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;

View File

@ -10,6 +10,7 @@ import java.text.SimpleDateFormat;
import java.util.Random; import java.util.Random;
import org.moparscape.msc.gs.connection.RSCPacket; 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.model.Point;
import org.moparscape.msc.gs.util.Logger; import org.moparscape.msc.gs.util.Logger;
@ -363,7 +364,7 @@ public final class DataConversions {
} }
public static String timeSince(long time) { public static String timeSince(long time) {
int seconds = (int) ((System.currentTimeMillis() - time) / 1000); int seconds = (int) ((GameEngine.getTime() - time) / 1000);
int minutes = (int) (seconds / 60); int minutes = (int) (seconds / 60);
int hours = (int) (minutes / 60); int hours = (int) (minutes / 60);
int days = (int) (hours / 24); int days = (int) (hours / 24);

View File

@ -20,11 +20,11 @@ public class DefCompressor {
while ((read = fis.read(buf)) != -1) { while ((read = fis.read(buf)) != -1) {
out.write(buf, 0, read); out.write(buf, 0, read);
} }
System.out.println("Done."); Logger.println("Done.");
fis.close(); fis.close();
out.close(); out.close();
long endSize = target.length(); long endSize = target.length();
System.out.println("Initial size: " + initialSize + "; Compressed size: " + endSize); Logger.println("Initial size: " + initialSize + "; Compressed size: " + endSize);
} }
public static void decompressFile(File f) throws IOException { public static void decompressFile(File f) throws IOException {
@ -38,11 +38,11 @@ public class DefCompressor {
while ((read = in.read(buf)) != -1) { while ((read = in.read(buf)) != -1) {
fos.write(buf, 0, read); fos.write(buf, 0, read);
} }
System.out.println("Done."); Logger.println("Done.");
fos.close(); fos.close();
in.close(); in.close();
long endSize = target.length(); long endSize = target.length();
System.out.println("Initial size: " + initialSize + "; Decompressed size: " + endSize); Logger.println("Initial size: " + initialSize + "; Decompressed size: " + endSize);
} }
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {

View File

@ -19,7 +19,7 @@ public class Logger {
private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
public static void connection(Object o) { public static void connection(Object o) {
// System.out.println(o.toString()); // Logging.debug(o.toString());
} }
public static void error(Object o) { public static void error(Object o) {

View File

@ -27,7 +27,7 @@ public class MapGenerator {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
if (args.length < 1) { if (args.length < 1) {
System.out.println("Invalid args"); Logger.println("Invalid args");
return; return;
} }
String configFile = "conf/server/Conf.xml"; String configFile = "conf/server/Conf.xml";

View File

@ -10,13 +10,11 @@
<delete file="${jar}" /> <delete file="${jar}" />
<delete dir="${build}" /> <delete dir="${build}" />
<mkdir dir="${build}" /> <mkdir dir="${build}" />
<javac srcdir="${src}" destdir="${build}" debug="on" target="1.5"> <javac srcdir="${src}" destdir="${build}" debug="on" target="1.6">
<classpath> <classpath>
<pathelement location="${lib}/mina.jar" /> <pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/xpp3.jar" /> <pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/slf4j.jar" /> <pathelement location="${lib}/slf4j.jar" />
<pathelement location="${lib}/xstream.jar" /> <pathelement location="${lib}/xstream.jar" />
<pathelement location="${lib}/mysql-connector.jar" /> <pathelement location="${lib}/mysql-connector.jar" />
<pathelement location="${lib}/hex-string.jar" /> <pathelement location="${lib}/hex-string.jar" />

Binary file not shown.

View File

@ -11,7 +11,6 @@ import org.moparscape.msc.ls.packethandler.PacketHandler;
import org.moparscape.msc.ls.packethandler.PacketHandlerDef; import org.moparscape.msc.ls.packethandler.PacketHandlerDef;
import org.moparscape.msc.ls.util.PersistenceManager; import org.moparscape.msc.ls.util.PersistenceManager;
public class LoginEngine extends Thread { public class LoginEngine extends Thread {
/** /**
* The mapping of packet IDs to their handler * The mapping of packet IDs to their handler
@ -61,7 +60,8 @@ public class LoginEngine extends Thread {
* Loads the packet handling classes from the persistence manager. * Loads the packet handling classes from the persistence manager.
*/ */
protected void loadPacketHandlers() { protected void loadPacketHandlers() {
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager.load("LSPacketHandlers.xml"); PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager
.load("LSPacketHandlers.xml");
for (PacketHandlerDef handlerDef : handlerDefs) { for (PacketHandlerDef handlerDef : handlerDefs) {
try { try {
String className = handlerDef.getClassName(); String className = handlerDef.getClassName();
@ -76,7 +76,8 @@ public class LoginEngine extends Thread {
Server.error(e); Server.error(e);
} }
} }
handlerDefs = (PacketHandlerDef[]) PersistenceManager.load("FPacketHandlers.xml"); handlerDefs = (PacketHandlerDef[]) PersistenceManager
.load("FPacketHandlers.xml");
for (PacketHandlerDef handlerDef : handlerDefs) { for (PacketHandlerDef handlerDef : handlerDefs) {
try { try {
String className = handlerDef.getClassName(); String className = handlerDef.getClassName();
@ -99,7 +100,8 @@ public class LoginEngine extends Thread {
private void processIncomingPackets() { private void processIncomingPackets() {
for (LSPacket p : LSPacketQueue.getPackets()) { for (LSPacket p : LSPacketQueue.getPackets()) {
PacketHandler handler; PacketHandler handler;
if (((handler = uniqueHandlers.get(p.getUID())) != null) || ((handler = LSPacketHandlers.get(p.getID())) != null)) { if (((handler = uniqueHandlers.get(p.getUID())) != null)
|| ((handler = LSPacketHandlers.get(p.getID())) != null)) {
try { try {
handler.handlePacket(p, p.getSession()); handler.handlePacket(p, p.getSession());
uniqueHandlers.remove(p.getUID()); uniqueHandlers.remove(p.getUID());

View File

@ -104,13 +104,13 @@ public class Server {
// if(s != null) { // if(s != null) {
// w.unassosiateSave(s); // w.unassosiateSave(s);
// save = s; // save = s;
// System.out.println("Found cached save for " + // Logging.debug("Found cached save for " +
// DataConversions.hashToUsername(user)); // DataConversions.hashToUsername(user));
// break; // break;
// } // }
// } // }
// if(save == null) { // if(save == null) {
// System.out.println("No save found for " + // Logging.debug("No save found for " +
// DataConversions.hashToUsername(user) + ", loading fresh"); // DataConversions.hashToUsername(user) + ", loading fresh");
save = PlayerSave.loadPlayer(user); save = PlayerSave.loadPlayer(user);
// } // }

View File

@ -83,7 +83,7 @@ public class FConnectionHandler implements IoHandler {
*/ */
public void sessionCreated(IoSession session) { public void sessionCreated(IoSession session) {
session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new FCodecFactory())); session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new FCodecFactory()));
// System.out.println("Connection from: " + // Logging.debug("Connection from: " +
// ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress()); // ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress());
} }

View File

@ -90,7 +90,7 @@ public class LSConnectionHandler implements IoHandler {
*/ */
public void sessionCreated(IoSession session) { public void sessionCreated(IoSession session) {
session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new LSCodecFactory())); session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new LSCodecFactory()));
// System.out.println("Connection from: " + // Logging.debug("Connection from: " +
// ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress()); // ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress());
} }