Restore old sigPlace server code

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent f76910c093
commit 71c522b26b
  1. BIN
      bin/sigPlace.class
  2. BIN
      bin/sigServer.class
  3. BIN
      sigPlace.jar
  4. 434
      sigPlace.java

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -154,7 +154,7 @@ public class sigPlace {
} }
} else { } else {
populateDatabase(); populateDatabase();
/*String fontName = "sdvx_EXScore"; /*String fontName = "sdvx_EXScore";
String value = "00457"; String value = "00457";
Path f = Paths.get("tests","sdvx8.png"); Path f = Paths.get("tests","sdvx8.png");
BufferedImage img; BufferedImage img;
@ -198,7 +198,7 @@ public class sigPlace {
ArcadeReader.submitToDatabase(Paths.get("tests","sdvx4.png"));*/ ArcadeReader.submitToDatabase(Paths.get("tests","sdvx4.png"));*/
//System.out.println(RECENT_PLAYS); //System.out.println(RECENT_PLAYS);
//System.out.println(RECENT_RECORDS); //System.out.println(RECENT_RECORDS);
/* Path secretFile = Paths.get(".clientsecret"); Path secretFile = Paths.get(".clientsecret");
List<String> data; List<String> data;
try { try {
data = Files.readAllLines(secretFile); data = Files.readAllLines(secretFile);
@ -256,255 +256,255 @@ public class sigPlace {
System.out.println("\nStarting web server..."); System.out.println("\nStarting web server...");
new sigServer(); new sigServer();
} }
}
private static String JSON(HashMap<String, Object> testMap) { private static String JSON(HashMap<String, Object> testMap) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String temp = testMap.toString(); String temp = testMap.toString();
if (temp.charAt(0)=='{') { if (temp.charAt(0)=='{') {
sb.append("{"); sb.append("{");
int marker=1; int marker=1;
boolean ending=false; boolean ending=false;
while (marker<temp.length()) { while (marker<temp.length()) {
if (!ending&&temp.charAt(marker)!=' '&&temp.charAt(marker)!='{'&&temp.charAt(marker)!='}'&&temp.charAt(marker)!=',') { if (!ending&&temp.charAt(marker)!=' '&&temp.charAt(marker)!='{'&&temp.charAt(marker)!='}'&&temp.charAt(marker)!=',') {
ending=true; ending=true;
sb.append("\""); sb.append("\"");
} else } else
if (ending&&(temp.charAt(marker)=='='||temp.charAt(marker)==','||temp.charAt(marker)=='}')) { if (ending&&(temp.charAt(marker)=='='||temp.charAt(marker)==','||temp.charAt(marker)=='}')) {
ending=false; ending=false;
sb.append("\""); sb.append("\"");
}
if (!ending&&temp.charAt(marker)=='=') {
sb.append(':');
} else {
sb.append(temp.charAt(marker));
}
marker++;
} }
} else { if (!ending&&temp.charAt(marker)=='=') {
throw new UnsupportedOperationException("Not valid JSON!"); sb.append(':');
} else {
sb.append(temp.charAt(marker));
}
marker++;
} }
return sb.toString(); } else {
throw new UnsupportedOperationException("Not valid JSON!");
} }
private static void ParseArticleFiles(Iterator<Path> items) { return sb.toString();
while (items.hasNext()) { }
Path f = items.next(); private static void ParseArticleFiles(Iterator<Path> items) {
System.out.println(" Found "+f.getFileName()); while (items.hasNext()) {
if (Files.isRegularFile(f)) { Path f = items.next();
try { System.out.println(" Found "+f.getFileName());
if (Files.isRegularFile(f)) {
try {
System.out.println(" Preparing "+f.getFileName()); System.out.println(" Preparing "+f.getFileName());
List<String> content = Files.readAllLines(f); List<String> content = Files.readAllLines(f);
if (isHTMLFile(f)) { if (isHTMLFile(f)) {
content.addAll(0,Files.readAllLines(ops.get("%NAVBAR"))); content.addAll(0,Files.readAllLines(ops.get("%NAVBAR")));
content.addAll(0,Files.readAllLines(ops.get("%DEFAULT"))); content.addAll(0,Files.readAllLines(ops.get("%DEFAULT")));
content.addAll(Files.readAllLines(ops.get("%FOOTER"))); content.addAll(Files.readAllLines(ops.get("%FOOTER")));
} }
System.out.println(" Parsing "+f.getFileName()); System.out.println(" Parsing "+f.getFileName());
for (int i=0;i<content.size();i++) { for (int i=0;i<content.size();i++) {
String s = content.get(i); String s = content.get(i);
boolean endPreLine=false; boolean endPreLine=false;
//System.out.println(s); //System.out.println(s);
if (s.length()>0&&(isHTMLFile(f)||isArticleFile(f))) { if (s.length()>0&&(isHTMLFile(f)||isArticleFile(f))) {
if (!inCodeBlock) { if (!inCodeBlock) {
if (s.trim().equals("<pre>")) { if (s.trim().equals("<pre>")) {
//System.out.println("Inside <pre>"); //System.out.println("Inside <pre>");
inCodeBlock=true; inCodeBlock=true;
storedCodeBlock=""; storedCodeBlock="";
s=s.substring(0,s.indexOf("<pre>")); s=s.substring(0,s.indexOf("<pre>"));
}
} }
if (inCodeBlock&&s.trim().equals("</pre>")) { }
inCodeBlock=false; if (inCodeBlock&&s.trim().equals("</pre>")) {
boolean keyword=false; inCodeBlock=false;
boolean inString=false; boolean keyword=false;
boolean inComment=false; boolean inString=false;
boolean inMultiLineComment=false; boolean inComment=false;
char stringChar=' '; boolean inMultiLineComment=false;
boolean canBeNumericalConstant=false; char stringChar=' ';
int lengthOfConstant=0; boolean canBeNumericalConstant=false;
storedCodeBlock+=s.substring(0,s.indexOf("</pre>")); int lengthOfConstant=0;
storedCodeBlock=storedCodeBlock.replaceAll(Pattern.quote("<"),"\2"); storedCodeBlock+=s.substring(0,s.indexOf("</pre>"));
storedCodeBlock+="</pre>"; storedCodeBlock=storedCodeBlock.replaceAll(Pattern.quote("<"),"\2");
int startPos=0; storedCodeBlock+="</pre>";
String endText=s.substring(s.indexOf("</pre>")+"</pre>".length(),s.length()); int startPos=0;
s=""; String endText=s.substring(s.indexOf("</pre>")+"</pre>".length(),s.length());
for (int j=0;j<storedCodeBlock.length();j++) { s="";
if (storedCodeBlock.charAt(j)=='\n'&&inString) { for (int j=0;j<storedCodeBlock.length();j++) {
inString=false; if (storedCodeBlock.charAt(j)=='\n'&&inString) {
inString=false;
s+="</span>";
} else
if (storedCodeBlock.charAt(j)=='\n'&&inComment) {
inComment=false;
s+=SPAN("comment")+storedCodeBlock.substring(startPos,j)+"</span>";
startPos=j+1;
}
if (!inComment&&!inMultiLineComment&&(j>0&&storedCodeBlock.charAt(j-1)!='\\'&&(!inString&&(storedCodeBlock.charAt(j)=='"'||storedCodeBlock.charAt(j)=='\'')||inString&&(storedCodeBlock.charAt(j)==stringChar)))) {
inString=!inString;
if (inString) {
stringChar=storedCodeBlock.charAt(j);
s+=SPAN("string")+stringChar;
} else {
s+=stringChar;
s+="</span>"; s+="</span>";
} else
if (storedCodeBlock.charAt(j)=='\n'&&inComment) {
inComment=false;
s+=SPAN("comment")+storedCodeBlock.substring(startPos,j)+"</span>";
startPos=j+1; startPos=j+1;
} }
if (!inComment&&!inMultiLineComment&&(j>0&&storedCodeBlock.charAt(j-1)!='\\'&&(!inString&&(storedCodeBlock.charAt(j)=='"'||storedCodeBlock.charAt(j)=='\'')||inString&&(storedCodeBlock.charAt(j)==stringChar)))) { } else
inString=!inString; if (!inString) {
if (inString) { if (canBeNumericalConstant&&validNumericalConstantCharacters(lengthOfConstant, j)) {
stringChar=storedCodeBlock.charAt(j); lengthOfConstant++;
s+=SPAN("string")+stringChar; //System.out.println("Length of Constant now "+lengthOfConstant);
}
if (j>0&&storedCodeBlock.charAt(j)=='/'&&storedCodeBlock.charAt(j+1)=='*'||inMultiLineComment) {
if (!inMultiLineComment) {
inMultiLineComment=true;
} else { } else {
s+=stringChar; if (storedCodeBlock.charAt(j-1)=='*'&&storedCodeBlock.charAt(j)=='/') {
s+="</span>"; inMultiLineComment=false;
startPos=j+1; s+=SPAN("comment")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+"</span>";
startPos=j+1;
}
} }
//Stops further execution since we're in a comment.
} else } else
if (!inString) { if (j>0&&storedCodeBlock.charAt(j)=='/'&&storedCodeBlock.charAt(j+1)=='/'||inComment) {
if (canBeNumericalConstant&&validNumericalConstantCharacters(lengthOfConstant, j)) { if (!inComment) {
lengthOfConstant++; inComment=true;
//System.out.println("Length of Constant now "+lengthOfConstant);
} }
if (j>0&&storedCodeBlock.charAt(j)=='/'&&storedCodeBlock.charAt(j+1)=='*'||inMultiLineComment) { //Stops further execution since we're in a comment.
if (!inMultiLineComment) { } else
inMultiLineComment=true; if (canBeNumericalConstant&&lengthOfConstant>0&&!(validNumericalConstantCharacters(lengthOfConstant, j))) {
} else { s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j);
if (storedCodeBlock.charAt(j-1)=='*'&&storedCodeBlock.charAt(j)=='/') { //System.out.println("Setting "+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j));
inMultiLineComment=false; lengthOfConstant=0;
s+=SPAN("comment")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+"</span>"; canBeNumericalConstant=false;
startPos=j+1; startPos=j+1;
} } else
} if (!canBeNumericalConstant&&storedCodeBlock.charAt(j)=='.') {
//Stops further execution since we're in a comment. //Previous section was a member.
} else s+=SPAN("class")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j);
if (j>0&&storedCodeBlock.charAt(j)=='/'&&storedCodeBlock.charAt(j+1)=='/'||inComment) { startPos=j+1;
if (!inComment) { } else
inComment=true; if (j>3&&storedCodeBlock.substring(j-3,j+1).equals("true")&&!isAlphanumeric(j-4)&&!isAlphanumeric(j+1)) {
} s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+"</span>";
//Stops further execution since we're in a comment. startPos=j+1;
} else } else
if (canBeNumericalConstant&&lengthOfConstant>0&&!(validNumericalConstantCharacters(lengthOfConstant, j))) { if (j>4&&storedCodeBlock.substring(j-4,j+1).equals("false")&&!isAlphanumeric(j-5)&&!isAlphanumeric(j+1)) {
s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j); s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+"</span>";
//System.out.println("Setting "+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)); startPos=j+1;
lengthOfConstant=0; } else
canBeNumericalConstant=false; if (storedCodeBlock.charAt(j)=='(') {
startPos=j+1; s+=SPAN("function")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j);
} else startPos=j+1;
if (!canBeNumericalConstant&&storedCodeBlock.charAt(j)=='.') { } else
//Previous section was a member. if (j>0&&isAlphanumeric(j-1) && storedCodeBlock.charAt(j)==' '&&storedCodeBlock.charAt(j-1)!=' ') {
s+=SPAN("class")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j); //Previous section was a keyword.
startPos=j+1; keyword=true;
} else s+=SPAN("keyword")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j);
if (j>3&&storedCodeBlock.substring(j-3,j+1).equals("true")&&!isAlphanumeric(j-4)&&!isAlphanumeric(j+1)) { startPos=j+1;
s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+"</span>"; } else
startPos=j+1; if (j>0&&isAlphanumeric(j-1) && (storedCodeBlock.charAt(j)==';'||storedCodeBlock.charAt(j)==':')) {
} else //Previous section was a keyword.
if (j>4&&storedCodeBlock.substring(j-4,j+1).equals("false")&&!isAlphanumeric(j-5)&&!isAlphanumeric(j+1)) { //keyword=true;
s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+"</span>"; s+=SPAN("keyword")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j);
startPos=j+1; startPos=j+1;
} else } else
if (storedCodeBlock.charAt(j)=='(') { if (keyword&&!(storedCodeBlock.charAt(j)=='_'||storedCodeBlock.charAt(j)>='0'&&storedCodeBlock.charAt(j)<='9'||storedCodeBlock.charAt(j)>='A'&&storedCodeBlock.charAt(j)<='Z'||storedCodeBlock.charAt(j)>='a'&&storedCodeBlock.charAt(j)<='z'||storedCodeBlock.charAt(j)==' ')) {
s+=SPAN("function")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j); keyword=false;
startPos=j+1; s+=SPAN("variable")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j);
} else startPos=j+1;
if (j>0&&isAlphanumeric(j-1) && storedCodeBlock.charAt(j)==' '&&storedCodeBlock.charAt(j-1)!=' ') { } else
//Previous section was a keyword. if (!isAlphanumeric(j)){
keyword=true; if (startPos<j) {
s+=SPAN("keyword")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j); s+=storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j);
startPos=j+1; } else {
} else s+=storedCodeBlock.charAt(j);
if (j>0&&isAlphanumeric(j-1) && (storedCodeBlock.charAt(j)==';'||storedCodeBlock.charAt(j)==':')) {
//Previous section was a keyword.
//keyword=true;
s+=SPAN("keyword")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j);
startPos=j+1;
} else
if (keyword&&!(storedCodeBlock.charAt(j)=='_'||storedCodeBlock.charAt(j)>='0'&&storedCodeBlock.charAt(j)<='9'||storedCodeBlock.charAt(j)>='A'&&storedCodeBlock.charAt(j)<='Z'||storedCodeBlock.charAt(j)>='a'&&storedCodeBlock.charAt(j)<='z'||storedCodeBlock.charAt(j)==' ')) {
keyword=false;
s+=SPAN("variable")+storedCodeBlock.substring(startPos,j)+"</span>"+storedCodeBlock.charAt(j);
startPos=j+1;
} else
if (!isAlphanumeric(j)){
if (startPos<j) {
s+=storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j);
} else {
s+=storedCodeBlock.charAt(j);
}
startPos=j+1;
} }
} else {
s+=storedCodeBlock.charAt(j);
startPos=j+1; startPos=j+1;
} }
if (canBeNumericalConstant&&lengthOfConstant==0&&!(storedCodeBlock.charAt(j)>='0'&&storedCodeBlock.charAt(j)<='9')) { } else {
canBeNumericalConstant=false; s+=storedCodeBlock.charAt(j);
} startPos=j+1;
if (!canBeNumericalConstant&&!isAlphanumeric(j)) {
canBeNumericalConstant=true;
lengthOfConstant=0;
//System.out.println("Found "+storedCodeBlock.charAt(j)+", can be numeric...");
}
} }
for (int j=0;j<s.length();j++) { if (canBeNumericalConstant&&lengthOfConstant==0&&!(storedCodeBlock.charAt(j)>='0'&&storedCodeBlock.charAt(j)<='9')) {
if (s.charAt(j)=='\2') { canBeNumericalConstant=false;
s=s.substring(0,j)+"&lt;"+s.substring(j+1,s.length());
}
} }
s="<pre>"+s; if (!canBeNumericalConstant&&!isAlphanumeric(j)) {
s+=endText; canBeNumericalConstant=true;
endPreLine=true; lengthOfConstant=0;
//System.out.println("Stored code block: "+storedCodeBlock); //System.out.println("Found "+storedCodeBlock.charAt(j)+", can be numeric...");
} else
if (inCodeBlock) {
storedCodeBlock+=s+"\n";
s=" ";
}
}
if (s.length()>0&&isArticleFile(f)&&!inCodeBlock) {
//Check for markdown pieces.
if (s.charAt(0)=='-') {
//Start of a title piece.
s=s.replace("-",map.get("$TITLE_CONTENT_START"));
s=s+map.get("$TITLE_CONTENT_END").replace("%ID%","id=\"content_"+f+"\"");
//Use ⤈ if there's more text to be shown than can fit.
} else
if (s.startsWith("===")) {
s=map.get("$CONTENT_END")+map.get("$DATE_CONTENT_START")+s.replace("===","")+map.get("$CONTENT_END")+"%CONDITIONAL_EXPAND%"+map.get("$CONTENT_END");
} else
if (s.charAt(0)==':') {
//Image with caption.
//Format:
//:<url>,<left|right|center>,<width>,<caption>
String[] splitter = s.split(Pattern.quote(","));
StringBuilder captionText = new StringBuilder(splitter[3]);
for (int j=4;j<splitter.length;j++) {
captionText.append(",").append(splitter[j]);
} }
s="<div><figure style=\"text-align:center;"+((splitter[1].equals("left")||splitter[1].equals("right"))?"width:"+splitter[2]+"%;float:"+splitter[1]+";":"")+"\"><img src=\"/"+splitter[0].substring(1)+"\" style=\"margin:auto;width:100%;\"><figcaption>"+captionText.toString()+"</figcaption></figure></div>";
} else {
//It's regular content, so add paragraphs.
s="<p class=\"color"+(((int)(COLOR_ROTATION=(COLOR_ROTATION+0.4)%6))+1)+"\">\n"+s+"\n</p>";
} }
} else { for (int j=0;j<s.length();j++) {
if (s.length()==0&&isArticleFile(f)&&!inCodeBlock) { if (s.charAt(j)=='\2') {
s="<br/>"; //Setup a line break here. s=s.substring(0,j)+"&lt;"+s.substring(j+1,s.length());
}
} }
s="<pre>"+s;
s+=endText;
endPreLine=true;
//System.out.println("Stored code block: "+storedCodeBlock);
} else
if (inCodeBlock) {
storedCodeBlock+=s+"\n";
s=" ";
} }
if (!endPreLine) { }
for (String key : map.keySet()) { if (s.length()>0&&isArticleFile(f)&&!inCodeBlock) {
s=s.replaceAll(Pattern.quote(key),map.get(key)); //Check for markdown pieces.
if (s.charAt(0)=='-') {
//Start of a title piece.
s=s.replace("-",map.get("$TITLE_CONTENT_START"));
s=s+map.get("$TITLE_CONTENT_END").replace("%ID%","id=\"content_"+f+"\"");
//Use ⤈ if there's more text to be shown than can fit.
} else
if (s.startsWith("===")) {
s=map.get("$CONTENT_END")+map.get("$DATE_CONTENT_START")+s.replace("===","")+map.get("$CONTENT_END")+"%CONDITIONAL_EXPAND%"+map.get("$CONTENT_END");
} else
if (s.charAt(0)==':') {
//Image with caption.
//Format:
//:<url>,<left|right|center>,<width>,<caption>
String[] splitter = s.split(Pattern.quote(","));
StringBuilder captionText = new StringBuilder(splitter[3]);
for (int j=4;j<splitter.length;j++) {
captionText.append(",").append(splitter[j]);
} }
} s="<div><figure style=\"text-align:center;"+((splitter[1].equals("left")||splitter[1].equals("right"))?"width:"+splitter[2]+"%;float:"+splitter[1]+";":"")+"\"><img src=\"/"+splitter[0].substring(1)+"\" style=\"margin:auto;width:100%;\"><figcaption>"+captionText.toString()+"</figcaption></figure></div>";
if (s.trim().length()==0) {
content.remove(i--);
} else { } else {
content.set(i,s); //It's regular content, so add paragraphs.
s="<p class=\"color"+(((int)(COLOR_ROTATION=(COLOR_ROTATION+0.4)%6))+1)+"\">\n"+s+"\n</p>";
}
} else {
if (s.length()==0&&isArticleFile(f)&&!inCodeBlock) {
s="<br/>"; //Setup a line break here.
} }
} }
if (!endPreLine) {
for (String key : map.keySet()) {
s=s.replaceAll(Pattern.quote(key),map.get(key));
}
}
if (s.trim().length()==0) {
content.remove(i--);
} else {
content.set(i,s);
}
}
System.out.println(" Writing to "+f.toAbsolutePath()); System.out.println(" Writing to "+f.toAbsolutePath());
Files.write(f, content, Charset.defaultCharset(),StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING,StandardOpenOption.WRITE); Files.write(f, content, Charset.defaultCharset(),StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING,StandardOpenOption.WRITE);
System.out.println(" "+f.getFileName() + " conversion complete!"); System.out.println(" "+f.getFileName() + " conversion complete!");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
}
} }
} */ }
} }
} }
private static void populateDatabase() { private static void populateDatabase() {

Loading…
Cancel
Save