|
@@ -120,29 +120,40 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<Object> {
|
|
|
if (null == messge) {
|
|
|
return;
|
|
|
}
|
|
|
- String cmd = messge.getCmd();
|
|
|
|
|
|
+
|
|
|
+ if (messge.getUserId().equals(-1)){
|
|
|
+ log.info("游客关闭连接,结束下面的逻辑");
|
|
|
+ process.logout(ctx.channel());
|
|
|
+ handShaker.close(ctx.channel(), (CloseWebSocketFrame)frame.retain());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String cmd = messge.getCmd();
|
|
|
+ String username = messge.getName();
|
|
|
ProcessorInterface processor = null;
|
|
|
+
|
|
|
// 发送消息业务处理类
|
|
|
- if (IMP.INITROOM.getName().equals(cmd)) {
|
|
|
- //附近的人加载
|
|
|
- log.info("我在-初始化:{}", msg);
|
|
|
- processor = new InitRoomProcessor();
|
|
|
- } else if (IMP.LOGINALL.getName().equals(cmd)) {
|
|
|
- log.info("我在-首次登陆:{}", msg);
|
|
|
+ if (IMP.LOGINALL.getName().equals(cmd)) {
|
|
|
+ log.info("[[{}]]登录-------------------->:{}", username, msg);
|
|
|
processor = new LoginProcessor();
|
|
|
- } else if (IMP.CHAT.getName().equals(cmd)) {
|
|
|
- log.info("我在-发送消息:{}", msg);
|
|
|
+ }else if (IMP.INITROOM.getName().equals(cmd)) {
|
|
|
+ //加载聊天室,如果聊天室不存在,就创建。如果客户端不在聊天室假如聊天室
|
|
|
+ log.info("[[{}]]加载房间==========>:{}", username, msg);
|
|
|
+ processor = new InitRoomProcessor();
|
|
|
+ } else if (IMP.CHAT.getName().equals(cmd)) {
|
|
|
+ log.info("[[{}]]发送消息----------------》:{}", username, msg);
|
|
|
processor = new ChatProcessor();
|
|
|
} else if (IMP.WEBLOGINALL.getName().equals(cmd)) {
|
|
|
- log.info("我在-web端发送消息:{}", msg);
|
|
|
+ log.info("[[{}]]我在-web端发送消息:{}", username, msg);
|
|
|
+ processor = new WebLoginAllProcessor();
|
|
|
+ } else if (IMP.LOOP.getName().equals(cmd)) {
|
|
|
+ log.info("[[{}]] heartbeat :{}", username, msg);
|
|
|
processor = new WebLoginAllProcessor();
|
|
|
} else {
|
|
|
- log.info("发送WebSoket协议异常:{}", msg);
|
|
|
+ log.info("[[{}]]发送WebSoket协议异常:{}", username, msg);
|
|
|
return;
|
|
|
}
|
|
|
processor.process(ctx.channel(), messge);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -157,24 +168,27 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<Object> {
|
|
|
if (evt instanceof IdleStateEvent){
|
|
|
IdleStateEvent event = (IdleStateEvent)evt;
|
|
|
if (event.state()== IdleState.READER_IDLE){
|
|
|
- log.info("{}-----》客户端写操作空闲",process.getNickName(ctx.channel()));
|
|
|
+ log.info("{}-----》客户端操作空闲",process.getNickName(ctx.channel()));
|
|
|
process.logout(ctx.channel());
|
|
|
+ CloseWebSocketFrame fram = new CloseWebSocketFrame();
|
|
|
+ handShaker.close(ctx.channel(), fram.retain());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
|
|
+ log.info("{}-----》客户端手动退出",process.getNickName(ctx.channel()));
|
|
|
+ process.logout(ctx.channel());
|
|
|
+ CloseWebSocketFrame fram = new CloseWebSocketFrame();
|
|
|
+ handShaker.close(ctx.channel(), fram.retain());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
|
|
log.info("{}-----》客户端不活跃",process.getNickName(ctx.channel()));
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
|
|
-
|
|
|
- log.info("{}-----》客户端手动退出",process.getNickName(ctx.channel()));
|
|
|
- process.logout(ctx.channel());
|
|
|
- }
|
|
|
- // 这里是出现异常的话要进行的操作
|
|
|
@Override
|
|
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
|
|
// super.exceptionCaught(ctx, cause);
|