mirror of
https://github.com/moparisthebest/MoparClassic
synced 2024-11-12 20:25:01 -05:00
Merge pull request #2 from CodeForFame/master
This commit is contained in:
parent
9fa8583303
commit
58a6016ad5
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
.classpath
|
||||
.project
|
||||
*.jar
|
||||
rscd.jar
|
||||
ls.jar
|
||||
*.ipr
|
||||
*.iws
|
||||
*.iml
|
||||
|
25
GameServer/alert-config.xml
Normal file
25
GameServer/alert-config.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<alert>
|
||||
<credentials>
|
||||
<!-- This is used for e-mails. -->
|
||||
<protocol>smtps</protocol>
|
||||
<host>smtp.gmail.com</host>
|
||||
<port>465</port>
|
||||
<auth>true</auth>
|
||||
<user>moparalert@gmail.com</user>
|
||||
<pass>supersecretpass</pass>
|
||||
</credentials>
|
||||
<user>
|
||||
<name>Example</name>
|
||||
<email>
|
||||
<address>codeforfame@gmail.com</address>
|
||||
<priority>10</priority>
|
||||
</email>
|
||||
</user>
|
||||
<user>
|
||||
<name>Example1</name>
|
||||
<email>
|
||||
<address>codeforfame@gmail.com</address>
|
||||
<priority>1</priority>
|
||||
</email>
|
||||
</user>
|
||||
</alert>
|
@ -7,13 +7,39 @@
|
||||
<property name="jar" location="rscd.jar" />
|
||||
<property name="settings" location="settings.ini" />
|
||||
<property name="quests" location="conf/server/quests" />
|
||||
<property name="scala-library.jar" value="lib/scala-library.jar" />
|
||||
|
||||
<target name="build">
|
||||
<delete file="${jar}" />
|
||||
<delete dir="${build}" />
|
||||
<mkdir dir="${build}" />
|
||||
<taskdef resource="scala/tools/ant/antlib.xml">
|
||||
<classpath>
|
||||
<pathelement location="lib/scala-compiler.jar" />
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
</classpath>
|
||||
</taskdef>
|
||||
<scalac srcdir="${src}" destdir="${build}">
|
||||
<classpath>
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="${lib}/mina.jar" />
|
||||
<pathelement location="${lib}/xpp3.jar" />
|
||||
<pathelement location="${lib}/slf4j.jar" />
|
||||
<pathelement location="${lib}/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" />
|
||||
<pathelement location="${lib}/jmf.jar" />
|
||||
<pathelement location="${lib}/mail.jar" />
|
||||
<pathelement path="${java.class.path}/" />
|
||||
</classpath>
|
||||
<include name="**/*.scala" />
|
||||
</scalac>
|
||||
<javac srcdir="${src}" destdir="${build}" debug="on" target="1.6">
|
||||
<classpath>
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="${lib}/mina.jar" />
|
||||
<pathelement location="${lib}/xpp3.jar" />
|
||||
<pathelement location="${lib}/slf4j.jar" />
|
||||
|
BIN
GameServer/lib/mail.jar
Normal file
BIN
GameServer/lib/mail.jar
Normal file
Binary file not shown.
BIN
GameServer/lib/scala-compiler.jar
Normal file
BIN
GameServer/lib/scala-compiler.jar
Normal file
Binary file not shown.
BIN
GameServer/lib/scala-library.jar
Normal file
BIN
GameServer/lib/scala-library.jar
Normal file
Binary file not shown.
@ -18,18 +18,30 @@ public class Config {
|
||||
public static String MYSQL_USER;
|
||||
public static String MYSQL_PASS;
|
||||
|
||||
public static String SERVER_IP, SERVER_NAME, RSCD_HOME, CONF_DIR,
|
||||
SERVER_LOCATION, LS_IP;
|
||||
|
||||
public static String SERVER_IP, SERVER_NAME, RSCD_HOME, CONF_DIR, SERVER_LOCATION, LS_IP;
|
||||
|
||||
public static int SERVER_PORT, SERVER_VERSION, MAX_PLAYERS, LS_PORT, SERVER_NUM;
|
||||
public static int SERVER_PORT, SERVER_VERSION, MAX_PLAYERS, LS_PORT,
|
||||
SERVER_NUM;
|
||||
|
||||
public static long START_TIME;
|
||||
|
||||
public static boolean members, f2pWildy;
|
||||
|
||||
public static double expRate, subExpRate;
|
||||
|
||||
public static String[] pmods, mods, admins;
|
||||
public static int IP_BAN_REMOVAL_DELAY;
|
||||
public static int GARBAGE_COLLECT_INTERVAL;
|
||||
public static int SAVE_INTERVAL;
|
||||
public static String DATE_FORMAT;
|
||||
public static String BLOCK_COMMAND;
|
||||
public static String UNBLOCK_COMMAND;
|
||||
|
||||
static {
|
||||
loadEnv();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called to load config settings from the given file
|
||||
*
|
||||
@ -61,7 +73,32 @@ public class Config {
|
||||
LS_PORT = Integer.parseInt(props.getProperty("lsport"));
|
||||
SERVER_NUM = Integer.parseInt(props.getProperty("servernum"));
|
||||
|
||||
members = Boolean.parseBoolean(props.getProperty("members", "false"));
|
||||
f2pWildy = Boolean.parseBoolean(props.getProperty("f2pWildy", "true"));
|
||||
expRate = Double.parseDouble(props.getProperty("expRate"));
|
||||
subExpRate = Double.parseDouble(props.getProperty("subExpRate"));
|
||||
|
||||
pmods = props.getProperty("pmods").replaceAll(", +", ",").split(",");
|
||||
mods = props.getProperty("mods").replaceAll(", +", ",").split(",");
|
||||
admins = props.getProperty("admins").replaceAll(", +", ",").split(",");
|
||||
|
||||
IP_BAN_REMOVAL_DELAY = Integer.parseInt(props
|
||||
.getProperty("ip-ban-removal-delay"));
|
||||
BLOCK_COMMAND = props.getProperty("block-command");
|
||||
UNBLOCK_COMMAND = props.getProperty("unblock-command");
|
||||
|
||||
GARBAGE_COLLECT_INTERVAL = Integer.parseInt(props
|
||||
.getProperty("garbage-collect-interval"));
|
||||
SAVE_INTERVAL = Integer.parseInt(props.getProperty("save-interval"));
|
||||
|
||||
DATE_FORMAT = props.getProperty("date-format");
|
||||
|
||||
props.clear();
|
||||
|
||||
Constants.GameServer.MOTD = "@yel@Welcome to @whi@"
|
||||
+ Config.SERVER_NAME + "@yel@ - World @whi@"
|
||||
+ (Config.SERVER_NUM == 0 ? 2 : Config.SERVER_NUM) + " ("
|
||||
+ (Config.members ? "P2P" : "F2P") + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,40 +13,10 @@ public class Constants {
|
||||
* @category GameServer
|
||||
*/
|
||||
public static class GameServer {
|
||||
/**
|
||||
* Used throughout strings ingame, this is your Server's name.
|
||||
*/
|
||||
public static final String SERVER_NAME = "MoparScape Classic";
|
||||
/**
|
||||
* Set by runtime arguments. Is this World a Members/Subscriber (P2P)
|
||||
* world?
|
||||
*/
|
||||
public static boolean MEMBER_WORLD = false;
|
||||
/**
|
||||
* Is this wilderness fully f2p (no p2p weapons, items etc)
|
||||
*/
|
||||
public static boolean F2P_WILDY = true;
|
||||
/**
|
||||
* Our World's Number, Gets set upon launch.
|
||||
*/
|
||||
public static int WORLD_NUMBER = 0;
|
||||
/**
|
||||
* Message of the Day (Seen as you log in)
|
||||
*/
|
||||
public static String MOTD = "";
|
||||
/**
|
||||
* Exp Rate multiplier per kill.
|
||||
*/
|
||||
public static final double EXP_RATE = 4.0;
|
||||
/**
|
||||
* Subscribed Exp Rate multiplier per kill.
|
||||
*/
|
||||
public static final double SUB_EXP_RATE = 4.0;
|
||||
/**
|
||||
* The amount of players on this server.
|
||||
*/
|
||||
public static int ONLINE_COUNT = Instance.getWorld().getPlayers()
|
||||
.size();
|
||||
/**
|
||||
* Each time a connection is made to the server, this is incremented.
|
||||
*/
|
||||
@ -83,54 +53,6 @@ public class Constants {
|
||||
public static final int[] NPCS_THAT_DONT_RETREAT = { 65, 102, 100, 127,
|
||||
258 };
|
||||
|
||||
public static final String[] PMODS = { "There are currently no PMODS" };
|
||||
public static final String[] MODS = { "Mod Jake", "Mod Robert",
|
||||
"Mod x0x0", "Mod Andrew", "Mod Trauma", "Mod Andrew",
|
||||
"Mod Miku" };
|
||||
|
||||
public static final String[] ADMINS = { "Mod Necroth", "KO9" };
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @category IRC
|
||||
*/
|
||||
public static class IRC {
|
||||
/**
|
||||
* to enable IRC integration or not.
|
||||
*/
|
||||
public static boolean USE_IRC = false;
|
||||
/**
|
||||
* Hosts of the IRC channels
|
||||
*/
|
||||
public static final String[] HOSTS = { "irc.shakeababy.net" };
|
||||
/**
|
||||
* Channels for the IRC bot to join Passwords in the second dimention
|
||||
*/
|
||||
public static final String[][] CHANNELS = { {
|
||||
"#org.moparscape.msc.staff", "staffonly" } };
|
||||
/**
|
||||
* Channel for the IRC bot to join
|
||||
*/
|
||||
public static final String NICK = "msc_"
|
||||
+ (GameServer.MEMBER_WORLD ? "P2P" : "F2P") + "_"
|
||||
+ Formulae.Rand(0, 900);
|
||||
/**
|
||||
* the login/full name thing IRC wants. [NOT NICKNAME]
|
||||
*/
|
||||
public static final String USER = "org.moparscape.msc";
|
||||
/**
|
||||
* Each person in here is their IRC name, if they are in here ALL
|
||||
* Moderator in-game activities will be sent to them via PM.
|
||||
*/
|
||||
public static final String[] ADMINISTRATORS = { "KO9", "ollie",
|
||||
"Necroth", "Melshef" };
|
||||
/**
|
||||
* Banned words you don't want your IRCBot to say (Optional) {Banned
|
||||
* word, new mask}
|
||||
*/
|
||||
public static final String[][] BANNED_WORDS = { { "stork",
|
||||
"org.moparscape.msc" } };
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -940,7 +940,7 @@ public class Formulae {
|
||||
* 0.25) newPrice = i.getDef().basePrice + (int) (i.getDef().basePrice *
|
||||
* getShopPercentage( i, 3, true)); } if (newPrice == -1) return
|
||||
* 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
|
||||
* price is 125% // lower than base // price to begin // with if
|
||||
* (shop.isGeneral()) // 3rd party item (player sold) base = base -
|
||||
|
@ -5,7 +5,6 @@ import org.moparscape.msc.gs.db.DBConnection;
|
||||
import org.moparscape.msc.gs.db.ReportHandlerQueries;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.plugins.dependencies.PluginHandler;
|
||||
import org.moparscape.msc.irc.IRC;
|
||||
|
||||
/**
|
||||
* Holds instances to commonly used Objects.
|
||||
@ -15,10 +14,6 @@ import org.moparscape.msc.irc.IRC;
|
||||
*/
|
||||
public class Instance {
|
||||
|
||||
public static IRC getIRC() {
|
||||
return getServer().getIRC();
|
||||
}
|
||||
|
||||
public static Server getServer() {
|
||||
return World.getWorld().getServer();
|
||||
}
|
||||
|
@ -14,242 +14,226 @@ import org.apache.mina.transport.socket.nio.SocketSessionConfig;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.gs.connection.RSCConnectionHandler;
|
||||
import org.moparscape.msc.gs.connection.filter.ConnectionFilter;
|
||||
import org.moparscape.msc.gs.core.GameEngine;
|
||||
import org.moparscape.msc.gs.core.LoginConnector;
|
||||
import org.moparscape.msc.gs.event.DelayedEvent;
|
||||
import org.moparscape.msc.gs.event.SingleEvent;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.irc.IRC;
|
||||
|
||||
|
||||
/**
|
||||
* The entry point for RSC server.
|
||||
*/
|
||||
public class Server {
|
||||
|
||||
/**
|
||||
* World instance
|
||||
*/
|
||||
private static World world = null;
|
||||
/**
|
||||
* World instance
|
||||
*/
|
||||
private static World world = null;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String configFile = "world.xml";
|
||||
if (args.length > 0) {
|
||||
File f = new File(args[0]);
|
||||
if (f.exists()) {
|
||||
configFile = f.getName();
|
||||
}
|
||||
public static void main(String[] args) throws IOException {
|
||||
String configFile = "world.xml";
|
||||
if (args.length > 0) {
|
||||
File f = new File(args[0]);
|
||||
if (f.exists()) {
|
||||
configFile = f.getName();
|
||||
}
|
||||
}
|
||||
|
||||
Config.initConfig(configFile);
|
||||
world = Instance.getWorld();
|
||||
world.wl.loadObjects();
|
||||
|
||||
World.initilizeDB();
|
||||
|
||||
Logger.println(Config.SERVER_NAME + " ["
|
||||
+ (Config.members ? "P2P" : "F2P") + "] "
|
||||
+ "Server starting up...");
|
||||
|
||||
server = new Server();
|
||||
}
|
||||
|
||||
|
||||
if (args[2] != null && args[2].equalsIgnoreCase("no"))
|
||||
Constants.IRC.USE_IRC = false;
|
||||
|
||||
Constants.GameServer.MEMBER_WORLD = args[1].equalsIgnoreCase("p2p");
|
||||
Constants.GameServer.MOTD = "@yel@Welcome to @whi@" + Constants.GameServer.SERVER_NAME + "@yel@ - World @whi@" + (Constants.GameServer.WORLD_NUMBER == 0 ? 2 : Constants.GameServer.WORLD_NUMBER) + " (" + (Constants.GameServer.MEMBER_WORLD ? "P2P" : "F2P") + ")";
|
||||
|
||||
world = Instance.getWorld();
|
||||
world.wl.loadObjects();
|
||||
private static Server server;
|
||||
|
||||
Config.initConfig(configFile);
|
||||
World.initilizeDB();
|
||||
|
||||
Logger.println(Constants.GameServer.SERVER_NAME + " [" + (Constants.GameServer.MEMBER_WORLD ? "P2P" : "F2P") + "] " + "Server starting up...");
|
||||
|
||||
new Server();
|
||||
}
|
||||
|
||||
public static boolean isMembers() {
|
||||
return Constants.GameServer.MEMBER_WORLD;
|
||||
}
|
||||
|
||||
/**
|
||||
* The SocketAcceptor
|
||||
*/
|
||||
private IoAcceptor acceptor;
|
||||
/**
|
||||
* The login server connection
|
||||
*/
|
||||
private LoginConnector connector;
|
||||
/**
|
||||
* The game engine
|
||||
*/
|
||||
private GameEngine engine;
|
||||
/**
|
||||
* The IRC.
|
||||
*/
|
||||
private IRC irc;
|
||||
|
||||
public IoAcceptor getAcceptor() {
|
||||
return acceptor;
|
||||
}
|
||||
|
||||
public void setAcceptor(IoAcceptor acceptor) {
|
||||
this.acceptor = acceptor;
|
||||
}
|
||||
|
||||
public LoginConnector getConnector() {
|
||||
return connector;
|
||||
}
|
||||
|
||||
public void setConnector(LoginConnector connector) {
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
public IRC getIRC() {
|
||||
return irc;
|
||||
}
|
||||
|
||||
public void setIRC(IRC irc) {
|
||||
this.irc = irc;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
public void setRunning(boolean running) {
|
||||
this.running = running;
|
||||
}
|
||||
|
||||
public DelayedEvent getUpdateEvent() {
|
||||
return updateEvent;
|
||||
}
|
||||
|
||||
public void setUpdateEvent(DelayedEvent updateEvent) {
|
||||
this.updateEvent = updateEvent;
|
||||
}
|
||||
|
||||
public static World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setEngine(GameEngine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the server running still?
|
||||
*/
|
||||
private boolean running;
|
||||
|
||||
/**
|
||||
* Update event - if the server is shutting down
|
||||
*/
|
||||
private DelayedEvent updateEvent;
|
||||
|
||||
/**
|
||||
* Creates a new server instance, which in turn creates a new engine and
|
||||
* prepares the server socket to accept connections.
|
||||
*/
|
||||
public Server() {
|
||||
running = true;
|
||||
world.setServer(this);
|
||||
irc = new IRC();
|
||||
if (Constants.IRC.USE_IRC) {
|
||||
new Thread(irc).start();
|
||||
} else {
|
||||
Logger.println("IRC is disabled");
|
||||
public static boolean isMembers() {
|
||||
return Config.members;
|
||||
}
|
||||
try {
|
||||
Instance.getPluginHandler().initPlugins();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
/**
|
||||
* The SocketAcceptor
|
||||
*/
|
||||
private IoAcceptor acceptor;
|
||||
/**
|
||||
* The login server connection
|
||||
*/
|
||||
private LoginConnector connector;
|
||||
/**
|
||||
* The game engine
|
||||
*/
|
||||
private GameEngine engine;
|
||||
|
||||
public IoAcceptor getAcceptor() {
|
||||
return acceptor;
|
||||
}
|
||||
try {
|
||||
connector = new LoginConnector();
|
||||
engine = new GameEngine();
|
||||
engine.start();
|
||||
while (!connector.isRegistered()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1, Executors.newCachedThreadPool());
|
||||
IoAcceptorConfig config = new SocketAcceptorConfig();
|
||||
config.setDisconnectOnUnbind(true);
|
||||
|
||||
config.setThreadModel(ThreadModel.MANUAL);
|
||||
SocketSessionConfig ssc = (SocketSessionConfig) config.getSessionConfig();
|
||||
ssc.setSendBufferSize(10000);
|
||||
ssc.setReceiveBufferSize(10000);
|
||||
acceptor.bind(new InetSocketAddress(Config.SERVER_IP, Config.SERVER_PORT), new RSCConnectionHandler(engine), config);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
public void setAcceptor(IoAcceptor acceptor) {
|
||||
this.acceptor = acceptor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game engine for this server
|
||||
*/
|
||||
public GameEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
public LoginConnector getLoginConnector() {
|
||||
return connector;
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return engine != null && connector != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the game engine and irc engine
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void kill() {
|
||||
Logger.print(Constants.GameServer.SERVER_NAME + " shutting down...");
|
||||
running = false;
|
||||
engine.emptyWorld();
|
||||
connector.kill();
|
||||
if (Constants.IRC.USE_IRC) {
|
||||
Instance.getIRC().disconnect();
|
||||
Instance.getIRC().dispose();
|
||||
public LoginConnector getConnector() {
|
||||
return connector;
|
||||
}
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
public boolean running() {
|
||||
return running;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the server in 60 seconds
|
||||
*/
|
||||
public boolean shutdownForUpdate() {
|
||||
if (updateEvent != null) {
|
||||
return false;
|
||||
public void setConnector(LoginConnector connector) {
|
||||
this.connector = connector;
|
||||
}
|
||||
updateEvent = new SingleEvent(null, 59000) {
|
||||
public void action() {
|
||||
kill();
|
||||
}
|
||||
};
|
||||
Instance.getDelayedEventHandler().add(updateEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* MS till the server shuts down
|
||||
*/
|
||||
public int timeTillShutdown() {
|
||||
if (updateEvent == null) {
|
||||
return -1;
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
return updateEvent.timeTillNextRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds the socket acceptor
|
||||
*/
|
||||
public void unbind() {
|
||||
try {
|
||||
acceptor.unbindAll();
|
||||
} catch (Exception e) {
|
||||
public void setRunning(boolean running) {
|
||||
this.running = running;
|
||||
}
|
||||
|
||||
public DelayedEvent getUpdateEvent() {
|
||||
return updateEvent;
|
||||
}
|
||||
|
||||
public void setUpdateEvent(DelayedEvent updateEvent) {
|
||||
this.updateEvent = updateEvent;
|
||||
}
|
||||
|
||||
public static World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setEngine(GameEngine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the server running still?
|
||||
*/
|
||||
private boolean running;
|
||||
|
||||
/**
|
||||
* Update event - if the server is shutting down
|
||||
*/
|
||||
private DelayedEvent updateEvent;
|
||||
|
||||
/**
|
||||
* Creates a new server instance, which in turn creates a new engine and
|
||||
* prepares the server socket to accept connections.
|
||||
*/
|
||||
public Server() {
|
||||
running = true;
|
||||
world.setServer(this);
|
||||
try {
|
||||
Instance.getPluginHandler().initPlugins();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
connector = new LoginConnector();
|
||||
engine = new GameEngine();
|
||||
engine.start();
|
||||
while (!connector.isRegistered()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
acceptor = new SocketAcceptor(Runtime.getRuntime()
|
||||
.availableProcessors() + 1, Executors.newCachedThreadPool());
|
||||
acceptor.getFilterChain().addFirst("connectionfilter",
|
||||
new ConnectionFilter());
|
||||
IoAcceptorConfig config = new SocketAcceptorConfig();
|
||||
config.setDisconnectOnUnbind(true);
|
||||
|
||||
config.setThreadModel(ThreadModel.MANUAL);
|
||||
SocketSessionConfig ssc = (SocketSessionConfig) config
|
||||
.getSessionConfig();
|
||||
ssc.setSendBufferSize(10000);
|
||||
ssc.setReceiveBufferSize(10000);
|
||||
acceptor.bind(new InetSocketAddress(Config.SERVER_IP,
|
||||
Config.SERVER_PORT), new RSCConnectionHandler(engine),
|
||||
config);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game engine for this server
|
||||
*/
|
||||
public GameEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
public LoginConnector getLoginConnector() {
|
||||
return connector;
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return engine != null && connector != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the game engine
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void kill() {
|
||||
Logger.print(Config.SERVER_NAME + " shutting down...");
|
||||
running = false;
|
||||
engine.emptyWorld();
|
||||
connector.kill();
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
public boolean running() {
|
||||
return running;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the server in 60 seconds
|
||||
*/
|
||||
public boolean shutdownForUpdate() {
|
||||
if (updateEvent != null) {
|
||||
return false;
|
||||
}
|
||||
updateEvent = new SingleEvent(null, 59000) {
|
||||
public void action() {
|
||||
kill();
|
||||
}
|
||||
};
|
||||
Instance.getDelayedEventHandler().add(updateEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* MS till the server shuts down
|
||||
*/
|
||||
public int timeTillShutdown() {
|
||||
if (updateEvent == null) {
|
||||
return -1;
|
||||
}
|
||||
return updateEvent.timeTillNextRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds the socket acceptor
|
||||
*/
|
||||
public void unbind() {
|
||||
try {
|
||||
acceptor.unbindAll();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static Server getServer() {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
162
GameServer/src/org/moparscape/msc/gs/alert/AlertHandler.scala
Normal file
162
GameServer/src/org/moparscape/msc/gs/alert/AlertHandler.scala
Normal file
@ -0,0 +1,162 @@
|
||||
package org.moparscape.msc.gs.alert
|
||||
|
||||
import scala.xml.XML
|
||||
import scala.xml.Node
|
||||
import scala.collection.mutable.HashMap
|
||||
import java.util.ArrayList
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import java.util.Properties
|
||||
import javax.mail.Session
|
||||
import javax.mail.internet.MimeMessage
|
||||
import javax.mail.Message
|
||||
import javax.mail.internet.InternetAddress
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
/**
|
||||
* This is for out-of-game alerts.
|
||||
*
|
||||
* @author CodeForFame
|
||||
*/
|
||||
object AlertHandler extends Application {
|
||||
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
|
||||
private var users: List[User] = Nil
|
||||
|
||||
load
|
||||
|
||||
def sendAlert(msg: String, recip: String, priority: Int) {
|
||||
for (u <- users; if (u.name == recip))
|
||||
sendAlert(msg, u, priority)
|
||||
}
|
||||
|
||||
private def sendAlert(msg: String, recip: User, priority: Int) {
|
||||
executor.execute(new Runnable() {
|
||||
override def run() {
|
||||
val meds = recip.data.filter(p => p._1 <= priority)
|
||||
for (m <- meds) {
|
||||
Service.send(m._2, msg)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an alert to all users.
|
||||
*/
|
||||
def sendAlert(msg: String, priority: Int) {
|
||||
for (u <- users)
|
||||
sendAlert(msg, u, priority)
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the config file.
|
||||
*/
|
||||
private def load {
|
||||
val config = XML.loadFile("alert-config.xml")
|
||||
val users1 = (config \\ "user")
|
||||
val list = new ListBuffer[User];
|
||||
for (u <- users1) {
|
||||
list += parseUser(u)
|
||||
}
|
||||
users = list.toList
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the XML and creates a User from it.
|
||||
*/
|
||||
private def parseUser(u: Node) = {
|
||||
val name = (u \ "name").text
|
||||
val credentials = {
|
||||
val map = new HashMap[Int, Service]
|
||||
val creds = u \ "email"
|
||||
for (c <- creds) {
|
||||
map.put(Integer.parseInt((c \ "priority").text), new Service("email", (c \ "address").text))
|
||||
}
|
||||
map.toMap
|
||||
}
|
||||
new User(name, credentials)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class contains information for the user, such as name, and preferences for Services.
|
||||
*
|
||||
* @author CodeForFame
|
||||
*/
|
||||
private class User(name_ : String, data_ : Map[Int, Service]) {
|
||||
def name = name_
|
||||
def data = data_
|
||||
}
|
||||
|
||||
/**
|
||||
* The companion object for the Service class.
|
||||
* This is where you 'register' services.
|
||||
*
|
||||
* @author CodeForFame
|
||||
*/
|
||||
private object Service {
|
||||
|
||||
var services = new HashMap[String, (String, String) => Unit]
|
||||
|
||||
{
|
||||
services += (("email", EMail.send _))
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message via the specified service.
|
||||
*/
|
||||
def send(s: Service, msg: String) {
|
||||
val pf = services.get(s.identifier).get
|
||||
pf(msg, s.recip)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A class that is for defining a service.
|
||||
*
|
||||
* @author CodeForFame
|
||||
*/
|
||||
private class Service(identifier_ : String, recip_ : String) {
|
||||
def identifier = identifier_
|
||||
def recip = recip_
|
||||
}
|
||||
|
||||
/**
|
||||
* Services should have this trait, you should override the send method.
|
||||
*
|
||||
* @author CodeForFame
|
||||
*/
|
||||
private trait ServiceTrait {
|
||||
def send(msg: String, recip: String)
|
||||
}
|
||||
|
||||
/**
|
||||
* This Service sends an alert via e-mail.
|
||||
*
|
||||
* @author CodeForFame
|
||||
*/
|
||||
private object EMail extends ServiceTrait {
|
||||
override def send(msg: String, recip: String) = {
|
||||
val props = new Properties()
|
||||
val config = XML.loadFile("alert-config.xml") \\ "credentials"
|
||||
val sender = config \ "user" text
|
||||
val pass = config \ "pass" text
|
||||
val host = config \ "host" text
|
||||
val port = Integer.parseInt(config \ "port" text);
|
||||
props.put("mail.transport.protocol", config \ "protocol" text)
|
||||
props.put("mail.smtps.host", host)
|
||||
props.put("mail.smtps.auth", config \ "auth" text)
|
||||
|
||||
val mailSession = Session.getDefaultInstance(props)
|
||||
mailSession.setDebug(false)
|
||||
val transport = mailSession.getTransport()
|
||||
val message = new MimeMessage(mailSession)
|
||||
message.setSubject("MoparRSC Alert")
|
||||
message.setContent(msg, "text/plain")
|
||||
message.addRecipient(Message.RecipientType.TO, new InternetAddress(recip))
|
||||
transport.connect(host, port, sender, pass)
|
||||
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO))
|
||||
transport.close()
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ public class PlayerUpdatePacketBuilder {
|
||||
// talking
|
||||
updates.addShort(cm.getSender().getIndex());
|
||||
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.addBytes(cm.getMessage());
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class PacketQueue<T extends Packet> {
|
||||
* Adds a packet to the queue
|
||||
*/
|
||||
public void add(T p) {
|
||||
//System.out.println("[DEBUG] Packet Q: " + packets.size());
|
||||
//Logging.debug("[DEBUG] Packet Q: " + packets.size());
|
||||
synchronized (packets) {
|
||||
packets.add(p);
|
||||
}
|
||||
|
@ -88,8 +88,8 @@ public class RSCConnectionHandler implements IoHandler {
|
||||
p.getActionSender().sendLogout();
|
||||
session.close();
|
||||
/*
|
||||
* System.out.println("---MINA Error from: " + p.getUsername() +
|
||||
* " -------"); cause.printStackTrace();System.out.println(
|
||||
* Logging.debug("---MINA Error from: " + p.getUsername() +
|
||||
* " -------"); cause.printStackTrace();Logging.debug(
|
||||
* "------------------------------------------------------------");
|
||||
*/
|
||||
cause.printStackTrace();
|
||||
@ -120,7 +120,7 @@ public class RSCConnectionHandler implements IoHandler {
|
||||
try {
|
||||
c = counts.get(addr);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error: " + e);
|
||||
Logging.debug("Error: " + e);
|
||||
}
|
||||
if (c >= 5) {
|
||||
if (!written.containsKey(addr)) {
|
||||
@ -136,7 +136,7 @@ public class RSCConnectionHandler implements IoHandler {
|
||||
// }
|
||||
try {
|
||||
/*
|
||||
* System.out.println("ATTACKER IP: " + ip);
|
||||
* Logging.debug("ATTACKER IP: " + ip);
|
||||
* BufferedWriter bf2 = new BufferedWriter(new
|
||||
* FileWriter( "ddos.log", true));
|
||||
* bf2.write("sudo /sbin/route add " +
|
||||
@ -151,18 +151,18 @@ public class RSCConnectionHandler implements IoHandler {
|
||||
try {
|
||||
Runtime.getRuntime().exec("sudo /sbin/route delete " + ip);
|
||||
} catch (Exception err) {
|
||||
System.out.println(err);
|
||||
Logging.debug(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
try {
|
||||
Runtime.getRuntime().exec("sudo /sbin/route add " + ip + " gw 127.0.0.1");
|
||||
} catch (Exception err) {
|
||||
System.out.println(err);
|
||||
Logging.debug(err);
|
||||
}
|
||||
|
||||
// try { Runtime.getRuntime().exec(ip + ".bat"); }
|
||||
// catch (Exception err) { System.out.println(err); }
|
||||
// catch (Exception err) { Logging.debug(err); }
|
||||
lastAttack = now;
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
|
@ -56,7 +56,7 @@ public class RSCProtocolEncoder implements ProtocolEncoder {
|
||||
buffer = ByteBuffer.allocate(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.flip();
|
||||
out.write(buffer);
|
||||
|
@ -0,0 +1,43 @@
|
||||
package org.moparscape.msc.gs.connection.filter;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import org.apache.mina.common.IoFilter;
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.apache.mina.filter.BlacklistFilter;
|
||||
import org.moparscape.msc.gs.util.Cache;
|
||||
|
||||
public class ConnectionFilter extends BlacklistFilter {
|
||||
private Cache<InetSocketAddress, Integer> connections = new Cache<InetSocketAddress, Integer>();
|
||||
private static final int BLOCK_THRESHOLD = 5;
|
||||
|
||||
public void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session) {
|
||||
final SocketAddress sa = session.getRemoteAddress();
|
||||
if (sa != null && sa instanceof InetSocketAddress) {
|
||||
final InetSocketAddress a = (InetSocketAddress) sa;
|
||||
final Integer val = connections.get(a);
|
||||
System.out.println(val);
|
||||
final Integer retVal = connections.put(a, val == null ? 1 : val + 1);
|
||||
if (retVal != null && retVal > BLOCK_THRESHOLD) {
|
||||
block(a.getAddress());
|
||||
}
|
||||
}
|
||||
super.sessionCreated(nextFilter, session);
|
||||
}
|
||||
|
||||
public void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
|
||||
throws Exception {
|
||||
final SocketAddress sa = session.getRemoteAddress();
|
||||
if (sa != null && sa instanceof InetSocketAddress) {
|
||||
final InetSocketAddress a = (InetSocketAddress) sa;
|
||||
final Integer val = connections.get(a);
|
||||
System.out.println(val);
|
||||
final Integer retVal = connections.put(a, val == null ? 1 : val + 1);
|
||||
if (retVal != null && retVal - 1 <= BLOCK_THRESHOLD) {
|
||||
unblock(a.getAddress());
|
||||
}
|
||||
}
|
||||
super.sessionClosed(nextFilter, session);
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package org.moparscape.msc.gs.connection.filter;
|
||||
|
||||
import java.util.List
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import org.moparscape.msc.gs.Server
|
||||
import org.moparscape.msc.gs.core.DelayedEventHandler
|
||||
import org.moparscape.msc.gs.event.DelayedEvent
|
||||
import org.moparscape.msc.gs.util.Logger
|
||||
import org.moparscape.msc.config.Config
|
||||
import org.moparscape.msc.gs.alert.AlertHandler
|
||||
|
||||
object OSLevelBlocking {
|
||||
|
||||
private val blocked = new CopyOnWriteArrayList[String];
|
||||
|
||||
private val events = Server.getServer().getEngine().getEventHandler()
|
||||
|
||||
def block(ip: String) {
|
||||
if (!blocked.contains(ip)) {
|
||||
events.add(new DelayedEvent(null, Config.IP_BAN_REMOVAL_DELAY) {
|
||||
|
||||
def run() {
|
||||
try {
|
||||
Runtime.getRuntime.exec(Config.UNBLOCK_COMMAND.replaceAll("${ip}", ip));
|
||||
blocked.remove(ip)
|
||||
Logger.println("Unblocked " + ip)
|
||||
} catch {
|
||||
case e: Exception => {
|
||||
Logger.error(e)
|
||||
Logger.println("Failed to unblock " + ip)
|
||||
AlertHandler.sendAlert("Failed to unblock " + ip, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Runtime.getRuntime.exec(Config.BLOCK_COMMAND.replaceAll("${ip}", ip));
|
||||
blocked.add(ip)
|
||||
AlertHandler.sendAlert("Blocked " + ip, blocked.size / 10);
|
||||
Logger.println("Blocked " + ip)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,412 +1,412 @@
|
||||
package org.moparscape.msc.gs.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.builders.GameObjectPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.ItemPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.NpcPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.NpcUpdatePacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.PlayerPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.PlayerUpdatePacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.WallObjectPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.connection.RSCPacket;
|
||||
import org.moparscape.msc.gs.model.ChatMessage;
|
||||
import org.moparscape.msc.gs.model.Npc;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.model.snapshot.Chatlog;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
import org.moparscape.msc.gs.util.EntityList;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.gs.util.Processor;
|
||||
import org.moparscape.msc.gs.util.WorkGroup;
|
||||
|
||||
|
||||
public final class ClientUpdater implements Processor {
|
||||
|
||||
public static int pktcount = 0;
|
||||
private static World world = Instance.getWorld();
|
||||
private GameObjectPositionPacketBuilder gameObjectPositionBuilder = new GameObjectPositionPacketBuilder();
|
||||
private ItemPositionPacketBuilder itemPositionBuilder = new ItemPositionPacketBuilder();
|
||||
private NpcUpdatePacketBuilder npcApperanceBuilder = new NpcUpdatePacketBuilder();
|
||||
private NpcPositionPacketBuilder npcPositionPacketBuilder = new NpcPositionPacketBuilder();
|
||||
private EntityList<Npc> npcs = world.getNpcs();
|
||||
private PlayerUpdatePacketBuilder playerApperanceBuilder = new PlayerUpdatePacketBuilder();
|
||||
private PlayerPositionPacketBuilder playerPositionBuilder = new PlayerPositionPacketBuilder();
|
||||
private WallObjectPositionPacketBuilder wallObjectPositionPacketBuilder = new WallObjectPositionPacketBuilder();
|
||||
|
||||
private EntityList<Player> players = world.getPlayers();
|
||||
private WorkGroup<Player> clientInformerGroup = null;
|
||||
|
||||
public ClientUpdater() {
|
||||
world.setClientUpdater(this);
|
||||
this.clientInformerGroup = new WorkGroup<Player>(this);
|
||||
}
|
||||
/**
|
||||
* Sends queued packets to each player
|
||||
*/
|
||||
public void sendQueuedPackets() {
|
||||
try {
|
||||
for (Player p : players) {
|
||||
List<RSCPacket> packets = p.getActionSender().getPackets();
|
||||
for (RSCPacket packet : packets) {
|
||||
p.getSession().write(packet);
|
||||
}
|
||||
p.getActionSender().clearPackets();
|
||||
if (p.destroyed()) {
|
||||
p.getSession().close();
|
||||
p.remove();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Update player/npc appearances, game objects, items, wall objects, ping
|
||||
*/
|
||||
public void doMinor() {
|
||||
for (Player p : players) {
|
||||
p.updateAppearanceID();
|
||||
}
|
||||
for (Player p : players) {
|
||||
if (p.isFirstMajorUpdateSent()) {
|
||||
updatePlayerApperances(p);
|
||||
}
|
||||
updateNpcApperances(p);
|
||||
}
|
||||
|
||||
for (Player p : players) {
|
||||
if (p.isFirstMajorUpdateSent()) {
|
||||
p.setAppearnceChanged(false);
|
||||
p.clearProjectilesNeedingDisplayed();
|
||||
p.clearPlayersNeedingHitsUpdate();
|
||||
p.clearNpcsNeedingHitsUpdate();
|
||||
p.clearChatMessagesNeedingDisplayed();
|
||||
p.clearNpcMessagesNeedingDisplayed();
|
||||
p.clearBubblesNeedingDisplayed();
|
||||
}
|
||||
}
|
||||
|
||||
for (Npc n : npcs) {
|
||||
n.setAppearnceChanged(false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean threaded = false;
|
||||
public volatile boolean updatingCollections;
|
||||
public void doMajor() {
|
||||
Long delay;
|
||||
Long now = System.currentTimeMillis();
|
||||
|
||||
updateNpcPositions();
|
||||
|
||||
delay = System.currentTimeMillis() - now;
|
||||
if(delay > 299) Logger.println("updateNpcPositions() is taking longer than it should, exactly " + delay + "ms");
|
||||
|
||||
now = System.currentTimeMillis();
|
||||
|
||||
updatePlayersPositions();
|
||||
|
||||
delay = System.currentTimeMillis() - now;
|
||||
if(delay > 299) Logger.println("updatePlayersPositions() is taking longer than it should, exactly " + delay + "ms");
|
||||
|
||||
now = System.currentTimeMillis();
|
||||
|
||||
updateMessageQueues();
|
||||
|
||||
delay = System.currentTimeMillis() - now;
|
||||
if(delay > 299) Logger.println("updateMessageQueues() is taking longer than it should, exactly " + delay + "ms");
|
||||
|
||||
now = System.currentTimeMillis();
|
||||
|
||||
updateOffers();
|
||||
|
||||
if(threaded) {
|
||||
try {
|
||||
clientInformerGroup.processWorkload(players);
|
||||
} catch(InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (Player p : players) {
|
||||
//System.out.println("Process for player " + p.getUsername() + " | threaded: " + threaded);
|
||||
|
||||
updateTimeouts(p);
|
||||
|
||||
updatePlayerPositions(p);
|
||||
updateNpcPositions(p);
|
||||
updateGameObjects(p);
|
||||
updateWallObjects(p);
|
||||
updateItems(p);
|
||||
|
||||
p.setFirstMajorUpdateSent(true);
|
||||
|
||||
}
|
||||
updateCollections();
|
||||
}
|
||||
}
|
||||
|
||||
public void process(Player p) {
|
||||
|
||||
//System.out.println("Process for player " + p.getUsername() + " | threaded: " + threaded);
|
||||
|
||||
updateTimeouts(p);
|
||||
|
||||
updatePlayerPositions(p); // Must be done before updating any objects/items/npcs!
|
||||
updateNpcPositions(p);
|
||||
updateGameObjects(p);
|
||||
updateWallObjects(p);
|
||||
updateItems(p);
|
||||
|
||||
p.setFirstMajorUpdateSent(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates collections, new becomes known, removing is removed etc.
|
||||
*/
|
||||
public void updateCollections() {
|
||||
updatingCollections = true;
|
||||
for (Player p : players) {
|
||||
if (p.isRemoved() && p.initialized()) {
|
||||
world.unregisterPlayer(p);
|
||||
}
|
||||
}
|
||||
for (Player p : players) {
|
||||
p.getWatchedPlayers().update();
|
||||
p.getWatchedObjects().update();
|
||||
p.getWatchedItems().update();
|
||||
p.getWatchedNpcs().update();
|
||||
|
||||
//p.clearProjectilesNeedingDisplayed();
|
||||
//p.clearPlayersNeedingHitsUpdate();
|
||||
//p.clearNpcsNeedingHitsUpdate();
|
||||
//p.clearChatMessagesNeedingDisplayed();
|
||||
//p.clearNpcMessagesNeedingDisplayed();
|
||||
//p.clearBubblesNeedingDisplayed();
|
||||
|
||||
p.resetSpriteChanged();
|
||||
//p.setAppearnceChanged(false);
|
||||
}
|
||||
for (Npc n : npcs) {
|
||||
n.resetSpriteChanged();
|
||||
//n.setAppearnceChanged(false);
|
||||
}
|
||||
updatingCollections = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends updates for game objects to the given player
|
||||
*/
|
||||
private void updateGameObjects(Player p) {
|
||||
gameObjectPositionBuilder.setPlayer(p);
|
||||
RSCPacket temp = gameObjectPositionBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends updates for game items to the given player
|
||||
*/
|
||||
private void updateItems(Player p) {
|
||||
itemPositionBuilder.setPlayer(p);
|
||||
RSCPacket temp = itemPositionBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the messages queues for each player
|
||||
*/
|
||||
private void updateMessageQueues() {
|
||||
for (Player sender : players) {
|
||||
ChatMessage message = sender.getNextChatMessage();
|
||||
if (message == null || !sender.loggedIn()) {
|
||||
continue;
|
||||
}
|
||||
String s = DataConversions.byteToString(message.getMessage(), 0, message.getMessage().length);
|
||||
s = s.toLowerCase();
|
||||
String k = s;
|
||||
s = s.replace(" ", "");
|
||||
s = s.replace(".", "");
|
||||
if (s.contains("#adm#") || s.contains("#mod#") || s.contains("#pmd#")) {
|
||||
sender.getActionSender().sendMessage("@red@Your last message was not sent out due to an illegal string");
|
||||
return;
|
||||
}
|
||||
if(sender.isMuted()) {
|
||||
sender.getActionSender().sendMessage("You are muted, you cannot send messages");
|
||||
return;
|
||||
}
|
||||
List<Player> recievers = sender.getViewArea().getPlayersInView();
|
||||
ArrayList<String> recieverUsernames = new ArrayList<String>();
|
||||
for(Player p : recievers)
|
||||
recieverUsernames.add(p.getUsername());
|
||||
|
||||
world.addEntryToSnapshots(new Chatlog(sender.getUsername(), k, recieverUsernames));
|
||||
for (Player recipient : recievers) {
|
||||
if (sender.getIndex() == recipient.getIndex() || !recipient.loggedIn()) {
|
||||
continue;
|
||||
}
|
||||
if (recipient.getPrivacySetting(0) && !recipient.isFriendsWith(sender.getUsernameHash()) && !sender.isPMod()) {
|
||||
continue;
|
||||
}
|
||||
if (recipient.isIgnoring(sender.getUsernameHash()) && !sender.isPMod()) {
|
||||
continue;
|
||||
}
|
||||
recipient.informOfChatMessage(message);
|
||||
}
|
||||
recievers = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update appearance of any npcs the given player should be aware of
|
||||
*/
|
||||
private void updateNpcApperances(Player p) {
|
||||
npcApperanceBuilder.setPlayer(p);
|
||||
RSCPacket temp = npcApperanceBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the position of npcs, and check if who (and what) they are aware
|
||||
* of needs updated
|
||||
*/
|
||||
private void updateNpcPositions() {
|
||||
for (Npc n : npcs) {
|
||||
n.resetMoved();
|
||||
n.updatePosition();
|
||||
n.updateAppearanceID();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends updates for npcs to the given player
|
||||
*/
|
||||
private void updateNpcPositions(Player p) {
|
||||
npcPositionPacketBuilder.setPlayer(p);
|
||||
RSCPacket temp = npcPositionPacketBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateOffers() {
|
||||
for (Player player : players) {
|
||||
if (!player.requiresOfferUpdate()) {
|
||||
continue;
|
||||
}
|
||||
player.setRequiresOfferUpdate(false);
|
||||
if (player.isTrading()) {
|
||||
Player affectedPlayer = player.getWishToTrade();
|
||||
if (affectedPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
affectedPlayer.getActionSender().sendTradeItems();
|
||||
} else if (player.isDueling()) {
|
||||
Player affectedPlayer = player.getWishToDuel();
|
||||
if (affectedPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
player.getActionSender().sendDuelSettingUpdate();
|
||||
affectedPlayer.getActionSender().sendDuelSettingUpdate();
|
||||
affectedPlayer.getActionSender().sendDuelItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update appearance of the given player, and any players they should be
|
||||
* aware of
|
||||
*/
|
||||
private void updatePlayerApperances(Player p) {
|
||||
playerApperanceBuilder.setPlayer(p);
|
||||
RSCPacket temp = playerApperanceBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update positions of the given player, and any players they should be
|
||||
* aware of
|
||||
*/
|
||||
private void updatePlayerPositions(Player p) {
|
||||
playerPositionBuilder.setPlayer(p);
|
||||
RSCPacket temp = playerPositionBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the position of players, and check if who (and what) they are
|
||||
* aware of needs updated
|
||||
*/
|
||||
private void updatePlayersPositions() {
|
||||
for (Player p : players) {
|
||||
p.resetMoved();
|
||||
p.updatePosition();
|
||||
p.updateAppearanceID();
|
||||
}
|
||||
for (Player p : players) {
|
||||
p.revalidateWatchedPlayers();
|
||||
p.revalidateWatchedObjects();
|
||||
p.revalidateWatchedItems();
|
||||
p.revalidateWatchedNpcs();
|
||||
p.updateViewedPlayers();
|
||||
p.updateViewedObjects();
|
||||
p.updateViewedItems();
|
||||
p.updateViewedNpcs();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the player has moved within the last 5mins
|
||||
*/
|
||||
private void updateTimeouts(Player p) {
|
||||
if (p.destroyed()) {
|
||||
return;
|
||||
}
|
||||
long curTime = GameEngine.getTime();
|
||||
if (curTime - p.getLastPing() >= 30000) {
|
||||
p.destroy(false);
|
||||
} else if (p.warnedToMove()) {
|
||||
if (curTime - p.getLastMoved() >= 360000 && p.loggedIn()) {
|
||||
p.destroy(false);
|
||||
}
|
||||
} else if (curTime - p.getLastMoved() >= 300000) {
|
||||
p.getActionSender().sendMessage("@cya@You have not moved for 5 mins, please move to a new area to avoid logout.");
|
||||
p.warnToMove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends updates for wall objects to the given player
|
||||
*/
|
||||
private void updateWallObjects(Player p) {
|
||||
wallObjectPositionPacketBuilder.setPlayer(p);
|
||||
RSCPacket temp = wallObjectPositionPacketBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
//p.getSession().write(temp);
|
||||
p.getActionSender().addPacket(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
package org.moparscape.msc.gs.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.builders.GameObjectPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.ItemPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.NpcPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.NpcUpdatePacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.PlayerPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.PlayerUpdatePacketBuilder;
|
||||
import org.moparscape.msc.gs.builders.WallObjectPositionPacketBuilder;
|
||||
import org.moparscape.msc.gs.connection.RSCPacket;
|
||||
import org.moparscape.msc.gs.model.ChatMessage;
|
||||
import org.moparscape.msc.gs.model.Npc;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.model.snapshot.Chatlog;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
import org.moparscape.msc.gs.util.EntityList;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.gs.util.Processor;
|
||||
import org.moparscape.msc.gs.util.WorkGroup;
|
||||
|
||||
|
||||
public final class ClientUpdater implements Processor {
|
||||
|
||||
public static int pktcount = 0;
|
||||
private static World world = Instance.getWorld();
|
||||
private GameObjectPositionPacketBuilder gameObjectPositionBuilder = new GameObjectPositionPacketBuilder();
|
||||
private ItemPositionPacketBuilder itemPositionBuilder = new ItemPositionPacketBuilder();
|
||||
private NpcUpdatePacketBuilder npcApperanceBuilder = new NpcUpdatePacketBuilder();
|
||||
private NpcPositionPacketBuilder npcPositionPacketBuilder = new NpcPositionPacketBuilder();
|
||||
private EntityList<Npc> npcs = world.getNpcs();
|
||||
private PlayerUpdatePacketBuilder playerApperanceBuilder = new PlayerUpdatePacketBuilder();
|
||||
private PlayerPositionPacketBuilder playerPositionBuilder = new PlayerPositionPacketBuilder();
|
||||
private WallObjectPositionPacketBuilder wallObjectPositionPacketBuilder = new WallObjectPositionPacketBuilder();
|
||||
|
||||
private EntityList<Player> players = world.getPlayers();
|
||||
private WorkGroup<Player> clientInformerGroup = null;
|
||||
|
||||
public ClientUpdater() {
|
||||
world.setClientUpdater(this);
|
||||
this.clientInformerGroup = new WorkGroup<Player>(this);
|
||||
}
|
||||
/**
|
||||
* Sends queued packets to each player
|
||||
*/
|
||||
public void sendQueuedPackets() {
|
||||
try {
|
||||
for (Player p : players) {
|
||||
List<RSCPacket> packets = p.getActionSender().getPackets();
|
||||
for (RSCPacket packet : packets) {
|
||||
p.getSession().write(packet);
|
||||
}
|
||||
p.getActionSender().clearPackets();
|
||||
if (p.destroyed()) {
|
||||
p.getSession().close();
|
||||
p.remove();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Update player/npc appearances, game objects, items, wall objects, ping
|
||||
*/
|
||||
public void doMinor() {
|
||||
for (Player p : players) {
|
||||
p.updateAppearanceID();
|
||||
}
|
||||
for (Player p : players) {
|
||||
if (p.isFirstMajorUpdateSent()) {
|
||||
updatePlayerApperances(p);
|
||||
}
|
||||
updateNpcApperances(p);
|
||||
}
|
||||
|
||||
for (Player p : players) {
|
||||
if (p.isFirstMajorUpdateSent()) {
|
||||
p.setAppearnceChanged(false);
|
||||
p.clearProjectilesNeedingDisplayed();
|
||||
p.clearPlayersNeedingHitsUpdate();
|
||||
p.clearNpcsNeedingHitsUpdate();
|
||||
p.clearChatMessagesNeedingDisplayed();
|
||||
p.clearNpcMessagesNeedingDisplayed();
|
||||
p.clearBubblesNeedingDisplayed();
|
||||
}
|
||||
}
|
||||
|
||||
for (Npc n : npcs) {
|
||||
n.setAppearnceChanged(false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean threaded = false;
|
||||
public volatile boolean updatingCollections;
|
||||
public void doMajor() {
|
||||
Long delay;
|
||||
Long now = System.currentTimeMillis();
|
||||
|
||||
updateNpcPositions();
|
||||
|
||||
delay = System.currentTimeMillis() - now;
|
||||
if(delay > 299) Logger.println("updateNpcPositions() is taking longer than it should, exactly " + delay + "ms");
|
||||
|
||||
now = System.currentTimeMillis();
|
||||
|
||||
updatePlayersPositions();
|
||||
|
||||
delay = System.currentTimeMillis() - now;
|
||||
if(delay > 299) Logger.println("updatePlayersPositions() is taking longer than it should, exactly " + delay + "ms");
|
||||
|
||||
now = System.currentTimeMillis();
|
||||
|
||||
updateMessageQueues();
|
||||
|
||||
delay = System.currentTimeMillis() - now;
|
||||
if(delay > 299) Logger.println("updateMessageQueues() is taking longer than it should, exactly " + delay + "ms");
|
||||
|
||||
now = System.currentTimeMillis();
|
||||
|
||||
updateOffers();
|
||||
|
||||
if(threaded) {
|
||||
try {
|
||||
clientInformerGroup.processWorkload(players);
|
||||
} catch(InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (Player p : players) {
|
||||
//Logging.debug("Process for player " + p.getUsername() + " | threaded: " + threaded);
|
||||
|
||||
updateTimeouts(p);
|
||||
|
||||
updatePlayerPositions(p);
|
||||
updateNpcPositions(p);
|
||||
updateGameObjects(p);
|
||||
updateWallObjects(p);
|
||||
updateItems(p);
|
||||
|
||||
p.setFirstMajorUpdateSent(true);
|
||||
|
||||
}
|
||||
updateCollections();
|
||||
}
|
||||
}
|
||||
|
||||
public void process(Player p) {
|
||||
|
||||
//Logging.debug("Process for player " + p.getUsername() + " | threaded: " + threaded);
|
||||
|
||||
updateTimeouts(p);
|
||||
|
||||
updatePlayerPositions(p); // Must be done before updating any objects/items/npcs!
|
||||
updateNpcPositions(p);
|
||||
updateGameObjects(p);
|
||||
updateWallObjects(p);
|
||||
updateItems(p);
|
||||
|
||||
p.setFirstMajorUpdateSent(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates collections, new becomes known, removing is removed etc.
|
||||
*/
|
||||
public void updateCollections() {
|
||||
updatingCollections = true;
|
||||
for (Player p : players) {
|
||||
if (p.isRemoved() && p.initialized()) {
|
||||
world.unregisterPlayer(p);
|
||||
}
|
||||
}
|
||||
for (Player p : players) {
|
||||
p.getWatchedPlayers().update();
|
||||
p.getWatchedObjects().update();
|
||||
p.getWatchedItems().update();
|
||||
p.getWatchedNpcs().update();
|
||||
|
||||
//p.clearProjectilesNeedingDisplayed();
|
||||
//p.clearPlayersNeedingHitsUpdate();
|
||||
//p.clearNpcsNeedingHitsUpdate();
|
||||
//p.clearChatMessagesNeedingDisplayed();
|
||||
//p.clearNpcMessagesNeedingDisplayed();
|
||||
//p.clearBubblesNeedingDisplayed();
|
||||
|
||||
p.resetSpriteChanged();
|
||||
//p.setAppearnceChanged(false);
|
||||
}
|
||||
for (Npc n : npcs) {
|
||||
n.resetSpriteChanged();
|
||||
//n.setAppearnceChanged(false);
|
||||
}
|
||||
updatingCollections = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends updates for game objects to the given player
|
||||
*/
|
||||
private void updateGameObjects(Player p) {
|
||||
gameObjectPositionBuilder.setPlayer(p);
|
||||
RSCPacket temp = gameObjectPositionBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends updates for game items to the given player
|
||||
*/
|
||||
private void updateItems(Player p) {
|
||||
itemPositionBuilder.setPlayer(p);
|
||||
RSCPacket temp = itemPositionBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the messages queues for each player
|
||||
*/
|
||||
private void updateMessageQueues() {
|
||||
for (Player sender : players) {
|
||||
ChatMessage message = sender.getNextChatMessage();
|
||||
if (message == null || !sender.loggedIn()) {
|
||||
continue;
|
||||
}
|
||||
String s = DataConversions.byteToString(message.getMessage(), 0, message.getMessage().length);
|
||||
s = s.toLowerCase();
|
||||
String k = s;
|
||||
s = s.replace(" ", "");
|
||||
s = s.replace(".", "");
|
||||
if (s.contains("#adm#") || s.contains("#mod#") || s.contains("#pmd#")) {
|
||||
sender.getActionSender().sendMessage("@red@Your last message was not sent out due to an illegal string");
|
||||
return;
|
||||
}
|
||||
if(sender.isMuted()) {
|
||||
sender.getActionSender().sendMessage("You are muted, you cannot send messages");
|
||||
return;
|
||||
}
|
||||
List<Player> recievers = sender.getViewArea().getPlayersInView();
|
||||
ArrayList<String> recieverUsernames = new ArrayList<String>();
|
||||
for(Player p : recievers)
|
||||
recieverUsernames.add(p.getUsername());
|
||||
|
||||
world.addEntryToSnapshots(new Chatlog(sender.getUsername(), k, recieverUsernames));
|
||||
for (Player recipient : recievers) {
|
||||
if (sender.getIndex() == recipient.getIndex() || !recipient.loggedIn()) {
|
||||
continue;
|
||||
}
|
||||
if (recipient.getPrivacySetting(0) && !recipient.isFriendsWith(sender.getUsernameHash()) && !sender.isPMod()) {
|
||||
continue;
|
||||
}
|
||||
if (recipient.isIgnoring(sender.getUsernameHash()) && !sender.isPMod()) {
|
||||
continue;
|
||||
}
|
||||
recipient.informOfChatMessage(message);
|
||||
}
|
||||
recievers = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update appearance of any npcs the given player should be aware of
|
||||
*/
|
||||
private void updateNpcApperances(Player p) {
|
||||
npcApperanceBuilder.setPlayer(p);
|
||||
RSCPacket temp = npcApperanceBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the position of npcs, and check if who (and what) they are aware
|
||||
* of needs updated
|
||||
*/
|
||||
private void updateNpcPositions() {
|
||||
for (Npc n : npcs) {
|
||||
n.resetMoved();
|
||||
n.updatePosition();
|
||||
n.updateAppearanceID();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends updates for npcs to the given player
|
||||
*/
|
||||
private void updateNpcPositions(Player p) {
|
||||
npcPositionPacketBuilder.setPlayer(p);
|
||||
RSCPacket temp = npcPositionPacketBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateOffers() {
|
||||
for (Player player : players) {
|
||||
if (!player.requiresOfferUpdate()) {
|
||||
continue;
|
||||
}
|
||||
player.setRequiresOfferUpdate(false);
|
||||
if (player.isTrading()) {
|
||||
Player affectedPlayer = player.getWishToTrade();
|
||||
if (affectedPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
affectedPlayer.getActionSender().sendTradeItems();
|
||||
} else if (player.isDueling()) {
|
||||
Player affectedPlayer = player.getWishToDuel();
|
||||
if (affectedPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
player.getActionSender().sendDuelSettingUpdate();
|
||||
affectedPlayer.getActionSender().sendDuelSettingUpdate();
|
||||
affectedPlayer.getActionSender().sendDuelItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update appearance of the given player, and any players they should be
|
||||
* aware of
|
||||
*/
|
||||
private void updatePlayerApperances(Player p) {
|
||||
playerApperanceBuilder.setPlayer(p);
|
||||
RSCPacket temp = playerApperanceBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update positions of the given player, and any players they should be
|
||||
* aware of
|
||||
*/
|
||||
private void updatePlayerPositions(Player p) {
|
||||
playerPositionBuilder.setPlayer(p);
|
||||
RSCPacket temp = playerPositionBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
p.getActionSender().addPacket(temp);
|
||||
//p.getSession().write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the position of players, and check if who (and what) they are
|
||||
* aware of needs updated
|
||||
*/
|
||||
private void updatePlayersPositions() {
|
||||
for (Player p : players) {
|
||||
p.resetMoved();
|
||||
p.updatePosition();
|
||||
p.updateAppearanceID();
|
||||
}
|
||||
for (Player p : players) {
|
||||
p.revalidateWatchedPlayers();
|
||||
p.revalidateWatchedObjects();
|
||||
p.revalidateWatchedItems();
|
||||
p.revalidateWatchedNpcs();
|
||||
p.updateViewedPlayers();
|
||||
p.updateViewedObjects();
|
||||
p.updateViewedItems();
|
||||
p.updateViewedNpcs();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the player has moved within the last 5mins
|
||||
*/
|
||||
private void updateTimeouts(Player p) {
|
||||
if (p.destroyed()) {
|
||||
return;
|
||||
}
|
||||
long curTime = GameEngine.getTime();
|
||||
if (curTime - p.getLastPing() >= 30000) {
|
||||
p.destroy(false);
|
||||
} else if (p.warnedToMove()) {
|
||||
if (curTime - p.getLastMoved() >= 960000 && p.loggedIn()) {
|
||||
p.destroy(false);
|
||||
}
|
||||
} else if (curTime - p.getLastMoved() >= 900000) {
|
||||
p.getActionSender().sendMessage("@cya@You have not moved for 15 mins, please move to a new area to avoid logout.");
|
||||
p.warnToMove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends updates for wall objects to the given player
|
||||
*/
|
||||
private void updateWallObjects(Player p) {
|
||||
wallObjectPositionPacketBuilder.setPlayer(p);
|
||||
RSCPacket temp = wallObjectPositionPacketBuilder.getPacket();
|
||||
if (temp != null) {
|
||||
//p.getSession().write(temp);
|
||||
p.getActionSender().addPacket(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,13 @@ import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.connection.PacketQueue;
|
||||
import org.moparscape.msc.gs.connection.RSCPacket;
|
||||
import org.moparscape.msc.gs.connection.filter.OSLevelBlocking;
|
||||
import org.moparscape.msc.gs.event.DelayedEvent;
|
||||
import org.moparscape.msc.gs.event.MiniEvent;
|
||||
import org.moparscape.msc.gs.model.ActiveTile;
|
||||
@ -96,12 +98,6 @@ public final class GameEngine extends Thread {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes incoming packets.
|
||||
*/
|
||||
private Map<String, Integer> written = Collections
|
||||
.synchronizedMap(new HashMap<String, Integer>());
|
||||
|
||||
/**
|
||||
* Constructs a new game engine with an empty packet queue.
|
||||
*/
|
||||
@ -132,9 +128,9 @@ public final class GameEngine extends Thread {
|
||||
* getAddress(session); String ip = addr.toString(); ip =
|
||||
* ip.replaceAll("/",""); long now = System.currentTimeMillis(); int c = 0;
|
||||
* 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 {
|
||||
* 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));
|
||||
* bf2.write("sudo /sbin/route add " + addr.getHostAddress() +
|
||||
* " gw 127.0.0.1"); bf2.newLine(); bf2.close(); written.put(addr, 1); }
|
||||
@ -208,6 +204,10 @@ public final class GameEngine extends Thread {
|
||||
private void processEvents() {
|
||||
eventHandler.doEvents();
|
||||
}
|
||||
|
||||
public DelayedEventHandler getEventHandler() {
|
||||
return eventHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects system err
|
||||
@ -242,29 +242,7 @@ public final class GameEngine extends Thread {
|
||||
&& p.getID() != 77 && p.getID() != 0) {
|
||||
final String ip = player.getCurrentIP();
|
||||
// flagSession(session);
|
||||
if (!written.containsKey(ip)) {
|
||||
eventHandler.add(new DelayedEvent(null, 1800000) {
|
||||
|
||||
public void run() {
|
||||
written.remove(ip);
|
||||
try {
|
||||
Runtime.getRuntime().exec(
|
||||
"sudo /sbin/route delete " + ip);
|
||||
} catch (Exception err) {
|
||||
System.out.println(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
try {
|
||||
// Runtime.getRuntime().exec(
|
||||
// "sudo /sbin/route add " + ip + " gw 127.0.0.1");
|
||||
} catch (Exception err) {
|
||||
System.out.println(err);
|
||||
}
|
||||
Logger.println("Dummy packet from " + player.getCurrentIP()
|
||||
+ ": " + p.getID());
|
||||
written.put(ip, 1);
|
||||
}
|
||||
OSLevelBlocking.block(ip);
|
||||
continue;
|
||||
}
|
||||
PacketHandler handler = packetHandlers.get(p.getID());
|
||||
@ -331,7 +309,7 @@ public final class GameEngine extends Thread {
|
||||
}
|
||||
time = System.currentTimeMillis();
|
||||
|
||||
eventHandler.add(new DelayedEvent(null, 300000 * 10 * 2) { // Ran every
|
||||
eventHandler.add(new DelayedEvent(null, Config.GARBAGE_COLLECT_INTERVAL) { // Ran every
|
||||
// 50*2
|
||||
// minutes
|
||||
@Override
|
||||
@ -343,12 +321,12 @@ public final class GameEngine extends Thread {
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
eventHandler.add(new DelayedEvent(null, 300000) { // 5 min
|
||||
eventHandler.add(new DelayedEvent(null, Config.SAVE_INTERVAL) { // 5 min
|
||||
public void run() {
|
||||
world.dbKeepAlive();
|
||||
long now = GameEngine.getTime();
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (now - p.getLastSaveTime() >= 900000) {
|
||||
if (now - p.getLastSaveTime() >= Config.SAVE_INTERVAL) {
|
||||
p.save();
|
||||
p.setLastSaveTime(now);
|
||||
}
|
||||
|
@ -10,11 +10,10 @@ import org.moparscape.msc.gs.model.Npc;
|
||||
import org.moparscape.msc.gs.model.Path;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.model.mini.Damager;
|
||||
import org.moparscape.msc.gs.model.mini.Damage;
|
||||
import org.moparscape.msc.gs.states.CombatState;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
|
||||
|
||||
public class FightEvent extends DelayedEvent {
|
||||
|
||||
private Mob affectedMob;
|
||||
@ -61,7 +60,9 @@ public class FightEvent extends DelayedEvent {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (!owner.loggedIn() || (affectedMob instanceof Player && !((Player) affectedMob).loggedIn())) {
|
||||
if (!owner.loggedIn()
|
||||
|| (affectedMob instanceof Player && !((Player) affectedMob)
|
||||
.loggedIn())) {
|
||||
owner.resetCombat(CombatState.ERROR);
|
||||
affectedMob.resetCombat(CombatState.ERROR);
|
||||
return;
|
||||
@ -98,8 +99,8 @@ public class FightEvent extends DelayedEvent {
|
||||
}
|
||||
}
|
||||
if (opponent instanceof Player && attacker instanceof Player) {
|
||||
if(((Player)opponent).isSleeping()) {
|
||||
((Player)opponent).getActionSender().sendWakeUp(false);
|
||||
if (((Player) opponent).isSleeping()) {
|
||||
((Player) opponent).getActionSender().sendWakeUp(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,26 +109,32 @@ public class FightEvent extends DelayedEvent {
|
||||
* opponent.resetCombat(CombatState.LOST); return; }
|
||||
*/
|
||||
attacker.incHitsMade();
|
||||
if (attacker instanceof Npc && opponent.isPrayerActivated(12) && ((Npc)attacker).getTeam() == 2) {
|
||||
if (attacker instanceof Npc && opponent.isPrayerActivated(12)
|
||||
&& ((Npc) attacker).getTeam() == 2) {
|
||||
return;
|
||||
}
|
||||
int damage = (attacker instanceof Player && opponent instanceof Player ? Formulae.calcFightHit(attacker, opponent) : Formulae.calcFightHitWithNPC(attacker, opponent));
|
||||
int damage = (attacker instanceof Player && opponent instanceof Player ? Formulae
|
||||
.calcFightHit(attacker, opponent) : Formulae
|
||||
.calcFightHitWithNPC(attacker, opponent));
|
||||
|
||||
if (attacker instanceof Player && opponent instanceof Npc) {
|
||||
Npc npc = (Npc) opponent;
|
||||
|
||||
|
||||
int newDmg = damage;
|
||||
if (npc.getCurHits() - damage <= 0 && npc.getCurHits() > 0) {
|
||||
newDmg = npc.getCurHits();
|
||||
}
|
||||
npc.getSyndicate().addDamage(owner, newDmg, false, true, false);
|
||||
npc.getSyndicate().addDamage(owner, newDmg, Damage.COMBAT_DAMAGE);
|
||||
}
|
||||
|
||||
if (attacker instanceof Npc && opponent instanceof Player && attacker.getHitsMade() >= (attacked ? 4 : 3)) {
|
||||
if (attacker instanceof Npc && opponent instanceof Player
|
||||
&& attacker.getHitsMade() >= (attacked ? 4 : 3)) {
|
||||
Npc npc = (Npc) attacker;
|
||||
Player player = (Player) opponent;
|
||||
if (npc.getCurHits() <= npc.getDef().hits * 0.10 && npc.getCurHits() > 0) {
|
||||
if (!npc.getLocation().inWilderness() && npc.getDef().attackable && !npc.getDef().aggressive) {
|
||||
if (npc.getCurHits() <= npc.getDef().hits * 0.10
|
||||
&& npc.getCurHits() > 0) {
|
||||
if (!npc.getLocation().inWilderness()
|
||||
&& npc.getDef().attackable && !npc.getDef().aggressive) {
|
||||
boolean go = true;
|
||||
for (int i : Constants.GameServer.NPCS_THAT_DONT_RETREAT) {
|
||||
if (i == npc.getID()) {
|
||||
@ -142,9 +149,14 @@ public class FightEvent extends DelayedEvent {
|
||||
npc.resetCombat(CombatState.RUNNING);
|
||||
player.resetCombat(CombatState.WAITING);
|
||||
npc.setRan(true);
|
||||
npc.setPath(new Path(attacker.getX(), attacker.getY(), DataConversions.random(npc.getLoc().minX(), npc.getLoc().maxX()), DataConversions.random(npc.getLoc().minY(), npc.getLoc().maxY())));
|
||||
npc.setPath(new Path(attacker.getX(), attacker.getY(),
|
||||
DataConversions.random(npc.getLoc().minX(), npc
|
||||
.getLoc().maxX()), DataConversions
|
||||
.random(npc.getLoc().minY(), npc
|
||||
.getLoc().maxY())));
|
||||
player.resetAll();
|
||||
player.getActionSender().sendMessage("Your opponent is retreating");
|
||||
player.getActionSender().sendMessage(
|
||||
"Your opponent is retreating");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -161,7 +173,8 @@ public class FightEvent extends DelayedEvent {
|
||||
double cur = n.getHits();
|
||||
int percent = (int) ((cur / max) * 100);
|
||||
if (n.isScripted()) {
|
||||
Instance.getPluginHandler().getNpcAIHandler(opponent.getID()).onHealthPercentage(n, percent);
|
||||
Instance.getPluginHandler().getNpcAIHandler(opponent.getID())
|
||||
.onHealthPercentage(n, percent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,97 +212,32 @@ public class FightEvent extends DelayedEvent {
|
||||
|
||||
if (newHp <= 0) {
|
||||
|
||||
int tempDmg = 0;
|
||||
Player toLoot = null;
|
||||
|
||||
//System.out.println(opponent+" killed by "+attacker);
|
||||
// Logging.debug(opponent+" killed by "+attacker);
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
Player attackerPlayer = (Player) attacker;
|
||||
toLoot = attackerPlayer;
|
||||
int exp = DataConversions.roundUp(Formulae.combatExperience(opponent) / 4D);
|
||||
int newXP = 0;
|
||||
if (opponent instanceof Player) {
|
||||
//System.out.println(opponent+" killed by "+attacker);
|
||||
// Logging.debug(opponent+" killed by "+attacker);
|
||||
opponent.killedBy(attackerPlayer, false);
|
||||
}
|
||||
|
||||
|
||||
if (attacker instanceof Player && opponent instanceof Npc) {
|
||||
Npc npc = (Npc) opponent;
|
||||
|
||||
for (Damager fig : ((Npc) opponent).getSyndicate().getDamagers()) {
|
||||
// boolean found = false;
|
||||
if (fig.getPlayer().isDueling()) {
|
||||
continue;
|
||||
}
|
||||
if (fig.getDamage() > tempDmg) {
|
||||
toLoot = fig.getPlayer();
|
||||
tempDmg = fig.getDamage();
|
||||
}
|
||||
if (fig.isUseMagic() && !fig.isUseCombat()) { // if they
|
||||
// shot
|
||||
// magic, and didn't
|
||||
// kill the npc with
|
||||
// melee
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* for(Player p :
|
||||
* attackerPlayer.getViewArea().getPlayersInView()) if(p
|
||||
* == fig.player) found = true; if(!found) // skip a
|
||||
* person who is not in the area. continue;
|
||||
*/// meh, no big deal, less cpu without it.
|
||||
|
||||
if (fig.getDamage() > npc.getDef().hits) {
|
||||
fig.setDamage(npc.getDef().hits);
|
||||
}
|
||||
if (fig.getPlayer() != null) {
|
||||
newXP = (exp * fig.getDamage()) / npc.getDef().hits;
|
||||
|
||||
if (fig.getPlayer() != attackerPlayer && fig.isUseRanged()) {
|
||||
fig.getPlayer().incExp(4, newXP * 4, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(4);
|
||||
attacker.resetCombat(CombatState.WON);
|
||||
opponent.resetCombat(CombatState.LOST);
|
||||
continue;
|
||||
}
|
||||
switch (fig.getPlayer().getCombatStyle()) {
|
||||
case 0:
|
||||
for (int x = 0; x < 2; x++) {
|
||||
fig.getPlayer().incExp(x, newXP, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(x);
|
||||
}
|
||||
fig.getPlayer().incExp(2, newXP, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(2);
|
||||
break;
|
||||
case 1:
|
||||
fig.getPlayer().incExp(2, newXP * 3, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(2);
|
||||
break;
|
||||
case 2:
|
||||
fig.getPlayer().incExp(0, newXP * 3, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(0);
|
||||
break;
|
||||
case 3:
|
||||
fig.getPlayer().incExp(1, newXP * 3, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(1);
|
||||
break;
|
||||
}
|
||||
fig.getPlayer().incExp(3, newXP, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(3);
|
||||
}
|
||||
}
|
||||
|
||||
npc.getSyndicate().distributeExp(npc);
|
||||
} else {
|
||||
int exp = DataConversions.roundUp(Formulae
|
||||
.combatExperience(opponent) / 4D);
|
||||
switch (attackerPlayer.getCombatStyle()) {
|
||||
case 0:
|
||||
|
||||
for (int x = 0; x < 2; x++) {
|
||||
attackerPlayer.incExp(x, newXP, true, true);
|
||||
attackerPlayer.incExp(x, exp, true, true);
|
||||
attackerPlayer.getActionSender().sendStat(x);
|
||||
}
|
||||
attackerPlayer.incExp(2, newXP, true, true);
|
||||
attackerPlayer.incExp(2, exp, true, true);
|
||||
attackerPlayer.getActionSender().sendStat(2);
|
||||
break;
|
||||
case 1:
|
||||
@ -309,7 +257,7 @@ public class FightEvent extends DelayedEvent {
|
||||
attackerPlayer.getActionSender().sendStat(3);
|
||||
}
|
||||
}
|
||||
//if the dead mob isn't a player...
|
||||
// if the dead mob isn't a player...
|
||||
if (!(affectedMob instanceof Player)) {
|
||||
opponent.killedBy(toLoot, false);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package org.moparscape.msc.gs.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.core.GameEngine;
|
||||
@ -13,7 +13,7 @@ import org.moparscape.msc.gs.model.Npc;
|
||||
import org.moparscape.msc.gs.model.PathGenerator;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.model.Projectile;
|
||||
import org.moparscape.msc.gs.model.mini.Damager;
|
||||
import org.moparscape.msc.gs.model.mini.Damage;
|
||||
import org.moparscape.msc.gs.states.Action;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
|
||||
@ -96,7 +96,7 @@ public class RangeEvent extends DelayedEvent {
|
||||
continue;
|
||||
}
|
||||
arrowID = aID;
|
||||
if(owner.getLocation().inWilderness() && Constants.GameServer.F2P_WILDY) {
|
||||
if(owner.getLocation().inWilderness() && Config.f2pWildy) {
|
||||
if(arrowID != 11 && arrowID != 190) {
|
||||
owner.getActionSender().sendMessage("You may not use P2P (Member Item) Arrows in the F2P Wilderness");
|
||||
owner.resetRange();
|
||||
@ -174,7 +174,7 @@ public class RangeEvent extends DelayedEvent {
|
||||
}
|
||||
if (affectedMob instanceof Npc) {
|
||||
Npc npc = (Npc) affectedMob;
|
||||
npc.getSyndicate().addDamage(owner, damage, false, false, true);
|
||||
npc.getSyndicate().addDamage(owner, damage, Damage.RANGE_DAMAGE);
|
||||
}
|
||||
Projectile projectile = new Projectile(owner, affectedMob, 2);
|
||||
|
||||
@ -212,49 +212,10 @@ public class RangeEvent extends DelayedEvent {
|
||||
owner.resetRange();
|
||||
if (owner instanceof Player) {
|
||||
Player attackerPlayer = (Player) owner;
|
||||
int exp = DataConversions.roundUp(Formulae.combatExperience(affectedMob) / 4D);
|
||||
int newXP = 0;
|
||||
if (owner instanceof Player && affectedMob instanceof Npc) {
|
||||
if (affectedMob instanceof Npc) {
|
||||
Npc npc = (Npc) affectedMob;
|
||||
|
||||
for (Damager fig : ((Npc) affectedMob).getSyndicate().getDamagers()) {
|
||||
if (fig.isUseMagic() && attackerPlayer != fig.getPlayer())
|
||||
continue;
|
||||
|
||||
if (fig.getDamage() > npc.getDef().hits)
|
||||
fig.setDamage(npc.getDef().hits);
|
||||
if (fig.getPlayer() != null) {
|
||||
newXP = (exp * fig.getDamage()) / npc.getDef().hits;
|
||||
|
||||
if (fig.isUseRanged()) {
|
||||
fig.getPlayer().incExp(4, newXP * 4, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(4);
|
||||
continue;
|
||||
}
|
||||
switch (fig.getPlayer().getCombatStyle()) {
|
||||
case 0:
|
||||
for (int x = 0; x < 3; x++) {
|
||||
fig.getPlayer().incExp(x, newXP, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(x);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
fig.getPlayer().incExp(2, newXP * 3, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(2);
|
||||
break;
|
||||
case 2:
|
||||
fig.getPlayer().incExp(0, newXP * 3, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(0);
|
||||
break;
|
||||
case 3:
|
||||
fig.getPlayer().incExp(1, newXP * 3, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(1);
|
||||
break;
|
||||
}
|
||||
fig.getPlayer().incExp(3, newXP, true, true);
|
||||
fig.getPlayer().getActionSender().sendStat(3);
|
||||
}
|
||||
}
|
||||
npc.getSyndicate().distributeExp(npc);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -4,38 +4,39 @@ import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.model.Point;
|
||||
|
||||
public abstract class WalkToPointEvent extends DelayedEvent {
|
||||
protected Point location;
|
||||
private int radius;
|
||||
private boolean stop;
|
||||
protected Point location;
|
||||
private int radius;
|
||||
private boolean stop;
|
||||
|
||||
public WalkToPointEvent(Player owner, Point location, int radius, boolean stop) {
|
||||
super(owner, 500);
|
||||
this.location = location;
|
||||
this.radius = radius;
|
||||
this.stop = stop;
|
||||
if (stop && owner.withinRange(location, radius)) {
|
||||
owner.resetPath();
|
||||
arrived();
|
||||
super.matchRunning = false;
|
||||
public WalkToPointEvent(Player owner, Point location, int radius,
|
||||
boolean stop) {
|
||||
super(owner, 500);
|
||||
this.location = location;
|
||||
this.radius = radius;
|
||||
this.stop = stop;
|
||||
if (stop && owner.withinRange(location, radius)) {
|
||||
owner.resetPath();
|
||||
arrived();
|
||||
super.matchRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void arrived();
|
||||
public abstract void arrived();
|
||||
|
||||
public Point getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
if (stop && owner.withinRange(location, radius)) {
|
||||
owner.resetPath();
|
||||
arrived();
|
||||
} else if (owner.hasMoved()) {
|
||||
return; // We're still moving
|
||||
} else if (owner.withinRange(location, radius)) {
|
||||
arrived();
|
||||
public Point getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
if (stop && owner.withinRange(location, radius)) {
|
||||
owner.resetPath();
|
||||
arrived();
|
||||
} else if (owner.hasMoved()) {
|
||||
return; // We're still moving
|
||||
} else if (owner.withinRange(location, radius)) {
|
||||
arrived();
|
||||
}
|
||||
super.matchRunning = false;
|
||||
}
|
||||
super.matchRunning = false;
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,6 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.external.EntityHandler;
|
||||
@ -32,7 +31,7 @@ public class WorldLoader {
|
||||
// private ZipOutputStream out;
|
||||
|
||||
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;
|
||||
try {
|
||||
String filename = "h" + height + "x" + sectionX + "y" + sectionY;
|
||||
@ -46,7 +45,7 @@ public class WorldLoader {
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
//System.out.println(2);
|
||||
//Logging.debug(2);
|
||||
for (int y = 0; y < Sector.HEIGHT; y++) {
|
||||
for (int x = 0; x < Sector.WIDTH; x++) {
|
||||
int bx = bigX + x;
|
||||
@ -92,7 +91,7 @@ public class WorldLoader {
|
||||
/** end of shit **/
|
||||
}
|
||||
}
|
||||
//System.out.println(3);
|
||||
//Logging.debug(3);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -130,7 +129,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); }
|
||||
for (Shop shop : (List<Shop>) PersistenceManager.load("locs/Shops.xml.gz")) {
|
||||
world.registerShop(shop);
|
||||
@ -142,14 +141,14 @@ public class WorldLoader {
|
||||
public void loadObjects() {
|
||||
World world = Instance.getWorld();
|
||||
for (GameObjectLoc gameObject : (List<GameObjectLoc>) PersistenceManager.load("locs/GameObjectLoc.xml.gz")) {
|
||||
if(Constants.GameServer.F2P_WILDY && Formulae.isP2P(true, gameObject))
|
||||
if(Config.f2pWildy && Formulae.isP2P(true, gameObject))
|
||||
continue;
|
||||
if (Formulae.isP2P(gameObject) && !World.isMembers())
|
||||
continue;
|
||||
world.registerGameObject(new GameObject(gameObject));
|
||||
}
|
||||
for (ItemLoc item : (List<ItemLoc>) PersistenceManager.load("locs/ItemLoc.xml.gz")) {
|
||||
if(Constants.GameServer.F2P_WILDY && Formulae.isP2P(true, item))
|
||||
if(Config.f2pWildy && Formulae.isP2P(true, item))
|
||||
continue;
|
||||
if (Formulae.isP2P(item) && !World.isMembers())
|
||||
continue;
|
||||
@ -157,7 +156,7 @@ public class WorldLoader {
|
||||
}// ember
|
||||
|
||||
for (NPCLoc npc : (List<NPCLoc>) PersistenceManager.load("locs/NpcLoc.xml.gz")) {
|
||||
if(Constants.GameServer.F2P_WILDY && Formulae.isP2P(true, npc))
|
||||
if(Config.f2pWildy && Formulae.isP2P(true, npc))
|
||||
continue;
|
||||
if (Formulae.isP2P(npc) && !World.isMembers())
|
||||
continue;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.moparscape.msc.gs.model;
|
||||
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
@ -185,7 +186,7 @@ public class Entity {
|
||||
}
|
||||
|
||||
public void setLocation(Point p) {
|
||||
if(this instanceof Player && location != null && Constants.GameServer.F2P_WILDY) {
|
||||
if(this instanceof Player && location != null && Config.f2pWildy) {
|
||||
Player pl = (Player)this;
|
||||
if(pl != null && getX() > 0 && getY() > 0) {
|
||||
if(!Point.inWilderness(getX(), getY()) && Point.inWilderness(p.getX(), p.getY())) {
|
||||
|
@ -3,6 +3,7 @@ package org.moparscape.msc.gs.model;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ConcurrentModificationException;
|
||||
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
@ -423,7 +424,7 @@ public class Npc extends Mob {
|
||||
int hit = DataConversions.random(0, total);
|
||||
total = 0;
|
||||
if (!this.getDef().name.equalsIgnoreCase("ghost")) {
|
||||
if (this.getCombatLevel() >= 90 && Constants.GameServer.MEMBER_WORLD) {
|
||||
if (this.getCombatLevel() >= 90 && Config.members) {
|
||||
if (Formulae.Rand(0, 3000) == 500) {
|
||||
if (Formulae.Rand(0, 1) == 1) {
|
||||
world.registerItem(new Item(1276, getX(), getY(), 1, owner));
|
||||
|
@ -14,6 +14,7 @@ import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
@ -22,7 +23,6 @@ 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;
|
||||
import org.moparscape.msc.gs.event.RangeEvent;
|
||||
@ -851,7 +851,7 @@ public final class Player extends Mob {
|
||||
}
|
||||
|
||||
public boolean canLogout() {
|
||||
if(this.location.inWilderness()) {
|
||||
if(this != null && this.location != null && this.location.inWilderness()) {
|
||||
if(GameEngine.getTime() - this.getLastMoved() < 10000) {
|
||||
getActionSender().sendMessage("You must stand peacefully in one place for 10 seconds!");
|
||||
return false;
|
||||
@ -1511,9 +1511,9 @@ public final class Player extends Mob {
|
||||
return;
|
||||
}
|
||||
|
||||
double exprate = Constants.GameServer.EXP_RATE;
|
||||
double exprate = Config.expRate;
|
||||
if (isSubscriber()) {
|
||||
exprate = Constants.GameServer.SUB_EXP_RATE;
|
||||
exprate = Config.subExpRate;
|
||||
}
|
||||
|
||||
if(getLocation().wildernessLevel() > 1) {
|
||||
@ -1741,7 +1741,7 @@ public final class Player extends Mob {
|
||||
* Restricts P2P stuff in wilderness.
|
||||
*/
|
||||
public void p2pWildy() {
|
||||
if (Constants.GameServer.F2P_WILDY) {
|
||||
if (Config.f2pWildy) {
|
||||
|
||||
boolean found = false;
|
||||
for (InvItem i : getInventory().getItems()) {
|
||||
@ -2421,7 +2421,7 @@ public final class Player extends Mob {
|
||||
}
|
||||
|
||||
public void setNpc(Npc npc) {
|
||||
// System.out.println("setNpc(npc)");
|
||||
// Logging.debug("setNpc(npc)");
|
||||
interactingNpc = npc;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package org.moparscape.msc.gs.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.moparscape.msc.gs.model.mini.Damager;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.model.mini.Damage;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
|
||||
/**
|
||||
* Each NPC has a Damage Syndicate (pool of damage) binded to them.
|
||||
@ -12,36 +15,76 @@ import org.moparscape.msc.gs.model.mini.Damager;
|
||||
*
|
||||
*/
|
||||
public class Syndicate {
|
||||
/**
|
||||
* All the damagers of this NPC Syndicate
|
||||
*/
|
||||
private ArrayList<Damager> damagers = new ArrayList<Damager>();
|
||||
|
||||
public void addDamage(Player p, int damage, boolean magic, boolean combat, boolean ranged) {
|
||||
boolean exist = false;
|
||||
Damager other = null;
|
||||
for (Damager damager : getDamagers()) {
|
||||
if (damager.getPlayer().getUsername().equals(p.getUsername())) {
|
||||
exist = true;
|
||||
other = damager;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
other = new Damager(p);
|
||||
getDamagers().add(other);
|
||||
}
|
||||
other.setDamage(other.getDamage() + damage);
|
||||
if (magic)
|
||||
other.setUseMagic(true);
|
||||
if (combat)
|
||||
other.setUseCombat(true);
|
||||
if (ranged)
|
||||
other.setUseRanged(true);
|
||||
}
|
||||
private Map<Player, Damage> damage = new WeakHashMap<Player, Damage>();
|
||||
|
||||
public ArrayList<Damager> getDamagers() {
|
||||
return damagers;
|
||||
}
|
||||
public void addDamage(final Player player, final int damage,
|
||||
final int damageType) {
|
||||
final Damage prev = this.damage.get(player);
|
||||
if (prev != null) {
|
||||
prev.addDamage(damage, damageType);
|
||||
} else {
|
||||
this.damage.put(player, new Damage(damage, damageType));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Player, Damage> getDamages() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public void distributeExp(final Npc npc) {
|
||||
final Map<Player, Damage> dmgs = getDamages();
|
||||
final int exp = DataConversions.roundUp(Formulae
|
||||
.combatExperience(npc) / 4D);
|
||||
int newXP = 0;
|
||||
for (final Player p : dmgs.keySet()) {
|
||||
Damage dmg = dmgs.get(p);
|
||||
int total = dmg.getTotalDamage();
|
||||
if (total > npc.getDef().hits) {
|
||||
total = npc.getDef().hits;
|
||||
}
|
||||
if (p != null) {
|
||||
newXP = (exp * total) / npc.getDef().hits;
|
||||
|
||||
p.incExp(4, roundAndCast(newXP * 4 * dmg.getRangePortion()),
|
||||
true);
|
||||
p.getActionSender().sendStat(4);
|
||||
switch (p.getCombatStyle()) {
|
||||
case 0:
|
||||
for (int x = 0; x < 3; x++) {
|
||||
p.incExp(x,
|
||||
roundAndCast(newXP * dmg.getCombatPortion()),
|
||||
true);
|
||||
p.getActionSender().sendStat(x);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
p.incExp(2,
|
||||
roundAndCast(newXP * 3 * dmg.getCombatPortion()),
|
||||
true);
|
||||
p.getActionSender().sendStat(2);
|
||||
break;
|
||||
case 2:
|
||||
p.incExp(0,
|
||||
roundAndCast(newXP * 3 * dmg.getCombatPortion()),
|
||||
true);
|
||||
p.getActionSender().sendStat(0);
|
||||
break;
|
||||
case 3:
|
||||
p.incExp(1,
|
||||
roundAndCast(newXP * 3 * dmg.getCombatPortion()),
|
||||
true);
|
||||
p.getActionSender().sendStat(1);
|
||||
break;
|
||||
}
|
||||
p.incExp(3, roundAndCast(newXP * dmg.getCombatPortion()), true);
|
||||
p.getActionSender().sendStat(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int roundAndCast(double d) {
|
||||
return (int) Math.round(d);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.Server;
|
||||
import org.moparscape.msc.gs.core.ClientUpdater;
|
||||
import org.moparscape.msc.gs.core.DelayedEventHandler;
|
||||
@ -128,7 +128,7 @@ public final class World {
|
||||
}
|
||||
|
||||
public static boolean isMembers() {
|
||||
return Constants.GameServer.MEMBER_WORLD;
|
||||
return Config.members;
|
||||
}
|
||||
public WorldLoader wl;
|
||||
/**
|
||||
|
77
GameServer/src/org/moparscape/msc/gs/model/mini/Damage.java
Normal file
77
GameServer/src/org/moparscape/msc/gs/model/mini/Damage.java
Normal file
@ -0,0 +1,77 @@
|
||||
package org.moparscape.msc.gs.model.mini;
|
||||
|
||||
/**
|
||||
* Damage values
|
||||
*
|
||||
* @author CodeForFame
|
||||
*
|
||||
*/
|
||||
public class Damage {
|
||||
|
||||
public static final int COMBAT_DAMAGE = 0;
|
||||
public static final int MAGIC_DAMAGE = 1;
|
||||
public static final int RANGE_DAMAGE = 2;
|
||||
|
||||
private final int[] damage = new int[3];
|
||||
|
||||
public Damage(final int damage, final int type) {
|
||||
this.addDamage(damage, type);
|
||||
}
|
||||
|
||||
public int getMagicDamage() {
|
||||
return damage[MAGIC_DAMAGE];
|
||||
}
|
||||
|
||||
public void setMagicDamage(final int damage) {
|
||||
this.damage[MAGIC_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addMagicDamage(final int damage) {
|
||||
this.damage[MAGIC_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public int getRangeDamage() {
|
||||
return this.damage[RANGE_DAMAGE];
|
||||
}
|
||||
|
||||
public void setRangeDamage(final int damage) {
|
||||
this.damage[RANGE_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addRangeDamage(final int damage) {
|
||||
this.damage[RANGE_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public int getCombatDamage() {
|
||||
return damage[COMBAT_DAMAGE];
|
||||
}
|
||||
|
||||
public void setCombatDamage(final int damage) {
|
||||
this.damage[COMBAT_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addCombatDamage(final int damage) {
|
||||
this.damage[COMBAT_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public void addDamage(final int damage, final int damageType) {
|
||||
// CBF typing out legit bounds checking...
|
||||
this.damage[damageType % 3] += damage;
|
||||
}
|
||||
|
||||
public int getTotalDamage() {
|
||||
return getCombatDamage() + getRangeDamage() + getMagicDamage();
|
||||
}
|
||||
|
||||
public double getRangePortion() {
|
||||
return getRangeDamage() / getTotalDamage();
|
||||
}
|
||||
|
||||
public double getMagicPortion() {
|
||||
return getMagicDamage() / getTotalDamage();
|
||||
}
|
||||
|
||||
public double getCombatPortion() {
|
||||
return getCombatDamage() / getTotalDamage();
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package org.moparscape.msc.gs.model.mini;
|
||||
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
|
||||
/**
|
||||
* a Damager (Player) that adds to a pool (Syndicate) of an NPC
|
||||
*
|
||||
* @author xEnt
|
||||
*
|
||||
*/
|
||||
public class Damager {
|
||||
|
||||
/**
|
||||
* Damage this player has dealt
|
||||
*/
|
||||
private int damage = 0;
|
||||
/**
|
||||
* the Player/Damager
|
||||
*/
|
||||
private Player player;
|
||||
/**
|
||||
* Have they used melee on this NPC?
|
||||
*/
|
||||
private boolean useCombat = false;
|
||||
/**
|
||||
* Have they used magic on this NPC?
|
||||
*/
|
||||
private boolean useMagic = false;
|
||||
/**
|
||||
* Have they used ranged on this NPC?
|
||||
*/
|
||||
private boolean useRanged = false;
|
||||
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public void setDamage(int damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public boolean isUseCombat() {
|
||||
return useCombat;
|
||||
}
|
||||
|
||||
public void setUseCombat(boolean useCombat) {
|
||||
this.useCombat = useCombat;
|
||||
}
|
||||
|
||||
public boolean isUseMagic() {
|
||||
return useMagic;
|
||||
}
|
||||
|
||||
public void setUseMagic(boolean useMagic) {
|
||||
this.useMagic = useMagic;
|
||||
}
|
||||
|
||||
public boolean isUseRanged() {
|
||||
return useRanged;
|
||||
}
|
||||
|
||||
public void setUseRanged(boolean useRanged) {
|
||||
this.useRanged = useRanged;
|
||||
}
|
||||
|
||||
public Damager(Player p) {
|
||||
this.player = p;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package org.moparscape.msc.gs.phandler;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
@ -140,7 +141,7 @@ public class PlayerLogin implements PacketHandler {
|
||||
|
||||
player.setQuestPoints(p.readShort(), false);
|
||||
int questCount = p.readShort();
|
||||
// System.out.println(questCount);
|
||||
// Logging.debug(questCount);
|
||||
for (int i = 0; i < questCount; i++)
|
||||
player.setQuestStage(p.readShort(), p.readShort(), false, false);
|
||||
|
||||
@ -230,7 +231,7 @@ public class PlayerLogin implements PacketHandler {
|
||||
sender.sendOnlinePlayers();
|
||||
|
||||
if(newchar)
|
||||
player.getActionSender().sendMessage("@ran@Talk to the Community Instructor for information about " + Constants.GameServer.SERVER_NAME);
|
||||
player.getActionSender().sendMessage("@ran@Talk to the Community Instructor for information about " + Config.SERVER_NAME);
|
||||
|
||||
if (player.clientWarn()) {
|
||||
player.getActionSender().sendAlert("@red@Alert! @whi@You are using an old client, please download the new client from our website. This client WILL stop working @red@soon.", false);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.moparscape.msc.gs.phandler.client;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.connection.Packet;
|
||||
@ -152,7 +152,7 @@ public class AttackHandler implements PacketHandler {
|
||||
player.resetPath();
|
||||
return;
|
||||
}
|
||||
if(Constants.GameServer.F2P_WILDY && player.getLocation().inWilderness()) {
|
||||
if(Config.f2pWildy && player.getLocation().inWilderness()) {
|
||||
|
||||
for(InvItem i : player.getInventory().getItems()) {
|
||||
if(i.getID() == 638 || i.getID() == 640 || i.getID() == 642 || i.getID() == 644 || i.getID() == 646) {
|
||||
|
@ -47,11 +47,6 @@ public class BotHandler implements PacketHandler {
|
||||
if (pl.lastPlayerInfo2 == null)
|
||||
continue;
|
||||
String s = "Client Statistics for " + player.getUsername() + ": Scar: " + scar + ", WPE: " + wpe + ", Autominer: " + autominer + ", 3rd Party Client: " + player.badClient;
|
||||
if (pl.lastPlayerInfo2.equals("(IRC)")) {
|
||||
Instance.getIRC().sendMessage(s);
|
||||
pl.lastPlayerInfo2 = null;
|
||||
return;
|
||||
}
|
||||
if (pl.lastPlayerInfo2.equalsIgnoreCase(player.getUsername())) {
|
||||
|
||||
s = s.replace("true", "@gre@true@whi@");
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.moparscape.msc.gs.phandler.client;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.builders.RSCPacketBuilder;
|
||||
import org.moparscape.msc.gs.connection.Packet;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
@ -14,7 +15,7 @@ public class DummyPacket implements PacketHandler {
|
||||
if (p.getLength() > 2) { // 1 for byte, 2 for short
|
||||
byte b = p.readByte();
|
||||
int clientVersion = p.readShort();
|
||||
if (clientVersion > 34 && clientVersion < 40) {
|
||||
if (clientVersion > Config.SERVER_VERSION - 5 && clientVersion < Config.SERVER_VERSION + 1) {
|
||||
RSCPacketBuilder pb = new RSCPacketBuilder();
|
||||
pb.setBare(true);
|
||||
pb.addByte((byte) 4); // client update
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.alert.AlertHandler;
|
||||
import org.moparscape.msc.gs.builders.ls.MiscPacketBuilder;
|
||||
import org.moparscape.msc.gs.connection.Packet;
|
||||
import org.moparscape.msc.gs.connection.RSCPacket;
|
||||
@ -68,7 +69,7 @@ public class FriendHandler implements PacketHandler {
|
||||
s = s.replace(".", "");
|
||||
if (s.contains("runeblast")) {
|
||||
Logger.println(player.getUsername() + " pmed " + DataConversions.hashToUsername(friend) + ":" + k);
|
||||
Instance.getIRC().sendMessage(player.getUsername() + " pmed " + DataConversions.hashToUsername(friend) + ":" + k);
|
||||
AlertHandler.sendAlert(player.getUsername() + " pmed " + DataConversions.hashToUsername(friend) + ":" + k, 2);
|
||||
return;
|
||||
}
|
||||
ArrayList<String> temp = new ArrayList<String>();
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.moparscape.msc.gs.phandler.client;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.Server;
|
||||
import org.moparscape.msc.gs.connection.Packet;
|
||||
@ -42,7 +42,7 @@ public class InvActionHandler implements PacketHandler {
|
||||
player.setSuspiciousPlayer(true);
|
||||
return;
|
||||
}
|
||||
if(item.getDef().isMembers() && Constants.GameServer.F2P_WILDY && player.getLocation().inWilderness() && item.getID() != 814) {
|
||||
if(item.getDef().isMembers() && Config.f2pWildy && player.getLocation().inWilderness() && item.getID() != 814) {
|
||||
player.getActionSender().sendMessage("Can not use a Member item in the wilderness");
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.moparscape.msc.gs.phandler.client;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.Server;
|
||||
@ -36,7 +36,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
|
||||
private boolean attachFeathers(Player player, final InvItem feathers, final InvItem item) {
|
||||
int amount = 10;
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return true;
|
||||
}
|
||||
@ -89,7 +89,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
|
||||
private boolean doArrowHeads(Player player, final InvItem headlessArrows, final InvItem arrowHeads) {
|
||||
final ItemArrowHeadDef headDef = EntityHandler.getItemArrowHeadDef(arrowHeads.getID());
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return true;
|
||||
}
|
||||
@ -125,7 +125,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
|
||||
private boolean doBowString(Player player, final InvItem bowString, final InvItem bow) {
|
||||
final ItemBowStringDef stringDef = EntityHandler.getItemBowStringDef(bow.getID());
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return true;
|
||||
}
|
||||
@ -180,7 +180,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
if (glass.getID() != 623) {
|
||||
return false;
|
||||
}
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return true;
|
||||
}
|
||||
@ -254,7 +254,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
if (herbDef == null) {
|
||||
return false;
|
||||
}
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return true;
|
||||
}
|
||||
@ -277,7 +277,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
}
|
||||
|
||||
private boolean doHerbSecond(Player player, final InvItem second, final InvItem unfinished, final ItemHerbSecond def) {
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return true;
|
||||
}
|
||||
@ -304,7 +304,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
private boolean doLogCut(final Player player, final InvItem knife, final InvItem log, int times) {
|
||||
final int retries = --times;
|
||||
final ItemLogCutDef cutDef = EntityHandler.getItemLogCutDef(log.getID());
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return true;
|
||||
}
|
||||
@ -810,7 +810,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
|
||||
for (int i = 0; i < combinePotions.length; i++) {
|
||||
if ((item1.getID() == combinePotions[i][0] && item2.getID() == combinePotions[i][1]) || (item2.getID() == combinePotions[i][0] && item1.getID() == combinePotions[i][1])) {
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return;
|
||||
}
|
||||
@ -821,7 +821,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
return;
|
||||
}
|
||||
} else if (item1.getID() == combinePotions[i][1] && item2.getID() == combinePotions[i][1]) {
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return;
|
||||
}
|
||||
@ -835,7 +835,7 @@ public class InvUseOnItem implements PacketHandler {
|
||||
player.getActionSender().sendMessage("You combine the Potions");
|
||||
return;
|
||||
} else if (item1.getID() == combinePotions[i][0] && item2.getID() == combinePotions[i][0]) {
|
||||
if (!Constants.GameServer.MEMBER_WORLD) {
|
||||
if (!Config.members) {
|
||||
player.getActionSender().sendMessage("This feature is not avaliable in f2p");
|
||||
return;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package org.moparscape.msc.gs.phandler.client;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.Server;
|
||||
@ -39,6 +39,7 @@ import org.moparscape.msc.gs.phandler.PacketHandler;
|
||||
import org.moparscape.msc.gs.plugins.extras.Thieving;
|
||||
import org.moparscape.msc.gs.states.Action;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
|
||||
public class ObjectAction implements PacketHandler {
|
||||
@ -73,7 +74,7 @@ public class ObjectAction implements PacketHandler {
|
||||
/*
|
||||
if (newtime == 0) {
|
||||
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++;
|
||||
}
|
||||
} else {// dummy
|
||||
@ -81,7 +82,7 @@ public class ObjectAction implements PacketHandler {
|
||||
player.lastPacketTime = newtime;
|
||||
else {
|
||||
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);
|
||||
} else {
|
||||
player.lastPacketTime = newtime;
|
||||
@ -126,12 +127,12 @@ public class ObjectAction implements PacketHandler {
|
||||
}
|
||||
world.addEntryToSnapshots(new Activity(owner.getUsername(), owner.getUsername() + " used an Object (" + object.getID() + ") @ " + object.getX() + ", " + object.getY()));
|
||||
owner.resetAll();
|
||||
if (object.getX() == 621 && object.getY() == 596 && Constants.GameServer.F2P_WILDY) {
|
||||
if (object.getX() == 621 && object.getY() == 596 && Config.f2pWildy) {
|
||||
owner.getActionSender().sendMessage("Currently disabled!1!");
|
||||
return;
|
||||
}
|
||||
String command = (click == 0 ? def.getCommand1() : def.getCommand2()).toLowerCase();
|
||||
// System.out.println(object.getID() + " " +
|
||||
// Logging.debug(object.getID() + " " +
|
||||
// command);
|
||||
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);
|
||||
@ -164,7 +165,7 @@ public class ObjectAction implements PacketHandler {
|
||||
// owner.teleport(251, 1411, false);
|
||||
}
|
||||
}
|
||||
System.out.println("Command: " + command);
|
||||
Logger.println("Command: " + command);
|
||||
if(command.equalsIgnoreCase("talk to") && object.getID() == 391) {
|
||||
|
||||
final String[] options = { "Yes please!", "No thanks I prefer to walk!" };
|
||||
|
@ -51,17 +51,20 @@ public class PickupItem implements PacketHandler {
|
||||
int id = p.readShort();
|
||||
final ActiveTile tile = world.getTile(location);
|
||||
final Item item = getItem(id, tile, player);
|
||||
|
||||
if (item == null) {
|
||||
//player.setSuspiciousPlayer(true);
|
||||
player.resetPath();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!item.getDef().canTrade()) {
|
||||
if(item.droppedby() != 0 && org.moparscape.msc.gs.tools.DataConversions.usernameToHash(player.getUsername()) != item.droppedby()) {
|
||||
player.getActionSender().sendMessage("This item is non-tradable.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (item == null) {
|
||||
//player.setSuspiciousPlayer(true);
|
||||
player.resetPath();
|
||||
return;
|
||||
}
|
||||
|
||||
if(player.isPMod() && !player.isMod())
|
||||
return;
|
||||
if (item.getDef().isMembers() && !World.isMembers()) {
|
||||
@ -70,7 +73,7 @@ public class PickupItem implements PacketHandler {
|
||||
}
|
||||
|
||||
player.setStatus(Action.TAKING_GITEM);
|
||||
Instance.getDelayedEventHandler().add(new WalkToPointEvent(player, location, 1, false) {
|
||||
Instance.getDelayedEventHandler().add(new WalkToPointEvent(player, location, 0, true) {
|
||||
public void arrived() {
|
||||
if (owner.isBusy() || owner.isRanging() || !tile.hasItem(item) || !owner.nextTo(item) || owner.getStatus() != Action.TAKING_GITEM) {
|
||||
return;
|
||||
|
@ -62,7 +62,7 @@ public class PlayerLogin implements PacketHandler {
|
||||
}
|
||||
else {
|
||||
player.load(username, password, 0, reconnecting);
|
||||
if (clientVersion < 39) {
|
||||
if (clientVersion < Config.SERVER_VERSION) {
|
||||
player.clientWarn(true);
|
||||
}
|
||||
return;
|
||||
|
@ -2,6 +2,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.alert.AlertHandler;
|
||||
import org.moparscape.msc.gs.connection.Packet;
|
||||
import org.moparscape.msc.gs.db.ReportHandlerQueries;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
@ -36,7 +37,7 @@ public class ReportHandler implements PacketHandler {
|
||||
player.getActionSender().sendMessage("You can't report yourself!");
|
||||
return;
|
||||
}
|
||||
Instance.getIRC().handleReport(player.getUsername(), DataConversions.hashToUsername(temp), b);
|
||||
AlertHandler.sendAlert(player.getUsername() + " sent a repot about: " + DataConversions.hashToUsername(temp), 1);
|
||||
//Instance.getServer().getLoginConnector().getActionSender().reportUser(player.getUsernameHash(), temp, b);
|
||||
Instance.getReport().submitRepot(player.getUsernameHash(), temp, b, player);
|
||||
player.setLastReport();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -107,7 +107,7 @@ public class TalkToNpcHandler implements PacketHandler {
|
||||
if (!(e instanceof InvocationTargetException)) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(affectedNpc.getID());
|
||||
Logger.println(affectedNpc.getID());
|
||||
affectedNpc.unblock();
|
||||
owner.setBusy(false);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.connection.Packet;
|
||||
@ -16,6 +16,7 @@ import org.moparscape.msc.gs.model.Script;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.phandler.PacketHandler;
|
||||
import org.moparscape.msc.gs.quest.Quest;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
|
||||
public class WieldHandler implements PacketHandler {
|
||||
@ -45,7 +46,7 @@ public class WieldHandler implements PacketHandler {
|
||||
player.setSuspiciousPlayer(true);
|
||||
return;
|
||||
}
|
||||
if(player.getLocation().inWilderness() && item.getDef().isMembers() && Constants.GameServer.F2P_WILDY) {
|
||||
if(player.getLocation().inWilderness() && item.getDef().isMembers() && Config.f2pWildy) {
|
||||
player.getActionSender().sendMessage("Can't wield a P2P item in wilderness");
|
||||
return;
|
||||
}
|
||||
@ -90,7 +91,7 @@ public class WieldHandler implements PacketHandler {
|
||||
player.getActionSender().sendMessage("You must have at least " + youNeed.substring(0, youNeed.length() - 2) + " to use this item.");
|
||||
return;
|
||||
}
|
||||
if (Constants.GameServer.MEMBER_WORLD) {
|
||||
if (Config.members) {
|
||||
if (item.getID() == 594) {
|
||||
int count = 0;
|
||||
for (Quest q : World.getQuestManager().getQuests()) {
|
||||
@ -101,7 +102,7 @@ public class WieldHandler implements PacketHandler {
|
||||
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) {
|
||||
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");
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.moparscape.msc.gs.plugins.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
@ -9,11 +10,10 @@ import org.moparscape.msc.gs.model.GameObject;
|
||||
import org.moparscape.msc.gs.model.Npc;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.model.Projectile;
|
||||
import org.moparscape.msc.gs.model.mini.Damager;
|
||||
import org.moparscape.msc.gs.model.mini.Damage;
|
||||
import org.moparscape.msc.gs.plugins.dependencies.NpcAI;
|
||||
import org.moparscape.msc.gs.plugins.dependencies.NpcScript;
|
||||
|
||||
|
||||
/**
|
||||
* KingBlackDragon intelligence class.
|
||||
*
|
||||
@ -22,156 +22,187 @@ import org.moparscape.msc.gs.plugins.dependencies.NpcScript;
|
||||
*/
|
||||
public class KingBlackDragon extends NpcScript implements NpcAI {
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return 477;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHealthPercentage(Npc npc, int percent) {
|
||||
/*
|
||||
* if(percent > 60 && percent <= 80 && npc.getStage() == 1) {
|
||||
* npc.setStage(2); shootFire(npc); } if(percent > 45 && percent <= 60
|
||||
* && npc.getStage() == 2) { npc.setStage(3); if(npc.getOpponent() !=
|
||||
* null || npc.getOpponent() instanceof Player) { sendNpcChat(npc,
|
||||
* (Player)npc.getOpponent(), "You can't kill me damn humans", true); }
|
||||
* } if(percent > 35 && percent < 50 && npc.getStage() == 3) {
|
||||
* npc.setStage(4); shootFire(npc); } if(percent > 5 && percent < 25 &&
|
||||
* npc.getStage() == 4) { npc.setStage(5); absorbHealth(npc); }
|
||||
* if(percent > 50 && percent < 65 && npc.getStage() == 5) {
|
||||
* npc.setStage(6); shootFire(npc); } if(percent > 42 && percent < 49 &&
|
||||
* npc.getStage() == 5) { npc.setStage(7); for(Player p :
|
||||
* npc.getViewArea().getPlayersInView()) { if(p != null) {
|
||||
* p.getActionSender().sendMessage("The " + npc.getDef().name +
|
||||
* " gets stronger!"); npc.getDef().strength+=npc.getDef().strength *
|
||||
* 0.30; } } } if(percent > 25 && percent < 40 && npc.getStage() == 7) {
|
||||
* npc.setStage(8); shootFire(npc); }
|
||||
*/
|
||||
}
|
||||
|
||||
public void absorbHealth(Npc npc) {
|
||||
for (Damager dam : npc.getSyndicate().getDamagers()) {
|
||||
if (dam == null || dam.getPlayer() == null)
|
||||
continue;
|
||||
|
||||
int drain = Formulae.Rand((int) (dam.getPlayer().getMaxStat(3) * 0.25) / 2, (int) (dam.getPlayer().getMaxStat(3) * 0.25));
|
||||
Projectile projectile = new Projectile(dam.getPlayer(), npc, 4);
|
||||
int newhp = npc.getCurHits() + drain;
|
||||
if (newhp > npc.getDef().hits)
|
||||
newhp = npc.getDef().hits;
|
||||
npc.setHits(newhp);
|
||||
ArrayList<Player> playersToInform = new ArrayList<Player>();
|
||||
playersToInform.addAll(npc.getViewArea().getPlayersInView());
|
||||
playersToInform.addAll(dam.getPlayer().getViewArea().getPlayersInView());
|
||||
for (Player p : playersToInform) {
|
||||
p.informOfModifiedHits(npc);
|
||||
p.informOfProjectile(projectile);
|
||||
}
|
||||
|
||||
shootPlayer(npc, dam.getPlayer(), drain, 1);
|
||||
dam.getPlayer().getActionSender().sendMessage("The " + npc.getDef().name + " absorbs health from you");
|
||||
@Override
|
||||
public int getID() {
|
||||
return 477;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMageAttack(Player attacker, Npc npc) {
|
||||
/*
|
||||
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, attacker,
|
||||
* "Feel my Wrath Humans!", true); shootFire(npc); }
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(Player attacker, final Npc npc) {
|
||||
/*if (attacker.getCurStat(5) > (int) (attacker.getMaxStat(5) * 0.01)) {
|
||||
attacker.setCurStat(5, (int) (attacker.getMaxStat(5) * 0.01));
|
||||
attacker.getActionSender().sendStat(5);
|
||||
attacker.getActionSender().sendMessage("The dragon lowers your Prayer");
|
||||
}*/
|
||||
if (attacker.getCurStat(5) > 0) {
|
||||
//attacker.setCurStat(5, (int)(attacker.getCurStat(5) * 0.10));
|
||||
// for (int prayerID = 0; prayerID < 14; prayerID++) {
|
||||
// attacker.setPrayer(prayerID, false);
|
||||
// }
|
||||
// attacker.setDrainRate(0);
|
||||
// attacker.getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
|
||||
// attacker.getActionSender().sendPrayers();
|
||||
@Override
|
||||
public void onHealthPercentage(Npc npc, int percent) {
|
||||
/*
|
||||
* if(percent > 60 && percent <= 80 && npc.getStage() == 1) {
|
||||
* npc.setStage(2); shootFire(npc); } if(percent > 45 && percent <= 60
|
||||
* && npc.getStage() == 2) { npc.setStage(3); if(npc.getOpponent() !=
|
||||
* null || npc.getOpponent() instanceof Player) { sendNpcChat(npc,
|
||||
* (Player)npc.getOpponent(), "You can't kill me damn humans", true); }
|
||||
* } if(percent > 35 && percent < 50 && npc.getStage() == 3) {
|
||||
* npc.setStage(4); shootFire(npc); } if(percent > 5 && percent < 25 &&
|
||||
* npc.getStage() == 4) { npc.setStage(5); absorbHealth(npc); }
|
||||
* if(percent > 50 && percent < 65 && npc.getStage() == 5) {
|
||||
* npc.setStage(6); shootFire(npc); } if(percent > 42 && percent < 49 &&
|
||||
* npc.getStage() == 5) { npc.setStage(7); for(Player p :
|
||||
* npc.getViewArea().getPlayersInView()) { if(p != null) {
|
||||
* p.getActionSender().sendMessage("The " + npc.getDef().name +
|
||||
* " gets stronger!"); npc.getDef().strength+=npc.getDef().strength *
|
||||
* 0.30; } } } if(percent > 25 && percent < 40 && npc.getStage() == 7) {
|
||||
* npc.setStage(8); shootFire(npc); }
|
||||
*/
|
||||
}
|
||||
/*
|
||||
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, attacker,
|
||||
* "Feel my Wrath Humans!", true); }
|
||||
*/
|
||||
}
|
||||
|
||||
public void shootFire(Npc npc) {
|
||||
try {
|
||||
if (npc != null) {
|
||||
if (npc.getOpponent() != null && npc.getOpponent() instanceof Player) {
|
||||
Instance.getDelayedEventHandler().add(new org.moparscape.msc.gs.event.MiniEvent((Player) npc.getOpponent(), 2500, new Object[] { npc }) {
|
||||
public void action() {
|
||||
Npc n = (Npc) super.args[0];
|
||||
if (n != null || n.getHits() > 0) {
|
||||
NpcScript script = new NpcScript();
|
||||
for (Damager dam : n.getSyndicate().getDamagers()) {
|
||||
if (dam == null || dam.getPlayer() == null)
|
||||
continue;
|
||||
if (dam.getPlayer().equals(owner))
|
||||
continue;
|
||||
script.shootPlayer(n, dam.getPlayer(), Formulae.Rand((int) (dam.getPlayer().getMaxStat(3) * 0.25) / 2, (int) (dam.getPlayer().getMaxStat(3) * 0.25)), 1);
|
||||
dam.getPlayer().getActionSender().sendMessage("The " + n.getDef().name + " spits fire at you");
|
||||
GameObject obj = new GameObject(dam.getPlayer().getLocation(), 1036, 0, 0);
|
||||
world.registerGameObject(obj);
|
||||
Instance.getDelayedEventHandler().add(new ObjectRemover(obj, 500));
|
||||
Instance.getDelayedEventHandler().add(new org.moparscape.msc.gs.event.MiniEvent((Player) n.getOpponent(), 2500, new Object[] { n }) {
|
||||
public void action() {
|
||||
shootFire((Npc) super.args[0]);
|
||||
}
|
||||
public void absorbHealth(Npc npc) {
|
||||
final Map<Player, Damage> dmgs = npc.getSyndicate().getDamages();
|
||||
for (final Player p : dmgs.keySet()) {
|
||||
if (p == null)
|
||||
continue;
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
int drain = Formulae.Rand((int) (p.getMaxStat(3) * 0.25) / 2,
|
||||
(int) (p.getMaxStat(3) * 0.25));
|
||||
Projectile projectile = new Projectile(p, npc, 4);
|
||||
int newhp = npc.getCurHits() + drain;
|
||||
if (newhp > npc.getDef().hits)
|
||||
newhp = npc.getDef().hits;
|
||||
npc.setHits(newhp);
|
||||
ArrayList<Player> playersToInform = new ArrayList<Player>();
|
||||
playersToInform.addAll(npc.getViewArea().getPlayersInView());
|
||||
playersToInform.addAll(p.getViewArea().getPlayersInView());
|
||||
for (Player p1 : playersToInform) {
|
||||
p1.informOfModifiedHits(npc);
|
||||
p1.informOfProjectile(projectile);
|
||||
}
|
||||
});
|
||||
|
||||
shootPlayer(npc, p, drain, 1);
|
||||
p.getActionSender().sendMessage(
|
||||
"The " + npc.getDef().name + " absorbs health from you");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNpcAttack(Npc npc, Player player) {
|
||||
/*if (player.getCurStat(5) > (int) (player.getMaxStat(5) * 0.01)) {
|
||||
player.setCurStat(5, (int) (player.getMaxStat(5) * 0.01));
|
||||
player.getActionSender().sendStat(5);
|
||||
player.getActionSender().sendMessage("The dragon lowers your Prayer");
|
||||
}*/
|
||||
if (player.getCurStat(5) > 0) {
|
||||
//player.setCurStat(5, (int)(player.getCurStat(5) * 0.10));
|
||||
// for (int prayerID = 0; prayerID < 14; prayerID++) {
|
||||
// player.setPrayer(prayerID, false);
|
||||
// }
|
||||
// player.setDrainRate(0);
|
||||
//player.getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
|
||||
//player.getActionSender().sendPrayers();
|
||||
@Override
|
||||
public void onMageAttack(Player attacker, Npc npc) {
|
||||
/*
|
||||
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, attacker,
|
||||
* "Feel my Wrath Humans!", true); shootFire(npc); }
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNpcDeath(Npc npc, Player player) {
|
||||
/*
|
||||
* if(npc.getOpponent() != null || npc.getOpponent() instanceof Player)
|
||||
* { sendNpcChat(npc, (Player)npc.getOpponent(),
|
||||
* "I'll be back muhahahaa", true); }
|
||||
*/
|
||||
}
|
||||
@Override
|
||||
public void onMeleeAttack(Player attacker, final Npc npc) {
|
||||
/*
|
||||
* if (attacker.getCurStat(5) > (int) (attacker.getMaxStat(5) * 0.01)) {
|
||||
* attacker.setCurStat(5, (int) (attacker.getMaxStat(5) * 0.01));
|
||||
* attacker.getActionSender().sendStat(5);
|
||||
* attacker.getActionSender().sendMessage
|
||||
* ("The dragon lowers your Prayer"); }
|
||||
*/
|
||||
if (attacker.getCurStat(5) > 0) {
|
||||
// attacker.setCurStat(5, (int)(attacker.getCurStat(5) * 0.10));
|
||||
// for (int prayerID = 0; prayerID < 14; prayerID++) {
|
||||
// attacker.setPrayer(prayerID, false);
|
||||
// }
|
||||
// attacker.setDrainRate(0);
|
||||
// attacker.getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
|
||||
// attacker.getActionSender().sendPrayers();
|
||||
}
|
||||
/*
|
||||
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, attacker,
|
||||
* "Feel my Wrath Humans!", true); }
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRangedAttack(Player p, Npc npc) {
|
||||
/*
|
||||
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, p,
|
||||
* "Feel my Wrath Humans!", true); shootFire(npc); }
|
||||
*/
|
||||
}
|
||||
public void shootFire(Npc npc) {
|
||||
try {
|
||||
if (npc != null) {
|
||||
if (npc.getOpponent() != null
|
||||
&& npc.getOpponent() instanceof Player) {
|
||||
Instance.getDelayedEventHandler().add(
|
||||
new org.moparscape.msc.gs.event.MiniEvent(
|
||||
(Player) npc.getOpponent(), 2500,
|
||||
new Object[] { npc }) {
|
||||
public void action() {
|
||||
Npc n = (Npc) super.args[0];
|
||||
if (n != null || n.getHits() > 0) {
|
||||
NpcScript script = new NpcScript();
|
||||
final Map<Player, Damage> dmgs = n
|
||||
.getSyndicate().getDamages();
|
||||
for (final Player p : dmgs.keySet()) {
|
||||
if (p == null)
|
||||
continue;
|
||||
if (p.equals(owner))
|
||||
continue;
|
||||
script.shootPlayer(
|
||||
n,
|
||||
p,
|
||||
Formulae.Rand(
|
||||
(int) (p.getMaxStat(3) * 0.25) / 2,
|
||||
(int) (p.getMaxStat(3) * 0.25)),
|
||||
1);
|
||||
p.getActionSender()
|
||||
.sendMessage(
|
||||
"The "
|
||||
+ n.getDef().name
|
||||
+ " spits fire at you");
|
||||
GameObject obj = new GameObject(p
|
||||
.getLocation(), 1036, 0, 0);
|
||||
world.registerGameObject(obj);
|
||||
Instance.getDelayedEventHandler()
|
||||
.add(new ObjectRemover(obj,
|
||||
500));
|
||||
Instance.getDelayedEventHandler()
|
||||
.add(new org.moparscape.msc.gs.event.MiniEvent(
|
||||
(Player) n
|
||||
.getOpponent(),
|
||||
2500,
|
||||
new Object[] { n }) {
|
||||
public void action() {
|
||||
shootFire((Npc) super.args[0]);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNpcAttack(Npc npc, Player player) {
|
||||
/*
|
||||
* if (player.getCurStat(5) > (int) (player.getMaxStat(5) * 0.01)) {
|
||||
* player.setCurStat(5, (int) (player.getMaxStat(5) * 0.01));
|
||||
* player.getActionSender().sendStat(5);
|
||||
* player.getActionSender().sendMessage
|
||||
* ("The dragon lowers your Prayer"); }
|
||||
*/
|
||||
if (player.getCurStat(5) > 0) {
|
||||
// player.setCurStat(5, (int)(player.getCurStat(5) * 0.10));
|
||||
// for (int prayerID = 0; prayerID < 14; prayerID++) {
|
||||
// player.setPrayer(prayerID, false);
|
||||
// }
|
||||
// player.setDrainRate(0);
|
||||
// player.getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
|
||||
// player.getActionSender().sendPrayers();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNpcDeath(Npc npc, Player player) {
|
||||
/*
|
||||
* if(npc.getOpponent() != null || npc.getOpponent() instanceof Player)
|
||||
* { sendNpcChat(npc, (Player)npc.getOpponent(),
|
||||
* "I'll be back muhahahaa", true); }
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRangedAttack(Player p, Npc npc) {
|
||||
/*
|
||||
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, p,
|
||||
* "Feel my Wrath Humans!", true); shootFire(npc); }
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package org.moparscape.msc.gs.plugins.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.event.ObjectRemover;
|
||||
import org.moparscape.msc.gs.model.GameObject;
|
||||
@ -51,7 +51,7 @@ public class RedDragon extends NpcScript implements NpcAI {
|
||||
@Override
|
||||
public void onNpcDeath(Npc npc, Player player) {
|
||||
if(npc.getLocation().atAltar()) {
|
||||
if(Constants.GameServer.F2P_WILDY) {
|
||||
if(Config.f2pWildy) {
|
||||
switch(DataConversions.random(0, 3)) {
|
||||
case 0: {
|
||||
if(DataConversions.random(0, 2000) < 4) { // Drop d med
|
||||
|
@ -1,261 +0,0 @@
|
||||
package org.moparscape.msc.gs.plugins.extras;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
|
||||
public class Quiz extends Thread {
|
||||
|
||||
private static final int timeBetweenQuestions = 30; // Seconds.
|
||||
|
||||
static final World world = Instance.getWorld();
|
||||
|
||||
int phaze = 0;
|
||||
|
||||
int question = 0;
|
||||
// Question, Option1(A), Option2(B), Option3(C), Option4(D), Correct Option
|
||||
private final String[][] Quiz = { { "What is another name for sodium chloride?", "Salt", "Flour", "Sugar", "Oil", "a" }, { "What was Adam Sandler's first film called?", "Airheads", "Coneheads", "Going Overboard", "Happy Gilmore", "c" }, { "In terms of the ancient Roman empire, how was Nero related to Caligula?", "His Uncle", "His Brother", "His Nephew", "His Dad", "b" }, { "What do the Danish call Danish pastries?", "Danish Pastries", "Flatbread", "Viennese Bread", "Alsatian Cakes", "c" }, { "Which of these was once the national drink of Scotland?", "Claret", "Amaretto", "Vodka", "Scotch", "a" }, { "Which of the following was a predecessor of the Milky Way bar?", "Penny Plump", "Fat Emma", "Lardy Larry", "Milky Max", "b" }, { "Which is the deepest loch in Scotland?", "Loch Ness", "Loch Lomand", "Loch Morar", "Loch Ollie", "c" }, { "What was the first of Earth's supercontinents?", "Pangaea", "Gondwanaland", "Asia", "Rodinia", "d" }, { "In which country was the Can-Can invented?", "USA", "UK", "Canada", "England", "b" }, { "1987 saw the first Rugby Union World Cup. Who won it?", "New Zealand", "USA", "Fiji", "Japan", "a" }, { "What will a male lion often do in order to establish his authority when taking over a new pride?", "Kills The Lioness", "Mates and Leaves", "Kills the Cubs", "Hunts with the Pride", "c" }, { "Who is known as the father of modern day printing?", "Aristotle", "Mendel", "Theophrastus", "Gutenberg", "d" }, { "What group had the one hit wonder in the 90s by the name of 'Lovefool'?", "The Cardigans", "Creed", "The Coors", "Chumbawumba", "a" }, { "The color blue is said to represent which of the following emotions?", "Embarrassment", "Sadness", "Envy", "Anger", "b" }, { "Asteroids that are always closer to the Sun than the Earth are called?", "Argon", "Amor", "Aten", "Apollo", "c" }, { "During the Black Death, or Bubonic Plague, in mid 1300's Europe (approx.), what percentage of the population perished?", "One Tenth", "One Quarter", "One Third", "One Half", "c" }, { "What is the capital of Australia?", "Sydney", "Melbourne", "Canberra", "Liverpool", "c" }, { "A brogue is a type of what?", "Hat", "Shoe", "Guitar", "Shirt", "b" }, { "How many Wonders of the Ancient World were there?", "6", "7", "8", "9", "b" }, { "Which African nation did Winston Churchill once call 'the pearl of Africa?'", "Uganda", "Congo", "Chad", "Ethiopia", "a" }, { "What is the atomic number for Neon?", "1", "10", "30", "17", "b" }, { "An animal that eats only meat is called?", "A Canine", "An Omnivore", "A Carnivore", "None of the above", "c" }, { "According to the calendar of the time, when was Sir Isaac Newton born?", "November 4, 1642", "October 1, 1642", "December 25, 1642", "July 4, 1642", "c" }, { "Which fictional character lived in the Hundred Acre Wood?", "Winnie The Pooh", "Bambi", "Snow White", "Snoopy", "a" }, { "Which of the following does NOT Belong?", "Lincoln", "Mercury", "Ford", "Saturn", "d" }, { "Which of the following does NOT Belong?", "Pontiac", "Cadillac", "Hummer", "Mazda", "d" }, { "What does the term 'GUI' stands for?", "Graphics Unused Input", "Graphical User Interface", "Graphing Ultimate Interface", "Graph Unit Input", "b" }, { "In medicine, to examine a body part by listening to it is called what?", "Audiology", "Palpation", "Auscultation", "Radiology", "c" }, { "Of what is Botany the study?", "Plants", "Rocks", "Bugs", "Animals", "a" }, { "What element has a symbol on the periodic table that comes from the Latin word Aurum?", "Platinum", "Gold", "Silver", "Aluminum", "b" }, { "Which one of the following human bones is found in the wrist?", "Cochlea", "Cranium", "Femur", "Capitate", "d" }, { "", "", "", "", "", "" } // Leave
|
||||
// this
|
||||
// one
|
||||
// Blank.
|
||||
// It
|
||||
// won't
|
||||
// include. (Make sure its the last one)
|
||||
};
|
||||
|
||||
void endQuiz() {
|
||||
|
||||
try {
|
||||
// Clean's up the shit, reset's variables etc.
|
||||
|
||||
world.Quiz = false;
|
||||
world.QuizSignup = false;
|
||||
world.lastAnswer = null;
|
||||
|
||||
for (Player p : world.getPlayers()) {
|
||||
p.lastAnswer = null;
|
||||
p.hasAnswered = false;
|
||||
p.quizPoints = 0;
|
||||
}
|
||||
Logger.println("Destroying Thread, will create a stack.. ignore it.");
|
||||
Thread.currentThread().destroy();
|
||||
} catch (Exception e) {
|
||||
Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Error(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void handleAnswer(Player p) throws Exception {
|
||||
|
||||
if (!world.Quiz) {
|
||||
p.getActionSender().sendMessage("Sorry, It's not Quiz time just yet.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (p.hasAnswered) {
|
||||
p.getActionSender().sendMessage("You have already answered, please wait for the next question");
|
||||
return;
|
||||
}
|
||||
|
||||
p.hasAnswered = true;
|
||||
|
||||
if (p.lastAnswer.equalsIgnoreCase(world.lastAnswer)) {
|
||||
p.quizPoints++;
|
||||
}
|
||||
|
||||
p.getActionSender().sendMessage("You have answered @gre@(@whi@" + p.lastAnswer + "@gre@)");
|
||||
|
||||
p.lastAnswer = null;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* void removePlayer(Player p) throws Exception {
|
||||
*
|
||||
* try {
|
||||
*
|
||||
* int index = -1; for(int i=0; i < players.size(); i++) { if
|
||||
* (players.get(i).equals(p.getUsername())) index = i;
|
||||
*
|
||||
* if(i == -1) { System.out.println("Error removing " + p.getUsername() +
|
||||
* " from the Quiz list."); return; } else { System.out.println("[QUIZ] " +
|
||||
* players.get(index) + " has left the Quiz"); players.remove(index);
|
||||
* p.getActionSender().sendMessage("You have Quit the Quiz Queue"); } }
|
||||
*
|
||||
* } catch (Exception e) { Error(e); } }
|
||||
*/
|
||||
|
||||
/*
|
||||
* public void addPlayer(Player p) {
|
||||
*
|
||||
* try {
|
||||
*
|
||||
* if(!world.QuizSignup) return; if(p == null) return; if(!world.Quiz)
|
||||
* return; if(players.contains(p.getUsername())) return;
|
||||
*
|
||||
* players.add(p.getUsername());
|
||||
* p.getActionSender().sendMessage("You have Joined the Quiz Queue");
|
||||
*
|
||||
* } catch (Exception e) { Error(e); } }
|
||||
*/
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
if (world.Quiz)
|
||||
return;
|
||||
|
||||
world.QuizSignup = true;
|
||||
world.Quiz = false;
|
||||
|
||||
sayAll("@red@[QUIZ]@whi@ Quiz will be starting in @gre@" + timeBetweenQuestions + " @whi@seconds. Write @gre@::quiz@whi@ to join the quiz.", false, false);
|
||||
sayAll("@red@[QUIZ]@whi@ You will have @gre@" + timeBetweenQuestions + "@whi@ seconds to lock in the answers of each quiz.", false, false);
|
||||
sayAll("@red@[QUIZ]@whi@ Quiz results are tally'd up at the end. Use ::a ::b ::c ::d to answer.", false, false);
|
||||
|
||||
ActionListener phaze1 = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
|
||||
if (phaze == 0) { // the start of the quiz.
|
||||
phaze++;
|
||||
}
|
||||
|
||||
if (phaze == 1) {
|
||||
world.Quiz = true;
|
||||
if (question == 999) {
|
||||
tallyQuiz();
|
||||
endQuiz();
|
||||
}
|
||||
|
||||
for (Player p : world.getPlayers())
|
||||
p.hasAnswered = false;
|
||||
|
||||
sayAll("@red@[QUIZ]@gre@ " + question + "/" + (Quiz.length) + "@yel@ " + Quiz[question][0] + " @cya@(A) @whi@" + Quiz[question][1] + " @cya@(B)@whi@ " + Quiz[question][2] + " @cya@(C)@whi@ " + Quiz[question][3] + " @cya@(D) @whi@ " + Quiz[question][4], true, true);
|
||||
sayAll("@red@[QUIZ]@gre@ " + question + "/" + (Quiz.length) + "@yel@ " + Quiz[question][0] + " @cya@(A) @whi@" + Quiz[question][1] + " @cya@(B)@whi@ " + Quiz[question][2] + " @cya@(C)@whi@ " + Quiz[question][3] + " @cya@(D) @whi@ " + Quiz[question][4], false, true);
|
||||
world.lastAnswer = Quiz[question][5];
|
||||
question++;
|
||||
if (question == Quiz.length)
|
||||
question = 999;
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
Error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
Timer timer = new Timer(timeBetweenQuestions * 1000, phaze1);
|
||||
timer.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
void sayAll(String message, boolean Alert, boolean inQuiz) throws Exception {
|
||||
if (inQuiz) {
|
||||
ArrayList playersToSend = new ArrayList();
|
||||
Player p;
|
||||
for (Iterator i$ = world.getPlayers().iterator(); i$.hasNext(); playersToSend.add(p))
|
||||
p = (Player) i$.next();
|
||||
Player pl;
|
||||
for (Iterator i$ = playersToSend.iterator(); i$.hasNext();) {
|
||||
pl = (Player) i$.next();
|
||||
if (Alert && pl.inQuiz)
|
||||
pl.getActionSender().sendAlert(message, false);
|
||||
else if (!Alert && pl.inQuiz)
|
||||
pl.getActionSender().sendMessage(message);
|
||||
}
|
||||
} else {
|
||||
ArrayList playersToSend = new ArrayList();
|
||||
Player p;
|
||||
for (Iterator i$ = world.getPlayers().iterator(); i$.hasNext(); playersToSend.add(p))
|
||||
p = (Player) i$.next();
|
||||
Player pl;
|
||||
for (Iterator i$ = playersToSend.iterator(); i$.hasNext();) {
|
||||
pl = (Player) i$.next();
|
||||
if (Alert)
|
||||
pl.getActionSender().sendAlert(message, false);
|
||||
else
|
||||
pl.getActionSender().sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rofl.. couldent be fucked figuring out another way to do this at the
|
||||
// time.
|
||||
void tallyQuiz() {
|
||||
try {
|
||||
|
||||
String First = null;
|
||||
int first = -1;
|
||||
int second = -1;
|
||||
int third = -1;
|
||||
String Second = null;
|
||||
String Third = null;
|
||||
int temp = 0;
|
||||
int count = 0;
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (p.quizPoints != 0)
|
||||
count++;
|
||||
|
||||
if (p.quizPoints >= temp) {
|
||||
temp = p.quizPoints;
|
||||
First = p.getUsername();
|
||||
first = temp;
|
||||
}
|
||||
}
|
||||
temp = 0;
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (p.quizPoints >= temp && p.getUsername() != First) {
|
||||
temp = p.quizPoints;
|
||||
Second = p.getUsername();
|
||||
second = temp;
|
||||
}
|
||||
}
|
||||
temp = 0;
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (p.quizPoints >= temp && (p.getUsername() != First && p.getUsername() != Second)) {
|
||||
temp = p.quizPoints;
|
||||
Third = p.getUsername();
|
||||
third = temp;
|
||||
}
|
||||
}
|
||||
sayAll("Thank you all for Playing, the Quiz is over. " + count + " Players submitted Answers.", false, true);
|
||||
sayAll("@yel@Your Quiz Winners Are: @whi@" + First + "@gre@(" + first + ")@whi@, " + Second + "@gre@(" + second + ")@whi@, " + Third + "(@gre@" + third + ")", true, true);
|
||||
sayAll("@yel@Your Quiz Winners Are: @whi@" + First + "@gre@(" + first + ")@whi@, " + Second + "@gre@(" + second + ")@whi@, " + Third + "(@gre@" + third + ")", false, true);
|
||||
|
||||
/**
|
||||
*
|
||||
* Add SQL Here.
|
||||
*
|
||||
*/
|
||||
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (p.quizPoints != 0) {
|
||||
int points = p.quizPoints; // Each players total questions
|
||||
// correct from lsat round of
|
||||
// Quiz
|
||||
|
||||
// Code here for adding to SQL etc.
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -421,7 +421,7 @@ public class Thieving {
|
||||
player.setBusy(false);
|
||||
affectedNpc.setBusy(false);
|
||||
affectedNpc.unblock();
|
||||
System.out.println(e.getMessage() + "\nStack: " + e.getStackTrace());
|
||||
Logger.error(e.getMessage() + "\nStack: " + e.getStackTrace());
|
||||
player.setSpam(false);
|
||||
}
|
||||
|
||||
@ -459,7 +459,7 @@ public class Thieving {
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
System.out.println(e.getMessage());
|
||||
Logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -887,7 +887,7 @@ public class Thieving {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
Logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
34
GameServer/src/org/moparscape/msc/gs/util/Cache.java
Normal file
34
GameServer/src/org/moparscape/msc/gs/util/Cache.java
Normal file
@ -0,0 +1,34 @@
|
||||
package org.moparscape.msc.gs.util;
|
||||
|
||||
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> {
|
||||
|
||||
private final Map<K, V> cache;
|
||||
|
||||
public Cache() {
|
||||
this(100);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // Commons and their failure to support generics...
|
||||
public Cache(int maxSize) {
|
||||
cache = new LRUMap(maxSize);
|
||||
}
|
||||
|
||||
public V get(K key) {
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
public V put(K key, V value) {
|
||||
return cache.put(key, value);
|
||||
}
|
||||
|
||||
}
|
@ -20,11 +20,11 @@ public class DefCompressor {
|
||||
while ((read = fis.read(buf)) != -1) {
|
||||
out.write(buf, 0, read);
|
||||
}
|
||||
System.out.println("Done.");
|
||||
Logger.println("Done.");
|
||||
fis.close();
|
||||
out.close();
|
||||
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 {
|
||||
@ -38,11 +38,11 @@ public class DefCompressor {
|
||||
while ((read = in.read(buf)) != -1) {
|
||||
fos.write(buf, 0, read);
|
||||
}
|
||||
System.out.println("Done.");
|
||||
Logger.println("Done.");
|
||||
fos.close();
|
||||
in.close();
|
||||
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 {
|
||||
|
@ -3,69 +3,77 @@ package org.moparscape.msc.gs.util;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
|
||||
|
||||
public class Logger {
|
||||
/**
|
||||
* World instance
|
||||
*/
|
||||
private static final World world = Instance.getWorld();
|
||||
/**
|
||||
* World instance
|
||||
*/
|
||||
private static final World world = Instance.getWorld();
|
||||
|
||||
/**
|
||||
* Simple date formatter to keep a date on outputs
|
||||
*/
|
||||
private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
|
||||
|
||||
public static void connection(Object o) {
|
||||
// System.out.println(o.toString());
|
||||
}
|
||||
/**
|
||||
* Simple date formatter to keep a date on outputs
|
||||
*/
|
||||
private static SimpleDateFormat formatter = new SimpleDateFormat(
|
||||
Config.DATE_FORMAT);
|
||||
|
||||
public static void error(Object o) {
|
||||
if (o instanceof Exception) {
|
||||
Exception e = (Exception) o;
|
||||
e.printStackTrace();
|
||||
if (world == null || !Instance.getServer().isInitialized()) {
|
||||
System.exit(1);
|
||||
} else {
|
||||
Instance.getServer().kill();
|
||||
}
|
||||
return;
|
||||
public static void connection(Object o) {
|
||||
// Logging.debug(o.toString());
|
||||
}
|
||||
if (o.toString() != null)
|
||||
Instance.getServer().getLoginConnector().getActionSender().logAction(o.toString(), 2);
|
||||
}
|
||||
|
||||
public static void event(Object o) {
|
||||
Instance.getServer().getLoginConnector().getActionSender().logAction(o.toString(), 1);
|
||||
}
|
||||
public static void error(Object o) {
|
||||
if (o instanceof Exception) {
|
||||
Exception e = (Exception) o;
|
||||
e.printStackTrace();
|
||||
if (world == null || !Instance.getServer().isInitialized()) {
|
||||
System.exit(1);
|
||||
} else {
|
||||
Instance.getServer().kill();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void mod(Object o) {
|
||||
Instance.getServer().getLoginConnector().getActionSender().logAction(o.toString(), 3);
|
||||
if (!o.toString().contains("stuck"))
|
||||
Instance.getIRC().notifyAdmin("MOD", o.toString());
|
||||
}
|
||||
/**
|
||||
* Sends s to loginserver and prints to stdout
|
||||
* @param s
|
||||
*/
|
||||
public static void systemerr(String s) {
|
||||
Instance.getServer().getLoginConnector().getActionSender().logAction(s, 4);
|
||||
print(s);
|
||||
}
|
||||
/**
|
||||
* Prints to console with timestamp
|
||||
* @param o Object to print
|
||||
*/
|
||||
public static void print(Object o) {
|
||||
System.out.print(formatter.format(new Date()) + " " + o.toString());
|
||||
}
|
||||
/**
|
||||
* Prints to console with timestamp and newline
|
||||
* @param o Object to print
|
||||
*/
|
||||
public static void println(Object o) {
|
||||
System.out.println(formatter.format(new Date()) + " " + o.toString());
|
||||
}
|
||||
public static void event(Object o) {
|
||||
Instance.getServer().getLoginConnector().getActionSender()
|
||||
.logAction(o.toString(), 1);
|
||||
}
|
||||
|
||||
public static void mod(Object o) {
|
||||
Instance.getServer().getLoginConnector().getActionSender()
|
||||
.logAction(o.toString(), 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends s to loginserver and prints to stdout
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
public static void systemerr(String s) {
|
||||
Instance.getServer().getLoginConnector().getActionSender()
|
||||
.logAction(s, 4);
|
||||
print(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints to console with timestamp
|
||||
*
|
||||
* @param o
|
||||
* Object to print
|
||||
*/
|
||||
public static void print(Object o) {
|
||||
System.out.print(formatter.format(new Date()) + " " + o.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints to console with timestamp and newline
|
||||
*
|
||||
* @param o
|
||||
* Object to print
|
||||
*/
|
||||
public static void println(Object o) {
|
||||
System.out.println(formatter.format(new Date()) + " " + o.toString());
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class MapGenerator {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length < 1) {
|
||||
System.out.println("Invalid args");
|
||||
Logger.println("Invalid args");
|
||||
return;
|
||||
}
|
||||
String configFile = "conf/server/Conf.xml";
|
||||
|
@ -1,116 +0,0 @@
|
||||
package org.moparscape.msc.irc;
|
||||
|
||||
import static org.moparscape.msc.irc.IRC.IRCTools.bold;
|
||||
import static org.moparscape.msc.irc.IRC.IRCTools.getColor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.phandler.PlayerLogin;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
|
||||
|
||||
/**
|
||||
* Self explanatory, handles incoming commands.
|
||||
*
|
||||
* @author xEnt
|
||||
*
|
||||
*/
|
||||
public class CommandHandler {
|
||||
|
||||
/**
|
||||
* Handles an incoming piece of text.
|
||||
*
|
||||
* @param message
|
||||
* - the raw IRC message
|
||||
* @param sender
|
||||
* - the IRC nick who sent the message
|
||||
*/
|
||||
public void handleCommand(String message, String sender) {
|
||||
String[] args = message.split(" ");
|
||||
String cmd = args[0];
|
||||
message = message.replace(args[0], "").trim();
|
||||
command = cmd;
|
||||
|
||||
if (Command("say")) {
|
||||
Instance.getWorld().sendBroadcastMessage(sender + " (IRC)", message);
|
||||
} else if (Command("online")) {
|
||||
irc.sendMessage("Players Online: " + Constants.GameServer.ONLINE_COUNT);
|
||||
} else if (Command("add")) {
|
||||
try {
|
||||
if (validateInteger(message.trim())) {
|
||||
Runtime.getRuntime().exec("sudo route add " + message.trim());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
irc.sendMessage(e.getMessage());
|
||||
}
|
||||
} else if (Command("unblock")) {
|
||||
try {
|
||||
if (validateInteger(message.trim())) {
|
||||
Runtime.getRuntime().exec("sudo route delete " + message.trim());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
irc.sendMessage(e.getMessage());
|
||||
}
|
||||
} else if (Command("ssh")) {
|
||||
if (sender.equalsIgnoreCase("xEnt") || sender.equalsIgnoreCase("Pets") || sender.equalsIgnoreCase("KO9")) {
|
||||
try {
|
||||
if (validateInteger(message.trim())) {
|
||||
Runtime.getRuntime().exec("sudo iptables -I INPUT -s " + message.trim() + " -p tcp --dport 22 -j ACCEPT");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
irc.sendMessage(e.getMessage());
|
||||
}
|
||||
}
|
||||
} else if (Command("loggedin")) {
|
||||
for (Player p : Instance.getWorld().getPlayers()) {
|
||||
if (p.getUsername().equalsIgnoreCase(message)) {
|
||||
irc.sendMessage("Player (" + message + ") " + bold() + getColor("green") + " ONLINE");
|
||||
return;
|
||||
}
|
||||
}
|
||||
irc.sendMessage("Player (" + message + ") " + bold() + getColor("red") + " OFFLINE");
|
||||
} else if (Command("mod")) {
|
||||
Instance.getWorld().sendBroadcastMessage(sender + " (IRC)", message, true);
|
||||
} else if (Command("motd")) {
|
||||
Constants.GameServer.MOTD = message;
|
||||
} else if (Command("info2")) {
|
||||
Player p = Instance.getWorld().getPlayer(DataConversions.usernameToHash(args[0]));
|
||||
if (p == null) {
|
||||
irc.sendMessage(message + " is offline?");
|
||||
return;
|
||||
}
|
||||
p.lastPlayerInfo2 = "(IRC)";
|
||||
p.getActionSender().sendInfo2();
|
||||
irc.sendMessage("Requesting info.. please wait");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateInteger(String s) {
|
||||
try {
|
||||
s = s.replaceAll(".", "");
|
||||
int k = Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
} finally {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public CommandHandler(IRC irc) {
|
||||
this.irc = irc;
|
||||
}
|
||||
|
||||
public boolean Command(String cmd) {
|
||||
if (cmd.equalsIgnoreCase(command))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
IRC irc = null;
|
||||
String command = null;
|
||||
|
||||
}
|
@ -1,194 +0,0 @@
|
||||
package org.moparscape.msc.irc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jibble.pircbot.IrcException;
|
||||
import org.jibble.pircbot.NickAlreadyInUseException;
|
||||
import org.jibble.pircbot.PircBot;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* GameServer <> IRC Integration. Using PircBot v1.46 IRC Framework.
|
||||
*
|
||||
* @author xEnt
|
||||
*
|
||||
*/
|
||||
public class IRC extends PircBot implements Runnable {
|
||||
|
||||
/**
|
||||
* Thread entry point, also IRC initialization process.
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
|
||||
Thread.currentThread().setName("IRC");
|
||||
handler = new CommandHandler(this);
|
||||
|
||||
try {
|
||||
// setVerbose(true);
|
||||
setName(Constants.IRC.NICK);
|
||||
setLogin(Constants.IRC.USER);
|
||||
for (String server : Constants.IRC.HOSTS)
|
||||
connect(server);
|
||||
|
||||
for (int i = 0; i < Constants.IRC.CHANNELS.length; i++) {
|
||||
if (Constants.IRC.CHANNELS[i][1] != null) { // has password
|
||||
joinChannel(Constants.IRC.CHANNELS[i][0], Constants.IRC.CHANNELS[i][1]);
|
||||
continue;
|
||||
}
|
||||
joinChannel(Constants.IRC.CHANNELS[i][0]);
|
||||
}
|
||||
|
||||
} catch (NickAlreadyInUseException e) {
|
||||
changeNick(Constants.IRC.NICK + "A");
|
||||
} catch (IOException e) {
|
||||
Logger.error(e);
|
||||
} catch (IrcException e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
Logger.print("IRC Connected. [" + Constants.IRC.NICK + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When someone uses Report Abuse ingame, this relays it to IRC.
|
||||
*
|
||||
* @param sender
|
||||
* - the person complaining
|
||||
* @param target
|
||||
* - the bad person
|
||||
* @param id
|
||||
* - the report ID
|
||||
*/
|
||||
public void handleReport(String sender, String target, int id) {
|
||||
sendMessage(IRCTools.bold() + IRCTools.getColor("red") + sender + IRCTools.bold() + IRCTools.getColor("lightgreen") + " has reported " + IRCTools.bold() + IRCTools.getColor("red") + target + IRCTools.bold() + IRCTools.getColor("lightgreen") + " for " + IRCTools.bold() + IRCTools.getColor("blue") + IRCTools.getReportName(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get sent to each "Administrator" that accepts PMs for Moderator
|
||||
* logs.
|
||||
*
|
||||
* @param user
|
||||
* - (Optional) the user getting logged
|
||||
* @param message
|
||||
* - the message
|
||||
*/
|
||||
public void notifyAdmin(String user, String message) {
|
||||
if (Constants.IRC.USE_IRC) {
|
||||
message = Filter.translate(message);
|
||||
for (String admin : Constants.IRC.ADMINISTRATORS) {
|
||||
sendMessage(admin, IRCTools.bold() + IRCTools.getColor("blue") + user + IRCTools.bold() + IRCTools.getColor("lightgreen") + " " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired off upon a message recieved by our IRC Channel
|
||||
*/
|
||||
@Override
|
||||
public void onMessage(String channel, String sender, String login, String hostname, String message) {
|
||||
for (int i = 0; i < Constants.IRC.CHANNELS.length; i++) {
|
||||
if (Constants.IRC.CHANNELS[i][0].equalsIgnoreCase(channel)) {
|
||||
if (message.startsWith("!")) {
|
||||
handler.handleCommand(message.substring(1), sender);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Let's send a message to all IRC channels, and check for filtered words.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public void sendMessage(String message) {
|
||||
if (Constants.IRC.USE_IRC) {
|
||||
message = Filter.translate(message);
|
||||
for (int i = 0; i < Constants.IRC.CHANNELS.length; i++) {
|
||||
sendMessage(Constants.IRC.CHANNELS[i][0], message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance to our IRC command handler.
|
||||
*/
|
||||
private CommandHandler handler;
|
||||
|
||||
public CommandHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void setHandler(CommandHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Misc IRC dependencies
|
||||
*/
|
||||
public static class IRCTools {
|
||||
|
||||
/**
|
||||
* Starts/stops bold in a IRC string.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String bold() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the correct IRC color-code.
|
||||
*/
|
||||
public static String getColor(String s) {
|
||||
|
||||
String[] colorCode = { "2", "8", "9", "10", "6", "1", "3", "7" };
|
||||
String[] colors = { "red", "yellow", "lightgreen", "blue", "purple", "white", "darkgreen", "orange" };
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
if (colors[i].equalsIgnoreCase(s))
|
||||
return "" + colorCode[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID > String of the Report detail list.
|
||||
*
|
||||
* @param id
|
||||
* - the report id
|
||||
* @return the report name (String)
|
||||
*/
|
||||
public static String getReportName(int id) {
|
||||
id--;
|
||||
String[] reports = { "Offensive Language", "Item Scamming", "Password Scamming", "Bug Abuse", "Staff Impersonation", "Account sharing/trading", "Autoing/Macroing", "Multiple logging in", "Encouraging others to break rules", "Misuse of customer support", "Advertising / Website", "Real world item trading" };
|
||||
if (id < 0 || id > reports.length)
|
||||
return "ERROR?";
|
||||
return reports[id];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters anything relaying to IRC
|
||||
*/
|
||||
public static class Filter {
|
||||
/**
|
||||
* Let's swap the filtered words with their given masks.
|
||||
*
|
||||
* @param old
|
||||
* - the old String.
|
||||
* @return - the newly filtered string.
|
||||
*/
|
||||
public static String translate(String old) {
|
||||
String newStr = old;
|
||||
for (int i = 0; i < Constants.IRC.BANNED_WORDS.length; i++) {
|
||||
if (newStr.contains(Constants.IRC.BANNED_WORDS[i][0])) {
|
||||
newStr = newStr.replace(Constants.IRC.BANNED_WORDS[i][0], Constants.IRC.BANNED_WORDS[i][1]);
|
||||
}
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,4 +15,26 @@
|
||||
<entry key="mysqlpass"></entry>
|
||||
<entry key="mysqlhost">localhost</entry>
|
||||
<entry key="mysqldb">moparclassic</entry>
|
||||
|
||||
<entry key="members">false</entry>
|
||||
<entry key="f2pwildy">true</entry>
|
||||
<entry key="expRate">4.0</entry>
|
||||
<entry key="subExpRate">4.0</entry>
|
||||
|
||||
<!-- Separate names by commas -->
|
||||
<entry key="pmods">None</entry>
|
||||
<entry key="mods">None</entry>
|
||||
<entry key="admins">None</entry>
|
||||
|
||||
<entry key="ip-ban-removal-delay">1800000</entry>
|
||||
<entry key="block-command">sudo route add -host ${ip} reject</entry>
|
||||
<entry key="unblock-command">sudo route del -host ${ip} reject</entry>
|
||||
|
||||
<!-- Every 100 minutes -->
|
||||
<entry key="garbage-collect-interval">6000000</entry>
|
||||
<!-- Every 5 minutes -->
|
||||
<entry key="save-interval">300000</entry>
|
||||
|
||||
<!-- Date format for logger -->
|
||||
<entry key="date-format">yyyy.MM.dd HH:mm:ss</entry>
|
||||
</properties>
|
||||
|
@ -0,0 +1,84 @@
|
||||
10:27:56 22-06-11: java.io.IOException: Connection reset by peer
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: java.io.IOException: Connection reset by peer
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.FileDispatcher.read0(Native Method)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:251)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: java.io.IOException: Connection reset by peer
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.FileDispatcher.read0(Native Method)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:251)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.IOUtil.read(IOUtil.java:218)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:254)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:218)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:198)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$400(SocketIoProcessor.java:45)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: java.io.IOException: Connection reset by peer
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.FileDispatcher.read0(Native Method)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:251)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.IOUtil.read(IOUtil.java:218)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:254)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:218)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:198)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$400(SocketIoProcessor.java:45)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:485)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
|
||||
10:27:56 22-06-11:
|
||||
|
||||
10:27:56 22-06-11: at java.lang.Thread.run(Thread.java:636)
|
||||
10:27:56 22-06-11:
|
||||
|
@ -10,4 +10,5 @@
|
||||
<entry key="lsport">34526</entry>
|
||||
<entry key="queryip">localhost</entry>
|
||||
<entry key="queryport">8186</entry>
|
||||
<entry key="authURL">http://localhost/auth.php</entry>
|
||||
</properties>
|
||||
|
Binary file not shown.
@ -11,142 +11,144 @@ import org.moparscape.msc.ls.packethandler.PacketHandler;
|
||||
import org.moparscape.msc.ls.packethandler.PacketHandlerDef;
|
||||
import org.moparscape.msc.ls.util.PersistenceManager;
|
||||
|
||||
|
||||
public class LoginEngine extends Thread {
|
||||
/**
|
||||
* The mapping of packet IDs to their handler
|
||||
*/
|
||||
private TreeMap<Integer, PacketHandler> FPacketHandlers = new TreeMap<Integer, PacketHandler>();
|
||||
/**
|
||||
* The packet queue to be processed
|
||||
*/
|
||||
private PacketQueue<FPacket> FPacketQueue;
|
||||
/**
|
||||
* The mapping of packet IDs to their handler
|
||||
*/
|
||||
private TreeMap<Integer, PacketHandler> LSPacketHandlers = new TreeMap<Integer, PacketHandler>();
|
||||
/**
|
||||
* The packet queue to be processed
|
||||
*/
|
||||
private PacketQueue<LSPacket> LSPacketQueue;
|
||||
/**
|
||||
* Should we be running?
|
||||
*/
|
||||
private boolean running = true;
|
||||
/**
|
||||
* The main server
|
||||
*/
|
||||
private Server server;
|
||||
/**
|
||||
* The mapping of packet UIDs to their handler
|
||||
*/
|
||||
private TreeMap<Long, PacketHandler> uniqueHandlers = new TreeMap<Long, PacketHandler>();
|
||||
/**
|
||||
* The mapping of packet IDs to their handler
|
||||
*/
|
||||
private TreeMap<Integer, PacketHandler> FPacketHandlers = new TreeMap<Integer, PacketHandler>();
|
||||
/**
|
||||
* The packet queue to be processed
|
||||
*/
|
||||
private PacketQueue<FPacket> FPacketQueue;
|
||||
/**
|
||||
* The mapping of packet IDs to their handler
|
||||
*/
|
||||
private TreeMap<Integer, PacketHandler> LSPacketHandlers = new TreeMap<Integer, PacketHandler>();
|
||||
/**
|
||||
* The packet queue to be processed
|
||||
*/
|
||||
private PacketQueue<LSPacket> LSPacketQueue;
|
||||
/**
|
||||
* Should we be running?
|
||||
*/
|
||||
private boolean running = true;
|
||||
/**
|
||||
* The main server
|
||||
*/
|
||||
private Server server;
|
||||
/**
|
||||
* The mapping of packet UIDs to their handler
|
||||
*/
|
||||
private TreeMap<Long, PacketHandler> uniqueHandlers = new TreeMap<Long, PacketHandler>();
|
||||
|
||||
public LoginEngine(Server server) {
|
||||
this.server = server;
|
||||
LSPacketQueue = new PacketQueue<LSPacket>();
|
||||
FPacketQueue = new PacketQueue<FPacket>();
|
||||
loadPacketHandlers();
|
||||
}
|
||||
public LoginEngine(Server server) {
|
||||
this.server = server;
|
||||
LSPacketQueue = new PacketQueue<LSPacket>();
|
||||
FPacketQueue = new PacketQueue<FPacket>();
|
||||
loadPacketHandlers();
|
||||
}
|
||||
|
||||
public PacketQueue<FPacket> getFPacketQueue() {
|
||||
return FPacketQueue;
|
||||
}
|
||||
public PacketQueue<FPacket> getFPacketQueue() {
|
||||
return FPacketQueue;
|
||||
}
|
||||
|
||||
public PacketQueue<LSPacket> getLSPacketQueue() {
|
||||
return LSPacketQueue;
|
||||
}
|
||||
public PacketQueue<LSPacket> getLSPacketQueue() {
|
||||
return LSPacketQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the packet handling classes from the persistence manager.
|
||||
*/
|
||||
protected void loadPacketHandlers() {
|
||||
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager.load("LSPacketHandlers.xml");
|
||||
for (PacketHandlerDef handlerDef : handlerDefs) {
|
||||
try {
|
||||
String className = handlerDef.getClassName();
|
||||
Class c = Class.forName(className);
|
||||
if (c != null) {
|
||||
PacketHandler handler = (PacketHandler) c.newInstance();
|
||||
for (int packetID : handlerDef.getAssociatedPackets()) {
|
||||
LSPacketHandlers.put(packetID, handler);
|
||||
}
|
||||
/**
|
||||
* Loads the packet handling classes from the persistence manager.
|
||||
*/
|
||||
protected void loadPacketHandlers() {
|
||||
PacketHandlerDef[] handlerDefs = (PacketHandlerDef[]) PersistenceManager
|
||||
.load("LSPacketHandlers.xml");
|
||||
for (PacketHandlerDef handlerDef : handlerDefs) {
|
||||
try {
|
||||
String className = handlerDef.getClassName();
|
||||
Class c = Class.forName(className);
|
||||
if (c != null) {
|
||||
PacketHandler handler = (PacketHandler) c.newInstance();
|
||||
for (int packetID : handlerDef.getAssociatedPackets()) {
|
||||
LSPacketHandlers.put(packetID, handler);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Server.error(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Server.error(e);
|
||||
}
|
||||
}
|
||||
handlerDefs = (PacketHandlerDef[]) PersistenceManager.load("FPacketHandlers.xml");
|
||||
for (PacketHandlerDef handlerDef : handlerDefs) {
|
||||
try {
|
||||
String className = handlerDef.getClassName();
|
||||
Class c = Class.forName(className);
|
||||
if (c != null) {
|
||||
PacketHandler handler = (PacketHandler) c.newInstance();
|
||||
for (int packetID : handlerDef.getAssociatedPackets()) {
|
||||
FPacketHandlers.put(packetID, handler);
|
||||
}
|
||||
handlerDefs = (PacketHandlerDef[]) PersistenceManager
|
||||
.load("FPacketHandlers.xml");
|
||||
for (PacketHandlerDef handlerDef : handlerDefs) {
|
||||
try {
|
||||
String className = handlerDef.getClassName();
|
||||
Class c = Class.forName(className);
|
||||
if (c != null) {
|
||||
PacketHandler handler = (PacketHandler) c.newInstance();
|
||||
for (int packetID : handlerDef.getAssociatedPackets()) {
|
||||
FPacketHandlers.put(packetID, handler);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Server.error(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Server.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes incoming packets.
|
||||
*/
|
||||
private void processIncomingPackets() {
|
||||
for (LSPacket p : LSPacketQueue.getPackets()) {
|
||||
PacketHandler handler;
|
||||
if (((handler = uniqueHandlers.get(p.getUID())) != null) || ((handler = LSPacketHandlers.get(p.getID())) != null)) {
|
||||
try {
|
||||
handler.handlePacket(p, p.getSession());
|
||||
uniqueHandlers.remove(p.getUID());
|
||||
} catch (Exception e) {
|
||||
Server.error("Exception with p[" + p.getID() + "]: " + e);
|
||||
/**
|
||||
* Processes incoming packets.
|
||||
*/
|
||||
private void processIncomingPackets() {
|
||||
for (LSPacket p : LSPacketQueue.getPackets()) {
|
||||
PacketHandler handler;
|
||||
if (((handler = uniqueHandlers.get(p.getUID())) != null)
|
||||
|| ((handler = LSPacketHandlers.get(p.getID())) != null)) {
|
||||
try {
|
||||
handler.handlePacket(p, p.getSession());
|
||||
uniqueHandlers.remove(p.getUID());
|
||||
} catch (Exception e) {
|
||||
Server.error("Exception with p[" + p.getID() + "]: " + e);
|
||||
}
|
||||
} else {
|
||||
Server.error("Unhandled packet from server: " + p.getID());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Server.error("Unhandled packet from server: " + p.getID());
|
||||
}
|
||||
}
|
||||
for (FPacket p : FPacketQueue.getPackets()) {
|
||||
PacketHandler handler = FPacketHandlers.get(p.getID());
|
||||
if (handler != null) {
|
||||
try {
|
||||
handler.handlePacket(p, p.getSession());
|
||||
} catch (Exception e) {
|
||||
Server.error("Exception with p[" + p.getID() + "]: " + e);
|
||||
for (FPacket p : FPacketQueue.getPackets()) {
|
||||
PacketHandler handler = FPacketHandlers.get(p.getID());
|
||||
if (handler != null) {
|
||||
try {
|
||||
handler.handlePacket(p, p.getSession());
|
||||
} catch (Exception e) {
|
||||
Server.error("Exception with p[" + p.getID() + "]: " + e);
|
||||
}
|
||||
} else {
|
||||
Server.error("Unhandled packet from frontend: " + p.getID());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Server.error("Unhandled packet from frontend: " + p.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void processOutgoingPackets() {
|
||||
for (World w : server.getWorlds()) {
|
||||
List<LSPacket> packets = w.getActionSender().getPackets();
|
||||
for (LSPacket packet : packets) {
|
||||
w.getSession().write(packet);
|
||||
}
|
||||
w.getActionSender().clearPackets();
|
||||
public void processOutgoingPackets() {
|
||||
for (World w : server.getWorlds()) {
|
||||
List<LSPacket> packets = w.getActionSender().getPackets();
|
||||
for (LSPacket packet : packets) {
|
||||
w.getSession().write(packet);
|
||||
}
|
||||
w.getActionSender().clearPackets();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.out.println("LoginEngine now running");
|
||||
while (running) {
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
processIncomingPackets();
|
||||
processOutgoingPackets();
|
||||
public void run() {
|
||||
System.out.println("LoginEngine now running");
|
||||
while (running) {
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
processIncomingPackets();
|
||||
processOutgoingPackets();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setHandler(long uID, PacketHandler handler) {
|
||||
uniqueHandlers.put(uID, handler);
|
||||
}
|
||||
public void setHandler(long uID, PacketHandler handler) {
|
||||
uniqueHandlers.put(uID, handler);
|
||||
}
|
||||
}
|
@ -104,13 +104,13 @@ public class Server {
|
||||
// if(s != null) {
|
||||
// w.unassosiateSave(s);
|
||||
// save = s;
|
||||
// System.out.println("Found cached save for " +
|
||||
// Logging.debug("Found cached save for " +
|
||||
// DataConversions.hashToUsername(user));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if(save == null) {
|
||||
// System.out.println("No save found for " +
|
||||
// Logging.debug("No save found for " +
|
||||
// DataConversions.hashToUsername(user) + ", loading fresh");
|
||||
save = PlayerSave.loadPlayer(user);
|
||||
// }
|
||||
|
62
LoginServer/src/org/moparscape/msc/ls/auth/Auth.java
Normal file
62
LoginServer/src/org/moparscape/msc/ls/auth/Auth.java
Normal file
@ -0,0 +1,62 @@
|
||||
package org.moparscape.msc.ls.auth;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.moparscape.msc.ls.util.Config;
|
||||
|
||||
public class Auth {
|
||||
|
||||
public static double version = 1.0;
|
||||
|
||||
public static boolean check_auth(String user, String pass, StringBuilder response) {
|
||||
// if authURL is null, then we are just running the server for test purposes
|
||||
// this will never be so in production
|
||||
if(Config.AUTH_URL == null){
|
||||
response.append("TestUser");
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
user = URLEncoder.encode(user, "UTF-8");
|
||||
pass = URLEncoder.encode(pass, "UTF-8");
|
||||
|
||||
HttpURLConnection.setFollowRedirects(false);
|
||||
HttpURLConnection uc = (HttpURLConnection) new URL(Config.AUTH_URL).openConnection();
|
||||
|
||||
uc.setRequestMethod("POST");
|
||||
uc.setDoInput(true);
|
||||
uc.setDoOutput(true);
|
||||
uc.setUseCaches(false);
|
||||
uc.setAllowUserInteraction(false);
|
||||
uc.setInstanceFollowRedirects(false);
|
||||
uc.setRequestProperty("User-Agent", "Mozilla/5.0 MoparClassic/" + version);
|
||||
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
DataOutputStream out = new DataOutputStream(uc.getOutputStream());
|
||||
out.writeBytes("user=" + user + "&pass=" + pass);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
|
||||
String line = in.readLine();
|
||||
boolean success = line != null && line.equals("YES");
|
||||
response.append(in.readLine());
|
||||
in.close();
|
||||
return success;
|
||||
} catch (Exception e) {
|
||||
response.append(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
Config.AUTH_URL = "https://www.moparscape.org/auth.php?field=";
|
||||
String user = "CodeForFame";
|
||||
String pass = "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
System.out.println("success: "+check_auth(user, pass, sb));
|
||||
System.out.println("message: "+sb.toString());
|
||||
}
|
||||
}
|
@ -83,7 +83,7 @@ public class FConnectionHandler implements IoHandler {
|
||||
*/
|
||||
public void sessionCreated(IoSession session) {
|
||||
session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new FCodecFactory()));
|
||||
// System.out.println("Connection from: " +
|
||||
// Logging.debug("Connection from: " +
|
||||
// ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress());
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class LSConnectionHandler implements IoHandler {
|
||||
*/
|
||||
public void sessionCreated(IoSession session) {
|
||||
session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new LSCodecFactory()));
|
||||
// System.out.println("Connection from: " +
|
||||
// Logging.debug("Connection from: " +
|
||||
// ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress());
|
||||
}
|
||||
|
||||
|
@ -1,55 +0,0 @@
|
||||
package org.rscdaemon.ls.packethandler.loginserver;
|
||||
|
||||
import org.rscdaemon.ls.packethandler.PacketHandler;
|
||||
import org.rscdaemon.ls.Server;
|
||||
import org.rscdaemon.ls.model.World;
|
||||
import org.rscdaemon.ls.net.LSPacket;
|
||||
import org.rscdaemon.ls.net.Packet;
|
||||
import org.rscdaemon.ls.util.DataConversions;
|
||||
import org.rscdaemon.ls.packetbuilder.loginserver.ReplyPacketBuilder;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class BanHandler implements PacketHandler {
|
||||
private ReplyPacketBuilder builder = new ReplyPacketBuilder();
|
||||
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
final long uID = ((LSPacket)p).getUID();
|
||||
boolean banned = ((LSPacket)p).getID() == 4;
|
||||
long user = p.readLong();
|
||||
long modhash = p.readLong();
|
||||
|
||||
ResultSet result = Server.db.getQuery("SELECT u.group_id, p.playermod, p.owner FROM `users` AS u INNER JOIN `rscd_players` AS p ON p.owner=u.id WHERE p.user=" + user);
|
||||
if(!result.next()) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("There is not an account by that username");
|
||||
}
|
||||
else if(banned && (result.getInt("group_id") < 3 || result.getInt("playermod") == 1)) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("You cannot ban a (p)mod or admin!");
|
||||
}
|
||||
else if(Server.db.updateQuery("UPDATE `rscd_players` SET `banned`='" + (banned ? "1" : "0") + "' WHERE `user` LIKE '" + user + "'") == 0) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("There is not an account by that username");
|
||||
}
|
||||
else {
|
||||
World w = Server.getServer().findWorld(user);
|
||||
if(w != null) {
|
||||
w.getActionSender().logoutUser(user);
|
||||
}
|
||||
if(banned) Server.db.updateQuery("INSERT `rscd_banlog` VALUES('" + user + "','" + modhash + "','" + (System.currentTimeMillis() / 1000) + "')");
|
||||
builder.setSuccess(true);
|
||||
builder.setReply(DataConversions.hashToUsername(user) + " has been " + (banned ? "banned" : "unbanned"));
|
||||
}
|
||||
builder.setUID(uID);
|
||||
|
||||
LSPacket temp = builder.getPacket();
|
||||
if(temp != null) {
|
||||
session.write(temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package org.rscdaemon.ls.packethandler.loginserver;
|
||||
|
||||
import org.rscdaemon.ls.packethandler.PacketHandler;
|
||||
import org.rscdaemon.ls.Server;
|
||||
import org.rscdaemon.ls.model.World;
|
||||
import org.rscdaemon.ls.net.LSPacket;
|
||||
import org.rscdaemon.ls.net.Packet;
|
||||
import org.rscdaemon.ls.util.DataConversions;
|
||||
import org.rscdaemon.ls.packetbuilder.loginserver.ReplyPacketBuilder;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class BanHandler implements PacketHandler {
|
||||
private ReplyPacketBuilder builder = new ReplyPacketBuilder();
|
||||
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
final long uID = ((LSPacket)p).getUID();
|
||||
boolean banned = ((LSPacket)p).getID() == 4;
|
||||
long user = p.readLong();
|
||||
long modhash = p.readLong();
|
||||
|
||||
ResultSet result = Server.db.getQuery("SELECT u.group_id, p.playermod, p.owner FROM `users` AS u INNER JOIN `rscd_players` AS p ON p.owner=u.id WHERE p.user=" + user);
|
||||
if(!result.next()) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("There is not an account by that username");
|
||||
}
|
||||
else if(banned && (result.getInt("group_id") < 3 || result.getInt("playermod") == 1)) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("You cannot ban a (p)mod or admin!");
|
||||
}
|
||||
else if(Server.db.updateQuery("UPDATE `rscd_players` SET `banned`='" + (banned ? "1" : "0") + "' WHERE `user` LIKE '" + user + "'") == 0) {
|
||||
builder.setSuccess(false);
|
||||
builder.setReply("There is not an account by that username");
|
||||
}
|
||||
else {
|
||||
World w = Server.getServer().findWorld(user);
|
||||
if(w != null) {
|
||||
w.getActionSender().logoutUser(user);
|
||||
}
|
||||
if(banned) {
|
||||
String owner = result.getString("owner");
|
||||
Server.db.updateQuery("INSERT `rscd_banlog` VALUES('" + user + "','" + modhash + "','" + (System.currentTimeMillis() / 1000) + "')");
|
||||
ResultSet result2 = Server.db.getQuery("SELECT username FROM `users` WHERE id=" + owner);
|
||||
|
||||
String username = result2.getString("username");
|
||||
Server.db.updateQuery("INSERT `topics` (poster, subject, posted, last_post, last_poster, forum_id) VALUES('" + username + "','[" + DataConversions.hashToUsername(user) + "] Banned by [" + DataConversions.hashToUsername(modhash) + "]','" + (System.currentTimeMillis() / 1000) + "','" + (System.currentTimeMillis() / 1000) + "','" + username + "','19')");
|
||||
ResultSet result3 = Server.db.getQuery("SELECT LAST_INSERT_ID()");
|
||||
String tid = result3.getString(1);
|
||||
Server.db.updateQuery("INSERT `posts` (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES('" + username + "','0.0.0.0','null@null.org', This thread will close in 24h, post in here if you are the account owner.','1','" + (System.currentTimeMillis() / 1000) + "','" + tid + "')");
|
||||
ResultSet result4 = Server.db.getQuery("SELECT LAST_INSERT_ID()");
|
||||
String pid = result4.getString(1);
|
||||
Server.db.updateQuery("UPDATE `posts` SET last_post_id=`" + pid + "` WHERE id=`" + tid + "`");
|
||||
}
|
||||
builder.setSuccess(true);
|
||||
builder.setReply(DataConversions.hashToUsername(user) + " has been " + (banned ? "banned" : "unbanned"));
|
||||
}
|
||||
builder.setUID(uID);
|
||||
|
||||
LSPacket temp = builder.getPacket();
|
||||
if(temp != null) {
|
||||
session.write(temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.moparscape.msc.ls.Server;
|
||||
import org.moparscape.msc.ls.auth.Auth;
|
||||
import org.moparscape.msc.ls.model.World;
|
||||
import org.moparscape.msc.ls.net.LSPacket;
|
||||
import org.moparscape.msc.ls.net.Packet;
|
||||
@ -71,7 +72,7 @@ public class PlayerLoginHandler implements PacketHandler {
|
||||
if (!result.next()) {
|
||||
return 2;
|
||||
}
|
||||
if (!pass.equalsIgnoreCase(result.getString("pass"))) {
|
||||
if (!Auth.check_auth(DataConversions.hashToUsername(user), pass, new StringBuilder())) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -1,89 +0,0 @@
|
||||
package org.rscdaemon.ls.packethandler.loginserver;
|
||||
|
||||
import org.rscdaemon.ls.packethandler.PacketHandler;
|
||||
import org.rscdaemon.ls.Server;
|
||||
import org.rscdaemon.ls.model.World;
|
||||
import org.rscdaemon.ls.net.LSPacket;
|
||||
import org.rscdaemon.ls.net.Packet;
|
||||
import org.rscdaemon.ls.util.DataConversions;
|
||||
import org.rscdaemon.ls.packetbuilder.loginserver.PlayerLoginPacketBuilder;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class PlayerLoginHandler implements PacketHandler {
|
||||
private PlayerLoginPacketBuilder builder = new PlayerLoginPacketBuilder();
|
||||
|
||||
public void handlePacket(Packet p, IoSession session) throws Exception {
|
||||
final long uID = ((LSPacket)p).getUID();
|
||||
World world = (World)session.getAttachment();
|
||||
long user = p.readLong();
|
||||
String ip = DataConversions.IPToString(p.readLong());
|
||||
String pass = p.readString(32).trim();
|
||||
String className = p.readString();
|
||||
byte loginCode = validatePlayer(user, pass, ip);
|
||||
|
||||
builder.setUID(uID);
|
||||
if(loginCode == 0 || loginCode == 1 || loginCode == 99) {
|
||||
// if(!className.equals("ORG.RSCDAEMON.CLIENT.MUDCLIENT")) {
|
||||
// System.out.println(DataConversions.hashToUsername(user) + " was caught by a trap");
|
||||
// try { Server.db.updateQuery("INSERT INTO `rscd_traps`(`user`, `time`, `ip`, `details`) VALUES('" + user + "', '" + (int)(System.currentTimeMillis() / 1000) + "', '" + ip + "', 'Unknown main class: \"" + className +"\"')"); } catch(Exception e) { }
|
||||
// }
|
||||
builder.setPlayer(Server.getServer().findSave(user, world), loginCode);
|
||||
world.registerPlayer(user, ip);
|
||||
}
|
||||
else {
|
||||
builder.setPlayer(null, loginCode);
|
||||
}
|
||||
|
||||
LSPacket packet = builder.getPacket();
|
||||
if(packet != null) {
|
||||
session.write(packet);
|
||||
}
|
||||
}
|
||||
|
||||
private byte validatePlayer(long user, String pass, String ip) {
|
||||
Server server = Server.getServer();
|
||||
byte returnVal = 0;
|
||||
|
||||
try {
|
||||
ResultSet result = Server.db.getQuery("SELECT r.pass, r.banned, r.owner, u.group_id, b.id AS b_id FROM `rscd_players` AS r INNER JOIN `users` AS u ON u.id=r.owner LEFT JOIN `bans` AS b on (b.username LIKE u.username OR b.ip LIKE '" + ip + "') WHERE `user`=" + user);
|
||||
if(!result.next() || !pass.equalsIgnoreCase(result.getString("pass"))) {
|
||||
System.out.println(result.getString("pass"));
|
||||
return 2;
|
||||
}
|
||||
|
||||
if(result.getInt("banned") == 1 || result.getInt("b_id") != 0) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
if(result.getInt("group_id") == 1 || result.getInt("group_id") == 2) {
|
||||
returnVal = 99;
|
||||
}
|
||||
|
||||
int owner = result.getInt("owner");
|
||||
for(World w : server.getWorlds()) {
|
||||
for(Entry<Long, Integer> player : w.getPlayers()) {
|
||||
if(player.getKey() == user) {
|
||||
return 3;
|
||||
}
|
||||
if(player.getValue() == owner) {
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
if(w.hasPlayer(user)) {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
catch(SQLException e) {
|
||||
System.out.println("Exception in PlayerLoginHandler :" + e.getMessage());
|
||||
//System.out.println(e.getMessage(), e);
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ import java.util.Properties;
|
||||
public class Config {
|
||||
public static int LS_PORT, QUERY_PORT;
|
||||
|
||||
public static String RSCDLS_HOME, CONF_DIR, LOG_DIR, MYSQL_HOST, MYSQL_DB, MYSQL_USER, MYSQL_PASS, LS_IP, QUERY_IP;
|
||||
public static String RSCDLS_HOME, CONF_DIR, LOG_DIR, MYSQL_HOST, MYSQL_DB, MYSQL_USER, MYSQL_PASS, LS_IP, QUERY_IP, AUTH_URL;
|
||||
|
||||
public static long START_TIME;
|
||||
|
||||
@ -43,6 +43,7 @@ public class Config {
|
||||
LS_PORT = Integer.parseInt(props.getProperty("lsport"));
|
||||
QUERY_IP = props.getProperty("queryip");
|
||||
QUERY_PORT = Integer.parseInt(props.getProperty("queryport"));
|
||||
AUTH_URL = props.getProperty("authURL", "https://www.moparscape.org/auth.php?field=");
|
||||
|
||||
props.clear();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user