public ActionResult JoinTournament(long pId)
        {
            string user = Session["username"].ToString();

            var tournament = from t in context.Tournaments
                             where t.Id == pId
                             select t;

            var loggedInUser = from u in context.Users
                               where u.Username == user
                               select u;

            Tournament updateTournament = tournament.ToList().FirstOrDefault();
            User       currentUser      = loggedInUser.ToList().FirstOrDefault();


            if (currentUser.Rank < updateTournament.MinRank || currentUser.Rank > updateTournament.MaxRank)
            {
                var participantInfo = new
                {
                    Username = currentUser.Username,
                    Rank     = currentUser.Rank.ToString(),
                    Count    = updateTournament.Participants.Count,
                    IntRank  = currentUser.Rank,
                    MinRank  = updateTournament.MinRank,
                    MaxRank  = updateTournament.MaxRank
                };

                return(Json(new { info = participantInfo }, JsonRequestBehavior.DenyGet));
            }
            else
            {
                updateTournament.Participants.Add(currentUser);
                context.SaveChanges();

                var participantInfo = new
                {
                    Username = currentUser.Username,
                    Rank     = currentUser.Rank.ToString(),
                    Count    = updateTournament.Participants.Count,
                    IntRank  = currentUser.Rank,
                    MinRank  = updateTournament.MinRank,
                    MaxRank  = updateTournament.MaxRank
                };

                return(Json(new { info = participantInfo }, JsonRequestBehavior.DenyGet));
            }
        }
Example #2
0
        public ActionResult Register(string username, string email, string password, string password2)
        {
            Regex.Replace(username, @"\s+", "");  //Removes all white spaces.
            List <string> ErrorMsgList = checkRegisterInputFaults(username, email, password, password2);

            if (ErrorMsgList.Count == 0)
            {
                using (ArenaStarsContext context = new ArenaStarsContext())
                {
                    User newUser = new User()
                    {
                        Username      = username,
                        Password      = password,
                        Email         = email,
                        SignUpDate    = DateTime.Now,
                        IsAdmin       = false,
                        IsTerminated  = false,
                        LastLoggedIn  = DateTime.Now,
                        ProfilePic    = "/Images/Profile/ProfilePicture_Default.jpg",
                        BackgroundPic = "/Images/Profile/ProfileBackground_Default.jpg",
                        Country       = "World",
                        Rank          = Models.User.RankEnum.Unranked
                    };

                    Session["isLoggedIn"] = true;
                    Session["username"]   = username;

                    context.Users.Add(newUser);
                    context.SaveChanges();
                }
            }

            return(Json(new { errorList = ErrorMsgList }, JsonRequestBehavior.DenyGet));
        }
        public ActionResult AddTournament(string pName, DateTime?pStartDate, DateTime?pCheckIn, int pPlayerLimit, Tournament.TournamentTypeEnum pType, User.RankEnum pMinRank, User.RankEnum pMaxRank)
        {
            Tournament newTournament = new Tournament()
            {
                Name        = pName,
                StartDate   = pStartDate,
                CheckInDate = pCheckIn,
                PlayerLimit = pPlayerLimit,
                Type        = pType,
                MinRank     = pMinRank,
                MaxRank     = pMaxRank,
                CreatedDate = DateTime.Now,
                TrophyPic   = "/Images/Trophy/Trophy1.png"
            };

            context.Tournaments.Add(newTournament);
            context.SaveChanges();

            var tournament = new
            {
                Id          = newTournament.Id,
                Name        = newTournament.Name,
                StartDate   = newTournament.StartDate,
                PlayerLimit = newTournament.PlayerLimit,
                Type        = newTournament.Type.ToString(),
                MaxRank     = newTournament.MaxRank.ToString(),
                MinRank     = newTournament.MinRank.ToString(),
                //TrophyPic = newTournament.TrophyPic,
            };

            return(Json(new { newT = tournament }, JsonRequestBehavior.DenyGet));
        }
Example #4
0
        public ActionResult Settings()
        {
            if ((bool)Session["isLoggedIn"] == true)
            {
                string uname = Session["username"].ToString();
                using (ArenaStarsContext context = new ArenaStarsContext())
                {
                    string inputFirstname     = Request["inputFirstname"];
                    string inputLastname      = Request["inputLastname"];
                    string inputCountry       = Request["inputCountry"];
                    string inputSteamId       = Request["inputSteamId"];
                    string inputBio           = Request["inputBio"];
                    string inputProfilePic    = Request["inputProfilePic"];
                    string inputBackgroundPic = Request["inputBackgroundPic"];

                    var getUser = from u in context.Users
                                  where u.Username.ToLower() == uname.ToLower()
                                  select u;

                    User you = getUser.FirstOrDefault();

                    #region Input checks

                    if (string.IsNullOrEmpty(inputFirstname) == false)
                    {
                        you.Firstname = inputFirstname;
                    }

                    if (string.IsNullOrEmpty(inputLastname) == false)
                    {
                        you.Lastname = inputLastname;
                    }

                    if (string.IsNullOrEmpty(inputCountry) == false)
                    {
                        you.Country = inputCountry;
                    }

                    if (string.IsNullOrEmpty(inputSteamId) == false)
                    {
                        you.SteamId = inputSteamId;
                    }

                    if (string.IsNullOrEmpty(inputBio) == false)
                    {
                        you.Bio = inputBio;
                    }

                    if (string.IsNullOrEmpty(inputProfilePic) == false)
                    {
                        you.ProfilePic = inputProfilePic;
                    }

                    if (string.IsNullOrEmpty(inputBackgroundPic) == false)
                    {
                        you.BackgroundPic = inputBackgroundPic;
                    }

                    #endregion


                    context.SaveChanges();
                }

                using (ArenaStarsContext context = new ArenaStarsContext())
                {
                    //Set viewbag values

                    var getUser = from u in context.Users
                                  where u.Username.ToLower() == uname.ToLower()
                                  select u;

                    User you = getUser.FirstOrDefault();

                    ViewBag.Firstname            = you.Firstname;
                    ViewBag.Lastname             = you.Lastname;
                    ViewBag.Country              = you.Country;
                    ViewBag.SteamId              = you.SteamId;
                    ViewBag.Bio                  = you.Bio;
                    ViewBag.ProfilePic           = you.ProfilePic;
                    ViewBag.BackgroundPic        = you.BackgroundPic;
                    Session["profilePictureUrl"] = you.ProfilePic;
                }
            }
            else
            {
                return(RedirectToAction("/Index", "Home"));
            }


            return(View());
        }
Example #5
0
        public void SaveStatsAndGame(ArenaStars.Models.Game _game)
        {
            try
            {
                using (ArenaStarsContext db = new ArenaStarsContext())
                {
                    var findGame = from x in db.Games
                                   where x.Id == _game.Id
                                   select x;
                    ArenaStars.Models.Game g = findGame.FirstOrDefault();
                    User playerA             = g.Participants.FirstOrDefault();
                    User playerB             = g.Participants.LastOrDefault();

                    QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(EngineType.Source, "217.78.24.8", 28892);
                    ServerInfo info = server.GetInfo();


                    string playerAName    = "\"" + playerA.Username;
                    string playerASteamID = playerA.SteamId;
                    int    playerAKills   = 0;
                    int    playerADeaths  = 0;
                    int    playerAHSCount = 0;

                    string playerBName    = "\"" + playerB.Username;
                    string playerBSteamID = playerB.SteamId;
                    int    playerBKills   = 0;
                    int    playerBDeaths  = 0;
                    int    playerBHSCount = 0;

                    //Spagetthi for getting kills,deaths etc..
                    //Reads every line in Logs.txt and calculates
                    foreach (var line in File.ReadAllLines(logsPath))
                    {
                        if (line.StartsWith(playerAName) && line.Contains("killed"))
                        {
                            playerAKills++;
                            if (line.Contains("headshot"))
                            {
                                playerAHSCount++;
                            }
                        }
                        if (line.StartsWith(playerBName) && line.Contains("killed"))
                        {
                            playerBKills++;
                            if (line.Contains("headshot"))
                            {
                                playerBHSCount++;
                            }
                        }
                    }
                    playerADeaths = playerBKills;
                    playerBDeaths = playerAKills;


                    GameStats gameStatsA = new GameStats();
                    gameStatsA.SteamId = playerASteamID;
                    gameStatsA.Kills   = playerAKills;
                    gameStatsA.Deaths  = playerADeaths;
                    gameStatsA.HsRatio = headShotRatioConverter(playerAHSCount, playerAKills);
                    gameStatsA.Score   = 0;
                    gameStatsA.Game    = g;


                    GameStats gameStatsB = new GameStats();
                    gameStatsB.SteamId = playerBSteamID;
                    gameStatsB.Kills   = playerBKills;
                    gameStatsB.Deaths  = playerBDeaths;
                    gameStatsB.HsRatio = headShotRatioConverter(playerBHSCount, playerBKills); //ISSUES
                    gameStatsB.Score   = 0;
                    gameStatsB.Game    = g;

                    g.Winner   = getWinner(gameStatsA, gameStatsB, playerA, playerB, g);
                    g.HasEnded = true;


                    db.GameStats.Add(gameStatsA);
                    db.GameStats.Add(gameStatsB);


                    db.SaveChanges();

                    //Match has finished so we remove players from the whitelist and restart map.
                    string playerAID = "\"" + playerA.SteamId + "\"";
                    string playerBID = "\"" + playerB.SteamId + "\"";


                    if (server.GetControl("lol"))
                    {
                        server.Rcon.SendCommand("sm_whitelist_remove " + playerAID);
                        server.Rcon.SendCommand("sm_whitelist_remove " + playerBID);
                        server.Rcon.SendCommand("sm_kick @all");
                        server.Rcon.SendCommand("changelevel aim_map");
                        server.Rcon.SendCommand("warmup");
                    }
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter writer = new StreamWriter(errorsPath, true))
                {
                    writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + Environment.NewLine + "Innerexception :" + ex.InnerException +
                                     "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
            }
        }