From a31b6e62183ee458362e92d1a1c8b857449b01ac Mon Sep 17 00:00:00 2001 From: zxw Date: Sat, 26 Sep 2020 20:42:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ewatch=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...entEventListener_CODE_SHOW_OPTIONS_PVP.java | 18 +++++++++++++++++- .../client/handler/TransferHandler.java | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_OPTIONS_PVP.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_OPTIONS_PVP.java index 9f750f3..7b73288 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_OPTIONS_PVP.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_OPTIONS_PVP.java @@ -16,6 +16,7 @@ public class ClientEventListener_CODE_SHOW_OPTIONS_PVP extends ClientEventListen SimplePrinter.printNotice("1. Create Room"); SimplePrinter.printNotice("2. Room List"); SimplePrinter.printNotice("3. Join Room"); + SimplePrinter.printNotice("4. Watch Game"); SimplePrinter.printNotice("Please enter the number of options (enter [BACK] return options list)"); String line = SimpleWriter.write("pvp"); @@ -43,7 +44,22 @@ public class ClientEventListener_CODE_SHOW_OPTIONS_PVP extends ClientEventListen pushToServer(channel, ServerEventCode.CODE_ROOM_JOIN, String.valueOf(option)); } } - }else { + } else if (choose == 4) { + SimplePrinter.printNotice("Please enter the room id you want to watch (enter [BACK] return options list)"); + line = SimpleWriter.write("roomid"); + + if(line.equalsIgnoreCase("BACK")) { + call(channel, data); + }else { + int option = OptionsUtils.getOptions(line); + if(line == null || option < 1) { + SimplePrinter.printNotice("Invalid options, please choose again:"); + call(channel, data); + }else{ + pushToServer(channel, ServerEventCode.CODE_GAME_WATCH, String.valueOf(option)); + } + } + } else { SimplePrinter.printNotice("Invalid option, please choose again:"); call(channel, data); } diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/handler/TransferHandler.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/handler/TransferHandler.java index 9d4f34c..31407a2 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/handler/TransferHandler.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/handler/TransferHandler.java @@ -1,6 +1,8 @@ package org.nico.ratel.landlords.client.handler; +import org.nico.noson.Noson; import org.nico.ratel.landlords.channel.ChannelUtils; +import org.nico.ratel.landlords.client.entity.User; import org.nico.ratel.landlords.client.event.ClientEventListener; import org.nico.ratel.landlords.entity.ClientTransferData.ClientTransferDataProtoc; import org.nico.ratel.landlords.enums.ClientEventCode; @@ -12,6 +14,9 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; +import java.util.HashMap; +import java.util.Map; + public class TransferHandler extends ChannelInboundHandlerAdapter{ @Override @@ -24,7 +29,15 @@ public class TransferHandler extends ChannelInboundHandlerAdapter{ } ClientEventCode code = ClientEventCode.valueOf(clientTransferData.getCode()); if(code != null) { - ClientEventListener.get(code).call(ctx.channel(), clientTransferData.getData()); + if (User.INSTANCE.isWatching()) { + Map wrapMap = new HashMap<>(3); + wrapMap.put("code", code); + wrapMap.put("data", clientTransferData.getData()); + + ClientEventListener.get(ClientEventCode.CODE_GAME_WATCH).call(ctx.channel(), Noson.reversal(wrapMap)); + } else { + ClientEventListener.get(code).call(ctx.channel(), clientTransferData.getData()); + } } } }