mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 00:38:16 +00:00
Login post added
This commit is contained in:
@@ -7,9 +7,11 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.parabot.core.io.ProgressListener;
|
||||
import org.parabot.core.io.SizeInputStream;
|
||||
@@ -153,6 +155,46 @@ public class WebUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BufferedReader getReader(final URL url, String username, String password) {
|
||||
try {
|
||||
String data = URLEncoder.encode("username", "UTF-8") + "=" + username;
|
||||
data += "&" + URLEncoder.encode("password", "UTF-8") + "=" + password;
|
||||
|
||||
URLConnection connection = url.openConnection();
|
||||
|
||||
connection.setDoOutput(true);
|
||||
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
|
||||
wr.write(data);
|
||||
wr.flush();
|
||||
wr.close();
|
||||
|
||||
return new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static URLConnection getConnection(final URL url, String username, String password) {
|
||||
try {
|
||||
String data = URLEncoder.encode("username", "UTF-8") + "=" + username;
|
||||
data += "&" + URLEncoder.encode("password", "UTF-8") + "=" + password;
|
||||
|
||||
URLConnection connection = url.openConnection();
|
||||
|
||||
connection.setDoOutput(true);
|
||||
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
|
||||
wr.write(data);
|
||||
wr.flush();
|
||||
wr.close();
|
||||
|
||||
return connection;
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads a file on the internet
|
||||
@@ -186,6 +228,38 @@ public class WebUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads a file on the internet
|
||||
* @param url
|
||||
* @param destination
|
||||
* @param listener
|
||||
*/
|
||||
public static void downloadFile(final URL url, final File destination,
|
||||
final ProgressListener listener, String username, String password) {
|
||||
try {
|
||||
final URLConnection connection = getConnection(url, username, password);
|
||||
int size = connection.getContentLength();
|
||||
SizeInputStream sizeInputStream = new SizeInputStream(
|
||||
connection.getInputStream(), size, listener);
|
||||
BufferedInputStream in = new BufferedInputStream(sizeInputStream);
|
||||
FileOutputStream fileOut = new FileOutputStream(destination);
|
||||
try {
|
||||
byte data[] = new byte[1024];
|
||||
int count;
|
||||
while ((count = in.read(data, 0, 1024)) != -1) {
|
||||
fileOut.write(data, 0, count);
|
||||
}
|
||||
} finally {
|
||||
if (in != null)
|
||||
in.close();
|
||||
if (fileOut != null)
|
||||
fileOut.close();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts file format to url format
|
||||
* @param file
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.core.desc.ServerProviderInfo;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
@@ -28,6 +30,17 @@ import java.net.URL;
|
||||
public class PublicServerExecuter extends ServerExecuter {
|
||||
private String serverName;
|
||||
private String serverID;
|
||||
|
||||
private static AccountManager manager;
|
||||
|
||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||
|
||||
@Override
|
||||
public final void setManager(AccountManager manager) {
|
||||
PublicServerExecuter.manager = manager;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public PublicServerExecuter(final String serverName, final String serverID) {
|
||||
this.serverName = serverName;
|
||||
@@ -48,7 +61,7 @@ public class PublicServerExecuter extends ServerExecuter {
|
||||
}
|
||||
|
||||
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(new URL(Configuration.GET_SERVER_PROVIDER_INFO
|
||||
+ this.serverID));
|
||||
+ this.serverID), manager.getAccount().getUsername(), manager.getAccount().getPassword());
|
||||
|
||||
final File destination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getCRC32() + ".jar");
|
||||
@@ -62,7 +75,7 @@ public class PublicServerExecuter extends ServerExecuter {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
} else {
|
||||
WebUtil.downloadFile(new URL(jarUrl), destination,
|
||||
VerboseLoader.get());
|
||||
VerboseLoader.get(), manager.getAccount().getUsername(), manager.getAccount().getPassword());
|
||||
Core.verbose("Server provider downloaded...");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user