Thread: Need help changing the cache file in the client files

Results 1 to 3 of 3
  1. #1 Need help changing the cache file in the client files 
    Registered Member
    Join Date
    Apr 2018
    Posts
    13
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    So I am facing this issue.. Yesterday my friends couldnt connect to the server because the client kept throwing an error, it was because it was the wrong cache files.
    Now that I know what cache files are needed I would need some help adding them to the code so that it downloads them.

    I have the folder with the cache files but I can't upload it anywhere it just wont let me for some reason. It uploads until like 10% and then it stops (dropbox)


    Currently I am getting this error.
    Attached image


    Here is the code for that error
    Code:
    public class FileDownloader {
    
    	@SuppressWarnings("unused")
    	private Client client;
    	
    	private static final int BUFFER_SIZE = 1024;
    	
    	public FileDownloader(Client client) {
    		this.client = client;
    	}
    	
    	public enum FileType {
    		CACHE(Signlink.findcachedir(), Configuration.NEW_CACHE_LINK, 1);
    
    		private String url;
    		private int version;
    		private String directory;
    
    		FileType(String directory, String url, int version) {
    			this.directory = directory;
    			this.url = url;
    			this.version = version;
    		}
    
    		public int getVersion() {
    			return version;
    		}
    
    		public String getURL() {
    			return url;
    		}
    
    		public String getDirectory() {
    			return directory;
    		}
    
    		@Override
    		public String toString() {
    			return name().toLowerCase();
    		}
    	}
    	
    	public static int lastPercent;
    	
    	private static void downloadFile(Client client, FileType type, String localFileName) {
    		try {
    			URL url = new URL(type.getURL());
    			URLConnection conn = url.openConnection();
    			try (OutputStream out = new BufferedOutputStream(new FileOutputStream(type.getDirectory() + "/" + localFileName)); InputStream in = conn.getInputStream()) {
    				byte[] data = new byte[BUFFER_SIZE];
    				int numRead;
    				long numWritten = 0;
    				int length = conn.getContentLength();
    				long startTime = System.currentTimeMillis();
    				while ((numRead = in.read(data)) != -1) {
    					out.write(data, 0, numRead);
    					numWritten += numRead;
    
    					int percentage = (int) (((double) numWritten / (double) length) * 100D);
    					
    					if (percentage != lastPercent) {
    						long elapsedTime = System.currentTimeMillis() - startTime;
    						int downloadSpeed = (int) ((numWritten / 1024) / (1 + (elapsedTime / 1000)));
    					
    						float speedInBytes = 1000f * numWritten / elapsedTime;
    						int timeRemaining =  (int) ((length - numWritten) / speedInBytes);
    						
    						client.drawLoadingText(percentage, "Exotic - Downloading Cache " + percentage + "%", downloadSpeed, timeRemaining);
    						lastPercent = percentage;
    					}
    				}
    
    				client.drawLoadingText(100, "Exotic - Unzipping...", -1, -1);
    			}
    		} catch (IOException ex) {
    			ex.printStackTrace();
    		}
    	}
    	
    	private static String getArchivedName(FileType type) {
    		int lastSlashIndex = type.getURL().lastIndexOf('/');
    		if ((lastSlashIndex >= 0) && (lastSlashIndex < (type.getURL().length() - 1))) {
    			return type.getURL().substring(lastSlashIndex + 1);
    		}
    		return "";
    	}
    	
    	public static void unZip(FileType type) throws IOException {
    		File file = new File(type.getDirectory() + File.separator + getArchivedName(type));
    		ZipFile zipFile = new ZipFile(file);
    		try {
    			Enumeration<? extends ZipEntry> entries = zipFile.entries();
    			while (entries.hasMoreElements()) {
    				ZipEntry entry = entries.nextElement();
    				File entryDestination = new File(type.getDirectory(), entry.getName());
    				if (entry.isDirectory()) {
    					entryDestination.mkdirs();
    				} else {
    					entryDestination.getParentFile().mkdirs();
    					InputStream in = zipFile.getInputStream(entry);
    					OutputStream out = new FileOutputStream(entryDestination);
    					IOUtils.copy(in, out);
    					IOUtils.closeQuietly(in);
    					out.close();
    				}
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		} finally {
    			zipFile.close();
    		}
    	}
    	
    	public static String getNewestVersion() {
    		String md5 = null;
    		try (InputStream input = new URL("https://exoticrs.com/public/cache/exotic.zip").openStream()) {
    			md5 = IOUtils.toString(input);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		return md5;
    	}
    	
    	public static String getCurrentVersion() {
    		File file = new File(FileType.CACHE.getDirectory() + "/" + getArchivedName(FileType.CACHE));
    		if (!file.exists()) {
    			return "";
    		}
    		String md5 = null;
    		try (FileInputStream fis = new FileInputStream(file)) {
    			md5 = DigestUtils.md5Hex(fis);
    			fis.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return md5;
    	}
    	
    	private static void handleException(Exception e){
    		StringBuilder strBuff = new StringBuilder();
    		strBuff.append("Please Screenshot this message, and send it to an admin!\r\n\r\n");
            strBuff.append(e.getClass().getName()).append(" \"").append(e.getMessage()).append("\"\r\n");
    		for(StackTraceElement s : e.getStackTrace())
    			strBuff.append(s.toString()).append("\r\n");
    		alert("Exception [" + e.getClass().getSimpleName() + "]",strBuff.toString(),true);
    	}
    	
    	private static void alert(String title,String msg,boolean error){
    		JOptionPane.showMessageDialog(null,
    			   msg,
    			   title,
    			    (error ? JOptionPane.ERROR_MESSAGE : JOptionPane.PLAIN_MESSAGE));
    	}
    	
    	public static void start(Client client, FileType type) {
    		try {
    			if (!getNewestVersion().equalsIgnoreCase(getCurrentVersion())) {
    				downloadFile(client, type, getArchivedName(type));
    				unZip(type);
    				//deleteZIP(getArchivedName(type), type);
    				/*@SuppressWarnings("resource")
    				OutputStream out = new FileOutputStream(VERSION_FILE);
    				alert("Cache has been updated, please restart the client!");
    				out.write(String.valueOf(newest).getBytes());;
    				System.exit(0);*/
    			}
    		} catch (Exception e) {
    			handleException(e);
    		}
    	}
    And the dropbox consts

    Code:
    package com.client;
    
    public class Configuration {
    	
    	public static String IP = "HIDINGMYIP HEHExd";
    	
    	/**
    	 * Constants
    	 */
    
    	//Make sure this matches server version
    	public static final int CLIENT_VERSION = 2;
    	
    	public static Boolean LIVE_SERVER = false;
    	public static final String CLIENT_TITLE = "Neztec";
    	public static final int PORT = 43594;
    	public static final String CACHE_NAME = "/.ExoticRS_Cache/Cache";
    	
    	// Used for data dumping - Helpful for IDS
    	public static Boolean DUMP_DATA = false;
    	public static int dumpID = 149;
    	
    	//Dump stackables and noted items
    	
    	public static Boolean DUMP_OTHER = false;
    
    	/**
    	 * Used to repack indexes 
    	 * Index 1 = Models
    	 * Index 2 = Animations
    	 * Index 3 = Sounds/Music
    	 * Index 4 = Maps
    	 * You can only do up to 300 files at a time
    	 */
    	
    	public static boolean repackIndexOne = false, repackIndexTwo = false,
    			repackIndexThree = false, repackIndexFour = false;
    	
    	/**
    	 * https://www.dropbox.com/s/5l60skekdk5picp/Ethos.zip?dl=0
    	 */
    	public static final String CACHE_LINK = "https://exoticrs.com/public/cache/exotic.zip"; //Link for every client below client v1.12 - being deprecated after everyone updates
    	
    	public static final String NEW_CACHE_LINK = "https://exoticrs.com/public/cache/exotic.zip"; //Link for v1.12 and above.
    	
    	public static final boolean WORLD_CHANGER = true; //Set false
    	
    	/**
    	 * Seasonal Events
    	 */
    	public static boolean HALLOWEEN = false;
    	public static boolean CHRISTMAS = false;
    	public static boolean CHRISTMAS_EVENT = false;
    	public static boolean EASTER = false;
    
    	/**
    	 * Testing data
    	 */
    	public static boolean TEST_DATA = false;
    
    }
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Oct 2011
    Posts
    2,084
    Thanks given
    0
    Thanks received
    1,043
    Rep Power
    3608
    search, "auto-cache downloader" on the forums.
    Reply With Quote  
     

  3. #3  
    Development Services

    Tutus Frutus's Avatar
    Join Date
    Feb 2018
    Posts
    466
    Thanks given
    228
    Thanks received
    217
    Rep Power
    687
    Upload it... change the URL's of the FileDownloader or Cachedownloader, whatever you should easily find it.

    Attached image
    Attached image
    Reply With Quote  
     


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: 1
    Last Post: 07-06-2017, 12:13 PM
  2. Replies: 1
    Last Post: 05-07-2017, 11:03 AM
  3. Replies: 2
    Last Post: 01-13-2014, 06:29 PM
  4. Sprite is in the cache, not in the game?
    By chad8812 in forum Help
    Replies: 3
    Last Post: 09-29-2012, 11:01 PM
  5. Replies: 1
    Last Post: 05-15-2010, 07:31 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
  •