Submit a web request
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
baf1916417
commit
fe79eb6fc0
Binary file not shown.
BIN
readers.zip
Normal file
BIN
readers.zip
Normal file
Binary file not shown.
BIN
sigPlace.jar
BIN
sigPlace.jar
Binary file not shown.
@ -16,11 +16,18 @@ import java.util.Map;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
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.image.BufferedImage;
|
||||||
import java.awt.AWTException;
|
import java.awt.AWTException;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Robot;
|
import java.awt.Robot;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
|
||||||
import readers.Box;
|
import readers.Box;
|
||||||
import readers.fonts.Font;
|
import readers.fonts.Font;
|
||||||
@ -95,6 +102,10 @@ public class sigPlace {
|
|||||||
if (args.length>0&&args[0].equals("arcade")) {
|
if (args.length>0&&args[0].equals("arcade")) {
|
||||||
try {
|
try {
|
||||||
Robot r = new Robot();
|
Robot r = new Robot();
|
||||||
|
Reader lastReader = null;
|
||||||
|
int matches=0;
|
||||||
|
final int EXPECTED_MATCHES=20;
|
||||||
|
boolean submitted=false;
|
||||||
while (true) {
|
while (true) {
|
||||||
BufferedImage screenshot = r.createScreenCapture(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
|
BufferedImage screenshot = r.createScreenCapture(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
|
||||||
if (new Color(screenshot.getRGB(1550,604)).equals(SDVX_UI_COL)) {
|
if (new Color(screenshot.getRGB(1550,604)).equals(SDVX_UI_COL)) {
|
||||||
@ -115,7 +126,22 @@ public class sigPlace {
|
|||||||
ImageIO.write(screenshot,"png",temp.toFile());
|
ImageIO.write(screenshot,"png",temp.toFile());
|
||||||
result.interpretBoxes(temp, true);
|
result.interpretBoxes(temp, true);
|
||||||
if (result.isReasonableData()) {
|
if (result.isReasonableData()) {
|
||||||
|
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...");
|
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()) {
|
/*if (result.isReasonableData()) {
|
||||||
POSTRequest postRes = new POSTRequest("http://"+args[0]+"/uploadform.html",Path.of("..",filename));
|
POSTRequest postRes = new POSTRequest("http://"+args[0]+"/uploadform.html",Path.of("..",filename));
|
||||||
@ -123,7 +149,7 @@ public class sigPlace {
|
|||||||
}
|
}
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
}
|
}
|
||||||
} catch (AWTException | InterruptedException | IOException e) {
|
} catch (AWTException | InterruptedException | IOException | FailedResponseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -729,5 +755,16 @@ public class sigPlace {
|
|||||||
e.printStackTrace();
|
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);
|
stream = new FileOutputStream(myFile);
|
||||||
char[] buffer = new char[1024];
|
char[] buffer = new char[1024];
|
||||||
int count;
|
int count;
|
||||||
|
boolean wroteData=false;
|
||||||
while ((count = in.read(buffer))>0) {
|
while ((count = in.read(buffer))>0) {
|
||||||
//stream.write(in.read(buffer));
|
//stream.write(in.read(buffer));
|
||||||
//stream.write(buffer.,0,count);
|
//stream.write(buffer.,0,count);
|
||||||
String buf = new String(buffer);
|
String buf = new String(buffer);
|
||||||
byte[] data = buf.getBytes("ISO-8859-1");
|
byte[] data = buf.getBytes("ISO-8859-1");
|
||||||
stream.write(data,0,count);
|
stream.write(data,0,count);
|
||||||
|
wroteData=true;
|
||||||
if (buf.contains(boundary)) {
|
if (buf.contains(boundary)) {
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
System.out.println("<...>");
|
System.out.println("<...>");
|
||||||
@ -122,6 +124,12 @@ public class sigServer {
|
|||||||
stream.close();
|
stream.close();
|
||||||
|
|
||||||
filename=null;
|
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.");
|
System.out.println("Saving upload to "+sigPlace.UPLOADSDIR+" directory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user