From 28eb26d68f7a2a4e6b316c3ea9f511aa143db66e Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Mon, 30 Sep 2024 16:57:18 +0800
Subject: [PATCH] 55测试环境
---
src/main/java/com/xcong/excoin/netty/dispatch/MsgDispatch.java | 31 ++++++++++++++++++-------------
1 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/netty/dispatch/MsgDispatch.java b/src/main/java/com/xcong/excoin/netty/dispatch/MsgDispatch.java
index 540fd36..2b4be56 100644
--- a/src/main/java/com/xcong/excoin/netty/dispatch/MsgDispatch.java
+++ b/src/main/java/com/xcong/excoin/netty/dispatch/MsgDispatch.java
@@ -1,9 +1,14 @@
package com.xcong.excoin.netty.dispatch;
+import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.netty.bean.RequestBean;
+import com.xcong.excoin.netty.bean.ResponseBean;
+import com.xcong.excoin.netty.common.ChannelManager;
+import com.xcong.excoin.netty.common.Contans;
import com.xcong.excoin.netty.common.NettyTools;
import com.xcong.excoin.netty.logic.MsgLogic;
+import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
@@ -19,28 +24,28 @@
*/
@Slf4j
@Component("msgDispatch")
-public class MsgDispatch implements ApplicationContextAware {
-
- private ApplicationContext applicationContext;
+public class MsgDispatch {
@Autowired
private MsgLogic msgLogic;
public void webSocketDispatch(ChannelHandlerContext ctx, String msg) {
- RequestBean requestBean = null;
+ RequestBean requestBean = JSONObject.parseObject(msg, RequestBean.class);
+
+ // 判断当前通道用户是否已经登陆
+ if (StrUtil.isEmpty(ChannelManager.findWsMemberId(ctx.channel())) && requestBean.getType() != Contans.AUTH_CHECK) {
+ ResponseBean res = ResponseBean.fail();
+ res.setType(requestBean.getType());
+ ctx.channel().writeAndFlush(NettyTools.webSocketBytes(JSONObject.toJSONString(res)));
+ return;
+ }
+
try {
- requestBean = JSONObject.parseObject(msg, RequestBean.class);
requestBean.setChannelId(ctx.channel().id().asShortText());
msgLogic.webSocketMsgLogic(requestBean);
} catch (Exception e) {
- log.info("#websocket json error:{}#", e);
- ctx.channel().writeAndFlush(NettyTools.webSocketBytes("params error"));
+ log.info("#websocket json error:#", e);
+ ctx.channel().writeAndFlush(NettyTools.wsSendMsg(ResponseBean.fail()));
}
- }
-
-
- @Override
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- this.applicationContext = applicationContext;
}
}
--
Gitblit v1.9.1