无头模式 裁决

This commit is contained in:
DESKTOP-5RP3AKU\Jisol 2023-11-23 01:23:49 +08:00
parent f890be0728
commit e3781116dc
4 changed files with 76 additions and 5 deletions

View File

@ -26,12 +26,12 @@ import { JAPI, JAPIConfig } from "../../extensions/ngame/assets/ngame/util/JAPI"
import { AppData } from "./AppData";
import AppAction from "./AppAction";
// let APIPath = `http://localhost:8080`
// let WsPath = `ws://localhost:8080/websocket`
let APIPath = `http://localhost:8080`
let WsPath = `ws://localhost:8080/websocket`
// let APIPath = `http://192.168.1.23:8080`
// let WsPath = `ws://192.168.1.23:8080/websocket`
let APIPath = `http://192.168.0.123:8080`
let WsPath = `ws://192.168.0.123:8080/websocket`
// let APIPath = `http://192.168.0.123:8080`
// let WsPath = `ws://192.168.0.123:8080/websocket`
// let APIPath = `https://api.pet.jisol.cn`
// let WsPath = `wss://api.pet.jisol.cn/websocket`

View File

@ -1,12 +1,20 @@
package cn.jisol.game.actions;
import cn.hutool.core.util.IdUtil;
import cn.hutool.log.LogFactory;
import cn.jisol.game.network.client.GRefereeClient;
import cn.jisol.game.proto.GPVPMessage;
import cn.jisol.ngame.actions.core.NAction;
import cn.jisol.ngame.actions.core.NActionMethod;
import cn.jisol.ngame.util.JLoggerUtil;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* 裁决员行为 处理裁决
@ -17,6 +25,12 @@ public class GRefereeAction {
//裁决员列表
public static Map<String, GRefereeClient> REFEREES;
//裁决员线程列表
public static Map<String,Thread> THREADS = new HashMap<>();
//最大裁决员数量
public static int MAX = 10;
//获取一个空闲的裁决员
public static GRefereeClient getFreeReferee(){
@ -26,6 +40,10 @@ public class GRefereeAction {
return REFEREES.get(key);
}
}
//如果没有空闲的裁决客户端则添加
addRefereeClient();
return null;
}
@ -50,6 +68,40 @@ public class GRefereeAction {
return false;
}
//添加裁判客户端
public static void addRefereeClient(){
//生成客户端Id
String uuid = IdUtil.simpleUUID();
//创建日志类
Logger log = JLoggerUtil.file(uuid, "D:\\Jisol\\JisolGame\\headless\\logger", uuid + ".log");
if(Objects.isNull(log)) return;
Thread thread = new Thread(() -> {
try {
Process process = Runtime.getRuntime().exec("cmd /c npm run main", null, new File("D:\\Jisol\\JisolGame\\headless"));
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String content = br.readLine();
while (content != null) {
log.log(Level.ALL, content);
content = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
});
thread.start();
//保存线程
THREADS.put(uuid,thread);
}
public interface GRefereeActionAutoInter{
GRefereeClient run(GRefereeClient referee);
}

View File

@ -0,0 +1,19 @@
import java.io.*;
public class TestMain {
public static void main(String[] args) {
try {
Process process = Runtime.getRuntime().exec("cmd /c npm run main",null,new File("D:\\Jisol\\JisolGame\\headless"));
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String content = br.readLine();
while (content != null) {
System.out.println(content);
content = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,7 +1,7 @@
// const URL = "http://192.168.0.174:7457/web-desktop/web-desktop/index.html"
// const express = require("express");
// const app = express();
const URL = "http://192.168.0.123:7457/web-desktop/web-desktop/index.html"
const URL = "http://192.168.1.23:7456/web-desktop/web-desktop-001/index.html"
// const runCocos = () => {
const { JSDOM,ResourceLoader } = require('jsdom')