暂时提交

back_recharge
lvxinran 2021-04-21 14:16:59 +08:00
parent 5aa5b1fecb
commit 8d985faf56
1 changed files with 54 additions and 18 deletions

View File

@ -1,6 +1,7 @@
package com.ljsd.network.client;
import com.google.protobuf.*;
import com.ljsd.jieling.netty.PackageConstant;
import com.ljsd.jieling.netty.cocdex.Tea;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
@ -13,8 +14,12 @@ import rpc.protocols.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import static com.ljsd.jieling.netty.PackageConstant.GAMEID_LEN;
public class NettyClient {
@ -34,27 +39,39 @@ public class NettyClient {
b.group(group)
.channel(NioSocketChannel.class)
.handler(new NettyTCPClientInitializer());
Channel ch = b.connect("api.gamegs.cn",8741).sync().channel();
Channel ch = b.connect("127.0.0.1",26080).sync().channel();
// PlayerInfoProto.SignInRequest.Builder builder = PlayerInfoProto.SignInRequest.newBuilder().setDayIndex(1203);
NettyTCPClientHandler handler = ch.pipeline().get(NettyTCPClientHandler.class);
//------------------------------------------测试类型-------------------------------------------------------
// GameProto.GameMessage gameMessage = new NettyClient().sendLoginMessageTest();//登陆请求
PlayerInfoProto.GetPlayerInfoRequest gameMessage = new NettyClient().sendRegisterMessageTest();//注册请求
LOGGER.info(gameMessage.toString());
//---------------------------------------------------------------------------------------------------------
PlayerInfoProto.SignInRequest.Builder builder = PlayerInfoProto.SignInRequest.newBuilder().setDayIndex(1203);
PlayerInfoProto.SignInRequest build = builder.build();
PlayerInfoProto.SecretBoxRandomRequest.Builder builder1 = PlayerInfoProto.SecretBoxRandomRequest.newBuilder().setTypeId(29);
handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.RECONNECT_REQUEST_VALUE));
msgIndex=31;
while (!handler.rec){
Thread.sleep(1);
// ChatProto.ChatUserV3 userFrom = ChatProto.ChatUserV3.newBuilder().build();
// ChatProto.ChatV3 chat = ChatProto.ChatV3.newBuilder().setFrom(userFrom).build();
// byte[] bytes = wrappedBuffer((short) 100, chat.toByteArray());
;
NettyTCPClientHandler handler = ch.pipeline().get(NettyTCPClientHandler.class);
while(true){
// handler.sendRequest_jieling(bytes);
System.out.println(11111);
TimeUnit.SECONDS.sleep(3);
}
handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.HERO_RAND_REQQUEST_VALUE));
////------------------------------------------测试类型-------------------------------------------------------
// GameProto.GameMessage gameMessage = new NettyClient().sendLoginMessageTest();//登陆请求
// PlayerInfoProto.GetPlayerInfoRequest gameMessage = new NettyClient().sendRegisterMessageTest();//注册请求
// LOGGER.info(gameMessage.toString());
////---------------------------------------------------------------------------------------------------------
// PlayerInfoProto.SignInRequest.Builder builder = PlayerInfoProto.SignInRequest.newBuilder().setDayIndex(1203);
// PlayerInfoProto.SignInRequest build = builder.build();
//
// PlayerInfoProto.SecretBoxRandomRequest.Builder builder1 = PlayerInfoProto.SecretBoxRandomRequest.newBuilder().setTypeId(29);
//
// handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.RECONNECT_REQUEST_VALUE));
// msgIndex=31;
//
// while (!handler.rec){
// Thread.sleep(1);
// }
// handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.HERO_RAND_REQQUEST_VALUE));
/* for(int i=0;i<100000;i++){
handler.sendRequest_jieling(makeFinalMessage(builder1.build(), MessageTypeProto.MessageType.SECRETBOX_RANDOM_REQUEST_VALUE));
@ -288,4 +305,23 @@ public class NettyClient {
return PlayerInfoProto.WorkShopEquipCreateRequest.newBuilder().setEquipTid(equipTid).build();
}
public static byte[] wrappedBuffer(short gameId, byte[] content) {
int length = PackageConstant.GAMEID_LEN+PackageConstant.CONTENT_LEN+content.length;
byte[] bytes = new byte[length];
int pos = 0;
Tea.shortToByte(bytes, pos, gameId);
pos += PackageConstant.GAMEID_LEN;
Tea.intToByte(bytes, pos, content.length);
pos += PackageConstant.CONTENT_LEN;
if (content.length != 0) {
System.arraycopy(content, 0, bytes, pos, content.length);
}
// if (backMessage.length != 0) {
// LOGGER.info("wrappedBuffer uid=>{} sendbyte=>{}", uid, bytes1.length);
// }
return bytes;
}
}