Merge branch 'master' of http://60.1.1.230/backend/jieling_server
commit
14297b68f0
|
@ -4,24 +4,24 @@ import com.ljsd.common.mogodb.MongoBase;
|
|||
|
||||
public class Item extends MongoBase {
|
||||
|
||||
private String id;
|
||||
|
||||
private int itemId;
|
||||
|
||||
private int itemNum;
|
||||
|
||||
private int itemType;
|
||||
|
||||
private int itemQuality;
|
||||
|
||||
private boolean isStacking;
|
||||
|
||||
private int endingTime;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
public Item(){
|
||||
|
||||
}
|
||||
|
||||
public Item(int itemId,int itemNum){
|
||||
this.itemId = itemId;
|
||||
this.itemNum = itemNum;
|
||||
this.endingTime = (int)(System.currentTimeMillis()/1000);
|
||||
}
|
||||
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
@ -40,33 +40,6 @@ public class Item extends MongoBase {
|
|||
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() {
|
||||
return endingTime;
|
||||
}
|
||||
|
|
|
@ -33,18 +33,12 @@ public class ItemManager extends MongoBase {
|
|||
|
||||
public void removeItem(Integer key) {
|
||||
itemMap.remove(key);
|
||||
removeString(getMongoKey() + ".itemMap." + key);
|
||||
}
|
||||
|
||||
public Item newItem(int itemId, int itemNum) throws Exception {
|
||||
SItem sItem = SItem.getsItemMap().get(itemId);
|
||||
Item item = new 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());
|
||||
Item item = new Item(itemId,itemNum);
|
||||
addItem(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 业务邮件
|
||||
}
|
|
@ -30,9 +30,6 @@ public class CBean2Proto {
|
|||
.newBuilder()
|
||||
.setItemId(item.getItemId())
|
||||
.setItemNum(item.getItemNum())
|
||||
.setItemType(item.getItemType())
|
||||
.setItemQuality(item.getItemQuality())
|
||||
.setIsStacking(item.isStacking())
|
||||
.setEndingTime(item.getEndingTime())
|
||||
.build();
|
||||
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.ItemManager;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -21,15 +22,36 @@ public class ItemUtil {
|
|||
public static void addItem(User user, Map<Integer, Integer> itemMap) throws Exception {
|
||||
ItemManager itemManager = user.getItemManager();
|
||||
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
|
||||
SItem sItem = SItem.getsItemMap().get(entry.getKey());
|
||||
Item item = itemManager.getItem(entry.getKey());
|
||||
if (item == null){
|
||||
item = itemManager.newItem(entry.getKey(), entry.getValue());
|
||||
}else{
|
||||
if (item.isStacking()){
|
||||
if(sItem.isStacking()){
|
||||
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 {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
compile project(":serverlogic")
|
||||
compile("org.apache.poi:poi-ooxml:3.12")
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package com.ljsd.jieling.network.client;
|
||||
package network.client;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.network.NettyProperties;
|
||||
import com.google.protobuf.*;
|
||||
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||
import com.ljsd.jieling.protocols.GMCommandProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
|
@ -11,21 +12,15 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
|||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@EnableConfigurationProperties(NettyProperties.class)
|
||||
@ComponentScan
|
||||
public class NettyClient {
|
||||
|
||||
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 {
|
||||
EventLoopGroup group = new NioEventLoopGroup(1);
|
||||
|
||||
|
@ -39,28 +34,33 @@ public class NettyClient {
|
|||
Channel ch = b.connect("127.0.0.1",18090).sync().channel();
|
||||
|
||||
NettyTCPClientHandler handler = ch.pipeline().get(NettyTCPClientHandler.class);
|
||||
/*------------------------------------------测试类型-------------------------------------------------------*/
|
||||
//------------------------------------------测试类型-------------------------------------------------------
|
||||
// GameProto.GameMessage gameMessage = new NettyClient().sendLoginMessageTest();//登陆请求
|
||||
PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest gameMessage = new NettyClient().sendRegisterMessageTest();//注册请求
|
||||
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();
|
||||
}
|
||||
|
||||
// }
|
||||
// finally {
|
||||
// group.shutdownGracefully();
|
||||
// }
|
||||
private static byte[] makeFinalMessage(MessageLite request, int msgNum) {
|
||||
byte[] messageData = request.toByteArray();
|
||||
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.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
@ -65,23 +67,8 @@ public class NettyTCPClientHandler extends SimpleChannelInboundHandler<Object> {
|
|||
}
|
||||
|
||||
|
||||
public List<PacketNetData> sendRequest_jieling(MessageLite request) {
|
||||
|
||||
byte[] finalMessage = makeFinalMessage(request);
|
||||
|
||||
public void sendRequest_jieling( byte[] 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() {
|
||||
byte[] packetData = new byte[12];
|
||||
Tea.intToByte(packetData, 0, 10000001);
|
||||
|
@ -136,9 +108,14 @@ public class NettyTCPClientHandler extends SimpleChannelInboundHandler<Object> {
|
|||
int userId = packetNetData.getUserId();
|
||||
int token = packetNetData.getToken();
|
||||
int msgId = packetNetData.getMsgId();
|
||||
byte[] packetData = packetNetData.getPacketData();
|
||||
|
||||
|
||||
|
||||
System.out.println("back hartbeat id : "+msgId);
|
||||
|
||||
//System.out.println(JsonFormat.printToString());
|
||||
|
||||
// int msgIndex = packetNetData.getIndex();
|
||||
// int resultCode = packetNetData.getResult();
|
||||
// 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.ByteBufEncoder;
|
Loading…
Reference in New Issue