Add setting to set the base URL for MFC

This commit is contained in:
0xboobface 2018-12-02 22:35:12 +01:00
parent 353f3fb317
commit 6b4d320bc2
7 changed files with 38 additions and 16 deletions

View File

@ -26,6 +26,7 @@ public class MyFreeCamsConfigUI extends AbstractConfigUI {
GridPane layout = SettingsTab.createGridLayout();
layout.add(new Label("MyFreeCams User"), 0, 0);
TextField username = new TextField(Config.getInstance().getSettings().mfcUsername);
username.setPrefWidth(300);
username.textProperty().addListener((ob, o, n) -> {
Config.getInstance().getSettings().mfcUsername = username.getText();
save();
@ -47,13 +48,27 @@ public class MyFreeCamsConfigUI extends AbstractConfigUI {
GridPane.setColumnSpan(password, 2);
layout.add(password, 1, 1);
layout.add(new Label("MyFreeCams Base URL"), 0, 2);
TextField baseUrl = new TextField();
baseUrl.setText(Config.getInstance().getSettings().mfcBaseUrl);
baseUrl.textProperty().addListener((ob, o, n) -> {
Config.getInstance().getSettings().mfcBaseUrl = baseUrl.getText();
save();
});
GridPane.setFillWidth(baseUrl, true);
GridPane.setHgrow(baseUrl, Priority.ALWAYS);
GridPane.setColumnSpan(baseUrl, 2);
layout.add(baseUrl, 1, 2);
Button createAccount = new Button("Create new Account");
createAccount.setOnAction((e) -> DesktopIntegration.open(myFreeCams.getAffiliateLink()));
layout.add(createAccount, 1, 2);
layout.add(createAccount, 1, 3);
GridPane.setColumnSpan(createAccount, 2);
GridPane.setMargin(username, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
GridPane.setMargin(password, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
GridPane.setMargin(baseUrl, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
GridPane.setMargin(createAccount, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
return layout;
}
}

View File

@ -48,6 +48,7 @@ public class Settings {
public String bongaPassword = "";
public String mfcUsername = "";
public String mfcPassword = "";
public String mfcBaseUrl = "https://www.myfreecams.com";
public String camsodaUsername = "";
public String camsodaPassword = "";
public String cam4Username;

View File

@ -17,13 +17,14 @@ import okhttp3.Response;
public class MyFreeCams extends AbstractSite {
public static final String BASE_URI = "https://www.myfreecams.com";
static String baseUrl = "https://www.myfreecams.com";
private MyFreeCamsClient client;
private MyFreeCamsHttpClient httpClient;
@Override
public void init() throws IOException {
baseUrl = Config.getInstance().getSettings().mfcBaseUrl;
client = MyFreeCamsClient.getInstance();
client.setSite(this);
client.start();
@ -41,12 +42,12 @@ public class MyFreeCams extends AbstractSite {
@Override
public String getBaseUrl() {
return BASE_URI;
return baseUrl;
}
@Override
public String getAffiliateLink() {
return BASE_URI + "/?baf=8127165";
return baseUrl + "/?baf=8127165";
}
@Override
@ -59,7 +60,7 @@ public class MyFreeCams extends AbstractSite {
@Override
public Integer getTokenBalance() throws IOException {
Request req = new Request.Builder().url(BASE_URI + "/php/account.php?request=status").build();
Request req = new Request.Builder().url(baseUrl + "/php/account.php?request=status").build();
try(Response response = getHttpClient().execute(req)) {
if(response.isSuccessful()) {
String content = response.body().string();
@ -74,7 +75,7 @@ public class MyFreeCams extends AbstractSite {
@Override
public String getBuyTokensLink() {
return BASE_URI + "/php/purchase.php?request=tokens";
return baseUrl + "/php/purchase.php?request=tokens";
}
@Override

View File

@ -85,7 +85,7 @@ public class MyFreeCamsClient {
public void start() throws IOException {
running = true;
serverConfig = new ServerConfig(mfc.getHttpClient());
serverConfig = new ServerConfig(mfc);
List<String> websocketServers = new ArrayList<String>(serverConfig.wsServers.keySet());
String server = websocketServers.get((int) (Math.random()*websocketServers.size()));
String wsUrl = "ws://" + server + ".myfreecams.com:8080/fcsl";

View File

@ -53,8 +53,8 @@ public class MyFreeCamsHttpClient extends HttpClient {
.add("submit_login", "97")
.build();
Request req = new Request.Builder()
.url(MyFreeCams.BASE_URI + "/php/login.php")
.header("Referer", MyFreeCams.BASE_URI)
.url(MyFreeCams.baseUrl + "/php/login.php")
.header("Referer", MyFreeCams.baseUrl)
.header("Content-Type", "application/x-www-form-urlencoded")
.post(body)
.build();
@ -75,7 +75,7 @@ public class MyFreeCamsHttpClient extends HttpClient {
}
private boolean checkLogin() throws IOException {
Request req = new Request.Builder().url(MyFreeCams.BASE_URI + "/php/account.php?request=status").build();
Request req = new Request.Builder().url(MyFreeCams.baseUrl + "/php/account.php?request=status").build();
try(Response response = execute(req)) {
if(response.isSuccessful()) {
String content = response.body().string();
@ -99,7 +99,7 @@ public class MyFreeCamsHttpClient extends HttpClient {
public Cookie getCookie(String name) {
CookieJar jar = client.cookieJar();
HttpUrl url = HttpUrl.parse(MyFreeCams.BASE_URI);
HttpUrl url = HttpUrl.parse(MyFreeCams.baseUrl);
List<Cookie> cookies = jar.loadForRequest(url);
for (Cookie cookie : cookies) {
if(Objects.equals(cookie.name(), name)) {

View File

@ -132,7 +132,7 @@ public class MyFreeCamsModel extends AbstractModel {
@Override
public void receiveTip(int tokens) throws IOException {
String tipUrl = MyFreeCams.BASE_URI + "/php/tip.php";
String tipUrl = MyFreeCams.baseUrl + "/php/tip.php";
String initUrl = tipUrl + "?request=tip&username="+getName()+"&broadcaster_id="+getUid();
Request req = new Request.Builder().url(initUrl).build();
try(Response resp = site.getHttpClient().execute(req)) {

View File

@ -9,13 +9,16 @@ import java.util.Objects;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.io.HttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class ServerConfig {
private static final transient Logger LOG = LoggerFactory.getLogger(ServerConfig.class);
List<String> ajaxServers;
List<String> videoServers;
List<String> chatServers;
@ -24,9 +27,11 @@ public class ServerConfig {
Map<String, String> wzobsServers;
Map<String, String> ngVideoServers;
public ServerConfig(HttpClient client) throws IOException {
Request req = new Request.Builder().url("http://www.myfreecams.com/_js/serverconfig.js").build();
Response resp = client.execute(req);
public ServerConfig(MyFreeCams mfc) throws IOException {
String url = mfc.getBaseUrl() + "/_js/serverconfig.js";
LOG.debug("Loading server config from {}", url);
Request req = new Request.Builder().url(url).build();
Response resp = mfc.getHttpClient().execute(req);
String json = resp.body().string();
JSONObject serverConfig = new JSONObject(json);