Submit a web request

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 2 years ago
parent baf1916417
commit fe79eb6fc0
  1. BIN
      bin/readers/ITGReader.class
  2. BIN
      ding.wav
  3. BIN
      readers.zip
  4. BIN
      sigPlace.jar
  5. 43
      sigPlace.java
  6. 8
      sigServer.java

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -16,11 +16,18 @@ import java.util.Map;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import exceptions.FailedResponseException;
import java.awt.image.BufferedImage;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Robot;
import java.awt.GraphicsEnvironment;
import java.net.http.HttpResponse;
import readers.Box;
import readers.fonts.Font;
@ -95,6 +102,10 @@ public class sigPlace {
if (args.length>0&&args[0].equals("arcade")) {
try {
Robot r = new Robot();
Reader lastReader = null;
int matches=0;
final int EXPECTED_MATCHES=20;
boolean submitted=false;
while (true) {
BufferedImage screenshot = r.createScreenCapture(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
if (new Color(screenshot.getRGB(1550,604)).equals(SDVX_UI_COL)) {
@ -115,7 +126,22 @@ public class sigPlace {
ImageIO.write(screenshot,"png",temp.toFile());
result.interpretBoxes(temp, true);
if (result.isReasonableData()) {
System.out.println("Data is reasonable, prepare for submitting...");
if (lastReader!=null&&lastReader.equals(result)) {
matches++;
} else {
lastReader=result;
matches=0;
submitted=false;
}
if (matches>=EXPECTED_MATCHES&&!submitted) {
System.out.println("Data is reasonable, prepare for submitting...");
POSTRequest postRes = new POSTRequest("http://"+args[0]+"/uploadform.html",temp);
if (((HttpResponse<String>)postRes.run()).statusCode()==200) {
playSound(Paths.get("ding.wav"));
System.out.println("Successful!");
submitted=true;
}
}
}
/*if (result.isReasonableData()) {
POSTRequest postRes = new POSTRequest("http://"+args[0]+"/uploadform.html",Path.of("..",filename));
@ -123,7 +149,7 @@ public class sigPlace {
}
Thread.sleep(50);
}
} catch (AWTException | InterruptedException | IOException e) {
} catch (AWTException | InterruptedException | IOException | FailedResponseException e) {
e.printStackTrace();
}
} else {
@ -729,5 +755,16 @@ public class sigPlace {
e.printStackTrace();
}
}
}public static void playSound(Path file) {
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file.toFile());
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
// If you want the sound to loop infinitely, then put: clip.loop(Clip.LOOP_CONTINUOUSLY);
// If you want to stop the sound, then use clip.stop();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

@ -105,12 +105,14 @@ public class sigServer {
stream = new FileOutputStream(myFile);
char[] buffer = new char[1024];
int count;
boolean wroteData=false;
while ((count = in.read(buffer))>0) {
//stream.write(in.read(buffer));
//stream.write(buffer.,0,count);
String buf = new String(buffer);
byte[] data = buf.getBytes("ISO-8859-1");
stream.write(data,0,count);
wroteData=true;
if (buf.contains(boundary)) {
System.out.println("");
System.out.println("<...>");
@ -122,6 +124,12 @@ public class sigServer {
stream.close();
filename=null;
if (!wroteData) {
System.out.println("Upload failed!");
in.close();
CreateRequest(client,"400","Bad Request",Paths.get(sigPlace.OUTDIR,"testfile.html"));
return;
}
System.out.println("Saving upload to "+sigPlace.UPLOADSDIR+" directory.");
}
}

Loading…
Cancel
Save