Beispiel #1
0
        public ActionResult openMatchHistory(  )
        {
            if (Session["id"] == null || Session["role"].ToString() != "user")
            {
                return(RedirectToRoute("login"));
            }
            int playerid = Int32.Parse(Session["id"].ToString());

            csgomatch = new CSGOMatch();
            List <CSGOMatch> matchhistory = csgomatch.getPlayersMatches(playerid);

            string[] historyTable = new string[matchhistory.Count];
            for (int i = 0; i < matchhistory.Count; i++)
            {
                historyTable[i]  = "<tr>";
                historyTable[i] += "<td>" + matchhistory[i].id + "</td>";
                if (matchhistory[i].winner == 1)
                {
                    historyTable[i] += "<td>Won</td>";
                }
                else
                {
                    historyTable[i] += "<td>Lost</td>";
                }
                historyTable[i] += "<td>" + matchhistory[i].startTime.ToString() + "</td>";
                historyTable[i] += "<td>" + matchhistory[i].endTime.ToString() + "</td>";
                historyTable[i] += "</tr>";
            }
            ViewBag.historyTable = historyTable;
            return(View("~/Views/Game/MatchHistoryView.cshtml"));
        }
Beispiel #2
0
 public bool checkDidntPlayTogether(CSGOMatch match, int player_id, int[] addedPlayerIds)
 {
     foreach (var x in match.player)
     {
         if (addedPlayerIds.Contains(x.player.id))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #3
0
        public ActionResult openMatchView()
        {
            if (Session["id"] == null || Session["role"].ToString() != "user")
            {
                return(RedirectToRoute("login"));
            }
            int playerid = Int32.Parse(Session["id"].ToString());

            player    = new Player();
            csgomatch = new CSGOMatch();
            bool isSearching = player.checkIsSearching(playerid);

            if (isSearching)
            {
                return(View("~/Views/Game/MatchQueueView.cshtml"));
            }
            else
            {
                csgomatch.getOngoingMatches(playerid);
                ViewBag.x = csgomatch.id;
                bool playerIsPlayingNow = playerIsPlaying();
                if (playerIsPlayingNow)
                {
                    csgomatch.getMatchInfo();
                    ViewBag.MatchInfo = csgomatch.id.ToString();
                    string[] playerInfo1 = new string[5];
                    string[] playerInfo2 = new string[5];
                    int      index1      = 0;
                    int      index2      = 0;
                    for (int i = 0; i < 10; i++)
                    {
                        if (csgomatch.player[i].teamNo == 0)
                        {
                            playerInfo1[index1++] = csgomatch.player[i].player.id.ToString();
                        }
                        else
                        {
                            playerInfo2[index2++] = csgomatch.player[i].player.id.ToString();
                        }
                    }
                    ViewBag.PlayerInfo1 = playerInfo1;
                    ViewBag.PlayerInfo2 = playerInfo2;
                    return(View("~/Views/Game/MatchInfoView.cshtml"));
                }
                else
                {
                    player.addToQueue(playerid);
                    return(View("~/Views/Game/MatchQueueView.cshtml"));
                }
            }
        }
Beispiel #4
0
        public ActionResult checkMatchConcluded(int id)
        {
            if (Session["id"] == null || Session["role"].ToString() != "user")
            {
                return(RedirectToRoute("login"));
            }
            csgomatch = new CSGOMatch();
            bool matchConcluded = csgomatch.checkMatchConcluded(id);

            if (matchConcluded)
            {
                return(Json("1"));
            }
            return(Json("2"));
        }
Beispiel #5
0
 public ActionResult getPlayersOngoingMatch(int id)
 {
     if (Session["id"] == null || Session["role"].ToString() != "user")
     {
         return(RedirectToRoute("login"));
     }
     csgomatch = new CSGOMatch();
     csgomatch.getOngoingMatches(id);
     csgomatch.getMatchInfo();
     if (csgomatch.id != 0)
     {
         return(Json("1"));
     }
     else
     {
         return(Json("0"));
     }
 }
Beispiel #6
0
        public ActionResult admitDefeat(int playerid_, int matchid_)
        {
            if (Session["id"] == null || Session["role"].ToString() != "user")
            {
                return(RedirectToRoute("login"));
            }
            if (playerid_ != Int32.Parse(Session["id"].ToString()))
            {
                return(RedirectToRoute("login"));
            }
            csgomatchplayer = new CSGOMatchPlayer();
            int winnerTeam = csgomatchplayer.admitDefeat(playerid_, matchid_);

            csgomatch = new CSGOMatch();
            if (winnerTeam != -1)
            {
                csgomatch.concludeMatch(matchid_, winnerTeam);
            }
            return(Json("Success"));
        }
Beispiel #7
0
        public void initiateSearch(  )
        {
            player = new Player();
            int searchingCount = player.checkSearchingCount();


            if (searchingCount < 10)
            {
                return;
            }
            List <Player> players = player.getLongestSearchingPlayer();

            csgomatch = new CSGOMatch();
            csgomatch.addMatch();



            csgomatchplayer           = new CSGOMatchPlayer();
            csgomatchplayer.player    = player;
            csgomatchplayer.csgomatch = csgomatch;
            csgomatchplayer.addPlayer();
            double[] ratings = new double[10];
            ratings[0] = player.rating;
            int numberOfRatings = 1;

            int[] addedPlayerIds = new int[10];
            addedPlayerIds[0] = player.id;
            int addedPlayersCount = 1;

            string region = player.region;

            if (searchingCount < 30)
            {
                for (int i = 1; i < 10; i++)
                {
                    player.getSearchingPlayerByRating(players, ratings, numberOfRatings);
                    ratings[i]        = player.rating;
                    addedPlayerIds[i] = player.id;
                    csgomatchplayer.addPlayer();
                    numberOfRatings += 1;
                }

                /*var Connection = new MySqlConnection(ConnectionString);
                 * Connection.Open();
                 * string SQLStatement = "UPDATE player SET inQueue = 0 Where id = 100";
                 * var Command = new MySqlCommand(SQLStatement, Connection);
                 * Command.ExecuteNonQuery();
                 * Connection.Close();*/
                bool didntCancel = player.checkPlayersDidntCancel(addedPlayerIds);
                if (didntCancel == true)
                {
                    csgomatch.startMatch(addedPlayerIds);
                    player.removeFromQueue(addedPlayerIds);
                }
                else
                {
                    csgomatchplayer.removeAllUnused(csgomatch.id);
                    csgomatch.removeMatch();
                }
            }
            else
            {
                DateTime dateToCompare        = DateTime.Now;
                bool     playersCountPositive = true;
                bool     matchNotFull         = true;
                while (playersCountPositive && matchNotFull)
                {
                    player.getOtherSearchingPlayer(players);

                    bool searchLength = checkPlayerSearchLength(dateToCompare);

                    bool ratingAppropriate = checkRating(ratings, numberOfRatings);

                    bool playerRegion = checkRegion(region);

                    CSGOMatch toCheckPlayedTogether = csgomatch.getLastPlayedMatch(player.id);


                    bool playedTogether = checkDidntPlayTogether(toCheckPlayedTogether, player.id, addedPlayerIds);

                    var Connection = new MySqlConnection(ConnectionString);
                    Connection.Open();

                    if ((ratingAppropriate && playerRegion && playedTogether) || searchLength)
                    {
                        csgomatchplayer.addPlayer();
                        addedPlayerIds[addedPlayersCount++] = player.id;
                    }
                    playersCountPositive = checkAnyLeftPlayers(players);
                    matchNotFull         = !checkMatchFull(addedPlayersCount);
                }

                if (checkMatchFull(addedPlayersCount))
                {
                    bool didntCancel = player.checkPlayersDidntCancel(addedPlayerIds);
                    if (didntCancel == true)
                    {
                        csgomatch.startMatch(addedPlayerIds);
                        player.removeFromQueue(addedPlayerIds);
                    }
                    else
                    {
                        csgomatchplayer.removeAllUnused(csgomatch.id);
                        csgomatch.removeMatch();
                    }
                }
                else
                {
                    csgomatchplayer.removeAllUnused(csgomatch.id);
                    csgomatch.removeMatch();
                }
            }
        }