mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-25 10:54:43 +00:00
提交新架构
This commit is contained in:
parent
c4e8237d02
commit
4f0f332d47
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -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
|
||||
|
1
JisolGameServer/JNGame
Submodule
1
JisolGameServer/JNGame
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit bce1ad3522fb8ed1497eee9e01bba38d53e97279
|
49
JisolGameServer/Main/pom.xml
Normal file
49
JisolGameServer/Main/pom.xml
Normal file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>JisolGameServer</artifactId>
|
||||
<groupId>org.example</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>Main</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.jisol</groupId>
|
||||
<artifactId>JNGame</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- 指定该Main Class为全局的唯一入口 -->
|
||||
<mainClass>cn.jisol.game.JGameApplication</mainClass>
|
||||
<layout>ZIP</layout>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<!--可以把依赖的包都打包到生成的Jar包中-->
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -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);
|
||||
}
|
||||
}
|
@ -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("*");
|
||||
}
|
||||
}
|
@ -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<byte[]> 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";
|
||||
}
|
||||
|
||||
}
|
@ -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<Class<?>> getScanPackage() {
|
||||
return ClassUtil.scanPackage("cn.jisol");
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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<String, NClient> 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());
|
||||
}
|
||||
|
||||
}
|
@ -7,7 +7,19 @@
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>JisolGameServer</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.5.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>Main</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
@ -16,30 +28,6 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.jisol</groupId>
|
||||
<artifactId>JNGame</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>cn.jisol.game.JGameApplication</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
Loading…
x
Reference in New Issue
Block a user