public async Task <dynamic> addBuddy([FromBody] BuddyDTO buddyReq)
        {
            AccountFriend  existingFriend  = db.AccountFriend.Where(af => af.AccountId == buddyReq.AccountId && af.FriendAccountId == buddyReq.BuddyAccountId).FirstOrDefault();
            AccountIgnored existingIgnored = db.AccountIgnored.Where(af => af.AccountId == buddyReq.AccountId && af.IgnoredAccountId == buddyReq.BuddyAccountId).FirstOrDefault();

            if (existingFriend != null)
            {
                return(StatusCode(403, "Buddy already exists."));
            }

            if (existingIgnored != null)
            {
                db.AccountIgnored.Attach(existingIgnored);
                db.Entry(existingIgnored).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            }

            AccountFriend newFriend = new AccountFriend()
            {
                AccountId       = buddyReq.AccountId,
                FriendAccountId = buddyReq.BuddyAccountId,
                CreateDt        = DateTime.UtcNow
            };

            db.AccountFriend.Add(newFriend);
            db.SaveChanges();

            return(Ok("Buddy Added"));
        }
        public async Task <dynamic> initStats(int AccountId)
        {
            AccountController ac          = new AccountController(db, authService);
            AccountDTO        existingAcc = await ac.getAccount(AccountId);

            if (existingAcc == null)
            {
                return(BadRequest($"Account Id {AccountId} doesn't exist."));
            }

            if (existingAcc.AccountWideStats.Count() > 0)
            {
                return(StatusCode(403, "This account already has stats."));
            }

            List <AccountStat> newStats = (from ds in db.DimStats
                                           select new AccountStat()
            {
                AccountId = existingAcc.AccountId,
                StatId = ds.StatId,
                StatValue = ds.DefaultValue
            }).ToList();

            db.AccountStat.AddRange(newStats);
            db.SaveChanges();

            return(Ok("Stats Created"));
        }
Esempio n. 3
0
        public async Task <dynamic> createGame([FromBody] GameDTO game)
        {
            Game newGame = new Game()
            {
                GameId            = game.GameId,
                AppId             = game.AppId,
                MinPlayers        = game.MinPlayers,
                MaxPlayers        = game.MaxPlayers,
                PlayerCount       = game.PlayerCount,
                GameLevel         = game.GameLevel,
                PlayerSkillLevel  = game.PlayerSkillLevel,
                GameStats         = game.GameStats,
                GameName          = game.GameName,
                RuleSet           = game.RuleSet,
                PlayerListCurrent = game.PlayerListCurrent,
                PlayerListStart   = game.PlayerListStart,
                GenericField1     = game.GenericField1,
                GenericField2     = game.GenericField2,
                GenericField3     = game.GenericField3,
                GenericField4     = game.GenericField4,
                GenericField5     = game.GenericField5,
                GenericField6     = game.GenericField6,
                GenericField7     = game.GenericField7,
                GenericField8     = game.GenericField8,
                WorldStatus       = game.WorldStatus,
                GameHostType      = game.GameHostType,
                Metadata          = game.Metadata,
                GameCreateDt      = game.GameCreateDt ?? DateTime.UtcNow,
            };

            db.Game.Add(newGame);
            db.SaveChanges();

            return(Ok());
        }
Esempio n. 4
0
        public async Task <dynamic> deleteEULA(int id)
        {
            var eula = db.DimEula.FirstOrDefault(x => x.Id == id);

            if (eula == null)
            {
                return(StatusCode(403, "Cannot delete an eula entry that doesn't exist."));
            }

            db.DimEula.Remove(eula);
            db.SaveChanges();

            return(Ok("EULA Deleted"));
        }
Esempio n. 5
0
        public IActionResult error()
        {
            var context = HttpContext;

            var exceptionContext = HttpContext.Features.Get <IExceptionHandlerFeature>();

            context.Request.Body.Position = 0;
            using (StreamReader stream = new StreamReader(context.Request.Body))
            {
                string rbody = stream.ReadToEndAsync().Result;


                var payload = new
                {
                    query          = context.Request.QueryString.Value,
                    body           = rbody,
                    innerException = exceptionContext.Error.InnerException
                };
                context.Request.Body.Position = 0;
                string payloadString = JsonConvert.SerializeObject(payload, Formatting.Indented);

                RollBack();
                ServerLog log = new ServerLog()
                {
                    LogDt         = DateTime.UtcNow,
                    AccountId     = null,
                    MethodName    = context.Request.Path.ToString(),
                    LogTitle      = "Internal Error",
                    LogMsg        = exceptionContext.Error.Message,
                    LogStacktrace = exceptionContext.Error.StackTrace,
                    Payload       = payloadString,
                };
                db.ServerLog.Add(log);
                db.SaveChanges();
            }



            return(Problem());
        }
        public async Task <dynamic> createAccount([FromBody] AccountRequestDTO request)
        {
            DateTime now             = DateTime.UtcNow;
            Account  existingAccount = db.Account.Where(a => a.AccountName == request.AccountName).FirstOrDefault();

            if (existingAccount == null || existingAccount.IsActive == false)
            {
                if (existingAccount == null)
                {
                    Account acc = new Account()
                    {
                        AccountName     = request.AccountName,
                        AccountPassword = request.PasswordPreHashed ? request.AccountPassword : Crypto.ComputeSHA256(request.AccountPassword),
                        CreateDt        = now,
                        LastSignInDt    = now,
                        MachineId       = request.MachineId,
                        MediusStats     = request.MediusStats,
                        AppId           = request.AppId,
                    };

                    db.Account.Add(acc);
                    db.SaveChanges();


                    List <AccountStat> newStats = (from ds in db.DimStats
                                                   select new AccountStat()
                    {
                        AccountId = acc.AccountId,
                        StatId = ds.StatId,
                        StatValue = ds.DefaultValue
                    }).ToList();
                    db.AccountStat.AddRange(newStats);

                    AccountStatus newStatusData = new AccountStatus()
                    {
                        AccountId = acc.AccountId,
                        LoggedIn  = false,
                        GameId    = null,
                        ChannelId = null,
                        WorldId   = null
                    };
                    db.AccountStatus.Add(newStatusData);

                    db.SaveChanges();
                    return(await getAccount(acc.AccountId));
                }
                else
                {
                    existingAccount.IsActive        = true;
                    existingAccount.AccountPassword = request.AccountPassword;
                    existingAccount.ModifiedDt      = now;
                    existingAccount.MediusStats     = request.MediusStats;
                    existingAccount.AppId           = request.AppId;
                    existingAccount.MachineId       = request.MachineId;
                    existingAccount.LastSignInDt    = now;
                    db.Account.Attach(existingAccount);
                    db.Entry(existingAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified;

                    List <AccountStat> newStats = (from ds in db.DimStats
                                                   select new AccountStat()
                    {
                        AccountId = existingAccount.AccountId,
                        StatId = ds.StatId,
                        StatValue = ds.DefaultValue
                    }).ToList();
                    db.AccountStat.AddRange(newStats);

                    db.SaveChanges();
                    return(await getAccount(existingAccount.AccountId));
                }
            }
            else
            {
                return(StatusCode(403, $"Account {request.AccountName} already exists."));
            }
        }