Skip to content

Commit

Permalink
v0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kloping committed Dec 6, 2021
1 parent bcdaf74 commit c8efa21
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
24 changes: 15 additions & 9 deletions src/main/java/com/hrs/kloping/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static com.hrs.kloping.Resource.*;

public class Client implements Runnable {
public static ExecutorService threads = Executors.newFixedThreadPool(10);

public static final String uuid = UUID.randomUUID().toString();
private static final String uuidW = "/?key=" + uuid;
public Socket socket;

public Client(Socket socket) {
Expand All @@ -36,13 +38,20 @@ private void start() throws Exception {
StringBuilder sb = new StringBuilder();
String line = null;
String[] sss = null;
boolean can = false;
while ((line = br.readLine()) != null) {
if (sss == null) sss = line.split("\\s+");
if (line.trim().isEmpty()) break;
sb.append(line).append("\n");
if (line.startsWith("cookie")) {
can = line.equals("cookie: key=" + uuid);
}
}
String url = sss[1];
if (url.startsWith("/modify")) {
if (url.equals(uuidW)) {
source("/index.html");
return;
} else if (can && url.startsWith("/modify")) {
url = url.substring("/modify?".length());
String[] ss = url.split("&");
Map<String, String> map = new HashMap<>();
Expand All @@ -54,7 +63,7 @@ private void start() throws Exception {
ok();
else data("error");
return;
} else if (url.startsWith("/search")) {
} else if (can && url.startsWith("/search")) {
url = url.substring("/search?".length());
String[] ss = url.split("&");
Map<String, String> map = new HashMap<>();
Expand All @@ -66,11 +75,6 @@ private void start() throws Exception {
return;
}
switch (url) {
case "/":
case "/index":
case "/index.html":
source("/index.html");
return;
case "/favicon.ico":
favicon();
return;
Expand Down Expand Up @@ -135,7 +139,9 @@ private void source(String name) throws Exception {
"content-type: " + type + "\n" +
"content-length: " + bytes.length + "\n" +
"keep-alive: timeout=60\n" +
"connection: keep-alive\n");
"connection: keep-alive");
if (name.equals("/index.html"))
pw.println("set-cookie: key=" + uuid + "\n");
pw.println();
pw.flush();
os.write(bytes);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/hrs/kloping/HPlugin_AutoReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public final class HPlugin_AutoReply extends JavaPlugin {
public static final HPlugin_AutoReply INSTANCE = new HPlugin_AutoReply();

private HPlugin_AutoReply() {
super(new JvmPluginDescriptionBuilder("com.hrs.kloping.h_plugin_AutoReply", "0.3")
.name("插件_3 Author => HRS")
super(new JvmPluginDescriptionBuilder("com.hrs.kloping.h_plugin_AutoReply", "0.3.1")
.name("自定义回话插件 Author => HRS")
.info("自定义回话插件")
.author("HRS")
.build());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/hrs/kloping/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static com.hrs.kloping.Client.uuid;
import static com.hrs.kloping.MyUtils.tempMap;
import static io.github.kloping.judge.Judge.isNotNull;

Expand Down Expand Up @@ -85,7 +86,7 @@ private static void startHtml() {
new Thread(() -> {
try {
serverSocket = new ServerSocket(conf.getPort());
System.out.println("AutoReply 服务启动成功 address: http://localhost:" + conf.getPort());
System.out.println("AutoReply 服务启动成功 address: http://localhost:" + conf.getPort() + "?key=" + uuid);
while (true)
new Client(serverSocket.accept());
} catch (Exception e) {
Expand Down

0 comments on commit c8efa21

Please sign in to comment.