提交一版

back_recharge
mashiyu 2019-01-14 16:34:49 +08:00
parent 2420c68092
commit 2c9c067bf5
18 changed files with 365 additions and 85 deletions

View File

@ -56,9 +56,10 @@ public class GameMessageHandler<T extends GameSession> extends SimpleChannelInbo
super.channelInactive(ctx);
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
LOGGER.info("111111111111");
LOGGER.info("receive msg ...");
protocols.processMessage(this.session, msg);
}

View File

@ -5,6 +5,7 @@ import com.ljsd.jieling.config.json.ServerProperties;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.server.NettyGameServer;
import com.ljsd.jieling.network.NettyProperties;
import com.ljsd.jieling.network.NettyServerAutoConfiguration;
@ -61,7 +62,9 @@ public class GameApplication {
RedisUtil.getInstence().init(configurableApplicationContext);
STableManager.initialize("com.ljsd.jieling.config");
// STableManager.initialize("com.ljsd.jieling.config");
UserManager.init(configurableApplicationContext);
ThreadManager threadManager = new ThreadManager();
threadManager.init(configurableApplicationContext);

View File

@ -0,0 +1,64 @@
package com.ljsd.jieling.handler;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import com.ljsd.jieling.util.MessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
public class GetPlayerInfoHandler extends BaseHandler{
private static final Logger LOGGER = LoggerFactory.getLogger(GetPlayerInfoHandler.class);
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.GET_PLAYERINFO_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
int userId = netData.getUserId();
int token = netData.getToken();
int msgId = netData.getMsgId();
int msgIndex = netData.getIndex();
byte[] message = netData.parseClientProtoNetData();
PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest getPlayerInfoRequest
= PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest.parseFrom(message);
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}",
userId, token,msgId,msgIndex,getPlayerInfoRequest.getNum(),getPlayerInfoRequest.getStr());
User userForLogin = UserManager.getUserForLogin(userId);
CommonProto.Common.Player player = CommonProto.Common.Player
.newBuilder()
.setUid(userId)
.setNicknime("戒灵666")
.setExp(1000)
.setVipLevel(1)
.setFamilyId("abc")
.setHead("head_image_1")
.setGold(100002)
.setGem(8888)
.setChargeGem(1000)
.build();
PlayerInfoProto.PlayerInfo.GetPlayerInfoResponse getPlayerInfoResponse
= PlayerInfoProto.PlayerInfo.GetPlayerInfoResponse.newBuilder()
.setPlayer(player)
.build();
try {
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_PLAYERINFO_RESPONSE_VALUE, getPlayerInfoResponse, true);
LOGGER.info("back to client!");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -32,30 +32,18 @@ public class LoginRequestHandler extends BaseHandler {
byte[] message = netData.parseClientProtoNetData();
PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest getPlayerInfoRequest
= PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest.parseFrom(message);
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}",
userId, token,msgId,msgIndex,getPlayerInfoRequest.getNum(),getPlayerInfoRequest.getStr());
//TODO
User userForLogin = UserManager.getUserForLogin(userId);
CommonProto.Common.Player player = CommonProto.Common.Player
.newBuilder()
.setUid(userId)
.setNicknime("戒灵666")
.setExp(1000)
.setVipLevel(1)
.setFamilyId("abc")
.setHead("head_image_1")
.setGold(100002)
.setGem(8888)
.setChargeGem(1000)
.build();
PlayerInfoProto.PlayerInfo.GetPlayerInfoResponse getPlayerInfoResponse
= PlayerInfoProto.PlayerInfo.GetPlayerInfoResponse.newBuilder()
.setPlayer(player)
PlayerInfoProto.PlayerInfo.LoginResponse loginResponse
= PlayerInfoProto.PlayerInfo.LoginResponse.newBuilder()
.setResultCode(0)
.setNewToken("123456")
.build();
try {
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.LOGIN_RESPONSE_VALUE, getPlayerInfoResponse, true);
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.LOGIN_RESPONSE_VALUE, loginResponse, true);
LOGGER.info("back to client!");
} catch (Exception e) {
e.printStackTrace();

View File

@ -0,0 +1,41 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
public class Equip extends MongoBase {
private String id;
private int equipId;
private int level;
private int star;
public int getEquipId() {
return equipId;
}
public void setEquipId(int equipId) throws Exception {
updateString("equipId",equipId);
this.equipId = equipId;
}
public int getLevel() {
return level;
}
public void setLevel(int level) throws Exception {
updateString("level",level);
this.level = level;
}
public int getStar() {
return star;
}
public void setStar(int star) throws Exception {
updateString("star",star);
this.star = star;
}
}

View File

@ -1,6 +1,9 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
import com.ljsd.jieling.protocols.CommonProto;
import java.util.List;
public class Hero extends MongoBase {
private String id;
@ -25,9 +28,11 @@ public class Hero extends MongoBase {
private int speed;
private List<Skill> skillList;
public void setId(String id) throws Exception {
updateString("id",id);
private List<Equip> quipList;
public void setId(String id) {
this.id = id;
}

View File

@ -3,35 +3,73 @@ package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
public class Item extends MongoBase {
private int templateId;
private int overlap;
private long haveTime;
private String id;
private int itemId;
private int itemNum;
private int itemType;
private int itemQuality;
private boolean isStacking;
private int endingTime;
public void setTemplateId(int templateId) throws Exception {
updateString("templateId",templateId);
this.templateId = templateId;
public int getItemId() {
return itemId;
}
public void setOverlap(int overlap) throws Exception {
updateString("overlap",overlap);
this.overlap = overlap;
public void setItemId(int itemId) throws Exception {
updateString("itemId", itemId);
this.itemId = itemId;
}
public void setHaveTime(long haveTime) throws Exception {
updateString("haveTime",haveTime);
this.haveTime = haveTime;
public int getItemNum() {
return itemNum;
}
public int getTemplateId() {
return templateId;
public void setItemNum(int itemNum) throws Exception {
updateString("itemNum", itemNum);
this.itemNum = itemNum;
}
public int getOverlap() {
return overlap;
public int getItemType() {
return itemType;
}
public long getHaveTime() {
return haveTime;
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;
}
public void setEndingTime(int endingTime) throws Exception {
updateString("endingTime", endingTime);
this.endingTime = endingTime;
}
}

View File

@ -21,9 +21,9 @@ public class ItemManager extends MongoBase {
}
public void addItem(Item item) throws Exception {
item.init(getRoot(), getMongoKey() + ".itemMap." + item.getTemplateId());
updateString("itemMap." + item.getTemplateId(), item);
itemMap.put(item.getTemplateId(), item);
item.init(getRoot(), getMongoKey() + ".itemMap." + item.getItemId());
updateString("itemMap." + item.getItemId(), item);
itemMap.put(item.getItemId(), item);
}
public Item getItem(Integer key) {

View File

@ -5,12 +5,28 @@ import com.ljsd.common.mogodb.MongoBase;
public class PlayerInfoManager extends MongoBase {
private int uid;
private String nickName;
private int level;
private int exp;
private int vipLevel;
private String familyId;
private String head;
private long gold;
private int gem;
private int chargeGem;
public String getNickName() {
return nickName;
}
@ -37,4 +53,58 @@ public class PlayerInfoManager extends MongoBase {
updateString("exp", exp);
this.exp = exp;
}
public int getVipLevel() {
return vipLevel;
}
public void setVipLevel(int vipLevel) throws Exception {
updateString("vipLevel", vipLevel);
this.vipLevel = vipLevel;
}
public String getFamilyId() {
return familyId;
}
public void setFamilyId(String familyId) throws Exception {
updateString("familyId", familyId);
this.familyId = familyId;
}
public String getHead() {
return head;
}
public void setHead(String head) throws Exception {
updateString("head", head);
this.head = head;
}
public long getGold() {
return gold;
}
public void setGold(long gold) throws Exception {
updateString("gold", gold);
this.gold = gold;
}
public int getGem() {
return gem;
}
public void setGem(int gem) throws Exception {
updateString("gem", gem);
this.gem = gem;
}
public int getChargeGem() {
return chargeGem;
}
public void setChargeGem(int chargeGem) throws Exception {
updateString("chargeGem", chargeGem);
this.chargeGem = chargeGem;
}
}

View File

@ -0,0 +1,65 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
import java.util.List;
public class Skill extends MongoBase {
private String id;
private int skillId;
private int skillType;
private int level;
private int star;
private List<Integer> effectIdList;
public int getSkillId() {
return skillId;
}
public void setSkillId(int skillId) throws Exception {
updateString("skillId",skillId);
this.skillId = skillId;
}
public int getSkillType() {
return skillType;
}
public void setSkillType(int skillType) throws Exception {
updateString("skillType",skillType);
this.skillType = skillType;
}
public int getLevel() {
return level;
}
public void setLevel(int level) throws Exception {
updateString("level",level);
this.level = level;
}
public int getStar() {
return star;
}
public void setStar(int star) throws Exception {
updateString("star",star);
this.star = star;
}
public List<Integer> getEffectIdList() {
return effectIdList;
}
public void setEffectIdList(List<Integer> effectIdList) {
this.effectIdList = effectIdList;
}
}

View File

@ -24,7 +24,7 @@ public class User extends MongoRoot {
this.heroManager = heroManager;
this.mapManager = mapManager;
//綁定关系
playerInfoManager.init(this, "playerInfoManager", false);
playerInfoManager.init(this, "playerManager", false);
itemManager.init(this, "itemManager", false);
heroManager.init(this, "heroManager", false);
mapManager.init(this, "mapManager", false);
@ -37,7 +37,7 @@ public class User extends MongoRoot {
this.heroManager = new HeroManager();
this.mapManager = new MapManager();
//綁定关系
playerInfoManager.init(this, "playerInfoManager", false);
playerInfoManager.init(this, "playerManager", false);
itemManager.init(this, "itemManager", false);
heroManager.init(this, "heroManager", false);
mapManager.init(this, "mapManager", false);

View File

@ -8,8 +8,11 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class UserManager {
private static Map<Integer, User> userMap = new ConcurrentHashMap<>();
public static LjsdMongoTemplate ljsdMongoTemplate;
public static void init(ConfigurableApplicationContext configurableApplicationContext) {
ljsdMongoTemplate =configurableApplicationContext.getBean(LjsdMongoTemplate.class);
User.init(ljsdMongoTemplate);

View File

@ -45,13 +45,15 @@ public class NettyClient {
LOGGER.info(gameMessage.toString());
/*---------------------------------------------------------------------------------------------------------*/
while (true){
Thread.sleep(5000);
// List<PacketNetData> result = handler.sendRequest_jieling(gameMessage);
List<PacketNetData> result = handler.sendRequest_jieling(gameMessage);
List<PacketNetData> result = handler.sendHeartBeat_jieling();
LOGGER.info("send to server...");
}
// 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();
// }

View File

@ -101,7 +101,7 @@ public class NettyTCPClientHandler extends SimpleChannelInboundHandler<Object> {
byte[] packetData = new byte[messageData.length + 16];
Tea.intToByte(packetData, 0, 10000001);
Tea.intToByte(packetData, 4, 543242);
Tea.intToByte(packetData, 8, 10000);
Tea.intToByte(packetData, 8, 10600);
Tea.intToByte(packetData, 12, 1);
System.arraycopy(messageData, 0, packetData, 16, messageData.length);

View File

@ -220,29 +220,32 @@ public class ProtocolsManager implements ProtocolsAbstract {
baseHandler.execute(session, packetNetData);
} catch (Exception e) {
//TODO
LOGGER.error("error : " + e);
e.printStackTrace();
}
}
}
private void dealHeartBeat(ISession session) {
new Thread(new Runnable() {
@Override
public void run() {
Random random = new Random();
int time = random.nextInt(6)+1;
try {
System.out.println("sleep time : "+time);
Thread.sleep(time*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Thread.currentThread().setName("OOOOOOOOO");
MessageUtil.sendHeartBeat(session);
}
}).start();
// MessageUtil.sendHeartBeat(session);
// new Thread(new Runnable() {
// @Override
// public void run() {
//
// Random random = new Random();
// int time = random.nextInt(6)+1;
// try {
// System.out.println("sleep time : "+time);
// Thread.sleep(time*1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// Thread.currentThread().setName("");
// MessageUtil.sendHeartBeat(session);
// }
// }).start();
//TODO
MessageUtil.sendHeartBeat(session);
}
private int checkAndRefresh(ISession session, PacketNetData packetNetData) {
@ -256,9 +259,9 @@ public class ProtocolsManager implements ProtocolsAbstract {
}else {
}
if (myToken != packetNetData.getToken()){
return 1;
}
// if (myToken != packetNetData.getToken()){
// return 1;
// }
session.setUserLoginTime(System.currentTimeMillis()/1000);
session.setToken(myToken);
return 0;
@ -267,7 +270,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
@Override
public void offLine(GameSession gameSession) {
LOGGER.info("9999999");
LOGGER.info("player offLine ...");
ISession session = (ISession) gameSession;
synchronized (session) {

View File

@ -15,14 +15,14 @@ public class ThreadManager {
private static final Logger LOGGER = LoggerFactory.getLogger(ThreadManager.class);
private PlatConfigureTask testTask;
private PlatConfigureTask platConfigureTask;
private ScheduledThreadPoolExecutor scheduledExecutor; //管理task
public void init(ConfigurableApplicationContext configurableApplicationContext) {
testTask = configurableApplicationContext.getBean(PlatConfigureTask.class);
platConfigureTask = configurableApplicationContext.getBean(PlatConfigureTask.class);
go();
}
@ -58,7 +58,7 @@ public class ThreadManager {
scheduledExecutor = new ScheduledThreadPoolExecutor(8, new ScheduleThreadFactory());
// testTask 已秒为单位 延迟10s, 间隔30s为周期执行
scheduledExecutor.scheduleAtFixedRate(testTask, 10, 30, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(platConfigureTask, 10, PlatConfigureTask.SLEEP_INTEVAL_TIME, TimeUnit.SECONDS);
LOGGER.info("All Task running ...");
}

View File

@ -12,7 +12,7 @@ import java.io.IOException;
public class PlatConfigureTask implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(PlatConfigureTask.class);
private int SLEEP_INTEVAL_TIME = 60 * 1000; //每1分钟检查一次
public static int SLEEP_INTEVAL_TIME = 60 * 1000; //每1分钟检查一次
@Override
public void run() {
@ -20,13 +20,10 @@ public class PlatConfigureTask implements Runnable {
}
private void doLogic() {
while (true){
try {
ConfMessage.doWork();
TimeUtils.sleep(SLEEP_INTEVAL_TIME);
} catch (IOException e) {
e.printStackTrace();
}
try {
ConfMessage.doWork();
} catch (IOException e) {
e.printStackTrace();
}
}