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 be94d13fbe
39 changed files with 327 additions and 272 deletions

View File

@ -12,14 +12,14 @@
<delete file="${jar}" />
<delete 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>
<pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/slf4j.jar" />
<pathelement location="${lib}/pircbot.jar" />
<pathelement location="${lib}/bsh.jar" />
<pathelement location="${lib}/commons-collections-3.2.1.jar" />
<pathelement location="${lib}/xstream.jar" />
<pathelement location="${lib}/mysql-connector.jar" />
<pathelement location="${lib}/hex-string.jar" />
@ -47,6 +47,7 @@
<pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/bsh.jar" />
<pathelement location="${lib}/commons-collections-3.2.1.jar" />
<pathelement location="${lib}/pircbot.jar" />
<pathelement location="${lib}/slf4j.jar" />
<pathelement location="${lib}/xstream.jar" />

Binary file not shown.

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();
}
public static CacheHandler getCacheHandler() {
return CacheHandler.getCache();
}
public static PluginHandler getPluginHandler() {
return PluginHandler.getPluginHandler();
}

View File

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

View File

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

View File

@ -384,7 +384,7 @@ public final class ClientUpdater implements Processor {
if (p.destroyed()) {
return;
}
long curTime = System.currentTimeMillis();
long curTime = GameEngine.getTime();
if (curTime - p.getLastPing() >= 30000) {
p.destroy(false);
} else if (p.warnedToMove()) {

View File

@ -15,7 +15,6 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.mina.common.IoSession;
import org.moparscape.msc.config.Constants;
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.PersistenceManager;
/**
* The central motor of the game. This class is responsible for the primary
* operation of the entire game.
@ -56,6 +54,7 @@ public final class GameEngine extends Thread {
public static Captcha getCaptcha() {
return captcha;
}
/**
* 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
*/
private long lastSentClientUpdate = System.currentTimeMillis();
private long lastSentClientUpdateFast = System.currentTimeMillis();
private long lastSentClientUpdate = GameEngine.getTime();
private long lastSentClientUpdateFast = GameEngine.getTime();
private long lastCleanedChatlogs = 0;
private int lastCleanedChatlogsOutput = 0;
/**
@ -83,11 +82,25 @@ public final class GameEngine extends Thread {
* Whether the engine's thread is running
*/
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.
*/
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.
@ -108,7 +121,8 @@ public final class GameEngine extends Thread {
p.save();
p.getActionSender().sendLogout();
}
Instance.getServer().getLoginConnector().getActionSender().saveProfiles();
Instance.getServer().getLoginConnector().getActionSender()
.saveProfiles();
}
/**
@ -130,11 +144,10 @@ public final class GameEngine extends Thread {
* counts.put(addr, 0); } else c = counts.get(addr) + 1; counts.put(addr,
* c); } else { clients.put(addr, now); } } else { clients.put(addr, now); }
* }
private InetAddress getAddress(IoSession io) {
return ((InetSocketAddress) io.getRemoteAddress()).getAddress();
}
*/
*
* private InetAddress getAddress(IoSession io) { return
* ((InetSocketAddress) io.getRemoteAddress()).getAddress(); }
*/
/**
* Returns the current packet queue.
*
@ -153,7 +166,8 @@ public final class GameEngine extends Thread {
* Loads the packet handling classes from the persistence manager.
*/
protected void loadPacketHandlers() {
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager.load("PacketHandlers.xml");
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager
.load("PacketHandlers.xml");
for (PacketHandlerDef handlerDef : handlerDefs) {
try {
String className = handlerDef.getClassName();
@ -169,19 +183,22 @@ public final class GameEngine extends Thread {
}
}
}
private void processClients() {
clientUpdater.sendQueuedPackets();
long now = System.currentTimeMillis();
long now = GameEngine.getTime();
if (now - lastSentClientUpdate >= 600) {
if (now - lastSentClientUpdate >= 1000) {
//Logger.println("MAJOR UPDATE DELAYED: " + (now - lastSentClientUpdate));
// Logger.println("MAJOR UPDATE DELAYED: " + (now -
// lastSentClientUpdate));
}
lastSentClientUpdate = now;
clientUpdater.doMajor();
}
if (now - lastSentClientUpdateFast >= 104) {
if (now - lastSentClientUpdateFast >= 6000) {
//Logger.println("MINOR UPDATE DELAYED: " + (now - lastSentClientUpdateFast));
// Logger.println("MINOR UPDATE DELAYED: " + (now -
// lastSentClientUpdateFast));
}
lastSentClientUpdateFast = now;
clientUpdater.doMinor();
@ -191,34 +208,38 @@ public final class GameEngine extends Thread {
private void processEvents() {
eventHandler.doEvents();
}
/**
* Redirects system err
*/
public static void redirectSystemStreams() {
OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
String line = String.valueOf((char) b);
Logger.systemerr(line);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
String line = new String(b, off, len);
Logger.systemerr(line);
}
OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
String line = String.valueOf((char) b);
Logger.systemerr(line);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
String line = new String(b, off, len);
Logger.systemerr(line);
}
@Override
public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
};
System.setErr(new PrintStream(out, true));
}
@Override
public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
};
System.setErr(new PrintStream(out, true));
}
private void processIncomingPackets() {
for (RSCPacket p : packetQueue.getPackets()) {
IoSession session = p.getSession();
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();
// flagSession(session);
if (!written.containsKey(ip)) {
@ -227,7 +248,8 @@ public final class GameEngine extends Thread {
public void run() {
written.remove(ip);
try {
Runtime.getRuntime().exec("sudo /sbin/route delete " + ip);
Runtime.getRuntime().exec(
"sudo /sbin/route delete " + ip);
} catch (Exception err) {
System.out.println(err);
}
@ -239,7 +261,8 @@ public final class GameEngine extends Thread {
} catch (Exception err) {
System.out.println(err);
}
Logger.println("Dummy packet from " + player.getCurrentIP() + ": " + p.getID());
Logger.println("Dummy packet from " + player.getCurrentIP()
+ ": " + p.getID());
written.put(ip, 1);
}
continue;
@ -250,31 +273,37 @@ public final class GameEngine extends Thread {
try {
handler.handlePacket(p, session);
try {
if(p.getID() != 5) {
//String s = "[PACKET] " + session.getRemoteAddress().toString().replace("/", "") + " : " + p.getID()+ " ["+handler.getClass().toString()+"]" + " : "+ player.getUsername() + " : ";
//for(Byte b : p.getData())
// s += b;
//Logger.println(s);
}
if (p.getID() != 5) {
// String s = "[PACKET] " +
// session.getRemoteAddress().toString().replace("/",
// "") + " : " + p.getID()+
// " ["+handler.getClass().toString()+"]" + " : "+
// player.getUsername() + " : ";
// for(Byte b : p.getData())
// s += b;
// Logger.println(s);
}
catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
String s;
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
e.printStackTrace(pw);
pw.flush();
sw.flush();
s = sw.toString();
Logger.error("Exception with p[" + p.getID() + "] from " + player.getUsername() + " [" + player.getCurrentIP() + "]: " + s);
PrintWriter pw = new PrintWriter(sw, true);
e.printStackTrace(pw);
pw.flush();
sw.flush();
s = sw.toString();
Logger.error("Exception with p[" + p.getID() + "] from "
+ player.getUsername() + " ["
+ player.getCurrentIP() + "]: " + s);
player.getActionSender().sendLogout();
player.destroy(false);
}
} 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,55 +331,68 @@ public final class GameEngine extends Thread {
}
time = System.currentTimeMillis();
eventHandler.add(new DelayedEvent(null, 300000*10*2) { // Ran every 50*2 minutes
@Override
public void run() {
new Thread(new Runnable() {
eventHandler.add(new DelayedEvent(null, 300000 * 10 * 2) { // Ran every
// 50*2
// minutes
@Override
public void run() {
garbageCollect();
}
}).start();
}}
);
eventHandler.add(new DelayedEvent(null, 300000) { // 5 min
public void run() {
world.dbKeepAlive();
Long now = System.currentTimeMillis();
for (Player p : world.getPlayers()) {
if (now - p.getLastSaveTime() >= 900000) {
p.save();
p.setLastSaveTime(now);
new Thread(new Runnable() {
public void run() {
garbageCollect();
}
}).start();
}
}
Instance.getServer().getLoginConnector().getActionSender().saveProfiles();
}
});
});
eventHandler.add(new DelayedEvent(null, 300000) { // 5 min
public void run() {
world.dbKeepAlive();
long now = GameEngine.getTime();
for (Player p : world.getPlayers()) {
if (now - p.getLastSaveTime() >= 900000) {
p.save();
p.setLastSaveTime(now);
}
}
Instance.getServer().getLoginConnector()
.getActionSender().saveProfiles();
}
});
while (running) {
try {
Thread.sleep(50);
} catch (InterruptedException ie) {
}
Long AIDS = System.currentTimeMillis();
Long Delay;
time = System.currentTimeMillis();
long Delay;
processLoginServer();
Delay = System.currentTimeMillis() - AIDS;
if(Delay >= 1000) Logger.println("processLoginServer is taking longer than it should, exactly " + Delay + "ms");
AIDS = System.currentTimeMillis();
Delay = System.currentTimeMillis() - time;
if (Delay >= 1000)
Logger.println("processLoginServer is taking longer than it should, exactly "
+ Delay + "ms");
time = System.currentTimeMillis();
processIncomingPackets();
Delay = System.currentTimeMillis() - AIDS;
if(Delay >= 1000) Logger.println("processIncomingPackets is taking longer than it should, exactly " + Delay + "ms");
AIDS = System.currentTimeMillis();
Delay = System.currentTimeMillis() - time;
if (Delay >= 1000)
Logger.println("processIncomingPackets is taking longer than it should, exactly "
+ Delay + "ms");
time = System.currentTimeMillis();
processEvents();
Delay = System.currentTimeMillis() - AIDS;
if(Delay >= 1000) Logger.println("processEvents is taking longer than it should, exactly " + Delay + "ms");
AIDS = System.currentTimeMillis();
Delay = System.currentTimeMillis() - time;
if (Delay >= 1000)
Logger.println("processEvents is taking longer than it should, exactly "
+ Delay + "ms");
time = System.currentTimeMillis();
processClients();
Delay = System.currentTimeMillis() - AIDS;
if(Delay >= 1000) Logger.println("processClients is taking longer than it should, exactly " + Delay + "ms");
AIDS = System.currentTimeMillis();
Delay = System.currentTimeMillis() - time;
if (Delay >= 1000)
Logger.println("processClients is taking longer than it should, exactly "
+ Delay + "ms");
time = System.currentTimeMillis();
cleanSnapshotDeque();
Delay = System.currentTimeMillis() - AIDS;
if(Delay >= 1000) Logger.println("processSnapshotDeque is taking longer than it should, exactly " + Delay + "ms");
Delay = System.currentTimeMillis() - time;
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)
*/
public void cleanSnapshotDeque() {
long curTime = System.currentTimeMillis();
long curTime = GameEngine.getTime();
if (curTime - lastCleanedChatlogs > 1000) {
lastCleanedChatlogs = curTime;
lastCleanedChatlogsOutput++;
if(lastCleanedChatlogsOutput > 60*5) {
if (lastCleanedChatlogsOutput > 60 * 5) {
Logger.println("----------------------------------------------");
Logger.println(world.getSnapshots().size() + " items on deque");
}
@ -373,25 +415,27 @@ public final class GameEngine extends Thread {
if (curTime - s.getTimestamp() > 60000) {
i.remove();
s = null;
}
else {
} else {
s = null;
}
}
i = null;
if(lastCleanedChatlogsOutput > 60*5) {
Logger.println(world.getSnapshots().size() + " items on deque AFTER CLEANUP");
if (lastCleanedChatlogsOutput > 60 * 5) {
Logger.println(world.getSnapshots().size()
+ " items on deque AFTER CLEANUP");
Logger.println("----------------------------------------------");
lastCleanedChatlogsOutput = 0;
}
}
}
/**
* Cleans garbage (Tilecleanup)
*/
public synchronized void garbageCollect() {
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 cleaned = 0;
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];
if (tile != null) {
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;
cleaned++;
}
@ -407,9 +452,13 @@ public final class GameEngine extends Thread {
}
}
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 | Memory before: " + curMemory + "kb" + " Memory after: " + newMemory + " (Freed: " + (curMemory - newMemory) + "kb)");
Logger.println("GARBAGE COLLECT | Cleanup took " + (System.currentTimeMillis() - startTime) + "ms");
Logger.println("GARBAGE COLLECT | Memory before: " + curMemory + "kb"
+ " 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 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.World;
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) {
long time = System.currentTimeMillis()/1000;
long time = GameEngine.getTime()/1000;
String f = org.moparscape.msc.gs.tools.DataConversions.hashToUsername(from);
String a = org.moparscape.msc.gs.tools.DataConversions.hashToUsername(about);
@ -123,7 +124,7 @@ public class ReportHandlerQueries {
insertNewDupeDataRow.setString(1, username);
insertNewDupeDataRow.setLong(2, hash);
insertNewDupeDataRow.setString(3, data.toString());
insertNewDupeDataRow.setLong(4,System.currentTimeMillis());
insertNewDupeDataRow.setLong(4,GameEngine.getTime());
insertNewDupeDataRow.executeUpdate();
} catch (SQLException e) {
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.core.DelayedEventHandler;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.World;
@ -9,7 +10,7 @@ public abstract class DelayedEvent {
public static final World world = Instance.getWorld();
protected int delay = 500;
protected final DelayedEventHandler handler = Instance.getWorld().getDelayedEventHandler();
private long lastRun = System.currentTimeMillis();
private long lastRun = GameEngine.getTime();
protected Player owner;
protected boolean matchRunning = true;
public Object[] args = null;
@ -65,7 +66,7 @@ public abstract class DelayedEvent {
}
public final boolean shouldRun() {
return matchRunning && System.currentTimeMillis() - lastRun >= delay;
return matchRunning && GameEngine.getTime() - lastRun >= delay;
}
public final void stop() {
@ -73,11 +74,11 @@ public abstract class DelayedEvent {
}
public int timeTillNextRun() {
int time = (int) (delay - (System.currentTimeMillis() - lastRun));
int time = (int) (delay - (GameEngine.getTime() - lastRun));
return time < 0 ? 0 : time;
}
public final void updateLastRun() {
lastRun = System.currentTimeMillis();
lastRun = GameEngine.getTime();
}
}

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package org.moparscape.msc.gs.model;
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.DuelEvent;
import org.moparscape.msc.gs.event.FightEvent;
@ -53,8 +54,8 @@ public abstract class Mob extends Entity {
/**
* Time of last movement, used for timeout
*/
protected long lastMovement = System.currentTimeMillis();
public long lastTimeShot = System.currentTimeMillis();
protected long lastMovement = GameEngine.getTime();
public long lastTimeShot = GameEngine.getTime();
protected int mobSprite = 1;
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() {
combatTimer = System.currentTimeMillis();
combatTimer = GameEngine.getTime();
}
public abstract void setHits(int lvl);
@ -261,7 +262,7 @@ public abstract class Mob extends Entity {
}
public void setLastMoved() {
lastMovement = System.currentTimeMillis();
lastMovement = GameEngine.getTime();
}
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.Formulae;
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.FightEvent;
import org.moparscape.msc.gs.external.EntityHandler;
@ -315,7 +316,7 @@ public class Npc extends Mob {
if (hasRan()) {
return null;
}
long now = System.currentTimeMillis();
long now = GameEngine.getTime();
if (getChasing() != null) {
return null;
}
@ -534,7 +535,7 @@ public class Npc extends Mob {
}
public void updatePosition() {
long now = System.currentTimeMillis();
long now = GameEngine.getTime();
Player victim = null;
if (!isBusy() && def.isAggressive() && now - getCombatTimer() > 3000 && (victim = findVictim()) != null) {
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.connection.LSPacket;
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.event.DelayedEvent;
import org.moparscape.msc.gs.event.MiniEvent;
@ -64,24 +65,24 @@ public final class Player extends Mob {
private int lastwithdrawamount = 0;
public void setLastWithdrawTime(int itemid, int amount) {
this.lastwithdrawtime = System.currentTimeMillis();
this.lastwithdrawtime = GameEngine.getTime();
lastwithdrawitem = itemid;
lastwithdrawamount = amount;
}
public void setLastDepositTime(int itemid, int amount) {
this.lastbanktime = System.currentTimeMillis();
this.lastbanktime = GameEngine.getTime();
lastdepositeditem = itemid;
lastdepositedamount = amount;
}
public void setLastInvTime(int itemposition) {
this.lastinvtime = System.currentTimeMillis();
this.lastinvtime = GameEngine.getTime();
lastitemposition = itemposition;
}
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;
if(amount == 0)
return false;
@ -89,7 +90,7 @@ public final class Player extends Mob {
}
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;
if(amount == 0)
return false;
@ -99,7 +100,7 @@ public final class Player extends Mob {
private int lastitemposition = 0;
public boolean shouldThrowInvError(int itemposition) {
if(System.currentTimeMillis() - lastinvtime < 100 && lastitemposition == itemposition)
if(GameEngine.getTime() - lastinvtime < 100 && lastitemposition == itemposition)
return false;
return true;
@ -113,7 +114,7 @@ public final class Player extends Mob {
public boolean hasAdminPriv = false;
public boolean hasModPriv = 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
* send them any minor updates.
@ -234,7 +235,7 @@ public final class Player extends Mob {
public int tempy = -1;
public Npc lastNpcChasingYou = null;
public long lastNPCChat = System.currentTimeMillis();
public long lastNPCChat = GameEngine.getTime();
public boolean doricDependency = false;
public boolean flagCarrier = false;
@ -249,13 +250,13 @@ public final class Player extends Mob {
public void addInterval() {
if (lastInterval == 0) {
lastInterval = System.currentTimeMillis();
lastInterval = GameEngine.getTime();
} else {
intervals.addFirst(System.currentTimeMillis() - lastInterval);
intervals.addFirst(GameEngine.getTime() - lastInterval);
if (intervals.size() > 75) {
intervals.removeLast();
}
lastInterval = System.currentTimeMillis();
lastInterval = GameEngine.getTime();
}
}
@ -286,7 +287,7 @@ public final class Player extends Mob {
* @return
*/
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
*/
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
*/
//
public long lastCast = System.currentTimeMillis();
public long lastCast = GameEngine.getTime();
/**
* Time of last charge spell
*/
@ -492,7 +493,7 @@ public final class Player extends Mob {
* Last packet count time
*/
private long lastCount = 0;
public long lastDeath = System.currentTimeMillis();
public long lastDeath = GameEngine.getTime();
/**
* Stores the last IP address used
*/
@ -503,7 +504,7 @@ public final class Player extends Mob {
private long lastLogin = 0;
// Player(IoSession
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
*/
@ -512,20 +513,20 @@ public final class Player extends Mob {
/**
* Last time a 'ping' was received
*/
private long lastPing = System.currentTimeMillis();
private long lastPing = GameEngine.getTime();
public String lastPlayerInfo2 = null;
private int lastQuestMenuReply = -1;
// don't remove this. -xEnt
public int lastRandom = 0;
public long lastRange = System.currentTimeMillis();
public long lastRange = GameEngine.getTime();
/**
* Time last report was sent, used to throttle reports
*/
private long lastReport = 0;
public long lastRun = System.currentTimeMillis(); // Leave this here
private long lastSaveTime = System.currentTimeMillis()
public long lastRun = GameEngine.getTime(); // Leave this here
private long lastSaveTime = GameEngine.getTime()
+ 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
*/
@ -708,14 +709,14 @@ public final class Player extends Mob {
*/
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.
*/
public void setLastInfected() {
lastInfected = System.currentTimeMillis();
lastInfected = GameEngine.getTime();
}
/*
@ -750,7 +751,7 @@ public final class Player extends Mob {
ioSession = ios;
currentIP = ((InetSocketAddress) ios.getRemoteAddress()).getAddress()
.getHostAddress();
currentLogin = System.currentTimeMillis();
currentLogin = GameEngine.getTime();
actionSender = new MiscPacketBuilder(this);
setBusy(true);
Instance.getWorld();
@ -768,7 +769,7 @@ public final class Player extends Mob {
}
public void addAttackedBy(Player p) {
attackedBy.put(p.getUsernameHash(), System.currentTimeMillis());
attackedBy.put(p.getUsernameHash(), GameEngine.getTime());
}
public void addFriend(long id, int world) {
@ -787,7 +788,7 @@ public final class Player extends Mob {
}
public void addPacket(RSCPacket p) {
long now = System.currentTimeMillis();
long now = GameEngine.getTime();
if (now - lastCount > 3000) {
lastCount = now;
packetCount = 0;
@ -838,7 +839,7 @@ public final class Player extends Mob {
super.setAppearnceChanged(true);
}
skullEvent
.setLastRun(System.currentTimeMillis() - (1200000 - timeLeft));
.setLastRun(GameEngine.getTime() - (1200000 - timeLeft));
}
public void addToDuelOffer(InvItem item) {
@ -851,20 +852,20 @@ public final class Player extends Mob {
public boolean canLogout() {
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!");
return false;
}
}
return !isBusy() && System.currentTimeMillis() - getCombatTimer() > 10000;
return !isBusy() && GameEngine.getTime() - getCombatTimer() > 10000;
}
public boolean canReport() {
return System.currentTimeMillis() - lastReport > 60000;
return GameEngine.getTime() - lastReport > 60000;
}
public boolean castTimer() {
return System.currentTimeMillis() - lastSpellCast > 1200;
return GameEngine.getTime() - lastSpellCast > 1200;
}
public boolean checkAttack(Mob mob, boolean missile) {
@ -894,7 +895,7 @@ public final class Player extends Mob {
return true;
}
}
if (System.currentTimeMillis() - mob.getCombatTimer() < (mob
if (GameEngine.getTime() - mob.getCombatTimer() < (mob
.getCombatState() == CombatState.RUNNING
|| mob.getCombatState() == CombatState.WAITING ? 3000 : 500)
&& !mob.inCombat()) {
@ -978,11 +979,11 @@ public final class Player extends Mob {
destroy = true;
actionSender.sendLogout();
} else {
final long startDestroy = System.currentTimeMillis();
final long startDestroy = GameEngine.getTime();
Instance.getDelayedEventHandler().add(new DelayedEvent(this, 3000) {
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);
matchRunning = false;
}
@ -999,11 +1000,11 @@ public final class Player extends Mob {
destroy = true;
actionSender.sendLogout();
} else {
final long startDestroy = System.currentTimeMillis();
final long startDestroy = GameEngine.getTime();
Instance.getDelayedEventHandler().add(new DelayedEvent(this, 3000) {
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);
matchRunning = false;
}
@ -1115,7 +1116,7 @@ public final class Player extends Mob {
}
public int getDaysSubscriptionLeft() {
long now = (System.currentTimeMillis() / 1000);
long now = (GameEngine.getTime() / 1000);
if (subscriptionExpires == 0 || now >= subscriptionExpires) {
return 0;
}
@ -1379,8 +1380,7 @@ public final class Player extends Mob {
}
public int getSpellWait() {
return DataConversions.roundUp((double) (1200 - (System
.currentTimeMillis() - lastSpellCast)) / 1000D);
return DataConversions.roundUp((double) (1200 - (GameEngine.getTime() - lastSpellCast)) / 1000D);
}
public Action getStatus() {
@ -1638,7 +1638,7 @@ public final class Player extends Mob {
}
public boolean isCharged() {
return System.currentTimeMillis() - lastCharge < 600000;
return GameEngine.getTime() - lastCharge < 600000;
}
public boolean isDuelConfirmAccepted() {
@ -1806,7 +1806,7 @@ public final class Player extends Mob {
opponent.resetCombat(CombatState.WON);
}
actionSender.sendSound("death");
lastDeath = System.currentTimeMillis();
lastDeath = GameEngine.getTime();
actionSender.sendDied();
for (int i = 0; i < 18; i++) {
curStat[i] = maxStat[i];
@ -1979,7 +1979,7 @@ public final class Player extends Mob {
}
public void ping() {
lastPing = System.currentTimeMillis();
lastPing = GameEngine.getTime();
}
public void remove() {
@ -2215,7 +2215,7 @@ public final class Player extends Mob {
}
public void setArrowFired() {
lastArrow = System.currentTimeMillis();
lastArrow = GameEngine.getTime();
}
public void setBank(Bank b) {
@ -2223,7 +2223,7 @@ public final class Player extends Mob {
}
public void setCastTimer() {
lastSpellCast = System.currentTimeMillis();
lastSpellCast = GameEngine.getTime();
}
public void setChangingAppearance(boolean b) {
@ -2231,7 +2231,7 @@ public final class Player extends Mob {
}
public void setCharged() {
lastCharge = System.currentTimeMillis();
lastCharge = GameEngine.getTime();
}
public void setClassName(String className) {
@ -2373,7 +2373,7 @@ public final class Player extends Mob {
}
public void setLastReport() {
lastReport = System.currentTimeMillis();
lastReport = GameEngine.getTime();
}
public void setLastSaveTime(long save) {
@ -2386,7 +2386,7 @@ public final class Player extends Mob {
public void setLoggedIn(boolean loggedIn) {
if (loggedIn) {
currentLogin = System.currentTimeMillis();
currentLogin = GameEngine.getTime();
}
this.loggedIn = loggedIn;
}
@ -2446,7 +2446,7 @@ public final class Player extends Mob {
if (save) {
// save();
setLastSaveTime(System.currentTimeMillis());
setLastSaveTime(GameEngine.getTime());
getActionSender().sendQuestInfo();
getActionSender().sendMessage(
"@gre@You just gained " + gained + " quest point"
@ -2530,7 +2530,7 @@ public final class Player extends Mob {
public void setSkulledOn(Player player) {
player.addAttackedBy(this);
if (System.currentTimeMillis() - lastAttackedBy(player) > 1200000) {
if (GameEngine.getTime() - lastAttackedBy(player) > 1200000) {
addSkull(1200000);
}
}
@ -2552,7 +2552,7 @@ public final class Player extends Mob {
}
public void setSpellFail() {
lastSpellCast = System.currentTimeMillis() + 20000;
lastSpellCast = GameEngine.getTime() + 20000;
}
public void setStatus(Action a) {
@ -2643,7 +2643,7 @@ public final class Player extends Mob {
}
public boolean tradeDuelThrottling() {
long now = System.currentTimeMillis();
long now = GameEngine.getTime();
if (now - lastTradeDuelRequest > 1000) {
lastTradeDuelRequest = now;
return false;

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@ import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet;
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.RangeEvent;
import org.moparscape.msc.gs.event.WalkToMobEvent;
@ -76,7 +77,7 @@ public class AttackHandler implements PacketHandler {
if (affectedMob instanceof Player) {
Player opp = (Player) affectedMob;
if (System.currentTimeMillis() - opp.lastMineTimer < 2000 && opp.isBusy())
if (GameEngine.getTime() - opp.lastMineTimer < 2000 && opp.isBusy())
cont = true;
}
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.connection.Packet;
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.event.MiniEvent;
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 {
MiscPacketBuilder loginServer = Instance.getServer().getLoginConnector().getActionSender();
if(System.currentTimeMillis() - player.lastCommandUsed < 2000 && !player.isMod()) {
if(System.currentTimeMillis() - player.lastCommandUsed < 100) { // incase spammers
if(GameEngine.getTime() - player.lastCommandUsed < 2000 && !player.isMod()) {
if(GameEngine.getTime() - player.lastCommandUsed < 100) { // incase spammers
return;
}
player.getActionSender().sendMessage("2 second delay on using a new command");
return;
}
player.lastCommandUsed = System.currentTimeMillis();
player.lastCommandUsed = GameEngine.getTime();
if (cmd.equals("help")) {
player.getActionSender().sendAlert("List of commands are shown on forums!", true);
return;
@ -89,20 +90,20 @@ public class CommandHandler implements PacketHandler {
}
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");
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!");
return;
}
if (player.getLocation().inModRoom() && !player.isMod()) {
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("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());
player.setCastTimer();
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.connection.Packet;
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.SingleEvent;
import org.moparscape.msc.gs.event.WalkToMobEvent;
@ -246,7 +247,7 @@ public class DuelHandler implements PacketHandler {
affectedPlayer.setBusy(false);
}
};
walking.setLastRun(System.currentTimeMillis() + 500);
walking.setLastRun(GameEngine.getTime() + 500);
Instance.getDelayedEventHandler().add(walking);
}
break;

View File

@ -3,6 +3,7 @@ package org.moparscape.msc.gs.phandler.client;
import org.apache.mina.common.IoSession;
import org.moparscape.msc.gs.Instance;
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.World;
import org.moparscape.msc.gs.model.snapshot.Activity;
@ -26,7 +27,7 @@ public class FollowRequest implements PacketHandler {
player.resetPath();
return;
}
if (System.currentTimeMillis() - player.lastRun < 3000)
if (GameEngine.getTime() - player.lastRun < 3000)
return;
player.resetAll();
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.Server;
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.MiniEvent;
import org.moparscape.msc.gs.event.SingleEvent;
@ -174,7 +175,7 @@ public class InvActionHandler implements PacketHandler {
} else if (item.getDef().getCommand().equalsIgnoreCase("open")) {
if(item.getID() == INFECTED_BLOOD) {
if(!player.isInfected()) { player.setInfected(); return; }
long lastUsed = System.currentTimeMillis() - player.lastInfected();
long lastUsed = GameEngine.getTime() - player.lastInfected();
long remaining = 5 - lastUsed / 1000;
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; }

View File

@ -8,6 +8,7 @@ import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.Server;
import org.moparscape.msc.gs.connection.Packet;
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.ShortEvent;
import org.moparscape.msc.gs.event.WalkToObjectEvent;
@ -466,9 +467,9 @@ public class InvUseOnObject implements PacketHandler {
if (i.getID() == 517 && i.getAmount() > 20) {
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) {
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.getActionSender().sendInventory();
return;

View File

@ -3,6 +3,7 @@ package org.moparscape.msc.gs.phandler.client;
import org.apache.mina.common.IoSession;
import org.moparscape.msc.gs.Instance;
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.WalkToMobEvent;
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
return;
}
if (System.currentTimeMillis() - affectedPlayer.lastRun < 2000) {
if (GameEngine.getTime() - affectedPlayer.lastRun < 2000) {
player.resetPath();
return;
}

View File

@ -9,6 +9,7 @@ import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.Server;
import org.moparscape.msc.gs.connection.Packet;
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.MiniEvent;
import org.moparscape.msc.gs.event.ShortEvent;
@ -132,7 +133,7 @@ public class ObjectAction implements PacketHandler {
String command = (click == 0 ? def.getCommand1() : def.getCommand2()).toLowerCase();
// System.out.println(object.getID() + " " +
// 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);
if (telePoint != null) {
owner.teleport(telePoint.getX(), telePoint.getY(), false);

View File

@ -9,6 +9,7 @@ import org.apache.mina.common.IoSession;
import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.connection.Packet;
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.World;
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 {
Player player = (Player) session.getAttachment();
int pID = ((RSCPacket) p).getID();
long now = System.currentTimeMillis();
long now = GameEngine.getTime();
try {
String sleepword_result = ((RSCPacket) p).readString().trim();
if (System.currentTimeMillis() - player.getLastSleepTime() < 1000)
if (GameEngine.getTime() - player.getLastSleepTime() < 1000)
return;
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.connection.Packet;
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.ObjectRemover;
import org.moparscape.msc.gs.event.WalkMobToMobEvent;
@ -121,7 +122,7 @@ public class SpellHandler implements PacketHandler {
private Random r = new Random();
private void finalizeSpell(Player player, SpellDef spell) {
player.lastCast = System.currentTimeMillis();
player.lastCast = GameEngine.getTime();
player.getActionSender().sendSound("spellok");
player.getActionSender().sendMessage("Cast spell successfully");
player.setCastTimer();
@ -398,12 +399,12 @@ public class SpellHandler implements PacketHandler {
}
if (affectedMob instanceof Player) {
Player other = (Player) affectedMob;
if (player.getLocation().inWilderness() && System.currentTimeMillis() - other.lastRun < 1000) {
if (player.getLocation().inWilderness() && GameEngine.getTime() - other.lastRun < 1000) {
player.resetPath();
return;
}
}
if (player.getLocation().inWilderness() && System.currentTimeMillis() - player.lastRun < 3000) {
if (player.getLocation().inWilderness() && GameEngine.getTime() - player.lastRun < 3000) {
player.resetPath();
return;
}

View File

@ -7,6 +7,7 @@ import org.apache.mina.common.IoSession;
import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance;
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.model.ChatMessage;
import org.moparscape.msc.gs.model.Npc;
@ -32,10 +33,10 @@ public class TalkToNpcHandler implements PacketHandler {
player.resetPath();
return;
}
if (System.currentTimeMillis() - player.lastNPCChat < 1500)
if (GameEngine.getTime() - player.lastNPCChat < 1500)
return;
player.setLastQuestMenuReply(-2);
player.lastNPCChat = System.currentTimeMillis();
player.lastNPCChat = GameEngine.getTime();
player.resetAll();
final Npc affectedNpc = world.getNpc(p.readShort());
if (affectedNpc == null || !world.getQuestManager().isNpcVisible(affectedNpc, player)) {

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.connection.Packet;
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.external.ItemDef;
import org.moparscape.msc.gs.model.InvItem;
@ -225,7 +226,7 @@ public class TradeHandler implements PacketHandler {
player.getActionSender().sendInventory();
player.getActionSender().sendEquipmentStats();
Long now = System.currentTimeMillis();
long now = GameEngine.getTime();
player.save();
player.setLastSaveTime(now);
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.connection.Packet;
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.MiniEvent;
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.");
return;
}
player.lastRun = System.currentTimeMillis();
player.lastRun = GameEngine.getTime();
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 IoSession newsession = session;
Instance.getDelayedEventHandler().add(new MiniEvent(player, 2000) {
@ -127,11 +128,11 @@ public class WalkRequest implements PacketHandler {
} else {
return;
}
} else if (player.isBusy() && System.currentTimeMillis() - player.lastMineTimer > 2000) {
} else if (player.isBusy() && GameEngine.getTime() - player.lastMineTimer > 2000) {
return;
}
if (System.currentTimeMillis() - player.lastCast < 600)
if (GameEngine.getTime() - player.lastCast < 600)
return;
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.connection.Packet;
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.WalkToPointEvent;
import org.moparscape.msc.gs.external.DoorDef;
@ -111,7 +112,7 @@ public class WallObjectAction implements PacketHandler {
if (object.getX() != 282 || object.getY() != 3020) {
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");
return;
}

View File

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

View File

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

View File

@ -10,6 +10,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
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.InvItem;
import org.moparscape.msc.gs.model.Item;
@ -105,7 +106,7 @@ public class QuestManager {
*/
public final boolean loadQuests() {
try {
long start = System.currentTimeMillis();
long start = GameEngine.getTime();
if (quests != null)
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) {
e.printStackTrace();
return false;

View File

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

View File

@ -10,13 +10,11 @@
<delete file="${jar}" />
<delete 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>
<pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/slf4j.jar" />
<pathelement location="${lib}/xstream.jar" />
<pathelement location="${lib}/mysql-connector.jar" />
<pathelement location="${lib}/hex-string.jar" />