Beispiel #1
0
        /// <summary>
        /// </summary>
        /// <param name="messageModel"></param>
        /// <exception cref="ArgumentNullException">Error.InputDataIncorrect</exception>
        /// <exception cref="NotImplementedException">messageModel.Model.CreatorIcon not exist</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotConnected</exception>
        /// <exception cref="InvalidOperationException">Error.YouInAlliance</exception>
        /// <exception cref="SecurityException">Error.IsNotCurrentUser</exception>
        /// <returns></returns>
        public async Task <AllianceMessageModelExt> RequestAllianceFromMyAllianceAddMessage(
            AllianceMessageModelExt messageModel)
        {
            return(await _contextActionAsync(async connection =>
            {
                if (messageModel?.Model == null)
                {
                    throw new ArgumentNullException(Error.InputDataIncorrect);
                }
                if (string.IsNullOrWhiteSpace(messageModel.Model.CreatorIcon))
                {
                    throw new NotImplementedException(nameof(messageModel.Model.CreatorIcon));
                }

                var cr = _getLocalUser(Context.ConnectionId);
                if (cr.AllianceId != (int)NpcAllianceId.Confederation)
                {
                    throw new InvalidOperationException(Error.YouInAlliance);
                }
                if (cr.UserId != messageModel.Model.FromId || cr.Name != messageModel.Model.FromName)
                {
                    throw new SecurityException(Error.IsNotCurrentUser);
                }

                messageModel.Model.SourceType = MessageSourceType.IsUser;
                messageModel.Model.DateCreate = UnixTime.UtcNow();
                messageModel.Model = _allianceService.AddArmItem(connection, messageModel.Model);
                var groupName = ConnectionUserExtension.CreateAllianceRecrutManagerGroupName(messageModel.Model.ToId);
                await Clients.Group(groupName).InvokeAsync("requestAllianceAddMessageToAllianceManage", messageModel);
                return messageModel;
            }));
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="messageModel"></param>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotConnected</exception>
        /// <exception cref="Exception">Error.UserConnectionNotUnic (target user)</exception>
        /// <returns></returns>
        public async Task <AllianceMessageModelExt> RequestAllianceFromAllianceManageAddMessage(
            AllianceMessageModelExt messageModel)
        {
            var cid = Context.ConnectionId;

            return(await _contextActionAsync(async connection =>
            {
                var data = _requestAllianceFromAllianceManageAddMessage(connection, messageModel);
                var targetUser = _getOnlineSingleUser(connection, data.MessageModel.Model.ToId);
                if (targetUser != null && targetUser.Connected)
                {
                    await Clients.Client(targetUser.ConnectionId).InvokeAsync("requestAllianceAddMessageToMyAlliance", data.MessageModel);
                }


                var sourceUser = _getCurrentUser(connection);
                var groupName = sourceUser.CreateAllianceGroupName();



                try
                {
                    await Groups.RemoveFromGroupAsync(cid, groupName);
                    await Clients.Group(data.GroupName).InvokeAsync("requestAllianceAddMessageToAllianceManage", data);
                }
                finally
                {
                    await Groups.AddToGroupAsync(cid, groupName);
                }



                return data.MessageModel;
            }));
        }
Beispiel #3
0
        private UserRequestModel _requestAllianceFromAllianceManageAddMessage(IDbConnection connection, AllianceMessageModelExt messageModel)
        {
            if (!messageModel.FromAlliance)
            {
                throw new NotImplementedException(nameof(messageModel.FromAlliance));
            }
            var curUserManager = _getLocalUser(Context.ConnectionId);

            if (string.IsNullOrWhiteSpace(messageModel.Model.CreatorIcon))
            {
                throw new NotImplementedException(nameof(messageModel.Model.CreatorIcon));
            }
            if (messageModel.AllianceRoleId == 0 || messageModel.AllianceUserId == 0)
            {
                throw new InvalidOperationException(Error.NotPermitted);
            }
            if (curUserManager.AllianceId != messageModel.Model.FromId)
            {
                throw new SecurityException(Error.NotPermitted);
            }
            var role = AllianceRoleHelper.GetByRoleId(curUserManager.AllianceRoleId);

            if (!role.AcceptNewMembers)
            {
                throw new SecurityException(Error.NotPermitted);
            }
            if (messageModel.Model.AllianceAccepted == 0)
            {
                messageModel.Model.AllianceAccepted = ArmAllianceAcceptedStatus.NoAction;
            }
            messageModel.Model.SourceType = MessageSourceType.IsAlliance;
            messageModel.Model.DateCreate = UnixTime.UtcNow();
            messageModel.Model            = _allianceService.AddArmItem(connection, messageModel.Model);

            var groupName = curUserManager.CreateAllianceRecrutManagerGroupName();

            if (!curUserManager.HasGroup(groupName))
            {
                throw new NotImplementedException(Error.UserNotHasHubGroup);
            }
            return(new UserRequestModel
            {
                ConnectionUser = curUserManager,
                MessageModel = messageModel,
                GroupName = groupName
            });
        }
Beispiel #4
0
        /// <summary>
        /// </summary>
        /// <param name="messageModel"></param>
        /// <exception cref="ArgumentNullException">Error.InputDataIncorrect</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotConnected</exception>
        /// <exception cref="SecurityException">Error.NotPermitted message alliance id is not equal</exception>
        /// <exception cref="SecurityException">Error.NotPermitted not has role to manage</exception>
        /// <exception cref="ArgumentException">target user Error.UserInAlliance</exception>
        /// <returns></returns>
        public async Task <AllianceMessageModelExt> RequestAllianceConfirmAcceptFromAllianceManage(
            AllianceMessageModelExt messageModel)
        {
            _tryCatch(() =>
            {
                if (messageModel == null)
                {
                    throw new ArgumentNullException(Error.InputDataIncorrect, nameof(messageModel));
                }
                if (messageModel.Model.ToId == 0)
                {
                    throw new NotImplementedException(nameof(messageModel.Model.ToId));
                }
            });
            return(await _contextActionAsync(async connection =>
            {
                var tergetAllianceUser = _allianceService.GetAllianceUserByUserId(connection, messageModel.Model.ToId);

                if (tergetAllianceUser.AllianceId != (int)NpcAllianceId.Confederation)
                {
                    var curUserManager = _getLocalUser(Context.ConnectionId);
                    if (messageModel.AllianceRoleId == 0 || messageModel.AllianceUserId == 0)
                    {
                        throw new InvalidOperationException(Error.NotPermitted);
                    }
                    if (curUserManager.AllianceId != messageModel.Model.FromId)
                    {
                        throw new SecurityException(Error.NotPermitted);
                    }
                    var role = AllianceRoleHelper.GetByRoleId(curUserManager.AllianceRoleId);
                    if (!role.AcceptNewMembers)
                    {
                        throw new SecurityException(Error.NotPermitted);
                    }
                    var crGroupName = curUserManager.CreateAllianceRecrutManagerGroupName();
                    if (!curUserManager.HasGroup(crGroupName))
                    {
                        throw new NotImplementedException(Error.UserNotHasHubGroup);
                    }

                    _allianceService.DeleteAllianceRequestsByManager(connection, curUserManager.AllianceId,
                                                                     messageModel.Model.ToId, role.AcceptNewMembers);


                    var cid = curUserManager.ConnectionId;
                    try
                    {
                        await Groups.RemoveFromGroupAsync(cid, crGroupName);
                        await Clients.Group(crGroupName).InvokeAsync("onDeleteAllianceRequestsByManager",
                                                                     curUserManager.AllianceId, messageModel.Model.ToId);
                    }
                    finally
                    {
                        await Groups.AddToGroupAsync(cid, crGroupName);
                    }



                    //todo  проверить клиент почему тут исключение
                    throw new ArgumentException(Error.UserInAlliance);
                }

                messageModel.Model.AllianceAccepted = ArmAllianceAcceptedStatus.Accept;
                messageModel.FromAlliance = true;
                messageModel.Model.Message = "tr_ Confirmed";
                var data = _requestAllianceFromAllianceManageAddMessage(connection, messageModel);

                var targetUser = _getOnlineSingleUser(connection, data.MessageModel.Model.ToId);
                if (targetUser != null && targetUser.Connected)
                {
                    await Clients.Client(targetUser.ConnectionId)
                    .InvokeAsync("onRequestAllianceConfirmAcceptFromAllianceManage", data.MessageModel, true);
                }
                // Clients.Group(data.GroupName, data.ConnectionUser.ConnectionId)
                await Clients.Group(data.GroupName)
                .InvokeAsync("onRequestAllianceConfirmAcceptFromAllianceManage", data.MessageModel);
                return data.MessageModel;
            }));
        }