コード例 #1
0
        public async void AddConnectionAsync(string aConnectionId, ClaimsPrincipal aUser, IGroupManager aGroups)
        {
            User CurrentUser = UserManager.Value.GetById(int.Parse(aUser.Identity.Name));

            if (CurrentUser.Role <= Role.GameMaster)
            {
                await aGroups.AddToGroupAsync(aConnectionId, RoleHubBase.AdminsGroupName);
            }
            else
            {
                await aGroups.AddToGroupAsync(aConnectionId, CurrentUser.InGameSteamId);

                var CurrentPlayer = GetPlayer(CurrentUser.InGameSteamId);
                await aGroups.AddToGroupAsync(aConnectionId, CurrentPlayer.FactionId.ToString());
            }
        }
コード例 #2
0
        private static async Task <string> _addOrReplaceGroupAsync(this ConnectionUser connectionUser,
                                                                   IGroupManager groups, int groupId, string groupName, HubGroupTypes groupType, string nativeName)
        {
            await groups.AddToGroupAsync(connectionUser.ConnectionId, groupName);

            connectionUser.Groups[groupName] = new HubGroupItem(groupId, (byte)groupType, nativeName, groupName);
            return(groupName);
        }
コード例 #3
0
ファイル: GameHubExtensions.cs プロジェクト: BrunoRM/WeStop
        public static async Task AddConnectionsToGameRoundGroupAsync(this IGroupManager groups, Guid gameId, int roundNumber, ICollection <string> connectionsIds)
        {
            string gameRoundGroupName = GetGroupName(gameId, roundNumber);

            foreach (var connectionId in connectionsIds)
            {
                await groups.AddToGroupAsync(connectionId, gameRoundGroupName);
            }
        }
コード例 #4
0
 private async Task RegisterGuildOnExistingResponse(NetworkEntityGuid guid, IGroupManager groupManager, string connectionId)
 {
     if (GuildStatusMappable[guid].isSuccessful)
     {
         //TODO: don't hardcode
         await groupManager.AddToGroupAsync(connectionId, $"guild:{GuildStatusMappable[guid].GuildId}")
         .ConfigureAwait(false);
     }
 }
コード例 #5
0
        private async Task RegisterGuildOnExistingResponse(NetworkEntityGuid guid, IGroupManager groupManager, string connectionId)
        {
            //If no guild status exists we cannot register a guild channel.
            if (!GuildStatusMappable.ContainsKey(guid))
            {
                return;
            }

            //TODO: don't hardcode
            await groupManager.AddToGroupAsync(connectionId, $"guild:{GuildStatusMappable.RetrieveEntity(guid).GuildId}")
            .ConfigureAwaitFalseVoid();
        }
コード例 #6
0
ファイル: GameHubExtensions.cs プロジェクト: BrunoRM/WeStop
 public static async Task AddConnectionToGameRoundGroupAsync(this IGroupManager groups, Guid gameId, int roundNumber, string connectionId)
 {
     string gameRoundGroupName = GetGroupName(gameId, roundNumber);
     await groups.AddToGroupAsync(connectionId, gameRoundGroupName);
 }
コード例 #7
0
 public async Task DoAfterConnected(HubCallerContext context, IGroupManager groupManager)
 {
     await HandleUserGroups(context, (connectionId, groupId) => {
         return(groupManager.AddToGroupAsync(connectionId, groupId));
     });
 }
コード例 #8
0
 public static Task AddToGroupAsync(this IGroupManager groupManager, string connectionId, Guid groupName,
                                    CancellationToken cancellationToken = default(CancellationToken))
 {
     return(groupManager.AddToGroupAsync(connectionId, groupName.ToString(), cancellationToken));
 }
コード例 #9
0
ファイル: ChatContextService.cs プロジェクト: xianhaochun/np
        /// <summary>
        /// 处理新建组
        /// </summary>
        /// <param name="cg">组信息</param>
        /// <param name="Groups"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static ActionResultVM HandelGroupNew(ChatGroupVM cg, IGroupManager Groups, Data.ContextBase db)
        {
            var vm = new ActionResultVM();

            if (cg == null)
            {
                vm.Set(ARTag.lack);
                vm.Msg = "组信息不能为空";
            }
            else if (string.IsNullOrWhiteSpace(cg.GroupName))
            {
                vm.Set(ARTag.lack);
                vm.Msg = "组名称不能为空";
            }
            else if (cg.GroupUser.Count == 0)
            {
                vm.Set(ARTag.fail);
                vm.Msg = "组用户至少有一个(默认第一个用户为管理员)";
            }

            //管理员
            var users = FindUsers(cg.GroupUser.Keys.ToList());

            if (users?.Count > 0)
            {
                var now = DateTime.Now;

                cg.GroupId = Core.UniqueTo.LongId().ToString();

                //组成员
                var listgm = new List <Domain.NChatGroupMember>();

                //用户加入组
                foreach (var user in users)
                {
                    foreach (var conn in user.Conns.Keys)
                    {
                        Groups.AddToGroupAsync(conn, cg.GroupId);
                    }

                    //添加组成员
                    listgm.Add(new Domain.NChatGroupMember()
                    {
                        CgmId         = Core.UniqueTo.LongId().ToString(),
                        CgId          = cg.GroupId,
                        CuUserId      = user.UserId,
                        CgmCreateTime = now,
                        CgmStatus     = 1
                    });
                }

                //维护组
                OnlineGroup1.Add(cg.GroupId, cg);

                //写入表
                db.NChatGroup.Add(new Domain.NChatGroup()
                {
                    CgId         = cg.GroupId,
                    CgName       = cg.GroupName,
                    CgOwnerId    = users.FirstOrDefault().UserId,
                    CgCreateTime = DateTime.Now,
                    CcId         = string.IsNullOrWhiteSpace(cg.GroupClassify) ? "1" : cg.GroupClassify,
                    CgStatus     = 1
                });
                db.NChatGroupMember.AddRange(listgm);
                db.SaveChangesAsync();

                //成功
                vm.Data = cg.GroupId;
                vm.Set(ARTag.success);
            }
            else
            {
                vm.Set(ARTag.invalid);
                vm.Msg = "组用户无效";
            }

            return(vm);
        }
コード例 #10
0
 public override Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) => _groupManager.AddToGroupAsync(connectionId, groupName, cancellationToken);