Thread: Cache downloading Problem (ruse base)

Results 1 to 3 of 3
  1. #1 Cache downloading Problem (ruse base) 
    Registered Member
    Join Date
    Dec 2016
    Posts
    2
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    *Edited Due to bad wording *

    Hey
    .
    I am having trouble that i need help solving. I have a rsps uploaded on a vps at the moment with the source set up correctly so if i copy my cache from my vps to my pc and download my jarred client i can log in into the game fine.

    But that is no good to people who do not have the cache to copy . So i began setting up the auto cache downloader and even getting the cache update server that came with the base working.

    My problem is the way the cache works it downloads 3 load files before the rest of the cache being a loading background and loading bar ect and then downloads the rest. I have it working to the point it downloads most of the files but dont seem to download my sprite files (sprites.dat, sprites.idx)

    i checked in my cache downloader to see if the file names were mentioned to download and they were but are the only one's that will not download...

    I cant seem to work out why and would be a great help if anyone knew the problem and how to fix???

    NOTE: If i place the sprite files in my cache myself after the downloader has downloaded the rest of the files the game will load up fine if i close up and restart so it just a problem downloading the files.
    NOTE: I did change background by dumping and repacking the files could this somehow cause them to not download properly mabye something to do with cache version??

    Many Thanks.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Dec 2016
    Posts
    2
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Without your CacheDownloader class being posted, there isn't much anyone can do to help you.
    Though, one solution would be cache packing your sprites.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Dec 2016
    Posts
    2
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    here is my cache downloader the 2 sprite files are in there to download so not sure

    I also connected my cache downloader to my localhost client on my pc so i could see any errors and i get xxx replied HTTP code:404
    which is the invalid link etc error code but i checked by navigating to them myself such as xxxxx.com/cashefiles and it will show them in the directory.


    Code:
    /**
     * Enchanced cache downloader
     * Handles cache downloading & unzipping
     * @author Gabriel Hannason
     */
    public class CacheDownloader {
    
    	public static void init() {
    		try {
    			for(CACHE_DOWNLOAD_FILES cacheFile : CACHE_DOWNLOAD_FILES.values()) {
    				boolean exists = new File(signlink.findcachedir() + cacheFile.identifier).exists();
    				if(!exists) {
    					int total = cacheFile.file.length;
    					int current = 1;
    					for(String file : cacheFile.file) {
    						downloadFile(cacheFile, file, current, total);
    						if(file.endsWith(".zip")) {
    							unzip(new File(signlink.findcachedir() + file));
    						}
    						current ++;
    					}
    					new File(signlink.findcachedir() + cacheFile.identifier).createNewFile();
    				}
    			}
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static void downloadFile(CACHE_DOWNLOAD_FILES cacheFile, String file, int current, int total) throws IOException {
    		String fileURL = "http://hydruxscape.com/client/cache/" + file;
    		String downloadingText = Client.optimizeText(cacheFile.toString().toLowerCase());
    		URL url = new URL(fileURL);
    		HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
    		httpConn.addRequestProperty("User-Agent", "Mozilla/4.76");
    		int responseCode = httpConn.getResponseCode();
    
    		// always check HTTP response code first
    		if (responseCode == HttpURLConnection.HTTP_OK) {
    			String fileName = "";
    			String disposition = httpConn.getHeaderField("Content-Disposition");
    
    			if (disposition != null) {
    				// extracts file name from header field
    				int index = disposition.indexOf("filename=");
    				if (index > 0) {
    					fileName = disposition.substring(index + 10,
    							disposition.length() - 1);
    				}
    			} else {
    				// extracts file name from URL
    				fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1,
    						fileURL.length());
    			}
    
    			// opens input stream from the HTTP connection
    			InputStream inputStream = httpConn.getInputStream();
    			String saveFilePath = signlink.findcachedir() + File.separator + fileName;
    
    			// opens an output stream to save into file
    			FileOutputStream outputStream = new FileOutputStream(saveFilePath);
    
    			int bytesRead = -1;
    			byte[] buffer = new byte[4096];
    			long startTime = System.currentTimeMillis();
    			int downloaded = 0;
    			long numWritten = 0;
    			int length = httpConn.getContentLength();
    			while ((bytesRead = inputStream.read(buffer)) != -1) {
    				outputStream.write(buffer, 0, bytesRead);
    				numWritten += bytesRead;
    				downloaded += bytesRead;
    				int percentage = (int)(((double)numWritten / (double)length) * 100D);
    				int downloadSpeed = (int) ((downloaded / 1024) / (1 + ((System.currentTimeMillis() - startTime) / 1000)));
    				String s = total > 1 ? "("+current+"/"+total+")" : "";
    				drawLoadingText(percentage, (new StringBuilder()).append("Downloading "+downloadingText+""+s+": "+percentage+"% ").append("@ "+downloadSpeed+"Kb/s").toString());
    			}
    
    			outputStream.close();
    			inputStream.close();
    
    		} else {
    			System.out.println("Hydrux Scape replied HTTP code: " + responseCode);
    		}
    		httpConn.disconnect();
    	}
    
    
    	private static void drawLoadingText(int amount, String text) {
    		Client.loadingPercentage = amount;
    		Client.loadingText = text;
    	}
    
    	private static void unzip(final File file) {
    		try {
    			InputStream in =  new BufferedInputStream(new FileInputStream(file));
    			ZipInputStream zin = new ZipInputStream(in);
    			ZipEntry e;
    			while((e=zin.getNextEntry()) != null) {
    				if(e.isDirectory()) {
    					(new File(signlink.findcachedir() + e.getName())).mkdir();
    				} else {
    					if (e.getName().equals(file.getName())) {
    						unzipPartlyArchive(zin, file.getName());
    						break;
    					}
    					unzipPartlyArchive(zin, signlink.findcachedir() + e.getName());
    				}
    			}
    			zin.close();
    			file.delete();
    		} catch(Exception e) {}
    	}
    
    	/**
    	 * Unzips a partly archive
    	 * @param zin	The zip inputstream
    	 * @param s		The location of the zip file
    	 * @throws IOException	The method can throw an IOException.
    	 */
    	private static void unzipPartlyArchive(ZipInputStream zin, String s) throws Exception {
    		FileOutputStream out = new FileOutputStream(s);
    		drawLoadingText(100, "Unpacking data..");
    		byte [] b = new byte[1024];
    		int len = 0;
    
    		while ((len = zin.read(b)) != -1) {
    			out.write(b,0,len);
    		}
    		out.close();
    	}
    
    	enum CACHE_DOWNLOAD_FILES {
    
    		IMAGES(new String[]{"sprites.idx", "sprites.dat", "icon.png"}, "cache1loaded"),
    		//CACHE(new String[]{"ruse.dat", "ruse.idx0", "ruse.idx1", "ruse.idx2", "ruse.idx3", "ruse.idx4", "ruse.idx5", "ruse.idx6"}, "cache2loaded"),
    		DATA(new String[]{"data.zip"}, "cache3loaded"),
    		;
    
    		CACHE_DOWNLOAD_FILES(String[] file, String identifier) {
    			this.file = file;
    			this.identifier = identifier;
    		}
    
    		private String[] file;
    		private String identifier;
    	}
    }
    Edit: you will notice the cache line with ruse 1-6 in it is marked out with // thats due to my update server downloading them files so that is not causing it.


    also below is a picture of it stuck loading and what downloads into my cache so you will see my sprites files sprites.dat and sprites.idx are missing..


    Last edited by evans95; 01-11-2017 at 12:22 AM.
    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. Auto Cache downloading problem
    By Affliction in forum Help
    Replies: 7
    Last Post: 05-01-2011, 05:41 AM
  2. Cache downloader problem [$15]
    By Nigboat in forum Help
    Replies: 0
    Last Post: 04-23-2011, 01:52 PM
  3. Cache downloader problem
    By Flux in forum Help
    Replies: 2
    Last Post: 02-16-2011, 08:59 PM
  4. cache downloading problem
    By thim slug in forum Help
    Replies: 2
    Last Post: 12-29-2010, 02:53 PM
  5. Cache Downloader Problem
    By Damien in forum Help
    Replies: 5
    Last Post: 04-18-2010, 12:48 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •