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.
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;
}