back_recharge
parent
5df73a6802
commit
4fc7cd3f32
|
@ -62,7 +62,7 @@ public class GameApplication {
|
||||||
|
|
||||||
RedisUtil.getInstence().init(configurableApplicationContext);
|
RedisUtil.getInstence().init(configurableApplicationContext);
|
||||||
|
|
||||||
STableManager.initialize("com.ljsd.jieling.config");
|
// STableManager.initialize("com.ljsd.jieling.config");
|
||||||
|
|
||||||
UserManager.init(configurableApplicationContext);
|
UserManager.init(configurableApplicationContext);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.ljsd.jieling.db.redis;
|
||||||
|
|
||||||
|
public class RedisKey {
|
||||||
|
|
||||||
|
private final static String Delimiter_colon = ":";
|
||||||
|
|
||||||
|
private final static String areaId = "0";
|
||||||
|
|
||||||
|
public static final String TOKEN = "JL_TOKEN";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近登录服务器列表
|
||||||
|
*/
|
||||||
|
public static final String USER_SERVER_INFO = "JL_USER_SERVER_INFO";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private <K, T> String getKey(String type, K key, boolean withServerId) {
|
||||||
|
if (withServerId) {
|
||||||
|
return areaId + Delimiter_colon + type + Delimiter_colon + String.valueOf(key);
|
||||||
|
} else {
|
||||||
|
return type + Delimiter_colon + String.valueOf(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ljsd.jieling.handler;
|
package com.ljsd.jieling.handler;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||||
import com.ljsd.jieling.logic.dao.User;
|
import com.ljsd.jieling.logic.dao.User;
|
||||||
import com.ljsd.jieling.logic.dao.UserManager;
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package com.ljsd.jieling.handler;
|
package com.ljsd.jieling.handler;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.db.redis.RedisKey;
|
||||||
|
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||||
|
import com.ljsd.jieling.logic.dao.PlayerManager;
|
||||||
import com.ljsd.jieling.logic.dao.User;
|
import com.ljsd.jieling.logic.dao.User;
|
||||||
import com.ljsd.jieling.logic.dao.UserManager;
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
|
import com.ljsd.jieling.logic.dao.UserServerInfo;
|
||||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
import com.ljsd.jieling.network.session.ISession;
|
import com.ljsd.jieling.network.session.ISession;
|
||||||
import com.ljsd.jieling.protocols.CommonProto;
|
import com.ljsd.jieling.protocols.CommonProto;
|
||||||
|
@ -30,17 +34,23 @@ public class LoginRequestHandler extends BaseHandler {
|
||||||
int msgId = netData.getMsgId();
|
int msgId = netData.getMsgId();
|
||||||
int msgIndex = netData.getIndex();
|
int msgIndex = netData.getIndex();
|
||||||
byte[] message = netData.parseClientProtoNetData();
|
byte[] message = netData.parseClientProtoNetData();
|
||||||
PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest getPlayerInfoRequest
|
PlayerInfoProto.PlayerInfo.LoginRequest loginRequest
|
||||||
= PlayerInfoProto.PlayerInfo.GetPlayerInfoRequest.parseFrom(message);
|
= PlayerInfoProto.PlayerInfo.LoginRequest.parseFrom(message);
|
||||||
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}",
|
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}",
|
||||||
userId, token,msgId,msgIndex,getPlayerInfoRequest.getNum(),getPlayerInfoRequest.getStr());
|
userId, token,msgId,msgIndex,loginRequest.getNum(),loginRequest.getStr());
|
||||||
//TODO
|
|
||||||
User userForLogin = UserManager.getUserForLogin(userId);
|
//登陆注册入内存
|
||||||
|
User user = UserManager.userLogin(userId);
|
||||||
|
user.getPlayerInfoManager().setOpenId(loginRequest.getOpenId());
|
||||||
|
UserServerInfo userServerInfo = new UserServerInfo(user.getPlayerInfoManager());
|
||||||
|
RedisUtil.getInstence().hset(RedisKey.USER_SERVER_INFO,loginRequest.getOpenId(), userServerInfo);
|
||||||
|
|
||||||
|
String newToken = UserManager.getNewToken(userId);
|
||||||
|
|
||||||
PlayerInfoProto.PlayerInfo.LoginResponse loginResponse
|
PlayerInfoProto.PlayerInfo.LoginResponse loginResponse
|
||||||
= PlayerInfoProto.PlayerInfo.LoginResponse.newBuilder()
|
= PlayerInfoProto.PlayerInfo.LoginResponse.newBuilder()
|
||||||
.setResultCode(0)
|
.setResultCode(0)
|
||||||
.setNewToken("123456")
|
.setNewToken(newToken)
|
||||||
.build();
|
.build();
|
||||||
try {
|
try {
|
||||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.LOGIN_RESPONSE_VALUE, loginResponse, true);
|
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.LOGIN_RESPONSE_VALUE, loginResponse, true);
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.ljsd.jieling.logic;
|
||||||
|
|
||||||
|
public class CalHeroFinalAttri {
|
||||||
|
|
||||||
|
public static CalHeroFinalAttri getInstance(){
|
||||||
|
return Instance.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Instance{
|
||||||
|
public final static CalHeroFinalAttri instance = new CalHeroFinalAttri();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ public class Hero extends MongoBase {
|
||||||
|
|
||||||
private List<Skill> skillList;
|
private List<Skill> skillList;
|
||||||
|
|
||||||
private List<Equip> quipList;
|
private List<Equip> equipList;
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -129,4 +129,20 @@ public class Hero extends MongoBase {
|
||||||
public int getSpeed() {
|
public int getSpeed() {
|
||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Skill> getSkillList() {
|
||||||
|
return skillList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSkillList(List<Skill> skillList) {
|
||||||
|
this.skillList = skillList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Equip> getEquipList() {
|
||||||
|
return equipList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEquipList(List<Equip> equipList) {
|
||||||
|
this.equipList = equipList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@ 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;
|
||||||
|
@ -18,9 +16,6 @@ public class Item extends MongoBase {
|
||||||
|
|
||||||
private int endingTime;
|
private int endingTime;
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getItemId() {
|
public int getItemId() {
|
||||||
return itemId;
|
return itemId;
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
public class PlayerManager extends MongoBase {
|
public class PlayerManager extends MongoBase {
|
||||||
|
|
||||||
|
private String openId;
|
||||||
|
|
||||||
private String nickName;
|
private String nickName;
|
||||||
|
|
||||||
private int level;
|
private int level;
|
||||||
|
@ -24,6 +26,14 @@ public class PlayerManager extends MongoBase {
|
||||||
private int chargeGem;
|
private int chargeGem;
|
||||||
|
|
||||||
|
|
||||||
|
public String getOpenId() {
|
||||||
|
return openId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpenId(String openId) {
|
||||||
|
this.openId = openId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getNickName() {
|
public String getNickName() {
|
||||||
return nickName;
|
return nickName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class Skill extends MongoBase {
|
public class Skill extends MongoBase {
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
private int skillId;
|
private int skillId;
|
||||||
|
|
||||||
private int skillType;
|
private int skillType;
|
||||||
|
@ -19,6 +17,7 @@ public class Skill extends MongoBase {
|
||||||
|
|
||||||
private List<Integer> effectIdList;
|
private List<Integer> effectIdList;
|
||||||
|
|
||||||
|
|
||||||
public int getSkillId() {
|
public int getSkillId() {
|
||||||
return skillId;
|
return skillId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,10 @@ public class UserManager {
|
||||||
userMap.put(user._getIntId(), user);
|
userMap.put(user._getIntId(), user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isUserExist(int uid) {
|
||||||
|
return userMap.containsKey(uid);
|
||||||
|
}
|
||||||
|
|
||||||
public static User getUserForLogin(int uid) throws Exception {
|
public static User getUserForLogin(int uid) throws Exception {
|
||||||
User user = userMap.get(uid);
|
User user = userMap.get(uid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
@ -36,16 +40,51 @@ public class UserManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void refreshUserLoginInfo(User user) {
|
private static void refreshUserLoginInfo(User user) {
|
||||||
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static User userLogin(int uid) throws Exception {
|
||||||
|
User user = ljsdMongoTemplate.findById(User.getCollectionName(), Integer.toString(uid), User.class);
|
||||||
|
if (user == null) {
|
||||||
|
user = registerUser(uid);
|
||||||
|
}else {
|
||||||
|
if (!UserManager.isUserExist(uid)){
|
||||||
|
UserManager.addUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static User registerUser(int uid) throws Exception {
|
private static User registerUser(int uid) throws Exception {
|
||||||
User user = new User(uid,new PlayerManager(),new ItemManager(),new HeroManager(),new MapManager());
|
User user = new User(uid,new PlayerManager(),new ItemManager(),new HeroManager(),new MapManager());
|
||||||
|
initPlayer(user);
|
||||||
UserManager.addUser(user);
|
UserManager.addUser(user);
|
||||||
ljsdMongoTemplate.save(user);
|
ljsdMongoTemplate.save(user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void initPlayer(User user) throws Exception {
|
||||||
|
PlayerManager playerManager = user.getPlayerInfoManager();
|
||||||
|
playerManager.setNickName("戒灵666");
|
||||||
|
playerManager.setLevel(1);
|
||||||
|
playerManager.setExp(0);
|
||||||
|
playerManager.setVipLevel(0);
|
||||||
|
playerManager.setFamilyId("12345");
|
||||||
|
playerManager.setHead("image_head_1");
|
||||||
|
playerManager.setGold(100000l);
|
||||||
|
playerManager.setGem(9999);
|
||||||
|
playerManager.setChargeGem(666);
|
||||||
|
|
||||||
|
ItemManager itemManager = user.getItemManager();
|
||||||
|
//TODO
|
||||||
|
HeroManager heroManager = user.getHeroManager();
|
||||||
|
//TODO
|
||||||
|
MapManager mapManager = user.getMapManager();
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static User getUser(int uid) throws Exception {
|
public static User getUser(int uid) throws Exception {
|
||||||
User user = userMap.get(uid);
|
User user = userMap.get(uid);
|
||||||
|
@ -65,5 +104,8 @@ public class UserManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getNewToken(int userId) {
|
||||||
|
|
||||||
|
return "33521";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
public class UserServerInfo {
|
||||||
|
|
||||||
|
private long loginTime;
|
||||||
|
|
||||||
|
private int level;
|
||||||
|
|
||||||
|
public UserServerInfo(PlayerManager playerInfoManager) {
|
||||||
|
this.loginTime = System.currentTimeMillis();
|
||||||
|
this.level = playerInfoManager.getLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLoginTime() {
|
||||||
|
return loginTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginTime(long loginTime) {
|
||||||
|
this.loginTime = loginTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevel(int level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package com.ljsd.jieling.util;
|
package com.ljsd.jieling.util;
|
||||||
|
|
||||||
import com.ljsd.jieling.logic.dao.Hero;
|
import com.ljsd.jieling.logic.dao.*;
|
||||||
import com.ljsd.jieling.logic.dao.Item;
|
|
||||||
import com.ljsd.jieling.logic.dao.ItemManager;
|
|
||||||
import com.ljsd.jieling.logic.dao.PlayerManager;
|
|
||||||
import com.ljsd.jieling.protocols.CommonProto;
|
import com.ljsd.jieling.protocols.CommonProto;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CBean2Proto {
|
public class CBean2Proto {
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -42,9 +38,43 @@ public class CBean2Proto {
|
||||||
public static CommonProto.Common.Hero getHero(Hero hero){
|
public static CommonProto.Common.Hero getHero(Hero hero){
|
||||||
CommonProto.Common.Hero heroProto = CommonProto.Common.Hero
|
CommonProto.Common.Hero heroProto = CommonProto.Common.Hero
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
|
.setId(hero.getId())
|
||||||
|
.setHeroId(hero.getTemplateId())
|
||||||
|
.setHeroType(hero.getHeroType())
|
||||||
|
.setLevel(hero.getLevel())
|
||||||
|
.setStar(hero.getStar())
|
||||||
|
.setQuality(1)
|
||||||
|
.setHp(hero.getHp())
|
||||||
|
.setAttack(hero.getAttack())
|
||||||
|
.setPDefence(hero.getpDefence())
|
||||||
|
.setMDefence(hero.getmDefence())
|
||||||
|
.setSpeed(hero.getSpeed())
|
||||||
|
.addAllSkillList(getHeroSkill(hero.getSkillList()))
|
||||||
|
.addAllEquipList(getHeroEquip(hero.getEquipList()))
|
||||||
.build();
|
.build();
|
||||||
return heroProto;
|
return heroProto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<CommonProto.Common.Skill> getHeroSkill(List<Skill> skillList) {
|
||||||
|
|
||||||
|
List<CommonProto.Common.Skill> skills = new ArrayList<>();
|
||||||
|
for(Skill skill : skillList){
|
||||||
|
CommonProto.Common.Skill skill1 = CommonProto.Common.Skill
|
||||||
|
.newBuilder()
|
||||||
|
.setSkillId(skill.getSkillId())
|
||||||
|
.setSkillType(skill.getSkillType())
|
||||||
|
.setLevel(skill.getLevel())
|
||||||
|
.setStar(skill.getStar())
|
||||||
|
.addAllEffectId(skill.getEffectIdList())
|
||||||
|
.build();
|
||||||
|
skills.add(skill1);
|
||||||
|
}
|
||||||
|
return skills;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<CommonProto.Common.Equip> getHeroEquip(List<Equip> equipList) {
|
||||||
|
List<CommonProto.Common.Equip> equips = new ArrayList<>();
|
||||||
|
return equips;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue