public async Task <IActionResult> Get()
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await HangarService.RetrieveHangarOverviews(accountSessionView.AccountID)));
     }
     return(Ok(ValidatedView <List <HangarOverview> > .Invalid(ErrorCode.OPERATION_FAILED)));
 }
 public async Task <IActionResult> Activate(int id)
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await HangarService.ActivateHangar(accountSessionView.AccountID, id)));
     }
     return(Ok(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED)));
 }
示例#3
0
 public async Task <IActionResult> CreateDiplomacy([FromBody] ClanDiplomacyCreateView clanDiplomacyCreateView)
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await ClanService.CreateDiplomacy(accountSessionView.AccountID, clanDiplomacyCreateView)));
     }
     return(Ok(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED)));
 }
示例#4
0
 public async Task <IActionResult> GetCurrent()
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await ClanService.RetrieveClanViewFromMember(accountSessionView.AccountID)));
     }
     return(Ok(ValidatedView <ClanView> .Invalid(ErrorCode.OPERATION_FAILED)));
 }
示例#5
0
 public async Task <IActionResult> Get([FromQuery] string query, [FromQuery] int offset, [FromQuery] int count)
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await ClanService.RetrieveClans(accountSessionView.AccountID, (query ?? "").ToLower(), offset, count)));
     }
     return(Ok(ValidatedView <EnumerableResultView <ClanView> > .Invalid(ErrorCode.OPERATION_FAILED)));
 }
 public async Task <IActionResult> Post([FromBody] HangarDetailView hangarDetailView)
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await HangarService.UpdateHangar(accountSessionView.AccountID, hangarDetailView)));
     }
     return(Ok(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED)));
 }
示例#7
0
 public async Task <IActionResult> GetOnlinePlayers()
 {
     return(Ok(ValidatedView <AccountPlayersOnline> .Valid(
                   new AccountPlayersOnline {
         Active = GameContext.IsRunning,
         Count = GameManager.Players.Count
     })));
 }
示例#8
0
 public async Task <IActionResult> GetPendingDiplomacies()
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await ClanService.RetrievePendingDiplomacies(accountSessionView.AccountID)));
     }
     return(Ok(ValidatedView <List <ClanDiplomacyView> > .Invalid(ErrorCode.OPERATION_FAILED)));
 }
示例#9
0
 public async Task <IActionResult> AssingRole(int id, int role)
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await ClanService.AssignRole(accountSessionView.AccountID, id, (ClanRole)role)));
     }
     return(Ok(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED)));
 }
示例#10
0
 public async Task <IActionResult> RevokeRequest(int clanId)
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await ClanService.RevokeJoinRequest(accountSessionView.AccountID, clanId)));
     }
     return(Ok(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED)));
 }
示例#11
0
        public static async Task <ValidatedView <AccountView> > RetrieveAccount(int accountId)
        {
            try {
                AccountModel accountModel = await Model <AccountModel> .AsQueryable()
                                            .FirstOrDefault(x => x.ID == accountId);

                if (accountModel == null)
                {
                    return(ValidatedView <AccountView> .Invalid(ErrorCode.ACCOUNT_NOT_FOUND));
                }

                AccountView accountView = Mapper <AccountModel> .Map <AccountView>(accountModel);

                accountView.GGRings = 64;

                ValidatedView <HangarView> validatedHangarView = await HangarService.RetrieveHangar(accountModel.ID, accountModel.ActiveShipID);

                if (!validatedHangarView.IsValid)
                {
                    return(ValidatedView <AccountView> .Invalid(validatedHangarView.Message));
                }
                accountView.CurrentHangar = validatedHangarView.Object;

                ValidatedView <VaultView> validatedVaultView = await RetrieveVault(accountId);

                if (!validatedVaultView.IsValid)
                {
                    return(ValidatedView <AccountView> .Invalid(validatedVaultView.Message));
                }
                accountView.Vault = validatedVaultView.Object;

                ValidatedView <CooldownView> validatedCooldownView = await RetrieveCooldown(accountId);

                if (!validatedCooldownView.IsValid)
                {
                    return(ValidatedView <AccountView> .Invalid(validatedCooldownView.Message));
                }
                accountView.Cooldown = validatedCooldownView.Object;

                accountView.Clan = new ClanOverview();
                ValidatedView <ClanOverview> validatedClanOverview = await ClanService.RetrieveClanOverviewFromMember(accountId);

                if (validatedClanOverview.IsValid && validatedClanOverview.Object != null)
                {
                    accountView.Clan = validatedClanOverview.Object;
                }

                return(ValidatedView <AccountView> .Valid(accountView));
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <AccountView> .Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#12
0
        public static async Task <ValidatedView> UpdateAccount(AccountView accountView)
        {
            try {
                AccountModel accountModel = await Model <AccountModel> .AsQueryable()
                                            .Where(x => x.ID == accountView.ID).FirstOrDefault();

                if (accountModel == null)
                {
                    return(ValidatedView.Invalid(ErrorCode.ACCOUNT_NOT_FOUND));
                }

                bool success = true;

                ReplaceOneResult result = await Model <AccountModel> .AsCollection()
                                          .ReplaceOneAsync(x => x.ID == accountView.ID,
                                                           Mapper <AccountView> .Map(accountView, accountModel));

                success &= result.IsModifiedCountAvailable && result.ModifiedCount == 1;

                ValidatedView validatedHangarResultView = await HangarService
                                                          .UpdateHangar(accountView.ID, accountView.CurrentHangar);

                if (!validatedHangarResultView.IsValid)
                {
                    GameContext.Logger.LogInformation($"Player: '{accountView.ID}': {validatedHangarResultView.Message}");
                }
                success &= validatedHangarResultView.IsValid;

                ValidatedView validatedVaultResultView = await UpdateVault(accountView.ID, accountView.Vault);

                if (!validatedVaultResultView.IsValid)
                {
                    GameContext.Logger.LogInformation($"Player: '{accountView.ID}': {validatedVaultResultView.Message}");
                }
                success &= validatedVaultResultView.IsValid;

                ValidatedView validatedCooldownResultView = await UpdateCooldown(accountView.ID, accountView.Cooldown);

                if (!validatedCooldownResultView.IsValid)
                {
                    GameContext.Logger.LogInformation($"Player: '{accountView.ID}': {validatedCooldownResultView.Message}");
                }
                success &= validatedCooldownResultView.IsValid;

                if (success)
                {
                    return(ValidatedView.Valid());
                }
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#13
0
        public static async Task <ValidatedView> CreateClan(int accountId, ClanCreateView clanCreateView)
        {
            if (!clanCreateView.IsValid(out string message))
            {
                return(ValidatedView.Invalid(message));
            }

            try {
                if (await Model <ClanMemberModel> .AsQueryable().Any(x => x.AccountID == accountId))
                {
                    GameContext.Logger.LogCritical($"Player [id: '{accountId}'] tries creating a clan while being member of another!");
                    return(ValidatedView.Invalid(ErrorCode.CLAN_ALREADY_MEMBER));
                }

                if (await Model <ClanModel> .AsQueryable().Any(x => x.Name == clanCreateView.Name))
                {
                    return(ValidatedView.Invalid(ErrorCode.CLAN_NAME_ALREADY_IN_USE));
                }

                if (await Model <ClanModel> .AsQueryable().Any(x => x.Tag == clanCreateView.Tag))
                {
                    return(ValidatedView.Invalid(ErrorCode.CLAN_TAG_ALREADY_IN_USE));
                }

                ClanModel clanModel = Mapper <ClanCreateView> .Map <ClanModel>(clanCreateView);

                ClanMemberModel clanMemberModel = new ClanMemberModel {
                    ClanID = clanModel.ID, AccountID = accountId, Role = ClanRole.LEADER
                };

                await Model <ClanMemberPendingModel> .AsCollection().DeleteManyAsync(x => x.AccountID == accountId);

                await Model <ClanModel> .AsCollection().InsertOneAsync(clanModel);

                await Model <ClanMemberModel> .AsCollection().InsertOneAsync(clanMemberModel);

                if (GameManager.Get(accountId, out PlayerController controller))
                {
                    controller.Account.Clan = Mapper <ClanModel> .Map <ClanOverview>(clanModel);

                    ClanChangedCommand clanChangedCommand = PacketBuilder.ClanChangedCommand(controller);
                    controller.Send(clanChangedCommand);
                    controller.EntitesInRange(x => x.Send(clanChangedCommand));
                }

                return(ValidatedView.Valid());
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#14
0
        public static async Task <ValidatedView> AcceptJoinRequest(int accountId, int targetId)
        {
            try {
                ClanMemberModel clanMemberModel = await Model <ClanMemberModel> .AsQueryable()
                                                  .FirstOrDefault(x => x.AccountID == accountId);

                if (clanMemberModel == null || clanMemberModel.Role < ClanRole.VICE_LEADER)
                {
                    return(ValidatedView.Invalid(ErrorCode.CLAN_ACCEPT_MEMBER_INSUFFICIENT_RIGHTS));
                }

                if (await Model <ClanMemberModel> .AsQueryable().Count(x => x.ClanID == clanMemberModel.ClanID) >= 50)
                {
                    return(ValidatedView.Invalid(ErrorCode.CLAN_FULL));
                }

                ClanMemberPendingModel clanMemberPendingModel = await Model <ClanMemberPendingModel> .AsQueryable()
                                                                .FirstOrDefault(x => x.AccountID == targetId && x.ClanID == clanMemberModel.ClanID);

                if (clanMemberPendingModel == null)
                {
                    return(ValidatedView.Invalid(ErrorCode.CLAN_PENDING_DID_NOT_REQUEST));
                }

                ClanMemberModel newClanMemberModel = new ClanMemberModel {
                    ClanID = clanMemberModel.ClanID, AccountID = targetId
                };
                await Model <ClanMemberPendingModel> .AsCollection().DeleteManyAsync(x => x.AccountID == targetId);

                await Model <ClanMemberModel> .AsCollection().InsertOneAsync(newClanMemberModel);

                if (GameManager.Get(accountId, out PlayerController controller))
                {
                    ValidatedView <ClanOverview> validatedView = await RetrieveClanOverviewFromMember(accountId);

                    if (validatedView.IsValid)
                    {
                        controller.Account.Clan = validatedView.Object ?? new ClanOverview();
                    }

                    ClanChangedCommand clanChangedCommand = PacketBuilder.ClanChangedCommand(controller);
                    controller.Send(clanChangedCommand);
                    controller.EntitesInRange(x => x.Send(clanChangedCommand));
                }

                return(ValidatedView.Valid());
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#15
0
        public static async Task <ValidatedView <List <ClanDiplomacyView> > > RetrievePendingDiplomacies(int accountId)
        {
            try {
                ClanMemberModel clanMemberModel = await Model <ClanMemberModel>
                                                  .AsQueryable().FirstOrDefault(x => x.AccountID == accountId);

                if (clanMemberModel != null)
                {
                    ClanModel clanModel = await Model <ClanModel> .AsQueryable()
                                          .FirstOrDefault(x => x.ID == clanMemberModel.ClanID);

                    if (clanModel == null)
                    {
                        return(ValidatedView <List <ClanDiplomacyView> > .Invalid(ErrorCode.CLAN_NOT_FOUND));
                    }
                    else
                    {
                        List <ClanDiplomacyView> diplomacies = new List <ClanDiplomacyView>();
                        foreach (ClanRelationPendingModel clanRelationModel in await Model <ClanRelationPendingModel>
                                 .AsQueryable().Where(x => x.InitiatorID == clanModel.ID || x.TargetID == clanModel.ID)
                                 .ToList())
                        {
                            ClanDiplomacyView clanDiplomacyView = Mapper <ClanRelationPendingModel> .Map <ClanDiplomacyView>(clanRelationModel);

                            ValidatedView <ClanView> validatedView = await RetrieveClan(accountId,
                                                                                        (clanRelationModel.InitiatorID == clanModel.ID ? clanRelationModel.TargetID
                                : clanRelationModel.InitiatorID));

                            if (!validatedView.IsValid)
                            {
                                GameContext.Logger.LogWarning($"Failed to load pending diplomacy for {clanModel.ID}!");
                                continue;
                            }

                            clanDiplomacyView.Clan = validatedView.Object;
                            diplomacies.Add(clanDiplomacyView);
                        }

                        return(ValidatedView <List <ClanDiplomacyView> > .Valid(diplomacies));
                    }
                }
                else
                {
                    return(ValidatedView <List <ClanDiplomacyView> > .Invalid(ErrorCode.CLAN_NOT_MEMBER));
                }
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <List <ClanDiplomacyView> > .Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#16
0
 public async Task <IActionResult> Get()
 {
     return(Ok(ValidatedView <ShopView> .Valid(new ShopView {
         Categories = new Dictionary <string, ShopCategoryView> {
             { "Drones", new ShopCategoryView {
                   Items = new Dictionary <string, ShopItemView> {
                       { "", new ShopItemView {
                             Name = "LF-2", Identifier = "weapon_lf-2"
                         } }
                   }
               } }
         }
     })));
 }
示例#17
0
        public static async Task <ValidatedView> Register(AccountRegisterView accountRegisterView)
        {
            if (!accountRegisterView.IsValid(out string message))
            {
                return(ValidatedView.Invalid(message));
            }

            try {
                if (await Model <AccountModel> .AsQueryable()
                    .Any(x => x.Username == accountRegisterView.Username))
                {
                    return(ValidatedView.Invalid(ErrorCode.USERNAME_ALREADY_IN_USE));
                }

                AccountModel accountModel = new AccountModel(accountRegisterView.Username,
                                                             accountRegisterView.Password, accountRegisterView.Email, accountRegisterView.Faction);

                int tries = 5;
                while (await Model <AccountModel> .AsQueryable().Any(x => x.ID == accountModel.ID))
                {
                    accountModel.ID = RandomGenerator.UniqueIdentifier();

                    if (tries-- == 0)
                    {
                        return(ValidatedView.Invalid(ErrorCode.PROBLEM_WHILE_CREATING_ACCOUNT));
                    }
                }

                AccountVaultModel  accountVaultModel = new AccountVaultModel(accountModel.ID);
                List <HangarModel> hangarModels      = accountVaultModel.Ships
                                                       .Select(ship => new HangarModel(accountModel.ID, ship, accountModel.FactionID))
                                                       .ToList();

                await Model <AccountModel> .AsCollection().InsertOneAsync(accountModel);

                await Model <AccountChatModel> .AsCollection().InsertOneAsync(new AccountChatModel(accountModel.ID));

                await Model <AccountCooldownModel> .AsCollection().InsertOneAsync(new AccountCooldownModel(accountModel.ID));

                await Model <AccountVaultModel> .AsCollection().InsertOneAsync(accountVaultModel);

                await Model <HangarModel> .AsCollection().InsertManyAsync(hangarModels);

                return(ValidatedView.Valid());
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
        public static async Task <GlobalRole> GetCurrentUserRole(this HttpContext context)
        {
            if (!TryGetCurrentSession(context, out AccountSessionView accountSession))
            {
                return(GlobalRole.NONE);
            }

            ValidatedView <GlobalRole> validatedAuthenticateView =
                await AccountService.Authenticate(accountSession);

            if (!validatedAuthenticateView.IsValid)
            {
                return(GlobalRole.NONE);
            }

            return(validatedAuthenticateView.Object);
        }
        public static async Task <ValidatedView> UpdateHangar(int accountId, HangarDetailView hangarDetailView)
        {
            if (!hangarDetailView.IsValid(out string message))
            {
                return(ValidatedView.Invalid(message));
            }

            try {
                if (GameManager.Get(accountId, out PlayerController controller) && !controller.ZoneAssembly.CanEquip)
                {
                    return(ValidatedView.Invalid(ErrorCode.EQUIPMENT_NOT_POSSIBLE));
                }

                HangarModel hangarModel = await Model <HangarModel> .AsQueryable()
                                          .FirstOrDefault(x => x.AccountID == accountId && x.ShipID == hangarDetailView.ShipID);

                if (hangarModel == null)
                {
                    return(ValidatedView <HangarView> .Invalid(ErrorCode.NO_HANGAR_FOUND));
                }

                if (controller != null && controller.HangarAssembly.Ship.ID == hangarDetailView.ShipID)
                {
                    HangarView hangarView = Mapper <HangarModel> .Map <HangarView>(hangarModel);

                    hangarView.Configuration_1 = hangarDetailView.Configuration_1;
                    hangarView.Configuration_2 = hangarDetailView.Configuration_2;

                    UpdateHangarIngame(accountId, hangarView);
                }
                else
                {
                    hangarModel.Configuration_1 = Mapper <ConfigurationView> .Map <Configuration>(hangarDetailView.Configuration_1);

                    hangarModel.Configuration_2 = Mapper <ConfigurationView> .Map <Configuration>(hangarDetailView.Configuration_2);

                    ReplaceOneResult result = await Model <HangarModel> .AsCollection()
                                              .ReplaceOneAsync(x => x.AccountID == accountId && x.ShipID == hangarDetailView.ShipID, hangarModel);
                }

                return(ValidatedView.Valid());
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#20
0
        public static async Task <ValidatedView <ClanView> > RetrieveClanViewFromMember(int accountId)
        {
            try {
                ClanMemberModel clanMemberModel = await Model <ClanMemberModel>
                                                  .AsQueryable().FirstOrDefault(x => x.AccountID == accountId);

                if (clanMemberModel != null)
                {
                    return(await RetrieveClan(accountId, clanMemberModel.ClanID));
                }

                return(ValidatedView <ClanView> .Valid(null));
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <ClanView> .Invalid(ErrorCode.OPERATION_FAILED));
        }
        public void Execute(IClient initiator, LoginRequest command)
        {
            // dummes spiel amk
            command.sessionID = command.sessionID.Replace("\0", "").Trim();

            Task.Run(async() => {
                try {
                    AccountSessionView session        = new AccountSessionView(command.userID, command.sessionID);
                    ValidatedView <GlobalRole> result = await AccountService.Authenticate(session);
                    if (result.IsValid)
                    {
                        if (GameManager.Get(command.userID, out _))
                        {
                            GameManager.Attach(command.userID, initiator as GameConnectionHandler,
                                               null, command.version.Replace("\0", "").Trim().Length != 0);
                            return;
                        }

                        ValidatedView <AccountView> validatedAccountView = await AccountService.RetrieveAccount(session.AccountID);
                        if (validatedAccountView.IsValid)
                        {
                            validatedAccountView.Object.CurrentHangar.Check(initiator.Logger,
                                                                            validatedAccountView.Object.ID, validatedAccountView.Object.Vault);
                            validatedAccountView.Object.CurrentHangar.Calculate();

                            GameManager.Attach(validatedAccountView.Object.ID, initiator as GameConnectionHandler,
                                               validatedAccountView.Object, command.version.Replace("\0", "").Trim().Length != 0);
                        }
                        else
                        {
                            initiator.Logger.LogError(new Exception($"Player: '{session.AccountID}': {validatedAccountView.Message}"));
                            initiator.Dispose();
                        }
                    }
                    else
                    {
                        initiator.Send(PacketBuilder.InvalidSession());
                        initiator.Dispose();
                    }
                } catch (Exception e) {
                    initiator.Logger.LogError(e);
                    initiator.Dispose();
                }
            });
        }
示例#22
0
        public static async Task <ValidatedView> RevokeJoinRequest(int accountId, int clanId)
        {
            try {
                var result = await Model <ClanMemberPendingModel>
                             .AsCollection()
                             .DeleteOneAsync(x => x.AccountID == accountId && x.ClanID == clanId);

                if (result.DeletedCount == 0)
                {
                    return(ValidatedView.Invalid(ErrorCode.CLAN_FAILED_TO_REVOKE_REQUEST));
                }

                return(ValidatedView.Valid());
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#23
0
        public static async Task <ValidatedView> UpdateCooldown(int accountId, CooldownView cooldown)
        {
            try {
                ReplaceOneResult result = await Model <AccountCooldownModel> .AsCollection()
                                          .ReplaceOneAsync(x => x.AccountID == accountId, Mapper <CooldownView>
                                                           .Map(cooldown, new AccountCooldownModel {
                    AccountID = accountId
                }));

                if (result.IsModifiedCountAvailable && result.ModifiedCount == 1)
                {
                    return(ValidatedView.Valid());
                }
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
        public static async Task <ValidatedView> ActivateHangar(int accountId, int shipId)
        {
            try {
                if (GameManager.Get(accountId, out PlayerController controller) && !controller.ZoneAssembly.CanEquip)
                {
                    return(ValidatedView.Invalid(ErrorCode.EQUIPMENT_NOT_POSSIBLE));
                }

                HangarModel hangarModel = await Model <HangarModel> .AsQueryable()
                                          .FirstOrDefault(x => x.AccountID == accountId && x.ShipID == shipId);

                if (hangarModel == null)
                {
                    return(ValidatedView <HangarView> .Invalid(ErrorCode.NO_HANGAR_FOUND));
                }

                if (await Model <AccountModel> .AsQueryable()
                    .Any(x => x.ID == accountId && x.ActiveShipID == shipId))
                {
                    return(ValidatedView.Invalid(ErrorCode.HANGAR_ALREADY_ACTIVE));
                }

                if (controller != null)
                {
                    HangarView hangarView = Mapper <HangarModel> .Map <HangarView>(hangarModel);

                    hangarView.Configuration_1 = Mapper <Configuration> .Map <ConfigurationView>(hangarModel.Configuration_1);

                    hangarView.Configuration_2 = Mapper <Configuration> .Map <ConfigurationView>(hangarModel.Configuration_2);

                    UpdateHangarIngame(accountId, hangarView);
                }

                await Model <AccountModel> .AsCollection()
                .UpdateOneAsync(x => x.ID == accountId,
                                new UpdateDefinitionBuilder <AccountModel>()
                                .Set(x => x.ActiveShipID, shipId));

                return(ValidatedView.Valid());
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#25
0
        public static async Task <ValidatedView <int> > RetrieveLeaderID(int clanId)
        {
            try {
                int?leaderId = await Model <ClanMemberModel> .AsQueryable()
                               .Where(x => x.ClanID == clanId && x.Role == ClanRole.LEADER)
                               .Select(x => (int?)x.AccountID)
                               .FirstOrDefault();

                if (!leaderId.HasValue)
                {
                    return(ValidatedView <int> .Invalid(ErrorCode.CLAN_NOT_FOUND));
                }

                return(ValidatedView <int> .Valid(leaderId.Value));
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <int> .Invalid(ErrorCode.OPERATION_FAILED));
        }
        public static async Task <ValidatedView <HangarDetailView> > RetrieveHangarDetailView(int accountId, int shipId)
        {
            try {
                ValidatedView <HangarView> validatedHangarView = await RetrieveHangar(accountId, shipId);

                if (!validatedHangarView.IsValid)
                {
                    return(ValidatedView <HangarDetailView> .Invalid(validatedHangarView.Message));
                }

                HangarDetailView hangarDetailView = Mapper <HangarView> .Map <HangarDetailView>(validatedHangarView.Object);

                hangarDetailView.IsActive = await Model <AccountModel> .AsQueryable()
                                            .Any(x => x.ID == accountId && x.ActiveShipID == shipId);

                return(ValidatedView <HangarDetailView> .Valid(hangarDetailView));
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <HangarDetailView> .Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#27
0
        public static async Task <ValidatedView <EnumerableResultView <ClanView> > > RetrieveClans(int accountId, string query, int offset, int count)
        {
            try {
                int totalCount = await Model <ClanModel> .AsQueryable().Count();

                List <ClanView> clanViews = new List <ClanView>();

                List <int> pending = await Model <ClanMemberPendingModel> .AsQueryable()
                                     .Where(x => x.AccountID == accountId).Select(x => x.ClanID).ToList();

                List <int> clans = await Model <ClanModel> .AsQueryable().Where(x => pending.Contains(x.ID) && x.Name.ToLower().Contains(query) && x.Tag.ToLower().Contains(query)).OrderBy(x => x.Points)
                                   .Union(Model <ClanModel> .AsQueryable().Where(x => !pending.Contains(x.ID) && x.Name.ToLower().Contains(query) && x.Tag.ToLower().Contains(query)).OrderBy(x => x.Points))
                                   .Skip(Math.Max(0, offset))
                                   .Take(Math.Max(0, Math.Min(count, 50)))
                                   .Select(x => x.ID)
                                   .ToList();

                foreach (int id in clans)
                {
                    ValidatedView <ClanView> validatedView = await RetrieveClan(accountId, id);

                    if (validatedView.IsValid)
                    {
                        clanViews.Add(validatedView.Object);
                    }
                    else
                    {
                        GameContext.Logger.LogWarning($"Clan retrieval failed: {validatedView.Message}");
                    }
                }

                return(ValidatedView <EnumerableResultView <ClanView> >
                       .Valid(new EnumerableResultView <ClanView>(Math.Max(0, offset), clanViews.Count,
                                                                  totalCount, clanViews)));
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <EnumerableResultView <ClanView> > .Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#28
0
        public static async Task <ValidatedView <ClanView> > RetrieveClan(int accountId, int clanId)
        {
            try {
                ClanModel clanModel = await Model <ClanModel> .AsQueryable().FirstOrDefault(x => x.ID == clanId);

                if (clanModel == null)   // wtf kann nd sein
                {
                    return(ValidatedView <ClanView> .Invalid(ErrorCode.CLAN_NOT_FOUND));
                }

                ClanView clanOverview = Mapper <ClanModel> .Map <ClanView>(clanModel);

                clanOverview.LeaderUsername = "";
                ValidatedView <int> validatedLeaderIDView = await RetrieveLeaderID(clanModel.ID);

                if (validatedLeaderIDView.IsValid)
                {
                    ValidatedView <string> validedLeaderUsernameView = await AccountService.RetrieveUsername(validatedLeaderIDView.Object);

                    if (validedLeaderUsernameView.IsValid)
                    {
                        clanOverview.LeaderUsername = validedLeaderUsernameView.Object;
                    }
                }

                clanOverview.MembersCount = await Model <ClanMemberModel> .AsQueryable().Count(x => x.ClanID == clanModel.ID);

                if (await Model <ClanMemberPendingModel> .AsQueryable()
                    .Any(x => x.AccountID == accountId && x.ClanID == clanId))
                {
                    clanOverview.Pending = true;
                }

                return(ValidatedView <ClanView> .Valid(clanOverview));
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <ClanView> .Invalid(ErrorCode.OPERATION_FAILED));
        }
        public static async Task <ValidatedView <HangarView> > RetrieveHangar(int accountId, int shipId)
        {
            try {
                HangarModel hangarModel = await Model <HangarModel> .AsQueryable()
                                          .FirstOrDefault(x => x.AccountID == accountId && x.ShipID == shipId);

                if (hangarModel == null)
                {
                    return(ValidatedView <HangarView> .Invalid(ErrorCode.NO_HANGAR_FOUND));
                }

                HangarView hangarView = Mapper <HangarModel> .Map <HangarView>(hangarModel);

                hangarView.Configuration_1 = Mapper <Configuration> .Map <ConfigurationView>(hangarModel.Configuration_1);

                hangarView.Configuration_2 = Mapper <Configuration> .Map <ConfigurationView>(hangarModel.Configuration_2);

                return(ValidatedView <HangarView> .Valid(hangarView));
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <HangarView> .Invalid(ErrorCode.OPERATION_FAILED));
        }
示例#30
0
        public bool RevokeJoinRequest(ClanView clanView, out string message, out HttpStatusCode code)
        {
            message = ErrorCode.CONNECTION_FAILED;

            Api().CreateAuthenticated($"api/clan/request/{clanView.ID}", "delete")
            .Execute(out HttpWebResponse response);

            if (response.TryGetStatusCode(out code) && code == HttpStatusCode.OK)
            {
                ValidatedView validatedView = response.GetReponseString()
                                              .DeserializeJsonSafe <ValidatedView>();
                if (validatedView == null)
                {
                    message = ErrorCode.ERROR_WHILE_READING_RESULT;
                }
                else
                {
                    message = validatedView.Message;
                    return(validatedView.IsValid);
                }
            }

            return(false);
        }