r/programminghelp • u/asdf3-14159 • May 09 '21
Java Can someone who know's Java tell me what's going on here?
The java code:
protected void sendPulse(boolean on) {
if (mothershipDown && !on) {
log("Skipping pulse removal for " + getDisplayNick() + " (mothership down)");
return;
}
boolean down = true;
for (int i = 0; i < MOTHERSHIPS.length; i++) {
String mothership = MOTHERSHIPS[i];
try {
URL homeUrl = new URL(mothership + pulseWord + "," + pulseName + "-" + (on ? "1" : "0") + "-" + chatDab);
URLConnection conn = homeUrl.openConnection();
conn.setDoOutput(true);
Util.fillHeaders(conn, "json post");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write("");
wr.flush();
wr.close();
String line;
try (Scanner s = new Scanner(conn.getInputStream());) {
line = s.useDelimiter(Util.EOF).next();
}
String[] parts = line.split(", name: ");
if (parts.length > 1 && i == 0) {// choose which mothership's assignment is the chatname i == 0 or i == 1
callback("chatname", parts[1]);
}
log("Pulse for " + getDisplayNick() + " (front " + server + "): " + line + ", interests: " + getPulseWords());
down = false;
//mothershipDown = false;
} catch (Exception ex) {
log("Failed to send pulse for " + getDisplayNick() + " on " + mothership);
// mothershipDown = true;
if (verbose) {
ex.printStackTrace();
}
}
}
mothershipDown = down;
}where MOTHERSHIPS = a list of "https://bellawhiskey.ca/trollegle/" and "http://centimeters.herokuapp.com/trollegle/"
I know it makes some sort of a web request (maybe post). I plan on using "fetch" in JavaScript.
Even if you can't translate it to JavaScript, could you at least tell me what it is doing? Thanks!