public MatchCreateResponse Fight(Guid managerId, Guid awayId) { var lastTime = MemcachedFactory.FriendMutexClient.Get <DateTime>(managerId); if (lastTime > DateTime.Now) { return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.FriendMatchWait)); } //好友比赛每天每个好友只能挑战3次, 只有第一次有奖励 var friend = FriendManagerMgr.GetOne(managerId, awayId); if (friend.DayMatchCount >= 3)//每日三次比赛 { return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.FriendMatchOver)); } var matchId = ShareUtil.GenerateComb(); var code = MatchCore.CreateMatchFriendAsyn(matchId, managerId, awayId, friend, MatchCallback); if (code != MessageCode.Success) { return(ResponseHelper.Create <MatchCreateResponse>(code)); } MemcachedFactory.FriendMutexClient.Set(managerId, DateTime.Now.AddSeconds(_friendMatchWaitTime)); return(ResponseHelper.MatchCreateResponse(matchId)); }
public MyBlacksResponse DeleteBlack(Guid managerId, int recordId, int pageIndex, int pageSize) { var friend = FriendManagerMgr.GetById(recordId); if (friend == null || friend.ManagerId != managerId || friend.Status != 1) { return(ResponseHelper.InvalidParameter <MyBlacksResponse>()); } var byFriend = FriendManagerMgr.GetOne(friend.FriendId, managerId); if (byFriend != null && byFriend.Status == 1) { friend.Status = 2; FriendManagerMgr.Update(friend); } else { FriendManagerMgr.Delete(friend.Idx, friend.RowVersion); if (byFriend != null && byFriend.Status == 2) { FriendManagerMgr.Delete(byFriend.Idx, byFriend.RowVersion); } } return(GetMyBlacks(managerId, pageIndex, pageSize)); }
public MessageCodeResponse AddFriend(Guid managerId, string name, bool hasTask) { var byManager = ManagerCore.Instance.GetManagerByName(name); if (byManager == null) { return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendNotExistsName)); } if (managerId == byManager.Idx) { return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendNotSelf)); } var manager = ManagerCore.Instance.GetManager(managerId); var friend = FriendManagerMgr.GetOne(managerId, byManager.Idx); if (friend != null) { if (friend.Status == 0) { return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendHasExists)); } if (friend.Status == 2) { return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendIsByBlack)); } } int returnCode = 0; FriendManagerMgr.AddFriend(managerId, byManager.Idx, _friendMaxCount, (int)MessageCode.FriendCountOver, (int)MessageCode.FriendHasExists, ref returnCode); if (returnCode == 1) //自己已在对方好友列表 { returnCode = 0; } else { InformationHelper.SendAddFriendPop(byManager.Idx, manager.Name); } if (returnCode == 0) { var response = ResponseHelper.CreateSuccess <MessageCodeResponse>(); response.Data = new MessageDataEntity(); if (hasTask) { //response.Data.PopMsg = TaskHandler.Instance.FriendAdd(managerId); } return(response); } else { return(ResponseHelper.Create <MessageCodeResponse>(returnCode)); } }
MessageCodeResponse AddBlack(Guid managerId, NbManagerEntity byManager) { if (byManager == null) { return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendNotExistsName)); } if (managerId == byManager.Idx) { return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendNotSelf)); } var friend = FriendManagerMgr.GetOne(managerId, byManager.Idx); if (friend != null && friend.Status == 1) { return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendBlackExists)); } FriendManagerMgr.AddBlack(managerId, byManager.Idx); return(ResponseHelper.CreateSuccess <MessageCodeResponse>()); }