ctbrec-5.3.2-experimental/common/src/main/java/ctbrec/sites/stripchat/StripchatUtil.java

59 lines
2.0 KiB
Java

package ctbrec.sites.stripchat;
// import ctbrec.sites.stripchat.Stripchat;
import java.text.MessageFormat;
import java.time.Instant;
import java.util.Random;
import org.json.JSONObject;
public class StripchatUtil {
private static final Random RNG = new Random();
private static final String HEX = "0123456789abcdef";
private static final String ALPHA = "0123456789abcdefghijklmnopqrstuvwxyz";
public static String getUniq() {
return StripchatUtil.randomString(16, ALPHA);
}
public static String randomString(int length, String dict) {
char[] text = new char[length];
for (int i = 0; i < length; ++i) {
text[i] = dict.charAt(RNG.nextInt(dict.length()));
}
return new String(text);
}
public static String getTabId() {
return StripchatUtil.randomString(60, HEX);
}
public static String hexString(int length) {
return StripchatUtil.randomString(length, HEX);
}
public static String alphaString(int length) {
return StripchatUtil.randomString(length, ALPHA);
}
public static String getEventId() {
return MessageFormat.format("{0}-{1}-{2}-{3}-{4}", StripchatUtil.hexString(8), StripchatUtil.hexString(4), StripchatUtil.hexString(4), StripchatUtil.hexString(4), StripchatUtil.hexString(12));
}
public static JSONObject getEventData() {
JSONObject data = new JSONObject();
data.put("ek.platformVersion", "10.92.4");
data.put("ek.tabId", StripchatUtil.getTabId());
data.put("ek.timestampCreated", Instant.now().getEpochSecond());
data.put("ek.deviceFlags", "2073600|10001110000001000");
data.put("ek.httpHost", Stripchat.domain);
data.put("ek.httpPath", "/");
data.put("ek.isDocumentHidden", 0);
data.put("ek.isTabFocused", 1);
data.put("ek.pageClass", "viewcam");
data.put("ek.contractVersion", "v0.2.1");
data.put("ek.eventId", StripchatUtil.getEventId());
return data;
}
}