新增watch操作

This commit is contained in:
zxw
2020-09-26 20:42:48 +08:00
parent aadaf7dc68
commit a31b6e6218
2 changed files with 31 additions and 2 deletions
@@ -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);
}
@@ -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<String, Object> 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());
}
}
}
}