刷新好友状态

back_recharge
gaojie 2019-06-14 10:07:29 +08:00
parent 9690a3f414
commit b4cdcb2c10
6 changed files with 89 additions and 20 deletions

View File

@ -37,4 +37,9 @@ public interface Global {
int MONSTER_1 = 0;
int MONSTER_2 = 1;
int MONSTER_3 = 2;
//返回状态
int USER_NO_EXIT_STATE = 10000; // 玩家不存在
int NO_FIND_ONESELF_STATE = 10001; // 不能查找自己
}

View File

@ -0,0 +1,25 @@
package com.ljsd.jieling.handler.friend;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.friend.FriendLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class RefreshFriendStateRequestHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.REFRESH_FRIEND_STATE_REQEUST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
FriendLogic.getInstance().refreshFirendState(iSession);
}
}

View File

@ -216,6 +216,7 @@ public class MapManager extends MongoBase {
if (addValue != 0) {
int curEnergy = MathUtils.setBetweenWithMax(itemNum + addValue, 0, SGameSetting.getGameSetting().getInitialEnergy());
item.setItemNum(curEnergy > playerInfoManager.getMaxStamina() ? playerInfoManager.getMaxStamina() : curEnergy);
System.out.println("增加之前的==============================="+itemNum + "增加的数量============"+addValue +"总数========="+item.getItemNum());
setLastUpdateEnergyTime(item, updateTime, lastUpdateEnergyTime);
}
} else {

View File

@ -4,6 +4,7 @@ import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.globals.Global;
import com.ljsd.jieling.globals.GlobalItemType;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.dao.FriendManager;
@ -34,7 +35,27 @@ public class FriendLogic {
return FriendLogic.Instance.instance;
}
/**
*
* @param iSession
*/
public void refreshFirendState(ISession iSession) throws Exception {
int uid = iSession.getUid();
User user = UserManager.getUser(uid);
FriendManager friendManager = user.getFriendManager();
List<Integer> friends = friendManager.getFriends();
List<Integer> onlineList = new CopyOnWriteArrayList<>();
for (Integer friendId :friends){
if(!OnlineUserManager.checkUidOnline(uid)){
continue;
}
onlineList.add(friendId);
}
PlayerInfoProto.RefreshFriendStateResponse refreshFriendStateResponse = PlayerInfoProto.RefreshFriendStateResponse
.newBuilder().addAllFriendIds(onlineList)
.build();
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.REFRESH_FRIEND_STATE_RESPONSE_VALUE, refreshFriendStateResponse, true);
}
/**
*
*/
@ -168,7 +189,7 @@ public class FriendLogic {
applyFriends.remove(0);
}
friendManager.addApplyFriend(uid);
sendFriendInfoIndication(uid,1);
sendFriendInfoIndication(uid,inviteUid,1);
}
MessageUtil.sendMessage(iSession, 1, msgId, null, true);
}
@ -177,18 +198,29 @@ public class FriendLogic {
* 线
* @param inviteUid
*/
private void sendFriendInfoIndication(int inviteUid,int type) throws Exception {
private void sendFriendInfoIndication(int uid,int inviteUid,int type) throws Exception {
boolean isOnline = OnlineUserManager.checkUidOnline(inviteUid);
if (isOnline){
ISession session = OnlineUserManager.getSessionByUid(inviteUid);
PlayerInfoProto.sendFriendInfoIndication.Builder sendFriendInfoIndication = PlayerInfoProto.sendFriendInfoIndication.newBuilder();
sendFriendInfoIndication .setType(type);
if (type == 1){
sendFriendInfoIndication .setFriends(CBean2Proto.getFriendInfo(inviteUid,null));
sendFriendInfoIndication .setFriends(CBean2Proto.getFriendInfo(uid,null));
}
MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.SEND_FRIEND_INFO_INDICATION_VALUE, sendFriendInfoIndication.build(), true);
}
}
//t推送赠送体力状态
private void sendFriendStatedication(int uid ,int inviteUid,int type) throws Exception {
boolean isOnline = OnlineUserManager.checkUidOnline(inviteUid);
if (isOnline) {
ISession session = OnlineUserManager.getSessionByUid(inviteUid);
PlayerInfoProto.SendFriendStateIndication.Builder sendFriendStateIndication = PlayerInfoProto.SendFriendStateIndication.newBuilder();
sendFriendStateIndication.setType(type);
sendFriendStateIndication.setFriendId(uid);
MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.SEND_FRIEND_INFO_INDICATION_VALUE, sendFriendStateIndication.build(), true);
}
}
/**
*
@ -233,7 +265,7 @@ public class FriendLogic {
friendfriendManager.addFriendId(uid);
initFriendGriveAndRreward(friendId, uid, friendManager, friendfriendManager);
sendFriendInfoIndication(friendId,2);
sendFriendInfoIndication(uid,friendId,2);
break;
case 2://拒绝
applyFriends = friendManager.getApplyFriends();
@ -272,7 +304,7 @@ public class FriendLogic {
friendfriendManager.addFriendId(uid);
friendManager.addFriendId(applyfriendId);
initFriendGriveAndRreward(applyfriendId, uid, friendManager, friendfriendManager);
sendFriendInfoIndication(applyfriendId,2);
sendFriendInfoIndication(uid,applyfriendId,2);
}
}
@ -302,7 +334,7 @@ public class FriendLogic {
User friendUser = UserManager.getUser(friendId);
FriendManager friendManager1 = friendUser.getFriendManager();
delFriendInfo(friendId, uid, friendManager, friendManager1);
sendFriendInfoIndication(friendId,3);
sendFriendStatedication(uid,friendId,1);
MessageUtil.sendMessage(iSession, 1, msgId, null, true);
}
//删除好友清除赠送领取体力信息
@ -346,7 +378,7 @@ public class FriendLogic {
}
friendManager.updateGiveMap(friendId,1);
friendManager1.updateHaveRewardMap(uid,1);
sendFriendInfoIndication(friendId,4);
sendFriendStatedication(uid,friendId,2);
}else{ //赠送全部好友
for (Integer friendUserId : friends) {
if (giveMap.get(friendUserId) == 1) {
@ -360,7 +392,7 @@ public class FriendLogic {
}
friendManager.updateGiveMap(friendUserId,1);
friendManager1.updateHaveRewardMap(uid,1);
sendFriendInfoIndication(friendUserId,4);
sendFriendStatedication(uid,friendId,2);
}
}
MessageUtil.sendMessage(iSession, 1, msgId, null, true);
@ -426,17 +458,17 @@ public class FriendLogic {
List<Integer> friends = friendManager.getFriends();
boolean result = ShieldedWordUtils.checkName( name);
if (!result) {
MessageUtil.sendErrorResponse(iSession, 0, msgId, "");
MessageUtil.sendErrorResponse(iSession, 0, msgId, "名字不合法");
return;
}
if (playerInfoManager.getNickName().equals(name)){
MessageUtil.sendErrorResponse(iSession, 0, msgId, "不可以查找自己");
MessageUtil.sendErrorCode(iSession, Global.NO_FIND_ONESELF_STATE, "不能查找自己");
return;
}
String key = RedisKey.getKey(RedisKey.C_User_Name_Key, name, false);
Object friend = RedisUtil.getInstence().get(key);
if (friend == null){
MessageUtil.sendErrorResponse(iSession, 0, msgId, "该玩家不存在");
MessageUtil.sendErrorCode(iSession, Global.USER_NO_EXIT_STATE, "玩家不存在");
return;
}
int type = 1;

View File

@ -3,10 +3,12 @@ package com.ljsd.jieling.util;
import com.ljsd.jieling.config.SMonsterConfig;
import com.ljsd.jieling.handler.map.MapManager;
import com.ljsd.jieling.handler.map.TemporaryItems;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.dao.*;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.protocols.ChatProto;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import java.util.ArrayList;
@ -267,7 +269,11 @@ public class CBean2Proto {
friend.setId(Integer.parseInt(user.getId()));
friend.setName(playerInfoManager.getNickName());
friend.setLv(playerInfoManager.getLevel());
friend.setOffLineTime(playerInfoManager.getOffLineTime());
long isOnline = 0;
if (!OnlineUserManager.checkUidOnline(friendId)){
isOnline = playerInfoManager.getOffLineTime();
}
friend.setOffLineTime(isOnline);
friend.setHaveReward(haveReward);
friend.setIsGive(isGrive);
friend.setHead(playerInfoManager.getHead());

View File

@ -20,9 +20,9 @@ public class NettyClient {
private static final Logger LOGGER = LoggerFactory.getLogger(NettyClient.class);
// private static int uid = 10004436;
private static int uid = 10004555;
private static int msgIndex = 1;
private static int uid = 10004481;
// private static int uid = 10004481;
private static int token=543242;
public static void main(String[] args) throws InterruptedException, InvalidProtocolBufferException {
@ -46,7 +46,7 @@ public class NettyClient {
handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE));
//获取好友信息
// handler.sendRequest_jieling(makeFinalMessage(getFriends(), MessageTypeProto.MessageType.GET_FRIEND_INFO_REQUEST_VALUE));
handler.sendRequest_jieling(makeFinalMessage(getFriends(), MessageTypeProto.MessageType.GET_FRIEND_INFO_REQUEST_VALUE));
//根据用户名查找玩家
// handler.sendRequest_jieling(makeFinalMessage(findUserByName(), MessageTypeProto.MessageType.FRIEND_SEARCH_REQUEST_VALUE));
//发送好友申请
@ -56,9 +56,9 @@ public class NettyClient {
//删除好友
// handler.sendRequest_jieling(makeFinalMessage(delFriend(), MessageTypeProto.MessageType.DEL_FRIEND_REQUEST_VALUE));
//赠送体力
handler.sendRequest_jieling(makeFinalMessage(friendGive(), MessageTypeProto.MessageType.FRIEND_GIVE_PRESENT_REQUEST_VALUE));
// handler.sendRequest_jieling(makeFinalMessage(friendGive(), MessageTypeProto.MessageType.FRIEND_GIVE_PRESENT_REQUEST_VALUE));
//领取体力
handler.sendRequest_jieling(makeFinalMessage(takeHeart(), MessageTypeProto.MessageType.FRIEND_TAKE_HEART_REQUEST_VALUE));
// handler.sendRequest_jieling(makeFinalMessage(takeHeart(), MessageTypeProto.MessageType.FRIEND_TAKE_HEART_REQUEST_VALUE));
//聊天
// for (int i= 0; i < 1000; i++){
// handler.sendRequest_jieling(makeFinalMessage(sendChatInfo(i), MessageTypeProto.MessageType.SEND_CHAT_INFO_REQUEST_VALUE));
@ -138,14 +138,14 @@ public class NettyClient {
private static MessageLite findUserByName() {
PlayerInfoProto.FriendSearchRequest friendSearchRequest = PlayerInfoProto.FriendSearchRequest
. newBuilder()
.setName("10004481")
.setName("王五")
.build();
return friendSearchRequest;
}
private static MessageLite getFriends() {
PlayerInfoProto.GetFriendInfoRequest getFriendInfoRequest = PlayerInfoProto.GetFriendInfoRequest
.newBuilder().setType(3)
.newBuilder().setType(2)
.build();
return getFriendInfoRequest;
}