diff --git a/JisolGameCocos/assets/script/App.ts b/JisolGameCocos/assets/script/App.ts index 5370f45a..bf7c4a99 100644 --- a/JisolGameCocos/assets/script/App.ts +++ b/JisolGameCocos/assets/script/App.ts @@ -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` diff --git a/JisolGameServer/Main/src/main/java/cn/jisol/game/actions/GRefereeAction.java b/JisolGameServer/Main/src/main/java/cn/jisol/game/actions/GRefereeAction.java index 36aa4751..819dfe7d 100644 --- a/JisolGameServer/Main/src/main/java/cn/jisol/game/actions/GRefereeAction.java +++ b/JisolGameServer/Main/src/main/java/cn/jisol/game/actions/GRefereeAction.java @@ -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 REFEREES; + //裁决员线程列表 + public static Map 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); } diff --git a/JisolGameServer/Main/src/test/java/TestMain.java b/JisolGameServer/Main/src/test/java/TestMain.java new file mode 100644 index 00000000..8c57adae --- /dev/null +++ b/JisolGameServer/Main/src/test/java/TestMain.java @@ -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(); + } + } +} diff --git a/headless/index.js b/headless/index.js index d8d07e34..a393e0c6 100644 --- a/headless/index.js +++ b/headless/index.js @@ -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')