无任何改动
This commit is contained in:
@@ -11,7 +11,6 @@ import java.util.List;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class AutoSoftwarePacket extends BasePackets {
|
public class AutoSoftwarePacket extends BasePackets {
|
||||||
private String merMessage;
|
|
||||||
@Override
|
@Override
|
||||||
public Byte getCommand() {
|
public Byte getCommand() {
|
||||||
return Command.SOFT_CALL_MSG;
|
return Command.SOFT_CALL_MSG;
|
||||||
|
|||||||
@@ -1,25 +1,45 @@
|
|||||||
package com.realtime.packets.server.handler;
|
package com.realtime.packets.server.handler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.realtime.packets.AutoSoftwarePacket;
|
import com.realtime.packets.AutoSoftwarePacket;
|
||||||
|
import com.realtime.packets.PingPongPacket;
|
||||||
|
import com.realtime.packets.SendMsgPackets;
|
||||||
|
import com.realtime.utils.SessionUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||||
public class AutoSoftwareHandler extends SimpleChannelInboundHandler<AutoSoftwarePacket> {
|
public class AutoSoftwareHandler extends SimpleChannelInboundHandler<AutoSoftwarePacket> {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext channelHandlerContext, AutoSoftwarePacket connectPacket) throws Exception {
|
protected void channelRead0(ChannelHandlerContext channelHandlerContext, AutoSoftwarePacket connectPacket) throws Exception {
|
||||||
|
Channel chanel = SessionUtils.getChannel(connectPacket.getReceiver());
|
||||||
|
ByteBuf buff = getBuff(channelHandlerContext, connectPacket);
|
||||||
|
Objects.requireNonNull(chanel).writeAndFlush(new TextWebSocketFrame(buff));
|
||||||
|
System.out.println("发送私聊消息");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ByteBuf getBuff(ChannelHandlerContext channelHandlerContext, AutoSoftwarePacket autoSoftwarePacket) {
|
||||||
|
ByteBuf byteBuf = channelHandlerContext.alloc().buffer();
|
||||||
|
byte[] bytes = JSONObject.toJSONString(autoSoftwarePacket).getBytes(StandardCharsets.UTF_8);
|
||||||
|
byteBuf.writeBytes(bytes);
|
||||||
|
return byteBuf;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ public class PrivateMessageHandler extends SimpleChannelInboundHandler<SendMsgPa
|
|||||||
ByteBuf buff = getBuff(channelHandlerContext, sendMsgPackets);
|
ByteBuf buff = getBuff(channelHandlerContext, sendMsgPackets);
|
||||||
Objects.requireNonNull(chanel).writeAndFlush(new TextWebSocketFrame(buff));
|
Objects.requireNonNull(chanel).writeAndFlush(new TextWebSocketFrame(buff));
|
||||||
System.out.println("发送私聊消息");
|
System.out.println("发送私聊消息");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf getBuff(ChannelHandlerContext channelHandlerContext, SendMsgPackets sendMsgPackets) {
|
ByteBuf getBuff(ChannelHandlerContext channelHandlerContext, SendMsgPackets sendMsgPackets) {
|
||||||
|
|||||||
Reference in New Issue
Block a user