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()); } }
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); }
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); } }
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); } }
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(); }
public static async Task AddConnectionToGameRoundGroupAsync(this IGroupManager groups, Guid gameId, int roundNumber, string connectionId) { string gameRoundGroupName = GetGroupName(gameId, roundNumber); await groups.AddToGroupAsync(connectionId, gameRoundGroupName); }
public async Task DoAfterConnected(HubCallerContext context, IGroupManager groupManager) { await HandleUserGroups(context, (connectionId, groupId) => { return(groupManager.AddToGroupAsync(connectionId, groupId)); }); }
public static Task AddToGroupAsync(this IGroupManager groupManager, string connectionId, Guid groupName, CancellationToken cancellationToken = default(CancellationToken)) { return(groupManager.AddToGroupAsync(connectionId, groupName.ToString(), cancellationToken)); }
/// <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); }
public override Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) => _groupManager.AddToGroupAsync(connectionId, groupName, cancellationToken);