获取好友申请列表
parent
60bd86264b
commit
1d08720a5a
|
@ -0,0 +1,28 @@
|
||||||
|
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 FriendInviteOperationHandler extends BaseHandler {
|
||||||
|
@Override
|
||||||
|
public MessageTypeProto.MessageType getMessageCode() {
|
||||||
|
return MessageTypeProto.MessageType.FRIEND_INVITE_OPERATION_REQUEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||||
|
PlayerInfoProto.FriendInviteOperationRequest friendInviteOperationRequest = PlayerInfoProto.FriendInviteOperationRequest.parseFrom(netData.parseClientProtoNetData());
|
||||||
|
int type = friendInviteOperationRequest.getType();
|
||||||
|
int friendId = friendInviteOperationRequest.getFriendId();
|
||||||
|
FriendLogic.getInstance().sendAgree(iSession,type,friendId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ public class FriendManager extends MongoBase {
|
||||||
|
|
||||||
private List<Integer> friends = new CopyOnWriteArrayList<>();
|
private List<Integer> friends = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
private Set<Integer> applyFriends = Sets.newConcurrentHashSet(); // 申请列表信息
|
private List<Integer> applyFriends = new CopyOnWriteArrayList<>();; // 申请列表信息
|
||||||
|
|
||||||
public int getUid() {
|
public int getUid() {
|
||||||
return uid;
|
return uid;
|
||||||
|
@ -31,12 +31,12 @@ public class FriendManager extends MongoBase {
|
||||||
this.friends = friends;
|
this.friends = friends;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Integer> getApplyFriends() {
|
public void setApplyFriends(List<Integer> applyFriends) {
|
||||||
return applyFriends;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplyFriends(Set<Integer> applyFriends) {
|
|
||||||
updateString("applyFriends", applyFriends);
|
updateString("applyFriends", applyFriends);
|
||||||
this.applyFriends = applyFriends;
|
this.applyFriends = applyFriends;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Integer> getApplyFriends() {
|
||||||
|
return applyFriends;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ljsd.jieling.logic.friend;
|
package com.ljsd.jieling.logic.friend;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||||
import com.ljsd.jieling.logic.dao.FriendManager;
|
import com.ljsd.jieling.logic.dao.FriendManager;
|
||||||
import com.ljsd.jieling.logic.dao.PlayerManager;
|
import com.ljsd.jieling.logic.dao.PlayerManager;
|
||||||
|
@ -116,8 +117,20 @@ public class FriendLogic {
|
||||||
* 获取申请列表
|
* 获取申请列表
|
||||||
* @param iSession
|
* @param iSession
|
||||||
*/
|
*/
|
||||||
public void getApplyFriends(ISession iSession) {
|
public void getApplyFriends(ISession iSession) throws Exception {
|
||||||
|
int uid = iSession.getUid();
|
||||||
|
User user = UserManager.getUser(uid);
|
||||||
|
FriendManager friendManager = user.getFriendManager();
|
||||||
|
List<Integer> applyFriends = friendManager.getApplyFriends();
|
||||||
|
List<CommonProto.Friend> friendList = new CopyOnWriteArrayList<>();
|
||||||
|
for (Integer applyFriendId :applyFriends){
|
||||||
|
CommonProto.Friend friend = CBean2Proto.getFriendInfo(applyFriendId);
|
||||||
|
friendList.add(friend);
|
||||||
|
}
|
||||||
|
PlayerInfoProto.GetFriendInfoResponse getFriendInfoResponse = PlayerInfoProto.GetFriendInfoResponse
|
||||||
|
.newBuilder().addAllFriends(friendList)
|
||||||
|
.build();
|
||||||
|
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_FRIEND_INFO_REPONSE_VALUE, getFriendInfoResponse, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,6 +148,7 @@ public class FriendLogic {
|
||||||
User user = UserManager.getUser(uid);
|
User user = UserManager.getUser(uid);
|
||||||
List<Integer> friends = user.getFriendManager().getFriends();
|
List<Integer> friends = user.getFriendManager().getFriends();
|
||||||
int maxFriends = 200;
|
int maxFriends = 200;
|
||||||
|
int maxApplyFriends = 10;
|
||||||
if (friends.size() >= maxFriends){
|
if (friends.size() >= maxFriends){
|
||||||
MessageUtil.sendErrorResponse(iSession,0,msgId,"好友已达上限");
|
MessageUtil.sendErrorResponse(iSession,0,msgId,"好友已达上限");
|
||||||
}
|
}
|
||||||
|
@ -151,15 +165,83 @@ public class FriendLogic {
|
||||||
}
|
}
|
||||||
FriendManager friendManager = inviteUser.getFriendManager();
|
FriendManager friendManager = inviteUser.getFriendManager();
|
||||||
List<Integer> friends1 = friendManager.getFriends();
|
List<Integer> friends1 = friendManager.getFriends();
|
||||||
Set<Integer> applyFriends = friendManager.getApplyFriends();
|
List<Integer> applyFriends = friendManager.getApplyFriends();
|
||||||
if (applyFriends.contains(uid)){
|
if (applyFriends.contains(uid)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (friends1.size() >= maxFriends){
|
if (friends1.size() >= maxFriends){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (applyFriends.size()>= maxApplyFriends){
|
||||||
|
applyFriends.remove(0);
|
||||||
|
}
|
||||||
applyFriends.add(uid);
|
applyFriends.add(uid);
|
||||||
}
|
}
|
||||||
MessageUtil.sendMessage(iSession, 1, msgId, null, true);
|
MessageUtil.sendMessage(iSession, 1, msgId, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同意好友申请
|
||||||
|
* @param iSession
|
||||||
|
* @param type
|
||||||
|
* @param friendId
|
||||||
|
*/
|
||||||
|
public void sendAgree(ISession iSession, int type, int friendId ) throws Exception {
|
||||||
|
int msgId = MessageTypeProto.MessageType.FRIEND_INVITE_OPERATION_RESPONSE_VALUE;
|
||||||
|
int uid = iSession.getUid();
|
||||||
|
User user = UserManager.getUser(uid);
|
||||||
|
FriendManager friendManager = user.getFriendManager();
|
||||||
|
List<Integer> friends = friendManager.getFriends();
|
||||||
|
List<Integer> applyFriends = friendManager.getApplyFriends();
|
||||||
|
int maxFriends = 200;
|
||||||
|
User friendUser;
|
||||||
|
List<Integer> friendFriendList;
|
||||||
|
switch (type){
|
||||||
|
case 1://同意
|
||||||
|
if (friends.size() >= maxFriends){
|
||||||
|
MessageUtil.sendErrorResponse(iSession,0,msgId,"好友已达上限");
|
||||||
|
}
|
||||||
|
if (applyFriends.contains(friendId)){
|
||||||
|
applyFriends.remove(friendId);
|
||||||
|
}
|
||||||
|
friendUser = UserManager.getUser(friendId);
|
||||||
|
friendFriendList = friendUser.getFriendManager().getFriends();
|
||||||
|
if (friendFriendList.size() >=maxFriends){
|
||||||
|
MessageUtil.sendErrorResponse(iSession,0,msgId,"对方好友已达上限");
|
||||||
|
}
|
||||||
|
friendFriendList.add(uid);
|
||||||
|
friends.add(friendId);
|
||||||
|
break;
|
||||||
|
case 2://拒绝
|
||||||
|
applyFriends = friendManager.getApplyFriends();
|
||||||
|
if (applyFriends.contains(friendId)){
|
||||||
|
applyFriends.remove(friendId);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3://全部同意
|
||||||
|
allApplyFriend(friendId, uid, friends, applyFriends, maxFriends);
|
||||||
|
break;
|
||||||
|
case 4://全部拒绝
|
||||||
|
friendManager.setApplyFriends(new CopyOnWriteArrayList<>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MessageUtil.sendMessage(iSession, 1, msgId, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void allApplyFriend(int friendId, int uid, List<Integer> friends, List<Integer> applyFriends, int maxFriends) throws Exception {
|
||||||
|
User friendUser;
|
||||||
|
List<Integer> friendFriendList;
|
||||||
|
for (Integer applyfriendId :applyFriends){
|
||||||
|
friendUser = UserManager.getUser(applyfriendId);
|
||||||
|
friendFriendList = friendUser.getFriendManager().getFriends();
|
||||||
|
if (friends.size() >= maxFriends){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (friendFriendList.size() >= maxFriends){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
friendFriendList.add(uid);
|
||||||
|
friends.add(friendId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue