Exemple #1
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            var cid  = Context.ConnectionId;
            var user = _getLocalUser(cid);

            if (user == null)
            {
                await base.OnDisconnectedAsync(exception);

                return;
            }
            await _dbProvider.ContextActionAsync(async c =>
            {
                var userId   = user.UserId;
                var userList = _getLocalUserList(c, userId);
                if (userList == null || userList.Count == 0)
                {
                    throw new NullReferenceException(nameof(userList));
                }


                if (userList.Count == 1 && cid == userList[0].ConnectionId)
                {
                    await _cleanDisconnectedUserData(userList[0], exception);
                    _gameUserService.UpdateUserOnlineStatus(c, userId, false);
                    return(true);
                }
                var orderedUserList = userList.OrderBy(i => i.DateJoin).ToList();
                var last            = orderedUserList.Last();
                if (last.Connected && last.ConnectionId != cid)
                {
                    foreach (var u in orderedUserList.Take(orderedUserList.Count - 1))
                    {
                        await _cleanDisconnectedUserData(u, exception);
                    }
                    _gameUserService.UpdateUserOnlineStatus(c, userId, false);
                    return(true);
                }
                foreach (var u in orderedUserList)
                {
                    await _cleanDisconnectedUserData(u, exception);
                }
                _gameUserService.UpdateUserOnlineStatus(c, userId, false);
                return(true);
            });
        }
Exemple #2
0
        public Dictionary <string, object> InitUser(IDbConnection connection, ClaimsPrincipal pricipalUser, IServiceProvider resolver)
        {
            if (pricipalUser == null)
            {
                throw new NullReferenceException(nameof(pricipalUser));
            }
            var allianceService   = resolver.GetService <IAllianceService>();
            var sectorService     = resolver.GetService <IGSectorsService>();
            var estateListService = resolver.GetService <IEstateListService>();
            var systemService     = resolver.GetService <ISystemService>();
            var localizer         = resolver.GetService <ILocalizerService>();

            var tmpUser = _gameUserService.GetCurrentGameUser(connection, pricipalUser);

            if (tmpUser == null)
            {
                throw new NullReferenceException(nameof(tmpUser));
            }
            var gameUser      = _gameUserService.UpdateUserOnlineStatus(connection, tmpUser, true);
            var userChest     = _storeService.GetChestUser(connection, gameUser.Id);
            var balanceData   = (UchBalanceCcData)userChest.ActivatedItemsView[ProductTypeIds.Cc].Data;
            var up            = (UchPremiumData)userChest.ActivatedItemsView[ProductTypeIds.Premium].Data;
            var userPremiumWm = new UserPremiumWorkModel(up.Premium);

            var motherData = _mothershipService.GetMother(connection, gameUser.Id);
            var mother     =
                _synchronizer.UserMothership(connection, motherData, userPremiumWm, _mothershipService, _motherJumpService);

            var planetsData = _detailPlanetService.GetUserPlanets(connection, gameUser.Id);

            if (planetsData != null && planetsData.Any())
            {
                planetsData = _synchronizer.UserPlanets(connection, planetsData, userPremiumWm, _detailPlanetService);
            }
            _synchronizer.RunUserTasks(connection, gameUser.Id);

            var sectors      = sectorService.GetInitSectors(connection);
            var allianceUser = allianceService.GetAllianceUserByUserId(connection, gameUser.Id);
            var alliance     = allianceService.Initial(connection, allianceUser, _gameUserService);
            var personalInfo =
                _gameUserService.GetUserPlanshetProfile(connection, allianceUser.UserId, allianceUser.AllianceId, alliance, true);
            // обновляет пользователя в дб обект юзер обновляет по ссылке
            var myAlliance     = (TabMyAllianceOut)alliance.Bodys[1].TemplateData;
            var connectionUser = _gameUserService.SetConnectionUser(connection, gameUser, allianceUser, myAlliance.Name);
            //btns
            var units = HangarUnitsOut.EmptyHangar();
            var keys  = units.Keys.ToList();

            var systemGeometry = systemService.GetSystemGeometryViewData(connection, mother.StartSystemId);
            var motherEstates  = GetMotherEstate(connection, gameUser, userPremiumWm, mother, false);

            var toggleBtns = new List <IButtonsView>
            {
                ButtonsView.HangarToggle()
            };

            var leftNavBtns = new List <IButtonsView>
            {
                ButtonsView.LefMenuNavAlliance(),
                ButtonsView.LefMenuNavConfederation(),
                ButtonsView.LefMenuNavJournal(),
                ButtonsView.LefMenuNavChannels()
            };
            var mapControllBtns = MapInfoService.MapControllButtons(_localizer);
            var hangarBtns      = keys.Select(key => units[key]).Select(ButtonsView.HangarListBtns).ToList();
            //var storageModel = new StorageResources();
            //storageModel.InitializeField();

            var btns = new Dictionary <string, IReadOnlyList <IButtonsView> >
            {
                { "toggleBtns", toggleBtns },
                { "leftNavBtns", leftNavBtns },
                { "mapControllBtns", mapControllBtns },
                { "hangarBtns", hangarBtns }
            };
            var alianceNames = allianceService.GetAllianceNames(connection, false);


            var result = new Dictionary <string, object>
            {
                { localizer.TranslationKey, localizer.GetGameTranslate() },
                { ResourcesView.ViewKey, ResourcesView.GetInitList(balanceData.BalanceCc.Quantity) },
                { MapTypes.Sector.ToString(), sectors },
                { ButtonsView.BaseBtnsKey, btns },
                //todo data incorrect

                { UchView.ViewKey, userChest },
                { EstateItemOut.ViewKey, estateListService.GetList(connection, gameUser.Id) },
                { ConnectionUser.ViewKey, connectionUser },

                { alliance.UniqueId, alliance },
                { UserProfileInfo.AvatarViewKey, personalInfo },
                { EstateViewKey, motherEstates },
                { AllianceOut.AllianceNamesKey, alianceNames },
                { Planetoids.ViewKey, systemGeometry }
            };

            return(result);
        }