diff --git a/.gitignore b/.gitignore index 15f2057..1223e80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ .classpath .project -*.jar +rscd.jar +ls.jar *.ipr *.iws *.iml *.class -Client/ bin build .* diff --git a/GameServer/build.xml b/GameServer/build.xml index a64be0c..863479f 100644 --- a/GameServer/build.xml +++ b/GameServer/build.xml @@ -7,13 +7,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GameServer/src/org/moparscape/msc/config/Config.java b/GameServer/src/org/moparscape/msc/config/Config.java index 79be490..bf19ee9 100644 --- a/GameServer/src/org/moparscape/msc/config/Config.java +++ b/GameServer/src/org/moparscape/msc/config/Config.java @@ -30,6 +30,7 @@ public class Config { public static double expRate, subExpRate; public static String[] pmods, mods, admins; + public static String UNUSED_IP; static { loadEnv(); @@ -77,6 +78,8 @@ public class Config { mods = props.getProperty("mods").replaceAll(", +", ",").split(","); admins = props.getProperty("admins").replaceAll(", +", ",").split(","); + UNUSED_IP = props.getProperty("unused-ip"); + 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") + ")"; diff --git a/GameServer/src/org/moparscape/msc/gs/Cache.java b/GameServer/src/org/moparscape/msc/gs/Cache.java deleted file mode 100644 index f18d06b..0000000 --- a/GameServer/src/org/moparscape/msc/gs/Cache.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.moparscape.msc.gs; - -import java.util.Map; - -import org.apache.commons.collections.map.LRUMap; - -/** - * A basic cache backed by a {@link LRUMap}. - * - * @author CodeForFame - * - */ -public class Cache { - - // Shitty commons and their failure to support generics... - @SuppressWarnings("unchecked") - private Map cache = new LRUMap(); - - public V get(K key) { - return cache.get(key); - } - - public void put(K key, V value) { - cache.put(key, value); - } - -} diff --git a/GameServer/src/org/moparscape/msc/gs/Server.java b/GameServer/src/org/moparscape/msc/gs/Server.java index f772a87..f8249a4 100644 --- a/GameServer/src/org/moparscape/msc/gs/Server.java +++ b/GameServer/src/org/moparscape/msc/gs/Server.java @@ -14,6 +14,7 @@ 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; @@ -21,209 +22,221 @@ import org.moparscape.msc.gs.event.SingleEvent; import org.moparscape.msc.gs.model.World; import org.moparscape.msc.gs.util.Logger; - /** * 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(); + } + } + + if (args[2] != null && args[2].equalsIgnoreCase("no")) + Constants.IRC.USE_IRC = false; + + world = Instance.getWorld(); + world.wl.loadObjects(); + + Config.initConfig(configFile); + 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; - - world = Instance.getWorld(); - world.wl.loadObjects(); + private static Server server; - Config.initConfig(configFile); - World.initilizeDB(); - - Logger.println(Config.SERVER_NAME + " [" + (Config.members ? "P2P" : "F2P") + "] " + "Server starting up..."); - - new Server(); - } - - public static boolean isMembers() { - return Config.members; - } - - /** - * The SocketAcceptor - */ - private IoAcceptor acceptor; - /** - * The login server connection - */ - private LoginConnector connector; - /** - * The game engine - */ - private GameEngine engine; - - 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 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); - try { - Instance.getPluginHandler().initPlugins(); - } catch (Exception e) { - e.printStackTrace(); + public static boolean isMembers() { + return Config.members; } - 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); + /** + * The SocketAcceptor + */ + private IoAcceptor acceptor; + /** + * The login server connection + */ + private LoginConnector connector; + /** + * The game engine + */ + private GameEngine engine; - 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 IoAcceptor getAcceptor() { + return 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(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; + public void setAcceptor(IoAcceptor acceptor) { + this.acceptor = acceptor; } - 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 LoginConnector getConnector() { + return connector; } - return updateEvent.timeTillNextRun(); - } - /** - * Unbinds the socket acceptor - */ - public void unbind() { - try { - acceptor.unbindAll(); - } catch (Exception e) { + public void setConnector(LoginConnector connector) { + this.connector = connector; + } + + 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); + 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 and irc 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; } - } } diff --git a/GameServer/src/org/moparscape/msc/gs/core/GameEngine.java b/GameServer/src/org/moparscape/msc/gs/core/GameEngine.java index abb92e1..c1fcdf0 100644 --- a/GameServer/src/org/moparscape/msc/gs/core/GameEngine.java +++ b/GameServer/src/org/moparscape/msc/gs/core/GameEngine.java @@ -21,6 +21,7 @@ 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 +97,6 @@ public final class GameEngine extends Thread { return time; } - /** - * Processes incoming packets. - */ - private Map written = Collections - .synchronizedMap(new HashMap()); - /** * Constructs a new game engine with an empty packet queue. */ @@ -208,6 +203,10 @@ public final class GameEngine extends Thread { private void processEvents() { eventHandler.doEvents(); } + + public DelayedEventHandler getEventHandler() { + return eventHandler; + } /** * Redirects system err @@ -242,29 +241,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) { - Logger.error(err); - } - } - }); - try { - // Runtime.getRuntime().exec( - // "sudo /sbin/route add " + ip + " gw 127.0.0.1"); - } catch (Exception err) { - Logger.error(err); - } - Logger.println("Dummy packet from " + player.getCurrentIP() - + ": " + p.getID()); - written.put(ip, 1); - } + OSLevelBlocking.block(ip); continue; } PacketHandler handler = packetHandlers.get(p.getID()); diff --git a/GameServer/src/org/moparscape/msc/gs/model/Player.java b/GameServer/src/org/moparscape/msc/gs/model/Player.java index b3cabe6..bda826a 100644 --- a/GameServer/src/org/moparscape/msc/gs/model/Player.java +++ b/GameServer/src/org/moparscape/msc/gs/model/Player.java @@ -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; diff --git a/GameServer/src/org/moparscape/msc/gs/model/mini/CacheObject.java b/GameServer/src/org/moparscape/msc/gs/model/mini/CacheObject.java deleted file mode 100644 index 423fbb9..0000000 --- a/GameServer/src/org/moparscape/msc/gs/model/mini/CacheObject.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.moparscape.msc.gs.model.mini; - -/** - * Data each player gets cached. - * - * @author xEnt - * - */ -public class CacheObject { - - public boolean muted = false; - public boolean inRed = false; - public boolean inBlue = false; - -} diff --git a/GameServer/src/org/moparscape/msc/gs/model/mini/Damage.java b/GameServer/src/org/moparscape/msc/gs/model/mini/Damage.java index 4d080da..ea54c63 100644 --- a/GameServer/src/org/moparscape/msc/gs/model/mini/Damage.java +++ b/GameServer/src/org/moparscape/msc/gs/model/mini/Damage.java @@ -1,77 +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(); - } -} +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(); + } +} \ No newline at end of file diff --git a/GameServer/src/org/moparscape/msc/gs/plugins/extras/Quiz.java b/GameServer/src/org/moparscape/msc/gs/plugins/extras/Quiz.java deleted file mode 100644 index 7084b96..0000000 --- a/GameServer/src/org/moparscape/msc/gs/plugins/extras/Quiz.java +++ /dev/null @@ -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) { Logging.debug("Error removing " + p.getUsername() + - * " from the Quiz list."); return; } else { Logging.debug("[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); - } - } - -}