修改测试客户端 & 修改item
parent
5df73a6802
commit
ecb8d8cc51
|
|
@ -4,24 +4,24 @@ import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
public class Item extends MongoBase {
|
public class Item extends MongoBase {
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
private int itemId;
|
private int itemId;
|
||||||
|
|
||||||
private int itemNum;
|
private int itemNum;
|
||||||
|
|
||||||
private int itemType;
|
|
||||||
|
|
||||||
private int itemQuality;
|
|
||||||
|
|
||||||
private boolean isStacking;
|
|
||||||
|
|
||||||
private int endingTime;
|
private int endingTime;
|
||||||
|
|
||||||
public String getId() {
|
public Item(){
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Item(int itemId,int itemNum){
|
||||||
|
this.itemId = itemId;
|
||||||
|
this.itemNum = itemNum;
|
||||||
|
this.endingTime = (int)(System.currentTimeMillis()/1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getItemId() {
|
public int getItemId() {
|
||||||
return itemId;
|
return itemId;
|
||||||
}
|
}
|
||||||
|
|
@ -40,33 +40,6 @@ public class Item extends MongoBase {
|
||||||
this.itemNum = itemNum;
|
this.itemNum = itemNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getItemType() {
|
|
||||||
return itemType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItemType(int itemType) throws Exception {
|
|
||||||
updateString("itemType", itemType);
|
|
||||||
this.itemType = itemType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getItemQuality() {
|
|
||||||
return itemQuality;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItemQuality(int itemQuality) throws Exception {
|
|
||||||
updateString("itemQuality", itemQuality);
|
|
||||||
this.itemQuality = itemQuality;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStacking() {
|
|
||||||
return isStacking;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStacking(boolean stacking) throws Exception {
|
|
||||||
updateString("stacking", stacking);
|
|
||||||
isStacking = stacking;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEndingTime() {
|
public int getEndingTime() {
|
||||||
return endingTime;
|
return endingTime;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,18 +33,12 @@ public class ItemManager extends MongoBase {
|
||||||
|
|
||||||
public void removeItem(Integer key) {
|
public void removeItem(Integer key) {
|
||||||
itemMap.remove(key);
|
itemMap.remove(key);
|
||||||
|
removeString(getMongoKey() + ".itemMap." + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item newItem(int itemId, int itemNum) throws Exception {
|
public Item newItem(int itemId, int itemNum) throws Exception {
|
||||||
SItem sItem = SItem.getsItemMap().get(itemId);
|
Item item = new Item(itemId,itemNum);
|
||||||
Item item = new Item();
|
addItem(item);
|
||||||
item.setItemId(itemId);
|
|
||||||
item.setItemNum(itemNum);
|
|
||||||
item.setItemType(sItem.getItemType());
|
|
||||||
item.setItemQuality(sItem.getQuantity());
|
|
||||||
int endTime = (int)(System.currentTimeMillis()/1000);
|
|
||||||
item.setEndingTime(endTime);
|
|
||||||
item.setStacking( sItem.isStacking());
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Mail {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private int roleUid; //所属玩家的UID
|
||||||
|
|
||||||
|
private boolean isRead;//是,否已读,未读,附件未领取
|
||||||
|
|
||||||
|
private String head; //标题
|
||||||
|
|
||||||
|
private Date sendDate;//发送的日期
|
||||||
|
|
||||||
|
private long sendTime; //发送时间
|
||||||
|
|
||||||
|
private String mailItemList;//获取所有的附件
|
||||||
|
|
||||||
|
private int effectiveTime;//有效日期
|
||||||
|
|
||||||
|
private int isDraw;//附件状态 是 否领取1和0
|
||||||
|
|
||||||
|
private String content;//邮件内容
|
||||||
|
|
||||||
|
private long readtime;//读邮件时间
|
||||||
|
|
||||||
|
private String sendName;//发送者名字
|
||||||
|
|
||||||
|
private int senderUid;
|
||||||
|
|
||||||
|
private long recvTime;
|
||||||
|
|
||||||
|
private int mailType; //邮件类型 1:系统邮件 2:idip 业务邮件
|
||||||
|
}
|
||||||
|
|
@ -28,12 +28,8 @@ public class CBean2Proto {
|
||||||
public static CommonProto.Common.Item getItem(Item item){
|
public static CommonProto.Common.Item getItem(Item item){
|
||||||
CommonProto.Common.Item itemProto = CommonProto.Common.Item
|
CommonProto.Common.Item itemProto = CommonProto.Common.Item
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
.setId(item.getId())
|
|
||||||
.setItemId(item.getItemId())
|
.setItemId(item.getItemId())
|
||||||
.setItemNum(item.getItemNum())
|
.setItemNum(item.getItemNum())
|
||||||
.setItemType(item.getItemType())
|
|
||||||
.setItemQuality(item.getItemQuality())
|
|
||||||
.setIsStacking(item.isStacking())
|
|
||||||
.setEndingTime(item.getEndingTime())
|
.setEndingTime(item.getEndingTime())
|
||||||
.build();
|
.build();
|
||||||
return itemProto;
|
return itemProto;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.ljsd.jieling.config.SItem;
|
||||||
import com.ljsd.jieling.logic.dao.Item;
|
import com.ljsd.jieling.logic.dao.Item;
|
||||||
import com.ljsd.jieling.logic.dao.ItemManager;
|
import com.ljsd.jieling.logic.dao.ItemManager;
|
||||||
import com.ljsd.jieling.logic.dao.User;
|
import com.ljsd.jieling.logic.dao.User;
|
||||||
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
@ -21,15 +22,36 @@ public class ItemUtil {
|
||||||
public static void addItem(User user, Map<Integer, Integer> itemMap) throws Exception {
|
public static void addItem(User user, Map<Integer, Integer> itemMap) throws Exception {
|
||||||
ItemManager itemManager = user.getItemManager();
|
ItemManager itemManager = user.getItemManager();
|
||||||
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
|
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
|
||||||
|
SItem sItem = SItem.getsItemMap().get(entry.getKey());
|
||||||
Item item = itemManager.getItem(entry.getKey());
|
Item item = itemManager.getItem(entry.getKey());
|
||||||
if (item == null){
|
if (item == null){
|
||||||
item = itemManager.newItem(entry.getKey(), entry.getValue());
|
item = itemManager.newItem(entry.getKey(), entry.getValue());
|
||||||
}else{
|
}else{
|
||||||
if (item.isStacking()){
|
if(sItem.isStacking()){
|
||||||
item.setItemNum(item.getItemNum() + entry.getValue());
|
item.setItemNum(item.getItemNum() + entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
itemManager.addItem(item);
|
}
|
||||||
|
//todo 为了测试 日后要删掉
|
||||||
|
UserManager.ljsdMongoTemplate.lastUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void useItem(User user,Map<Integer,Integer> useItemMap) throws Exception{
|
||||||
|
if(useItemMap.isEmpty()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemManager itemManager = user.getItemManager();
|
||||||
|
for (Map.Entry<Integer, Integer> userItem : useItemMap.entrySet()) {
|
||||||
|
Item myItem = itemManager.getItem(userItem.getKey());
|
||||||
|
if( null == myItem){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int needCount = userItem.getValue();
|
||||||
|
if(myItem.getItemNum()<=needCount){
|
||||||
|
itemManager.removeItem(userItem.getKey());
|
||||||
|
}else{
|
||||||
|
myItem.setItemNum( myItem.getItemNum() - needCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,6 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
|
compile project(":serverlogic")
|
||||||
compile("org.apache.poi:poi-ooxml:3.12")
|
compile("org.apache.poi:poi-ooxml:3.12")
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
package com.ljsd.jieling.network.client;
|
package network.client;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.*;
|
||||||
|
import com.googlecode.protobuf.format.JsonFormat;
|
||||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
|
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||||
import com.ljsd.jieling.network.NettyProperties;
|
import com.ljsd.jieling.network.NettyProperties;
|
||||||
|
import com.ljsd.jieling.protocols.GMCommandProto;
|
||||||
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
|
@ -16,16 +20,14 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableAutoConfiguration
|
|
||||||
@EnableConfigurationProperties(NettyProperties.class)
|
|
||||||
@ComponentScan
|
|
||||||
public class NettyClient {
|
public class NettyClient {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(NettyClient.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(NettyClient.class);
|
||||||
|
|
||||||
|
private static int uid = 10000001;
|
||||||
|
private static int msgIndex = 1;
|
||||||
|
private static int token=543242;
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException, InvalidProtocolBufferException {
|
public static void main(String[] args) throws InterruptedException, InvalidProtocolBufferException {
|
||||||
EventLoopGroup group = new NioEventLoopGroup(1);
|
EventLoopGroup group = new NioEventLoopGroup(1);
|
||||||
|
|
||||||
|
|
@ -39,28 +41,33 @@ public class NettyClient {
|
||||||
Channel ch = b.connect("127.0.0.1",18090).sync().channel();
|
Channel ch = b.connect("127.0.0.1",18090).sync().channel();
|
||||||
|
|
||||||
NettyTCPClientHandler handler = ch.pipeline().get(NettyTCPClientHandler.class);
|
NettyTCPClientHandler handler = ch.pipeline().get(NettyTCPClientHandler.class);
|
||||||
/*------------------------------------------测试类型-------------------------------------------------------*/
|
//------------------------------------------测试类型-------------------------------------------------------
|
||||||
// GameProto.GameMessage gameMessage = new NettyClient().sendLoginMessageTest();//登陆请求
|
// GameProto.GameMessage gameMessage = new NettyClient().sendLoginMessageTest();//登陆请求
|
||||||
PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest gameMessage = new NettyClient().sendRegisterMessageTest();//注册请求
|
PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest gameMessage = new NettyClient().sendRegisterMessageTest();//注册请求
|
||||||
LOGGER.info(gameMessage.toString());
|
LOGGER.info(gameMessage.toString());
|
||||||
/*---------------------------------------------------------------------------------------------------------*/
|
//---------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
List<PacketNetData> result = handler.sendRequest_jieling(gameMessage);
|
handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE));
|
||||||
|
handler.sendRequest_jieling(makeFinalMessage(gmRequest(), MessageTypeProto.MessageType.GM_COMMAND_VALUE));
|
||||||
|
|
||||||
// while (true){
|
}
|
||||||
// Thread.sleep(5000);
|
|
||||||
// List<PacketNetData> result = handler.sendRequest_jieling(gameMessage);
|
|
||||||
//
|
|
||||||
//// List<PacketNetData> result = handler.sendHeartBeat_jieling();
|
|
||||||
// LOGGER.info("send to server...");
|
|
||||||
// }
|
|
||||||
// ch.close();
|
|
||||||
|
|
||||||
// }
|
private static byte[] makeFinalMessage(MessageLite request, int msgNum) {
|
||||||
// finally {
|
byte[] messageData = request.toByteArray();
|
||||||
// group.shutdownGracefully();
|
byte[] packetData = new byte[messageData.length + 16];
|
||||||
// }
|
Tea.intToByte(packetData, 0, uid); //uid
|
||||||
|
Tea.intToByte(packetData, 4, token); //token
|
||||||
|
Tea.intToByte(packetData, 8,msgNum); //msgId
|
||||||
|
Tea.intToByte(packetData, 12, msgIndex); // msgIndex
|
||||||
|
System.arraycopy(messageData, 0, packetData, 16, messageData.length);
|
||||||
|
|
||||||
|
int[] secretKey = Tea.KEY;
|
||||||
|
byte[] finalData = Tea.encrypt2(packetData, secretKey);
|
||||||
|
return finalData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GMCommandProto.GMCommand gmRequest(){
|
||||||
|
return GMCommandProto.GMCommand.newBuilder().setCommand("10000001#0#1#100").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package com.ljsd.jieling.network.client;
|
package network.client;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.google.protobuf.GeneratedMessage;
|
||||||
|
import com.google.protobuf.GeneratedMessageLite;
|
||||||
import com.google.protobuf.MessageLite;
|
import com.google.protobuf.MessageLite;
|
||||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
import com.ljsd.jieling.netty.cocdex.Tea;
|
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
|
|
@ -65,23 +67,8 @@ public class NettyTCPClientHandler extends SimpleChannelInboundHandler<Object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<PacketNetData> sendRequest_jieling(MessageLite request) {
|
public void sendRequest_jieling( byte[] finalMessage) {
|
||||||
|
|
||||||
byte[] finalMessage = makeFinalMessage(request);
|
|
||||||
|
|
||||||
channel.writeAndFlush(finalMessage);
|
channel.writeAndFlush(finalMessage);
|
||||||
ArrayList<PacketNetData> msgs = new ArrayList<PacketNetData>();
|
|
||||||
// try {
|
|
||||||
// Thread.sleep(1000);
|
|
||||||
// for (PacketNetData gameMessage1: answer){
|
|
||||||
// gameMessage1 = answer.take();
|
|
||||||
// msgs.add(gameMessage1);
|
|
||||||
// }
|
|
||||||
// } catch (InterruptedException e) {
|
|
||||||
// LOGGER.error("sendRequest->msg={}", e.getMessage(), e);
|
|
||||||
// }
|
|
||||||
return msgs;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -96,21 +83,6 @@ public class NettyTCPClientHandler extends SimpleChannelInboundHandler<Object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private byte[] makeFinalMessage(MessageLite request) {
|
|
||||||
byte[] messageData = request.toByteArray();
|
|
||||||
byte[] packetData = new byte[messageData.length + 16];
|
|
||||||
Tea.intToByte(packetData, 0, 10000001);
|
|
||||||
Tea.intToByte(packetData, 4, 543242);
|
|
||||||
Tea.intToByte(packetData, 8, 10600);
|
|
||||||
Tea.intToByte(packetData, 12, 1);
|
|
||||||
System.arraycopy(messageData, 0, packetData, 16, messageData.length);
|
|
||||||
|
|
||||||
int[] secretKey = Tea.KEY;
|
|
||||||
byte[] finalData = Tea.encrypt2(packetData, secretKey);
|
|
||||||
|
|
||||||
return finalData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] makeHeartBeatMessage() {
|
private byte[] makeHeartBeatMessage() {
|
||||||
byte[] packetData = new byte[12];
|
byte[] packetData = new byte[12];
|
||||||
Tea.intToByte(packetData, 0, 10000001);
|
Tea.intToByte(packetData, 0, 10000001);
|
||||||
|
|
@ -136,9 +108,14 @@ public class NettyTCPClientHandler extends SimpleChannelInboundHandler<Object> {
|
||||||
int userId = packetNetData.getUserId();
|
int userId = packetNetData.getUserId();
|
||||||
int token = packetNetData.getToken();
|
int token = packetNetData.getToken();
|
||||||
int msgId = packetNetData.getMsgId();
|
int msgId = packetNetData.getMsgId();
|
||||||
|
byte[] packetData = packetNetData.getPacketData();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("back hartbeat id : "+msgId);
|
System.out.println("back hartbeat id : "+msgId);
|
||||||
|
|
||||||
|
//System.out.println(JsonFormat.printToString());
|
||||||
|
|
||||||
// int msgIndex = packetNetData.getIndex();
|
// int msgIndex = packetNetData.getIndex();
|
||||||
// int resultCode = packetNetData.getResult();
|
// int resultCode = packetNetData.getResult();
|
||||||
// byte[] backmessage = packetNetData.parseServerProtoNetData();
|
// byte[] backmessage = packetNetData.parseServerProtoNetData();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.ljsd.jieling.network.client;
|
package network.client;
|
||||||
|
|
||||||
import com.ljsd.jieling.netty.cocdex.ByteBufDecoder;
|
import com.ljsd.jieling.netty.cocdex.ByteBufDecoder;
|
||||||
import com.ljsd.jieling.netty.cocdex.ByteBufEncoder;
|
import com.ljsd.jieling.netty.cocdex.ByteBufEncoder;
|
||||||
Loading…
Reference in New Issue