Exemplo n.º 1
0
        public bool RetrieveSelf(out AccountClanView accountClanView, out string message, out HttpStatusCode code)
        {
            message         = ErrorCode.CONNECTION_FAILED;
            accountClanView = null;

            Api().CreateAuthenticated("api/clan/current/members/self", "get")
            .Execute(out HttpWebResponse response);

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

            return(false);
        }
Exemplo n.º 2
0
        public static async Task <ValidatedView <AccountClanView> > RetrieveSelf(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)
                    {
                        GameContext.Logger.LogWarning($"Player [id: '{accountId}'] is member of a clan [id: '{clanMemberModel.ClanID}'] which does not even exist");
                    }
                    else
                    {
                        AccountClanView accountClanView = new AccountClanView {
                            Role     = clanMemberModel.Role,
                            JoinDate = clanMemberModel.CreationDate
                        };

                        if (GameManager.Players.TryGetValue(clanMemberModel.AccountID, out PlayerController controller))
                        {
                            accountClanView = Mapper <AccountView> .Map(controller.Account, accountClanView);

                            accountClanView.ActiveShipID = controller.Account.CurrentHangar.ShipID;
                            accountClanView.Online       = true;
                            accountClanView.Map          = controller.HangarAssembly.Map.Name;

                            Position actualPosition = controller.MovementAssembly.ActualPosition();
                            accountClanView.Position = (actualPosition.X, actualPosition.Y);
                        }
                        else
                        {
                            AccountModel accountModel = await Model <AccountModel> .AsQueryable()
                                                        .FirstOrDefault(x => x.ID == clanMemberModel.AccountID);

                            if (accountModel == null)
                            {
                                GameContext.Logger.LogCritical($"Player [id: '{clanMemberModel.AccountID}'] not found!");
                                return(ValidatedView <AccountClanView> .Invalid(ErrorCode.ACCOUNT_NOT_FOUND));
                            }

                            accountClanView = Mapper <AccountModel> .Map(accountModel, accountClanView);
                        }

                        return(ValidatedView <AccountClanView> .Valid(accountClanView));
                    }
                }
                else
                {
                    return(ValidatedView <AccountClanView> .Invalid(ErrorCode.CLAN_NOT_MEMBER));
                }
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <AccountClanView> .Invalid(ErrorCode.OPERATION_FAILED));
        }
Exemplo n.º 3
0
 protected void Change(AccountClanView selected)
 {
     Selected = selected;
 }
Exemplo n.º 4
0
 protected void Kick(AccountClanView selected)
 {
 }
Exemplo n.º 5
0
        public static async Task <ValidatedView <List <AccountClanView> > > RetrievePendingFromMember(int accountId)
        {
            try {
                List <AccountClanView> accountClanViews = new List <AccountClanView>();

                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)
                    {
                        GameContext.Logger.LogWarning($"Player [id: '{accountId}'] is member of a clan [id: '{clanMemberModel.ClanID}'] which does not even exist");
                    }
                    else
                    {
                        foreach (ClanMemberPendingModel pendingMember in await Model <ClanMemberPendingModel>
                                 .AsQueryable()
                                 .Where(x => x.ClanID == clanModel.ID).ToList())
                        {
                            AccountClanView accountClanView = new AccountClanView {
                                JoinDate = pendingMember.CreationDate,
                                Message  = pendingMember.Message
                            };

                            if (GameManager.Players.TryGetValue(pendingMember.AccountID, out PlayerController controller))
                            {
                                accountClanView = Mapper <AccountView> .Map(controller.Account, accountClanView);

                                accountClanView.ActiveShipID = controller.Account.CurrentHangar.ShipID;
                                accountClanView.Online       = true;
                                accountClanView.Map          = controller.HangarAssembly.Map.Name;
                            }
                            else
                            {
                                AccountModel accountModel = await Model <AccountModel> .AsQueryable()
                                                            .FirstOrDefault(x => x.ID == pendingMember.AccountID);

                                if (accountModel == null)
                                {
                                    GameContext.Logger.LogCritical($"Player [id: '{pendingMember.AccountID}'] not found!");
                                    continue;
                                }

                                accountClanView = Mapper <AccountModel> .Map(accountModel, accountClanView);
                            }

                            accountClanViews.Add(accountClanView);
                        }
                    }
                }
                else
                {
                    return(ValidatedView <List <AccountClanView> > .Invalid(ErrorCode.CLAN_NOT_MEMBER));
                }

                return(ValidatedView <List <AccountClanView> > .Valid(accountClanViews));
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <List <AccountClanView> > .Invalid(ErrorCode.OPERATION_FAILED));
        }