无头模式测试

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2023-11-22 03:51:37 +08:00
parent 5ab90ea221
commit 7389f6d716
535 changed files with 991 additions and 162534 deletions

View File

@@ -0,0 +1,55 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg.TB;
import luban.*;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
public final class TbSServerInfo extends AbstractBean {
public TbSServerInfo(JsonObject _buf) {
id = _buf.get("id").getAsInt();
args = _buf.get("args").getAsString();
tig = _buf.get("tig").getAsString();
}
public static TbSServerInfo deserialize(JsonObject _buf) {
return new cfg.TB.TbSServerInfo(_buf);
}
/**
* id
*/
public final int id;
/**
* 全局表参数
*/
public final String args;
/**
* 描述
*/
public final String tig;
public static final int __ID__ = 1231379574;
@Override
public int getTypeId() { return __ID__; }
@Override
public String toString() {
return "{ "
+ "(format_field_name __code_style field.name):" + id + ","
+ "(format_field_name __code_style field.name):" + args + ","
+ "(format_field_name __code_style field.name):" + tig + ","
+ "}";
}
}

View File

@@ -39,6 +39,8 @@ public final class Tables
public cfg.TbGRoleCUp getTbGRoleCUp() { return _tbgrolecup; }
private final cfg.TbGRoleCStar _tbgrolecstar;
public cfg.TbGRoleCStar getTbGRoleCStar() { return _tbgrolecstar; }
private final cfg.TbSServerInfo _tbsserverinfo;
public cfg.TbSServerInfo getTbSServerInfo() { return _tbsserverinfo; }
public Tables(IJsonLoader loader) throws java.io.IOException {
_tbgglobal = new cfg.TbGGlobal(loader.load("tbgglobal"));
@@ -51,6 +53,7 @@ public final class Tables
_tbgresource = new cfg.TbGResource(loader.load("tbgresource"));
_tbgrolecup = new cfg.TbGRoleCUp(loader.load("tbgrolecup"));
_tbgrolecstar = new cfg.TbGRoleCStar(loader.load("tbgrolecstar"));
_tbsserverinfo = new cfg.TbSServerInfo(loader.load("tbsserverinfo"));
}
}

View File

@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg;
import luban.*;
import com.google.gson.JsonElement;
public final class TbSServerInfo {
private final java.util.HashMap<Integer, cfg.TB.TbSServerInfo> _dataMap;
private final java.util.ArrayList<cfg.TB.TbSServerInfo> _dataList;
public TbSServerInfo(JsonElement _buf) {
_dataMap = new java.util.HashMap<Integer, cfg.TB.TbSServerInfo>();
_dataList = new java.util.ArrayList<cfg.TB.TbSServerInfo>();
for (com.google.gson.JsonElement _e_ : _buf.getAsJsonArray()) {
cfg.TB.TbSServerInfo _v;
_v = cfg.TB.TbSServerInfo.deserialize(_e_.getAsJsonObject());
_dataList.add(_v);
_dataMap.put(_v.id, _v);
}
}
public java.util.HashMap<Integer, cfg.TB.TbSServerInfo> getDataMap() { return _dataMap; }
public java.util.ArrayList<cfg.TB.TbSServerInfo> getDataList() { return _dataList; }
public cfg.TB.TbSServerInfo get(int key) { return _dataMap.get(key); }
}

View File

@@ -2,20 +2,24 @@ package cn.jisol.game.actions;
public interface GActionEnum {
int TOKEN_EXPIRED = 1001; //Token过期
int TOKEN_EXPIRED = 1001; //Token过期
/*************** 聊天 *********************/
int CHAT_MESSAGE = 2001; //发送聊天消息
int CHAT_RECEIVE_MESSAGE = 2002; //接受聊天消息
int CHAT_MESSAGE = 2001; //发送聊天消息
int CHAT_RECEIVE_MESSAGE = 2002; //接受聊天消息
/*************** PVP *********************/
int S_MODE_PVP_JOIN = 3001; //加入PVP
int S_MODE_PVP_LEAVE = 3002; //离开PVP
int C_MODE_PVP_WAIT = 3003; //等待PVP开始
int C_MODE_PVP_START = 3004; //PVP开始
int C_MODE_PVP_END = 3005; //PVP结束
int C_MODE_PVP_START_WAIT = 3006; //开始等待PVP开始
int C_MODE_PVP_END_WAIT = 3007; //结束等待PVP开始
int C_MODE_PVP_MESSAGE = 3008; //PVP 消息通知
int S_MODE_PVP_JOIN = 3001; //加入PVP
int S_MODE_PVP_LEAVE = 3002; //离开PVP
int C_MODE_PVP_WAIT = 3003; //等待PVP开始
int C_MODE_PVP_START = 3004; //PVP开始
int C_MODE_PVP_END = 3005; //PVP结束
int C_MODE_PVP_START_WAIT = 3006; //开始等待PVP开始
int C_MODE_PVP_END_WAIT = 3007; //结束等待PVP开始
int C_MODE_PVP_MESSAGE = 3008; //PVP 消息通知
/*************** 裁决 *********************/
int CR_REFEREE_PVP_MODE = 4001; //裁决PVP模式
}

View File

@@ -0,0 +1,51 @@
package cn.jisol.game.actions;
import cn.jisol.game.network.client.GClient;
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 java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* 裁决员行为 处理裁决
*/
@NAction
public class GRefereeAction {
//裁决员列表
public static Map<String, GRefereeClient> REFEREES;
//裁决PVP
public static void onPVPReferee(GPVPMessage.GPVPStart info){
GRefereeClient referee;
//判断是否有裁决员 如果 没有裁决员则返回
if(Objects.isNull(referee = getFreeReferee())) {
System.out.println("没有裁决员");
return;
}
//如果有裁决员则向裁决员发送要裁决的信息
referee.invoke(GActionEnum.CR_REFEREE_PVP_MODE,info);
}
//获取一个空闲的裁决员
public static GRefereeClient getFreeReferee(){
for (String key : REFEREES.keySet()) {
if (!(REFEREES.get(key).isReferee)) {
return REFEREES.get(key);
}
}
return null;
}
}

View File

@@ -3,6 +3,7 @@ package cn.jisol.game.actions.onhook;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import cn.jisol.game.actions.GActionEnum;
import cn.jisol.game.actions.GRefereeAction;
import cn.jisol.game.controller.game.GPlayerPetController;
import cn.jisol.game.controller.game.GPlayerTacticalController;
import cn.jisol.game.entity.game.PlayerTactical;
@@ -142,6 +143,9 @@ public class GPVPAction {
client1.invoke(GActionEnum.C_MODE_PVP_START, info);
client2.invoke(GActionEnum.C_MODE_PVP_START, info);
//发送裁决
GRefereeAction.onPVPReferee(info);
}
}

View File

@@ -0,0 +1,33 @@
package cn.jisol.game.config;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
public class CORSFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Credentials", "true");
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
res.addHeader("Access-Control-Allow-Headers", "*");
if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) {
response.getWriter().println("ok");
return;
}
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
}

View File

@@ -4,6 +4,7 @@ import cn.jisol.game.entity.User;
import cn.jisol.game.entity.game.Player;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -15,4 +16,7 @@ public class Cache {
public static Map<String, User> TOKEN = new HashMap<>(); //Token
public static Map<Long, Player> PLAYER = new HashMap<>(); //玩家
//裁决员账号
public static List<String> REFEREES;
}

View File

@@ -8,4 +8,7 @@ public interface GlobalId {
//OnHook模式 宠物生成数量
int MODE_ON_HOOK_SPAWN_NUM = 80001;
//服务器配置表 裁决员Id
int SERVER_REFEREE_ID = 100001;
}

View File

@@ -2,6 +2,9 @@ package cn.jisol.game.listener;
import cfg.Tables;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.json.JSONUtil;
import cn.jisol.game.data.Cache;
import cn.jisol.game.data.GlobalId;
import cn.jisol.game.data.TD;
import com.google.gson.JsonParser;
import org.springframework.context.event.ContextRefreshedEvent;
@@ -11,6 +14,7 @@ import org.springframework.stereotype.Component;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@Component
public class InitGameListener {
@@ -24,6 +28,11 @@ public class InitGameListener {
System.out.println("加载配置表:"+file);
return JsonParser.parseString(ResourceUtil.readUtf8Str("json/"+file+".json"));
});
//设置基础缓存信息
//裁决员
Cache.REFEREES = JSONUtil.toList(TD.DATA.getTbSServerInfo().get(GlobalId.SERVER_REFEREE_ID).args, String.class);
} catch (IOException e) {
e.printStackTrace();
}

View File

@@ -1,8 +1,11 @@
package cn.jisol.game.network;
import cn.jisol.game.actions.GActionEnum;
import cn.jisol.game.actions.GRefereeAction;
import cn.jisol.game.controller.game.GPlayerController;
import cn.jisol.game.data.Cache;
import cn.jisol.game.network.client.GClient;
import cn.jisol.game.network.client.GRefereeClient;
import cn.jisol.ngame.network.JNetwork;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -30,7 +33,17 @@ public class WebSocket {
WebSocket.playerController = playerController;
}
//玩家列表
public static final Map<String, GClient> CLIENTS = new ConcurrentHashMap<>();
//裁决员列表
public static final Map<String, GRefereeClient> REFEREES = new ConcurrentHashMap<>();
static {
//将裁决员给裁决行为类
GRefereeAction.REFEREES = REFEREES;
}
@OnOpen
public void onOpen(Session session){
@@ -47,20 +60,29 @@ public class WebSocket {
}
client.player = playerController.getPlayerInfo(client.user).data;
CLIENTS.put(session.getId(),client);
System.out.printf("[WebSocket] %s 连接成功.\n",session.getId());
//判断玩家是否是裁决员是的话添加到裁决员列表中
if(Cache.REFEREES.contains(client.user.getUserId()+"")){
REFEREES.put(session.getId(),new GRefereeClient(token,session));
System.out.printf("[WebSocket] %s 裁决员连接成功.\n",session.getId());
}else{
CLIENTS.put(session.getId(),client);
System.out.printf("[WebSocket] %s 连接成功.\n",session.getId());
}
}
@OnMessage
public void onMessage(Session session, InputStream inputStream){
GClient client = CLIENTS.get(session.getId());
JNetwork.onMessage(inputStream,client,client,CLIENTS,client.user,client.player);
GClient referee = REFEREES.get(session.getId());
JNetwork.onMessage(inputStream,client,client,referee,CLIENTS,client.user,client.player);
}
@OnClose
public void onClose(Session session){
CLIENTS.remove(session.getId());
REFEREES.remove(session.getId());
}
}

View File

@@ -0,0 +1,16 @@
package cn.jisol.game.network.client;
import cn.jisol.ngame.client.QueueNClient;
import javax.websocket.Session;
//裁决员客户端
public class GRefereeClient extends GClient {
//是否正在裁决
public boolean isReferee = false;
public GRefereeClient(String token, Session session) {
super(token, session);
}
}

View File

@@ -0,0 +1,7 @@
[
{
"id": 100001,
"args": "[100000]",
"tig": "服务器账号 (用来帧同步裁决)"
}
]