Thread: [ NEWBIE ] Could someone please help me with a run error [ MYSQL ]

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 [ NEWBIE ] Could someone please help me with a run error [ MYSQL ] 
    Registered Member
    Join Date
    Aug 2013
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Hi everyone thanks for viewing my thread, I've spent the last 4 hours trying to figure this out and I just have no idea.
    I recently downloaded this source & client here: https://www.rune-server.ee/runescape...l-release.html .

    I've set up everyone for it to work uploaded all the .SQL's to the Xampp database etc. and when i go to run the server i'm getting this error it also prevents me from logging in aswell, If anyone could explain to me what I've done wrong or why its happening it would be much appreciated.

    Code:
    00:00:08]: [SQL] Error establishing connection. Please make sure you've correctly configured db.properties.
    [00:00:08]: java.lang.NullPointerException
    [00:00:08]:     at com.rs2.mysql.Mysql$ThreadLocalConnection.get(Mysql.java:27)
    [00:00:08]:     at com.rs2.mysql.Mysql$ThreadLocalConnection.get(Mysql.java:13)
    [00:00:08]:     at com.rs2.mysql.Mysql.getConnection(Mysql.java:63)
    [00:00:08]:     at com.rs2.mysql.Loadable.runSQLQuerys(Loadable.java:120)
    [00:00:08]:     at com.rs2.GameEngine.main(GameEngine.java:425)
    Reply With Quote  
     

  2. #2  
    Jake from State Farm

    FKN Jake's Avatar
    Join Date
    Nov 2013
    Posts
    675
    Thanks given
    45
    Thanks received
    58
    Rep Power
    153
    I'm assuming the login/password is attached to a forums login system somewhere. Look through GameEngine and MySql classes.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Aug 2013
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    I'm not sure what you mean, could you try explain what i have to do
    Reply With Quote  
     

  4. #4  
    Jake from State Farm

    FKN Jake's Avatar
    Join Date
    Nov 2013
    Posts
    675
    Thanks given
    45
    Thanks received
    58
    Rep Power
    153
    Quote Originally Posted by macemace View Post
    I'm not sure what you mean, could you try explain what i have to do
    Post GameEngine.java and MySQL.java here, remove database information.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Aug 2013
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Gameengine.java
    Code:
    package com.rs2;
    
    import com.creativescape.hiscores.HiscoreHandler;
    import com.rspserver.mvh.AuthService;
    import com.rspserver.mvh.Motivote;
    import com.rs2.content.Announcements;
    import com.rs2.content.VoteHandler;
    import com.rs2.content.StarterHandler;
    import com.rs2.content.actions.ActionManager;
    import com.rs2.content.bans.PunishmentHandler;
    import com.rs2.content.clanchat.ClanChatHandler;
    import com.rs2.content.cluescrolls.ClueScrollHandler;
    import com.rs2.content.controllers.ControllerManager;
    import com.rs2.content.dungeons.DungeonManager;
    import com.rs2.content.minigames.Zombie;
    import com.rs2.content.minigames.GodWars;
    import com.rs2.content.quests.QuestHandler;
    import com.rs2.gameevents.PestControl;
    import com.rs2.model.combat.CombatEngine;
    import com.rs2.model.npc.NPC;
    import com.rs2.model.player.Client;
    import com.rs2.model.player.Player;
    import com.rs2.model.player.commandmanager.CommandManager;
    import com.rs2.model.player.packetmanager.PacketManager;
    import com.rs2.model.regions.RegionHandler;
    import com.rs2.mysql.Loadable;
    import com.rs2.mysql.Website;
    import com.rs2.net.ConnectionListener;
    import com.rs2.task.Task;
    import com.rs2.task.TaskScheduler;
    import com.rs2.tiles.WorldMap;
    import com.rs2.util.log.Log;
    import com.rs2.world.DialogueManager;
    import com.rs2.world.GlobalActions;
    import com.rs2.world.NPCManager;
    import com.rs2.world.ObeliskManager;
    import com.rs2.world.ObjectManager;
    import com.rs2.world.PlayerManager;
    import com.rs2.world.ShopManager;
    import com.rs2.world.WorldItemManager;
    import com.rs2.world.XMLManager;
    import com.rs2.util.Misc;
    
    /**
     * GameEngine
     * 
     * @author Ultimate
     */
    
    public class GameEngine {
    
    	public static boolean multiValve = true;
    	public static boolean systemValve = false;
    
    	public static int dataSaved = 0;
    
    	private static long runTime, serverNullTime = System.currentTimeMillis();
    
    	private static Object gameLogicLock = new Object();
    
    	private static ConnectionListener ioThread = null;
    
    	private static final TaskScheduler scheduler = new TaskScheduler();
    
    	private static QuestHandler questHandler = null;
    
    	private static PlayerManager playerManager = null;
    
    	private static RegionHandler regionHandler = null;
    
    	private static DialogueManager dialogueManager = null;
    
    	private static NPCManager npcManager = null;
    
    	public static ObjectManager objectManager = null;
    
    	private static ObeliskManager obeliskManager = null;
    
    	private static WorldItemManager worldItemManager = null;
    
    	private static DungeonManager dungeonManager = null;
    
    	private static PestControl pestControl = null;
    
    	private static Zombie zombie = null;
    
    	private static ShopManager shopManager = null;
    
    	private static GlobalActions globalActions = null;
    	
    	private static HiscoreHandler hiscores = null;
    
    	private static int averageProcessTime = -1;
    
    	private static long start = 0;
    
    	private static boolean debug = false;
    
    	private static boolean shutdownServer = false;
    
    	private static void addShutdownHook(){
    		Runtime.getRuntime().addShutdownHook(new Thread() {
    			@Override
    			public void run() {
    				int saved = 0;
    				System.out.println("SERVER CRASHED, SAVING ALL PLAYERS");
    				if (Constants.showSaveMessage) {
    					System.out.println("Saving All Players...");
    				}
    				synchronized (this) {
    					for (Player p : getPlayerManager().getPlayers()) {
    						if (p == null)
    							continue;
    						if (((Client) p).getTradeHandler().stage > 0) {
    							System.out.println("Did not save "
    									+ p.getUsername()
    									+ " as they are in a trade.");
    							continue;
    						}
    						saved++;
    						getPlayerManager().saveGame((Client) p, true);
    						System.out.println("Game saved from " + p.getUsername()
    								+ ".");
    					}
    				}
    				if (Constants.showSaveMessage) {
    					System.out.println("All Players Saved");
    				}
    				getPlayerManager().hasSavedAll = true;
    			}
    		});
    	}
    	
    	public static boolean voteEvent = false;
    	
    	public static void setEvent(boolean x){
    		voteEvent = x;
    	}
    	
    	public static boolean voteWinner(Client client){
    		if(voteEvent){
    			if(votesLeft <= 0){
    				setEvent(false);
    				client.getActionSender().addItemOrDrop(rewards[rewardId], 1);
    				client.getActionSender().sendMessage("@yel@@sha@Congratulations, You win "+rewardName[rewardId]+". ty for participating!");
    				getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: "+client.getUsername()+" has claimed 16th vote! congratulations.");
    				return true;
    			}
    			votesLeft--;
    			return false;
    		}
    		return false;
    	}
    	
    	public static int[] rewards = {4151,4151,6570,6585,7158,6524,2577,4079,6866,1037,6808,6865,10396,10394};
    	public static String[] rewardName = {"Abyssal whip","Abyssal whip","Fire cape","Amulet of Fury","Dragon 2h sword","Obby shield","Ranger boots","Yo-yo","Green marionette","Bunny ears","Premium Scroll","Blue marionette","Pantalooons","Flared trousers"};
    	public static int rewardId, votesLeft;
    
    	public static void engineProcessing() {
    		scheduler.schedule(new Task() {
    			private int cycles = -2;
    			boolean firstRun = true;
    			boolean[] announcements = new boolean[6];
    
    			@Override
    			protected void execute() {
    				if(!isShutdown()){
    					getItemManager().process();
    					getShopManager().process();
    					getObeliskManager().process();
    					Announcements.process();
    					GodWars.process();
    					ClanChatHandler.process();
    
    					runTime = (System.currentTimeMillis() - serverNullTime);
    
    					if (cycles++ >= 1000 || firstRun && cycles == 30) {
    						if (firstRun)
    							firstRun = false;
    						System.gc();
    						cycles = 0;
    					}
    
    					if(cycles % 500 == 0){
    						String dataFormat = dataSaved + "B";
    						if(dataSaved > 1024)
    							dataFormat = dataSaved / 1024 + "KB";
    						if(dataSaved > 1024 * 1024)
    							dataFormat = dataSaved / (1024 * 1024) + "MB";
    						if(dataSaved > ((1024 * 1024) * 1024)){
    							dataFormat = dataSaved / ((1024 * 1024) * 1024) + "GB";
    						}
    
    						System.out.println("Data saved: " + dataFormat);
    					}
    
    					if (runTime >= (240 * 60000) && !getPlayerManager().updateRunning) {
    						serverNullTime = System.currentTimeMillis();
    						System.out.println("Server need to get Restarted.");
    						getPlayerManager().updateSeconds = 300;
    						getPlayerManager().updateAnnounced = false;
    						getPlayerManager().updateRunning = true;
    						getPlayerManager().updateStartTime = System
    								.currentTimeMillis();
    					}
    					if (runTime >= (200 * 60000) && runTime <= (200 * 60000 + 2000)) {
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    					}
    					
    					if(runTime >= (1000000) && runTime <= (1000600) || (runTime >= (120 * 60000) && runTime <= (7200600)) || (runTime >= (180 * 60000) && runTime <= (180 * 60000 + 600))){
    						setEvent(true);
    						votesLeft = 16;
    						rewardId = Misc.random(rewards.length-1);
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Vote event has started! the 16th auth wins "+rewardName[rewardId]+", gogog ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Vote event has started! the 16th auth wins "+rewardName[rewardId]+", gogog ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Vote event has started! the 16th auth wins "+rewardName[rewardId]+", gogog ::vote");
    					}
    					if(runTime >= (1000000 - 360000) && runTime <= (1000600 - 360000) || (runTime >= (120 * 60000 - 360000) && runTime <= (120 * 60000 + 600 - 360000)) ||
    							(runTime >= (180 * 60000 - 360000) && runTime <= (180 * 60000 + 600 - 360000)))
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Next Vote Event in 5mins, get your auths ready!");
    					
    					if(getPlayerManager().updateRunning){
    						long endTime =  getPlayerManager().updateStartTime + (getPlayerManager().updateSeconds * 1000);
    						if(!announcements[0]){
    							if(System.currentTimeMillis() >= endTime - 60000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server reboot in 60 seconds.");
    								announcements[0] = true;
    							}
    						} else if(!announcements[1]){
    							if(System.currentTimeMillis() >= endTime - 30000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server reboot in 30 seconds.");
    								getPlayerManager().sendGlobalMessage((long) 0, "Just a reminder this is a perfect time to do ::vote. :)");
    								announcements[1] = true;
    							}
    						/*} else if(!announcements[2]){
    							if(System.currentTimeMillis() >= endTime - 15000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server update in progress: 15 seconds left until reboot.");
    								announcements[2] = true;
    							}*/
    						} else if(!announcements[3]){
    							if(System.currentTimeMillis() >= endTime - 10000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server reboot in 10 seconds.");
    								announcements[3] = true;
    							}
    						/*} else if(!announcements[4]){
    							if(System.currentTimeMillis() >= endTime - 5000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server update in progress: 5 seconds left until reboot.");
    								announcements[4] = true;
    							}*/
    						} else if(!announcements[5]){
    							for(NPC npc : getNPCManager().getNpcMap().values()){
    								if(npc == null)
    									continue;
    								CombatEngine.resetAttack(npc, true);
    							}
    							for(Client plr : getPlayerManager().getPlayers()){
    								if(plr == null)
    									continue;
    								CombatEngine.resetAttack(plr, true);
    							}
    							announcements[5] = true;
    						}
    					}
    				} else {
    					GameEngine.getIoThread().shutdown();
    					getPlayerManager().shutdown();
    					StarterHandler.save();
    					//VoteHandler.saveVotes(); TODO
    					//PunishmentHandler.saveBlacklist(); TODO
    					
    					if(getPlayerManager().hasSavedAll){
    						stop();
    						System.out.println("*** Process ended. ***");
    					}
    				}
    			}
    
    			@Override
    			public void stop() {
    				System.exit(0); // server shut down
    			}
    		});
    
    	}
    
    	public static DialogueManager getDialogueManager() {
    		return dialogueManager;
    	}
    
    	public static DungeonManager getDungeonManager() {
    		return dungeonManager;
    	}
    	
    	public static HiscoreHandler getHiscores() {
    		return hiscores;
    	}
    
    	public static Object getGameLogicLock() {
    		return gameLogicLock;
    	}
    
    	public static GlobalActions getGlobalActions() {
    		return globalActions;
    	}
    
    	public static ConnectionListener getIoThread() {
    		return ioThread;
    	}
    
    	public static ConnectionListener getIOThread() {
    		return getIoThread();
    	}
    
    	public static WorldItemManager getItemManager() {
    		return worldItemManager;
    	}
    
    	public static int getJVMSize() {
    		Runtime runtime = Runtime.getRuntime();
    		return (int) ((runtime.totalMemory() - runtime.freeMemory()) / 1024L);
    	}
    
    	public static NPCManager getNPCManager() {
    		return npcManager;
    	}
    
    	public static ObeliskManager getObeliskManager() {
    		return obeliskManager;
    	}
    
    	public static ObjectManager getObjectManager() {
    		return objectManager;
    	}
    
    	public static PestControl getPestControl() {
    		return pestControl;
    	}
    
    	public static PlayerManager getPlayerManager() {
    		return playerManager;
    	}
    
    	public static int getProcessTime() {
    		return averageProcessTime;
    	}
    
    	public static long getRunTime(){
    		return runTime;
    	}
    
    	public static QuestHandler getQuestHandler() {
    		return questHandler;
    	}
    
    	public static ShopManager getShopManager() {
    		return shopManager;
    	}
    
    	/**
    	 * Gets the task scheduler.
    	 * 
    	 * @return The task scheduler.
    	 */
    	public static TaskScheduler getTaskScheduler() {
    		return scheduler;
    	}
    
    	public static String getUptime() {
    		long uptime = (System.currentTimeMillis() - start) / 1000;
    		int minutes = (int) (uptime / 60);
    		if (minutes == 0 || minutes == 1) {
    			return minutes + " min";
    		} else {
    			return minutes + " mins";
    		}
    	}
    
    	public static Zombie getZombie() {
    		return zombie;
    	}
    
    	public static boolean isDebugEnabled() {
    		return debug;
    	}
    
    	public static boolean isShutdown() {
    		return shutdownServer;
    	}
    
    	public static void main(String[] args) {
    		try {
    			AuthService.setProvider(new Motivote("S1XjZx74AcaphB338eFJuRMncN8M3Ule"));
    			System.setOut(new Log(System.out));
    			System.setErr(new Log(System.err));
    			addShutdownHook();
    
    			regionHandler = new RegionHandler();
    
    			start = System.currentTimeMillis();
    			XMLManager.loadServerSettings();
    			System.out.println();
    			System.out.println("Loading "
    					+ XMLManager.settings().getServerName() + "...");
    			StarterHandler.load();
    			//VoteHandler.loadVotes();
    			PunishmentHandler.loadBlacklist();
    
    			shopManager = new ShopManager();
    			npcManager = new NPCManager();
    			objectManager = new ObjectManager();
    			obeliskManager = new ObeliskManager();
    			worldItemManager = new WorldItemManager();
    			globalActions = new GlobalActions();
    			dialogueManager = new DialogueManager();
    			playerManager = PlayerManager.getSingleton();
    
    			PacketManager.loadAllPackets();
    			CommandManager.loadAllCommands();
    			ActionManager.loadAllActions();
    			Loadable.runSQLQuerys();
    			XMLManager.load();
    			WorldMap.load();
    			//Website.LoadTop10();
    			ClanChatHandler.preloadChannel();
    			System.gc();
    
    			engineProcessing();
    			playerProcessing();
    			minigameProcessing();
    
    			hiscores = new HiscoreHandler();
    			questHandler = new QuestHandler();
    			dungeonManager = new DungeonManager();// Has to load after world
    
    			ClueScrollHandler.initializeEvents(); 
    			// management
    
    			ioThread = new ConnectionListener();
    			(new Thread(getIoThread(), "ioThread")).start();
    
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static void minigameProcessing() {
    		scheduler.schedule(new Task() {
    			@Override
    			protected void execute() {
    				PestControl.process();
    				Zombie.process();
    
    				if (GameEngine.isShutdown())
    					stop();
    			}
    		});
    
    	}
    
    	public static void playerProcessing() {
    		scheduler.schedule(new Task() {
    
    			@Override
    			protected void execute() {
    				try {
    					ControllerManager.processRequests();
    					getNPCManager().process();
    					getPlayerManager().process();
    					ActionManager.processActions();
    					if (GameEngine.isShutdown())
    						stop();
    				} catch (Exception ex) {
    					ex.printStackTrace();
    				}
    			}
    		});
    
    	}
    
    	public static void setShutdown(boolean shutdown) {
    		shutdownServer = shutdown;
    	}
    }
    Mysql.java
    Code:
    package com.rs2.mysql;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    import com.rs2.model.player.Client;
    
    public class Mysql {
    
    	private static class ThreadLocalConnection extends ThreadLocal<Connection> {
    		static {
    			try {
    				Class.forName("com.mysql.jdbc.Driver");
    			} catch (ClassNotFoundException e) {
    				System.out
    						.println("[SQL] Could not locate the JDBC mysql driver.");
    			}
    		}
    
    		@Override
    		public Connection get() {
    			Connection con = super.get();
    			try {
    				if (!con.isClosed()) {
    					return con;
    				}
    			} catch (SQLException sql) {
    			}
    			con = getConnection();
    			super.set(con);
    			return con;
    		}
    
    		private Connection getConnection() {
    			DriverManager.setLoginTimeout(15);
    			try {
    				return DriverManager.getConnection(url, user, pass);
    			} catch (SQLException sql) {
    				System.out
    						.println("[SQL] Error establishing connection. Please make sure you've correctly configured db.properties.");
    				return null;
    			}
    		}
    
    		@Override
    		protected Connection initialValue() {
    			return getConnection();
    		}
    
    	}
    
    	private static ThreadLocal<Connection> con = new ThreadLocalConnection();
    	// private static String url =
    	// "jdbc:mysql://creativescape.myftp.org:3306/creativescape";
    	private static String url = "jdbc:mysql://localhost:3306/creativescape";
    	private static String user = "removed";
    	private static String pass = "removed";
    
    	public static Connection getConnection() {
    		return con.get();
    	}
    
    	public static void Membership(Client client, boolean lifetime) {
    		long daysLeft = 0;
    		if(client.getLong("MEMS_END") != -1){
    			daysLeft = client.getLong("MEMS_END");
    			daysLeft -= System.currentTimeMillis();
    		}
    		long dayyys = ((long)86400000 * (lifetime ?  1000 : 1000));
    		dayyys += (daysLeft > 0 ? daysLeft : 0);
    		long memberDay = System.currentTimeMillis() + dayyys;
    		try {
    			Connection con = Mysql.getConnection();
    			Statement s = con.createStatement();
    			s.executeUpdate("DELETE FROM `membership` WHERE ID = '" + client.ID
    					+ "'");
    			s.executeUpdate("INSERT INTO `membership` (ID,startms,endms) VALUES ('"
    					+ client.ID + "','" + System.currentTimeMillis() + "','" + memberDay
    					+ "');");
    			s.close();
    			con.close();
    			Mysql.release();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		client.playerIsMember = true;
    	}
    	
    	public static void convertMembers(){
    		try {
    			Connection con = Mysql.getConnection();
    			Statement s = con.createStatement();
    		for(int i = 0;i<=130000;i++){
    		
    			s.execute("SELECT * FROM `membership` WHERE ID = '" + i + "'");
    			ResultSet rs = s.getResultSet();
    			if(rs.next()){
    				int days = rs.getInt("days");
    				int date = rs.getInt("date");
    				rs.close();
    				long timeLeft = date - days;
    				if(timeLeft > 500)
    					timeLeft = 10000;
    				long newDate =  (86400000 * timeLeft);
    				newDate +=System.currentTimeMillis();
    				System.out.println(newDate);
    				s.executeUpdate("UPDATE `membership`"
    						+ " SET startms='" + System.currentTimeMillis() + "', endms='" + (newDate) + "' WHERE ID='" + i + "'");
    			}
    
    		}
    
    			s.close();
    			con.close();
    			Mysql.release();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static void release() throws SQLException {
    		con.get().close();
    		con.remove();
    	}
    }
    Reply With Quote  
     

  6. #6  
    Community Veteran


    Arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,950
    Thanks given
    210
    Thanks received
    349
    Rep Power
    1376
    Quote Originally Posted by macemace View Post
    Gameengine.java
    Code:
    package com.rs2;
    
    import com.creativescape.hiscores.HiscoreHandler;
    import com.rspserver.mvh.AuthService;
    import com.rspserver.mvh.Motivote;
    import com.rs2.content.Announcements;
    import com.rs2.content.VoteHandler;
    import com.rs2.content.StarterHandler;
    import com.rs2.content.actions.ActionManager;
    import com.rs2.content.bans.PunishmentHandler;
    import com.rs2.content.clanchat.ClanChatHandler;
    import com.rs2.content.cluescrolls.ClueScrollHandler;
    import com.rs2.content.controllers.ControllerManager;
    import com.rs2.content.dungeons.DungeonManager;
    import com.rs2.content.minigames.Zombie;
    import com.rs2.content.minigames.GodWars;
    import com.rs2.content.quests.QuestHandler;
    import com.rs2.gameevents.PestControl;
    import com.rs2.model.combat.CombatEngine;
    import com.rs2.model.npc.NPC;
    import com.rs2.model.player.Client;
    import com.rs2.model.player.Player;
    import com.rs2.model.player.commandmanager.CommandManager;
    import com.rs2.model.player.packetmanager.PacketManager;
    import com.rs2.model.regions.RegionHandler;
    import com.rs2.mysql.Loadable;
    import com.rs2.mysql.Website;
    import com.rs2.net.ConnectionListener;
    import com.rs2.task.Task;
    import com.rs2.task.TaskScheduler;
    import com.rs2.tiles.WorldMap;
    import com.rs2.util.log.Log;
    import com.rs2.world.DialogueManager;
    import com.rs2.world.GlobalActions;
    import com.rs2.world.NPCManager;
    import com.rs2.world.ObeliskManager;
    import com.rs2.world.ObjectManager;
    import com.rs2.world.PlayerManager;
    import com.rs2.world.ShopManager;
    import com.rs2.world.WorldItemManager;
    import com.rs2.world.XMLManager;
    import com.rs2.util.Misc;
    
    /**
     * GameEngine
     * 
     * @author Ultimate
     */
    
    public class GameEngine {
    
    	public static boolean multiValve = true;
    	public static boolean systemValve = false;
    
    	public static int dataSaved = 0;
    
    	private static long runTime, serverNullTime = System.currentTimeMillis();
    
    	private static Object gameLogicLock = new Object();
    
    	private static ConnectionListener ioThread = null;
    
    	private static final TaskScheduler scheduler = new TaskScheduler();
    
    	private static QuestHandler questHandler = null;
    
    	private static PlayerManager playerManager = null;
    
    	private static RegionHandler regionHandler = null;
    
    	private static DialogueManager dialogueManager = null;
    
    	private static NPCManager npcManager = null;
    
    	public static ObjectManager objectManager = null;
    
    	private static ObeliskManager obeliskManager = null;
    
    	private static WorldItemManager worldItemManager = null;
    
    	private static DungeonManager dungeonManager = null;
    
    	private static PestControl pestControl = null;
    
    	private static Zombie zombie = null;
    
    	private static ShopManager shopManager = null;
    
    	private static GlobalActions globalActions = null;
    	
    	private static HiscoreHandler hiscores = null;
    
    	private static int averageProcessTime = -1;
    
    	private static long start = 0;
    
    	private static boolean debug = false;
    
    	private static boolean shutdownServer = false;
    
    	private static void addShutdownHook(){
    		Runtime.getRuntime().addShutdownHook(new Thread() {
    			@Override
    			public void run() {
    				int saved = 0;
    				System.out.println("SERVER CRASHED, SAVING ALL PLAYERS");
    				if (Constants.showSaveMessage) {
    					System.out.println("Saving All Players...");
    				}
    				synchronized (this) {
    					for (Player p : getPlayerManager().getPlayers()) {
    						if (p == null)
    							continue;
    						if (((Client) p).getTradeHandler().stage > 0) {
    							System.out.println("Did not save "
    									+ p.getUsername()
    									+ " as they are in a trade.");
    							continue;
    						}
    						saved++;
    						getPlayerManager().saveGame((Client) p, true);
    						System.out.println("Game saved from " + p.getUsername()
    								+ ".");
    					}
    				}
    				if (Constants.showSaveMessage) {
    					System.out.println("All Players Saved");
    				}
    				getPlayerManager().hasSavedAll = true;
    			}
    		});
    	}
    	
    	public static boolean voteEvent = false;
    	
    	public static void setEvent(boolean x){
    		voteEvent = x;
    	}
    	
    	public static boolean voteWinner(Client client){
    		if(voteEvent){
    			if(votesLeft <= 0){
    				setEvent(false);
    				client.getActionSender().addItemOrDrop(rewards[rewardId], 1);
    				client.getActionSender().sendMessage("@yel@@sha@Congratulations, You win "+rewardName[rewardId]+". ty for participating!");
    				getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: "+client.getUsername()+" has claimed 16th vote! congratulations.");
    				return true;
    			}
    			votesLeft--;
    			return false;
    		}
    		return false;
    	}
    	
    	public static int[] rewards = {4151,4151,6570,6585,7158,6524,2577,4079,6866,1037,6808,6865,10396,10394};
    	public static String[] rewardName = {"Abyssal whip","Abyssal whip","Fire cape","Amulet of Fury","Dragon 2h sword","Obby shield","Ranger boots","Yo-yo","Green marionette","Bunny ears","Premium Scroll","Blue marionette","Pantalooons","Flared trousers"};
    	public static int rewardId, votesLeft;
    
    	public static void engineProcessing() {
    		scheduler.schedule(new Task() {
    			private int cycles = -2;
    			boolean firstRun = true;
    			boolean[] announcements = new boolean[6];
    
    			@Override
    			protected void execute() {
    				if(!isShutdown()){
    					getItemManager().process();
    					getShopManager().process();
    					getObeliskManager().process();
    					Announcements.process();
    					GodWars.process();
    					ClanChatHandler.process();
    
    					runTime = (System.currentTimeMillis() - serverNullTime);
    
    					if (cycles++ >= 1000 || firstRun && cycles == 30) {
    						if (firstRun)
    							firstRun = false;
    						System.gc();
    						cycles = 0;
    					}
    
    					if(cycles % 500 == 0){
    						String dataFormat = dataSaved + "B";
    						if(dataSaved > 1024)
    							dataFormat = dataSaved / 1024 + "KB";
    						if(dataSaved > 1024 * 1024)
    							dataFormat = dataSaved / (1024 * 1024) + "MB";
    						if(dataSaved > ((1024 * 1024) * 1024)){
    							dataFormat = dataSaved / ((1024 * 1024) * 1024) + "GB";
    						}
    
    						System.out.println("Data saved: " + dataFormat);
    					}
    
    					if (runTime >= (240 * 60000) && !getPlayerManager().updateRunning) {
    						serverNullTime = System.currentTimeMillis();
    						System.out.println("Server need to get Restarted.");
    						getPlayerManager().updateSeconds = 300;
    						getPlayerManager().updateAnnounced = false;
    						getPlayerManager().updateRunning = true;
    						getPlayerManager().updateStartTime = System
    								.currentTimeMillis();
    					}
    					if (runTime >= (200 * 60000) && runTime <= (200 * 60000 + 2000)) {
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Have you voted? ::vote");
    					}
    					
    					if(runTime >= (1000000) && runTime <= (1000600) || (runTime >= (120 * 60000) && runTime <= (7200600)) || (runTime >= (180 * 60000) && runTime <= (180 * 60000 + 600))){
    						setEvent(true);
    						votesLeft = 16;
    						rewardId = Misc.random(rewards.length-1);
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Vote event has started! the 16th auth wins "+rewardName[rewardId]+", gogog ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Vote event has started! the 16th auth wins "+rewardName[rewardId]+", gogog ::vote");
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Vote event has started! the 16th auth wins "+rewardName[rewardId]+", gogog ::vote");
    					}
    					if(runTime >= (1000000 - 360000) && runTime <= (1000600 - 360000) || (runTime >= (120 * 60000 - 360000) && runTime <= (120 * 60000 + 600 - 360000)) ||
    							(runTime >= (180 * 60000 - 360000) && runTime <= (180 * 60000 + 600 - 360000)))
    						getPlayerManager().sendGlobalMessage((long) 0, "@dre@WolfPk@bla@: Next Vote Event in 5mins, get your auths ready!");
    					
    					if(getPlayerManager().updateRunning){
    						long endTime =  getPlayerManager().updateStartTime + (getPlayerManager().updateSeconds * 1000);
    						if(!announcements[0]){
    							if(System.currentTimeMillis() >= endTime - 60000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server reboot in 60 seconds.");
    								announcements[0] = true;
    							}
    						} else if(!announcements[1]){
    							if(System.currentTimeMillis() >= endTime - 30000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server reboot in 30 seconds.");
    								getPlayerManager().sendGlobalMessage((long) 0, "Just a reminder this is a perfect time to do ::vote. :)");
    								announcements[1] = true;
    							}
    						/*} else if(!announcements[2]){
    							if(System.currentTimeMillis() >= endTime - 15000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server update in progress: 15 seconds left until reboot.");
    								announcements[2] = true;
    							}*/
    						} else if(!announcements[3]){
    							if(System.currentTimeMillis() >= endTime - 10000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server reboot in 10 seconds.");
    								announcements[3] = true;
    							}
    						/*} else if(!announcements[4]){
    							if(System.currentTimeMillis() >= endTime - 5000){
    								getPlayerManager().sendGlobalMessage((long) 0, "Server update in progress: 5 seconds left until reboot.");
    								announcements[4] = true;
    							}*/
    						} else if(!announcements[5]){
    							for(NPC npc : getNPCManager().getNpcMap().values()){
    								if(npc == null)
    									continue;
    								CombatEngine.resetAttack(npc, true);
    							}
    							for(Client plr : getPlayerManager().getPlayers()){
    								if(plr == null)
    									continue;
    								CombatEngine.resetAttack(plr, true);
    							}
    							announcements[5] = true;
    						}
    					}
    				} else {
    					GameEngine.getIoThread().shutdown();
    					getPlayerManager().shutdown();
    					StarterHandler.save();
    					//VoteHandler.saveVotes(); TODO
    					//PunishmentHandler.saveBlacklist(); TODO
    					
    					if(getPlayerManager().hasSavedAll){
    						stop();
    						System.out.println("*** Process ended. ***");
    					}
    				}
    			}
    
    			@Override
    			public void stop() {
    				System.exit(0); // server shut down
    			}
    		});
    
    	}
    
    	public static DialogueManager getDialogueManager() {
    		return dialogueManager;
    	}
    
    	public static DungeonManager getDungeonManager() {
    		return dungeonManager;
    	}
    	
    	public static HiscoreHandler getHiscores() {
    		return hiscores;
    	}
    
    	public static Object getGameLogicLock() {
    		return gameLogicLock;
    	}
    
    	public static GlobalActions getGlobalActions() {
    		return globalActions;
    	}
    
    	public static ConnectionListener getIoThread() {
    		return ioThread;
    	}
    
    	public static ConnectionListener getIOThread() {
    		return getIoThread();
    	}
    
    	public static WorldItemManager getItemManager() {
    		return worldItemManager;
    	}
    
    	public static int getJVMSize() {
    		Runtime runtime = Runtime.getRuntime();
    		return (int) ((runtime.totalMemory() - runtime.freeMemory()) / 1024L);
    	}
    
    	public static NPCManager getNPCManager() {
    		return npcManager;
    	}
    
    	public static ObeliskManager getObeliskManager() {
    		return obeliskManager;
    	}
    
    	public static ObjectManager getObjectManager() {
    		return objectManager;
    	}
    
    	public static PestControl getPestControl() {
    		return pestControl;
    	}
    
    	public static PlayerManager getPlayerManager() {
    		return playerManager;
    	}
    
    	public static int getProcessTime() {
    		return averageProcessTime;
    	}
    
    	public static long getRunTime(){
    		return runTime;
    	}
    
    	public static QuestHandler getQuestHandler() {
    		return questHandler;
    	}
    
    	public static ShopManager getShopManager() {
    		return shopManager;
    	}
    
    	/**
    	 * Gets the task scheduler.
    	 * 
    	 * @return The task scheduler.
    	 */
    	public static TaskScheduler getTaskScheduler() {
    		return scheduler;
    	}
    
    	public static String getUptime() {
    		long uptime = (System.currentTimeMillis() - start) / 1000;
    		int minutes = (int) (uptime / 60);
    		if (minutes == 0 || minutes == 1) {
    			return minutes + " min";
    		} else {
    			return minutes + " mins";
    		}
    	}
    
    	public static Zombie getZombie() {
    		return zombie;
    	}
    
    	public static boolean isDebugEnabled() {
    		return debug;
    	}
    
    	public static boolean isShutdown() {
    		return shutdownServer;
    	}
    
    	public static void main(String[] args) {
    		try {
    			AuthService.setProvider(new Motivote("S1XjZx74AcaphB338eFJuRMncN8M3Ule"));
    			System.setOut(new Log(System.out));
    			System.setErr(new Log(System.err));
    			addShutdownHook();
    
    			regionHandler = new RegionHandler();
    
    			start = System.currentTimeMillis();
    			XMLManager.loadServerSettings();
    			System.out.println();
    			System.out.println("Loading "
    					+ XMLManager.settings().getServerName() + "...");
    			StarterHandler.load();
    			//VoteHandler.loadVotes();
    			PunishmentHandler.loadBlacklist();
    
    			shopManager = new ShopManager();
    			npcManager = new NPCManager();
    			objectManager = new ObjectManager();
    			obeliskManager = new ObeliskManager();
    			worldItemManager = new WorldItemManager();
    			globalActions = new GlobalActions();
    			dialogueManager = new DialogueManager();
    			playerManager = PlayerManager.getSingleton();
    
    			PacketManager.loadAllPackets();
    			CommandManager.loadAllCommands();
    			ActionManager.loadAllActions();
    			Loadable.runSQLQuerys();
    			XMLManager.load();
    			WorldMap.load();
    			//Website.LoadTop10();
    			ClanChatHandler.preloadChannel();
    			System.gc();
    
    			engineProcessing();
    			playerProcessing();
    			minigameProcessing();
    
    			hiscores = new HiscoreHandler();
    			questHandler = new QuestHandler();
    			dungeonManager = new DungeonManager();// Has to load after world
    
    			ClueScrollHandler.initializeEvents(); 
    			// management
    
    			ioThread = new ConnectionListener();
    			(new Thread(getIoThread(), "ioThread")).start();
    
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static void minigameProcessing() {
    		scheduler.schedule(new Task() {
    			@Override
    			protected void execute() {
    				PestControl.process();
    				Zombie.process();
    
    				if (GameEngine.isShutdown())
    					stop();
    			}
    		});
    
    	}
    
    	public static void playerProcessing() {
    		scheduler.schedule(new Task() {
    
    			@Override
    			protected void execute() {
    				try {
    					ControllerManager.processRequests();
    					getNPCManager().process();
    					getPlayerManager().process();
    					ActionManager.processActions();
    					if (GameEngine.isShutdown())
    						stop();
    				} catch (Exception ex) {
    					ex.printStackTrace();
    				}
    			}
    		});
    
    	}
    
    	public static void setShutdown(boolean shutdown) {
    		shutdownServer = shutdown;
    	}
    }
    Mysql.java
    Code:
    package com.rs2.mysql;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    import com.rs2.model.player.Client;
    
    public class Mysql {
    
    	private static class ThreadLocalConnection extends ThreadLocal<Connection> {
    		static {
    			try {
    				Class.forName("com.mysql.jdbc.Driver");
    			} catch (ClassNotFoundException e) {
    				System.out
    						.println("[SQL] Could not locate the JDBC mysql driver.");
    			}
    		}
    
    		@Override
    		public Connection get() {
    			Connection con = super.get();
    			try {
    				if (!con.isClosed()) {
    					return con;
    				}
    			} catch (SQLException sql) {
    			}
    			con = getConnection();
    			super.set(con);
    			return con;
    		}
    
    		private Connection getConnection() {
    			DriverManager.setLoginTimeout(15);
    			try {
    				return DriverManager.getConnection(url, user, pass);
    			} catch (SQLException sql) {
    				System.out
    						.println("[SQL] Error establishing connection. Please make sure you've correctly configured db.properties.");
    				return null;
    			}
    		}
    
    		@Override
    		protected Connection initialValue() {
    			return getConnection();
    		}
    
    	}
    
    	private static ThreadLocal<Connection> con = new ThreadLocalConnection();
    	// private static String url =
    	// "jdbc:mysql://creativescape.myftp.org:3306/creativescape";
    	private static String url = "jdbc:mysql://localhost:3306/creativescape";
    	private static String user = "removed";
    	private static String pass = "removed";
    
    	public static Connection getConnection() {
    		return con.get();
    	}
    
    	public static void Membership(Client client, boolean lifetime) {
    		long daysLeft = 0;
    		if(client.getLong("MEMS_END") != -1){
    			daysLeft = client.getLong("MEMS_END");
    			daysLeft -= System.currentTimeMillis();
    		}
    		long dayyys = ((long)86400000 * (lifetime ?  1000 : 1000));
    		dayyys += (daysLeft > 0 ? daysLeft : 0);
    		long memberDay = System.currentTimeMillis() + dayyys;
    		try {
    			Connection con = Mysql.getConnection();
    			Statement s = con.createStatement();
    			s.executeUpdate("DELETE FROM `membership` WHERE ID = '" + client.ID
    					+ "'");
    			s.executeUpdate("INSERT INTO `membership` (ID,startms,endms) VALUES ('"
    					+ client.ID + "','" + System.currentTimeMillis() + "','" + memberDay
    					+ "');");
    			s.close();
    			con.close();
    			Mysql.release();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		client.playerIsMember = true;
    	}
    	
    	public static void convertMembers(){
    		try {
    			Connection con = Mysql.getConnection();
    			Statement s = con.createStatement();
    		for(int i = 0;i<=130000;i++){
    		
    			s.execute("SELECT * FROM `membership` WHERE ID = '" + i + "'");
    			ResultSet rs = s.getResultSet();
    			if(rs.next()){
    				int days = rs.getInt("days");
    				int date = rs.getInt("date");
    				rs.close();
    				long timeLeft = date - days;
    				if(timeLeft > 500)
    					timeLeft = 10000;
    				long newDate =  (86400000 * timeLeft);
    				newDate +=System.currentTimeMillis();
    				System.out.println(newDate);
    				s.executeUpdate("UPDATE `membership`"
    						+ " SET startms='" + System.currentTimeMillis() + "', endms='" + (newDate) + "' WHERE ID='" + i + "'");
    			}
    
    		}
    
    			s.close();
    			con.close();
    			Mysql.release();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static void release() throws SQLException {
    		con.get().close();
    		con.remove();
    	}
    }
    This is what causing it:

    private static String user = "removed";
    private static String pass = "removed";

    return DriverManager.getConnection(url, user, pass);


    "A fail act is something you do regular, but a dumb act is something you can learn from"
    Spoiler for Problem?:
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Aug 2013
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    I just typed removed so no one could see my password. Hey mate do you think you could tell me what i need to put in this field
    return DriverManager.getConnection(url, user, pass);

    what would the URL be? thanks again
    Reply With Quote  
     

  8. #8  
    Community Veteran


    Arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,950
    Thanks given
    210
    Thanks received
    349
    Rep Power
    1376
    Quote Originally Posted by macemace View Post
    I just typed removed so no one could see my password. Hey mate do you think you could tell me what i need to put in this field
    return DriverManager.getConnection(url, user, pass);

    what would the URL be? thanks again
    [00:00:08]: at com.rs2.mysql.Mysql.getConnection(Mysql.java:63)
    Mysql.java @line 63
    [00:00:08]: at com.rs2.mysql.Loadable.runSQLQuerys(Loadable.java: 120)
    Loadable.java @line 120


    "A fail act is something you do regular, but a dumb act is something you can learn from"
    Spoiler for Problem?:
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Aug 2013
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    I sound so dumb right now, so what do i do? i don't have a notepad that numbers the lines lol.
    Reply With Quote  
     

  10. #10  
    Registered Member Stevenhax's Avatar
    Join Date
    Jul 2014
    Posts
    387
    Thanks given
    55
    Thanks received
    64
    Rep Power
    42
    Quote Originally Posted by macemace View Post
    I sound so dumb right now, so what do i do? i don't have a notepad that numbers the lines lol.
    Kinda off topic but please consider using an IDE like Eclipse or IntelliJ, not doing so makes things so
    much harder than they have to be.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 0
    Last Post: 07-29-2013, 12:14 PM
  2. Can someone please help me with this!
    By Xoath in forum Hardware
    Replies: 7
    Last Post: 10-13-2012, 09:38 PM
  3. Could someone please help me?
    By wannabecoder :) in forum Requests
    Replies: 3
    Last Post: 01-05-2011, 09:29 AM
  4. Someone please help me with this simple code
    By jordan641 in forum Requests
    Replies: 1
    Last Post: 10-24-2010, 05:00 AM
  5. Replies: 0
    Last Post: 06-30-2010, 03:00 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •