From 4f0f332d475d152ae64c3693b7d0aa2cf77bfd93 Mon Sep 17 00:00:00 2001 From: "DESKTOP-5RP3AKU\\Jisol" <2858626794@qq.com> Date: Tue, 31 Oct 2023 00:44:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=96=B0=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 4 ++ JisolGameServer/JNGame | 1 + JisolGameServer/Main/pom.xml | 49 ++++++++++++++++ .../java/cn/jisol/game/JGameApplication.java | 12 ++++ .../java/cn/jisol/game/config/CorsConfig.java | 17 ++++++ .../jisol/game/controller/DemoController.java | 53 ++++++++++++++++++ .../game/listener/InitNGameListener.java | 15 +++++ .../jisol/game/network/NSocketConfigurer.java | 32 +++++++++++ .../java/cn/jisol/game/network/WebSocket.java | 41 ++++++++++++++ JisolGameServer/pom.xml | 38 +++++-------- src.rar | Bin 3186 -> 0 bytes 11 files changed, 237 insertions(+), 25 deletions(-) create mode 160000 JisolGameServer/JNGame create mode 100644 JisolGameServer/Main/pom.xml create mode 100644 JisolGameServer/Main/src/main/java/cn/jisol/game/JGameApplication.java create mode 100644 JisolGameServer/Main/src/main/java/cn/jisol/game/config/CorsConfig.java create mode 100644 JisolGameServer/Main/src/main/java/cn/jisol/game/controller/DemoController.java create mode 100644 JisolGameServer/Main/src/main/java/cn/jisol/game/listener/InitNGameListener.java create mode 100644 JisolGameServer/Main/src/main/java/cn/jisol/game/network/NSocketConfigurer.java create mode 100644 JisolGameServer/Main/src/main/java/cn/jisol/game/network/WebSocket.java delete mode 100644 src.rar diff --git a/.gitmodules b/.gitmodules index e0ae5901..bdeff238 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "JisolGameCocos/extensions/ngame"] path = JisolGameCocos/extensions/ngame url = https://gitee.com/jisol/jngame-pro-cocos +[submodule "JisolGameServer/JNGame"] + path = JisolGameServer/JNGame + url = https://gitee.com/jisol/jngame-pro-server + branch = master diff --git a/JisolGameServer/JNGame b/JisolGameServer/JNGame new file mode 160000 index 00000000..bce1ad35 --- /dev/null +++ b/JisolGameServer/JNGame @@ -0,0 +1 @@ +Subproject commit bce1ad3522fb8ed1497eee9e01bba38d53e97279 diff --git a/JisolGameServer/Main/pom.xml b/JisolGameServer/Main/pom.xml new file mode 100644 index 00000000..1cfaadf0 --- /dev/null +++ b/JisolGameServer/Main/pom.xml @@ -0,0 +1,49 @@ + + + + JisolGameServer + org.example + 1.0-SNAPSHOT + + 4.0.0 + + Main + + + 8 + 8 + + + + + cn.jisol + JNGame + 2.0-SNAPSHOT + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + cn.jisol.game.JGameApplication + ZIP + + + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/JisolGameServer/Main/src/main/java/cn/jisol/game/JGameApplication.java b/JisolGameServer/Main/src/main/java/cn/jisol/game/JGameApplication.java new file mode 100644 index 00000000..1f6f756f --- /dev/null +++ b/JisolGameServer/Main/src/main/java/cn/jisol/game/JGameApplication.java @@ -0,0 +1,12 @@ +package cn.jisol.game; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; + +@SpringBootApplication +public class JGameApplication { + public static void main(String[] args) { + ApplicationContext applicationContext = SpringApplication.run(JGameApplication.class); + } +} diff --git a/JisolGameServer/Main/src/main/java/cn/jisol/game/config/CorsConfig.java b/JisolGameServer/Main/src/main/java/cn/jisol/game/config/CorsConfig.java new file mode 100644 index 00000000..b52857f5 --- /dev/null +++ b/JisolGameServer/Main/src/main/java/cn/jisol/game/config/CorsConfig.java @@ -0,0 +1,17 @@ +package cn.jisol.game.config; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +class CorsConfig implements WebMvcConfigurer { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS") + .allowCredentials(true) + .maxAge(3600) + .allowedHeaders("*"); + } +} diff --git a/JisolGameServer/Main/src/main/java/cn/jisol/game/controller/DemoController.java b/JisolGameServer/Main/src/main/java/cn/jisol/game/controller/DemoController.java new file mode 100644 index 00000000..80f80ac6 --- /dev/null +++ b/JisolGameServer/Main/src/main/java/cn/jisol/game/controller/DemoController.java @@ -0,0 +1,53 @@ +package cn.jisol.game.controller; + + +import cn.jisol.ngame.actions.SystemAction; +import cn.jisol.ngame.proto.JNSyncMessage; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Objects; + +@Api(value = "JNGameDemo - API", tags = {"WorldCard - API"}) +@RestController +@RequestMapping() +@ResponseBody +public class DemoController { + + @ApiImplicitParams({ + @ApiImplicitParam(name="start",value="帧开始"), + @ApiImplicitParam(name="end",value="帧结束") + }) + @ApiOperation(value = "获取帧同步数据") + @GetMapping("/sync/frame") + public ResponseEntity getSyncFrame(Integer start, Integer end){ + + HttpHeaders headers = new HttpHeaders(); + headers.set("Content-Type", "application/json"); + + if(Objects.isNull(SystemAction.frame)) + return ResponseEntity.ok().headers(headers).body(new byte[0]); + + JNSyncMessage.JNFrameInfos infos = SystemAction.frame.vGetFrame(start, end); + return ResponseEntity.ok().headers(headers).body(infos.toByteArray()); + } + + @ApiImplicitParams({ + @ApiImplicitParam(name="start",value="帧开始"), + @ApiImplicitParam(name="end",value="帧结束") + }) + @ApiOperation(value = "获取帧同步数据") + @GetMapping("/sync/hello") + public String getSyncHello(Integer start, Integer end){ + return "HelloWorld"; + } + +} diff --git a/JisolGameServer/Main/src/main/java/cn/jisol/game/listener/InitNGameListener.java b/JisolGameServer/Main/src/main/java/cn/jisol/game/listener/InitNGameListener.java new file mode 100644 index 00000000..ba9b788e --- /dev/null +++ b/JisolGameServer/Main/src/main/java/cn/jisol/game/listener/InitNGameListener.java @@ -0,0 +1,15 @@ +package cn.jisol.game.listener; + +import cn.hutool.core.util.ClassUtil; +import cn.jisol.ngame.listener.InitNGameRPCListener; +import org.springframework.stereotype.Component; + +import java.util.Set; + +@Component +public class InitNGameListener extends InitNGameRPCListener { + @Override + public Set> getScanPackage() { + return ClassUtil.scanPackage("cn.jisol"); + } +} diff --git a/JisolGameServer/Main/src/main/java/cn/jisol/game/network/NSocketConfigurer.java b/JisolGameServer/Main/src/main/java/cn/jisol/game/network/NSocketConfigurer.java new file mode 100644 index 00000000..6717e22b --- /dev/null +++ b/JisolGameServer/Main/src/main/java/cn/jisol/game/network/NSocketConfigurer.java @@ -0,0 +1,32 @@ +package cn.jisol.game.network; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; +import org.springframework.web.socket.config.annotation.StompEndpointRegistry; +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +@Configuration +@EnableWebSocketMessageBroker +public class NSocketConfigurer implements WebSocketMessageBrokerConfigurer { + + /** + * 添加一个服务端点,来接收客户端的连接 + * @param registry + */ + @Override + public void registerStompEndpoints(StompEndpointRegistry registry) { + registry.addEndpoint("/websocket").setAllowedOrigins("*"); + } + + /** + * 开启WebSocket支持 + * @return + */ + @Bean + public ServerEndpointExporter serverEndpointExporter() { + return new ServerEndpointExporter(); + } + +} diff --git a/JisolGameServer/Main/src/main/java/cn/jisol/game/network/WebSocket.java b/JisolGameServer/Main/src/main/java/cn/jisol/game/network/WebSocket.java new file mode 100644 index 00000000..185cb626 --- /dev/null +++ b/JisolGameServer/Main/src/main/java/cn/jisol/game/network/WebSocket.java @@ -0,0 +1,41 @@ +package cn.jisol.game.network; + +import cn.jisol.ngame.client.NClient; +import cn.jisol.ngame.network.JNetwork; +import org.springframework.stereotype.Controller; + +import javax.websocket.OnClose; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; +import java.io.InputStream; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@ServerEndpoint( + value = "/websocket" +) +@Controller +public class WebSocket { + + public static final Map CLIENTS = new ConcurrentHashMap<>(); + + + @OnOpen + public void onOpen(Session session){ + CLIENTS.put(session.getId(),new NClient(session)); + System.out.printf("[WebSocket] %s 连接成功.\n",session.getId()); + } + + @OnMessage + public void onMessage(Session session, InputStream inputStream){ + JNetwork.onMessage(inputStream,CLIENTS.get(session.getId()),CLIENTS); + } + + @OnClose + public void onClose(Session session){ + CLIENTS.remove(session.getId()); + } + +} diff --git a/JisolGameServer/pom.xml b/JisolGameServer/pom.xml index 00136ddd..82b3947c 100644 --- a/JisolGameServer/pom.xml +++ b/JisolGameServer/pom.xml @@ -7,7 +7,19 @@ org.example JisolGameServer 1.0-SNAPSHOT - jar + + + org.springframework.boot + spring-boot-starter-parent + 2.3.5.RELEASE + + + + + Main + + pom + 8 @@ -16,30 +28,6 @@ - - cn.jisol - JNGame - 2.0-SNAPSHOT - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - - cn.jisol.game.JGameApplication - - - - jar-with-dependencies - - - - - - \ No newline at end of file diff --git a/src.rar b/src.rar deleted file mode 100644 index 32828fc19bd3451031d596c7bc7a8b7991d9bdf6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3186 zcmai0c{EfH1D!E541*A3&yp?MU?{unOQA9**`hJ_W*F;8nJD`;Gr1&ut71_S&>*qW9o$u89=e>8%z4x5=?tS;&Q?3Lt0VW_|Wjb;J281vH7=b_% zi3CtOd3ex@0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